Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-11-12 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
7fd59977 | 17 | #include <ViewerTest.hxx> |
18 | ||
bc001a40 | 19 | #include <AIS_PlaneTrihedron.hxx> |
20 | ||
7fd59977 | 21 | #include <Quantity_NameOfColor.hxx> |
22 | #include <Draw_Interpretor.hxx> | |
23 | #include <Draw.hxx> | |
24 | #include <Draw_Appli.hxx> | |
25 | #include <DBRep.hxx> | |
68ef63f9 | 26 | #include <DBRep_DrawableShape.hxx> |
7fd59977 | 27 | |
b514beda | 28 | #include <Font_BRepFont.hxx> |
ac84fcf6 | 29 | #include <Font_BRepTextBuilder.hxx> |
725ef85e | 30 | #include <Font_FontMgr.hxx> |
bc001a40 | 31 | |
32 | #include <NCollection_List.hxx> | |
33 | ||
161c4476 | 34 | #include <OSD_Chronometer.hxx> |
7fd59977 | 35 | #include <TCollection_AsciiString.hxx> |
36 | #include <V3d_Viewer.hxx> | |
37 | #include <V3d_View.hxx> | |
38 | #include <V3d.hxx> | |
39 | ||
40 | #include <AIS_Shape.hxx> | |
41 | #include <AIS_DisplayMode.hxx> | |
d33222c1 | 42 | #include <AIS_PointCloud.hxx> |
7fd59977 | 43 | #include <TColStd_MapOfInteger.hxx> |
44 | #include <AIS_MapOfInteractive.hxx> | |
4e18052b | 45 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 46 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
47 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
48 | #include <ViewerTest_EventManager.hxx> | |
49 | ||
50 | #include <TopoDS_Solid.hxx> | |
51 | #include <BRepTools.hxx> | |
52 | #include <BRep_Builder.hxx> | |
53 | #include <TopAbs_ShapeEnum.hxx> | |
54 | ||
55 | #include <TopoDS.hxx> | |
56 | #include <BRep_Tool.hxx> | |
57 | #include <TopExp_Explorer.hxx> | |
58 | ||
59 | #include <BRepAdaptor_Curve.hxx> | |
60 | #include <BRepAdaptor_Surface.hxx> | |
61 | ||
62 | #include <TopAbs.hxx> | |
63 | #include <TopExp.hxx> | |
64 | #include <TopoDS_Vertex.hxx> | |
65 | #include <TopoDS_Shape.hxx> | |
66 | #include <TopoDS_Face.hxx> | |
67 | ||
68 | #include <Draw_Window.hxx> | |
69 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
70 | #include <AIS_ListOfInteractive.hxx> | |
c60ec7f5 | 71 | #include <AIS_ColoredShape.hxx> |
7fd59977 | 72 | #include <AIS_DisplayMode.hxx> |
73 | #include <AIS_Shape.hxx> | |
74 | ||
75 | #include <AIS_InteractiveContext.hxx> | |
76 | #include <Geom_Plane.hxx> | |
77 | #include <gp_Pln.hxx> | |
7fd59977 | 78 | #include <TCollection_ExtendedString.hxx> |
725ef85e | 79 | #include <TCollection_HAsciiString.hxx> |
7fd59977 | 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> | |
29d43f9c | 87 | #include <gp_Trsf.hxx> |
1beb58d7 | 88 | #include <gp_Quaternion.hxx> |
29d43f9c | 89 | #include <TopLoc_Location.hxx> |
3fc57801 | 90 | |
91 | #include <HLRAlgo_Projector.hxx> | |
c60ec7f5 | 92 | #include <HLRBRep_Algo.hxx> |
3fc57801 | 93 | #include <HLRBRep_PolyAlgo.hxx> |
94 | #include <HLRBRep_PolyHLRToShape.hxx> | |
c60ec7f5 | 95 | #include <HLRBRep_HLRToShape.hxx> |
3fc57801 | 96 | #include <Aspect_Window.hxx> |
97 | ||
9558a876 A |
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> | |
da87ddc3 | 107 | #include <Graphic3d_AttribBuffer.hxx> |
a577aaab | 108 | #include <Graphic3d_AspectMarker3d.hxx> |
9558a876 A |
109 | #include <Graphic3d_Group.hxx> |
110 | #include <Standard_Real.hxx> | |
111 | ||
329843e2 | 112 | #include <AIS_Circle.hxx> |
329843e2 A |
113 | #include <BRepBuilderAPI_MakeEdge.hxx> |
114 | #include <BRepBuilderAPI_MakeFace.hxx> | |
115 | #include <BRepBuilderAPI_MakeWire.hxx> | |
116 | #include <Geom_Circle.hxx> | |
117 | #include <GC_MakeCircle.hxx> | |
329843e2 A |
118 | #include <Select3D_SensitiveCircle.hxx> |
119 | #include <SelectMgr_EntityOwner.hxx> | |
120 | #include <SelectMgr_Selection.hxx> | |
121 | #include <StdFail_NotDone.hxx> | |
122 | #include <StdPrs_ShadedShape.hxx> | |
a2d5ab2e | 123 | #include <TopoDS_Wire.hxx> |
ac04d101 | 124 | |
792c785c | 125 | #include <AIS_MultipleConnectedInteractive.hxx> |
0717ddc1 | 126 | #include <AIS_ConnectedInteractive.hxx> |
29e2c6d2 | 127 | #include <AIS_TextLabel.hxx> |
ac04d101 SA |
128 | #include <TopLoc_Location.hxx> |
129 | #include <TColStd_ListOfInteger.hxx> | |
130 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
329843e2 | 131 | |
9427bc1d | 132 | #include <Select3D_SensitiveSegment.hxx> |
133 | #include <Select3D_SensitivePrimitiveArray.hxx> | |
ceae62f0 A |
134 | #include <Select3D_SensitiveTriangle.hxx> |
135 | #include <Select3D_SensitiveCurve.hxx> | |
a577aaab | 136 | #include <Select3D_SensitivePoint.hxx> |
ceae62f0 A |
137 | #include <BRepAdaptor_Curve.hxx> |
138 | #include <StdPrs_Curve.hxx> | |
139 | ||
140 | #include <BRepExtrema_ExtPC.hxx> | |
141 | #include <BRepExtrema_ExtPF.hxx> | |
142 | ||
68ef63f9 | 143 | #include <Prs3d_Arrow.hxx> |
144 | #include <Prs3d_ArrowAspect.hxx> | |
bc001a40 | 145 | #include <Prs3d_DatumAttribute.hxx> |
046a1c9d | 146 | #include <Prs3d_DatumAspect.hxx> |
6262338c | 147 | #include <Prs3d_Drawer.hxx> |
53b15292 | 148 | #include <Prs3d_VertexDrawMode.hxx> |
a2d5ab2e | 149 | #include <Prs3d_LineAspect.hxx> |
a577aaab | 150 | #include <Prs3d_PointAspect.hxx> |
bc001a40 | 151 | #include <Prs3d_Presentation.hxx> |
61b0191c | 152 | #include <Prs3d_TextAspect.hxx> |
a577aaab | 153 | |
154 | #include <Image_AlienPixMap.hxx> | |
eb4320f2 | 155 | #include <TColStd_HArray1OfAsciiString.hxx> |
046a1c9d | 156 | #include <TColStd_HSequenceOfAsciiString.hxx> |
a2d5ab2e | 157 | |
7fd59977 | 158 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
9558a876 A |
159 | extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
160 | const Handle(AIS_InteractiveObject)& theAISObj, | |
161 | Standard_Boolean theReplaceIfExists = Standard_True); | |
1d0a9d4d | 162 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); |
7fd59977 | 163 | extern Handle(AIS_InteractiveContext)& TheAISContext(); |
164 | ||
bc001a40 | 165 | namespace |
166 | { | |
167 | static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues, | |
168 | Quantity_Color& theColor) | |
169 | { | |
170 | const char* anArgs[3] = | |
171 | { | |
172 | theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "", | |
173 | theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "", | |
174 | theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : "" | |
175 | }; | |
176 | return ViewerTest::ParseColor (theColorValues->Size(), anArgs, theColor) != 0; | |
177 | } | |
178 | ||
179 | static bool convertToDatumPart (const TCollection_AsciiString& theValue, | |
180 | Prs3d_DatumParts& theDatumPart) | |
181 | { | |
182 | TCollection_AsciiString aValue = theValue; | |
183 | aValue.LowerCase(); | |
184 | if (aValue == "origin") theDatumPart = Prs3d_DP_Origin; | |
185 | else if (aValue == "xaxis") theDatumPart = Prs3d_DP_XAxis; | |
186 | else if (aValue == "yaxis") theDatumPart = Prs3d_DP_YAxis; | |
187 | else if (aValue == "zaxis") theDatumPart = Prs3d_DP_ZAxis; | |
188 | else if (aValue == "xarrow") theDatumPart = Prs3d_DP_XArrow; | |
189 | else if (aValue == "yarrow") theDatumPart = Prs3d_DP_YArrow; | |
190 | else if (aValue == "zarrow") theDatumPart = Prs3d_DP_ZArrow; | |
191 | else if (aValue == "xoyaxis") theDatumPart = Prs3d_DP_XOYAxis; | |
192 | else if (aValue == "yozaxis") theDatumPart = Prs3d_DP_YOZAxis; | |
193 | else if (aValue == "xozaxis") theDatumPart = Prs3d_DP_XOZAxis; | |
194 | else if (aValue == "whole") theDatumPart = Prs3d_DP_None; | |
195 | else | |
196 | { | |
197 | return false; | |
198 | } | |
199 | return true; | |
200 | } | |
201 | ||
202 | static void convertToDatumParts (const TCollection_AsciiString& theValue, | |
203 | NCollection_List<Prs3d_DatumParts>& theParts) | |
204 | { | |
205 | TCollection_AsciiString aValue = theValue; | |
206 | const Standard_Integer aSplitPos = theValue.Search ("|"); | |
207 | Prs3d_DatumParts aPart = Prs3d_DP_None; | |
208 | if (aSplitPos > 0) | |
209 | { | |
210 | convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts); | |
211 | if (aSplitPos == 1) // first symbol | |
212 | { | |
213 | return; | |
214 | } | |
215 | aValue = theValue.SubString (1, aSplitPos - 1); | |
216 | } | |
217 | if (convertToDatumPart (aValue, aPart)) | |
218 | { | |
219 | theParts.Append (aPart); | |
220 | } | |
221 | } | |
222 | ||
223 | static bool convertToDatumAttribute (const TCollection_AsciiString& theValue, | |
224 | Prs3d_DatumAttribute& theAttribute) | |
225 | { | |
226 | TCollection_AsciiString aValue = theValue; | |
227 | aValue.LowerCase(); | |
228 | if (aValue == "xaxislength") theAttribute = Prs3d_DA_XAxisLength; | |
229 | else if (aValue == "yaxislength") theAttribute = Prs3d_DA_YAxisLength; | |
230 | else if (aValue == "zaxislength") theAttribute = Prs3d_DA_ZAxisLength; | |
231 | else if (aValue == "tuberadiuspercent") theAttribute = Prs3d_DP_ShadingTubeRadiusPercent; | |
232 | else if (aValue == "coneradiuspercent") theAttribute = Prs3d_DP_ShadingConeRadiusPercent; | |
233 | else if (aValue == "conelengthpercent") theAttribute = Prs3d_DP_ShadingConeLengthPercent; | |
234 | else if (aValue == "originradiuspercent") theAttribute = Prs3d_DP_ShadingOriginRadiusPercent; | |
235 | else if (aValue == "shadingnumberoffacettes") theAttribute = Prs3d_DP_ShadingNumberOfFacettes; | |
236 | else | |
237 | return false; | |
238 | return true; | |
239 | } | |
240 | ||
241 | static void convertToDatumAttributes (const TCollection_AsciiString& theValue, | |
242 | NCollection_List<Prs3d_DatumAttribute>& theAttributes) | |
243 | { | |
244 | TCollection_AsciiString aValue = theValue; | |
245 | const Standard_Integer aSplitPos = theValue.Search ("|"); | |
246 | Prs3d_DatumAttribute anAttribute = Prs3d_DA_XAxisLength; | |
247 | if (aSplitPos > 0) | |
248 | { | |
249 | convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes); | |
250 | if (aSplitPos == 1) // first symbol | |
251 | { | |
252 | return; | |
253 | } | |
254 | aValue = theValue.SubString (1, aSplitPos - 1); | |
255 | } | |
256 | if (convertToDatumAttribute (aValue, anAttribute)) | |
257 | { | |
258 | theAttributes.Append (anAttribute); | |
259 | } | |
260 | } | |
261 | ||
262 | static bool convertToDatumAxes (const TCollection_AsciiString& theValue, | |
263 | Prs3d_DatumAxes& theDatumAxes) | |
264 | { | |
265 | TCollection_AsciiString aValue = theValue; | |
266 | aValue.LowerCase(); | |
267 | if (aValue == "x") theDatumAxes = Prs3d_DA_XAxis; | |
268 | else if (aValue == "y") theDatumAxes = Prs3d_DA_YAxis; | |
269 | else if (aValue == "z") theDatumAxes = Prs3d_DA_ZAxis; | |
270 | else if (aValue == "xy") theDatumAxes = Prs3d_DA_XYAxis; | |
271 | else if (aValue == "zy") theDatumAxes = Prs3d_DA_YZAxis; | |
272 | else if (aValue == "xz") theDatumAxes = Prs3d_DA_XZAxis; | |
273 | else if (aValue == "xyz") theDatumAxes = Prs3d_DA_XYZAxis; | |
274 | else | |
275 | { | |
276 | return false; | |
277 | } | |
278 | return true; | |
279 | } | |
280 | ||
281 | static Standard_Boolean setTrihedronParams (Standard_Integer theArgsNb, | |
282 | const char** theArgVec, | |
283 | Handle(AIS_Trihedron) theTrihedron) | |
284 | { | |
285 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; | |
286 | TCollection_AsciiString aParseKey; | |
287 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
288 | { | |
289 | TCollection_AsciiString anArg (theArgVec [anArgIt]); | |
290 | if (anArg.Value (1) == '-' | |
291 | && !anArg.IsRealValue()) | |
292 | { | |
293 | aParseKey = anArg; | |
294 | aParseKey.Remove (1); | |
295 | aParseKey.LowerCase(); | |
296 | std::string aKey = aParseKey.ToCString(); | |
297 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString()); | |
298 | continue; | |
299 | } | |
300 | ||
301 | if (aParseKey.IsEmpty()) | |
302 | { | |
303 | continue; | |
304 | } | |
305 | ||
306 | aMapOfArgs (aParseKey)->Append (anArg); | |
307 | } | |
308 | ||
309 | // Check parameters | |
310 | if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis")) | |
311 | || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis"))) | |
312 | { | |
313 | std::cout << "Syntax error: -xaxis and -zaxis parameters are to set together.\n"; | |
314 | return Standard_False; | |
315 | } | |
316 | ||
317 | Handle(TColStd_HSequenceOfAsciiString) aValues; | |
318 | Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component(); | |
319 | if (aMapOfArgs.Find ("origin", aValues)) | |
320 | { | |
321 | aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(), | |
322 | aValues->Value (2).RealValue(), | |
323 | aValues->Value (3).RealValue())); | |
324 | } | |
325 | Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues; | |
326 | if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues)) | |
327 | { | |
328 | gp_Dir aXDir (aXValues->Value (1).RealValue(), | |
329 | aXValues->Value (2).RealValue(), | |
330 | aXValues->Value (3).RealValue()); | |
331 | ||
332 | gp_Dir aZDir (aZValues->Value (1).RealValue(), | |
333 | aZValues->Value (2).RealValue(), | |
334 | aZValues->Value (3).RealValue()); | |
335 | ||
336 | if (!aZDir.IsNormal (aXDir, M_PI / 180.0)) | |
337 | { | |
338 | std::cout << "Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ\n"; | |
339 | return Standard_False; | |
340 | } | |
341 | ||
169c944c | 342 | aComponent->SetAx2 (gp_Ax2 (aComponent->Location(), aZDir, aXDir)); |
bc001a40 | 343 | } |
344 | ||
345 | if (aMapOfArgs.Find ("dispmode", aValues)) | |
346 | { | |
347 | TCollection_AsciiString aValue (aValues->Value (1)); | |
348 | bool isWireframe = true; | |
349 | if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading")) | |
350 | isWireframe = false; | |
351 | theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame | |
352 | : Prs3d_DM_Shaded); | |
353 | } | |
354 | ||
355 | if (aMapOfArgs.Find ("hidelabels", aValues)) | |
356 | { | |
fae1ae11 ZA |
357 | Standard_Boolean toHideLabels = Standard_True; |
358 | if (aValues->Size() == 1) | |
359 | { | |
360 | ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideLabels); | |
361 | } | |
362 | else if (aValues->Size() != 0) | |
bc001a40 | 363 | { |
364 | std::cout << "Syntax error: -hidelabels expects parameter 'on' or 'off' after.\n"; | |
365 | return Standard_False; | |
366 | } | |
367 | ||
bc001a40 | 368 | if (!theTrihedron->Attributes()->HasOwnDatumAspect()) |
fae1ae11 ZA |
369 | { |
370 | theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect()); | |
371 | } | |
372 | theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels); | |
373 | } | |
374 | ||
375 | if (aMapOfArgs.Find ("hidearrows", aValues)) | |
376 | { | |
377 | Standard_Boolean toHideArrows = Standard_True; | |
378 | if (aValues->Size() == 1) | |
379 | { | |
380 | ViewerTest::ParseOnOff (aValues->First().ToCString(), toHideArrows); | |
381 | } | |
382 | else if (aValues->Size() != 0) | |
383 | { | |
384 | std::cout << "Syntax error: -hidearrows expects parameter 'on' or 'off' after.\n"; | |
385 | return Standard_False; | |
386 | } | |
387 | ||
388 | if (!theTrihedron->Attributes()->HasOwnDatumAspect()) | |
389 | { | |
390 | theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect()); | |
391 | } | |
392 | theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows); | |
bc001a40 | 393 | } |
394 | ||
395 | if (aMapOfArgs.Find ("color", aValues)) | |
396 | { | |
397 | NCollection_List<Prs3d_DatumParts> aParts; | |
398 | if (aValues->Size() < 2) | |
399 | { | |
400 | std::cout << "Syntax error: -color wrong parameters.\n"; | |
401 | return Standard_False; | |
402 | } | |
403 | ||
404 | convertToDatumParts (aValues->Value(1), aParts); | |
405 | aValues->Remove (1); // datum part is processed | |
406 | Quantity_Color aColor; | |
407 | if (!convertToColor (aValues, aColor)) | |
408 | { | |
409 | std::cout << "Syntax error: -color wrong parameters.\n"; | |
410 | return Standard_False; | |
411 | } | |
412 | ||
413 | for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next()) | |
414 | { | |
415 | Prs3d_DatumParts aDatumPart = anIterator.Value(); | |
416 | if (aDatumPart == Prs3d_DP_None) | |
417 | { | |
418 | theTrihedron->SetColor (aColor); | |
419 | } | |
420 | else | |
421 | { | |
422 | theTrihedron->SetDatumPartColor (aDatumPart, aColor); | |
423 | } | |
424 | } | |
425 | } | |
426 | ||
427 | if (aMapOfArgs.Find ("textcolor", aValues)) | |
428 | { | |
429 | Quantity_Color aColor; | |
430 | if (!convertToColor (aValues, aColor)) | |
431 | { | |
432 | std::cout << "Syntax error: -textcolor wrong parameters.\n"; | |
433 | return Standard_False; | |
434 | } | |
435 | theTrihedron->SetTextColor (aColor); | |
436 | } | |
437 | ||
438 | if (aMapOfArgs.Find ("arrowcolor", aValues)) | |
439 | { | |
440 | Quantity_Color aColor; | |
441 | if (!convertToColor (aValues, aColor)) | |
442 | { | |
443 | std::cout << "Syntax error: -arrowcolor wrong parameters.\n"; | |
444 | return Standard_False; | |
445 | } | |
446 | theTrihedron->SetArrowColor (aColor); | |
447 | } | |
448 | ||
449 | if (aMapOfArgs.Find ("attribute", aValues)) | |
450 | { | |
451 | NCollection_List<Prs3d_DatumAttribute> anAttributes; | |
452 | if (aValues->Size() != 2) | |
453 | { | |
454 | std::cout << "Syntax error: -attribute wrong parameters.\n"; | |
455 | return Standard_False; | |
456 | } | |
457 | ||
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()) | |
462 | { | |
463 | theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue()); | |
464 | } | |
465 | } | |
466 | ||
467 | if (aMapOfArgs.Find ("priority", aValues)) | |
468 | { | |
469 | Prs3d_DatumParts aDatumPart; | |
470 | if (aValues->Size() < 2 | |
471 | || !convertToDatumPart (aValues->Value (1), aDatumPart)) | |
472 | { | |
473 | std::cout << "Syntax error: -priority wrong parameters.\n"; | |
474 | return Standard_False; | |
475 | } | |
476 | theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue()); | |
477 | } | |
478 | ||
169c944c | 479 | if (aMapOfArgs.Find ("labels", aValues) |
480 | || aMapOfArgs.Find ("label", aValues)) | |
bc001a40 | 481 | { |
482 | Prs3d_DatumParts aDatumPart = Prs3d_DP_None; | |
169c944c | 483 | if (aValues->Size() >= 2 |
bc001a40 | 484 | && convertToDatumPart(aValues->Value(1), aDatumPart) |
485 | && aDatumPart >= Prs3d_DP_XAxis | |
486 | && aDatumPart <= Prs3d_DP_ZAxis) // labels are set to axes only | |
487 | { | |
488 | theTrihedron->SetLabel (aDatumPart, aValues->Value (2)); | |
489 | } | |
490 | else | |
491 | { | |
492 | std::cout << "Syntax error: -labels wrong parameters.\n"; | |
493 | return Standard_False; | |
494 | } | |
495 | } | |
496 | ||
497 | if (aMapOfArgs.Find ("drawaxes", aValues)) | |
498 | { | |
499 | Prs3d_DatumAxes aDatumAxes = Prs3d_DA_XAxis; | |
500 | if (aValues->Size() < 1 | |
501 | || !convertToDatumAxes (aValues->Value (1), aDatumAxes)) | |
502 | { | |
503 | std::cout << "Syntax error: -drawaxes wrong parameters.\n"; | |
504 | return Standard_False; | |
505 | } | |
506 | if (!theTrihedron->Attributes()->HasOwnDatumAspect()) | |
507 | theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect()); | |
508 | theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes); | |
509 | } | |
510 | return Standard_True; | |
511 | } | |
5b377041 | 512 | |
513 | //! Auxiliary function to parse font aspect style argument | |
514 | static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg, | |
515 | Font_FontAspect& theAspect) | |
516 | { | |
517 | if (theArg == "regular" | |
518 | || *theArg.ToCString() == 'r') | |
519 | { | |
520 | theAspect = Font_FA_Regular; | |
521 | return Standard_True; | |
522 | } | |
523 | else if (theArg == "bolditalic" | |
524 | || theArg == "bold-italic" | |
525 | || theArg == "italic-bold" | |
526 | || theArg == "italicbold") | |
527 | { | |
528 | theAspect = Font_FA_BoldItalic; | |
529 | return Standard_True; | |
530 | } | |
531 | else if (theArg == "bold" | |
532 | || *theArg.ToCString() == 'b') | |
533 | { | |
534 | theAspect = Font_FA_Bold; | |
535 | return Standard_True; | |
536 | } | |
537 | else if (theArg == "italic" | |
538 | || *theArg.ToCString() == 'i') | |
539 | { | |
540 | theAspect = Font_FA_Italic; | |
541 | return Standard_True; | |
542 | } | |
543 | return Standard_False; | |
544 | } | |
1bbd7c79 | 545 | |
546 | //! Auxiliary function to parse font strict level argument | |
547 | static Standard_Integer parseFontStrictLevel (const Standard_Integer theArgNb, | |
548 | const char** theArgVec, | |
549 | Font_StrictLevel& theLevel) | |
550 | { | |
551 | if (theArgNb >= 1) | |
552 | { | |
553 | TCollection_AsciiString anArg (theArgVec[0]); | |
554 | anArg.LowerCase(); | |
555 | if (anArg == "any") | |
556 | { | |
557 | theLevel = Font_StrictLevel_Any; | |
558 | return 1; | |
559 | } | |
560 | else if (anArg == "aliases") | |
561 | { | |
562 | theLevel = Font_StrictLevel_Aliases; | |
563 | return 1; | |
564 | } | |
565 | else if (anArg == "strict") | |
566 | { | |
567 | theLevel = Font_StrictLevel_Strict; | |
568 | return 1; | |
569 | } | |
570 | } | |
571 | theLevel = Font_StrictLevel_Strict; | |
572 | return 0; | |
573 | } | |
bc001a40 | 574 | } |
575 | ||
7fd59977 | 576 | //============================================================================== |
577 | //function : Vtrihedron 2d | |
578 | //purpose : Create a plane with a 2D trihedron from a faceselection | |
161c4476 | 579 | //Draw arg : vtri2d name |
7fd59977 | 580 | //============================================================================== |
404c8936 | 581 | static int VTrihedron2D (Draw_Interpretor& /*theDI*/, |
582 | Standard_Integer theArgsNum, | |
583 | const char** theArgVec) | |
584 | { | |
585 | if (theArgsNum != 2) | |
586 | { | |
587 | std::cerr << theArgVec[0]<< " error.\n"; | |
588 | return 1; | |
589 | } | |
7fd59977 | 590 | |
404c8936 | 591 | TopTools_ListOfShape aShapes; |
592 | ViewerTest::GetSelectedShapes (aShapes); | |
7fd59977 | 593 | |
404c8936 | 594 | if (aShapes.Extent() != 1) |
595 | { | |
596 | std::cerr << "Error: wrong number of selected shapes.\n"; | |
597 | return 1; | |
598 | } | |
7fd59977 | 599 | |
404c8936 | 600 | const TopoDS_Shape& aShape = aShapes.First(); |
7fd59977 | 601 | |
404c8936 | 602 | TopoDS_Face aFace = TopoDS::Face (aShape); |
603 | TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE); | |
604 | TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current()); | |
7fd59977 | 605 | |
7fd59977 | 606 | gp_Pnt A,B,C; |
404c8936 | 607 | if (aFaceExp.More()) |
608 | { | |
609 | aFaceExp.Next(); | |
610 | TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() ); | |
611 | BRepAdaptor_Curve aCurve0 (anEdge0); | |
612 | BRepAdaptor_Curve aCurve1 (anEdge1); | |
613 | A = aCurve1.Value (0.1); | |
614 | B = aCurve1.Value (0.9); | |
615 | C = aCurve0.Value (0.5); | |
7fd59977 | 616 | } |
404c8936 | 617 | else |
618 | { | |
619 | BRepAdaptor_Curve aCurve0 (anEdge0); | |
620 | A = aCurve0.Value (0.1); | |
621 | B = aCurve0.Value (0.9); | |
622 | C = aCurve0.Value (0.5); | |
7fd59977 | 623 | } |
7fd59977 | 624 | |
404c8936 | 625 | GC_MakePlane aMkPlane (A,B,C); |
7fd59977 | 626 | |
404c8936 | 627 | Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value()); |
628 | TCollection_AsciiString aName (theArgVec[1]); | |
7fd59977 | 629 | |
404c8936 | 630 | VDisplayAISObject (aName, anAISPlaneTri); |
7fd59977 | 631 | |
161c4476 | 632 | return 0; |
7fd59977 | 633 | } |
634 | ||
bc001a40 | 635 | //======================================================================= |
636 | //function : VTrihedron | |
637 | //purpose : | |
638 | //======================================================================= | |
639 | static int VTrihedron (Draw_Interpretor& , | |
640 | Standard_Integer theArgsNb, | |
641 | const char** theArgVec) | |
7fd59977 | 642 | { |
bc001a40 | 643 | if (theArgsNb < 2) |
dc9b6d23 | 644 | { |
bc001a40 | 645 | std::cout << "Syntax error: the wrong number of input parameters.\n"; |
dc9b6d23 | 646 | return 1; |
7fd59977 | 647 | } |
7fd59977 | 648 | |
bc001a40 | 649 | TCollection_AsciiString aName (theArgVec[1]); |
650 | gp_Pln aWorkingPlane; | |
651 | Standard_Boolean toUpdate = Standard_True; | |
046a1c9d | 652 | |
bc001a40 | 653 | NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams; |
654 | NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams; | |
046a1c9d | 655 | |
bc001a40 | 656 | Handle(AIS_Trihedron) aTrihedron; |
8f521168 | 657 | Handle(AIS_InteractiveObject) anObject; |
658 | if (GetMapOfAIS().Find2 (aName, anObject)) | |
046a1c9d | 659 | { |
bc001a40 | 660 | aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject); |
661 | if (aTrihedron.IsNull()) | |
046a1c9d | 662 | { |
bc001a40 | 663 | std::cout << "Syntax error: no trihedron with this name.\n"; |
664 | return 1; | |
046a1c9d | 665 | } |
666 | } | |
bc001a40 | 667 | else |
dc9b6d23 | 668 | { |
bc001a40 | 669 | Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0), |
670 | gp::DZ(), gp::DX()); | |
671 | aTrihedron = new AIS_Trihedron (aPlacement); | |
046a1c9d | 672 | } |
dc9b6d23 | 673 | |
bc001a40 | 674 | if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron)) |
046a1c9d | 675 | { |
bc001a40 | 676 | return 1; |
dc9b6d23 | 677 | } |
7fd59977 | 678 | |
bc001a40 | 679 | // Redisplay a dimension after parameter changing. |
680 | if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron)) | |
dc9b6d23 | 681 | { |
bc001a40 | 682 | ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate); |
dc9b6d23 | 683 | } |
bc001a40 | 684 | else |
046a1c9d | 685 | { |
bc001a40 | 686 | VDisplayAISObject (theArgVec[1], aTrihedron); |
046a1c9d | 687 | } |
688 | ||
161c4476 | 689 | return 0; |
7fd59977 | 690 | } |
691 | ||
7fd59977 | 692 | //============================================================================== |
693 | //function : VSize | |
694 | //author : ege | |
695 | //purpose : Change the size of a named or selected trihedron | |
696 | // if no name : it affects the trihedrons witch are selected otherwise nothing is donne | |
697 | // if no value, the value is set at 100 by default | |
698 | //Draw arg : vsize [name] [size] | |
699 | //============================================================================== | |
700 | ||
701 | static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
702 | ||
703 | { | |
704 | // Declaration de booleens | |
705 | Standard_Boolean ThereIsName; | |
706 | Standard_Boolean ThereIsCurrent; | |
707 | Standard_Real value; | |
161c4476 | 708 | Standard_Boolean hascol; |
1d47d8d0 | 709 | |
87432b82 | 710 | Quantity_Color col = Quantity_NOC_BLACK; |
7fd59977 | 711 | |
712 | // Verification des arguments | |
586db386 | 713 | if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;} |
7fd59977 | 714 | |
715 | // Verification du nombre d'arguments | |
716 | if (argc==1) {ThereIsName=Standard_False;value=100;} | |
91322f44 | 717 | else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);} |
718 | else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);} | |
7fd59977 | 719 | |
7fd59977 | 720 | // On set le booleen ThereIsCurrent |
c3282ec1 | 721 | if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;} |
7fd59977 | 722 | else {ThereIsCurrent=Standard_False;} |
723 | ||
724 | ||
725 | ||
726 | //=============================================================== | |
727 | // Il n'y a pas de nom mais des objets selectionnes | |
728 | //=============================================================== | |
161c4476 | 729 | if (!ThereIsName && ThereIsCurrent) |
7fd59977 | 730 | { |
731 | ||
732 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
733 | it (GetMapOfAIS()); | |
734 | ||
735 | while ( it.More() ) { | |
736 | ||
8f521168 | 737 | Handle(AIS_InteractiveObject) aShape = it.Key1(); |
7fd59977 | 738 | |
c3282ec1 | 739 | if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) ) |
7fd59977 | 740 | { |
741 | ||
161c4476 | 742 | // On verifie que l'AIS InteraciveObject selectionne est bien |
7fd59977 | 743 | // un AIS_Trihedron |
744 | if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) { | |
745 | ||
87432b82 | 746 | if (aShape->HasColor()) |
747 | { | |
748 | hascol = Standard_True; | |
7fd59977 | 749 | |
750 | // On recupere la couleur de aShape | |
87432b82 | 751 | aShape->Color (col); |
752 | } | |
753 | else | |
754 | { | |
755 | hascol = Standard_False; | |
756 | } | |
7fd59977 | 757 | |
758 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
759 | // pour lui appliquer la methode SetSize() | |
c5f3a425 | 760 | Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape); |
7fd59977 | 761 | |
762 | // C'est bien un triedre,on chage sa valeur! | |
763 | aTrihedron->SetSize(value); | |
764 | ||
765 | // On donne la couleur au Trihedron | |
766 | if(hascol) aTrihedron->SetColor(col); | |
767 | else aTrihedron->UnsetColor(); | |
768 | ||
769 | ||
770 | // The trihedron hasn't be errased from the map | |
771 | // so you just have to redisplay it | |
772 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
773 | ||
774 | } | |
775 | ||
776 | } | |
777 | ||
778 | it.Next(); | |
779 | } | |
780 | ||
781 | TheAISContext() ->UpdateCurrentViewer(); | |
782 | } | |
783 | ||
784 | //=============================================================== | |
785 | // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire! | |
786 | //=============================================================== | |
787 | ||
788 | ||
789 | ||
790 | //=============================================================== | |
791 | // Il y a un nom de triedre passe en argument | |
792 | //=============================================================== | |
793 | if (ThereIsName) { | |
794 | TCollection_AsciiString name=argv[1]; | |
795 | ||
796 | // on verifie que ce nom correspond bien a une shape | |
8f521168 | 797 | Handle(AIS_InteractiveObject) aShape; |
798 | if (GetMapOfAIS().Find2(name, aShape)) | |
799 | { | |
161c4476 | 800 | // On verifie que l'AIS InteraciveObject est bien |
7fd59977 | 801 | // un AIS_Trihedron |
802 | if (!aShape.IsNull() && | |
803 | aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) | |
804 | { | |
87432b82 | 805 | if (aShape->HasColor()) |
806 | { | |
7fd59977 | 807 | hascol=Standard_True; |
808 | ||
809 | // On recupere la couleur de aShape | |
87432b82 | 810 | aShape->Color (col); |
811 | } | |
812 | else | |
813 | { | |
814 | hascol = Standard_False; | |
815 | } | |
7fd59977 | 816 | |
817 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
818 | // pour lui appliquer la methode SetSize() | |
c5f3a425 | 819 | Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape); |
7fd59977 | 820 | |
821 | // C'est bien un triedre,on chage sa valeur | |
822 | aTrihedron->SetSize(value); | |
823 | ||
824 | // On donne la couleur au Trihedron | |
825 | if(hascol) aTrihedron->SetColor(col); | |
826 | else aTrihedron->UnsetColor(); | |
827 | ||
828 | // The trihedron hasn't be errased from the map | |
829 | // so you just have to redisplay it | |
830 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
831 | ||
832 | TheAISContext() ->UpdateCurrentViewer(); | |
833 | } | |
834 | } | |
835 | } | |
161c4476 | 836 | return 0; |
7fd59977 | 837 | } |
838 | ||
839 | ||
840 | //============================================================================== | |
841 | ||
842 | //============================================================================== | |
843 | //function : VPlaneTrihedron | |
844 | //purpose : Create a plane from a trihedron selection. If no arguments are set, the default | |
161c4476 | 845 | //Draw arg : vplanetri name |
7fd59977 | 846 | //============================================================================== |
847 | #include <AIS_Plane.hxx> | |
848 | ||
849 | ||
850 | ||
851 | static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
852 | ||
853 | { | |
854 | // Verification des arguments | |
586db386 | 855 | if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;} |
7fd59977 | 856 | |
404c8936 | 857 | if (TheAISContext()->NbSelected() != 1) |
858 | { | |
859 | std::cerr << "Error: Wrong number of selected shapes.\n"; | |
860 | return 1; | |
7fd59977 | 861 | } |
862 | ||
404c8936 | 863 | TheAISContext()->InitSelected(); |
864 | Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive(); | |
865 | Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest); | |
866 | if (aPlane.IsNull()) | |
867 | { | |
868 | std::cerr << "Error: Selected shape is not a plane.\n"; | |
869 | return 1; | |
7fd59977 | 870 | } |
7fd59977 | 871 | |
404c8936 | 872 | VDisplayAISObject (argv[1], aPlane); |
7fd59977 | 873 | |
161c4476 | 874 | return 0; |
7fd59977 | 875 | } |
876 | ||
877 | ||
878 | ||
879 | //============================================================================== | |
880 | // Fonction First click 2de click | |
161c4476 | 881 | // |
7fd59977 | 882 | // vaxis vertex vertex |
883 | // edge None | |
884 | // vaxispara edge vertex | |
885 | // vaxisortho edge Vertex | |
886 | // vaxisinter Face Face | |
887 | //============================================================================== | |
888 | ||
889 | //============================================================================== | |
890 | //function : VAxisBuilder | |
161c4476 | 891 | //purpose : |
7fd59977 | 892 | //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb |
893 | //============================================================================== | |
894 | #include <TopoDS_Edge.hxx> | |
895 | #include <TopoDS_Vertex.hxx> | |
896 | #include <TopExp.hxx> | |
897 | #include <Geom_Line.hxx> | |
898 | ||
161c4476 | 899 | static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 900 | { |
901 | // Declarations | |
902 | Standard_Boolean HasArg; | |
903 | TCollection_AsciiString name; | |
7fd59977 | 904 | |
905 | // Verification | |
586db386 | 906 | if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;} |
7fd59977 | 907 | if (argc==8) HasArg=Standard_True; |
908 | else HasArg=Standard_False; | |
909 | ||
910 | name=argv[1]; | |
404c8936 | 911 | |
912 | TopTools_ListOfShape aShapes; | |
913 | ViewerTest::GetSelectedShapes (aShapes); | |
7fd59977 | 914 | |
915 | // Cas ou il y a des arguments | |
916 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom) | |
917 | if (HasArg) { | |
918 | Standard_Real coord[6]; | |
919 | for(Standard_Integer i=0;i<=5;i++){ | |
91322f44 | 920 | coord[i]=Draw::Atof(argv[2+i]); |
7fd59977 | 921 | } |
922 | gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ; | |
923 | ||
924 | gp_Vec myVect (p1,p2); | |
925 | Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect ); | |
926 | Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine ); | |
927 | GetMapOfAIS().Bind (TheAxis,name); | |
0577ae8c | 928 | TheAISContext()->Display(TheAxis, Standard_True); |
7fd59977 | 929 | } |
930 | ||
931 | // Pas d'arguments | |
932 | else { | |
933 | // fonction vaxis | |
934 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom) | |
935 | if ( !strcasecmp(argv[0], "vaxis")) { | |
404c8936 | 936 | if (aShapes.Extent() != 2 && aShapes.Extent() != 1) |
937 | { | |
938 | std::cerr << "Error: Wrong number of selected shapes.\n"; | |
939 | return 1; | |
7fd59977 | 940 | } |
7fd59977 | 941 | |
404c8936 | 942 | const TopoDS_Shape& aShapeA = aShapes.First(); |
943 | if (aShapeA.ShapeType() == TopAbs_VERTEX) | |
944 | { | |
945 | if (aShapes.Extent() != 2) | |
946 | { | |
947 | std::cerr << "Error: Wron number of selected shapes.\n"; | |
948 | return 1; | |
949 | } | |
7fd59977 | 950 | |
404c8936 | 951 | const TopoDS_Shape& aShapeB = aShapes.Last(); |
952 | if (aShapeB.ShapeType() != TopAbs_VERTEX) | |
953 | { | |
954 | std::cerr << "Syntax error: You should select two vertices or one edge.\n"; | |
955 | return 1; | |
956 | } | |
7fd59977 | 957 | |
161c4476 | 958 | // Construction de l'axe |
404c8936 | 959 | gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA)); |
960 | gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB)); | |
961 | gp_Vec V (A,B); | |
962 | gp_Dir D (V); | |
7fd59977 | 963 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); |
964 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
965 | GetMapOfAIS().Bind (TheAxis,name); | |
0577ae8c | 966 | TheAISContext()->Display (TheAxis, Standard_True); |
161c4476 | 967 | } |
404c8936 | 968 | else |
969 | { | |
970 | TopoDS_Edge ed =TopoDS::Edge (aShapeA); | |
7fd59977 | 971 | TopoDS_Vertex Va,Vb; |
972 | TopExp::Vertices(ed,Va,Vb ); | |
973 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
974 | gp_Pnt B=BRep_Tool::Pnt(Vb); | |
975 | gp_Vec V (A,B); | |
976 | gp_Dir D (V); | |
977 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
978 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
979 | GetMapOfAIS().Bind (TheAxis,name); | |
0577ae8c | 980 | TheAISContext()->Display (TheAxis, Standard_True); |
7fd59977 | 981 | } |
982 | ||
983 | } | |
984 | ||
985 | // Fonction axispara | |
986 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS) | |
404c8936 | 987 | else if ( !strcasecmp(argv[0], "vaxispara")) |
988 | { | |
989 | if (aShapes.Extent() != 2) | |
990 | { | |
991 | std::cerr << "Error: Wrong number of selected shapes.\n"; | |
992 | return 1; | |
7fd59977 | 993 | } |
404c8936 | 994 | |
995 | const TopoDS_Shape& aShapeA = aShapes.First(); | |
996 | const TopoDS_Shape& aShapeB = aShapes.Last(); | |
997 | if (!(aShapeA.ShapeType() == TopAbs_EDGE | |
998 | && aShapeB.ShapeType() == TopAbs_VERTEX)) | |
999 | { | |
1000 | std::cerr << "Syntax error: You should select face and then vertex.\n"; | |
1001 | return 1; | |
7fd59977 | 1002 | } |
7fd59977 | 1003 | |
404c8936 | 1004 | TopoDS_Edge ed=TopoDS::Edge (aShapeA); |
1005 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB)); | |
7fd59977 | 1006 | TopoDS_Vertex Va,Vc; |
1007 | TopExp::Vertices(ed,Va,Vc ); | |
1008 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
1009 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
1010 | gp_Vec V (A,C); | |
1011 | gp_Dir D (V); | |
1012 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
1013 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
1014 | GetMapOfAIS().Bind (TheAxis,name); | |
0577ae8c | 1015 | TheAISContext()->Display (TheAxis, Standard_True); |
7fd59977 | 1016 | |
1017 | } | |
1018 | ||
1019 | // Fonction axisortho | |
404c8936 | 1020 | else |
1021 | { | |
1022 | if (aShapes.Extent() != 2) | |
1023 | { | |
1024 | std::cerr << "Error: Wrong number of selected shapes.\n"; | |
1025 | return 1; | |
7fd59977 | 1026 | } |
404c8936 | 1027 | |
1028 | const TopoDS_Shape& aShapeA = aShapes.First(); | |
1029 | const TopoDS_Shape& aShapeB = aShapes.Last(); | |
1030 | if (!(aShapeA.ShapeType() == TopAbs_EDGE | |
1031 | && aShapeB.ShapeType() == TopAbs_VERTEX)) | |
1032 | { | |
1033 | std::cerr << "Syntax error: You should select face and then vertex.\n"; | |
1034 | return 1; | |
7fd59977 | 1035 | } |
7fd59977 | 1036 | |
1037 | // Construction de l'axe | |
404c8936 | 1038 | TopoDS_Edge ed=TopoDS::Edge(aShapeA) ; |
1039 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) ); | |
7fd59977 | 1040 | TopoDS_Vertex Va,Vc; |
1041 | TopExp::Vertices(ed,Va,Vc ); | |
1042 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
1043 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
1044 | gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() ); | |
1045 | gp_Vec V (A,E); | |
1046 | gp_Dir D (V); | |
1047 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
1048 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
1049 | GetMapOfAIS().Bind (TheAxis,name); | |
0577ae8c | 1050 | TheAISContext()->Display (TheAxis, Standard_True); |
7fd59977 | 1051 | |
1052 | } | |
1053 | ||
1054 | } | |
1055 | return 0; | |
1056 | } | |
1057 | ||
1058 | ||
1059 | //============================================================================== | |
1060 | // Fonction First click Result | |
161c4476 | 1061 | // |
7fd59977 | 1062 | // vpoint vertex AIS_Point=Vertex |
1063 | // edge AIS_Point=Middle of the edge | |
1064 | //============================================================================== | |
1065 | ||
1066 | //============================================================================== | |
1067 | //function : VPointBuilder | |
1068 | //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge | |
1069 | //Draw arg : vpoint PoinName [Xa] [Ya] [Za] | |
1070 | //============================================================================== | |
1071 | #include <TopoDS_Edge.hxx> | |
1072 | #include <TopoDS_Vertex.hxx> | |
1073 | #include <TopExp.hxx> | |
1074 | #include <AIS_Point.hxx> | |
1075 | #include <Geom_CartesianPoint.hxx> | |
1076 | ||
161c4476 | 1077 | static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1078 | { |
1079 | // Declarations | |
1080 | Standard_Boolean HasArg; | |
1081 | TCollection_AsciiString name; | |
7fd59977 | 1082 | |
1083 | // Verification | |
586db386 | 1084 | if (argc<2 || argc>5 ) {di<<" Syntaxe error\n";return 1;} |
7fd59977 | 1085 | if (argc==5) HasArg=Standard_True; |
1086 | else HasArg=Standard_False; | |
1087 | ||
1088 | name=argv[1]; | |
7fd59977 | 1089 | |
1090 | // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom) | |
1091 | if (HasArg) { | |
1092 | Standard_Real thecoord[3]; | |
1093 | for(Standard_Integer i=0;i<=2;i++) | |
91322f44 | 1094 | thecoord[i]=Draw::Atof(argv[2+i]); |
7fd59977 | 1095 | Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]); |
1096 | Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint ); | |
1097 | GetMapOfAIS().Bind (myAISPoint,name); | |
0577ae8c | 1098 | TheAISContext()->Display (myAISPoint, Standard_True); |
7fd59977 | 1099 | } |
1100 | ||
1101 | // Il n'a pas d'arguments | |
404c8936 | 1102 | else |
1103 | { | |
1104 | TopTools_ListOfShape aShapes; | |
1105 | ViewerTest::GetSelectedShapes (aShapes); | |
1106 | ||
1107 | if (aShapes.Extent() != 1) | |
1108 | { | |
1109 | std::cerr << "Error: Wrong number of selected shapes.\n"; | |
1110 | std::cerr << "\tYou should select one edge or vertex.\n"; | |
1111 | return 1; | |
7fd59977 | 1112 | } |
1113 | ||
404c8936 | 1114 | const TopoDS_Shape& aShapeA = aShapes.First(); |
7fd59977 | 1115 | |
404c8936 | 1116 | if (aShapeA.ShapeType()==TopAbs_VERTEX ) |
1117 | { | |
1118 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(aShapeA ) ); | |
7fd59977 | 1119 | Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A ); |
1120 | Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint ); | |
1121 | GetMapOfAIS().Bind(myAISPoint,name); | |
0577ae8c | 1122 | TheAISContext()->Display (myAISPoint, Standard_True); |
7fd59977 | 1123 | } |
404c8936 | 1124 | else |
1125 | { | |
1126 | TopoDS_Edge myEdge=TopoDS::Edge(aShapeA); | |
7fd59977 | 1127 | TopoDS_Vertex myVertexA,myVertexB; |
1128 | TopExp::Vertices (myEdge ,myVertexA ,myVertexB ); | |
1129 | gp_Pnt A=BRep_Tool::Pnt(myVertexA ); | |
1130 | gp_Pnt B=BRep_Tool::Pnt(myVertexB ); | |
1131 | // M est le milieu de [AB] | |
1132 | Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 ); | |
1133 | Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM ); | |
1134 | GetMapOfAIS().Bind(myAISPointM,name); | |
0577ae8c | 1135 | TheAISContext()->Display (myAISPointM, Standard_True); |
7fd59977 | 1136 | } |
1137 | ||
1138 | } | |
1139 | return 0; | |
1140 | ||
1141 | } | |
1142 | ||
1143 | //============================================================================== | |
ceae62f0 | 1144 | // Function 1st click 2de click 3de click |
7fd59977 | 1145 | // vplane Vertex Vertex Vertex |
1146 | // Vertex Edge | |
1147 | // Edge Vertex | |
1148 | // Face | |
1149 | // vplanepara Face Vertex | |
1150 | // Vertex Face | |
1151 | // vplaneortho Face Edge | |
1152 | // Edge Face | |
1153 | //============================================================================== | |
1154 | ||
1155 | //============================================================================== | |
1156 | //function : VPlaneBuilder | |
ceae62f0 | 1157 | //purpose : Build an AIS_Plane from selected entities or Named AIS components |
9e8804b6 | 1158 | //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity] |
1159 | // [PointName] [PointName] [PointName] [TypeOfSensitivity] | |
1160 | // [PlaneName] [PointName] [TypeOfSensitivity] | |
7fd59977 | 1161 | //============================================================================== |
1162 | ||
35e08fe8 | 1163 | static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/, |
ceae62f0 A |
1164 | Standard_Integer argc, |
1165 | const char** argv) | |
7fd59977 | 1166 | { |
1167 | // Declarations | |
ceae62f0 A |
1168 | Standard_Boolean hasArg; |
1169 | TCollection_AsciiString aName; | |
7fd59977 | 1170 | |
1171 | // Verification | |
9e8804b6 | 1172 | if (argc<2 || argc>6 ) |
ceae62f0 A |
1173 | { |
1174 | std::cout<<" Syntax error\n"; | |
1175 | return 1; | |
1176 | } | |
9e8804b6 | 1177 | if (argc == 6 || argc==5 || argc==4) |
ceae62f0 A |
1178 | hasArg=Standard_True; |
1179 | else | |
1180 | hasArg=Standard_False; | |
7fd59977 | 1181 | |
ceae62f0 | 1182 | aName=argv[1]; |
7fd59977 | 1183 | |
ceae62f0 A |
1184 | // There are some arguments |
1185 | if (hasArg) | |
1186 | { | |
8f521168 | 1187 | Handle(AIS_InteractiveObject) aShapeA; |
1188 | if (!GetMapOfAIS().Find2 (argv[2], aShapeA)) | |
ceae62f0 A |
1189 | { |
1190 | std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n"; | |
1191 | return 1; | |
1192 | } | |
7fd59977 | 1193 | |
ceae62f0 A |
1194 | // The first argument is an AIS_Point |
1195 | if (!aShapeA.IsNull() && | |
1196 | aShapeA->Type()==AIS_KOI_Datum && | |
1197 | aShapeA->Signature()==1) | |
1198 | { | |
1199 | // The second argument must also be an AIS_Point | |
8f521168 | 1200 | Handle(AIS_InteractiveObject) aShapeB; |
1201 | if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB)) | |
ceae62f0 A |
1202 | { |
1203 | std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n"; | |
1204 | return 1; | |
1205 | } | |
ceae62f0 A |
1206 | // If B is not an AIS_Point |
1207 | if (aShapeB.IsNull() || | |
1208 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1209 | { |
ceae62f0 | 1210 | std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n"; |
7fd59977 | 1211 | return 1; |
1212 | } | |
ceae62f0 | 1213 | // The third object is an AIS_Point |
8f521168 | 1214 | Handle(AIS_InteractiveObject) aShapeC; |
1215 | if (!GetMapOfAIS().Find2(argv[4], aShapeC)) | |
ceae62f0 A |
1216 | { |
1217 | std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n"; | |
1218 | return 1; | |
1219 | } | |
ceae62f0 A |
1220 | // If C is not an AIS_Point |
1221 | if (aShapeC.IsNull() || | |
1222 | (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1))) | |
7fd59977 | 1223 | { |
ceae62f0 | 1224 | std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n"; |
7fd59977 | 1225 | return 1; |
1226 | } | |
1227 | ||
ceae62f0 A |
1228 | // Treatment of objects A, B, C |
1229 | // Downcast an AIS_IO to AIS_Point | |
1230 | Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA); | |
1231 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB); | |
1232 | Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC); | |
7fd59977 | 1233 | |
ceae62f0 A |
1234 | Handle(Geom_CartesianPoint ) aCartPointA = |
1235 | Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component()); | |
7fd59977 | 1236 | |
ceae62f0 A |
1237 | Handle(Geom_CartesianPoint ) aCartPointB = |
1238 | Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component()); | |
7fd59977 | 1239 | |
ceae62f0 A |
1240 | Handle(Geom_CartesianPoint ) aCartPointC = |
1241 | Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component()); | |
7fd59977 | 1242 | |
ceae62f0 | 1243 | // Verification that the three points are different |
91322f44 | 1244 | if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() && |
1245 | Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() && | |
1246 | Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion()) | |
ceae62f0 | 1247 | { |
7fd59977 | 1248 | // B=A |
586db386 | 1249 | std::cout<<"vplane error: same points\n";return 1; |
7fd59977 | 1250 | } |
91322f44 | 1251 | if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() && |
1252 | Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() && | |
1253 | Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion()) | |
ceae62f0 | 1254 | { |
7fd59977 | 1255 | // C=A |
586db386 | 1256 | std::cout<<"vplane error: same points\n";return 1; |
7fd59977 | 1257 | } |
91322f44 | 1258 | if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() && |
1259 | Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() && | |
1260 | Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion()) | |
ceae62f0 | 1261 | { |
7fd59977 | 1262 | // C=B |
586db386 | 1263 | std::cout<<"vplane error: same points\n";return 1; |
7fd59977 | 1264 | } |
1265 | ||
ceae62f0 A |
1266 | gp_Pnt A = aCartPointA->Pnt(); |
1267 | gp_Pnt B = aCartPointB->Pnt(); | |
1268 | gp_Pnt C = aCartPointC->Pnt(); | |
7fd59977 | 1269 | |
ceae62f0 | 1270 | // Construction of AIS_Plane |
7fd59977 | 1271 | GC_MakePlane MkPlane (A,B,C); |
ceae62f0 A |
1272 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); |
1273 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane ); | |
1274 | GetMapOfAIS().Bind (anAISPlane,aName ); | |
9e8804b6 | 1275 | if (argc == 6) |
1276 | { | |
1277 | Standard_Integer aType = Draw::Atoi (argv[5]); | |
1278 | if (aType != 0 && aType != 1) | |
1279 | { | |
1280 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1281 | << "Should be one of the following values:\n" | |
1282 | << "0 - Interior\n" | |
1283 | << "1 - Boundary" | |
1284 | << std::endl; | |
1285 | return 1; | |
1286 | } | |
1287 | else | |
1288 | { | |
1289 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1290 | } | |
1291 | } | |
0577ae8c | 1292 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1293 | } |
1294 | ||
ceae62f0 A |
1295 | // The first argument is an AIS_Axis |
1296 | // Creation of a plane orthogonal to the axis through a point | |
1297 | else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) { | |
1298 | // The second argument should be an AIS_Point | |
8f521168 | 1299 | Handle(AIS_InteractiveObject) aShapeB; |
1300 | if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB)) | |
7fd59977 | 1301 | { |
ceae62f0 | 1302 | std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n"; |
7fd59977 | 1303 | return 1; |
1304 | } | |
ceae62f0 A |
1305 | // If B is not an AIS_Point |
1306 | if (aShapeB.IsNull() || | |
1307 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1308 | { |
ceae62f0 | 1309 | std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n"; |
7fd59977 | 1310 | return 1; |
1311 | } | |
1312 | ||
ceae62f0 A |
1313 | // Treatment of objects A and B |
1314 | Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA); | |
1315 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB); | |
7fd59977 | 1316 | |
ceae62f0 A |
1317 | Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component(); |
1318 | Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ; | |
7fd59977 | 1319 | |
ceae62f0 A |
1320 | gp_Ax1 anAxis = aGeomLineA->Position(); |
1321 | Handle(Geom_CartesianPoint) aCartPointB = | |
1322 | Handle(Geom_CartesianPoint)::DownCast(aGeomPointB); | |
7fd59977 | 1323 | |
ceae62f0 A |
1324 | gp_Dir D =anAxis.Direction(); |
1325 | gp_Pnt B = aCartPointB->Pnt(); | |
7fd59977 | 1326 | |
ceae62f0 A |
1327 | // Construction of AIS_Plane |
1328 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D); | |
1329 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B ); | |
1330 | GetMapOfAIS().Bind (anAISPlane,aName ); | |
9e8804b6 | 1331 | if (argc == 5) |
1332 | { | |
1333 | Standard_Integer aType = Draw::Atoi (argv[4]); | |
1334 | if (aType != 0 && aType != 1) | |
1335 | { | |
1336 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1337 | << "Should be one of the following values:\n" | |
1338 | << "0 - Interior\n" | |
1339 | << "1 - Boundary" | |
1340 | << std::endl; | |
1341 | return 1; | |
1342 | } | |
1343 | else | |
1344 | { | |
1345 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1346 | } | |
1347 | } | |
0577ae8c | 1348 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1349 | |
1350 | } | |
ceae62f0 A |
1351 | // The first argumnet is an AIS_Plane |
1352 | // Creation of a plane parallel to the plane passing through the point | |
1353 | else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7) | |
1354 | { | |
1355 | // The second argument should be an AIS_Point | |
8f521168 | 1356 | Handle(AIS_InteractiveObject) aShapeB; |
1357 | if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB)) | |
ceae62f0 A |
1358 | { |
1359 | std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n"; | |
7fd59977 | 1360 | return 1; |
1361 | } | |
ceae62f0 A |
1362 | // B should be an AIS_Point |
1363 | if (aShapeB.IsNull() || | |
1364 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1365 | { |
ceae62f0 | 1366 | std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n"; |
7fd59977 | 1367 | return 1; |
1368 | } | |
1369 | ||
ceae62f0 A |
1370 | // Treatment of objects A and B |
1371 | Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA); | |
1372 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB); | |
7fd59977 | 1373 | |
ceae62f0 A |
1374 | Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component(); |
1375 | Handle(Geom_Point) aGeomPointB = anAISPointB->Component(); | |
7fd59977 | 1376 | |
ceae62f0 A |
1377 | Handle(Geom_CartesianPoint) aCartPointB = |
1378 | Handle(Geom_CartesianPoint)::DownCast(aGeomPointB); | |
1379 | gp_Pnt B= aCartPointB->Pnt(); | |
7fd59977 | 1380 | |
ceae62f0 A |
1381 | // Construction of an AIS_Plane |
1382 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B); | |
1383 | GetMapOfAIS().Bind (anAISPlane, aName); | |
9e8804b6 | 1384 | if (argc == 5) |
1385 | { | |
1386 | Standard_Integer aType = Draw::Atoi (argv[4]); | |
1387 | if (aType != 0 && aType != 1) | |
1388 | { | |
1389 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1390 | << "Should be one of the following values:\n" | |
1391 | << "0 - Interior\n" | |
1392 | << "1 - Boundary" | |
1393 | << std::endl; | |
1394 | return 1; | |
1395 | } | |
1396 | else | |
1397 | { | |
1398 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1399 | } | |
1400 | } | |
0577ae8c | 1401 | TheAISContext()->Display (anAISPlane, Standard_True); |
ceae62f0 A |
1402 | } |
1403 | // Error | |
1404 | else | |
1405 | { | |
1406 | std::cout<<"vplane: error 1st object is not an AIS\n"; | |
1407 | return 1; | |
7fd59977 | 1408 | } |
7fd59977 | 1409 | } |
ceae62f0 A |
1410 | // There are no arguments |
1411 | else | |
1412 | { | |
404c8936 | 1413 | TopTools_ListOfShape aShapes; |
1414 | ViewerTest::GetSelectedShapes (aShapes); | |
1415 | ||
ceae62f0 A |
1416 | // Function vplane |
1417 | // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean ) | |
1418 | if (!strcasecmp(argv[0], "vplane")) | |
1419 | { | |
404c8936 | 1420 | if (aShapes.Extent() < 1 || aShapes.Extent() > 3) |
ceae62f0 | 1421 | { |
404c8936 | 1422 | std::cerr << "Error: Wront number of selected shapes.\n"; |
1423 | std::cerr << "\tYou should one of variant: face, edge and vertex or three vertices.\n"; | |
1424 | return 1; | |
7fd59977 | 1425 | } |
1426 | ||
404c8936 | 1427 | const TopoDS_Shape& aShapeA = aShapes.First(); |
1428 | if (aShapeA.ShapeType() == TopAbs_VERTEX) | |
ceae62f0 | 1429 | { |
404c8936 | 1430 | if (aShapes.Extent() == 2) |
ceae62f0 | 1431 | { |
404c8936 | 1432 | const TopoDS_Shape& aShapeB = aShapes.Last(); |
1433 | if (aShapeB.ShapeType() != TopAbs_EDGE) | |
ceae62f0 | 1434 | { |
404c8936 | 1435 | std::cerr << "Syntax error: Together with vertex should be edge.\n"; |
ceae62f0 | 1436 | return 1; |
7fd59977 | 1437 | } |
7fd59977 | 1438 | |
ceae62f0 A |
1439 | // Verify that the vertex is not on the edge ShapeB |
1440 | TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB); | |
1441 | TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA); | |
7fd59977 | 1442 | |
ceae62f0 A |
1443 | BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB); |
1444 | if (OrthoProj.SquareDistance(1)<Precision::Approximation()) | |
1445 | { | |
1446 | // The vertex is on the edge | |
1447 | std::cout<<" vplane: error point is on the edge\n"; | |
1448 | return 1; | |
1449 | } | |
1450 | else | |
1451 | { | |
ceae62f0 A |
1452 | gp_Pnt A = BRep_Tool::Pnt(aVertA); |
1453 | TopoDS_Vertex aVBa, aVBb; | |
1454 | TopExp::Vertices(anEdgeB ,aVBa ,aVBb); | |
1455 | gp_Pnt aBa = BRep_Tool::Pnt(aVBa); | |
1456 | gp_Pnt aBb = BRep_Tool::Pnt(aVBb); | |
1457 | GC_MakePlane MkPlane (A, aBa, aBb); | |
1458 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1459 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1460 | GetMapOfAIS().Bind (anAISPlane, aName); | |
0577ae8c | 1461 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1462 | } |
7fd59977 | 1463 | } |
404c8936 | 1464 | else if (aShapes.Extent() == 3) |
1465 | { | |
1466 | TopTools_ListOfShape::Iterator anIter (aShapes); | |
1467 | ||
1468 | anIter.Next(); | |
1469 | const TopoDS_Shape& aShapeB = anIter.Value(); | |
1470 | ||
1471 | anIter.Next(); | |
1472 | const TopoDS_Shape& aShapeC = anIter.Value(); | |
1473 | ||
1474 | if (!(aShapeB.ShapeType() == TopAbs_VERTEX | |
1475 | && aShapeC.ShapeType() == TopAbs_VERTEX)) | |
1476 | { | |
1477 | std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n"; | |
1478 | return 1; | |
1479 | } | |
1480 | ||
1481 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA)); | |
1482 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB)); | |
1483 | gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC)); | |
1484 | GC_MakePlane MkPlane(A, B, C); | |
1485 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1486 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1487 | GetMapOfAIS().Bind (anAISPlane, aName); | |
0577ae8c | 1488 | TheAISContext()->Display (anAISPlane, Standard_True); |
404c8936 | 1489 | } |
1490 | else | |
1491 | { | |
1492 | std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n"; | |
1493 | return 1; | |
1494 | } | |
7fd59977 | 1495 | } |
404c8936 | 1496 | else if (aShapeA.ShapeType() == TopAbs_EDGE) |
ceae62f0 | 1497 | { |
404c8936 | 1498 | if (aShapes.Extent() != 2) |
ceae62f0 | 1499 | { |
404c8936 | 1500 | std::cerr << "Error: wrong number of selected shapes.\n"; |
1501 | return 1; | |
1502 | } | |
1503 | ||
1504 | const TopoDS_Shape& aShapeB = aShapes.Last(); | |
1505 | if (aShapeB.ShapeType() != TopAbs_VERTEX) | |
1506 | { | |
1507 | std::cerr << "Syntax error: Together with edge should be vertex.\n"; | |
1508 | return 1; | |
7fd59977 | 1509 | } |
404c8936 | 1510 | |
ceae62f0 A |
1511 | // Check that the vertex aShapeB is not on the edge |
1512 | TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA); | |
1513 | TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB); | |
1514 | ||
1515 | BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA); | |
1516 | if (OrthoProj.SquareDistance(1)<Precision::Approximation()) | |
1517 | { | |
1518 | // The vertex is on the edge | |
1519 | std::cout<<" vplane: error point is on the edge\n"; | |
1520 | return 1; | |
7fd59977 | 1521 | } |
404c8936 | 1522 | |
1523 | gp_Pnt B = BRep_Tool::Pnt(aVertB); | |
1524 | TopoDS_Vertex aVAa, aVAb; | |
1525 | TopExp::Vertices(anEdgeA, aVAa, aVAb); | |
1526 | gp_Pnt Aa = BRep_Tool::Pnt(aVAa); | |
1527 | gp_Pnt Ab = BRep_Tool::Pnt(aVAb); | |
1528 | GC_MakePlane MkPlane (B,Aa,Ab); | |
1529 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1530 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1531 | GetMapOfAIS().Bind (anAISPlane ,aName); | |
0577ae8c | 1532 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1533 | } |
404c8936 | 1534 | else if (aShapeA.ShapeType() == TopAbs_FACE) |
ceae62f0 | 1535 | { |
ceae62f0 A |
1536 | TopoDS_Face aFace = TopoDS::Face(aShapeA); |
1537 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1538 | if (aSurface.GetType()==GeomAbs_Plane) | |
1539 | { | |
1540 | gp_Pln aPlane = aSurface.Plane(); | |
1541 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane); | |
1542 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane); | |
1543 | GetMapOfAIS().Bind (anAISPlane, aName); | |
0577ae8c | 1544 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1545 | } |
ceae62f0 A |
1546 | else |
1547 | { | |
1548 | std::cout<<" vplane: error\n"; | |
1549 | return 1; | |
7fd59977 | 1550 | } |
7fd59977 | 1551 | } |
404c8936 | 1552 | else |
1553 | { | |
1554 | std::cerr << "Syntax error: You should one of variant: face, edge and vertex or three vertices.\n"; | |
1555 | return 1; | |
1556 | } | |
7fd59977 | 1557 | } |
1558 | ||
ceae62f0 | 1559 | // Function vPlanePara |
7fd59977 | 1560 | // =================== |
ceae62f0 A |
1561 | // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt) |
1562 | else if (!strcasecmp(argv[0], "vplanepara")) | |
1563 | { | |
404c8936 | 1564 | if (aShapes.Extent() != 2) |
ceae62f0 | 1565 | { |
404c8936 | 1566 | std::cerr << "Error: Wrong number of selected shapes.\n"; |
1567 | return 1; | |
7fd59977 | 1568 | } |
1569 | ||
404c8936 | 1570 | const TopoDS_Shape* aShapeA = &aShapes.First(); |
1571 | const TopoDS_Shape* aShapeB = &aShapes.Last(); | |
1572 | if (aShapeA->ShapeType() != TopAbs_VERTEX) | |
ceae62f0 | 1573 | { |
404c8936 | 1574 | std::swap (aShapeA, aShapeB); |
1575 | } | |
7fd59977 | 1576 | |
404c8936 | 1577 | if (!(aShapeA->ShapeType() == TopAbs_VERTEX |
1578 | && aShapeB->ShapeType() == TopAbs_FACE)) | |
1579 | { | |
1580 | std::cerr << "Syntax error: you should select face and vertex.\n"; | |
1581 | return 1; | |
1582 | } | |
7fd59977 | 1583 | |
404c8936 | 1584 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA)); |
ceae62f0 | 1585 | |
404c8936 | 1586 | TopoDS_Face aFace = TopoDS::Face(*aShapeB); |
1587 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1588 | if (aSurface.GetType() == GeomAbs_Plane) | |
1589 | { | |
1590 | gp_Pln aPlane = aSurface.Plane(); | |
1591 | // Construct a plane parallel to aGeomPlane through A | |
1592 | aPlane.SetLocation(A); | |
1593 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1594 | Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A); | |
1595 | GetMapOfAIS().Bind (aAISPlane ,aName); | |
0577ae8c | 1596 | TheAISContext()->Display (aAISPlane, Standard_True); |
7fd59977 | 1597 | } |
ceae62f0 A |
1598 | else |
1599 | { | |
404c8936 | 1600 | std::cerr << "Error: Builded surface is not a plane.\n"; |
1601 | return 1; | |
7fd59977 | 1602 | } |
7fd59977 | 1603 | } |
1604 | ||
ceae62f0 | 1605 | // Function vplaneortho |
7fd59977 | 1606 | // ==================== |
ceae62f0 A |
1607 | // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt) |
1608 | else | |
1609 | { | |
404c8936 | 1610 | if (aShapes.Extent() != 2) |
ceae62f0 | 1611 | { |
404c8936 | 1612 | std::cerr << "Error: wrong number of selected shapes.\n"; |
1613 | return 1; | |
7fd59977 | 1614 | } |
1615 | ||
404c8936 | 1616 | const TopoDS_Shape* aShapeA = &aShapes.First(); |
1617 | const TopoDS_Shape* aShapeB = &aShapes.Last(); | |
7fd59977 | 1618 | |
404c8936 | 1619 | if (aShapeA->ShapeType() != TopAbs_EDGE) |
1620 | { | |
1621 | std::swap (aShapeA, aShapeB); | |
1622 | } | |
7fd59977 | 1623 | |
404c8936 | 1624 | if (!(aShapeA->ShapeType() == TopAbs_EDGE |
1625 | && aShapeB->ShapeType() == TopAbs_FACE)) | |
1626 | { | |
1627 | std::cerr << "Error: you should select edge and face.\n"; | |
1628 | return 1; | |
1629 | } | |
ceae62f0 | 1630 | |
404c8936 | 1631 | // Construction of plane |
1632 | TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA); | |
1633 | TopoDS_Vertex aVAa, aVAb; | |
1634 | TopExp::Vertices(anEdgeA, aVAa, aVAb); | |
1635 | gp_Pnt Aa = BRep_Tool::Pnt(aVAa); | |
1636 | gp_Pnt Ab = BRep_Tool::Pnt(aVAb); | |
1637 | gp_Vec ab (Aa,Ab); | |
1638 | ||
1639 | gp_Dir Dab (ab); | |
1640 | // Creation of rotation axis | |
1641 | gp_Ax1 aRotAxis (Aa,Dab); | |
1642 | ||
1643 | TopoDS_Face aFace = TopoDS::Face(*aShapeB); | |
1644 | // The edge must be parallel to the face | |
1645 | BRepExtrema_ExtPF aHeightA (aVAa, aFace); | |
1646 | BRepExtrema_ExtPF aHeightB (aVAb, aFace); | |
1647 | // Compare to heights | |
1648 | if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1))) | |
1649 | >Precision::Confusion()) | |
1650 | { | |
1651 | // the edge is not parallel to the face | |
1652 | std::cout<<" vplaneortho error: the edge is not parallel to the face\n"; | |
1653 | return 1; | |
1654 | } | |
1655 | // the edge is OK | |
1656 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1657 | if (aSurface.GetType()==GeomAbs_Plane) | |
1658 | { | |
1659 | gp_Pln aPlane = aSurface.Plane(); | |
1660 | // It rotates a half turn round the axis of rotation | |
1661 | aPlane.Rotate(aRotAxis , M_PI/2); | |
1662 | ||
1663 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1664 | // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge) | |
1665 | gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 ); | |
1666 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle); | |
1667 | GetMapOfAIS().Bind (anAISPlane, aName); | |
0577ae8c | 1668 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1669 | } |
ceae62f0 A |
1670 | else |
1671 | { | |
404c8936 | 1672 | std::cout<<" vplaneortho: error\n"; |
1673 | return 1; | |
7fd59977 | 1674 | } |
7fd59977 | 1675 | } |
7fd59977 | 1676 | } |
1677 | return 0; | |
7fd59977 | 1678 | } |
1679 | ||
f3889691 | 1680 | //=============================================================================================== |
1681 | //function : VChangePlane | |
1682 | //purpose : | |
1683 | //=============================================================================================== | |
1684 | static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) | |
1685 | { | |
1686 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
1687 | if (aContextAIS.IsNull()) | |
1688 | { | |
1689 | std::cout << theArgVec[0] << "AIS context is not available.\n"; | |
1690 | return 1; | |
1691 | } | |
1692 | ||
1693 | if (theArgsNb < 3 || theArgsNb > 11) | |
1694 | { | |
1695 | std::cerr << theArgVec[0] | |
1696 | << ": incorrect number of command arguments.\n" | |
1697 | << "Type help for more information.\n"; | |
1698 | return 1; | |
1699 | } | |
1700 | ||
1701 | TCollection_AsciiString aName (theArgVec[1]); | |
1702 | ||
1703 | Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName) | |
1704 | ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName)) | |
1705 | : NULL; | |
1706 | ||
1707 | if ( aPlane.IsNull() ) | |
1708 | { | |
1709 | std::cout << theArgVec[0] | |
1710 | << ": there is no interactive plane with the given name." | |
1711 | << "Type help for more information.\n"; | |
1712 | return 1; | |
1713 | } | |
1714 | ||
1715 | Standard_Real aCenterX = aPlane->Center().X(); | |
1716 | Standard_Real aCenterY = aPlane->Center().Y(); | |
1717 | Standard_Real aCenterZ = aPlane->Center().Z(); | |
1718 | ||
1719 | Standard_Real aDirX = aPlane->Component()->Axis().Direction().X(); | |
1720 | Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y(); | |
1721 | Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z(); | |
1722 | ||
1723 | Standard_Real aSizeX = 0.0; | |
1724 | Standard_Real aSizeY = 0.0; | |
1725 | aPlane->Size (aSizeX, aSizeY); | |
1726 | Standard_Boolean isUpdate = Standard_True; | |
1727 | ||
1728 | TCollection_AsciiString aPName, aPValue; | |
1729 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
1730 | { | |
1731 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; | |
1732 | TCollection_AsciiString anArgCase = anArg; | |
1733 | anArgCase.UpperCase(); | |
1734 | if (ViewerTest::SplitParameter (anArg, aPName, aPValue)) | |
1735 | { | |
1736 | aPName.UpperCase(); | |
1737 | if (aPName.IsEqual ("X")) | |
1738 | { | |
1739 | aCenterX = aPValue.RealValue(); | |
1740 | } | |
1741 | else if (aPName.IsEqual ("Y")) | |
1742 | { | |
1743 | aCenterY = aPValue.RealValue(); | |
1744 | } | |
1745 | else if (aPName.IsEqual ("Z")) | |
1746 | { | |
1747 | aCenterZ = aPValue.RealValue(); | |
1748 | } | |
1749 | else if (aPName.IsEqual ("DX")) | |
1750 | { | |
1751 | aDirX = aPValue.RealValue(); | |
1752 | } | |
1753 | else if (aPName.IsEqual ("DY")) | |
1754 | { | |
1755 | aDirY = aPValue.RealValue(); | |
1756 | } | |
1757 | else if (aPName.IsEqual ("DZ")) | |
1758 | { | |
1759 | aDirZ = aPValue.RealValue(); | |
1760 | } | |
1761 | else if (aPName.IsEqual ("SX")) | |
1762 | { | |
1763 | aSizeX = aPValue.RealValue(); | |
1764 | } | |
1765 | else if (aPName.IsEqual ("SY")) | |
1766 | { | |
1767 | aSizeY = aPValue.RealValue(); | |
1768 | } | |
1769 | } | |
1770 | else if (anArg.IsEqual ("NOUPDATE")) | |
1771 | { | |
1772 | isUpdate = Standard_False; | |
1773 | } | |
1774 | } | |
1775 | ||
1776 | gp_Dir aDirection (aDirX, aDirY, aDirZ); | |
1777 | gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ); | |
1778 | aPlane->SetCenter (aCenterPnt); | |
1779 | aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection)); | |
1780 | aPlane->SetSize (aSizeX, aSizeY); | |
1781 | ||
f751596e | 1782 | aContextAIS->Update (aPlane, isUpdate); |
f3889691 | 1783 | |
1784 | return 0; | |
1785 | } | |
7fd59977 | 1786 | |
1787 | //============================================================================== | |
1788 | // Fonction vline | |
1789 | // --------------- Uniquement par parametre. Pas de selection dans le viewer. | |
1790 | //============================================================================== | |
1791 | ||
1792 | //============================================================================== | |
1793 | //function : VLineBuilder | |
161c4476 | 1794 | //purpose : Build an AIS_Line |
7fd59977 | 1795 | //Draw arg : vline LineName [AIS_PointName] [AIS_PointName] |
1796 | // [Xa] [Ya] [Za] [Xb] [Yb] [Zb] | |
1797 | //============================================================================== | |
1798 | #include <Geom_CartesianPoint.hxx> | |
1799 | #include <AIS_Line.hxx> | |
1800 | ||
1801 | ||
161c4476 | 1802 | static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1803 | { |
7fd59977 | 1804 | // Verifications |
586db386 | 1805 | if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; } |
7fd59977 | 1806 | |
1807 | // On recupere les parametres | |
1808 | Handle(AIS_InteractiveObject) theShapeA; | |
1809 | Handle(AIS_InteractiveObject) theShapeB; | |
1810 | ||
1811 | // Parametres: AIS_Point AIS_Point | |
1812 | // =============================== | |
1813 | if (argc==4) { | |
8f521168 | 1814 | GetMapOfAIS().Find2 (argv[2], theShapeA); |
7fd59977 | 1815 | // On verifie que c'est bien une AIS_Point |
1816 | if (!theShapeA.IsNull() && | |
1817 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) { | |
1818 | // on recupere le deuxieme AIS_Point | |
8f521168 | 1819 | GetMapOfAIS().Find2 (argv[3], theShapeB); |
1820 | if (theShapeB.IsNull() || | |
7fd59977 | 1821 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) |
1822 | { | |
586db386 | 1823 | di <<"vline error: wrong type of 2de argument.\n"; |
7fd59977 | 1824 | return 1; |
1825 | } | |
1826 | } | |
586db386 | 1827 | else {di <<"vline error: wrong type of 1st argument.\n";return 1; } |
7fd59977 | 1828 | // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus |
c5f3a425 | 1829 | Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA); |
1830 | Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB); | |
7fd59977 | 1831 | |
1832 | Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component(); | |
c5f3a425 | 1833 | Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA); |
7fd59977 | 1834 | // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ; |
1835 | ||
1836 | Handle(Geom_Point ) myGeomPointB= theAISPointB->Component(); | |
c5f3a425 | 1837 | Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB); |
7fd59977 | 1838 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ; |
1839 | ||
1840 | if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) { | |
1841 | // B=A | |
586db386 | 1842 | di<<"vline error: same points\n";return 1; |
7fd59977 | 1843 | } |
1844 | // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB) | |
1845 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1846 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
0577ae8c | 1847 | TheAISContext()->Display (theAISLine, Standard_True); |
7fd59977 | 1848 | |
1849 | } | |
1850 | ||
1851 | // Parametres 6 Reals | |
1852 | // ================== | |
1853 | ||
1854 | else if (argc==8) { | |
161c4476 | 1855 | // On verifie que les deux points ne sont pas confondus |
7fd59977 | 1856 | |
1857 | Standard_Real coord[6]; | |
1858 | for(Standard_Integer i=0;i<=2;i++){ | |
91322f44 | 1859 | coord[i]=Draw::Atof(argv[2+i]); |
1860 | coord[i+3]=Draw::Atof(argv[5+i]); | |
7fd59977 | 1861 | } |
1862 | ||
1863 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] ); | |
1864 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] ); | |
1865 | ||
1866 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1867 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
0577ae8c | 1868 | TheAISContext()->Display (theAISLine, Standard_True); |
7fd59977 | 1869 | |
1870 | } | |
1871 | ||
1872 | // Pas de parametres: Selection dans le viewer. | |
1873 | // ============================================ | |
1874 | ||
404c8936 | 1875 | else |
1876 | { | |
1877 | TopTools_ListOfShape aShapes; | |
1878 | ViewerTest::GetSelectedShapes (aShapes); | |
1879 | if (aShapes.Extent() != 2) | |
1880 | { | |
1881 | std::cerr << "Error: wrong number of selected shapes.\n"; | |
1882 | return 1; | |
7fd59977 | 1883 | } |
1884 | ||
404c8936 | 1885 | const TopoDS_Shape& aShapeA = aShapes.First(); |
1886 | const TopoDS_Shape& aShapeB = aShapes.Last(); | |
7fd59977 | 1887 | |
404c8936 | 1888 | if (!(aShapeA.ShapeType() == TopAbs_VERTEX |
1889 | && aShapeB.ShapeType() == TopAbs_VERTEX)) | |
1890 | { | |
1891 | std::cerr << "Error: you should select two different vertex.\n"; | |
1892 | return 1; | |
1893 | } | |
7fd59977 | 1894 | |
404c8936 | 1895 | // Construction de la line |
1896 | gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA)); | |
1897 | gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB)); | |
7fd59977 | 1898 | |
404c8936 | 1899 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A); |
1900 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B); | |
7fd59977 | 1901 | |
404c8936 | 1902 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); |
1903 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
0577ae8c | 1904 | TheAISContext()->Display (theAISLine, Standard_True); |
7fd59977 | 1905 | } |
1906 | ||
1907 | return 0; | |
1908 | } | |
1909 | ||
329843e2 A |
1910 | //============================================================================== |
1911 | // class : FilledCircle | |
1912 | // purpose : creates filled circle based on AIS_InteractiveObject | |
1913 | // and Geom_Circle. | |
1914 | // This class is used to check method Matches() of class | |
1915 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True, | |
1916 | // because none of AIS classes provides creation of | |
1917 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True | |
1918 | // (look method ComputeSelection() ) | |
1919 | //============================================================================== | |
1920 | ||
1921 | Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
1922 | { | |
1923 | gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.))); | |
1924 | gp_Circ aCirc(anAxes, theRadius); | |
1925 | Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc); | |
1926 | return aCircle; | |
1927 | } | |
1928 | ||
329843e2 A |
1929 | class FilledCircle : public AIS_InteractiveObject |
1930 | { | |
1931 | public: | |
1932 | // CASCADE RTTI | |
92efcf78 | 1933 | DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject); |
329843e2 A |
1934 | |
1935 | FilledCircle(gp_Pnt theCenter, Standard_Real theRadius); | |
1936 | FilledCircle(Handle(Geom_Circle) theCircle); | |
1937 | ||
1938 | private: | |
1939 | TopoDS_Face ComputeFace(); | |
1940 | ||
1941 | // Virtual methods implementation | |
1942 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
1943 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 1944 | const Standard_Integer theMode) Standard_OVERRIDE; |
329843e2 A |
1945 | |
1946 | void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, | |
79104795 | 1947 | const Standard_Integer theMode) Standard_OVERRIDE; |
329843e2 A |
1948 | |
1949 | protected: | |
1950 | Handle(Geom_Circle) myCircle; | |
1951 | Standard_Boolean myFilledStatus; | |
1952 | ||
1953 | }; | |
1954 | ||
329843e2 A |
1955 | |
1956 | FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
1957 | { | |
1958 | myCircle = CreateCircle(theCenter, theRadius); | |
1959 | myFilledStatus = Standard_True; | |
1960 | } | |
1961 | ||
1962 | FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle) | |
1963 | { | |
1964 | myCircle = theCircle; | |
1965 | myFilledStatus = Standard_True; | |
1966 | } | |
1967 | ||
1968 | TopoDS_Face FilledCircle::ComputeFace() | |
1969 | { | |
1970 | // Create edge from myCircle | |
1971 | BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ()); | |
1972 | TopoDS_Edge anEdge = anEdgeMaker.Edge(); | |
1973 | ||
1974 | // Create wire from anEdge | |
1975 | BRepBuilderAPI_MakeWire aWireMaker(anEdge); | |
1976 | TopoDS_Wire aWire = aWireMaker.Wire(); | |
1977 | ||
1978 | // Create face from aWire | |
1979 | BRepBuilderAPI_MakeFace aFaceMaker(aWire); | |
1980 | TopoDS_Face aFace = aFaceMaker.Face(); | |
1981 | ||
1982 | return aFace; | |
1983 | } | |
1984 | ||
857ffd5e | 1985 | void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/, |
1986 | const Handle(Prs3d_Presentation) &thePresentation, | |
329843e2 A |
1987 | const Standard_Integer theMode) |
1988 | { | |
1989 | thePresentation->Clear(); | |
1990 | ||
1991 | TopoDS_Face aFace = ComputeFace(); | |
1992 | ||
1993 | if (aFace.IsNull()) return; | |
1994 | if (theMode != 0) return; | |
1995 | ||
1996 | StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer); | |
1997 | } | |
1998 | ||
857ffd5e | 1999 | void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection, |
35e08fe8 | 2000 | const Standard_Integer /*theMode*/) |
329843e2 A |
2001 | { |
2002 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this); | |
2003 | Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner, | |
2004 | myCircle, myFilledStatus); | |
2005 | theSelection->Add(aSensitiveCircle); | |
2006 | } | |
7fd59977 | 2007 | |
2008 | //============================================================================== | |
2009 | // Fonction vcircle | |
2010 | // ----------------- Uniquement par parametre. Pas de selection dans le viewer. | |
2011 | //============================================================================== | |
2012 | ||
2013 | //============================================================================== | |
2014 | //function : VCircleBuilder | |
161c4476 | 2015 | //purpose : Build an AIS_Circle |
329843e2 A |
2016 | //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled |
2017 | // PointName PointName PointName IsFilled | |
7fd59977 | 2018 | //============================================================================== |
329843e2 A |
2019 | |
2020 | void DisplayCircle (Handle (Geom_Circle) theGeomCircle, | |
2021 | TCollection_AsciiString theName, | |
2022 | Standard_Boolean isFilled) | |
2023 | { | |
2024 | Handle(AIS_InteractiveObject) aCircle; | |
2025 | if (isFilled) | |
2026 | { | |
2027 | aCircle = new FilledCircle(theGeomCircle); | |
2028 | } | |
2029 | else | |
2030 | { | |
2031 | aCircle = new AIS_Circle(theGeomCircle); | |
9e8804b6 | 2032 | Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False); |
329843e2 A |
2033 | } |
2034 | ||
2035 | // Check if there is an object with given name | |
2036 | // and remove it from context | |
2037 | if (GetMapOfAIS().IsBound2(theName)) | |
2038 | { | |
8f521168 | 2039 | Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName); |
329843e2 A |
2040 | TheAISContext()->Remove(anInterObj, Standard_False); |
2041 | GetMapOfAIS().UnBind2(theName); | |
2042 | } | |
2043 | ||
2044 | // Bind the circle to its name | |
2045 | GetMapOfAIS().Bind(aCircle, theName); | |
2046 | ||
2047 | // Display the circle | |
0577ae8c | 2048 | TheAISContext()->Display (aCircle, Standard_True); |
329843e2 A |
2049 | |
2050 | } | |
7fd59977 | 2051 | |
35e08fe8 | 2052 | static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv) |
7fd59977 | 2053 | { |
329843e2 A |
2054 | // Verification of the arguments |
2055 | if (argc>6 || argc<2) | |
2056 | { | |
2057 | std::cout << "vcircle error: expect 4 arguments.\n"; | |
2058 | return 1; // TCL_ERROR | |
2059 | } | |
7fd59977 | 2060 | |
329843e2 A |
2061 | // There are all arguments |
2062 | if (argc == 6) | |
2063 | { | |
2064 | // Get arguments | |
2065 | TCollection_AsciiString aName(argv[1]); | |
dde68833 | 2066 | Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0; |
329843e2 | 2067 | |
8f521168 | 2068 | Handle(AIS_InteractiveObject) theShapeA, theShapeB; |
2069 | GetMapOfAIS().Find2 (argv[2], theShapeA); | |
2070 | GetMapOfAIS().Find2 (argv[3], theShapeB); | |
7fd59977 | 2071 | |
2072 | // Arguments: AIS_Point AIS_Point AIS_Point | |
2073 | // ======================================== | |
329843e2 | 2074 | if (!theShapeA.IsNull() && !theShapeB.IsNull() && |
7fd59977 | 2075 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) |
2076 | { | |
329843e2 A |
2077 | if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) |
2078 | { | |
2079 | std::cout << "vcircle error: 2d argument is unexpected to be a point.\n"; | |
2080 | return 1; // TCL_ERROR | |
7fd59977 | 2081 | } |
329843e2 | 2082 | // The third object must be a point |
8f521168 | 2083 | Handle(AIS_InteractiveObject) theShapeC; |
2084 | GetMapOfAIS().Find2 (argv[4], theShapeC); | |
7fd59977 | 2085 | if (theShapeC.IsNull() || |
329843e2 A |
2086 | theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) |
2087 | { | |
2088 | std::cout << "vcircle error: 3d argument is unexpected to be a point.\n"; | |
2089 | return 1; // TCL_ERROR | |
2090 | } | |
7fd59977 | 2091 | // tag |
329843e2 A |
2092 | // Verify that the three points are different |
2093 | Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA); | |
2094 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
2095 | Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC); | |
2096 | ||
2097 | Handle(Geom_Point) myGeomPointA = theAISPointA->Component(); | |
2098 | Handle(Geom_CartesianPoint) myCartPointA = | |
2099 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointA); | |
2100 | ||
2101 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
2102 | Handle(Geom_CartesianPoint) myCartPointB = | |
2103 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
2104 | ||
2105 | Handle(Geom_Point) myGeomPointC = theAISPointC->Component(); | |
2106 | Handle(Geom_CartesianPoint) myCartPointC = | |
2107 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointC); | |
7fd59977 | 2108 | |
2109 | // Test A=B | |
91322f44 | 2110 | if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() && |
2111 | Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() && | |
2112 | Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2113 | { |
2114 | std::cout << "vcircle error: Same points.\n"; | |
2115 | return 1; // TCL_ERROR | |
7fd59977 | 2116 | } |
2117 | // Test A=C | |
91322f44 | 2118 | if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() && |
2119 | Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
2120 | Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2121 | { |
2122 | std::cout << "vcircle error: Same points.\n"; | |
2123 | return 1; // TCL_ERROR | |
7fd59977 | 2124 | } |
2125 | // Test B=C | |
91322f44 | 2126 | if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() && |
2127 | Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
2128 | Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2129 | { |
2130 | std::cout << "vcircle error: Same points.\n"; | |
2131 | return 1;// TCL_ERROR | |
7fd59977 | 2132 | } |
329843e2 A |
2133 | // Construction of the circle |
2134 | GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(), | |
2135 | myCartPointB->Pnt(), myCartPointC->Pnt() ); | |
2136 | Handle (Geom_Circle) theGeomCircle; | |
2137 | try | |
2138 | { | |
2139 | theGeomCircle = Cir.Value(); | |
2140 | } | |
a738b534 | 2141 | catch (StdFail_NotDone const&) |
329843e2 A |
2142 | { |
2143 | std::cout << "vcircle error: can't create circle\n"; | |
2144 | return -1; // TCL_ERROR | |
2145 | } | |
2146 | ||
2147 | DisplayCircle(theGeomCircle, aName, isFilled); | |
7fd59977 | 2148 | } |
2149 | ||
329843e2 | 2150 | // Arguments: AIS_Plane AIS_Point Real |
7fd59977 | 2151 | // =================================== |
329843e2 A |
2152 | else if (theShapeA->Type() == AIS_KOI_Datum && |
2153 | theShapeA->Signature() == 7 ) | |
2154 | { | |
2155 | if (theShapeB->Type() != AIS_KOI_Datum || | |
2156 | theShapeB->Signature() != 1 ) | |
2157 | { | |
2158 | std::cout << "vcircle error: 2d element is a unexpected to be a point.\n"; | |
2159 | return 1; // TCL_ERROR | |
2160 | } | |
623c29a5 | 2161 | // Check that the radius is >= 0 |
91322f44 | 2162 | if (Draw::Atof(argv[4]) <= 0 ) |
329843e2 A |
2163 | { |
2164 | std::cout << "vcircle error: the radius must be >=0.\n"; | |
2165 | return 1; // TCL_ERROR | |
7fd59977 | 2166 | } |
7fd59977 | 2167 | |
329843e2 A |
2168 | // Recover the normal to the plane |
2169 | Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA); | |
2170 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
7fd59977 | 2171 | |
329843e2 A |
2172 | Handle(Geom_Plane) myGeomPlane = theAISPlane->Component(); |
2173 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
2174 | Handle(Geom_CartesianPoint) myCartPointB = | |
2175 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
7fd59977 | 2176 | |
2177 | gp_Pln mygpPlane = myGeomPlane->Pln(); | |
2178 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
2179 | gp_Dir theDir = thegpAxe.Direction(); | |
329843e2 | 2180 | gp_Pnt theCenter = myCartPointB->Pnt(); |
91322f44 | 2181 | Standard_Real TheR = Draw::Atof(argv[4]); |
329843e2 A |
2182 | GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR); |
2183 | Handle (Geom_Circle) theGeomCircle; | |
2184 | try | |
2185 | { | |
2186 | theGeomCircle = Cir.Value(); | |
2187 | } | |
a738b534 | 2188 | catch (StdFail_NotDone const&) |
329843e2 A |
2189 | { |
2190 | std::cout << "vcircle error: can't create circle\n"; | |
2191 | return -1; // TCL_ERROR | |
2192 | } | |
2193 | ||
2194 | DisplayCircle(theGeomCircle, aName, isFilled); | |
7fd59977 | 2195 | |
2196 | } | |
2197 | ||
2198 | // Error | |
329843e2 A |
2199 | else |
2200 | { | |
2201 | std::cout << "vcircle error: 1st argument is a unexpected type.\n"; | |
2202 | return 1; // TCL_ERROR | |
7fd59977 | 2203 | } |
2204 | ||
2205 | } | |
329843e2 | 2206 | // No arguments: selection in the viewer |
7fd59977 | 2207 | // ========================================= |
329843e2 A |
2208 | else |
2209 | { | |
2210 | // Get the name of the circle | |
2211 | TCollection_AsciiString aName(argv[1]); | |
7fd59977 | 2212 | |
404c8936 | 2213 | TopTools_ListOfShape aShapes; |
2214 | ViewerTest::GetSelectedShapes (aShapes); | |
2215 | if (aShapes.Extent() != 3 && aShapes.Extent() != 2) | |
329843e2 | 2216 | { |
404c8936 | 2217 | std::cerr << "Error: Wrong number of selected shapes.\n"; |
2218 | return 1; | |
7fd59977 | 2219 | } |
2220 | ||
404c8936 | 2221 | const TopoDS_Shape& aShapeA = aShapes.First(); |
2222 | if (aShapeA.ShapeType() == TopAbs_VERTEX ) | |
329843e2 | 2223 | { |
404c8936 | 2224 | if (aShapes.Extent() != 3) |
329843e2 | 2225 | { |
404c8936 | 2226 | std::cerr << "Error: wrong number of selected shapes.\n"; |
2227 | return 1; | |
2228 | } | |
7fd59977 | 2229 | |
404c8936 | 2230 | TopTools_ListOfShape::Iterator anIter (aShapes); |
2231 | ||
2232 | anIter.Next(); | |
2233 | const TopoDS_Shape& aShapeB = anIter.Value(); | |
2234 | ||
2235 | anIter.Next(); | |
2236 | const TopoDS_Shape& aShapeC = anIter.Value(); | |
329843e2 A |
2237 | |
2238 | // Get isFilled | |
2239 | Standard_Boolean isFilled; | |
2240 | std::cout << "Enter filled status (0 or 1)\n"; | |
2241 | cin >> isFilled; | |
7fd59977 | 2242 | |
329843e2 | 2243 | // Construction of the circle |
404c8936 | 2244 | gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA)); |
2245 | gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB)); | |
2246 | gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC)); | |
329843e2 A |
2247 | |
2248 | GC_MakeCircle Cir = GC_MakeCircle (A, B, C); | |
2249 | Handle (Geom_Circle) theGeomCircle; | |
2250 | try | |
2251 | { | |
2252 | theGeomCircle = Cir.Value(); | |
2253 | } | |
a738b534 | 2254 | catch (StdFail_NotDone const&) |
329843e2 A |
2255 | { |
2256 | std::cout << "vcircle error: can't create circle\n"; | |
2257 | return -1; // TCL_ERROR | |
2258 | } | |
7fd59977 | 2259 | |
329843e2 | 2260 | DisplayCircle(theGeomCircle, aName, isFilled); |
7fd59977 | 2261 | |
2262 | } | |
404c8936 | 2263 | else if (aShapeA.ShapeType() == TopAbs_FACE) |
329843e2 | 2264 | { |
404c8936 | 2265 | const TopoDS_Shape& aShapeB = aShapes.Last(); |
7fd59977 | 2266 | |
329843e2 A |
2267 | // Recover the radius |
2268 | Standard_Real theRad; | |
2269 | do | |
2270 | { | |
2271 | std::cout << " Enter the value of the radius:\n"; | |
2272 | cin >> theRad; | |
2273 | } while (theRad <= 0); | |
2274 | ||
2275 | // Get filled status | |
2276 | Standard_Boolean isFilled; | |
2277 | std::cout << "Enter filled status (0 or 1)\n"; | |
2278 | cin >> isFilled; | |
7fd59977 | 2279 | |
329843e2 | 2280 | // Recover the normal to the plane. tag |
404c8936 | 2281 | TopoDS_Face myFace = TopoDS::Face(aShapeA); |
329843e2 A |
2282 | BRepAdaptor_Surface mySurface (myFace, Standard_False); |
2283 | gp_Pln myPlane = mySurface.Plane(); | |
2284 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane); | |
7fd59977 | 2285 | gp_Pln mygpPlane = theGeomPlane->Pln(); |
2286 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
2287 | gp_Dir theDir = thegpAxe.Direction(); | |
2288 | ||
329843e2 | 2289 | // Recover the center |
404c8936 | 2290 | gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB)); |
7fd59977 | 2291 | |
623c29a5 | 2292 | // Construct the circle |
329843e2 A |
2293 | GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad); |
2294 | Handle (Geom_Circle) theGeomCircle; | |
2295 | try | |
2296 | { | |
2297 | theGeomCircle = Cir.Value(); | |
2298 | } | |
a738b534 | 2299 | catch (StdFail_NotDone const&) |
329843e2 A |
2300 | { |
2301 | std::cout << "vcircle error: can't create circle\n"; | |
2302 | return -1; // TCL_ERROR | |
2303 | } | |
7fd59977 | 2304 | |
329843e2 | 2305 | DisplayCircle(theGeomCircle, aName, isFilled); |
7fd59977 | 2306 | } |
404c8936 | 2307 | else |
2308 | { | |
2309 | std::cerr << "Error: You should select face and vertex or three vertices.\n"; | |
2310 | return 1; | |
2311 | } | |
7fd59977 | 2312 | } |
2313 | ||
2314 | return 0; | |
2315 | } | |
2316 | ||
29e2c6d2 | 2317 | //======================================================================= |
7fd59977 | 2318 | //function : VDrawText |
29e2c6d2 | 2319 | //purpose : |
2320 | //======================================================================= | |
2321 | static int VDrawText (Draw_Interpretor& theDI, | |
2322 | Standard_Integer theArgsNb, | |
2323 | const char** theArgVec) | |
7fd59977 | 2324 | { |
29e2c6d2 | 2325 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
2326 | if (theArgsNb < 3) | |
fe551aef | 2327 | { |
29e2c6d2 | 2328 | std::cout << "Error: wrong number of arguments! See usage:\n"; |
2329 | theDI.PrintHelp (theArgVec[0]); | |
2330 | return 1; | |
2331 | } | |
2332 | else if (aContext.IsNull()) | |
2333 | { | |
2334 | std::cout << "Error: no active view!\n"; | |
2335 | return 1; | |
fe551aef | 2336 | } |
2337 | ||
29e2c6d2 | 2338 | Standard_Integer anArgIt = 1; |
2339 | TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True); | |
2340 | TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True); | |
2341 | Handle(AIS_TextLabel) aTextPrs; | |
2342 | ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView()); | |
7fd59977 | 2343 | |
1beb58d7 | 2344 | Standard_Boolean isNewPrs = Standard_False; |
29e2c6d2 | 2345 | if (GetMapOfAIS().IsBound2 (aName)) |
7fd59977 | 2346 | { |
1beb58d7 | 2347 | aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName)); |
29e2c6d2 | 2348 | } |
1beb58d7 | 2349 | |
2350 | if (aTextPrs.IsNull()) | |
29e2c6d2 | 2351 | { |
1beb58d7 | 2352 | isNewPrs = Standard_True; |
29e2c6d2 | 2353 | aTextPrs = new AIS_TextLabel(); |
2354 | aTextPrs->SetFont ("Courier"); | |
7fd59977 | 2355 | } |
13a22457 | 2356 | |
29e2c6d2 | 2357 | aTextPrs->SetText (aText); |
13a22457 | 2358 | |
778cd667 | 2359 | Handle(Graphic3d_TransformPers) aTrsfPers; |
61b0191c | 2360 | Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL; |
2361 | ||
ce01ec26 | 2362 | Standard_Boolean aHasPlane = Standard_False; |
2363 | gp_Dir aNormal; | |
2364 | gp_Dir aDirection; | |
2365 | gp_Pnt aPos; | |
2366 | ||
29e2c6d2 | 2367 | for (; anArgIt < theArgsNb; ++anArgIt) |
161c4476 | 2368 | { |
29e2c6d2 | 2369 | TCollection_AsciiString aParam (theArgVec[anArgIt]); |
2370 | aParam.LowerCase(); | |
2371 | ||
2372 | if (anAutoUpdater.parseRedrawMode (aParam)) | |
13a22457 | 2373 | { |
29e2c6d2 | 2374 | continue; |
13a22457 | 2375 | } |
29e2c6d2 | 2376 | else if (aParam == "-pos" |
2377 | || aParam == "-position") | |
2378 | { | |
2379 | if (anArgIt + 3 >= theArgsNb) | |
2380 | { | |
2381 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2382 | return 1; | |
2383 | } | |
7fd59977 | 2384 | |
29e2c6d2 | 2385 | aPos.SetX (Draw::Atof (theArgVec[++anArgIt])); |
2386 | aPos.SetY (Draw::Atof (theArgVec[++anArgIt])); | |
2387 | aPos.SetZ (Draw::Atof (theArgVec[++anArgIt])); | |
2388 | aTextPrs->SetPosition (aPos); | |
2389 | } | |
2390 | else if (aParam == "-color") | |
2391 | { | |
2392 | if (anArgIt + 1 >= theArgsNb) | |
2393 | { | |
2394 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2395 | return 1; | |
2396 | } | |
7fd59977 | 2397 | |
29e2c6d2 | 2398 | TCollection_AsciiString aColor (theArgVec[anArgIt + 1]); |
2399 | Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK; | |
2400 | if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor)) | |
2401 | { | |
2402 | anArgIt += 1; | |
2403 | aTextPrs->SetColor (aNameOfColor); | |
2404 | continue; | |
2405 | } | |
2406 | else if (anArgIt + 3 >= theArgsNb) | |
2407 | { | |
2408 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2409 | return 1; | |
2410 | } | |
7fd59977 | 2411 | |
29e2c6d2 | 2412 | TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]); |
2413 | TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]); | |
2414 | if (!aColor.IsRealValue() | |
2415 | || !aGreen.IsRealValue() | |
2416 | || !aBlue.IsRealValue()) | |
2417 | { | |
2418 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
2419 | return 1; | |
2420 | } | |
7fd59977 | 2421 | |
29e2c6d2 | 2422 | const Graphic3d_Vec3d anRGB (aColor.RealValue(), |
2423 | aGreen.RealValue(), | |
2424 | aBlue.RealValue()); | |
7fd59977 | 2425 | |
29e2c6d2 | 2426 | aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB)); |
2427 | anArgIt += 3; | |
2428 | } | |
2429 | else if (aParam == "-halign") | |
2430 | { | |
2431 | if (++anArgIt >= theArgsNb) | |
2432 | { | |
2433 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2434 | return 1; | |
2435 | } | |
13a22457 | 2436 | |
29e2c6d2 | 2437 | TCollection_AsciiString aType (theArgVec[anArgIt]); |
2438 | aType.LowerCase(); | |
2439 | if (aType == "left") | |
2440 | { | |
2441 | aTextPrs->SetHJustification (Graphic3d_HTA_LEFT); | |
2442 | } | |
2443 | else if (aType == "center") | |
2444 | { | |
2445 | aTextPrs->SetHJustification (Graphic3d_HTA_CENTER); | |
2446 | } | |
2447 | else if (aType == "right") | |
2448 | { | |
2449 | aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT); | |
2450 | } | |
2451 | else | |
2452 | { | |
2453 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
2454 | return 1; | |
2455 | } | |
2456 | } | |
2457 | else if (aParam == "-valign") | |
2458 | { | |
2459 | if (++anArgIt >= theArgsNb) | |
2460 | { | |
2461 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2462 | return 1; | |
2463 | } | |
2464 | ||
2465 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
2466 | aType.LowerCase(); | |
2467 | if (aType == "top") | |
2468 | { | |
2469 | aTextPrs->SetVJustification (Graphic3d_VTA_TOP); | |
2470 | } | |
2471 | else if (aType == "center") | |
2472 | { | |
2473 | aTextPrs->SetVJustification (Graphic3d_VTA_CENTER); | |
2474 | } | |
2475 | else if (aType == "bottom") | |
2476 | { | |
2477 | aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM); | |
2478 | } | |
ac84fcf6 | 2479 | else if (aType == "topfirstline") |
2480 | { | |
2481 | aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE); | |
2482 | } | |
29e2c6d2 | 2483 | else |
2484 | { | |
2485 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
2486 | return 1; | |
2487 | } | |
2488 | } | |
2489 | else if (aParam == "-angle") | |
2490 | { | |
2491 | if (++anArgIt >= theArgsNb) | |
2492 | { | |
2493 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2494 | return 1; | |
2495 | } | |
13a22457 | 2496 | |
29e2c6d2 | 2497 | aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0)); |
2498 | } | |
2499 | else if (aParam == "-zoom") | |
2500 | { | |
2501 | if (++anArgIt >= theArgsNb) | |
2502 | { | |
2503 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2504 | return 1; | |
2505 | } | |
13a22457 | 2506 | |
29e2c6d2 | 2507 | aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1); |
2508 | } | |
2509 | else if (aParam == "-height") | |
2510 | { | |
2511 | if (++anArgIt >= theArgsNb) | |
2512 | { | |
2513 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2514 | return 1; | |
2515 | } | |
13a22457 | 2516 | |
29e2c6d2 | 2517 | aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt])); |
2518 | } | |
2519 | else if (aParam == "-aspect") | |
2520 | { | |
2521 | if (++anArgIt >= theArgsNb) | |
2522 | { | |
2523 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2524 | return 1; | |
2525 | } | |
13a22457 | 2526 | |
29e2c6d2 | 2527 | TCollection_AsciiString anOption (theArgVec[anArgIt]); |
2528 | anOption.LowerCase(); | |
5b377041 | 2529 | Font_FontAspect aFontAspect = Font_FA_Undefined; |
2530 | if (!parseFontStyle (anOption, aFontAspect)) | |
29e2c6d2 | 2531 | { |
5b377041 | 2532 | std::cout << "Error: unknown font aspect '" << anOption << "'.\n"; |
2533 | return 1; | |
29e2c6d2 | 2534 | } |
5b377041 | 2535 | aTextPrs->SetFontAspect (aFontAspect); |
29e2c6d2 | 2536 | } |
2537 | else if (aParam == "-font") | |
2538 | { | |
2539 | if (++anArgIt >= theArgsNb) | |
2540 | { | |
2541 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2542 | return 1; | |
2543 | } | |
13a22457 | 2544 | |
29e2c6d2 | 2545 | aTextPrs->SetFont (theArgVec[anArgIt]); |
2546 | } | |
ce01ec26 | 2547 | else if (aParam == "-plane") |
2548 | { | |
2549 | if (anArgIt + 6 >= theArgsNb) | |
2550 | { | |
2551 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2552 | return 1; | |
2553 | } | |
2554 | ||
2555 | Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]); | |
2556 | Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]); | |
2557 | Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]); | |
2558 | aNormal.SetCoord (aX, aY, aZ); | |
2559 | ||
2560 | aX = Draw::Atof (theArgVec[++anArgIt]); | |
2561 | aY = Draw::Atof (theArgVec[++anArgIt]); | |
2562 | aZ = Draw::Atof (theArgVec[++anArgIt]); | |
2563 | aDirection.SetCoord (aX, aY, aZ); | |
2564 | ||
2565 | aHasPlane = Standard_True; | |
2566 | } | |
3f1eb0ab | 2567 | else if (aParam == "-flipping") |
2568 | { | |
2569 | aTextPrs->SetFlipping (Standard_True); | |
2570 | } | |
61b0191c | 2571 | else if (aParam == "-disptype" |
2572 | || aParam == "-displaytype") | |
2573 | { | |
2574 | if (++anArgIt >= theArgsNb) | |
2575 | { | |
2576 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2577 | return 1; | |
2578 | } | |
2579 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
2580 | aType.LowerCase(); | |
2581 | if (aType == "subtitle") | |
2582 | aDisplayType = Aspect_TODT_SUBTITLE; | |
2583 | else if (aType == "decal") | |
2584 | aDisplayType = Aspect_TODT_DEKALE; | |
2585 | else if (aType == "blend") | |
2586 | aDisplayType = Aspect_TODT_BLEND; | |
2587 | else if (aType == "dimension") | |
2588 | aDisplayType = Aspect_TODT_DIMENSION; | |
2589 | else if (aType == "normal") | |
2590 | aDisplayType = Aspect_TODT_NORMAL; | |
3cbd0a8e | 2591 | else if (aType == "shadow") |
2592 | aDisplayType = Aspect_TODT_SHADOW; | |
61b0191c | 2593 | else |
2594 | { | |
2595 | std::cout << "Error: wrong display type '" << aType << "'.\n"; | |
2596 | return 1; | |
2597 | } | |
2598 | } | |
2599 | else if (aParam == "-subcolor" | |
2600 | || aParam == "-subtitlecolor") | |
2601 | { | |
2602 | if (anArgIt + 1 >= theArgsNb) | |
2603 | { | |
2604 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2605 | return 1; | |
2606 | } | |
2607 | ||
2608 | TCollection_AsciiString aColor (theArgVec[anArgIt + 1]); | |
2609 | Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK; | |
2610 | if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor)) | |
2611 | { | |
2612 | anArgIt += 1; | |
2613 | aTextPrs->SetColorSubTitle (aNameOfColor); | |
2614 | continue; | |
2615 | } | |
2616 | else if (anArgIt + 3 >= theArgsNb) | |
2617 | { | |
2618 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2619 | return 1; | |
2620 | } | |
2621 | ||
2622 | TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]); | |
2623 | TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]); | |
2624 | if (!aColor.IsRealValue() | |
2625 | || !aGreen.IsRealValue() | |
2626 | || !aBlue.IsRealValue()) | |
2627 | { | |
2628 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
2629 | return 1; | |
2630 | } | |
2631 | ||
2632 | const Graphic3d_Vec3d anRGB (aColor.RealValue(), | |
2633 | aGreen.RealValue(), | |
2634 | aBlue.RealValue()); | |
2635 | ||
2636 | aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB)); | |
2637 | anArgIt += 3; | |
2638 | } | |
2639 | else if (aParam == "-2d") | |
2640 | { | |
778cd667 | 2641 | aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d); |
61b0191c | 2642 | } |
2643 | else if (aParam == "-trsfperspos" | |
2644 | || aParam == "-perspos") | |
2645 | { | |
2646 | if (anArgIt + 2 >= theArgsNb) | |
2647 | { | |
2648 | std::cerr << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2649 | return 1; | |
2650 | } | |
2651 | ||
2652 | TCollection_AsciiString aX (theArgVec[++anArgIt]); | |
2653 | TCollection_AsciiString aY (theArgVec[++anArgIt]); | |
2654 | TCollection_AsciiString aZ = "0"; | |
2655 | if (!aX.IsIntegerValue() | |
2656 | || !aY.IsIntegerValue()) | |
2657 | { | |
2658 | std::cerr << "Error: wrong syntax at '" << aParam << "'.\n"; | |
2659 | return 1; | |
2660 | } | |
2661 | if (anArgIt + 1 < theArgsNb) | |
2662 | { | |
2663 | TCollection_AsciiString aTemp = theArgVec[anArgIt + 1]; | |
2664 | if (aTemp.IsIntegerValue()) | |
2665 | { | |
2666 | aZ = aTemp; | |
2667 | ++anArgIt; | |
2668 | } | |
2669 | } | |
778cd667 | 2670 | |
2671 | aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue())); | |
61b0191c | 2672 | } |
29e2c6d2 | 2673 | else |
2674 | { | |
2675 | std::cout << "Error: unknown argument '" << aParam << "'\n"; | |
2676 | return 1; | |
2677 | } | |
13a22457 S |
2678 | } |
2679 | ||
ce01ec26 | 2680 | if (aHasPlane) |
2681 | { | |
2682 | aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection)); | |
2683 | } | |
2684 | ||
284c9238 | 2685 | aTextPrs->SetDisplayType (aDisplayType); |
2686 | ||
778cd667 | 2687 | if (!aTrsfPers.IsNull()) |
61b0191c | 2688 | { |
778cd667 | 2689 | aContext->SetTransformPersistence (aTextPrs, aTrsfPers); |
61b0191c | 2690 | aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD); |
ce01ec26 | 2691 | if (aTextPrs->Position().Z() != 0) |
61b0191c | 2692 | { |
ce01ec26 | 2693 | aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0)); |
61b0191c | 2694 | } |
2695 | } | |
778cd667 | 2696 | else if (!aTextPrs->TransformPersistence().IsNull()) |
61b0191c | 2697 | { |
778cd667 | 2698 | aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)()); |
61b0191c | 2699 | } |
1beb58d7 | 2700 | |
2701 | if (isNewPrs) | |
2702 | { | |
2703 | ViewerTest::Display (aName, aTextPrs, Standard_False); | |
2704 | } | |
2705 | else | |
2706 | { | |
2707 | aContext->Redisplay (aTextPrs, Standard_False, Standard_True); | |
2708 | } | |
161c4476 | 2709 | return 0; |
7fd59977 | 2710 | } |
2711 | ||
2712 | #include <math.h> | |
2713 | #include <gp_Pnt.hxx> | |
2714 | #include <Graphic3d_ArrayOfPoints.hxx> | |
2715 | #include <Graphic3d_ArrayOfPrimitives.hxx> | |
7fd59977 | 2716 | #include <Graphic3d_ArrayOfTriangles.hxx> |
2717 | #include <Poly_Array1OfTriangle.hxx> | |
2718 | #include <Poly_Triangle.hxx> | |
2719 | #include <Poly_Triangulation.hxx> | |
2720 | #include <TColgp_Array1OfPnt.hxx> | |
2721 | #include <TShort_Array1OfShortReal.hxx> | |
2722 | #include <TShort_HArray1OfShortReal.hxx> | |
2723 | ||
2724 | #include <AIS_Triangulation.hxx> | |
5ad8c033 | 2725 | #include <StdPrs_ToolTriangulatedShape.hxx> |
7fd59977 | 2726 | #include <Poly_Connect.hxx> |
2727 | #include <TColgp_Array1OfDir.hxx> | |
2728 | #include <Graphic3d_GraphicDriver.hxx> | |
2729 | ||
7fd59977 | 2730 | #include <TColStd_Array1OfInteger.hxx> |
2731 | #include <TColStd_HArray1OfInteger.hxx> | |
2732 | #include <Prs3d_ShadingAspect.hxx> | |
2733 | #include <Graphic3d_MaterialAspect.hxx> | |
2734 | #include <Graphic3d_AspectFillArea3d.hxx> | |
2735 | ||
2736 | #include <BRepPrimAPI_MakeCylinder.hxx> | |
2737 | #include <TopoDS_Shape.hxx> | |
2738 | #include <TopExp_Explorer.hxx> | |
2739 | #include <TopAbs.hxx> | |
2740 | #include <StdSelect_ShapeTypeFilter.hxx> | |
ec357c5c | 2741 | #include <AIS_InteractiveObject.hxx> |
7fd59977 | 2742 | |
2743 | ||
2744 | //=============================================================================================== | |
2745 | //function : CalculationOfSphere | |
2746 | //author : psn | |
2747 | //purpose : Create a Sphere | |
2748 | //=============================================================================================== | |
2749 | ||
161c4476 | 2750 | Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z , |
7fd59977 | 2751 | int res , |
2752 | double Radius ){ | |
2753 | double mRadius = Radius; | |
2754 | double mCenter[3] = {X,Y,Z}; | |
2755 | int mThetaResolution; | |
2756 | int mPhiResolution; | |
2757 | double mStartTheta = 0;//StartTheta; | |
2758 | double mEndTheta = 360;//EndTheta; | |
2759 | double mStartPhi = 0;//StartPhi; | |
2760 | double mEndPhi = 180;//EndPhi; | |
2761 | res = res < 4 ? 4 : res; | |
2762 | ||
2763 | mThetaResolution = res; | |
2764 | mPhiResolution = res; | |
2765 | ||
2766 | int i, j; | |
2767 | int jStart, jEnd, numOffset; | |
7fd59977 | 2768 | double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius; |
2769 | double startTheta, endTheta, startPhi, endPhi; | |
2770 | int base, numPoles=0, thetaResolution, phiResolution; | |
2771 | ||
2772 | int pts[3]; | |
2773 | int piece = -1; | |
2774 | int numPieces = 1; | |
2775 | if ( numPieces > mThetaResolution ) { | |
2776 | numPieces = mThetaResolution; | |
2777 | } | |
2778 | ||
2779 | int localThetaResolution = mThetaResolution; | |
2780 | double localStartTheta = mStartTheta; | |
2781 | double localEndTheta = mEndTheta; | |
2782 | ||
2783 | while ( localEndTheta < localStartTheta ) { | |
2784 | localEndTheta += 360.0; | |
2785 | } | |
2786 | ||
2787 | deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution; | |
2788 | ||
2789 | // Change the ivars based on pieces. | |
2790 | int start, end; | |
2791 | start = piece * localThetaResolution / numPieces; | |
2792 | end = (piece+1) * localThetaResolution / numPieces; | |
2793 | localEndTheta = localStartTheta + (double)(end) * deltaTheta; | |
2794 | localStartTheta = localStartTheta + (double)(start) * deltaTheta; | |
2795 | localThetaResolution = end - start; | |
2796 | ||
7fd59977 | 2797 | // Create north pole if needed |
2798 | int number_point = 0; | |
2799 | int number_pointArray = 0; | |
2800 | ||
2801 | if ( mStartPhi <= 0.0 ) { | |
2802 | number_pointArray++; | |
2803 | numPoles++; | |
2804 | } | |
2805 | if ( mEndPhi >= 180.0 ) { | |
2806 | number_pointArray++; | |
2807 | numPoles++; | |
2808 | } | |
161c4476 | 2809 | |
7fd59977 | 2810 | // Check data, determine increments, and convert to radians |
2811 | startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta); | |
c6541a0c | 2812 | startTheta *= M_PI / 180.0; |
7fd59977 | 2813 | endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta); |
c6541a0c | 2814 | endTheta *= M_PI / 180.0; |
7fd59977 | 2815 | |
2816 | ||
2817 | startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi); | |
c6541a0c | 2818 | startPhi *= M_PI / 180.0; |
7fd59977 | 2819 | endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi); |
c6541a0c | 2820 | endPhi *= M_PI / 180.0; |
7fd59977 | 2821 | |
2822 | phiResolution = mPhiResolution - numPoles; | |
2823 | deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1); | |
2824 | thetaResolution = localThetaResolution; | |
2825 | if ( fabs(localStartTheta - localEndTheta) < 360.0 ) { | |
2826 | ++localThetaResolution; | |
2827 | } | |
2828 | deltaTheta = (endTheta - startTheta) / thetaResolution; | |
2829 | ||
2830 | jStart = ( mStartPhi <= 0.0 ? 1 : 0); | |
2831 | jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution); | |
2832 | ||
2833 | // Create intermediate points | |
2834 | for ( i = 0; i < localThetaResolution; i++ ) { | |
2835 | for ( j = jStart; j < jEnd; j++ ) { | |
2836 | number_pointArray++; | |
2837 | } | |
2838 | } | |
2839 | ||
2840 | //Generate mesh connectivity | |
2841 | base = phiResolution * localThetaResolution; | |
2842 | ||
2843 | int number_triangle = 0 ; | |
2844 | if ( mStartPhi <= 0.0 ) { // around north pole | |
2845 | number_triangle += localThetaResolution; | |
2846 | } | |
161c4476 | 2847 | |
7fd59977 | 2848 | if ( mEndPhi >= 180.0 ) { // around south pole |
2849 | number_triangle += localThetaResolution; | |
2850 | } | |
2851 | ||
2852 | // bands in-between poles | |
2853 | for ( i=0; i < localThetaResolution; i++){ | |
2854 | for ( j=0; j < (phiResolution-1); j++){ | |
2855 | number_triangle +=2; | |
2856 | } | |
2857 | } | |
2858 | ||
2859 | Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false); | |
2860 | TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes(); | |
2861 | Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles(); | |
2862 | ||
2863 | if ( mStartPhi <= 0.0 ){ | |
2864 | x[0] = mCenter[0]; | |
2865 | x[1] = mCenter[1]; | |
2866 | x[2] = mCenter[2] + mRadius; | |
2867 | PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2])); | |
2868 | } | |
2869 | ||
2870 | // Create south pole if needed | |
2871 | if ( mEndPhi >= 180.0 ){ | |
2872 | x[0] = mCenter[0]; | |
2873 | x[1] = mCenter[1]; | |
2874 | x[2] = mCenter[2] - mRadius; | |
2875 | PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2])); | |
2876 | } | |
2877 | ||
2878 | number_point = 3; | |
2879 | for ( i=0; i < localThetaResolution; i++){ | |
c6541a0c | 2880 | theta = localStartTheta * M_PI / 180.0 + i*deltaTheta; |
7fd59977 | 2881 | for ( j = jStart; j < jEnd; j++){ |
2882 | phi = startPhi + j*deltaPhi; | |
2883 | radius = mRadius * sin((double)phi); | |
2884 | n[0] = radius * cos((double)theta); | |
2885 | n[1] = radius * sin((double)theta); | |
2886 | n[2] = mRadius * cos((double)phi); | |
2887 | x[0] = n[0] + mCenter[0]; | |
2888 | x[1] = n[1] + mCenter[1]; | |
2889 | x[2] = n[2] + mCenter[2]; | |
2890 | PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2])); | |
2891 | number_point++; | |
2892 | } | |
2893 | } | |
2894 | ||
2895 | numPoles = 3; | |
2896 | number_triangle = 1; | |
2897 | if ( mStartPhi <= 0.0 ){// around north pole | |
2898 | for (i=0; i < localThetaResolution; i++){ | |
2899 | pts[0] = phiResolution*i + numPoles; | |
2900 | pts[1] = (phiResolution*(i+1) % base) + numPoles; | |
2901 | pts[2] = 1; | |
2902 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2903 | number_triangle++; | |
2904 | } | |
2905 | } | |
161c4476 | 2906 | |
7fd59977 | 2907 | if ( mEndPhi >= 180.0 ){ // around south pole |
2908 | numOffset = phiResolution - 1 + numPoles; | |
2909 | for (i=0; i < localThetaResolution; i++){ | |
2910 | pts[0] = phiResolution*i + numOffset; | |
2911 | pts[2] = ((phiResolution*(i+1)) % base) + numOffset; | |
2912 | pts[1] = numPoles - 1; | |
2913 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2914 | number_triangle++; | |
2915 | } | |
2916 | } | |
2917 | ||
2918 | // bands in-between poles | |
161c4476 | 2919 | |
7fd59977 | 2920 | for (i=0; i < localThetaResolution; i++){ |
2921 | for (j=0; j < (phiResolution-1); j++){ | |
2922 | pts[0] = phiResolution*i + j + numPoles; | |
2923 | pts[1] = pts[0] + 1; | |
2924 | pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1; | |
2925 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2926 | number_triangle++; | |
2927 | pts[1] = pts[2]; | |
2928 | pts[2] = pts[1] - 1; | |
2929 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2930 | number_triangle++; | |
2931 | } | |
2932 | } | |
2933 | ||
2934 | Poly_Connect* pc = new Poly_Connect(polyTriangulation); | |
2935 | ||
2936 | Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3); | |
2937 | ||
2938 | Standard_Integer index[3]; | |
2939 | Standard_Real Tol = Precision::Confusion(); | |
2940 | ||
2941 | gp_Dir Nor; | |
2942 | for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) { | |
2943 | gp_XYZ eqPlan(0, 0, 0); | |
2944 | for ( pc->Initialize(i); pc->More(); pc->Next()) { | |
2945 | pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]); | |
2946 | gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord()); | |
2947 | gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord()); | |
2948 | gp_XYZ vv = v1^v2; | |
2949 | Standard_Real mod = vv.Modulus(); | |
2950 | if(mod < Tol) continue; | |
2951 | eqPlan += vv/mod; | |
2952 | } | |
2953 | ||
2954 | Standard_Real modmax = eqPlan.Modulus(); | |
2955 | ||
161c4476 | 2956 | if(modmax > Tol) |
7fd59977 | 2957 | Nor = gp_Dir(eqPlan); |
161c4476 | 2958 | else |
7fd59977 | 2959 | Nor = gp_Dir(0., 0., 1.); |
51740958 | 2960 | |
2961 | Standard_Integer k = (i - PointsOfArray.Lower()) * 3; | |
2962 | Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X()); | |
2963 | Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y()); | |
2964 | Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z()); | |
7fd59977 | 2965 | } |
2966 | ||
2967 | delete pc; | |
2968 | polyTriangulation->SetNormals(Normals); | |
2969 | ||
2970 | return polyTriangulation; | |
2971 | } | |
2972 | ||
2973 | //=============================================================================================== | |
2974 | //function : VDrawSphere | |
2975 | //author : psn | |
2976 | //purpose : Create an AIS shape. | |
7fd59977 | 2977 | //=============================================================================================== |
35e08fe8 | 2978 | static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv) |
161c4476 K |
2979 | { |
2980 | // check for errors | |
2981 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
2982 | if (aContextAIS.IsNull()) | |
2983 | { | |
2984 | std::cout << "Call vinit before!\n"; | |
2985 | return 1; | |
2986 | } | |
2987 | else if (argc < 3) | |
2988 | { | |
2989 | std::cout << "Use: " << argv[0] | |
58655684 | 2990 | << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n"; |
161c4476 K |
2991 | return 1; |
2992 | } | |
7fd59977 | 2993 | |
161c4476 K |
2994 | // read the arguments |
2995 | TCollection_AsciiString aShapeName (argv[1]); | |
91322f44 | 2996 | Standard_Integer aResolution = Draw::Atoi (argv[2]); |
2997 | Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0; | |
2998 | Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0; | |
2999 | Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0; | |
3000 | Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0; | |
b7cd4ba7 | 3001 | Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False; |
3002 | Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True; | |
7fd59977 | 3003 | |
161c4476 | 3004 | // remove AIS object with given name from map |
208e6839 | 3005 | VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)()); |
161c4476 | 3006 | |
b7cd4ba7 | 3007 | if (toPrintInfo) |
3008 | std::cout << "Compute Triangulation...\n"; | |
161c4476 K |
3009 | Handle(AIS_Triangulation) aShape |
3010 | = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ, | |
3011 | aResolution, | |
3012 | aRadius)); | |
3013 | Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length(); | |
3014 | Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length(); | |
3015 | ||
161c4476 K |
3016 | // stupid initialization of Green color in RGBA space as integer |
3017 | // probably wrong for big-endian CPUs | |
dcc17419 | 3018 | const Graphic3d_Vec4ub aColor (0, 255, 0, 0); |
161c4476 K |
3019 | |
3020 | // setup colors array per vertex | |
3021 | Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints); | |
3022 | for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId) | |
3023 | { | |
6a657c92 | 3024 | aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData())); |
7fd59977 | 3025 | } |
161c4476 K |
3026 | aShape->SetColors (aColorArray); |
3027 | ||
3028 | // show statistics | |
3029 | Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
3030 | Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
3031 | Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha | |
3032 | Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint | |
3033 | Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4; | |
3034 | Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize; | |
3035 | aTotalSize >>= 20; //MB | |
3036 | aNormalsSize >>= 20; | |
3037 | aColorsSize >>= 20; | |
3038 | aTrianglesSize >>= 20; | |
3039 | aPolyConnectSize >>= 20; | |
b7cd4ba7 | 3040 | if (toPrintInfo) |
3041 | { | |
3042 | std::cout << "NumberOfPoints: " << aNumberPoints << "\n" | |
3043 | << "NumberOfTriangles: " << aNumberTriangles << "\n" | |
3044 | << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n" | |
3045 | << "Amount of memory for colors: " << aColorsSize << " Mb\n" | |
3046 | << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n" | |
3047 | << "Amount of graphic card memory required: " << aTotalSize << " Mb\n"; | |
3048 | } | |
7fd59977 | 3049 | |
3050 | // Setting material properties, very important for desirable visual result! | |
161c4476 | 3051 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC); |
4e1bc39a | 3052 | aMat.SetAmbient (0.2f); |
3053 | aMat.SetSpecular (0.5f); | |
161c4476 K |
3054 | Handle(Graphic3d_AspectFillArea3d) anAspect |
3055 | = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, | |
3056 | Quantity_NOC_RED, | |
3057 | Quantity_NOC_YELLOW, | |
3058 | Aspect_TOL_SOLID, | |
3059 | 1.0, | |
3060 | aMat, | |
3061 | aMat); | |
7fd59977 | 3062 | Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect(); |
2a332745 | 3063 | anAspect->SetDrawEdges (toShowEdges); |
161c4476 K |
3064 | aShAsp->SetAspect (anAspect); |
3065 | aShape->Attributes()->SetShadingAspect (aShAsp); | |
7fd59977 | 3066 | |
208e6839 | 3067 | VDisplayAISObject (aShapeName, aShape); |
7fd59977 | 3068 | return 0; |
3069 | } | |
3070 | ||
3fc57801 | 3071 | //============================================================================= |
3072 | //function : VComputeHLR | |
3073 | //purpose : | |
3074 | //============================================================================= | |
3075 | ||
c60ec7f5 | 3076 | static int VComputeHLR (Draw_Interpretor& , |
3077 | Standard_Integer theArgNb, | |
3078 | const char** theArgVec) | |
3fc57801 | 3079 | { |
c60ec7f5 | 3080 | TCollection_AsciiString aShapeName, aHlrName; |
3081 | TopoDS_Shape aSh; | |
3fc57801 | 3082 | gp_Pnt anEye; |
3083 | gp_Dir aDir; | |
3084 | gp_Ax2 aProjAx; | |
c60ec7f5 | 3085 | bool hasViewDirArg = false; |
3086 | Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo; | |
3087 | bool toShowTangentEdges = false, toShowHiddenEdges = false; | |
3088 | int aNbIsolines = 0; | |
3089 | if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext()) | |
3fc57801 | 3090 | { |
3091 | gp_Dir aRight; | |
c60ec7f5 | 3092 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3fc57801 | 3093 | Standard_Integer aWidth, aHeight; |
3094 | Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ; | |
3095 | Standard_Real aRightX, aRightY, aRightZ; | |
3096 | aView->Window()->Size (aWidth, aHeight); | |
3097 | ||
3098 | aView->ConvertWithProj (aWidth, aHeight/2, | |
3099 | aRightX, aRightY, aRightZ, | |
3100 | aDirX, aDirY, aDirZ); | |
3fc57801 | 3101 | aView->ConvertWithProj (aWidth/2, aHeight/2, |
3102 | aCentX, aCentY, aCentZ, | |
3103 | aDirX, aDirY, aDirZ); | |
3104 | ||
3105 | anEye.SetCoord (-aCentX, -aCentY, -aCentZ); | |
3106 | aDir.SetCoord (-aDirX, -aDirY, -aDirZ); | |
3107 | aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ); | |
3108 | aProjAx.SetLocation (anEye); | |
3109 | aProjAx.SetDirection (aDir); | |
3110 | aProjAx.SetXDirection (aRight); | |
3111 | } | |
c60ec7f5 | 3112 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
3113 | { | |
3114 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); | |
3115 | anArgCase.LowerCase(); | |
3116 | if (anArgIter + 1 < theArgNb | |
3117 | && (anArgCase == "-algotype" | |
3118 | || anArgCase == "-algo" | |
3119 | || anArgCase == "-type")) | |
3120 | { | |
3121 | TCollection_AsciiString anArgNext (theArgVec[++anArgIter]); | |
3122 | anArgNext.LowerCase(); | |
3123 | if (anArgNext == "polyalgo") | |
3124 | { | |
3125 | anAlgoType = Prs3d_TOH_PolyAlgo; | |
3126 | } | |
3127 | else if (anArgNext == "algo") | |
3128 | { | |
3129 | anAlgoType = Prs3d_TOH_Algo; | |
3130 | } | |
3131 | else | |
3132 | { | |
3133 | std::cout << "Syntax error: unknown algo type '" << anArgNext << "'\n"; | |
3134 | return 1; | |
3135 | } | |
3136 | } | |
3137 | else if (anArgCase == "-showhiddenedges" | |
3138 | || anArgCase == "-hiddenedges" | |
3139 | || anArgCase == "-hidden") | |
3140 | { | |
3141 | toShowHiddenEdges = true; | |
3142 | if (anArgIter + 1 < theArgNb | |
3143 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges)) | |
3144 | { | |
3145 | ++anArgIter; | |
3146 | } | |
3147 | } | |
3148 | else if (anArgCase == "-showtangentedges" | |
3149 | || anArgCase == "-tangentedges" | |
3150 | || anArgCase == "-tangent") | |
3151 | { | |
3152 | toShowTangentEdges = true; | |
3153 | if (anArgIter + 1 < theArgNb | |
3154 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toShowTangentEdges)) | |
3155 | { | |
3156 | ++anArgIter; | |
3157 | } | |
3158 | } | |
3159 | else if (anArgIter + 1 < theArgNb | |
3160 | && (anArgCase == "-nbiso" | |
3161 | || anArgCase == "-nbisolines")) | |
3162 | { | |
3163 | aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]); | |
3164 | } | |
3165 | else if (aSh.IsNull()) | |
3166 | { | |
3167 | aSh = DBRep::Get (theArgVec[anArgIter]); | |
3168 | aShapeName = theArgVec[anArgIter]; | |
3169 | if (aSh.IsNull()) | |
3170 | { | |
3171 | BRep_Builder aBrepBuilder; | |
3172 | BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder); | |
3173 | if (aSh.IsNull()) | |
3174 | { | |
3175 | std::cout << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found\n"; | |
3176 | return 1; | |
3177 | } | |
3178 | } | |
3179 | } | |
3180 | else if (aHlrName.IsEmpty()) | |
3181 | { | |
3182 | aHlrName = theArgVec[anArgIter]; | |
3183 | } | |
3184 | else if (!hasViewDirArg | |
3185 | && anArgIter + 8 < theArgNb) | |
3186 | { | |
3187 | hasViewDirArg = true; | |
3188 | gp_Dir anUp; | |
3189 | anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2])); | |
3190 | aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5])); | |
3191 | anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8])); | |
3192 | aProjAx.SetLocation (anEye); | |
3193 | aProjAx.SetDirection (aDir); | |
3194 | aProjAx.SetYDirection (anUp); | |
3195 | anArgIter += 8; | |
3196 | } | |
3197 | else | |
3198 | { | |
3199 | std::cout << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'\n"; | |
3200 | return 1; | |
3201 | } | |
3202 | } | |
3fc57801 | 3203 | |
c60ec7f5 | 3204 | if (aHlrName.IsEmpty() || aSh.IsNull() |
3205 | || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg)) | |
3206 | { | |
3207 | std::cout << "Syntax error: wrong number of arguments\n"; | |
3208 | return 1; | |
3209 | } | |
3fc57801 | 3210 | |
c60ec7f5 | 3211 | HLRAlgo_Projector aProjector (aProjAx); |
3212 | TopoDS_Shape aVisible[6]; | |
3213 | TopoDS_Shape aHidden[6]; | |
3214 | if (anAlgoType == Prs3d_TOH_PolyAlgo) | |
3215 | { | |
3216 | Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo(); | |
3217 | aPolyAlgo->Projector (aProjector); | |
3218 | aPolyAlgo->Load (aSh); | |
3219 | aPolyAlgo->Update(); | |
3fc57801 | 3220 | |
c60ec7f5 | 3221 | HLRBRep_PolyHLRToShape aHLRToShape; |
3222 | aHLRToShape.Update (aPolyAlgo); | |
3fc57801 | 3223 | |
c60ec7f5 | 3224 | aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound(); |
3225 | aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines | |
3226 | aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound(); | |
3227 | if (toShowTangentEdges) | |
3228 | { | |
3229 | aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound(); | |
3230 | } | |
3231 | if (toShowHiddenEdges) | |
3232 | { | |
3233 | aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound(); | |
3234 | aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound(); | |
3235 | aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound(); | |
3236 | if (toShowTangentEdges) | |
3237 | { | |
3238 | aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound(); | |
3239 | } | |
3240 | } | |
3241 | } | |
3242 | else | |
3fc57801 | 3243 | { |
c60ec7f5 | 3244 | Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo(); |
3245 | aHlrAlgo->Add (aSh, aNbIsolines); | |
3246 | aHlrAlgo->Projector (aProjector); | |
3247 | aHlrAlgo->Update(); | |
3248 | aHlrAlgo->Hide(); | |
3249 | ||
3250 | HLRBRep_HLRToShape aHLRToShape (aHlrAlgo); | |
3251 | aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound(); | |
3252 | aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); | |
3253 | aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound(); | |
3254 | if (toShowTangentEdges) | |
3255 | { | |
3256 | aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound(); | |
3257 | } | |
3258 | aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound(); | |
3259 | ||
3260 | if (toShowHiddenEdges) | |
3261 | { | |
3262 | aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound(); | |
3263 | aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound(); | |
3264 | aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound(); | |
3265 | if (toShowTangentEdges) | |
3266 | { | |
3267 | aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound(); | |
3268 | } | |
3269 | aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound(); | |
3270 | } | |
3271 | // extract 3d | |
3272 | //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True); | |
3273 | //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d(); | |
3fc57801 | 3274 | } |
c60ec7f5 | 3275 | |
3276 | TopoDS_Compound aCompRes, aCompVis, aCompHid; | |
3277 | BRep_Builder aBuilder; | |
3278 | aBuilder.MakeCompound (aCompVis); | |
3279 | aBuilder.MakeCompound (aCompHid); | |
3280 | aBuilder.MakeCompound (aCompRes); | |
3281 | for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter) | |
3fc57801 | 3282 | { |
c60ec7f5 | 3283 | if (!aVisible[aTypeIter].IsNull()) |
3284 | { | |
3285 | aBuilder.Add (aCompVis, aVisible[aTypeIter]); | |
3286 | } | |
3287 | if (!aHidden[aTypeIter].IsNull()) | |
3288 | { | |
3289 | aBuilder.Add (aCompHid, aHidden[aTypeIter]); | |
3290 | } | |
3fc57801 | 3291 | } |
c60ec7f5 | 3292 | aBuilder.Add (aCompRes, aCompVis); |
3293 | aBuilder.Add (aCompRes, aCompHid); | |
3fc57801 | 3294 | |
3295 | // create an AIS shape and display it | |
c60ec7f5 | 3296 | if (!ViewerTest::GetAISContext().IsNull()) |
3297 | { | |
3298 | Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes); | |
3299 | if (toShowHiddenEdges) | |
3300 | { | |
3301 | Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f); | |
3302 | for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter) | |
3303 | { | |
3304 | if (!aHidden[aTypeIter].IsNull()) | |
3305 | { | |
3306 | Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]); | |
3307 | aDrawer->SetLineAspect (aLineAspect); | |
3308 | aDrawer->SetWireAspect (aLineAspect); | |
3309 | aDrawer->SetFreeBoundaryAspect (aLineAspect); | |
3310 | aDrawer->SetUnFreeBoundaryAspect (aLineAspect); | |
3311 | } | |
3312 | } | |
3313 | } | |
3314 | ViewerTest::Display (aHlrName, anObject, true); | |
3315 | } | |
3fc57801 | 3316 | |
c60ec7f5 | 3317 | DBRep::Set (aHlrName.ToCString(), aCompRes); |
3fc57801 | 3318 | return 0; |
3319 | } | |
3320 | ||
9558a876 A |
3321 | // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for |
3322 | // manipulating and displaying such an array with AIS context | |
c04c30b3 | 3323 | |
9558a876 A |
3324 | class MyPArrayObject : public AIS_InteractiveObject |
3325 | { | |
3326 | ||
3327 | public: | |
3328 | ||
9427bc1d | 3329 | MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {} |
3330 | ||
da87ddc3 | 3331 | MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType, |
3332 | const Handle(TColStd_HArray1OfAsciiString)& theDesc, | |
3333 | const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect) | |
3334 | { | |
3335 | Init (thePrimType, theDesc, theMarkerAspect, Standard_False); | |
3336 | } | |
3337 | ||
3338 | //! Initialize the array from specified description. | |
3339 | Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType, | |
3340 | const Handle(TColStd_HArray1OfAsciiString)& theDesc, | |
3341 | const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect, | |
3342 | Standard_Boolean theToPatch); | |
9558a876 | 3343 | |
92efcf78 | 3344 | DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject); |
9558a876 | 3345 | |
9427bc1d | 3346 | virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; } |
3347 | ||
9558a876 A |
3348 | private: |
3349 | ||
3350 | void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
3351 | const Handle(Prs3d_Presentation)& aPresentation, | |
79104795 | 3352 | const Standard_Integer aMode) Standard_OVERRIDE; |
9558a876 | 3353 | |
a577aaab | 3354 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
79104795 | 3355 | const Standard_Integer /*theMode*/) Standard_OVERRIDE; |
9558a876 | 3356 | |
eb4320f2 | 3357 | bool CheckInputCommand (const TCollection_AsciiString theCommand, |
da87ddc3 | 3358 | const Handle(TColStd_HArray1OfAsciiString)& theArgsArray, |
eb4320f2 | 3359 | Standard_Integer &theArgIndex, |
3360 | Standard_Integer theArgCount, | |
3361 | Standard_Integer theMaxArgs); | |
3362 | ||
9558a876 A |
3363 | protected: |
3364 | ||
a577aaab | 3365 | Handle(Graphic3d_AspectMarker3d) myMarkerAspect; |
9427bc1d | 3366 | Handle(Graphic3d_ArrayOfPrimitives) myPArray; |
9558a876 A |
3367 | |
3368 | }; | |
3369 | ||
35e08fe8 | 3370 | void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
9427bc1d | 3371 | const Handle(Prs3d_Presentation)& thePrs, |
3372 | const Standard_Integer theMode) | |
9558a876 | 3373 | { |
9427bc1d | 3374 | if (myPArray.IsNull() || theMode != 0) |
3375 | { | |
3376 | return; | |
3377 | } | |
3378 | ||
3379 | Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); | |
3380 | if (!myMarkerAspect.IsNull()) | |
3381 | { | |
3382 | aGroup->SetGroupPrimitivesAspect (myMarkerAspect); | |
3383 | } | |
bf5f0ca2 | 3384 | else |
3385 | { | |
3386 | aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect()); | |
3387 | } | |
9427bc1d | 3388 | aGroup->AddPrimitiveArray (myPArray); |
3389 | } | |
3390 | ||
da87ddc3 | 3391 | Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType, |
3392 | const Handle(TColStd_HArray1OfAsciiString)& theDesc, | |
3393 | const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect, | |
3394 | Standard_Boolean theToPatch) | |
9427bc1d | 3395 | { |
9427bc1d | 3396 | myMarkerAspect = theMarkerAspect; |
da87ddc3 | 3397 | if (!theToPatch) |
3398 | { | |
3399 | myPArray.Nullify(); | |
3400 | } | |
9558a876 | 3401 | |
eb4320f2 | 3402 | // Parsing array description |
9558a876 | 3403 | Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0; |
34253146 | 3404 | Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None; |
9558a876 | 3405 | |
da87ddc3 | 3406 | const Standard_Integer anArgsCount = theDesc->Length(); |
9558a876 | 3407 | TCollection_AsciiString aCommand; |
da87ddc3 | 3408 | for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); ) |
9558a876 | 3409 | { |
da87ddc3 | 3410 | aCommand = theDesc->Value (anArgIndex); |
9558a876 | 3411 | aCommand.LowerCase(); |
9558a876 | 3412 | |
da87ddc3 | 3413 | if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount)) |
3414 | { | |
3415 | anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved; | |
3416 | } | |
3417 | else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount)) | |
3418 | { | |
3419 | anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable; | |
3420 | anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable; | |
3421 | } | |
9558a876 | 3422 | // vertex command |
da87ddc3 | 3423 | else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3424 | { |
3425 | // vertex has a normal or normal with color or texel | |
da87ddc3 | 3426 | if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount)) |
34253146 | 3427 | { |
3428 | anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal; | |
3429 | } | |
9558a876 A |
3430 | |
3431 | // vertex has a color | |
da87ddc3 | 3432 | if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount)) |
34253146 | 3433 | { |
3434 | anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor; | |
3435 | } | |
9558a876 A |
3436 | |
3437 | // vertex has a texel | |
da87ddc3 | 3438 | if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount)) |
34253146 | 3439 | { |
3440 | anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel; | |
3441 | } | |
9558a876 A |
3442 | |
3443 | aVertexNum++; | |
3444 | } | |
3445 | // bound command | |
da87ddc3 | 3446 | else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount)) |
9558a876 A |
3447 | { |
3448 | // bound has color | |
da87ddc3 | 3449 | if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount)) |
34253146 | 3450 | { |
3451 | anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor; | |
3452 | } | |
9558a876 A |
3453 | |
3454 | aBoundNum++; | |
3455 | } | |
3456 | // edge command | |
da87ddc3 | 3457 | else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount)) |
9558a876 | 3458 | { |
9558a876 A |
3459 | aEdgeNum++; |
3460 | } | |
3461 | // unknown command | |
3462 | else | |
eb4320f2 | 3463 | anArgIndex++; |
9558a876 A |
3464 | } |
3465 | ||
da87ddc3 | 3466 | if (myPArray.IsNull()) |
a577aaab | 3467 | { |
da87ddc3 | 3468 | myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags); |
3469 | } | |
3470 | else | |
3471 | { | |
3472 | if (myPArray->Type() != thePrimType | |
3473 | || aVertexNum > myPArray->VertexNumberAllocated() | |
3474 | || aEdgeNum > myPArray->EdgeNumberAllocated() | |
3475 | || aBoundNum > myPArray->BoundNumberAllocated() | |
3476 | || !myPArray->Attributes()->IsMutable() | |
3477 | || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable())) | |
3478 | { | |
3479 | std::cout << "Syntax error: array cannot be patched\n"; | |
3480 | return Standard_False; | |
3481 | } | |
3482 | ||
3483 | myPArray->Attributes()->NbElements = aVertexNum; | |
3484 | if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes())) | |
3485 | { | |
3486 | anAttribs->Invalidate (0, aVertexNum - 1); | |
3487 | } | |
3488 | if (!myPArray->Indices().IsNull()) | |
3489 | { | |
3490 | myPArray->Indices()->NbElements = aEdgeNum; | |
3491 | } | |
3492 | if (!myPArray->Bounds().IsNull()) | |
3493 | { | |
3494 | myPArray->Bounds()->NbBounds = aBoundNum; | |
3495 | } | |
a577aaab | 3496 | } |
9558a876 | 3497 | |
da87ddc3 | 3498 | Standard_Integer aVertIndex = 0; |
3499 | for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); ) | |
9558a876 | 3500 | { |
da87ddc3 | 3501 | aCommand = theDesc->Value (anArgIndex); |
9558a876 | 3502 | aCommand.LowerCase(); |
da87ddc3 | 3503 | if (!aCommand.IsAscii() |
3504 | || aCommand.IsEmpty()) | |
3505 | { | |
9558a876 | 3506 | break; |
da87ddc3 | 3507 | } |
9558a876 | 3508 | |
da87ddc3 | 3509 | // skip beautifiers (syntax is not actually validated) |
3510 | if (aCommand == "-deinterleaved" | |
3511 | || aCommand == "-mutable" | |
3512 | || aCommand.Value (1) == '(' | |
3513 | || aCommand.Value (1) == ')' | |
3514 | || aCommand.Value (1) == ',') | |
3515 | { | |
3516 | ++anArgIndex; | |
3517 | } | |
9558a876 | 3518 | // vertex command |
da87ddc3 | 3519 | else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount)) |
9558a876 | 3520 | { |
da87ddc3 | 3521 | const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(), |
3522 | (float )theDesc->Value (anArgIndex - 2).RealValue(), | |
3523 | (float )theDesc->Value (anArgIndex - 1).RealValue()); | |
3524 | if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0 | |
3525 | || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0) | |
3526 | { | |
3527 | ++aVertIndex; | |
3528 | myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z()); | |
3529 | } | |
3530 | else | |
3531 | { | |
3532 | aVertIndex = myPArray->AddVertex (aVert); | |
3533 | } | |
9558a876 A |
3534 | |
3535 | // vertex has a normal or normal with color or texel | |
da87ddc3 | 3536 | if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount)) |
3537 | { | |
3538 | const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(), | |
3539 | (float )theDesc->Value (anArgIndex - 2).RealValue(), | |
3540 | (float )theDesc->Value (anArgIndex - 1).RealValue()); | |
3541 | myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z()); | |
3542 | } | |
9558a876 | 3543 | |
da87ddc3 | 3544 | if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount)) |
3545 | { | |
3546 | const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(), | |
3547 | theDesc->Value (anArgIndex - 2).RealValue(), | |
3548 | theDesc->Value (anArgIndex - 1).RealValue()); | |
3549 | myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b()); | |
3550 | } | |
3551 | if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount)) | |
3552 | { | |
3553 | const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(), | |
3554 | (float )theDesc->Value (anArgIndex - 1).RealValue()); | |
3555 | myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y()); | |
3556 | } | |
9558a876 A |
3557 | } |
3558 | // bounds command | |
da87ddc3 | 3559 | else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount)) |
9558a876 | 3560 | { |
da87ddc3 | 3561 | Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue(); |
9558a876 | 3562 | |
da87ddc3 | 3563 | if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount)) |
3564 | myPArray->AddBound (aVertCount, | |
3565 | theDesc->Value (anArgIndex - 3).RealValue(), | |
3566 | theDesc->Value (anArgIndex - 2).RealValue(), | |
3567 | theDesc->Value (anArgIndex - 1).RealValue()); | |
9558a876 A |
3568 | |
3569 | else | |
da87ddc3 | 3570 | myPArray->AddBound (aVertCount); |
9558a876 A |
3571 | } |
3572 | // edge command | |
da87ddc3 | 3573 | else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount)) |
9558a876 | 3574 | { |
da87ddc3 | 3575 | const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue(); |
3576 | myPArray->AddEdge (anEdge); | |
9558a876 A |
3577 | } |
3578 | // unknown command | |
3579 | else | |
da87ddc3 | 3580 | { |
3581 | std::cout << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'\n"; | |
3582 | return Standard_False; | |
3583 | } | |
eb4320f2 | 3584 | } |
da87ddc3 | 3585 | return Standard_True; |
eb4320f2 | 3586 | } |
3587 | ||
3588 | void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
9427bc1d | 3589 | const Standard_Integer theMode) |
eb4320f2 | 3590 | { |
9427bc1d | 3591 | if (theMode != 0 |
3592 | || myPArray.IsNull()) | |
3593 | { | |
3594 | return; | |
3595 | } | |
eb4320f2 | 3596 | |
9427bc1d | 3597 | Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this); |
3598 | if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray)) | |
3599 | { | |
3600 | Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner); | |
3601 | aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true); | |
3602 | theSelection->Add (aSensitive); | |
3603 | } | |
3604 | else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray)) | |
eb4320f2 | 3605 | { |
9427bc1d | 3606 | if (aSegs->EdgeNumber() > 0) |
eb4320f2 | 3607 | { |
9427bc1d | 3608 | for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2) |
3609 | { | |
3610 | Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1))); | |
3611 | aSeg->SetSensitivityFactor (4); | |
3612 | theSelection->Add (aSeg); | |
3613 | } | |
eb4320f2 | 3614 | } |
3615 | else | |
3616 | { | |
9427bc1d | 3617 | for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2) |
3618 | { | |
3619 | Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1)); | |
3620 | aSeg->SetSensitivityFactor (4); | |
3621 | theSelection->Add (aSeg); | |
3622 | } | |
eb4320f2 | 3623 | } |
3624 | } | |
9427bc1d | 3625 | else |
3626 | { | |
3627 | Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner); | |
3628 | aSensitive->SetSensitivityFactor (8); | |
3629 | aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true); | |
3630 | theSelection->Add (aSensitive); | |
3631 | } | |
eb4320f2 | 3632 | } |
3633 | ||
3634 | bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand, | |
da87ddc3 | 3635 | const Handle(TColStd_HArray1OfAsciiString)& theArgsArray, |
eb4320f2 | 3636 | Standard_Integer &theArgIndex, |
3637 | Standard_Integer theArgCount, | |
3638 | Standard_Integer theMaxArgs) | |
3639 | { | |
3640 | // check if there is more elements than expected | |
3641 | if (theArgIndex >= theMaxArgs) | |
3642 | return false; | |
3643 | ||
3644 | TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex); | |
3645 | aStrCommand.LowerCase(); | |
3646 | if (aStrCommand.Search(theCommand) != 1 || | |
3647 | theArgIndex + (theArgCount - 1) >= theMaxArgs) | |
3648 | return false; | |
3649 | ||
3650 | // go to the first data element | |
3651 | theArgIndex++; | |
3652 | ||
3653 | // check data if it can be converted to numeric | |
3654 | for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++) | |
3655 | { | |
3656 | aStrCommand = theArgsArray->Value (theArgIndex); | |
3657 | if (!aStrCommand.IsRealValue()) | |
3658 | return false; | |
3659 | } | |
3660 | ||
3661 | return true; | |
3662 | } | |
3663 | ||
3664 | //============================================================================= | |
3665 | //function : VDrawPArray | |
3666 | //purpose : Draws primitives array from list of vertexes, bounds, edges | |
3667 | //============================================================================= | |
3668 | ||
3669 | static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3670 | { | |
3671 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3672 | if (aContextAIS.IsNull()) | |
3673 | { | |
4a056d20 | 3674 | std::cout << "Error: no active Viewer\n"; |
eb4320f2 | 3675 | return 1; |
3676 | } | |
3677 | else if (argc < 3) | |
3678 | { | |
4a056d20 | 3679 | std::cout << "Syntax error: wrong number of arguments\n"; |
eb4320f2 | 3680 | return 1; |
3681 | } | |
3682 | ||
3683 | // read the arguments | |
da87ddc3 | 3684 | Standard_Integer anArgIndex = 1; |
3685 | TCollection_AsciiString aName (argv[anArgIndex++]); | |
3686 | TCollection_AsciiString anArrayType (argv[anArgIndex++]); | |
3687 | anArrayType.LowerCase(); | |
3688 | Handle(MyPArrayObject) aPObject; | |
4a056d20 | 3689 | if (anArrayType == "-shape") |
3690 | { | |
da87ddc3 | 3691 | Standard_CString aShapeName = argv[anArgIndex++]; |
4a056d20 | 3692 | TopoDS_Shape aShape = DBRep::Get (aShapeName); |
3693 | Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape); | |
3694 | if (aShape.IsNull()) | |
3695 | { | |
3696 | std::cout << "Syntax error: shape '" << aShapeName << "' is not found\n"; | |
3697 | return 1; | |
3698 | } | |
3699 | else if (aTris.IsNull()) | |
3700 | { | |
3701 | std::cout << "Syntax error: shape '" << aShapeName << "' is not triangulated\n"; | |
3702 | return 1; | |
3703 | } | |
3704 | ||
da87ddc3 | 3705 | aPObject = new MyPArrayObject (aTris); |
4a056d20 | 3706 | ViewerTest::Display (aName, aPObject); |
3707 | return 0; | |
3708 | } | |
da87ddc3 | 3709 | else if (anArrayType == "-patch" |
3710 | || anArrayType == "-modify" | |
3711 | || anArrayType == "-edit") | |
3712 | { | |
3713 | if (argc >= 3) | |
3714 | { | |
3715 | anArrayType = argv[anArgIndex++]; | |
3716 | anArrayType.LowerCase(); | |
3717 | } | |
eb4320f2 | 3718 | |
da87ddc3 | 3719 | if (GetMapOfAIS().IsBound2 (aName)) |
3720 | { | |
3721 | aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName)); | |
3722 | } | |
3723 | if (aPObject.IsNull()) | |
3724 | { | |
3725 | std::cout << "Syntax error: object '" << aName << "' cannot be found\n"; | |
3726 | return 1; | |
3727 | } | |
3728 | } | |
eb4320f2 | 3729 | |
da87ddc3 | 3730 | Standard_Boolean hasVertex = Standard_False; |
eb4320f2 | 3731 | |
da87ddc3 | 3732 | Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED; |
3733 | if (anArrayType == "points") | |
3734 | { | |
3735 | aPrimType = Graphic3d_TOPA_POINTS; | |
3736 | } | |
3737 | else if (anArrayType == "segments") | |
3738 | { | |
3739 | aPrimType = Graphic3d_TOPA_SEGMENTS; | |
3740 | } | |
3741 | else if (anArrayType == "polylines") | |
3742 | { | |
3743 | aPrimType = Graphic3d_TOPA_POLYLINES; | |
3744 | } | |
3745 | else if (anArrayType == "triangles") | |
3746 | { | |
3747 | aPrimType = Graphic3d_TOPA_TRIANGLES; | |
3748 | } | |
3749 | else if (anArrayType == "trianglefans") | |
eb4320f2 | 3750 | { |
da87ddc3 | 3751 | aPrimType = Graphic3d_TOPA_TRIANGLEFANS; |
3752 | } | |
3753 | else if (anArrayType == "trianglestrips") | |
3754 | { | |
3755 | aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS; | |
3756 | } | |
3757 | else if (anArrayType == "quads") | |
3758 | { | |
3759 | aPrimType = Graphic3d_TOPA_QUADRANGLES; | |
3760 | } | |
3761 | else if (anArrayType == "quadstrips") | |
3762 | { | |
3763 | aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS; | |
3764 | } | |
3765 | else if (anArrayType == "polygons") | |
3766 | { | |
3767 | aPrimType = Graphic3d_TOPA_POLYGONS; | |
3768 | } | |
3769 | if (aPrimType == Graphic3d_TOPA_UNDEFINED) | |
3770 | { | |
3771 | std::cout << "Syntax error: unexpected type of primitives array\n"; | |
eb4320f2 | 3772 | return 1; |
3773 | } | |
3774 | ||
da87ddc3 | 3775 | Standard_Integer aLowerArg = anArgIndex; |
3776 | Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3); | |
3777 | for (; anArgIndex < argc; ++anArgIndex) | |
eb4320f2 | 3778 | { |
da87ddc3 | 3779 | TCollection_AsciiString aCommand (argv[anArgIndex]); |
eb4320f2 | 3780 | aCommand.LowerCase(); |
3781 | if (!aCommand.IsAscii()) | |
3782 | { | |
da87ddc3 | 3783 | di << "Unexpected argument: #" << anArgIndex - 1 << " , " |
eb4320f2 | 3784 | << "should be an array element: 'v', 'b', 'e' \n"; |
3785 | break; | |
3786 | } | |
3787 | ||
3788 | if (aCommand == "v") | |
3789 | { | |
3790 | hasVertex = Standard_True; | |
3791 | } | |
3792 | ||
da87ddc3 | 3793 | anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand); |
eb4320f2 | 3794 | } |
3795 | ||
3796 | if (!hasVertex) | |
3797 | { | |
3798 | di << "You should pass any verticies in the list of array elements\n"; | |
3799 | return 1; | |
3800 | } | |
3801 | ||
3802 | Handle(Graphic3d_AspectMarker3d) anAspPoints; | |
da87ddc3 | 3803 | if (aPrimType == Graphic3d_TOPA_POINTS) |
eb4320f2 | 3804 | { |
3805 | anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f); | |
9558a876 A |
3806 | } |
3807 | ||
9558a876 | 3808 | // create primitives array object |
da87ddc3 | 3809 | if (aPObject.IsNull()) |
3810 | { | |
3811 | // register the object in map | |
3812 | aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints); | |
3813 | VDisplayAISObject (aName, aPObject); | |
3814 | } | |
3815 | else | |
3816 | { | |
3817 | aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True); | |
3818 | ViewerTest::CurrentView()->Redraw(); | |
3819 | } | |
9558a876 A |
3820 | return 0; |
3821 | } | |
3822 | ||
1beb58d7 | 3823 | namespace |
3824 | { | |
3825 | //! Auxiliary function for parsing translation vector - either 2D or 3D. | |
3826 | static Standard_Integer parseTranslationVec (Standard_Integer theArgNb, | |
3827 | const char** theArgVec, | |
3828 | gp_Vec& theVec) | |
3829 | { | |
3830 | if (theArgNb < 2) | |
3831 | { | |
3832 | return 0; | |
3833 | } | |
3834 | ||
3835 | TCollection_AsciiString anX (theArgVec[0]); | |
3836 | TCollection_AsciiString anY (theArgVec[1]); | |
3837 | if (!anX.IsRealValue() | |
3838 | || !anY.IsRealValue()) | |
3839 | { | |
3840 | return 0; | |
3841 | } | |
3842 | ||
3843 | theVec.SetX (anX.RealValue()); | |
3844 | theVec.SetY (anY.RealValue()); | |
3845 | if (theArgNb >= 3) | |
3846 | { | |
3847 | TCollection_AsciiString anZ (theArgVec[2]); | |
3848 | if (anZ.IsRealValue()) | |
3849 | { | |
3850 | theVec.SetZ (anZ.RealValue()); | |
3851 | return 3; | |
3852 | } | |
3853 | } | |
3854 | return 2; | |
3855 | } | |
3856 | } | |
3857 | ||
29d43f9c A |
3858 | //======================================================================= |
3859 | //function : VSetLocation | |
3860 | //purpose : Change location of AIS interactive object | |
3861 | //======================================================================= | |
3862 | ||
1beb58d7 | 3863 | static Standard_Integer VSetLocation (Draw_Interpretor& theDI, |
4e18052b | 3864 | Standard_Integer theArgNb, |
3865 | const char** theArgVec) | |
29d43f9c A |
3866 | { |
3867 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4e18052b | 3868 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
29d43f9c A |
3869 | if (aContext.IsNull()) |
3870 | { | |
4e18052b | 3871 | std::cout << "Error: no active view!\n"; |
29d43f9c A |
3872 | return 1; |
3873 | } | |
3874 | ||
1beb58d7 | 3875 | Standard_Boolean toPrintInfo = Standard_True; |
3876 | Handle(AIS_InteractiveObject) anObj; | |
3877 | TCollection_AsciiString aCmdName (theArgVec[0]); | |
3878 | aCmdName.LowerCase(); | |
3879 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
29d43f9c | 3880 | { |
1beb58d7 | 3881 | TCollection_AsciiString anArg = theArgVec[anArgIter]; |
3882 | anArg.LowerCase(); | |
3883 | if (anUpdateTool.parseRedrawMode (anArg)) | |
4e18052b | 3884 | { |
3885 | continue; | |
3886 | } | |
1beb58d7 | 3887 | else if (anObj.IsNull()) |
4e18052b | 3888 | { |
1beb58d7 | 3889 | const TCollection_AsciiString aName (theArgVec[anArgIter]); |
8f521168 | 3890 | GetMapOfAIS().Find2 (aName, anObj); |
1beb58d7 | 3891 | if (anObj.IsNull()) |
3892 | { | |
3893 | std::cout << "Error: object '" << aName << "' is not displayed!\n"; | |
3894 | return 1; | |
3895 | } | |
4e18052b | 3896 | } |
1beb58d7 | 3897 | else if (anArg == "-reset") |
3898 | { | |
3899 | toPrintInfo = Standard_False; | |
3900 | aContext->SetLocation (anObj, gp_Trsf()); | |
3901 | } | |
3902 | else if (anArg == "-copyfrom" | |
3903 | || anArg == "-copy") | |
4e18052b | 3904 | { |
4e18052b | 3905 | if (anArgIter + 1 >= theArgNb) |
3906 | { | |
1beb58d7 | 3907 | std::cout << "Syntax error at '" << anArg << "'\n"; |
4e18052b | 3908 | return 1; |
3909 | } | |
1beb58d7 | 3910 | |
3911 | const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]); | |
1beb58d7 | 3912 | Handle(AIS_InteractiveObject) anObj2; |
8f521168 | 3913 | GetMapOfAIS().Find2 (aName2, anObj2); |
1beb58d7 | 3914 | if (anObj2.IsNull()) |
4e18052b | 3915 | { |
1beb58d7 | 3916 | std::cout << "Error: object '" << aName2 << "' is not displayed!\n"; |
3917 | return 1; | |
4e18052b | 3918 | } |
1beb58d7 | 3919 | |
3920 | ++anArgIter; | |
3921 | aContext->SetLocation (anObj, anObj2->LocalTransformation()); | |
4e18052b | 3922 | } |
1beb58d7 | 3923 | else if (anArg == "-rotate") |
4e18052b | 3924 | { |
1beb58d7 | 3925 | toPrintInfo = Standard_False; |
3926 | if (anArgIter + 7 >= theArgNb) | |
3927 | { | |
3928 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3929 | return 1; | |
3930 | } | |
7d9e854b | 3931 | |
1beb58d7 | 3932 | gp_Trsf aTrsf; |
3933 | aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]), | |
3934 | Draw::Atof (theArgVec[anArgIter + 2]), | |
3935 | Draw::Atof (theArgVec[anArgIter + 3])), | |
3936 | gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]), | |
3937 | Draw::Atof (theArgVec[anArgIter + 5]), | |
3938 | Draw::Atof (theArgVec[anArgIter + 6]))), | |
3939 | Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0)); | |
3940 | anArgIter += 7; | |
7d9e854b | 3941 | |
1beb58d7 | 3942 | aTrsf = anObj->LocalTransformation() * aTrsf; |
3943 | aContext->SetLocation (anObj, aTrsf); | |
7d9e854b | 3944 | } |
1beb58d7 | 3945 | else if (anArg == "-translate") |
7d9e854b | 3946 | { |
1beb58d7 | 3947 | toPrintInfo = Standard_False; |
3948 | gp_Vec aLocVec; | |
3949 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec); | |
3950 | anArgIter += aNbParsed; | |
3951 | if (aNbParsed == 0) | |
3952 | { | |
3953 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
3954 | return 1; | |
3955 | } | |
7d9e854b | 3956 | |
1beb58d7 | 3957 | gp_Trsf aTrsf; |
3958 | aTrsf.SetTranslationPart (aLocVec); | |
3959 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
3960 | aContext->SetLocation (anObj, aTrsf); | |
7d9e854b | 3961 | } |
1beb58d7 | 3962 | else if (anArg == "-scale" |
3963 | || anArg == "-setscale") | |
3964 | { | |
3965 | toPrintInfo = Standard_False; | |
3966 | gp_XYZ aScaleLoc; | |
3967 | Standard_Real aScale = 1.0; | |
3968 | Standard_Boolean toPrintScale = Standard_True; | |
3969 | Standard_Boolean hasScaleLoc = Standard_False; | |
3970 | if (anArgIter + 4 < theArgNb) | |
3971 | { | |
3972 | TCollection_AsciiString aScaleArgs[4] = | |
3973 | { | |
3974 | TCollection_AsciiString (theArgVec[anArgIter + 1]), | |
3975 | TCollection_AsciiString (theArgVec[anArgIter + 2]), | |
3976 | TCollection_AsciiString (theArgVec[anArgIter + 3]), | |
3977 | TCollection_AsciiString (theArgVec[anArgIter + 4]) | |
3978 | }; | |
3979 | Standard_Integer aScaleArgIter = 0; | |
3980 | for (; aScaleArgIter < 4; ++aScaleArgIter) | |
3981 | { | |
3982 | if (!aScaleArgs[aScaleArgIter].IsRealValue()) | |
3983 | { | |
3984 | break; | |
3985 | } | |
3986 | } | |
3987 | if (aScaleArgIter == 4) | |
3988 | { | |
3989 | aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue()); | |
3990 | aScale = aScaleArgs[3].RealValue(); | |
3991 | anArgIter += 4; | |
3992 | toPrintScale = Standard_False; | |
3993 | hasScaleLoc = Standard_True; | |
3994 | } | |
3995 | else if (aScaleArgIter >= 1) | |
3996 | { | |
3997 | aScale = aScaleArgs[0].RealValue(); | |
3998 | ++anArgIter; | |
3999 | toPrintScale = Standard_False; | |
4000 | } | |
4001 | } | |
4002 | else if (anArgIter + 1 < theArgNb) | |
4003 | { | |
4004 | TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]); | |
4005 | if (aScaleArg.IsRealValue()) | |
4006 | { | |
4007 | aScale = aScaleArg.RealValue(); | |
4008 | ++anArgIter; | |
4009 | toPrintScale = Standard_False; | |
4010 | } | |
4011 | } | |
4012 | ||
4013 | if (toPrintScale) | |
4014 | { | |
4015 | if (anArg == "-setscale") | |
4016 | { | |
4017 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
4018 | return 1; | |
4019 | } | |
7d9e854b | 4020 | |
1beb58d7 | 4021 | char aText[1024]; |
4022 | Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor()); | |
4023 | theDI << aText; | |
4024 | continue; | |
4025 | } | |
7d9e854b | 4026 | |
1beb58d7 | 4027 | if (anArg == "-setscale") |
4028 | { | |
4029 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
4030 | if (hasScaleLoc) | |
4031 | { | |
4032 | aTrsf.SetScale (aScaleLoc, aScale); | |
4033 | } | |
4034 | else | |
4035 | { | |
4036 | aTrsf.SetScaleFactor (aScale); | |
4037 | } | |
4038 | aContext->SetLocation (anObj, aTrsf); | |
4039 | } | |
4040 | else | |
4041 | { | |
4042 | gp_Trsf aTrsf; | |
4043 | if (hasScaleLoc) | |
4044 | { | |
4045 | aTrsf.SetScale (aScaleLoc, aScale); | |
4046 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
4047 | } | |
4048 | else | |
4049 | { | |
4050 | aTrsf = anObj->LocalTransformation(); | |
4051 | aTrsf.SetScaleFactor (aTrsf.ScaleFactor() * aScale); | |
4052 | } | |
4053 | aContext->SetLocation (anObj, aTrsf); | |
4054 | } | |
7d9e854b | 4055 | } |
1beb58d7 | 4056 | else if (anArg == "-mirror") |
7d9e854b | 4057 | { |
1beb58d7 | 4058 | toPrintInfo = Standard_False; |
4059 | if (anArgIter + 6 >= theArgNb) | |
4060 | { | |
4061 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
4062 | return 1; | |
4063 | } | |
7d9e854b | 4064 | |
1beb58d7 | 4065 | gp_Trsf aTrsf; |
4066 | aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]), | |
4067 | Draw::Atof(theArgVec[theArgNb - 5]), | |
4068 | Draw::Atof(theArgVec[theArgNb - 4])), | |
4069 | gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]), | |
4070 | Draw::Atof(theArgVec[theArgNb - 2]), | |
4071 | Draw::Atof(theArgVec[theArgNb - 1])))); | |
4072 | anArgIter += 6; | |
4073 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
4074 | aContext->SetLocation (anObj, aTrsf); | |
7d9e854b | 4075 | } |
1beb58d7 | 4076 | else if (anArg == "-setrotation" |
4077 | || anArg == "-rotation") | |
7d9e854b | 4078 | { |
1beb58d7 | 4079 | toPrintInfo = Standard_False; |
4080 | if (anArgIter + 4 < theArgNb) | |
4081 | { | |
4082 | TCollection_AsciiString aQuatArgs[4] = | |
4083 | { | |
4084 | TCollection_AsciiString (theArgVec[anArgIter + 1]), | |
4085 | TCollection_AsciiString (theArgVec[anArgIter + 2]), | |
4086 | TCollection_AsciiString (theArgVec[anArgIter + 3]), | |
4087 | TCollection_AsciiString (theArgVec[anArgIter + 4]) | |
4088 | }; | |
4089 | Standard_Integer aQuatArgIter = 0; | |
4090 | for (; aQuatArgIter < 4; ++aQuatArgIter) | |
4091 | { | |
4092 | if (!aQuatArgs[aQuatArgIter].IsRealValue()) | |
4093 | { | |
4094 | break; | |
4095 | } | |
4096 | } | |
7d9e854b | 4097 | |
1beb58d7 | 4098 | if (aQuatArgIter == 4) |
4099 | { | |
4100 | anArgIter += 4; | |
4101 | const gp_Quaternion aQuat (aQuatArgs[0].RealValue(), | |
4102 | aQuatArgs[1].RealValue(), | |
4103 | aQuatArgs[2].RealValue(), | |
4104 | aQuatArgs[3].RealValue()); | |
4105 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
4106 | aTrsf.SetRotation (aQuat); | |
4107 | aContext->SetLocation (anObj, aTrsf); | |
4108 | continue; | |
4109 | } | |
4110 | else if (anArg == "-setrotation") | |
4111 | { | |
4112 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
4113 | return 1; | |
4114 | } | |
4115 | } | |
7d9e854b | 4116 | |
1beb58d7 | 4117 | char aText[1024]; |
4118 | const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation(); | |
4119 | Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W()); | |
4120 | theDI << aText; | |
7d9e854b | 4121 | } |
1beb58d7 | 4122 | else if (anArg == "-setlocation" |
4123 | || anArg == "-location") | |
7d9e854b | 4124 | { |
1beb58d7 | 4125 | toPrintInfo = Standard_False; |
4126 | gp_Vec aLocVec; | |
4127 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec); | |
4128 | anArgIter += aNbParsed; | |
4129 | if (aNbParsed != 0) | |
4130 | { | |
4131 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
4132 | aTrsf.SetTranslationPart (aLocVec); | |
4133 | aContext->SetLocation (anObj, aTrsf); | |
4134 | } | |
4135 | else if (anArg == "-setlocation") | |
4136 | { | |
4137 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
4138 | return 1; | |
4139 | } | |
4140 | ||
4141 | char aText[1024]; | |
4142 | const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart(); | |
4143 | Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z()); | |
4144 | theDI << aText; | |
7d9e854b | 4145 | } |
1beb58d7 | 4146 | else if (aCmdName == "vsetlocation") |
7d9e854b | 4147 | { |
1beb58d7 | 4148 | // compatibility with old syntax |
4149 | gp_Vec aLocVec; | |
4150 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec); | |
4151 | if (aNbParsed == 0) | |
4152 | { | |
4153 | std::cout << "Syntax error at '" << anArg << "'\n"; | |
4154 | return 1; | |
4155 | } | |
4156 | anArgIter = anArgIter + aNbParsed - 1; | |
4157 | ||
4158 | gp_Trsf aTrsf; | |
4159 | aTrsf.SetTranslationPart (aLocVec); | |
4160 | aContext->SetLocation (anObj, aTrsf); | |
4161 | toPrintInfo = Standard_False; | |
7d9e854b | 4162 | } |
4163 | else | |
4164 | { | |
1beb58d7 | 4165 | std::cout << "Error: unknown argument '" << anArg << "'\n"; |
4166 | return 1; | |
7d9e854b | 4167 | } |
1beb58d7 | 4168 | } |
7d9e854b | 4169 | |
1beb58d7 | 4170 | if (anObj.IsNull()) |
4171 | { | |
4172 | std::cout << "Syntax error - wrong number of arguments\n"; | |
4173 | return 1; | |
4174 | } | |
4175 | else if (!toPrintInfo) | |
4176 | { | |
4177 | return 0; | |
7d9e854b | 4178 | } |
4179 | ||
1beb58d7 | 4180 | const gp_Trsf aTrsf = anObj->LocalTransformation(); |
4181 | const gp_XYZ aLoc = aTrsf.TranslationPart(); | |
4182 | const gp_Quaternion aRot = aTrsf.GetRotation(); | |
4183 | char aText[4096]; | |
4184 | Sprintf (aText, "Location: %g %g %g\n" | |
4185 | "Rotation: %g %g %g %g\n" | |
4186 | "Scale: %g\n", | |
4187 | aLoc.X(), aLoc.Y(), aLoc.Z(), | |
4188 | aRot.X(), aRot.Y(), aRot.Z(), aRot.W(), | |
4189 | aTrsf.ScaleFactor()); | |
4190 | theDI << aText; | |
7d9e854b | 4191 | return 0; |
4192 | } | |
4193 | ||
ac04d101 SA |
4194 | //=============================================================================================== |
4195 | //function : VConnect | |
4196 | //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location | |
0717ddc1 | 4197 | //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME] |
ac04d101 SA |
4198 | //=============================================================================================== |
4199 | ||
0717ddc1 | 4200 | static Standard_Integer VConnect (Draw_Interpretor& /*di*/, |
4201 | Standard_Integer argc, | |
4202 | const char ** argv) | |
ac04d101 | 4203 | { |
792c785c | 4204 | // Check the viewer |
4205 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4206 | if (aContext.IsNull()) | |
ac04d101 | 4207 | { |
792c785c | 4208 | std::cout << "vconnect error : call vinit before\n"; |
ac04d101 SA |
4209 | return 1; // TCL_ERROR |
4210 | } | |
792c785c | 4211 | // Check argumnets |
0717ddc1 | 4212 | if (argc < 6) |
ac04d101 | 4213 | { |
0717ddc1 | 4214 | std::cout << "vconnect error: expect at least 5 arguments\n"; |
ac04d101 SA |
4215 | return 1; // TCL_ERROR |
4216 | } | |
792c785c | 4217 | |
4218 | // Get values | |
4219 | Standard_Integer anArgIter = 1; | |
4220 | TCollection_AsciiString aName (argv[anArgIter++]); | |
0717ddc1 | 4221 | Handle(AIS_MultipleConnectedInteractive) anOriginObject; |
792c785c | 4222 | TCollection_AsciiString aColorString (argv[argc-1]); |
1d47d8d0 | 4223 | Standard_CString aColorName = ""; |
792c785c | 4224 | Standard_Boolean hasColor = Standard_False; |
4225 | if (aColorString.Search ("color=") != -1) | |
ac04d101 | 4226 | { |
792c785c | 4227 | hasColor = Standard_True; |
4228 | aColorString.Remove (1, 6); | |
4229 | aColorName = aColorString.ToCString(); | |
4230 | } | |
4231 | Handle(AIS_InteractiveObject) anObject; | |
4232 | ||
0717ddc1 | 4233 | // AIS_MultipleConnectedInteractive |
4234 | const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc; | |
4235 | for (Standard_Integer i = 5; i < aNbShapes; ++i) | |
792c785c | 4236 | { |
0717ddc1 | 4237 | TCollection_AsciiString anOriginObjectName (argv[i]); |
792c785c | 4238 | if (aName.IsEqual (anOriginObjectName)) |
ac04d101 | 4239 | { |
0717ddc1 | 4240 | std::cout << "vconnect error: equal names for connected objects\n"; |
4241 | continue; | |
ac04d101 | 4242 | } |
8f521168 | 4243 | if (GetMapOfAIS().Find2 (anOriginObjectName, anObject)) |
792c785c | 4244 | { |
0717ddc1 | 4245 | if (anObject.IsNull()) |
792c785c | 4246 | { |
4247 | std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n"; | |
0717ddc1 | 4248 | continue; |
792c785c | 4249 | } |
4250 | } | |
4251 | else | |
4252 | { | |
51740958 | 4253 | Standard_CString aOriginName = anOriginObjectName.ToCString(); |
4254 | TopoDS_Shape aTDShape = DBRep::Get (aOriginName); | |
792c785c | 4255 | if (aTDShape.IsNull()) |
4256 | { | |
4257 | std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n"; | |
792c785c | 4258 | continue; |
4259 | } | |
0717ddc1 | 4260 | anObject = new AIS_Shape (aTDShape); |
6262338c | 4261 | aContext->Load (anObject); |
0717ddc1 | 4262 | anObject->SetColor (ViewerTest::GetColorFromName (aColorName)); |
792c785c | 4263 | } |
0717ddc1 | 4264 | |
792c785c | 4265 | if (anOriginObject.IsNull()) |
4266 | { | |
0717ddc1 | 4267 | anOriginObject = new AIS_MultipleConnectedInteractive(); |
792c785c | 4268 | } |
0717ddc1 | 4269 | |
4270 | anOriginObject->Connect (anObject); | |
4271 | } | |
4272 | if (anOriginObject.IsNull()) | |
4273 | { | |
4274 | std::cout << "vconect error : can't connect input objects\n"; | |
4275 | return 1; // TCL_ERROR | |
792c785c | 4276 | } |
4277 | ||
ac04d101 | 4278 | // Get location data |
91322f44 | 4279 | Standard_Real aXo = Draw::Atof (argv[anArgIter++]); |
4280 | Standard_Real aYo = Draw::Atof (argv[anArgIter++]); | |
4281 | Standard_Real aZo = Draw::Atof (argv[anArgIter++]); | |
ac04d101 SA |
4282 | |
4283 | // Create transformation | |
0717ddc1 | 4284 | gp_Vec aTranslation (aXo, aYo, aZo); |
4285 | ||
ac04d101 | 4286 | gp_Trsf aTrsf; |
0717ddc1 | 4287 | aTrsf.SetTranslationPart (aTranslation); |
4288 | TopLoc_Location aLocation (aTrsf); | |
ac04d101 | 4289 | |
0717ddc1 | 4290 | anOriginObject->SetLocalTransformation (aTrsf); |
ac04d101 SA |
4291 | |
4292 | // Check if there is another object with given name | |
4293 | // and remove it from context | |
8f521168 | 4294 | Handle(AIS_InteractiveObject) anObj; |
4295 | if (GetMapOfAIS().Find2 (aName, anObj)) | |
ac04d101 | 4296 | { |
ac04d101 SA |
4297 | TheAISContext()->Remove(anObj, Standard_False); |
4298 | GetMapOfAIS().UnBind2(aName); | |
4299 | } | |
4300 | ||
792c785c | 4301 | // Bind connected object to its name |
0717ddc1 | 4302 | GetMapOfAIS().Bind (anOriginObject, aName); |
ac04d101 SA |
4303 | |
4304 | // Display connected object | |
0577ae8c | 4305 | TheAISContext()->Display (anOriginObject, Standard_True); |
ac04d101 SA |
4306 | |
4307 | return 0; | |
4308 | } | |
4309 | ||
4310 | //=============================================================================================== | |
0717ddc1 | 4311 | //function : VConnectTo |
4312 | //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location | |
d4aaad5b | 4313 | //Draw arg : vconnectto name Xo Yo Zo object [-nodisplay|-noupdate|-update] |
ac04d101 SA |
4314 | //=============================================================================================== |
4315 | ||
0717ddc1 | 4316 | static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/, |
4317 | Standard_Integer argc, | |
4318 | const char ** argv) | |
ac04d101 | 4319 | { |
792c785c | 4320 | // Check the viewer |
4321 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
d4aaad5b | 4322 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
792c785c | 4323 | if (aContext.IsNull()) |
ac04d101 | 4324 | { |
0717ddc1 | 4325 | std::cout << "vconnect error : call vinit before\n"; |
ac04d101 SA |
4326 | return 1; // TCL_ERROR |
4327 | } | |
0717ddc1 | 4328 | // Check argumnets |
f751596e | 4329 | if (argc != 6 && argc != 7) |
ac04d101 | 4330 | { |
0717ddc1 | 4331 | std::cout << "vconnect error: expect at least 5 arguments\n"; |
ac04d101 SA |
4332 | return 1; // TCL_ERROR |
4333 | } | |
792c785c | 4334 | |
4335 | // Get values | |
4336 | Standard_Integer anArgIter = 1; | |
4337 | TCollection_AsciiString aName (argv[anArgIter++]); | |
0717ddc1 | 4338 | Handle(AIS_InteractiveObject) anOriginObject; |
4339 | ||
4340 | TCollection_AsciiString anOriginObjectName(argv[5]); | |
4341 | if (aName.IsEqual (anOriginObjectName)) | |
792c785c | 4342 | { |
0717ddc1 | 4343 | std::cout << "vconnect error: equal names for connected objects\n"; |
4344 | return 1; // TCL_ERROR | |
792c785c | 4345 | } |
8f521168 | 4346 | if (GetMapOfAIS().Find2 (anOriginObjectName, anOriginObject)) |
ac04d101 | 4347 | { |
0717ddc1 | 4348 | if (anOriginObject.IsNull()) |
ac04d101 | 4349 | { |
0717ddc1 | 4350 | std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n"; |
792c785c | 4351 | return 1; // TCL_ERROR |
4352 | } | |
792c785c | 4353 | } |
792c785c | 4354 | else |
4355 | { | |
51740958 | 4356 | Standard_CString aOriginName = anOriginObjectName.ToCString(); |
4357 | TopoDS_Shape aTDShape = DBRep::Get (aOriginName); | |
0717ddc1 | 4358 | if (aTDShape.IsNull()) |
792c785c | 4359 | { |
0717ddc1 | 4360 | std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n"; |
ac04d101 SA |
4361 | return 1; // TCL_ERROR |
4362 | } | |
0717ddc1 | 4363 | anOriginObject = new AIS_Shape (aTDShape); |
f751596e | 4364 | GetMapOfAIS().Bind (anOriginObject, anOriginObjectName); |
ac04d101 | 4365 | } |
0717ddc1 | 4366 | |
4367 | // Get location data | |
91322f44 | 4368 | Standard_Real aXo = Draw::Atof (argv[anArgIter++]); |
4369 | Standard_Real aYo = Draw::Atof (argv[anArgIter++]); | |
4370 | Standard_Real aZo = Draw::Atof (argv[anArgIter++]); | |
ac04d101 SA |
4371 | |
4372 | // Create transformation | |
0717ddc1 | 4373 | gp_Vec aTranslation (aXo, aYo, aZo); |
ac04d101 | 4374 | |
0717ddc1 | 4375 | gp_Trsf aTrsf; |
4376 | aTrsf.SetTranslationPart (aTranslation); | |
4377 | ||
792c785c | 4378 | Handle(AIS_ConnectedInteractive) aConnected; |
0717ddc1 | 4379 | |
4380 | aConnected = new AIS_ConnectedInteractive(); | |
4381 | ||
4382 | aConnected->Connect (anOriginObject, aTrsf); | |
ac04d101 SA |
4383 | |
4384 | // Check if there is another object with given name | |
4385 | // and remove it from context | |
8f521168 | 4386 | Handle(AIS_InteractiveObject) anObj; |
4387 | if (GetMapOfAIS().Find2 (aName, anObj)) | |
ac04d101 | 4388 | { |
8f521168 | 4389 | TheAISContext()->Remove (anObj, Standard_False); |
ac04d101 SA |
4390 | GetMapOfAIS().UnBind2(aName); |
4391 | } | |
4392 | ||
0717ddc1 | 4393 | // Bind connected object to its name |
792c785c | 4394 | GetMapOfAIS().Bind (aConnected, aName); |
ac04d101 | 4395 | |
f751596e | 4396 | if (argc == 7) |
4397 | { | |
4398 | TCollection_AsciiString anArg = argv[6]; | |
4399 | anArg.LowerCase(); | |
4400 | if (anArg == "-nodisplay") | |
4401 | return 0; | |
d4aaad5b | 4402 | |
4403 | if (!anUpdateTool.parseRedrawMode (anArg)) | |
4404 | { | |
4405 | std::cout << "Warning! Unknown argument '" << anArg << "' passed, -nodisplay|-noupdate|-update expected at this point.\n"; | |
4406 | } | |
f751596e | 4407 | } |
4408 | ||
0717ddc1 | 4409 | // Display connected object |
d4aaad5b | 4410 | TheAISContext()->Display (aConnected, Standard_False); |
ac04d101 SA |
4411 | |
4412 | return 0; | |
4413 | } | |
4414 | ||
0717ddc1 | 4415 | //======================================================================= |
4416 | //function : VDisconnect | |
4417 | //purpose : | |
4418 | //======================================================================= | |
4419 | static Standard_Integer VDisconnect (Draw_Interpretor& di, | |
4420 | Standard_Integer argc, | |
4421 | const char ** argv) | |
4422 | { | |
4423 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4424 | if (aContext.IsNull()) | |
4425 | { | |
586db386 | 4426 | std::cout << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 4427 | return 1; |
4428 | } | |
4429 | ||
4430 | if (argc != 3) | |
4431 | { | |
586db386 | 4432 | std::cout << "ERROR : Usage : " << argv[0] << " name object\n"; |
0717ddc1 | 4433 | return 1; |
4434 | } | |
4435 | ||
4436 | TCollection_AsciiString aName (argv[1]); | |
4437 | TCollection_AsciiString anObject (argv[2]); | |
4438 | Standard_Integer anObjectNumber = Draw::Atoi (argv[2]); | |
4439 | ||
4440 | // find objects | |
4441 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4442 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
4443 | if (!aMap.IsBound2 (aName) ) | |
4444 | { | |
586db386 | 4445 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4446 | return 1; |
4447 | } | |
4448 | ||
4449 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
4450 | if (anAssembly.IsNull()) | |
4451 | { | |
586db386 | 4452 | di << "Not an assembly\n"; |
0717ddc1 | 4453 | return 1; |
4454 | } | |
4455 | ||
4456 | Handle(AIS_InteractiveObject) anIObj; | |
8f521168 | 4457 | if (!aMap.Find2 (anObject, anIObj)) |
0717ddc1 | 4458 | { |
4459 | // try to interpret second argument as child number | |
4460 | if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size()) | |
4461 | { | |
4462 | Standard_Integer aCounter = 1; | |
4463 | for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next()) | |
4464 | { | |
4465 | if (aCounter == anObjectNumber) | |
4466 | { | |
4467 | anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); | |
4468 | break; | |
4469 | } | |
4470 | ++aCounter; | |
4471 | } | |
4472 | } | |
4473 | else | |
4474 | { | |
586db386 | 4475 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4476 | return 1; |
4477 | } | |
4478 | } | |
4479 | ||
f751596e | 4480 | aContext->Disconnect (anAssembly, anIObj); |
0717ddc1 | 4481 | aContext->UpdateCurrentViewer(); |
0717ddc1 | 4482 | return 0; |
4483 | } | |
4484 | ||
4485 | //======================================================================= | |
4486 | //function : VAddConnected | |
4487 | //purpose : | |
4488 | //======================================================================= | |
4489 | static Standard_Integer VAddConnected (Draw_Interpretor& di, | |
4490 | Standard_Integer argc, | |
4491 | const char ** argv) | |
4492 | { | |
4493 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4494 | if (aContext.IsNull()) | |
4495 | { | |
586db386 | 4496 | std::cout << argv[0] << "error : use 'vinit' command before \n"; |
0717ddc1 | 4497 | return 1; |
4498 | } | |
4499 | ||
4500 | if (argc != 6) | |
4501 | { | |
4502 | std::cout << argv[0] << " error: expect 5 arguments\n"; | |
4503 | return 1; | |
4504 | } | |
4505 | ||
4506 | TCollection_AsciiString aName (argv[1]); | |
4507 | TCollection_AsciiString anObject (argv[5]); | |
4508 | Standard_Real aX = Draw::Atof (argv[2]); | |
4509 | Standard_Real aY = Draw::Atof (argv[3]); | |
4510 | Standard_Real aZ = Draw::Atof (argv[4]); | |
4511 | ||
4512 | // find object | |
4513 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4514 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
4515 | if (!aMap.IsBound2 (aName) ) | |
4516 | { | |
586db386 | 4517 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4518 | return 1; |
4519 | } | |
4520 | ||
4521 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
4522 | if (anAssembly.IsNull()) | |
4523 | { | |
586db386 | 4524 | di << "Not an assembly\n"; |
0717ddc1 | 4525 | return 1; |
4526 | } | |
4527 | ||
4528 | Handle(AIS_InteractiveObject) anIObj; | |
8f521168 | 4529 | if (!aMap.Find2 (anObject, anIObj)) |
0717ddc1 | 4530 | { |
586db386 | 4531 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4532 | return 1; |
4533 | } | |
4534 | ||
0717ddc1 | 4535 | gp_Trsf aTrsf; |
4536 | aTrsf.SetTranslation (gp_Vec (aX, aY, aZ)); | |
4537 | ||
4538 | anAssembly->Connect (anIObj, aTrsf); | |
0577ae8c | 4539 | TheAISContext()->Display (anAssembly, Standard_False); |
0717ddc1 | 4540 | TheAISContext()->RecomputeSelectionOnly (anAssembly); |
4541 | aContext->UpdateCurrentViewer(); | |
4542 | ||
4543 | return 0; | |
4544 | } | |
4545 | ||
4546 | //======================================================================= | |
4547 | //function : VListConnected | |
4548 | //purpose : | |
4549 | //======================================================================= | |
0bd2a43f | 4550 | static Standard_Integer VListConnected (Draw_Interpretor& /*di*/, |
0717ddc1 | 4551 | Standard_Integer argc, |
4552 | const char ** argv) | |
4553 | { | |
4554 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4555 | if (aContext.IsNull()) | |
4556 | { | |
586db386 | 4557 | std::cout << argv[0] << "ERROR : use 'vinit' command before \n"; |
0717ddc1 | 4558 | return 1; |
4559 | } | |
4560 | ||
4561 | if (argc != 2) | |
4562 | { | |
586db386 | 4563 | std::cout << "ERROR : Usage : " << argv[0] << " name\n"; |
0717ddc1 | 4564 | return 1; |
4565 | } | |
4566 | ||
4567 | TCollection_AsciiString aName (argv[1]); | |
4568 | ||
4569 | // find object | |
4570 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4571 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
4572 | if (!aMap.IsBound2 (aName) ) | |
4573 | { | |
586db386 | 4574 | std::cout << "Use 'vdisplay' before\n"; |
0717ddc1 | 4575 | return 1; |
4576 | } | |
4577 | ||
4578 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
4579 | if (anAssembly.IsNull()) | |
4580 | { | |
586db386 | 4581 | std::cout << "Not an assembly\n"; |
0717ddc1 | 4582 | return 1; |
4583 | } | |
4584 | ||
4585 | std::cout << "Children of " << aName << ":\n"; | |
4586 | ||
4587 | Standard_Integer aCounter = 1; | |
4588 | for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next()) | |
4589 | { | |
8f521168 | 4590 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); |
4591 | if (GetMapOfAIS().IsBound1 (anObj)) | |
0717ddc1 | 4592 | { |
8f521168 | 4593 | TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj); |
51740958 | 4594 | std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")"; |
0717ddc1 | 4595 | } |
4596 | ||
4597 | std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name(); | |
4598 | ||
4599 | Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value()); | |
4600 | if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo())) | |
4601 | { | |
4602 | std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo()); | |
4603 | } | |
4604 | std::cout << std::endl; | |
4605 | ||
4606 | ++aCounter; | |
4607 | } | |
4608 | ||
4609 | return 0; | |
4610 | } | |
4611 | ||
245cbf94 | 4612 | //======================================================================= |
4613 | //function : VChild | |
4614 | //purpose : | |
4615 | //======================================================================= | |
4616 | static Standard_Integer VChild (Draw_Interpretor& , | |
4617 | Standard_Integer theNbArgs, | |
4618 | const char** theArgVec) | |
4619 | { | |
4620 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4621 | if (aContext.IsNull()) | |
4622 | { | |
4623 | std::cout << "Error: no active view\n"; | |
4624 | return 1; | |
4625 | } | |
4626 | ||
4627 | int toAdd = -1; | |
4628 | Handle(AIS_InteractiveObject) aParent; | |
4629 | bool hasActions = false; | |
4630 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); | |
4631 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
4632 | { | |
4633 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4634 | anArg.LowerCase(); | |
4635 | if (anUpdateTool.parseRedrawMode (anArg)) | |
4636 | { | |
4637 | continue; | |
4638 | } | |
4639 | else if (anArg == "-add") | |
4640 | { | |
4641 | toAdd = 1; | |
4642 | continue; | |
4643 | } | |
4644 | else if (anArg == "-remove") | |
4645 | { | |
4646 | toAdd = 0; | |
4647 | continue; | |
4648 | } | |
4649 | ||
4650 | Handle(AIS_InteractiveObject) aChild; | |
4651 | if (!GetMapOfAIS().Find2 (theArgVec[anArgIter], aChild)) | |
4652 | { | |
4653 | std::cout << "Syntax error: object '" << theArgVec[anArgIter] << "' is not found\n"; | |
4654 | return 1; | |
4655 | } | |
4656 | ||
4657 | if (aParent.IsNull()) | |
4658 | { | |
4659 | aParent = aChild; | |
4660 | } | |
4661 | else if (toAdd == -1) | |
4662 | { | |
4663 | std::cout << "Syntax error: no action specified\n"; | |
4664 | return 1; | |
4665 | } | |
4666 | else | |
4667 | { | |
4668 | hasActions = true; | |
4669 | if (toAdd == 1) | |
4670 | { | |
4671 | aParent->AddChild (aChild); | |
4672 | } | |
4673 | else | |
4674 | { | |
4675 | aParent->RemoveChild (aChild); | |
4676 | } | |
4677 | } | |
4678 | } | |
4679 | if (!hasActions) | |
4680 | { | |
4681 | std::cout << "Syntax error: not enough arguments\n"; | |
4682 | return 1; | |
4683 | } | |
4684 | return 0; | |
4685 | } | |
4686 | ||
ac04d101 SA |
4687 | //=============================================================================================== |
4688 | //function : VSetSelectionMode | |
f47849f4 | 4689 | //purpose : vselmode |
ac04d101 | 4690 | //=============================================================================================== |
9f37b47d | 4691 | static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/, |
f47849f4 | 4692 | Standard_Integer theNbArgs, |
9f37b47d | 4693 | const char** theArgv) |
ac04d101 SA |
4694 | { |
4695 | // Check errors | |
4696 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
9f37b47d | 4697 | if (anAISContext.IsNull()) |
ac04d101 | 4698 | { |
f47849f4 | 4699 | std::cout << "Error: no active Viewer\n"; |
9f37b47d | 4700 | return 1; |
ac04d101 SA |
4701 | } |
4702 | ||
f47849f4 | 4703 | NCollection_Sequence<TCollection_AsciiString> anObjNames; |
f47849f4 | 4704 | Standard_Integer aSelectionMode = -1; |
4705 | Standard_Boolean toTurnOn = Standard_True; | |
4706 | AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal; | |
4707 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
9f37b47d | 4708 | { |
f47849f4 | 4709 | TCollection_AsciiString anArgCase (theArgv[anArgIter]); |
4710 | anArgCase.LowerCase(); | |
68dcee02 | 4711 | if (anArgCase == "-set" |
4712 | || anArgCase == "-replace" | |
4713 | || anArgCase == "-single" | |
4714 | || anArgCase == "-exclusive") | |
f47849f4 | 4715 | { |
4716 | aSelModeConcurrency = AIS_SelectionModesConcurrency_Single; | |
4717 | } | |
4718 | else if (anArgCase == "-add" | |
4719 | || anArgCase == "-combine" | |
4720 | || anArgCase == "-combination" | |
4721 | || anArgCase == "-multiple") | |
4722 | { | |
4723 | aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple; | |
4724 | } | |
4725 | else if (anArgCase == "-globalorlocal" | |
4726 | || anArgCase == "-localorglobal") | |
4727 | { | |
4728 | aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal; | |
4729 | } | |
4730 | else | |
4731 | { | |
4732 | anObjNames.Append (theArgv[anArgIter]); | |
ac04d101 | 4733 | } |
9f37b47d | 4734 | } |
f47849f4 | 4735 | if (anObjNames.Size() < 2 |
4736 | || !ViewerTest::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn)) | |
4737 | { | |
4738 | std::cout << "Syntax error: wrong number of arguments\n"; | |
4739 | return 1; | |
4740 | } | |
4741 | anObjNames.Remove (anObjNames.Upper()); | |
d2e60688 | 4742 | { |
f47849f4 | 4743 | const TCollection_AsciiString aSelModeString = anObjNames.Last(); |
4744 | anObjNames.Remove (anObjNames.Upper()); | |
d2e60688 | 4745 | TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE; |
4746 | if (aSelModeString.IsIntegerValue()) | |
4747 | { | |
4748 | aSelectionMode = aSelModeString.IntegerValue(); | |
4749 | } | |
4750 | else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType)) | |
4751 | { | |
4752 | aSelectionMode = AIS_Shape::SelectionMode (aShapeType); | |
4753 | } | |
4754 | else | |
4755 | { | |
4756 | std::cout << "Syntax error: unknown selection mode '" << aSelModeString << "'\n"; | |
4757 | return 1; | |
4758 | } | |
4759 | } | |
d2e60688 | 4760 | |
f47849f4 | 4761 | AIS_ListOfInteractive aTargetIOs; |
4762 | for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next()) | |
709e97a0 | 4763 | { |
f47849f4 | 4764 | const TCollection_AsciiString& aNameIO = anObjIter.Value(); |
4765 | Handle(AIS_InteractiveObject) anIO; | |
8f521168 | 4766 | GetMapOfAIS().Find2 (aNameIO, anIO); |
f47849f4 | 4767 | if (anIO.IsNull()) |
709e97a0 | 4768 | { |
f47849f4 | 4769 | std::cout << "Syntax error: undefined presentable object " << aNameIO << "\n"; |
4770 | return 1; | |
709e97a0 | 4771 | } |
f47849f4 | 4772 | aTargetIOs.Append (anIO); |
4773 | } | |
4774 | if (aTargetIOs.IsEmpty()) | |
4775 | { | |
4776 | anAISContext->DisplayedObjects (aTargetIOs); | |
709e97a0 | 4777 | } |
4778 | ||
f47849f4 | 4779 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) |
9f37b47d | 4780 | { |
f47849f4 | 4781 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); |
f47849f4 | 4782 | anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency); |
ac04d101 SA |
4783 | } |
4784 | return 0; | |
4785 | } | |
4786 | ||
4ca4bbe8 | 4787 | //=============================================================================================== |
4788 | //function : VSelectionNext | |
4789 | //purpose : | |
4790 | //=============================================================================================== | |
4791 | static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/, | |
4792 | Standard_Integer /*theArgsNb*/, | |
4793 | const char** /*theArgVec*/) | |
4794 | { | |
4795 | // Check errors | |
4796 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
4797 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4798 | ||
4799 | if (anAISContext.IsNull()) | |
4800 | { | |
4801 | std::cerr << "Call vinit before!" << std::endl; | |
4802 | return 1; | |
4803 | } | |
4804 | ||
f0cddd16 | 4805 | anAISContext->HilightNextDetected (aView); |
4ca4bbe8 | 4806 | return 0; |
4807 | } | |
4808 | ||
4809 | //=============================================================================================== | |
4810 | //function : VSelectionPrevious | |
4811 | //purpose : | |
4812 | //=============================================================================================== | |
4813 | static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/, | |
4814 | Standard_Integer /*theArgsNb*/, | |
4815 | const char** /*theArgVec*/) | |
4816 | { | |
4817 | // Check errors | |
4818 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
4819 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4820 | ||
4821 | if (anAISContext.IsNull()) | |
4822 | { | |
4823 | std::cerr << "Call vinit before!" << std::endl; | |
4824 | return 1; | |
4825 | } | |
4826 | ||
f0cddd16 | 4827 | anAISContext->HilightPreviousDetected (aView); |
4ca4bbe8 | 4828 | return 0; |
4829 | } | |
4830 | ||
ceae62f0 A |
4831 | //=========================================================================== |
4832 | //function : VTriangle | |
4833 | //Draw arg : vtriangle Name PointName PointName PointName | |
4834 | //purpose : creates and displays Triangle | |
4835 | //=========================================================================== | |
35e08fe8 | 4836 | static Standard_Integer VTriangle (Draw_Interpretor& /*di*/, |
ceae62f0 A |
4837 | Standard_Integer argc, |
4838 | const char ** argv) | |
4839 | { | |
9427bc1d | 4840 | const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle"; |
4841 | Handle(Graphic3d_ArrayOfPrimitives) aPrims; | |
4842 | if (isTri) | |
ceae62f0 | 4843 | { |
9427bc1d | 4844 | aPrims = new Graphic3d_ArrayOfTriangles (3); |
ceae62f0 | 4845 | } |
9427bc1d | 4846 | else |
ceae62f0 | 4847 | { |
9427bc1d | 4848 | aPrims = new Graphic3d_ArrayOfSegments (2); |
ceae62f0 A |
4849 | } |
4850 | ||
9427bc1d | 4851 | if (argc != (2 + aPrims->VertexNumberAllocated())) |
ceae62f0 | 4852 | { |
9427bc1d | 4853 | std::cout << "Syntax error: wrong number of arguments\n"; |
4854 | return 1; | |
ceae62f0 A |
4855 | } |
4856 | ||
9427bc1d | 4857 | gp_Pnt aPnts[3]; |
4858 | for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter) | |
ceae62f0 | 4859 | { |
9427bc1d | 4860 | const TCollection_AsciiString aName (argv[2 + aPntIter]); |
4861 | if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL)) | |
4862 | { | |
4863 | aPnts[aPntIter] = aPntPrs->Component()->Pnt(); | |
4864 | } | |
4865 | else | |
4866 | { | |
4867 | TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]); | |
4868 | if (aShape.IsNull() | |
4869 | || aShape.ShapeType() != TopAbs_VERTEX) | |
4870 | { | |
4871 | std::cout << "Syntax error: argument " << aName << " must be a point\n"; | |
4872 | return 1; | |
4873 | } | |
4874 | aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape)); | |
4875 | } | |
ceae62f0 | 4876 | |
9427bc1d | 4877 | for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter) |
4878 | { | |
4879 | if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion())) | |
4880 | { | |
4881 | std::cout << "Syntax error: points should not be equal\n"; | |
4882 | return 1; | |
4883 | } | |
4884 | } | |
ceae62f0 | 4885 | |
9427bc1d | 4886 | aPrims->AddVertex (aPnts[aPntIter]); |
ceae62f0 A |
4887 | } |
4888 | ||
bf5f0ca2 | 4889 | Handle(AIS_InteractiveObject) aPrs = new MyPArrayObject (aPrims); |
4890 | if (!isTri) | |
4891 | { | |
4892 | aPrs->Attributes()->SetupOwnShadingAspect(); | |
4893 | aPrs->Attributes()->ShadingAspect()->Aspect()->SetColor (aPrs->Attributes()->LineAspect()->Aspect()->Color()); | |
4894 | } | |
4895 | ViewerTest::Display (argv[1], aPrs); | |
ceae62f0 A |
4896 | return 0; |
4897 | } | |
4898 | ||
59f45b7c | 4899 | //======================================================================= |
4900 | //function : VObjZLayer | |
4901 | //purpose : Set or get z layer id for presentable object | |
4902 | //======================================================================= | |
4903 | ||
4904 | static Standard_Integer VObjZLayer (Draw_Interpretor& di, | |
4905 | Standard_Integer argc, | |
4906 | const char ** argv) | |
4907 | { | |
4908 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4909 | if (aContext.IsNull()) | |
4910 | { | |
4911 | di << argv[0] << "Call 'vinit' before!\n"; | |
4912 | return 1; | |
4913 | } | |
4914 | ||
4915 | // get operation | |
4916 | TCollection_AsciiString aOperation; | |
4917 | if (argc >= 2) | |
4918 | aOperation = TCollection_AsciiString (argv [1]); | |
4919 | ||
4920 | // check for correct arguments | |
4921 | if (!(argc == 4 && aOperation.IsEqual ("set")) && | |
4922 | !(argc == 3 && aOperation.IsEqual ("get"))) | |
4923 | { | |
4924 | di << "Usage : " << argv[0] << " set/get object [layerid]\n"; | |
4925 | di << " set - set layer id for interactive object, layerid - z layer id\n"; | |
4926 | di << " get - get layer id of interactive object\n"; | |
4927 | di << " argument layerid should be passed for set operation only\n"; | |
4928 | return 1; | |
4929 | } | |
4930 | ||
4931 | // find object | |
4932 | TCollection_AsciiString aName (argv[2]); | |
8f521168 | 4933 | Handle(AIS_InteractiveObject) anInterObj; |
4934 | GetMapOfAIS().Find2 (aName, anInterObj); | |
59f45b7c | 4935 | if (anInterObj.IsNull()) |
4936 | { | |
8f521168 | 4937 | std::cout << "Syntax error: object '" << aName << "' is not displayed\n"; |
59f45b7c | 4938 | return 1; |
4939 | } | |
4940 | ||
4941 | // process operation | |
4942 | if (aOperation.IsEqual ("set")) | |
4943 | { | |
91322f44 | 4944 | Standard_Integer aLayerId = Draw::Atoi (argv [3]); |
59f45b7c | 4945 | aContext->SetZLayer (anInterObj, aLayerId); |
4946 | } | |
4947 | else if (aOperation.IsEqual ("get")) | |
4948 | { | |
4949 | di << "Z layer id: " << aContext->GetZLayer (anInterObj); | |
4950 | } | |
4951 | ||
4952 | return 0; | |
4953 | } | |
4954 | ||
3ddebf91 | 4955 | //======================================================================= |
4956 | //function : VPolygonOffset | |
4957 | //purpose : Set or get polygon offset parameters | |
4958 | //======================================================================= | |
35e08fe8 | 4959 | static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/, |
3ddebf91 | 4960 | Standard_Integer argc, |
4961 | const char ** argv) | |
4962 | { | |
4963 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4964 | if (aContext.IsNull()) | |
4965 | { | |
4966 | std::cout << argv[0] << " Call 'vinit' before!\n"; | |
4967 | return 1; | |
4968 | } | |
4969 | ||
4970 | if (argc > 2 && argc != 5) | |
4971 | { | |
4972 | std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object," | |
4973 | "without arguments prints the default values" << std::endl; | |
4974 | return 1; | |
4975 | } | |
4976 | ||
4977 | // find object | |
4978 | Handle(AIS_InteractiveObject) anInterObj; | |
4979 | if (argc >= 2) | |
4980 | { | |
4981 | TCollection_AsciiString aName (argv[1]); | |
8f521168 | 4982 | if (!GetMapOfAIS().Find2 (aName, anInterObj) |
4983 | || anInterObj.IsNull()) | |
3ddebf91 | 4984 | { |
8f521168 | 4985 | std::cout << "Syntax error: object '" << aName << "' is not displayed\n"; |
3ddebf91 | 4986 | return 1; |
4987 | } | |
4988 | } | |
4989 | ||
4990 | Standard_Integer aMode; | |
60be1f9b | 4991 | Standard_ShortReal aFactor, aUnits; |
3ddebf91 | 4992 | if (argc == 5) |
4993 | { | |
91322f44 | 4994 | aMode = Draw::Atoi(argv[2]); |
4995 | aFactor = (Standard_ShortReal) Draw::Atof(argv[3]); | |
4996 | aUnits = (Standard_ShortReal) Draw::Atof(argv[4]); | |
3ddebf91 | 4997 | |
4998 | anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits); | |
4999 | aContext->UpdateCurrentViewer(); | |
5000 | return 0; | |
5001 | } | |
5002 | else if (argc == 2) | |
5003 | { | |
5004 | if (anInterObj->HasPolygonOffsets()) | |
5005 | { | |
5006 | anInterObj->PolygonOffsets(aMode, aFactor, aUnits); | |
5007 | std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl; | |
5008 | std::cout << "\tMode: " << aMode << std::endl; | |
5009 | std::cout << "\tFactor: " << aFactor << std::endl; | |
5010 | std::cout << "\tUnits: " << aUnits << std::endl; | |
5011 | return 0; | |
5012 | } | |
5013 | else | |
5014 | { | |
5015 | std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl; | |
5016 | } | |
5017 | } | |
5018 | ||
5019 | std::cout << "Default polygon offset parameters:" << std::endl; | |
5020 | aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits); | |
5021 | std::cout << "\tMode: " << aMode << std::endl; | |
5022 | std::cout << "\tFactor: " << aFactor << std::endl; | |
5023 | std::cout << "\tUnits: " << aUnits << std::endl; | |
5024 | ||
5025 | return 0; | |
5026 | } | |
5027 | ||
eb4320f2 | 5028 | // This class is used for testing markers. |
eb4320f2 | 5029 | class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject |
5030 | { | |
5031 | ||
5032 | public: | |
5033 | ||
5034 | ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint, | |
5035 | const Standard_Integer& thePointsOnSide, | |
5036 | Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL) | |
5037 | { | |
5038 | myStartPoint = theStartPoint; | |
5039 | myPointsOnSide = thePointsOnSide; | |
5040 | myMarkerAspect = theMarkerAspect; | |
5041 | } | |
5042 | ||
0e9fe060 | 5043 | DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject); |
eb4320f2 | 5044 | |
5045 | private: | |
5046 | ||
5047 | void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
5048 | const Handle(Prs3d_Presentation)& aPresentation, | |
79104795 | 5049 | const Standard_Integer aMode) Standard_OVERRIDE; |
eb4320f2 | 5050 | |
5051 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
79104795 | 5052 | const Standard_Integer /*theMode*/) Standard_OVERRIDE; |
eb4320f2 | 5053 | |
5054 | protected: | |
5055 | ||
5056 | gp_XYZ myStartPoint; | |
5057 | Standard_Integer myPointsOnSide; | |
5058 | Handle(Graphic3d_AspectMarker3d) myMarkerAspect; | |
5059 | }; | |
5060 | ||
eb4320f2 | 5061 | |
5062 | void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, | |
5063 | const Handle(Prs3d_Presentation)& aPresentation, | |
5064 | const Standard_Integer /*aMode*/) | |
5065 | { | |
5066 | Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1); | |
5067 | if (myPointsOnSide == 1) | |
5068 | { | |
5069 | anArray->AddVertex (myStartPoint); | |
5070 | } | |
5071 | else | |
5072 | { | |
5073 | for (Standard_Real i = 1; i <= myPointsOnSide; i++) | |
5074 | { | |
5075 | for (Standard_Real j = 1; j <= myPointsOnSide; j++) | |
5076 | { | |
5077 | for (Standard_Real k = 1; k <= myPointsOnSide; k++) | |
5078 | { | |
5079 | anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k); | |
5080 | anArray->SetVertexColor (anArray->VertexNumber(), | |
5081 | i / myPointsOnSide, | |
5082 | j / myPointsOnSide, | |
5083 | k / myPointsOnSide); | |
5084 | } | |
5085 | } | |
5086 | } | |
5087 | } | |
5088 | ||
5089 | aPresentation->Clear(); | |
5090 | if (!myMarkerAspect.IsNull()) | |
5091 | { | |
5092 | Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect); | |
5093 | } | |
5094 | Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray); | |
5095 | } | |
5096 | ||
5097 | void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
5098 | const Standard_Integer /*theMode*/) | |
5099 | { | |
5100 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this); | |
5101 | ||
5102 | if (myPointsOnSide == 1) | |
5103 | { | |
5104 | gp_Pnt aPoint (myStartPoint); | |
5105 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
5106 | theSelection->Add (aSensetivePoint); | |
5107 | } | |
5108 | else | |
5109 | { | |
5110 | for (Standard_Real i = 1; i <= myPointsOnSide; i++) | |
5111 | { | |
5112 | for (Standard_Real j = 1; j <= myPointsOnSide; j++) | |
5113 | { | |
5114 | for (Standard_Real k = 1; k <= myPointsOnSide; k++) | |
5115 | { | |
5116 | gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k); | |
5117 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
5118 | theSelection->Add (aSensetivePoint); | |
5119 | } | |
5120 | } | |
5121 | } | |
5122 | } | |
5123 | } | |
a577aaab | 5124 | //======================================================================= |
5125 | //function : VMarkersTest | |
5126 | //purpose : Draws an array of markers for testing purposes. | |
5127 | //======================================================================= | |
498ce76b | 5128 | static Standard_Integer VMarkersTest (Draw_Interpretor&, |
a577aaab | 5129 | Standard_Integer theArgNb, |
5130 | const char** theArgVec) | |
5131 | { | |
5132 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5133 | if (aContext.IsNull()) | |
5134 | { | |
5135 | std::cerr << "Call 'vinit' before!\n"; | |
5136 | return 1; | |
5137 | } | |
5138 | ||
5139 | if (theArgNb < 5) | |
5140 | { | |
5141 | std::cerr << "Usage :\n " << theArgVec[0] | |
5142 | << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n"; | |
5143 | return 1; | |
5144 | } | |
5145 | ||
5146 | Standard_Integer anArgIter = 1; | |
5147 | ||
5148 | TCollection_AsciiString aName (theArgVec[anArgIter++]); | |
5149 | TCollection_AsciiString aFileName; | |
5150 | gp_XYZ aPnt (Atof (theArgVec[anArgIter]), | |
5151 | Atof (theArgVec[anArgIter + 1]), | |
5152 | Atof (theArgVec[anArgIter + 2])); | |
5153 | anArgIter += 3; | |
5154 | ||
5155 | Standard_Integer aPointsOnSide = 10; | |
5156 | Standard_Integer aMarkerType = -1; | |
5157 | Standard_Real aScale = 1.0; | |
5158 | for (; anArgIter < theArgNb; ++anArgIter) | |
5159 | { | |
5160 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5161 | if (anArg.Search ("PointsOnSide=") > -1) | |
5162 | { | |
5163 | aPointsOnSide = anArg.Token ("=", 2).IntegerValue(); | |
5164 | } | |
5165 | else if (anArg.Search ("MarkerType=") > -1) | |
5166 | { | |
5167 | aMarkerType = anArg.Token ("=", 2).IntegerValue(); | |
5168 | } | |
5169 | else if (anArg.Search ("Scale=") > -1) | |
5170 | { | |
5171 | aScale = anArg.Token ("=", 2).RealValue(); | |
5172 | } | |
5173 | else if (anArg.Search ("FileName=") > -1) | |
5174 | { | |
5175 | aFileName = anArg.Token ("=", 2); | |
5176 | } | |
5177 | else | |
5178 | { | |
5179 | std::cerr << "Wrong argument: " << anArg << "\n"; | |
5180 | return 1; | |
5181 | } | |
5182 | } | |
5183 | ||
5184 | Handle(Graphic3d_AspectMarker3d) anAspect; | |
5185 | Handle(Image_AlienPixMap) anImage; | |
5186 | Quantity_Color aColor (Quantity_NOC_GREEN1); | |
5187 | if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0) | |
5188 | && !aFileName.IsEmpty()) | |
5189 | { | |
5190 | anImage = new Image_AlienPixMap(); | |
5191 | if (!anImage->Load (aFileName)) | |
5192 | { | |
5193 | std::cerr << "Could not load image from file '" << aFileName << "'!\n"; | |
5194 | return 1; | |
5195 | } | |
dc858f4c | 5196 | if (anImage->Format() == Image_Format_Gray) |
076ca35c | 5197 | { |
dc858f4c | 5198 | anImage->SetFormat (Image_Format_Alpha); |
076ca35c | 5199 | } |
dc858f4c | 5200 | else if (anImage->Format() == Image_Format_GrayF) |
076ca35c | 5201 | { |
dc858f4c | 5202 | anImage->SetFormat (Image_Format_AlphaF); |
076ca35c | 5203 | } |
a577aaab | 5204 | anAspect = new Graphic3d_AspectMarker3d (anImage); |
5205 | } | |
5206 | else | |
5207 | { | |
5208 | anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale); | |
5209 | } | |
5210 | ||
eb4320f2 | 5211 | Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect); |
5212 | VDisplayAISObject (aName, aMarkersArray); | |
a577aaab | 5213 | |
5214 | return 0; | |
5215 | } | |
5216 | ||
b514beda | 5217 | //======================================================================= |
5218 | //function : TextToBrep | |
5219 | //purpose : Tool for conversion text to occt-shapes | |
5220 | //======================================================================= | |
b514beda | 5221 | static int TextToBRep (Draw_Interpretor& /*theDI*/, |
5222 | Standard_Integer theArgNb, | |
5223 | const char** theArgVec) | |
5224 | { | |
5225 | // Check arguments | |
ac84fcf6 | 5226 | if (theArgNb < 3) |
b514beda | 5227 | { |
5228 | std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n"; | |
5229 | return 1; | |
5230 | } | |
5231 | ||
ac84fcf6 | 5232 | Standard_Integer anArgIt = 1; |
5233 | Standard_CString aName = theArgVec[anArgIt++]; | |
5234 | Standard_CString aText = theArgVec[anArgIt++]; | |
b514beda | 5235 | |
ac84fcf6 | 5236 | Font_BRepFont aFont; |
5237 | TCollection_AsciiString aFontName ("Courier"); | |
5238 | Standard_Real aTextHeight = 16.0; | |
5239 | Font_FontAspect aFontAspect = Font_FA_Regular; | |
5240 | Standard_Boolean anIsCompositeCurve = Standard_False; | |
5241 | gp_Ax3 aPenAx3 (gp::XOY()); | |
5242 | gp_Dir aNormal (0.0, 0.0, 1.0); | |
5243 | gp_Dir aDirection (1.0, 0.0, 0.0); | |
5244 | gp_Pnt aPenLoc; | |
5245 | ||
5246 | Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT; | |
5247 | Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM; | |
1bbd7c79 | 5248 | Font_StrictLevel aStrictLevel = Font_StrictLevel_Any; |
ac84fcf6 | 5249 | for (; anArgIt < theArgNb; ++anArgIt) |
b514beda | 5250 | { |
ac84fcf6 | 5251 | TCollection_AsciiString aParam (theArgVec[anArgIt]); |
5252 | aParam.LowerCase(); | |
5253 | ||
5254 | if (aParam == "-pos" | |
5255 | || aParam == "-position") | |
b514beda | 5256 | { |
ac84fcf6 | 5257 | if (anArgIt + 3 >= theArgNb) |
5258 | { | |
5259 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5260 | return 1; | |
5261 | } | |
5262 | ||
5263 | aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt])); | |
5264 | aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt])); | |
5265 | aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt])); | |
b514beda | 5266 | } |
ac84fcf6 | 5267 | else if (aParam == "-halign") |
b514beda | 5268 | { |
ac84fcf6 | 5269 | if (++anArgIt >= theArgNb) |
5270 | { | |
5271 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5272 | return 1; | |
5273 | } | |
5274 | ||
5275 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
5276 | aType.LowerCase(); | |
5277 | if (aType == "left") | |
5278 | { | |
5279 | aHJustification = Graphic3d_HTA_LEFT; | |
5280 | } | |
5281 | else if (aType == "center") | |
5282 | { | |
5283 | aHJustification = Graphic3d_HTA_CENTER; | |
5284 | } | |
5285 | else if (aType == "right") | |
5286 | { | |
5287 | aHJustification = Graphic3d_HTA_RIGHT; | |
5288 | } | |
5289 | else | |
5290 | { | |
5291 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
5292 | return 1; | |
5293 | } | |
b514beda | 5294 | } |
ac84fcf6 | 5295 | else if (aParam == "-valign") |
b514beda | 5296 | { |
ac84fcf6 | 5297 | if (++anArgIt >= theArgNb) |
5298 | { | |
5299 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5300 | return 1; | |
5301 | } | |
5302 | ||
5303 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
5304 | aType.LowerCase(); | |
5305 | if (aType == "top") | |
5306 | { | |
5307 | aVJustification = Graphic3d_VTA_TOP; | |
5308 | } | |
5309 | else if (aType == "center") | |
5310 | { | |
5311 | aVJustification = Graphic3d_VTA_CENTER; | |
5312 | } | |
5313 | else if (aType == "bottom") | |
5314 | { | |
5315 | aVJustification = Graphic3d_VTA_BOTTOM; | |
5316 | } | |
5317 | else if (aType == "topfirstline") | |
5318 | { | |
5319 | aVJustification = Graphic3d_VTA_TOPFIRSTLINE; | |
5320 | } | |
5321 | else | |
5322 | { | |
5323 | std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n"; | |
5324 | return 1; | |
5325 | } | |
b514beda | 5326 | } |
ac84fcf6 | 5327 | else if (aParam == "-height") |
b514beda | 5328 | { |
ac84fcf6 | 5329 | if (++anArgIt >= theArgNb) |
5330 | { | |
5331 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5332 | return 1; | |
5333 | } | |
5334 | ||
5335 | aTextHeight = Draw::Atof(theArgVec[anArgIt]); | |
b514beda | 5336 | } |
ac84fcf6 | 5337 | else if (aParam == "-aspect") |
b514beda | 5338 | { |
ac84fcf6 | 5339 | if (++anArgIt >= theArgNb) |
5340 | { | |
5341 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5342 | return 1; | |
5343 | } | |
5344 | ||
5345 | TCollection_AsciiString anOption (theArgVec[anArgIt]); | |
5346 | anOption.LowerCase(); | |
5b377041 | 5347 | if (!parseFontStyle (anOption, aFontAspect)) |
ac84fcf6 | 5348 | { |
5b377041 | 5349 | std::cout << "Error: unknown font aspect '" << anOption << "'.\n"; |
ac84fcf6 | 5350 | return 1; |
5351 | } | |
5352 | } | |
5353 | else if (aParam == "-font") | |
5354 | { | |
5355 | if (++anArgIt >= theArgNb) | |
5356 | { | |
5357 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5358 | return 1; | |
5359 | } | |
5360 | ||
5361 | aFontName = theArgVec[anArgIt]; | |
5362 | } | |
1bbd7c79 | 5363 | else if (aParam == "-strict") |
5364 | { | |
5365 | anArgIt += parseFontStrictLevel (theArgNb - anArgIt - 1, | |
5366 | theArgVec + anArgIt + 1, | |
5367 | aStrictLevel); | |
5368 | } | |
ac84fcf6 | 5369 | else if (aParam == "-composite") |
5370 | { | |
5371 | if (++anArgIt >= theArgNb) | |
5372 | { | |
5373 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5374 | return 1; | |
5375 | } | |
5376 | ||
a5565a3c | 5377 | ViewerTest::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve); |
ac84fcf6 | 5378 | } |
5379 | else if (aParam == "-plane") | |
5380 | { | |
5381 | if (anArgIt + 6 >= theArgNb) | |
5382 | { | |
5383 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
5384 | return 1; | |
5385 | } | |
5386 | ||
5387 | Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]); | |
5388 | Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]); | |
5389 | Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]); | |
5390 | aNormal.SetCoord (aX, aY, aZ); | |
5391 | ||
5392 | aX = Draw::Atof (theArgVec[++anArgIt]); | |
5393 | aY = Draw::Atof (theArgVec[++anArgIt]); | |
5394 | aZ = Draw::Atof (theArgVec[++anArgIt]); | |
5395 | aDirection.SetCoord (aX, aY, aZ); | |
b514beda | 5396 | } |
5397 | else | |
5398 | { | |
ac84fcf6 | 5399 | std::cerr << "Warning! Unknown argument '" << aParam << "'\n"; |
b514beda | 5400 | } |
5401 | } | |
5402 | ||
ac84fcf6 | 5403 | aFont.SetCompositeCurveMode (anIsCompositeCurve); |
1bbd7c79 | 5404 | if (!aFont.FindAndInit (aFontName.ToCString(), aFontAspect, aTextHeight, aStrictLevel)) |
b514beda | 5405 | { |
1bbd7c79 | 5406 | std::cout << "Error: unable to load Font\n"; |
b514beda | 5407 | return 1; |
5408 | } | |
5409 | ||
ac84fcf6 | 5410 | aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection); |
5411 | ||
5412 | Font_BRepTextBuilder aBuilder; | |
5413 | DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification)); | |
b514beda | 5414 | return 0; |
5415 | } | |
5416 | ||
725ef85e | 5417 | //======================================================================= |
5418 | //function : VFont | |
5419 | //purpose : Font management | |
5420 | //======================================================================= | |
5421 | ||
5422 | static int VFont (Draw_Interpretor& theDI, | |
5423 | Standard_Integer theArgNb, | |
5424 | const char** theArgVec) | |
5425 | { | |
5426 | Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance(); | |
5427 | if (theArgNb < 2) | |
5428 | { | |
5429 | // just print the list of available fonts | |
5430 | Standard_Boolean isFirst = Standard_True; | |
5b377041 | 5431 | const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts(); |
5432 | for (Font_NListOfSystemFont::Iterator anIter (aFonts); anIter.More(); anIter.Next()) | |
725ef85e | 5433 | { |
5434 | const Handle(Font_SystemFont)& aFont = anIter.Value(); | |
5435 | if (!isFirst) | |
5436 | { | |
5437 | theDI << "\n"; | |
5438 | } | |
5439 | ||
5b377041 | 5440 | theDI << aFont->ToString(); |
725ef85e | 5441 | isFirst = Standard_False; |
5442 | } | |
5443 | return 0; | |
5444 | } | |
5445 | ||
1bbd7c79 | 5446 | Font_StrictLevel aStrictLevel = Font_StrictLevel_Any; |
725ef85e | 5447 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
5448 | { | |
5449 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5450 | TCollection_AsciiString anArgCase (anArg); | |
5451 | anArgCase.LowerCase(); | |
1bbd7c79 | 5452 | if (anArgCase == "-strict") |
5453 | { | |
5454 | anArgIter += parseFontStrictLevel (theArgNb - anArgIter - 1, | |
5455 | theArgVec + anArgIter + 1, | |
5456 | aStrictLevel); | |
5457 | } | |
5458 | else if (anArgIter + 1 < theArgNb | |
5459 | && (anArgCase == "-find" | |
5460 | || anArgCase == "find")) | |
725ef85e | 5461 | { |
5b377041 | 5462 | Standard_CString aFontName = theArgVec[++anArgIter]; |
725ef85e | 5463 | Font_FontAspect aFontAspect = Font_FA_Undefined; |
5464 | if (++anArgIter < theArgNb) | |
5465 | { | |
5466 | anArgCase = theArgVec[anArgIter]; | |
5467 | anArgCase.LowerCase(); | |
5468 | if (!parseFontStyle (anArgCase, aFontAspect)) | |
5469 | { | |
5470 | --anArgIter; | |
5471 | } | |
5472 | } | |
5b377041 | 5473 | |
1bbd7c79 | 5474 | if (Handle(Font_SystemFont) aFont = aMgr->FindFont (aFontName, aStrictLevel, aFontAspect)) |
5b377041 | 5475 | { |
5476 | theDI << aFont->ToString(); | |
5477 | } | |
5478 | else | |
725ef85e | 5479 | { |
1bbd7c79 | 5480 | std::cout << "Error: font '" << aFontName << "' is not found!\n"; |
725ef85e | 5481 | } |
725ef85e | 5482 | } |
5b377041 | 5483 | else if (anArgIter + 1 < theArgNb |
5484 | && (anArgCase == "-add" | |
5485 | || anArgCase == "add" | |
5486 | || anArgCase == "-register" | |
5487 | || anArgCase == "register")) | |
725ef85e | 5488 | { |
5b377041 | 5489 | ++anArgIter; |
e4f0cc46 | 5490 | Standard_CString aFontPath = theArgVec[anArgIter++]; |
5491 | TCollection_AsciiString aFontName; | |
725ef85e | 5492 | Font_FontAspect aFontAspect = Font_FA_Undefined; |
e4f0cc46 | 5493 | Standard_Integer isSingelStroke = -1; |
5494 | for (; anArgIter < theArgNb; ++anArgIter) | |
725ef85e | 5495 | { |
e4f0cc46 | 5496 | anArgCase = theArgVec[anArgIter]; |
5497 | anArgCase.LowerCase(); | |
5b377041 | 5498 | if (aFontAspect == Font_FontAspect_UNDEFINED |
e4f0cc46 | 5499 | && parseFontStyle (anArgCase, aFontAspect)) |
5500 | { | |
5501 | continue; | |
5502 | } | |
5503 | else if (anArgCase == "singlestroke" | |
5504 | || anArgCase == "singleline" | |
5505 | || anArgCase == "oneline") | |
5506 | { | |
5507 | isSingelStroke = 1; | |
5508 | } | |
5509 | else if (aFontName.IsEmpty()) | |
725ef85e | 5510 | { |
5511 | aFontName = theArgVec[anArgIter]; | |
5512 | } | |
e4f0cc46 | 5513 | else |
725ef85e | 5514 | { |
e4f0cc46 | 5515 | --anArgIter; |
5516 | break; | |
725ef85e | 5517 | } |
5518 | } | |
5519 | ||
5520 | Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath); | |
5521 | if (aFont.IsNull()) | |
5522 | { | |
5523 | std::cerr << "Error: font '" << aFontPath << "' is not found!\n"; | |
5524 | continue; | |
5525 | } | |
5526 | ||
5b377041 | 5527 | if (aFontAspect != Font_FontAspect_UNDEFINED |
e4f0cc46 | 5528 | || !aFontName.IsEmpty()) |
725ef85e | 5529 | { |
5b377041 | 5530 | TCollection_AsciiString aName = aFont->FontName(); |
5531 | if (!aFontName.IsEmpty()) | |
725ef85e | 5532 | { |
5b377041 | 5533 | aName = aFontName; |
725ef85e | 5534 | } |
5b377041 | 5535 | Handle(Font_SystemFont) aFont2 = new Font_SystemFont (aName); |
5536 | if (aFontAspect != Font_FontAspect_UNDEFINED) | |
5537 | { | |
5538 | aFont2->SetFontPath (aFontAspect, aFontPath); | |
5539 | } | |
5540 | else | |
725ef85e | 5541 | { |
5b377041 | 5542 | for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter) |
5543 | { | |
5544 | aFont2->SetFontPath ((Font_FontAspect )anAspectIter, aFont->FontPath ((Font_FontAspect )anAspectIter)); | |
5545 | } | |
725ef85e | 5546 | } |
5b377041 | 5547 | aFont = aFont2; |
725ef85e | 5548 | } |
e4f0cc46 | 5549 | if (isSingelStroke != -1) |
5550 | { | |
5551 | aFont->SetSingleStrokeFont (isSingelStroke == 1); | |
5552 | } | |
725ef85e | 5553 | |
5554 | aMgr->RegisterFont (aFont, Standard_True); | |
5b377041 | 5555 | theDI << aFont->ToString(); |
5556 | } | |
5557 | else if (anArgCase == "-verbose" | |
5558 | || anArgCase == "-trace") | |
5559 | { | |
5560 | bool toEnable = true; | |
5561 | if (anArgIter + 1 < theArgNb | |
5562 | && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) | |
5563 | { | |
5564 | ++anArgIter; | |
5565 | } | |
5566 | aMgr->SetTraceAliases (toEnable); | |
725ef85e | 5567 | } |
5568 | else | |
5569 | { | |
e4f0cc46 | 5570 | std::cerr << "Warning! Unknown argument '" << anArg << "'\n"; |
725ef85e | 5571 | } |
5572 | } | |
5573 | ||
5574 | return 0; | |
5575 | } | |
5576 | ||
53b15292 | 5577 | //======================================================================= |
5578 | //function : VVertexMode | |
5579 | //purpose : Switches vertex display mode for AIS_Shape or displays the current value | |
5580 | //======================================================================= | |
5581 | ||
5582 | static int VVertexMode (Draw_Interpretor& theDI, | |
5583 | Standard_Integer theArgNum, | |
5584 | const char** theArgs) | |
5585 | { | |
5586 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5587 | if (aContext.IsNull()) | |
5588 | { | |
5589 | std::cout << "Error: no view available, call 'vinit' before!" << std::endl; | |
5590 | return 1; | |
5591 | } | |
5592 | ||
5593 | // No arguments --> print the current default vertex draw mode | |
5594 | if (theArgNum == 1) | |
5595 | { | |
5596 | Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode(); | |
5597 | theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; | |
5598 | return 0; | |
5599 | } | |
5600 | ||
5601 | // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s) | |
5602 | TCollection_AsciiString aParam (theArgs[1]); | |
5603 | if (aParam == "-set") | |
5604 | { | |
5605 | if (theArgNum == 2) | |
5606 | { | |
5607 | std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl; | |
5608 | std::cout << "Type 'help vvertexmode' for usage hints" << std::endl; | |
5609 | return 1; | |
5610 | } | |
5611 | ||
5612 | TCollection_AsciiString aModeStr (theArgs[2]); | |
5613 | Prs3d_VertexDrawMode aNewMode = | |
5614 | aModeStr == "isolated" ? Prs3d_VDM_Isolated : | |
5615 | (aModeStr == "all" ? Prs3d_VDM_All : | |
5616 | Prs3d_VDM_Inherited); | |
5617 | ||
5618 | Standard_Boolean aRedrawNeeded = Standard_False; | |
5619 | AIS_ListOfInteractive anObjs; | |
5620 | ||
5621 | // No object(s) specified -> use all displayed | |
5622 | if (theArgNum == 3) | |
5623 | { | |
5624 | theDI << "Setting the default vertex draw mode and updating all displayed objects...\n"; | |
5625 | aContext->DisplayedObjects (anObjs); | |
5626 | aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode); | |
5627 | aRedrawNeeded = Standard_True; | |
5628 | } | |
5629 | ||
5630 | Handle(AIS_InteractiveObject) anObject; | |
5631 | for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++) | |
5632 | { | |
5633 | TCollection_AsciiString aName (theArgs[aCount]); | |
8f521168 | 5634 | if (!GetMapOfAIS().Find2 (aName, anObject)) |
53b15292 | 5635 | { |
5636 | theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n"; | |
5637 | continue; | |
5638 | } | |
53b15292 | 5639 | anObjs.Append (anObject); |
5640 | } | |
5641 | ||
5642 | for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next()) | |
5643 | { | |
5644 | anObject = anIt.Value(); | |
5645 | anObject->Attributes()->SetVertexDrawMode (aNewMode); | |
5646 | aContext->Redisplay (anObject, Standard_False); | |
5647 | aRedrawNeeded = Standard_True; | |
5648 | } | |
5649 | ||
5650 | if (aRedrawNeeded) | |
5651 | ViewerTest::CurrentView()->Redraw(); | |
5652 | ||
5653 | return 0; | |
5654 | } | |
5655 | ||
8f521168 | 5656 | Handle(AIS_InteractiveObject) anObject; |
5657 | if (theArgNum > 2 | |
5658 | || !GetMapOfAIS().Find2 (aParam, anObject)) | |
53b15292 | 5659 | { |
5660 | std::cout << "Error: invalid number of arguments" << std::endl; | |
53b15292 | 5661 | return 1; |
5662 | } | |
5663 | ||
5664 | // One argument (object name) --> print the current vertex draw mode for the object | |
53b15292 | 5665 | Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode(); |
5666 | theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; | |
5667 | return 0; | |
5668 | } | |
5669 | ||
d33222c1 | 5670 | //======================================================================= |
5671 | //function : VPointCloud | |
5672 | //purpose : Create interactive object for arbitary set of points. | |
5673 | //======================================================================= | |
5674 | static Standard_Integer VPointCloud (Draw_Interpretor& theDI, | |
5675 | Standard_Integer theArgNum, | |
5676 | const char** theArgs) | |
5677 | { | |
5678 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
5679 | if (anAISContext.IsNull()) | |
5680 | { | |
5681 | std::cerr << "Error: no active view!\n"; | |
5682 | return 1; | |
5683 | } | |
5684 | ||
5685 | // command to execute | |
5686 | enum Command | |
5687 | { | |
5688 | CloudForShape, // generate point cloud for shape | |
5689 | CloudSphere, // generate point cloud for generic sphere | |
5690 | Unknow | |
5691 | }; | |
5692 | ||
5693 | // count number of non-optional command arguments | |
5694 | Command aCmd = Unknow; | |
5695 | Standard_Integer aCmdArgs = 0; | |
5696 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter) | |
5697 | { | |
5698 | Standard_CString anArg = theArgs[anArgIter]; | |
5699 | TCollection_AsciiString aFlag (anArg); | |
5700 | aFlag.LowerCase(); | |
5701 | if (aFlag.IsRealValue() || aFlag.Search ("-") != 1) | |
5702 | { | |
5703 | aCmdArgs++; | |
5704 | } | |
5705 | } | |
5706 | switch (aCmdArgs) | |
5707 | { | |
5708 | case 2 : aCmd = CloudForShape; break; | |
5709 | case 7 : aCmd = CloudSphere; break; | |
5710 | default : | |
5711 | std::cout << "Error: wrong number of arguments! See usage:\n"; | |
5712 | theDI.PrintHelp (theArgs[0]); | |
5713 | return 1; | |
5714 | } | |
5715 | ||
5716 | // parse options | |
5717 | Standard_Boolean toRandColors = Standard_False; | |
5718 | Standard_Boolean hasNormals = Standard_True; | |
5719 | Standard_Boolean isSetArgNorm = Standard_False; | |
737e9a8d | 5720 | Standard_Boolean hasUV = Standard_False; |
d33222c1 | 5721 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter) |
5722 | { | |
5723 | Standard_CString anArg = theArgs[anArgIter]; | |
5724 | TCollection_AsciiString aFlag (anArg); | |
5725 | aFlag.LowerCase(); | |
5726 | if (aFlag == "-randcolors" | |
5727 | || aFlag == "-randcolor") | |
5728 | { | |
5729 | if (isSetArgNorm && hasNormals) | |
5730 | { | |
5731 | std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n"; | |
5732 | return 1; | |
5733 | } | |
5734 | toRandColors = Standard_True; | |
5735 | hasNormals = Standard_False; | |
5736 | } | |
5737 | else if (aFlag == "-normals" | |
5738 | || aFlag == "-normal") | |
5739 | { | |
5740 | if (toRandColors) | |
5741 | { | |
5742 | std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n"; | |
5743 | return 1; | |
5744 | } | |
5745 | isSetArgNorm = Standard_True; | |
5746 | hasNormals = Standard_True; | |
5747 | } | |
5748 | else if (aFlag == "-nonormals" | |
5749 | || aFlag == "-nonormal") | |
5750 | { | |
5751 | isSetArgNorm = Standard_True; | |
5752 | hasNormals = Standard_False; | |
5753 | } | |
737e9a8d | 5754 | else if (aFlag == "-uv" |
5755 | || aFlag == "-texels") | |
5756 | { | |
5757 | hasUV = Standard_True; | |
5758 | } | |
d33222c1 | 5759 | } |
5760 | ||
5761 | Standard_CString aName = theArgs[1]; | |
737e9a8d | 5762 | Graphic3d_ArrayFlags aFlags = Graphic3d_ArrayFlags_None; |
5763 | if (hasNormals) | |
5764 | { | |
5765 | aFlags |= Graphic3d_ArrayFlags_VertexNormal; | |
5766 | } | |
5767 | if (toRandColors) | |
5768 | { | |
5769 | aFlags |= Graphic3d_ArrayFlags_VertexColor; | |
5770 | } | |
5771 | if (hasUV) | |
5772 | { | |
5773 | aFlags |= Graphic3d_ArrayFlags_VertexTexel; | |
5774 | } | |
d33222c1 | 5775 | |
5776 | // generate arbitrary set of points | |
5777 | Handle(Graphic3d_ArrayOfPoints) anArrayPoints; | |
5778 | if (aCmd == CloudForShape) | |
5779 | { | |
5780 | Standard_CString aShapeName = theArgs[2]; | |
5781 | TopoDS_Shape aShape = DBRep::Get (aShapeName); | |
5782 | ||
5783 | if (aShape.IsNull()) | |
5784 | { | |
5785 | std::cout << "Error: no shape with name '" << aShapeName << "' found\n"; | |
5786 | return 1; | |
5787 | } | |
5788 | ||
5789 | // calculate number of points | |
5790 | TopLoc_Location aLocation; | |
5791 | Standard_Integer aNbPoints = 0; | |
5792 | for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) | |
5793 | { | |
5794 | const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current()); | |
5ad8c033 | 5795 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation); |
d33222c1 | 5796 | if (!aTriangulation.IsNull()) |
5797 | { | |
5798 | aNbPoints += aTriangulation->NbNodes(); | |
5799 | } | |
5800 | } | |
5801 | if (aNbPoints < 3) | |
5802 | { | |
5803 | std::cout << "Error: shape should be triangulated!\n"; | |
5804 | return 1; | |
5805 | } | |
5806 | ||
737e9a8d | 5807 | anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags); |
d33222c1 | 5808 | for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) |
5809 | { | |
5810 | const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current()); | |
5ad8c033 | 5811 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation); |
d33222c1 | 5812 | if (aTriangulation.IsNull()) |
5813 | { | |
5814 | continue; | |
5815 | } | |
5816 | ||
5817 | const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); | |
5818 | const gp_Trsf& aTrsf = aLocation.Transformation(); | |
5819 | ||
5820 | // extract normals from nodes | |
5821 | TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower()); | |
5822 | if (hasNormals) | |
5823 | { | |
5824 | Poly_Connect aPolyConnect (aTriangulation); | |
5ad8c033 | 5825 | StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals); |
d33222c1 | 5826 | } |
5827 | ||
5828 | for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) | |
5829 | { | |
5830 | gp_Pnt aPoint = aNodes (aNodeIter); | |
5831 | if (!aLocation.IsIdentity()) | |
5832 | { | |
5833 | aPoint.Transform (aTrsf); | |
5834 | if (hasNormals) | |
5835 | { | |
5836 | aNormals (aNodeIter).Transform (aTrsf); | |
5837 | } | |
5838 | } | |
5839 | ||
5840 | // add vertex into array of points | |
5841 | const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint); | |
5842 | if (toRandColors) | |
5843 | { | |
5844 | Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints), | |
5845 | 1.0, 0.5, Quantity_TOC_HLS); | |
5846 | anArrayPoints->SetVertexColor (anIndexOfPoint, aColor); | |
5847 | } | |
5848 | ||
5849 | if (hasNormals) | |
5850 | { | |
5851 | anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter)); | |
5852 | } | |
737e9a8d | 5853 | if (hasUV |
5854 | && aTriangulation->HasUVNodes()) | |
5855 | { | |
5856 | anArrayPoints->SetVertexTexel (anIndexOfPoint, aTriangulation->UVNode (aNodeIter)); | |
5857 | } | |
d33222c1 | 5858 | } |
5859 | } | |
5860 | } | |
5861 | else if (aCmd == CloudSphere) | |
5862 | { | |
5863 | Standard_Real aCenterX = Draw::Atof (theArgs[2]); | |
5864 | Standard_Real aCenterY = Draw::Atof (theArgs[3]); | |
5865 | Standard_Real aCenterZ = Draw::Atof (theArgs[4]); | |
5866 | Standard_Real aRadius = Draw::Atof (theArgs[5]); | |
5867 | Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]); | |
5868 | ||
5869 | TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]); | |
5870 | aDistribution.LowerCase(); | |
5871 | if ( aDistribution != "surface" && aDistribution != "volume" ) | |
5872 | { | |
5873 | std::cout << "Error: wrong arguments! See usage:\n"; | |
5874 | theDI.PrintHelp (theArgs[0]); | |
5875 | return 1; | |
5876 | } | |
5877 | Standard_Boolean isSurface = aDistribution == "surface"; | |
5878 | ||
5879 | gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ); | |
5880 | ||
737e9a8d | 5881 | anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags); |
d33222c1 | 5882 | for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt) |
5883 | { | |
5884 | Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI; | |
5885 | Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI; | |
5886 | Standard_Real aDistance = isSurface ? | |
5887 | aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius; | |
5888 | ||
5889 | gp_Dir aDir (Cos (anAlpha) * Sin (aBeta), | |
5890 | Sin (anAlpha), | |
5891 | Cos (anAlpha) * Cos (aBeta)); | |
5892 | gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance); | |
5893 | ||
5894 | const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint); | |
5895 | if (toRandColors) | |
5896 | { | |
5897 | Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints), | |
5898 | 1.0, 0.5, Quantity_TOC_HLS); | |
5899 | anArrayPoints->SetVertexColor (anIndexOfPoint, aColor); | |
5900 | } | |
5901 | ||
5902 | if (hasNormals) | |
5903 | { | |
5904 | anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir); | |
5905 | } | |
737e9a8d | 5906 | if (hasUV) |
5907 | { | |
5908 | anArrayPoints->SetVertexTexel (anIndexOfPoint, gp_Pnt2d (anAlpha / 2.0 * M_PI, | |
5909 | aBeta / 2.0 * M_PI)); | |
5910 | } | |
d33222c1 | 5911 | } |
5912 | } | |
5913 | ||
5914 | // set array of points in point cloud object | |
5915 | Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud(); | |
5916 | aPointCloud->SetPoints (anArrayPoints); | |
5917 | VDisplayAISObject (aName, aPointCloud); | |
5918 | return 0; | |
5919 | } | |
5920 | ||
a0c20252 | 5921 | //======================================================================= |
5922 | //function : VPriority | |
5923 | //purpose : Prints or sets the display priority for an object | |
5924 | //======================================================================= | |
5925 | ||
5926 | static int VPriority (Draw_Interpretor& theDI, | |
5927 | Standard_Integer theArgNum, | |
5928 | const char** theArgs) | |
5929 | { | |
5930 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5931 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); | |
5932 | if (aContext.IsNull()) | |
5933 | { | |
5934 | std::cout << "Error: no view available, call 'vinit' before!" << std::endl; | |
5935 | return 1; | |
5936 | } | |
5937 | ||
5938 | TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]); | |
5939 | Standard_Integer aPriority = -1; | |
5940 | Standard_Integer aNbArgs = theArgNum; | |
5941 | if (aLastArg.IsIntegerValue()) | |
5942 | { | |
5943 | aPriority = aLastArg.IntegerValue(); | |
5944 | --aNbArgs; | |
5945 | if (aPriority < 0 || aPriority > 10) | |
5946 | { | |
5947 | std::cout << "Error: the specified display priority value '" << aLastArg | |
5948 | << "' is outside the valid range [0..10]" << std::endl; | |
5949 | return 1; | |
5950 | } | |
5951 | } | |
5952 | else | |
5953 | { | |
5954 | anUpdateTool.Invalidate(); | |
5955 | } | |
5956 | ||
5957 | if (aNbArgs < 2) | |
5958 | { | |
5959 | std::cout << "Error: wrong number of arguments! See usage:\n"; | |
5960 | theDI.PrintHelp (theArgs[0]); | |
5961 | return 1; | |
5962 | } | |
5963 | ||
5964 | for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter) | |
5965 | { | |
5966 | if (anUpdateTool.parseRedrawMode (theArgs[anArgIter])) | |
5967 | { | |
5968 | continue; | |
5969 | } | |
5970 | ||
5971 | TCollection_AsciiString aName (theArgs[anArgIter]); | |
5972 | Handle(AIS_InteractiveObject) anIObj; | |
8f521168 | 5973 | GetMapOfAIS().Find2 (aName, anIObj); |
a0c20252 | 5974 | if (anIObj.IsNull()) |
5975 | { | |
5976 | std::cout << "Error: the object '" << theArgs[1] << "' is not displayed" << std::endl; | |
5977 | return 1; | |
5978 | } | |
5979 | ||
5980 | if (aPriority < 1) | |
5981 | { | |
5982 | theDI << aContext->DisplayPriority (anIObj) << " "; | |
5983 | } | |
5984 | else | |
5985 | { | |
5986 | aContext->SetDisplayPriority (anIObj, aPriority); | |
5987 | } | |
5988 | } | |
5989 | return 0; | |
5990 | } | |
5991 | ||
68ef63f9 | 5992 | //! Auxiliary class for command vnormals. |
5993 | class MyShapeWithNormals : public AIS_Shape | |
5994 | { | |
5995 | DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape); | |
5996 | public: | |
5997 | ||
5998 | Standard_Real NormalLength; | |
5999 | Standard_Integer NbAlongU; | |
6000 | Standard_Integer NbAlongV; | |
6001 | Standard_Boolean ToUseMesh; | |
6002 | Standard_Boolean ToOrient; | |
6003 | ||
6004 | public: | |
6005 | ||
6006 | //! Main constructor. | |
6007 | MyShapeWithNormals (const TopoDS_Shape& theShape) | |
6008 | : AIS_Shape (theShape), | |
6009 | NormalLength(10), | |
6010 | NbAlongU (1), | |
6011 | NbAlongV (1), | |
6012 | ToUseMesh (Standard_False), | |
6013 | ToOrient (Standard_False) {} | |
6014 | ||
6015 | protected: | |
6016 | ||
6017 | //! Comnpute presentation. | |
6018 | virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, | |
6019 | const Handle(Prs3d_Presentation)& thePrs, | |
6020 | const Standard_Integer theMode) Standard_OVERRIDE | |
6021 | { | |
6022 | AIS_Shape::Compute (thePrsMgr, thePrs, theMode); | |
6023 | ||
6024 | NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap; | |
6025 | if (ToUseMesh) | |
6026 | { | |
6027 | DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength); | |
6028 | } | |
6029 | else | |
6030 | { | |
6031 | DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV); | |
6032 | } | |
6033 | ||
6034 | Handle(Graphic3d_Group) aPrsGroup = Prs3d_Root::NewGroup (thePrs); | |
6035 | aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect()); | |
6036 | ||
6037 | const Standard_Real aArrowAngle = myDrawer->ArrowAspect()->Angle(); | |
6038 | const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length(); | |
6039 | for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap); | |
6040 | aFaceIt.More(); aFaceIt.Next()) | |
6041 | { | |
6042 | const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED; | |
6043 | Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size()); | |
6044 | for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next()) | |
6045 | { | |
6046 | std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value(); | |
6047 | if (toReverse) | |
6048 | { | |
6049 | const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ(); | |
6050 | aPair.second = aPair.first.XYZ() + aDir.XYZ(); | |
6051 | } | |
6052 | ||
6053 | aSegments->AddVertex (aPair.first); | |
6054 | aSegments->AddVertex (aPair.second); | |
6055 | Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength); | |
6056 | } | |
6057 | ||
6058 | aPrsGroup->AddPrimitiveArray (aSegments); | |
6059 | } | |
6060 | } | |
6061 | ||
6062 | }; | |
6063 | ||
6064 | //======================================================================= | |
6065 | //function : VNormals | |
6066 | //purpose : Displays/Hides normals calculated on shape geometry or retrieved from triangulation | |
6067 | //======================================================================= | |
6068 | static int VNormals (Draw_Interpretor& theDI, | |
6069 | Standard_Integer theArgNum, | |
6070 | const char** theArgs) | |
6071 | { | |
6072 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6073 | if (aContext.IsNull()) | |
6074 | { | |
6075 | std::cout << "Error: no view available, call 'vinit' before!\n"; | |
6076 | return 1; | |
6077 | } | |
6078 | else if (theArgNum < 2) | |
6079 | { | |
6080 | std::cout << "Error: wrong number of arguments! See usage:\n"; | |
6081 | theDI.PrintHelp (theArgs[0]); | |
6082 | return 1; | |
6083 | } | |
6084 | ||
6085 | Standard_Integer anArgIter = 1; | |
6086 | Standard_CString aShapeName = theArgs[anArgIter++]; | |
6087 | TopoDS_Shape aShape = DBRep::Get (aShapeName); | |
6088 | Standard_Boolean isOn = Standard_True; | |
6089 | if (aShape.IsNull()) | |
6090 | { | |
6091 | std::cout << "Error: shape with name '" << aShapeName << "' is not found\n"; | |
6092 | return 1; | |
6093 | } | |
6094 | ||
6095 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
6096 | Handle(MyShapeWithNormals) aShapePrs; | |
6097 | if (aMap.IsBound2 (aShapeName)) | |
6098 | { | |
6099 | aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName)); | |
6100 | } | |
6101 | ||
6102 | Standard_Boolean isUseMesh = Standard_False; | |
6103 | Standard_Real aLength = 10.0; | |
6104 | Standard_Integer aNbAlongU = 1, aNbAlongV = 1; | |
6105 | Standard_Boolean isOriented = Standard_False; | |
6106 | for (; anArgIter < theArgNum; ++anArgIter) | |
6107 | { | |
6108 | TCollection_AsciiString aParam (theArgs[anArgIter]); | |
6109 | aParam.LowerCase(); | |
6110 | if (anArgIter == 2 | |
6111 | && ViewerTest::ParseOnOff (aParam.ToCString(), isOn)) | |
6112 | { | |
6113 | continue; | |
6114 | } | |
6115 | else if (aParam == "-usemesh" | |
6116 | || aParam == "-mesh") | |
6117 | { | |
6118 | isUseMesh = Standard_True; | |
6119 | } | |
6120 | else if (aParam == "-length" | |
6121 | || aParam == "-len") | |
6122 | { | |
6123 | ++anArgIter; | |
6124 | aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0; | |
6125 | if (Abs (aLength) <= gp::Resolution()) | |
6126 | { | |
6127 | std::cout << "Syntax error: length should not be zero\n"; | |
6128 | return 1; | |
6129 | } | |
6130 | } | |
6131 | else if (aParam == "-orient" | |
6132 | || aParam == "-oriented") | |
6133 | { | |
6134 | isOriented = Standard_True; | |
6135 | if (anArgIter + 1 < theArgNum | |
6136 | && ViewerTest::ParseOnOff (theArgs[anArgIter + 1], isOriented)) | |
6137 | { | |
6138 | ++anArgIter; | |
6139 | } | |
6140 | } | |
6141 | else if (aParam == "-nbalongu" | |
6142 | || aParam == "-nbu") | |
6143 | { | |
6144 | ++anArgIter; | |
6145 | aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
6146 | if (aNbAlongU < 1) | |
6147 | { | |
6148 | std::cout << "Syntax error: NbAlongU should be >=1\n"; | |
6149 | return 1; | |
6150 | } | |
6151 | } | |
6152 | else if (aParam == "-nbalongv" | |
6153 | || aParam == "-nbv") | |
6154 | { | |
6155 | ++anArgIter; | |
6156 | aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
6157 | if (aNbAlongV < 1) | |
6158 | { | |
6159 | std::cout << "Syntax error: NbAlongV should be >=1\n"; | |
6160 | return 1; | |
6161 | } | |
6162 | } | |
6163 | else if (aParam == "-nbalong" | |
6164 | || aParam == "-nbuv") | |
6165 | { | |
6166 | ++anArgIter; | |
6167 | aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
6168 | aNbAlongV = aNbAlongU; | |
6169 | if (aNbAlongU < 1) | |
6170 | { | |
6171 | std::cout << "Syntax error: NbAlong should be >=1\n"; | |
6172 | return 1; | |
6173 | } | |
6174 | } | |
6175 | else | |
6176 | { | |
6177 | std::cout << "Syntax error: unknwon argument '" << aParam << "'\n"; | |
6178 | return 1; | |
6179 | } | |
6180 | } | |
6181 | ||
6182 | if (isOn) | |
6183 | { | |
6184 | if (aShapePrs.IsNull()) | |
6185 | { | |
6186 | aShapePrs = new MyShapeWithNormals (aShape); | |
6187 | } | |
6188 | aShapePrs->ToUseMesh = isUseMesh; | |
6189 | aShapePrs->ToOrient = isOriented; | |
6190 | aShapePrs->NormalLength = aLength; | |
6191 | aShapePrs->NbAlongU = aNbAlongU; | |
6192 | aShapePrs->NbAlongV = aNbAlongV; | |
6193 | VDisplayAISObject (aShapeName, aShapePrs); | |
6194 | } | |
6195 | else if (!aShapePrs.IsNull()) | |
6196 | { | |
6197 | VDisplayAISObject (aShapeName, new AIS_Shape (aShape)); | |
6198 | } | |
6199 | ||
6200 | return 0; | |
6201 | } | |
6202 | ||
7fd59977 | 6203 | //======================================================================= |
6204 | //function : ObjectsCommands | |
161c4476 | 6205 | //purpose : |
7fd59977 | 6206 | //======================================================================= |
6207 | ||
6208 | void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) | |
6209 | { | |
6210 | const char *group ="AISObjects"; | |
bc001a40 | 6211 | |
6212 | theCommands.Add ("vtrihedron", | |
6213 | "vtrihedron : vtrihedron name" | |
6214 | "\n\t\t: [-dispMode {wireframe|shading} ]" | |
6215 | "\n\t\t: [-origin x y z ]" | |
6216 | "\n\t\t: [-zaxis u v w -xaxis u v w ]" | |
fae1ae11 ZA |
6217 | "\n\t\t: [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]" |
6218 | "\n\t\t: [-hideLabels {on|off}]" | |
6219 | "\n\t\t: [-hideArrows {on|off}]" | |
bc001a40 | 6220 | "\n\t\t: [-label {XAxis|YAxis|ZAxis} value]" |
6221 | "\n\t\t: [-attribute {XAxisLength|YAxisLength|ZAxisLength" | |
6222 | "\n\t\t: |TubeRadiusPercent|ConeRadiusPercent" | |
6223 | "\n\t\t: |ConeLengthPercent|OriginRadiusPercent" | |
6224 | "\n\t\t: |ShadingNumberOfFacettes} value]" | |
6225 | "\n\t\t: [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis" | |
6226 | "\n\t\t: |XOZAxis|Whole} {r g b | colorName}]" | |
fae1ae11 ZA |
6227 | "\n\t\t: [-textColor {r g b | colorName}]" |
6228 | "\n\t\t: [-arrowColor {r g b | colorName}]" | |
bc001a40 | 6229 | "\n\t\t: [-priority {Origin|XAxis|YAxis|ZAxis|XArrow" |
6230 | "\n\t\t: |YArrow|ZArrow|XOYAxis|YOZAxis" | |
6231 | "\n\t\t: |XOZAxis|Whole} value]" | |
6232 | "\n\t\t:" | |
6233 | "\n\t\t: Creates a new *AIS_Trihedron* object or changes parameters of " | |
6234 | "\n\t\t: existing trihedron. If no argument is set," | |
6235 | "\n\t\t: the default trihedron (0XYZ) is created." | |
6236 | "\n\t\t: -dispMode mode of visualization: wf - wireframe," | |
6237 | "\n\t\t: sh - shading." | |
6238 | "\n\t\t: Default value is wireframe." | |
6239 | "\n\t\t: -origin allows to set trihedron location." | |
6240 | "\n\t\t: -zaxis/-xaxis allows to set trihedron X and Z" | |
6241 | "\n\t\t: directions. The directions should" | |
6242 | "\n\t\t: be orthogonal. Y direction is calculated." | |
fae1ae11 | 6243 | "\n\t\t: -drawAxes allows to set what axes are drawn in the" |
bc001a40 | 6244 | "\n\t\t: trihedron, default state is XYZ" |
fae1ae11 ZA |
6245 | "\n\t\t: -hideLabels allows to show/hide trihedron labels" |
6246 | "\n\t\t: -hideArrows allows to show/hide trihedron arrows" | |
169c944c | 6247 | "\n\t\t: -label allows to change default X/Y/Z titles of axes" |
bc001a40 | 6248 | "\n\t\t: -attribute sets parameters of trihedron" |
6249 | "\n\t\t: -color sets color properties of parts of trihedron" | |
fae1ae11 ZA |
6250 | "\n\t\t: -textColor sets color properties of trihedron labels" |
6251 | "\n\t\t: -arrowColor sets color properties of trihedron arrows" | |
bc001a40 | 6252 | "\n\t\t: -priority allows to change default selection priority" |
6253 | "\n\t\t: of trihedron components", | |
6254 | __FILE__,VTrihedron,group); | |
7fd59977 | 6255 | |
161c4476 | 6256 | theCommands.Add("vtri2d", |
faea8b40 | 6257 | "vtri2d Name" |
6258 | "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.", | |
7fd59977 | 6259 | __FILE__,VTrihedron2D ,group); |
6260 | ||
161c4476 | 6261 | theCommands.Add("vplanetri", |
faea8b40 | 6262 | "vplanetri name" |
6263 | "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default", | |
7fd59977 | 6264 | __FILE__,VPlaneTrihedron ,group); |
6265 | ||
6266 | theCommands.Add("vsize", | |
faea8b40 | 6267 | "vsize : vsize [name(Default=Current)] [size(Default=100)] " |
6268 | "\n\t\t: Changes the size of a named or selected trihedron." | |
6269 | "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done." | |
6270 | "\n\t\t: If the value is not defined: it is set to 100 by default.", | |
7fd59977 | 6271 | __FILE__,VSize,group); |
6272 | ||
6273 | theCommands.Add("vaxis", | |
faea8b40 | 6274 | "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]" |
6275 | "\n\t\t: Creates an axis. If the values are not defined, an axis is created by interactive selection of two vertices or one edge", | |
7fd59977 | 6276 | __FILE__,VAxisBuilder,group); |
6277 | ||
161c4476 | 6278 | theCommands.Add("vaxispara", |
faea8b40 | 6279 | "vaxispara name " |
6280 | "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.", | |
7fd59977 | 6281 | __FILE__,VAxisBuilder,group); |
6282 | ||
6283 | theCommands.Add("vaxisortho", | |
faea8b40 | 6284 | "vaxisortho name " |
6285 | "\n\t\t: Creates an axis by interactive selection of an edge and a vertex. The axis will be orthogonal to the selected edge.", | |
7fd59977 | 6286 | __FILE__,VAxisBuilder,group); |
6287 | ||
6288 | theCommands.Add("vpoint", | |
faea8b40 | 6289 | "vpoint PointName [Xa] [Ya] [Za] " |
6290 | "\n\t\t: Creates a point from coordinates. If the values are not defined," | |
6291 | "\n\t\t: a point is created by interactive selection of a vertice or an edge (in the center of the edge).", | |
7fd59977 | 6292 | __FILE__,VPointBuilder,group); |
6293 | ||
6294 | theCommands.Add("vplane", | |
faea8b40 | 6295 | "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]" |
6296 | "\n\t\t: Creates a plane from named or interactively selected entities." | |
6297 | "\n\t\t: TypeOfSensitivity:" | |
6298 | "\n\t\t: 0 - Interior" | |
6299 | "\n\t\t: 1 - Boundary", | |
7fd59977 | 6300 | __FILE__,VPlaneBuilder,group); |
6301 | ||
f3889691 | 6302 | theCommands.Add ("vchangeplane", "vchangeplane usage: \n" |
6303 | " vchangeplane <plane_name>" | |
6304 | " [x=center_x y=center_y z=center_z]" | |
6305 | " [dx=dir_x dy=dir_y dz=dir_z]" | |
6306 | " [sx=size_x sy=size_y]" | |
6307 | " [noupdate]\n" | |
6308 | " - changes parameters of the plane:\n" | |
6309 | " - x y z - center\n" | |
6310 | " - dx dy dz - normal\n" | |
6311 | " - sx sy - plane sizes\n" | |
6312 | " - noupdate - do not update/redisplay the plane in context\n" | |
6313 | " Please enter coordinates in format \"param=value\" in arbitrary order.", | |
6314 | __FILE__, VChangePlane, group); | |
6315 | ||
7fd59977 | 6316 | theCommands.Add("vplanepara", |
faea8b40 | 6317 | "vplanepara PlaneName " |
6318 | "\n\t\t: Creates a plane from interactively selected vertex and face.", | |
7fd59977 | 6319 | __FILE__,VPlaneBuilder,group); |
6320 | ||
6321 | theCommands.Add("vplaneortho", | |
faea8b40 | 6322 | "vplaneortho PlaneName " |
6323 | "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ", | |
7fd59977 | 6324 | __FILE__,VPlaneBuilder,group); |
6325 | ||
161c4476 | 6326 | theCommands.Add("vline", |
faea8b40 | 6327 | "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] " |
6328 | "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ", | |
7fd59977 | 6329 | __FILE__,VLineBuilder,group); |
6330 | ||
6331 | theCommands.Add("vcircle", | |
faea8b40 | 6332 | "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]" |
6333 | "\n\t\t: Creates a circle from named or interactively selected entities." | |
6334 | "\n\t\t: Parameter IsFilled is defined as 0 or 1.", | |
7fd59977 | 6335 | __FILE__,VCircleBuilder,group); |
6336 | ||
29e2c6d2 | 6337 | theCommands.Add ("vdrawtext", |
6338 | "vdrawtext name text" | |
6339 | "\n\t\t: [-pos X=0 Y=0 Z=0]" | |
6340 | "\n\t\t: [-color {R G B|name}=yellow]" | |
6341 | "\n\t\t: [-halign {left|center|right}=left]" | |
ac84fcf6 | 6342 | "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]" |
29e2c6d2 | 6343 | "\n\t\t: [-angle angle=0]" |
6344 | "\n\t\t: [-zoom {0|1}=0]" | |
6345 | "\n\t\t: [-height height=16]" | |
5b377041 | 6346 | "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]" |
29e2c6d2 | 6347 | "\n\t\t: [-font font=Times]" |
61b0191c | 6348 | "\n\t\t: [-2d]" |
6349 | "\n\t\t: [-perspos {X Y Z}=0 0 0], where" | |
6350 | "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window" | |
6351 | "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..." | |
6352 | "\n\t\t Z coordinate defines the gap from border of view window (except center position)." | |
3cbd0a8e | 6353 | "\n\t\t: [-disptype {blend|decal|shadow|subtitle|dimension|normal}=normal}" |
61b0191c | 6354 | "\n\t\t: [-subcolor {R G B|name}=white]" |
29e2c6d2 | 6355 | "\n\t\t: [-noupdate]" |
ce01ec26 | 6356 | "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]" |
3f1eb0ab | 6357 | "\n\t\t: [-flipping]" |
29e2c6d2 | 6358 | "\n\t\t: Display text label at specified position.", |
6359 | __FILE__, VDrawText, group); | |
7fd59977 | 6360 | |
6361 | theCommands.Add("vdrawsphere", | |
b7cd4ba7 | 6362 | "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n", |
7fd59977 | 6363 | __FILE__,VDrawSphere,group); |
6364 | ||
1beb58d7 | 6365 | theCommands.Add ("vlocation", |
6366 | "vlocation name" | |
6367 | "\n\t\t: [-reset]" | |
6368 | "\n\t\t: [-copyFrom otherName]" | |
6369 | "\n\t\t: [-translate X Y [Z]]" | |
6370 | "\n\t\t: [-rotate x y z dx dy dz angle]" | |
6371 | "\n\t\t: [-scale [X Y Z] scale]" | |
6372 | "\n\t\t: [-mirror x y z dx dy dz]" | |
6373 | "\n\t\t: [-setLocation X Y [Z]]" | |
6374 | "\n\t\t: [-setRotation QX QY QZ QW]" | |
6375 | "\n\t\t: [-setScale [X Y Z] scale]" | |
6376 | "\n\t\t: Object local transformation management:" | |
6377 | "\n\t\t: -reset reset transformation to identity" | |
6378 | "\n\t\t: -translate translate object" | |
6379 | "\n\t\t: -rotate applies rotation to local transformation" | |
6380 | "\n\t\t: -scale applies scale to local transformation" | |
6381 | "\n\t\t: -mirror applies mirror to local transformation" | |
6382 | "\n\t\t: -setLocation assign object location" | |
6383 | "\n\t\t: -setRotation assign object rotation (quaternion)" | |
6384 | "\n\t\t: -setScale assign object scale factor", | |
6385 | __FILE__, VSetLocation, group); | |
29d43f9c | 6386 | theCommands.Add ("vsetlocation", |
1beb58d7 | 6387 | "alias for vlocation", |
29d43f9c | 6388 | __FILE__, VSetLocation, group); |
245cbf94 | 6389 | theCommands.Add ("vchild", |
6390 | "vchild parent [-add] [-remove] child1 [child2] [...]" | |
6391 | "\n\t\t: Command for testing low-level presentation connections." | |
6392 | "\n\t\t: vconnect command should be used instead.", | |
6393 | __FILE__, VChild, group); | |
c60ec7f5 | 6394 | theCommands.Add ("vcomputehlr", |
6395 | "vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]" | |
6396 | "\n\t\t: [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]" | |
6397 | "\n\t\t: [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]" | |
6398 | "\n\t\t: Arguments:" | |
6399 | "\n\t\t: shapeInput - name of the initial shape" | |
6400 | "\n\t\t: hlrResult - result HLR object from initial shape" | |
6401 | "\n\t\t: eye, dir are eye position and look direction" | |
6402 | "\n\t\t: up is the look up direction vector" | |
6403 | "\n\t\t: -algoType HLR algorithm to use" | |
6404 | "\n\t\t: -showTangentEdges include tangent edges" | |
6405 | "\n\t\t: -nbIsolines include isolines" | |
6406 | "\n\t\t: -showHiddenEdges include hidden edges" | |
6407 | "\n\t\t: Use vtop to see projected HLR shape.", | |
3fc57801 | 6408 | __FILE__, VComputeHLR, group); |
6409 | ||
9558a876 | 6410 | theCommands.Add("vdrawparray", |
4a056d20 | 6411 | "vdrawparray name TypeOfArray={points|segments|polylines|triangles" |
6412 | "\n\t\t: |trianglefans|trianglestrips|quads|quadstrips|polygons}" | |
da87ddc3 | 6413 | "\n\t\t: [-deinterleaved|-mutable]" |
4a056d20 | 6414 | "\n\t\t: [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]" |
6415 | "\n\t\t: [bound= {'b' nbVertices [bound_color={'c' r g b}]]" | |
6416 | "\n\t\t: [edge= {'e' vertexId]" | |
da87ddc3 | 6417 | "\n\t\t: [-shape shapeName] [-patch]" |
4a056d20 | 6418 | "\n\t\t: Commands create an Interactive Object for specified Primitive Array definition (Graphic3d_ArrayOfPrimitives)" |
6419 | "\n\t\t: with the main purpose is covering various combinations by tests", | |
9558a876 | 6420 | __FILE__,VDrawPArray,group); |
ac04d101 SA |
6421 | |
6422 | theCommands.Add("vconnect", | |
faea8b40 | 6423 | "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]" |
6424 | "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.", | |
ac04d101 SA |
6425 | __FILE__, VConnect, group); |
6426 | ||
0717ddc1 | 6427 | theCommands.Add("vconnectto", |
d4aaad5b | 6428 | "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]" |
f751596e | 6429 | " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)." |
6430 | "\n\t\t: -nodisplay - only creates interactive object, but not displays it", | |
0717ddc1 | 6431 | __FILE__, VConnectTo,group); |
6432 | ||
6433 | theCommands.Add("vdisconnect", | |
6434 | "vdisconnect assembly_name (object_name | object_number | 'all')" | |
6435 | " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).", | |
6436 | __FILE__,VDisconnect,group); | |
6437 | ||
6438 | theCommands.Add("vaddconnected", | |
6439 | "vaddconnected assembly_name object_name" | |
6440 | "Adds object to assembly.", | |
6441 | __FILE__,VAddConnected,group); | |
6442 | ||
6443 | theCommands.Add("vlistconnected", | |
6444 | "vlistconnected assembly_name" | |
6445 | "Lists objects in assembly.", | |
6446 | __FILE__,VListConnected,group); | |
6447 | ||
ac04d101 SA |
6448 | |
6449 | theCommands.Add("vselmode", | |
f47849f4 | 6450 | "vselmode [object] selectionMode {on|off}" |
6451 | "\n\t\t: [{-add|-set|-globalOrLocal}=-globalOrLocal]" | |
6452 | "\n\t\t: Switches selection mode for the specified object or for all objects in context." | |
6453 | "\n\t\t: Selection mode is either an integer number specific to Interactive Object," | |
6454 | "\n\t\t: or sub-shape type in case of AIS_Shape:" | |
6455 | "\n\t\t: Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound" | |
6456 | "\n\t\t: The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole." | |
6457 | "\n\t\t: Additional options:" | |
6458 | "\n\t\t: -add already activated selection modes will be left activated" | |
6459 | "\n\t\t: -set already activated selection modes will be deactivated" | |
6460 | "\n\t\t: -globalOrLocal (default) if new mode is Global selection mode," | |
6461 | "\n\t\t: then active local selection modes will be deactivated" | |
6462 | "\n\t\t: and the samthen active local selection modes will be deactivated", | |
ac04d101 | 6463 | __FILE__, VSetSelectionMode, group); |
ceae62f0 | 6464 | |
4ca4bbe8 | 6465 | theCommands.Add("vselnext", |
6466 | "vselnext : hilight next detected", | |
6467 | __FILE__, VSelectionNext, group); | |
6468 | ||
6469 | theCommands.Add("vselprev", | |
6470 | "vselnext : hilight previous detected", | |
6471 | __FILE__, VSelectionPrevious, group); | |
6472 | ||
ceae62f0 | 6473 | theCommands.Add("vtriangle", |
faea8b40 | 6474 | "vtriangle Name PointName PointName PointName" |
6475 | "\n\t\t: Creates and displays a filled triangle from named points.", | |
ceae62f0 A |
6476 | __FILE__, VTriangle,group); |
6477 | ||
6478 | theCommands.Add("vsegment", | |
faea8b40 | 6479 | "vsegment Name PointName PointName" |
6480 | "\n\t\t: Creates and displays a segment from named points.", | |
9427bc1d | 6481 | __FILE__, VTriangle,group); |
59f45b7c | 6482 | |
6483 | theCommands.Add("vobjzlayer", | |
6484 | "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object", | |
6485 | __FILE__, VObjZLayer, group); | |
3ddebf91 | 6486 | |
6487 | theCommands.Add("vpolygonoffset", | |
6488 | "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values", | |
6489 | __FILE__, VPolygonOffset, group); | |
a2d5ab2e | 6490 | |
a577aaab | 6491 | theCommands.Add ("vmarkerstest", |
6492 | "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n", | |
6493 | __FILE__, VMarkersTest, group); | |
b514beda | 6494 | |
6495 | theCommands.Add ("text2brep", | |
ac84fcf6 | 6496 | "text2brep: name text" |
6497 | "\n\t\t: [-pos X=0 Y=0 Z=0]" | |
6498 | "\n\t\t: [-halign {left|center|right}=left]" | |
6499 | "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]" | |
6500 | "\n\t\t: [-height height=16]" | |
5b377041 | 6501 | "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]" |
1bbd7c79 | 6502 | "\n\t\t: [-font font=Courier] [-strict {strict|aliases|any}=any]" |
ac84fcf6 | 6503 | "\n\t\t: [-composite {on|off}=off]" |
6504 | "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]", | |
b514beda | 6505 | __FILE__, TextToBRep, group); |
725ef85e | 6506 | theCommands.Add ("vfont", |
5b377041 | 6507 | "vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]" |
1bbd7c79 | 6508 | "\n\t\t: [-strict {any|aliases|strict}] [-find fontName [regular,bold,italic,boldItalic=undefined]] [-verbose {on|off}]", |
725ef85e | 6509 | __FILE__, VFont, group); |
53b15292 | 6510 | |
6511 | theCommands.Add ("vvertexmode", | |
6512 | "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n" | |
6513 | "vvertexmode - prints the default vertex draw mode\n" | |
6514 | "vvertexmode name - prints the vertex draw mode of the given object\n" | |
6515 | "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n" | |
6516 | "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n", | |
6517 | __FILE__, VVertexMode, group); | |
d33222c1 | 6518 | |
6519 | theCommands.Add ("vpointcloud", | |
737e9a8d | 6520 | "vpointcloud name shape [-randColor] [-normals] [-noNormals] [-uv]" |
d33222c1 | 6521 | "\n\t\t: Create an interactive object for arbitary set of points" |
6522 | "\n\t\t: from triangulated shape." | |
6523 | "\n" | |
6524 | "vpointcloud name x y z r npts {surface|volume}\n" | |
737e9a8d | 6525 | " ... [-randColor] [-normals] [-noNormals] [-uv]" |
d33222c1 | 6526 | "\n\t\t: Create arbitrary set of points (npts) randomly distributed" |
6527 | "\n\t\t: on spheric surface or within spheric volume (x y z r)." | |
6528 | "\n\t\t:" | |
6529 | "\n\t\t: Additional options:" | |
6530 | "\n\t\t: -randColor - generate random color per point" | |
6531 | "\n\t\t: -normals - generate normal per point (default)" | |
6532 | "\n\t\t: -noNormals - do not generate normal per point" | |
6533 | "\n", | |
6534 | __FILE__, VPointCloud, group); | |
7d9e854b | 6535 | |
a0c20252 | 6536 | theCommands.Add("vpriority", |
6537 | "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object", | |
6538 | __FILE__, | |
6539 | VPriority, group); | |
68ef63f9 | 6540 | |
6541 | theCommands.Add ("vnormals", | |
6542 | "vnormals usage:\n" | |
6543 | "vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]" | |
6544 | "\n\t\t: [-useMesh] [-oriented {0}1}=0]" | |
6545 | "\n\t\t: Displays/Hides normals calculated on shape geometry or retrieved from triangulation", | |
6546 | __FILE__, VNormals, group); | |
7fd59977 | 6547 | } |