]>
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> |
23fe70ec | 31 | #include <Message.hxx> |
bc001a40 | 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> | |
a577aaab | 134 | #include <Select3D_SensitivePoint.hxx> |
ceae62f0 A |
135 | #include <BRepAdaptor_Curve.hxx> |
136 | #include <StdPrs_Curve.hxx> | |
137 | ||
138 | #include <BRepExtrema_ExtPC.hxx> | |
139 | #include <BRepExtrema_ExtPF.hxx> | |
140 | ||
68ef63f9 | 141 | #include <Prs3d_Arrow.hxx> |
142 | #include <Prs3d_ArrowAspect.hxx> | |
bc001a40 | 143 | #include <Prs3d_DatumAttribute.hxx> |
046a1c9d | 144 | #include <Prs3d_DatumAspect.hxx> |
6262338c | 145 | #include <Prs3d_Drawer.hxx> |
53b15292 | 146 | #include <Prs3d_VertexDrawMode.hxx> |
a2d5ab2e | 147 | #include <Prs3d_LineAspect.hxx> |
a577aaab | 148 | #include <Prs3d_PointAspect.hxx> |
bc001a40 | 149 | #include <Prs3d_Presentation.hxx> |
61b0191c | 150 | #include <Prs3d_TextAspect.hxx> |
113bda70 | 151 | #include <Prs3d_ToolCylinder.hxx> |
152 | #include <Prs3d_ToolSphere.hxx> | |
153 | #include <Prs3d_ToolTorus.hxx> | |
a577aaab | 154 | |
155 | #include <Image_AlienPixMap.hxx> | |
eb4320f2 | 156 | #include <TColStd_HArray1OfAsciiString.hxx> |
046a1c9d | 157 | #include <TColStd_HSequenceOfAsciiString.hxx> |
a2d5ab2e | 158 | |
7fd59977 | 159 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); |
9558a876 A |
160 | extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
161 | const Handle(AIS_InteractiveObject)& theAISObj, | |
162 | Standard_Boolean theReplaceIfExists = Standard_True); | |
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 | }; | |
dae2a922 | 176 | return Draw::ParseColor (theColorValues->Size(), anArgs, theColor) != 0; |
bc001a40 | 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 | { | |
23fe70ec | 313 | Message::SendFail ("Syntax error: -xaxis and -zaxis parameters are to set together"); |
bc001a40 | 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 | { | |
23fe70ec | 338 | Message::SendFail ("Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ"); |
bc001a40 | 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 | { | |
dae2a922 | 360 | Draw::ParseOnOff (aValues->First().ToCString(), toHideLabels); |
fae1ae11 ZA |
361 | } |
362 | else if (aValues->Size() != 0) | |
bc001a40 | 363 | { |
23fe70ec | 364 | Message::SendFail ("Syntax error: -hidelabels expects parameter 'on' or 'off' after"); |
bc001a40 | 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 | { | |
dae2a922 | 380 | Draw::ParseOnOff (aValues->First().ToCString(), toHideArrows); |
fae1ae11 ZA |
381 | } |
382 | else if (aValues->Size() != 0) | |
383 | { | |
23fe70ec | 384 | Message::SendFail ("Syntax error: -hidearrows expects parameter 'on' or 'off' after"); |
fae1ae11 ZA |
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 | { | |
23fe70ec | 400 | Message::SendFail ("Syntax error: -color wrong parameters"); |
bc001a40 | 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 | { | |
23fe70ec | 409 | Message::SendFail ("Syntax error: -color wrong parameters"); |
bc001a40 | 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 | { | |
23fe70ec | 432 | Message::SendFail ("Syntax error: -textcolor wrong parameters"); |
bc001a40 | 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 | { | |
23fe70ec | 443 | Message::SendFail ("Syntax error: -arrowcolor wrong parameters"); |
bc001a40 | 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 | { | |
23fe70ec | 454 | Message::SendFail ("Syntax error: -attribute wrong parameters"); |
bc001a40 | 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 | { | |
23fe70ec | 473 | Message::SendFail ("Syntax error: -priority wrong parameters"); |
bc001a40 | 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 | { | |
23fe70ec | 492 | Message::SendFail ("Syntax error: -labels wrong parameters"); |
bc001a40 | 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 | { | |
23fe70ec | 503 | Message::SendFail ("Syntax error: -drawaxes wrong parameters"); |
bc001a40 | 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 | { | |
23fe70ec | 587 | Message::SendFail() << "Syntax error: wrong number of arguments."; |
404c8936 | 588 | return 1; |
589 | } | |
7fd59977 | 590 | |
404c8936 | 591 | TopTools_ListOfShape aShapes; |
592 | ViewerTest::GetSelectedShapes (aShapes); | |
7fd59977 | 593 | |
404c8936 | 594 | if (aShapes.Extent() != 1) |
595 | { | |
23fe70ec | 596 | Message::SendFail ("Error: wrong number of selected shapes."); |
404c8936 | 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 | { |
23fe70ec | 645 | Message::SendFail ("Syntax error: the wrong number of input parameters"); |
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 | { |
23fe70ec | 663 | Message::SendFail ("Syntax error: no trihedron with this name"); |
bc001a40 | 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 | { | |
23fe70ec | 859 | Message::SendFail ("Error: Wrong number of selected shapes."); |
404c8936 | 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 | { | |
23fe70ec | 868 | Message::SendFail ("Error: Selected shape is not a plane."); |
404c8936 | 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 | { | |
23fe70ec | 938 | Message::SendFail ("Error: Wrong number of selected shapes."); |
404c8936 | 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 | { | |
23fe70ec | 947 | Message::SendFail ("Error: Wrong number of selected shapes."); |
404c8936 | 948 | return 1; |
949 | } | |
7fd59977 | 950 | |
404c8936 | 951 | const TopoDS_Shape& aShapeB = aShapes.Last(); |
952 | if (aShapeB.ShapeType() != TopAbs_VERTEX) | |
953 | { | |
23fe70ec | 954 | Message::SendFail ("Syntax error: You should select two vertices or one edge."); |
404c8936 | 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 | { | |
23fe70ec | 991 | Message::SendFail ("Error: Wrong number of selected shapes."); |
404c8936 | 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 | { | |
23fe70ec | 1000 | Message::SendFail ("Syntax error: You should select face and then vertex."); |
404c8936 | 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 | { | |
23fe70ec | 1024 | Message::SendFail ("Error: Wrong number of selected shapes."); |
404c8936 | 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 | { | |
23fe70ec | 1033 | Message::SendFail ("Syntax error: You should select face and then vertex."); |
404c8936 | 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 | |
2ff1d580 | 1068 | //purpose : |
7fd59977 | 1069 | //============================================================================== |
1070 | #include <TopoDS_Edge.hxx> | |
1071 | #include <TopoDS_Vertex.hxx> | |
1072 | #include <TopExp.hxx> | |
1073 | #include <AIS_Point.hxx> | |
1074 | #include <Geom_CartesianPoint.hxx> | |
1075 | ||
2ff1d580 | 1076 | static int VPointBuilder(Draw_Interpretor& , |
1077 | Standard_Integer theArgNb, | |
1078 | const char** theArgVec) | |
7fd59977 | 1079 | { |
2ff1d580 | 1080 | TCollection_AsciiString aName; |
1081 | gp_Pnt aPnt (RealLast(), 0.0, 0.0); | |
1082 | bool is2d = false, isNoSel = false; | |
1083 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
404c8936 | 1084 | { |
2ff1d580 | 1085 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
1086 | anArg.LowerCase(); | |
1087 | if (anArg == "-2d") | |
1088 | { | |
1089 | is2d = true; | |
1090 | } | |
1091 | else if (anArg == "-nosel" | |
1092 | || anArg == "-noselection") | |
1093 | { | |
1094 | isNoSel = true; | |
1095 | } | |
1096 | else if (aName.IsEmpty()) | |
1097 | { | |
1098 | aName = theArgVec[anArgIter]; | |
1099 | } | |
1100 | else if (aPnt.X() == RealLast() | |
1101 | && anArgIter + 1 < theArgNb | |
1102 | && Draw::ParseReal (theArgVec[anArgIter + 0], aPnt.ChangeCoord().ChangeCoord (1)) | |
1103 | && Draw::ParseReal (theArgVec[anArgIter + 1], aPnt.ChangeCoord().ChangeCoord (2))) | |
1104 | { | |
1105 | if (anArgIter + 2 < theArgNb | |
1106 | && TCollection_AsciiString (theArgVec[anArgIter + 2]) != "-2d" | |
1107 | && Draw::ParseReal (theArgVec[anArgIter + 2], aPnt.ChangeCoord().ChangeCoord (3))) | |
1108 | { | |
1109 | anArgIter += 2; | |
1110 | } | |
1111 | else | |
1112 | { | |
1113 | anArgIter += 1; | |
1114 | } | |
1115 | } | |
1116 | else | |
404c8936 | 1117 | { |
2ff1d580 | 1118 | Message::SendFail() << "Syntax error at argument '" << anArg << "'\n"; |
404c8936 | 1119 | return 1; |
7fd59977 | 1120 | } |
2ff1d580 | 1121 | } |
7fd59977 | 1122 | |
2ff1d580 | 1123 | if (aPnt.X() == RealLast()) |
1124 | { | |
1125 | TopTools_ListOfShape aShapes; | |
1126 | ViewerTest::GetSelectedShapes (aShapes); | |
1127 | TopoDS_Shape aShapeA; | |
1128 | if (aShapes.Extent() == 1) | |
404c8936 | 1129 | { |
2ff1d580 | 1130 | aShapeA = aShapes.First(); |
7fd59977 | 1131 | } |
2ff1d580 | 1132 | switch (!aShapeA.IsNull() ? aShapeA.ShapeType() : TopAbs_SHAPE) |
404c8936 | 1133 | { |
2ff1d580 | 1134 | case TopAbs_VERTEX: |
1135 | { | |
1136 | aPnt = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA)); | |
1137 | break; | |
1138 | } | |
1139 | case TopAbs_EDGE: // edge middle point | |
1140 | { | |
1141 | const TopoDS_Edge& anEdge = TopoDS::Edge (aShapeA); | |
1142 | TopoDS_Vertex aVertPair[2]; | |
1143 | TopExp::Vertices (anEdge, aVertPair[0], aVertPair[1]); | |
1144 | const gp_Pnt A = BRep_Tool::Pnt (aVertPair[0]); | |
1145 | const gp_Pnt B = BRep_Tool::Pnt (aVertPair[1]); | |
1146 | aPnt = (A.XYZ() + B.XYZ()) / 2; | |
1147 | break; | |
1148 | } | |
1149 | default: | |
1150 | { | |
1151 | Message::SendFail() << "Error: Wrong number of selected shapes.\n" | |
1152 | << "\tYou should select one edge or vertex."; | |
1153 | return 1; | |
1154 | } | |
7fd59977 | 1155 | } |
2ff1d580 | 1156 | } |
7fd59977 | 1157 | |
2ff1d580 | 1158 | if (is2d) |
1159 | { | |
1160 | aPnt.SetY (-aPnt.Y()); | |
1161 | } | |
1162 | Handle(Geom_CartesianPoint ) aGeomPoint = new Geom_CartesianPoint (aPnt); | |
1163 | Handle(AIS_Point) aPointPrs = new AIS_Point (aGeomPoint); | |
1164 | if (is2d) | |
1165 | { | |
1166 | aPointPrs->SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_UPPER)); | |
1167 | aPointPrs->SetZLayer (Graphic3d_ZLayerId_TopOSD); | |
1168 | } | |
1169 | ViewerTest::Display (aName, aPointPrs); | |
1170 | if (isNoSel) | |
1171 | { | |
1172 | ViewerTest::GetAISContext()->Deactivate (aPointPrs); | |
7fd59977 | 1173 | } |
1174 | return 0; | |
7fd59977 | 1175 | } |
1176 | ||
1177 | //============================================================================== | |
ceae62f0 | 1178 | // Function 1st click 2de click 3de click |
7fd59977 | 1179 | // vplane Vertex Vertex Vertex |
1180 | // Vertex Edge | |
1181 | // Edge Vertex | |
1182 | // Face | |
1183 | // vplanepara Face Vertex | |
1184 | // Vertex Face | |
1185 | // vplaneortho Face Edge | |
1186 | // Edge Face | |
1187 | //============================================================================== | |
1188 | ||
1189 | //============================================================================== | |
1190 | //function : VPlaneBuilder | |
ceae62f0 | 1191 | //purpose : Build an AIS_Plane from selected entities or Named AIS components |
9e8804b6 | 1192 | //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity] |
1193 | // [PointName] [PointName] [PointName] [TypeOfSensitivity] | |
1194 | // [PlaneName] [PointName] [TypeOfSensitivity] | |
7fd59977 | 1195 | //============================================================================== |
1196 | ||
35e08fe8 | 1197 | static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/, |
ceae62f0 A |
1198 | Standard_Integer argc, |
1199 | const char** argv) | |
7fd59977 | 1200 | { |
1201 | // Declarations | |
ceae62f0 A |
1202 | Standard_Boolean hasArg; |
1203 | TCollection_AsciiString aName; | |
7fd59977 | 1204 | |
1205 | // Verification | |
9e8804b6 | 1206 | if (argc<2 || argc>6 ) |
ceae62f0 | 1207 | { |
23fe70ec | 1208 | Message::SendFail ("Syntax error: wrong number of arguments"); |
ceae62f0 A |
1209 | return 1; |
1210 | } | |
9e8804b6 | 1211 | if (argc == 6 || argc==5 || argc==4) |
ceae62f0 A |
1212 | hasArg=Standard_True; |
1213 | else | |
1214 | hasArg=Standard_False; | |
7fd59977 | 1215 | |
ceae62f0 | 1216 | aName=argv[1]; |
7fd59977 | 1217 | |
ceae62f0 A |
1218 | // There are some arguments |
1219 | if (hasArg) | |
1220 | { | |
8f521168 | 1221 | Handle(AIS_InteractiveObject) aShapeA; |
1222 | if (!GetMapOfAIS().Find2 (argv[2], aShapeA)) | |
ceae62f0 | 1223 | { |
23fe70ec | 1224 | Message::SendFail ("Syntax error: 1st name is not displayed"); |
ceae62f0 A |
1225 | return 1; |
1226 | } | |
7fd59977 | 1227 | |
ceae62f0 A |
1228 | // The first argument is an AIS_Point |
1229 | if (!aShapeA.IsNull() && | |
1230 | aShapeA->Type()==AIS_KOI_Datum && | |
1231 | aShapeA->Signature()==1) | |
1232 | { | |
1233 | // The second argument must also be an AIS_Point | |
8f521168 | 1234 | Handle(AIS_InteractiveObject) aShapeB; |
1235 | if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB)) | |
ceae62f0 | 1236 | { |
23fe70ec | 1237 | Message::SendFail ("Syntax error: 2nd name is not displayed"); |
ceae62f0 A |
1238 | return 1; |
1239 | } | |
ceae62f0 A |
1240 | // If B is not an AIS_Point |
1241 | if (aShapeB.IsNull() || | |
1242 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1243 | { |
23fe70ec | 1244 | Message::SendFail ("Syntax error: 2nd object is expected to be an AIS_Point"); |
7fd59977 | 1245 | return 1; |
1246 | } | |
ceae62f0 | 1247 | // The third object is an AIS_Point |
8f521168 | 1248 | Handle(AIS_InteractiveObject) aShapeC; |
1249 | if (!GetMapOfAIS().Find2(argv[4], aShapeC)) | |
ceae62f0 | 1250 | { |
23fe70ec | 1251 | Message::SendFail ("Syntax error: 3d name is not displayed"); |
ceae62f0 A |
1252 | return 1; |
1253 | } | |
ceae62f0 A |
1254 | // If C is not an AIS_Point |
1255 | if (aShapeC.IsNull() || | |
1256 | (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1))) | |
7fd59977 | 1257 | { |
23fe70ec | 1258 | Message::SendFail ("Syntax error: 3d object is expected to be an AIS_Point"); |
7fd59977 | 1259 | return 1; |
1260 | } | |
1261 | ||
ceae62f0 A |
1262 | // Treatment of objects A, B, C |
1263 | // Downcast an AIS_IO to AIS_Point | |
1264 | Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA); | |
1265 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB); | |
1266 | Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC); | |
7fd59977 | 1267 | |
ceae62f0 A |
1268 | Handle(Geom_CartesianPoint ) aCartPointA = |
1269 | Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component()); | |
7fd59977 | 1270 | |
ceae62f0 A |
1271 | Handle(Geom_CartesianPoint ) aCartPointB = |
1272 | Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component()); | |
7fd59977 | 1273 | |
ceae62f0 A |
1274 | Handle(Geom_CartesianPoint ) aCartPointC = |
1275 | Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component()); | |
7fd59977 | 1276 | |
ceae62f0 | 1277 | // Verification that the three points are different |
91322f44 | 1278 | if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() && |
1279 | Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() && | |
1280 | Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion()) | |
ceae62f0 | 1281 | { |
7fd59977 | 1282 | // B=A |
23fe70ec | 1283 | Message::SendFail ("Error: same points"); |
1284 | return 1; | |
7fd59977 | 1285 | } |
91322f44 | 1286 | if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() && |
1287 | Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() && | |
1288 | Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion()) | |
ceae62f0 | 1289 | { |
7fd59977 | 1290 | // C=A |
23fe70ec | 1291 | Message::SendFail ("Error: same points"); |
1292 | return 1; | |
7fd59977 | 1293 | } |
91322f44 | 1294 | if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() && |
1295 | Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() && | |
1296 | Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion()) | |
ceae62f0 | 1297 | { |
7fd59977 | 1298 | // C=B |
23fe70ec | 1299 | Message::SendFail ("Error: same points"); |
1300 | return 1; | |
7fd59977 | 1301 | } |
1302 | ||
ceae62f0 A |
1303 | gp_Pnt A = aCartPointA->Pnt(); |
1304 | gp_Pnt B = aCartPointB->Pnt(); | |
1305 | gp_Pnt C = aCartPointC->Pnt(); | |
7fd59977 | 1306 | |
ceae62f0 | 1307 | // Construction of AIS_Plane |
7fd59977 | 1308 | GC_MakePlane MkPlane (A,B,C); |
ceae62f0 A |
1309 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); |
1310 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane ); | |
1311 | GetMapOfAIS().Bind (anAISPlane,aName ); | |
9e8804b6 | 1312 | if (argc == 6) |
1313 | { | |
1314 | Standard_Integer aType = Draw::Atoi (argv[5]); | |
1315 | if (aType != 0 && aType != 1) | |
1316 | { | |
23fe70ec | 1317 | Message::SendFail("Syntax error: wrong type of sensitivity.\n" |
1318 | "Should be one of the following values:\n" | |
1319 | "0 - Interior\n" | |
1320 | "1 - Boundary"); | |
9e8804b6 | 1321 | return 1; |
1322 | } | |
1323 | else | |
1324 | { | |
1325 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1326 | } | |
1327 | } | |
0577ae8c | 1328 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1329 | } |
1330 | ||
ceae62f0 A |
1331 | // The first argument is an AIS_Axis |
1332 | // Creation of a plane orthogonal to the axis through a point | |
1333 | else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) { | |
1334 | // The second argument should be an AIS_Point | |
8f521168 | 1335 | Handle(AIS_InteractiveObject) aShapeB; |
1336 | if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB)) | |
7fd59977 | 1337 | { |
23fe70ec | 1338 | Message::SendFail ("Syntax error: 2d name is not displayed"); |
7fd59977 | 1339 | return 1; |
1340 | } | |
ceae62f0 A |
1341 | // If B is not an AIS_Point |
1342 | if (aShapeB.IsNull() || | |
1343 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1344 | { |
23fe70ec | 1345 | Message::SendFail ("Syntax error: 2d object is expected to be an AIS_Point"); |
7fd59977 | 1346 | return 1; |
1347 | } | |
1348 | ||
ceae62f0 A |
1349 | // Treatment of objects A and B |
1350 | Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA); | |
1351 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB); | |
7fd59977 | 1352 | |
ceae62f0 A |
1353 | Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component(); |
1354 | Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ; | |
7fd59977 | 1355 | |
ceae62f0 A |
1356 | gp_Ax1 anAxis = aGeomLineA->Position(); |
1357 | Handle(Geom_CartesianPoint) aCartPointB = | |
1358 | Handle(Geom_CartesianPoint)::DownCast(aGeomPointB); | |
7fd59977 | 1359 | |
ceae62f0 A |
1360 | gp_Dir D =anAxis.Direction(); |
1361 | gp_Pnt B = aCartPointB->Pnt(); | |
7fd59977 | 1362 | |
ceae62f0 A |
1363 | // Construction of AIS_Plane |
1364 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D); | |
1365 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B ); | |
1366 | GetMapOfAIS().Bind (anAISPlane,aName ); | |
9e8804b6 | 1367 | if (argc == 5) |
1368 | { | |
1369 | Standard_Integer aType = Draw::Atoi (argv[4]); | |
1370 | if (aType != 0 && aType != 1) | |
1371 | { | |
23fe70ec | 1372 | Message::SendFail ("Syntax error: wrong type of sensitivity!\n" |
1373 | "Should be one of the following values:\n" | |
1374 | "0 - Interior\n" | |
1375 | "1 - Boundary"); | |
9e8804b6 | 1376 | return 1; |
1377 | } | |
1378 | else | |
1379 | { | |
1380 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1381 | } | |
1382 | } | |
0577ae8c | 1383 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1384 | |
1385 | } | |
ceae62f0 A |
1386 | // The first argumnet is an AIS_Plane |
1387 | // Creation of a plane parallel to the plane passing through the point | |
1388 | else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7) | |
1389 | { | |
1390 | // The second argument should be an AIS_Point | |
8f521168 | 1391 | Handle(AIS_InteractiveObject) aShapeB; |
1392 | if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB)) | |
ceae62f0 | 1393 | { |
23fe70ec | 1394 | Message::SendFail ("Syntax error: 2d name is not displayed"); |
7fd59977 | 1395 | return 1; |
1396 | } | |
ceae62f0 A |
1397 | // B should be an AIS_Point |
1398 | if (aShapeB.IsNull() || | |
1399 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1400 | { |
23fe70ec | 1401 | Message::SendFail ("Syntax error: 2d object is expected to be an AIS_Point"); |
7fd59977 | 1402 | return 1; |
1403 | } | |
1404 | ||
ceae62f0 A |
1405 | // Treatment of objects A and B |
1406 | Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA); | |
1407 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB); | |
7fd59977 | 1408 | |
ceae62f0 A |
1409 | Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component(); |
1410 | Handle(Geom_Point) aGeomPointB = anAISPointB->Component(); | |
7fd59977 | 1411 | |
ceae62f0 A |
1412 | Handle(Geom_CartesianPoint) aCartPointB = |
1413 | Handle(Geom_CartesianPoint)::DownCast(aGeomPointB); | |
1414 | gp_Pnt B= aCartPointB->Pnt(); | |
7fd59977 | 1415 | |
ceae62f0 A |
1416 | // Construction of an AIS_Plane |
1417 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B); | |
1418 | GetMapOfAIS().Bind (anAISPlane, aName); | |
9e8804b6 | 1419 | if (argc == 5) |
1420 | { | |
1421 | Standard_Integer aType = Draw::Atoi (argv[4]); | |
1422 | if (aType != 0 && aType != 1) | |
1423 | { | |
23fe70ec | 1424 | Message::SendFail ("Syntax error: wrong type of sensitivity!\n" |
1425 | "Should be one of the following values:\n" | |
1426 | "0 - Interior\n" | |
1427 | "1 - Boundary"); | |
9e8804b6 | 1428 | return 1; |
1429 | } | |
1430 | else | |
1431 | { | |
1432 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1433 | } | |
1434 | } | |
0577ae8c | 1435 | TheAISContext()->Display (anAISPlane, Standard_True); |
ceae62f0 A |
1436 | } |
1437 | // Error | |
1438 | else | |
1439 | { | |
23fe70ec | 1440 | Message::SendFail ("Syntax error: 1st object is not an AIS"); |
ceae62f0 | 1441 | return 1; |
7fd59977 | 1442 | } |
7fd59977 | 1443 | } |
ceae62f0 A |
1444 | // There are no arguments |
1445 | else | |
1446 | { | |
404c8936 | 1447 | TopTools_ListOfShape aShapes; |
1448 | ViewerTest::GetSelectedShapes (aShapes); | |
1449 | ||
ceae62f0 A |
1450 | // Function vplane |
1451 | // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean ) | |
1452 | if (!strcasecmp(argv[0], "vplane")) | |
1453 | { | |
404c8936 | 1454 | if (aShapes.Extent() < 1 || aShapes.Extent() > 3) |
ceae62f0 | 1455 | { |
23fe70ec | 1456 | Message::SendFail() << "Error: Wront number of selected shapes.\n" |
1457 | << "\tYou should one of variant: face, edge and vertex or three vertices."; | |
404c8936 | 1458 | return 1; |
7fd59977 | 1459 | } |
1460 | ||
404c8936 | 1461 | const TopoDS_Shape& aShapeA = aShapes.First(); |
1462 | if (aShapeA.ShapeType() == TopAbs_VERTEX) | |
ceae62f0 | 1463 | { |
404c8936 | 1464 | if (aShapes.Extent() == 2) |
ceae62f0 | 1465 | { |
404c8936 | 1466 | const TopoDS_Shape& aShapeB = aShapes.Last(); |
1467 | if (aShapeB.ShapeType() != TopAbs_EDGE) | |
ceae62f0 | 1468 | { |
23fe70ec | 1469 | Message::SendFail ("Syntax error: Together with vertex should be edge."); |
ceae62f0 | 1470 | return 1; |
7fd59977 | 1471 | } |
7fd59977 | 1472 | |
ceae62f0 A |
1473 | // Verify that the vertex is not on the edge ShapeB |
1474 | TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB); | |
1475 | TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA); | |
7fd59977 | 1476 | |
ceae62f0 A |
1477 | BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB); |
1478 | if (OrthoProj.SquareDistance(1)<Precision::Approximation()) | |
1479 | { | |
1480 | // The vertex is on the edge | |
23fe70ec | 1481 | Message::SendFail ("Error: point is on the edge"); |
ceae62f0 A |
1482 | return 1; |
1483 | } | |
1484 | else | |
1485 | { | |
ceae62f0 A |
1486 | gp_Pnt A = BRep_Tool::Pnt(aVertA); |
1487 | TopoDS_Vertex aVBa, aVBb; | |
1488 | TopExp::Vertices(anEdgeB ,aVBa ,aVBb); | |
1489 | gp_Pnt aBa = BRep_Tool::Pnt(aVBa); | |
1490 | gp_Pnt aBb = BRep_Tool::Pnt(aVBb); | |
1491 | GC_MakePlane MkPlane (A, aBa, aBb); | |
1492 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1493 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1494 | GetMapOfAIS().Bind (anAISPlane, aName); | |
0577ae8c | 1495 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1496 | } |
7fd59977 | 1497 | } |
404c8936 | 1498 | else if (aShapes.Extent() == 3) |
1499 | { | |
1500 | TopTools_ListOfShape::Iterator anIter (aShapes); | |
1501 | ||
1502 | anIter.Next(); | |
1503 | const TopoDS_Shape& aShapeB = anIter.Value(); | |
1504 | ||
1505 | anIter.Next(); | |
1506 | const TopoDS_Shape& aShapeC = anIter.Value(); | |
1507 | ||
1508 | if (!(aShapeB.ShapeType() == TopAbs_VERTEX | |
1509 | && aShapeC.ShapeType() == TopAbs_VERTEX)) | |
1510 | { | |
23fe70ec | 1511 | Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices."); |
404c8936 | 1512 | return 1; |
1513 | } | |
1514 | ||
1515 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA)); | |
1516 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB)); | |
1517 | gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC)); | |
1518 | GC_MakePlane MkPlane(A, B, C); | |
1519 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1520 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1521 | GetMapOfAIS().Bind (anAISPlane, aName); | |
0577ae8c | 1522 | TheAISContext()->Display (anAISPlane, Standard_True); |
404c8936 | 1523 | } |
1524 | else | |
1525 | { | |
23fe70ec | 1526 | Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices."); |
404c8936 | 1527 | return 1; |
1528 | } | |
7fd59977 | 1529 | } |
404c8936 | 1530 | else if (aShapeA.ShapeType() == TopAbs_EDGE) |
ceae62f0 | 1531 | { |
404c8936 | 1532 | if (aShapes.Extent() != 2) |
ceae62f0 | 1533 | { |
23fe70ec | 1534 | Message::SendFail ("Error: wrong number of selected shapes."); |
404c8936 | 1535 | return 1; |
1536 | } | |
1537 | ||
1538 | const TopoDS_Shape& aShapeB = aShapes.Last(); | |
1539 | if (aShapeB.ShapeType() != TopAbs_VERTEX) | |
1540 | { | |
23fe70ec | 1541 | Message::SendFail ("Syntax error: Together with edge should be vertex."); |
404c8936 | 1542 | return 1; |
7fd59977 | 1543 | } |
404c8936 | 1544 | |
ceae62f0 A |
1545 | // Check that the vertex aShapeB is not on the edge |
1546 | TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA); | |
1547 | TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB); | |
1548 | ||
1549 | BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA); | |
1550 | if (OrthoProj.SquareDistance(1)<Precision::Approximation()) | |
1551 | { | |
1552 | // The vertex is on the edge | |
23fe70ec | 1553 | Message::SendFail ("Error point is on the edge"); |
ceae62f0 | 1554 | return 1; |
7fd59977 | 1555 | } |
404c8936 | 1556 | |
1557 | gp_Pnt B = BRep_Tool::Pnt(aVertB); | |
1558 | TopoDS_Vertex aVAa, aVAb; | |
1559 | TopExp::Vertices(anEdgeA, aVAa, aVAb); | |
1560 | gp_Pnt Aa = BRep_Tool::Pnt(aVAa); | |
1561 | gp_Pnt Ab = BRep_Tool::Pnt(aVAb); | |
1562 | GC_MakePlane MkPlane (B,Aa,Ab); | |
1563 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1564 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1565 | GetMapOfAIS().Bind (anAISPlane ,aName); | |
0577ae8c | 1566 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1567 | } |
404c8936 | 1568 | else if (aShapeA.ShapeType() == TopAbs_FACE) |
ceae62f0 | 1569 | { |
ceae62f0 A |
1570 | TopoDS_Face aFace = TopoDS::Face(aShapeA); |
1571 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1572 | if (aSurface.GetType()==GeomAbs_Plane) | |
1573 | { | |
1574 | gp_Pln aPlane = aSurface.Plane(); | |
1575 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane); | |
1576 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane); | |
1577 | GetMapOfAIS().Bind (anAISPlane, aName); | |
0577ae8c | 1578 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1579 | } |
ceae62f0 A |
1580 | else |
1581 | { | |
23fe70ec | 1582 | Message::SendFail ("Error: surface is not Plane"); |
ceae62f0 | 1583 | return 1; |
7fd59977 | 1584 | } |
7fd59977 | 1585 | } |
404c8936 | 1586 | else |
1587 | { | |
23fe70ec | 1588 | Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices"); |
404c8936 | 1589 | return 1; |
1590 | } | |
7fd59977 | 1591 | } |
1592 | ||
ceae62f0 | 1593 | // Function vPlanePara |
7fd59977 | 1594 | // =================== |
ceae62f0 A |
1595 | // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt) |
1596 | else if (!strcasecmp(argv[0], "vplanepara")) | |
1597 | { | |
404c8936 | 1598 | if (aShapes.Extent() != 2) |
ceae62f0 | 1599 | { |
23fe70ec | 1600 | Message::SendFail ("Error: Wrong number of selected shapes."); |
404c8936 | 1601 | return 1; |
7fd59977 | 1602 | } |
1603 | ||
404c8936 | 1604 | const TopoDS_Shape* aShapeA = &aShapes.First(); |
1605 | const TopoDS_Shape* aShapeB = &aShapes.Last(); | |
1606 | if (aShapeA->ShapeType() != TopAbs_VERTEX) | |
ceae62f0 | 1607 | { |
404c8936 | 1608 | std::swap (aShapeA, aShapeB); |
1609 | } | |
7fd59977 | 1610 | |
404c8936 | 1611 | if (!(aShapeA->ShapeType() == TopAbs_VERTEX |
1612 | && aShapeB->ShapeType() == TopAbs_FACE)) | |
1613 | { | |
23fe70ec | 1614 | Message::SendFail ("Syntax error: you should select face and vertex."); |
404c8936 | 1615 | return 1; |
1616 | } | |
7fd59977 | 1617 | |
404c8936 | 1618 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA)); |
ceae62f0 | 1619 | |
404c8936 | 1620 | TopoDS_Face aFace = TopoDS::Face(*aShapeB); |
1621 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1622 | if (aSurface.GetType() == GeomAbs_Plane) | |
1623 | { | |
1624 | gp_Pln aPlane = aSurface.Plane(); | |
1625 | // Construct a plane parallel to aGeomPlane through A | |
1626 | aPlane.SetLocation(A); | |
1627 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1628 | Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A); | |
1629 | GetMapOfAIS().Bind (aAISPlane ,aName); | |
0577ae8c | 1630 | TheAISContext()->Display (aAISPlane, Standard_True); |
7fd59977 | 1631 | } |
ceae62f0 A |
1632 | else |
1633 | { | |
23fe70ec | 1634 | Message::SendFail ("Error: Builded surface is not a plane."); |
404c8936 | 1635 | return 1; |
7fd59977 | 1636 | } |
7fd59977 | 1637 | } |
1638 | ||
ceae62f0 | 1639 | // Function vplaneortho |
7fd59977 | 1640 | // ==================== |
ceae62f0 A |
1641 | // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt) |
1642 | else | |
1643 | { | |
404c8936 | 1644 | if (aShapes.Extent() != 2) |
ceae62f0 | 1645 | { |
23fe70ec | 1646 | Message::SendFail ("Error: wrong number of selected shapes."); |
404c8936 | 1647 | return 1; |
7fd59977 | 1648 | } |
1649 | ||
404c8936 | 1650 | const TopoDS_Shape* aShapeA = &aShapes.First(); |
1651 | const TopoDS_Shape* aShapeB = &aShapes.Last(); | |
7fd59977 | 1652 | |
404c8936 | 1653 | if (aShapeA->ShapeType() != TopAbs_EDGE) |
1654 | { | |
1655 | std::swap (aShapeA, aShapeB); | |
1656 | } | |
7fd59977 | 1657 | |
404c8936 | 1658 | if (!(aShapeA->ShapeType() == TopAbs_EDGE |
1659 | && aShapeB->ShapeType() == TopAbs_FACE)) | |
1660 | { | |
23fe70ec | 1661 | Message::SendFail ("Error: you should select edge and face."); |
404c8936 | 1662 | return 1; |
1663 | } | |
ceae62f0 | 1664 | |
404c8936 | 1665 | // Construction of plane |
1666 | TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA); | |
1667 | TopoDS_Vertex aVAa, aVAb; | |
1668 | TopExp::Vertices(anEdgeA, aVAa, aVAb); | |
1669 | gp_Pnt Aa = BRep_Tool::Pnt(aVAa); | |
1670 | gp_Pnt Ab = BRep_Tool::Pnt(aVAb); | |
1671 | gp_Vec ab (Aa,Ab); | |
1672 | ||
1673 | gp_Dir Dab (ab); | |
1674 | // Creation of rotation axis | |
1675 | gp_Ax1 aRotAxis (Aa,Dab); | |
1676 | ||
1677 | TopoDS_Face aFace = TopoDS::Face(*aShapeB); | |
1678 | // The edge must be parallel to the face | |
1679 | BRepExtrema_ExtPF aHeightA (aVAa, aFace); | |
1680 | BRepExtrema_ExtPF aHeightB (aVAb, aFace); | |
1681 | // Compare to heights | |
1682 | if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1))) | |
1683 | >Precision::Confusion()) | |
1684 | { | |
1685 | // the edge is not parallel to the face | |
23fe70ec | 1686 | Message::SendFail ("Error: the edge is not parallel to the face"); |
404c8936 | 1687 | return 1; |
1688 | } | |
1689 | // the edge is OK | |
1690 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1691 | if (aSurface.GetType()==GeomAbs_Plane) | |
1692 | { | |
1693 | gp_Pln aPlane = aSurface.Plane(); | |
1694 | // It rotates a half turn round the axis of rotation | |
1695 | aPlane.Rotate(aRotAxis , M_PI/2); | |
1696 | ||
1697 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1698 | // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge) | |
1699 | gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 ); | |
1700 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle); | |
1701 | GetMapOfAIS().Bind (anAISPlane, aName); | |
0577ae8c | 1702 | TheAISContext()->Display (anAISPlane, Standard_True); |
7fd59977 | 1703 | } |
ceae62f0 A |
1704 | else |
1705 | { | |
23fe70ec | 1706 | Message::SendFail ("Error: surface is not Plane"); |
404c8936 | 1707 | return 1; |
7fd59977 | 1708 | } |
7fd59977 | 1709 | } |
7fd59977 | 1710 | } |
1711 | return 0; | |
7fd59977 | 1712 | } |
1713 | ||
f3889691 | 1714 | //=============================================================================================== |
1715 | //function : VChangePlane | |
1716 | //purpose : | |
1717 | //=============================================================================================== | |
1718 | static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) | |
1719 | { | |
1720 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
1721 | if (aContextAIS.IsNull()) | |
1722 | { | |
23fe70ec | 1723 | Message::SendFail ("Error: no active viewer."); |
f3889691 | 1724 | return 1; |
1725 | } | |
1726 | ||
1727 | if (theArgsNb < 3 || theArgsNb > 11) | |
1728 | { | |
23fe70ec | 1729 | Message::SendFail ("Syntax error: wrong number of arguments."); |
f3889691 | 1730 | return 1; |
1731 | } | |
1732 | ||
1733 | TCollection_AsciiString aName (theArgVec[1]); | |
1734 | ||
1735 | Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName) | |
1736 | ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName)) | |
1737 | : NULL; | |
1738 | ||
1739 | if ( aPlane.IsNull() ) | |
1740 | { | |
23fe70ec | 1741 | Message::SendFail() << "Syntax error: there is no interactive plane with the given name '" << aName << "'."; |
f3889691 | 1742 | return 1; |
1743 | } | |
1744 | ||
1745 | Standard_Real aCenterX = aPlane->Center().X(); | |
1746 | Standard_Real aCenterY = aPlane->Center().Y(); | |
1747 | Standard_Real aCenterZ = aPlane->Center().Z(); | |
1748 | ||
1749 | Standard_Real aDirX = aPlane->Component()->Axis().Direction().X(); | |
1750 | Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y(); | |
1751 | Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z(); | |
1752 | ||
1753 | Standard_Real aSizeX = 0.0; | |
1754 | Standard_Real aSizeY = 0.0; | |
1755 | aPlane->Size (aSizeX, aSizeY); | |
1756 | Standard_Boolean isUpdate = Standard_True; | |
1757 | ||
1758 | TCollection_AsciiString aPName, aPValue; | |
1759 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
1760 | { | |
1761 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; | |
1762 | TCollection_AsciiString anArgCase = anArg; | |
1763 | anArgCase.UpperCase(); | |
1764 | if (ViewerTest::SplitParameter (anArg, aPName, aPValue)) | |
1765 | { | |
1766 | aPName.UpperCase(); | |
1767 | if (aPName.IsEqual ("X")) | |
1768 | { | |
1769 | aCenterX = aPValue.RealValue(); | |
1770 | } | |
1771 | else if (aPName.IsEqual ("Y")) | |
1772 | { | |
1773 | aCenterY = aPValue.RealValue(); | |
1774 | } | |
1775 | else if (aPName.IsEqual ("Z")) | |
1776 | { | |
1777 | aCenterZ = aPValue.RealValue(); | |
1778 | } | |
1779 | else if (aPName.IsEqual ("DX")) | |
1780 | { | |
1781 | aDirX = aPValue.RealValue(); | |
1782 | } | |
1783 | else if (aPName.IsEqual ("DY")) | |
1784 | { | |
1785 | aDirY = aPValue.RealValue(); | |
1786 | } | |
1787 | else if (aPName.IsEqual ("DZ")) | |
1788 | { | |
1789 | aDirZ = aPValue.RealValue(); | |
1790 | } | |
1791 | else if (aPName.IsEqual ("SX")) | |
1792 | { | |
1793 | aSizeX = aPValue.RealValue(); | |
1794 | } | |
1795 | else if (aPName.IsEqual ("SY")) | |
1796 | { | |
1797 | aSizeY = aPValue.RealValue(); | |
1798 | } | |
1799 | } | |
1800 | else if (anArg.IsEqual ("NOUPDATE")) | |
1801 | { | |
1802 | isUpdate = Standard_False; | |
1803 | } | |
1804 | } | |
1805 | ||
1806 | gp_Dir aDirection (aDirX, aDirY, aDirZ); | |
1807 | gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ); | |
1808 | aPlane->SetCenter (aCenterPnt); | |
1809 | aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection)); | |
1810 | aPlane->SetSize (aSizeX, aSizeY); | |
1811 | ||
f751596e | 1812 | aContextAIS->Update (aPlane, isUpdate); |
f3889691 | 1813 | |
1814 | return 0; | |
1815 | } | |
7fd59977 | 1816 | |
1817 | //============================================================================== | |
1818 | // Fonction vline | |
1819 | // --------------- Uniquement par parametre. Pas de selection dans le viewer. | |
1820 | //============================================================================== | |
1821 | ||
1822 | //============================================================================== | |
1823 | //function : VLineBuilder | |
161c4476 | 1824 | //purpose : Build an AIS_Line |
7fd59977 | 1825 | //Draw arg : vline LineName [AIS_PointName] [AIS_PointName] |
1826 | // [Xa] [Ya] [Za] [Xb] [Yb] [Zb] | |
1827 | //============================================================================== | |
1828 | #include <Geom_CartesianPoint.hxx> | |
1829 | #include <AIS_Line.hxx> | |
1830 | ||
1831 | ||
161c4476 | 1832 | static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1833 | { |
7fd59977 | 1834 | // Verifications |
586db386 | 1835 | if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; } |
7fd59977 | 1836 | |
1837 | // On recupere les parametres | |
1838 | Handle(AIS_InteractiveObject) theShapeA; | |
1839 | Handle(AIS_InteractiveObject) theShapeB; | |
1840 | ||
1841 | // Parametres: AIS_Point AIS_Point | |
1842 | // =============================== | |
1843 | if (argc==4) { | |
8f521168 | 1844 | GetMapOfAIS().Find2 (argv[2], theShapeA); |
7fd59977 | 1845 | // On verifie que c'est bien une AIS_Point |
1846 | if (!theShapeA.IsNull() && | |
1847 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) { | |
1848 | // on recupere le deuxieme AIS_Point | |
8f521168 | 1849 | GetMapOfAIS().Find2 (argv[3], theShapeB); |
1850 | if (theShapeB.IsNull() || | |
7fd59977 | 1851 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) |
1852 | { | |
586db386 | 1853 | di <<"vline error: wrong type of 2de argument.\n"; |
7fd59977 | 1854 | return 1; |
1855 | } | |
1856 | } | |
586db386 | 1857 | else {di <<"vline error: wrong type of 1st argument.\n";return 1; } |
7fd59977 | 1858 | // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus |
c5f3a425 | 1859 | Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA); |
1860 | Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB); | |
7fd59977 | 1861 | |
1862 | Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component(); | |
c5f3a425 | 1863 | Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA); |
7fd59977 | 1864 | // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ; |
1865 | ||
1866 | Handle(Geom_Point ) myGeomPointB= theAISPointB->Component(); | |
c5f3a425 | 1867 | Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB); |
7fd59977 | 1868 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ; |
1869 | ||
1870 | if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) { | |
1871 | // B=A | |
586db386 | 1872 | di<<"vline error: same points\n";return 1; |
7fd59977 | 1873 | } |
1874 | // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB) | |
1875 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1876 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
0577ae8c | 1877 | TheAISContext()->Display (theAISLine, Standard_True); |
7fd59977 | 1878 | |
1879 | } | |
1880 | ||
1881 | // Parametres 6 Reals | |
1882 | // ================== | |
1883 | ||
1884 | else if (argc==8) { | |
161c4476 | 1885 | // On verifie que les deux points ne sont pas confondus |
7fd59977 | 1886 | |
1887 | Standard_Real coord[6]; | |
1888 | for(Standard_Integer i=0;i<=2;i++){ | |
91322f44 | 1889 | coord[i]=Draw::Atof(argv[2+i]); |
1890 | coord[i+3]=Draw::Atof(argv[5+i]); | |
7fd59977 | 1891 | } |
1892 | ||
1893 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] ); | |
1894 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] ); | |
1895 | ||
1896 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1897 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
0577ae8c | 1898 | TheAISContext()->Display (theAISLine, Standard_True); |
7fd59977 | 1899 | |
1900 | } | |
1901 | ||
1902 | // Pas de parametres: Selection dans le viewer. | |
1903 | // ============================================ | |
1904 | ||
404c8936 | 1905 | else |
1906 | { | |
1907 | TopTools_ListOfShape aShapes; | |
1908 | ViewerTest::GetSelectedShapes (aShapes); | |
1909 | if (aShapes.Extent() != 2) | |
1910 | { | |
23fe70ec | 1911 | Message::SendFail ("Error: wrong number of selected shapes."); |
404c8936 | 1912 | return 1; |
7fd59977 | 1913 | } |
1914 | ||
404c8936 | 1915 | const TopoDS_Shape& aShapeA = aShapes.First(); |
1916 | const TopoDS_Shape& aShapeB = aShapes.Last(); | |
7fd59977 | 1917 | |
404c8936 | 1918 | if (!(aShapeA.ShapeType() == TopAbs_VERTEX |
1919 | && aShapeB.ShapeType() == TopAbs_VERTEX)) | |
1920 | { | |
23fe70ec | 1921 | Message::SendFail ("Error: you should select two different vertex."); |
404c8936 | 1922 | return 1; |
1923 | } | |
7fd59977 | 1924 | |
404c8936 | 1925 | // Construction de la line |
1926 | gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA)); | |
1927 | gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB)); | |
7fd59977 | 1928 | |
404c8936 | 1929 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A); |
1930 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B); | |
7fd59977 | 1931 | |
404c8936 | 1932 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); |
1933 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
0577ae8c | 1934 | TheAISContext()->Display (theAISLine, Standard_True); |
7fd59977 | 1935 | } |
1936 | ||
1937 | return 0; | |
1938 | } | |
1939 | ||
329843e2 A |
1940 | //============================================================================== |
1941 | // class : FilledCircle | |
1942 | // purpose : creates filled circle based on AIS_InteractiveObject | |
1943 | // and Geom_Circle. | |
1944 | // This class is used to check method Matches() of class | |
1945 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True, | |
1946 | // because none of AIS classes provides creation of | |
1947 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True | |
1948 | // (look method ComputeSelection() ) | |
1949 | //============================================================================== | |
1950 | ||
1951 | Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
1952 | { | |
1953 | gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.))); | |
1954 | gp_Circ aCirc(anAxes, theRadius); | |
1955 | Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc); | |
1956 | return aCircle; | |
1957 | } | |
1958 | ||
329843e2 A |
1959 | class FilledCircle : public AIS_InteractiveObject |
1960 | { | |
1961 | public: | |
1962 | // CASCADE RTTI | |
92efcf78 | 1963 | DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject); |
329843e2 A |
1964 | |
1965 | FilledCircle(gp_Pnt theCenter, Standard_Real theRadius); | |
1966 | FilledCircle(Handle(Geom_Circle) theCircle); | |
1967 | ||
1968 | private: | |
1969 | TopoDS_Face ComputeFace(); | |
1970 | ||
1971 | // Virtual methods implementation | |
1972 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
1973 | const Handle(Prs3d_Presentation)& thePresentation, | |
79104795 | 1974 | const Standard_Integer theMode) Standard_OVERRIDE; |
329843e2 A |
1975 | |
1976 | void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, | |
79104795 | 1977 | const Standard_Integer theMode) Standard_OVERRIDE; |
329843e2 A |
1978 | |
1979 | protected: | |
1980 | Handle(Geom_Circle) myCircle; | |
1981 | Standard_Boolean myFilledStatus; | |
1982 | ||
1983 | }; | |
1984 | ||
329843e2 A |
1985 | |
1986 | FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
1987 | { | |
1988 | myCircle = CreateCircle(theCenter, theRadius); | |
1989 | myFilledStatus = Standard_True; | |
1990 | } | |
1991 | ||
1992 | FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle) | |
1993 | { | |
1994 | myCircle = theCircle; | |
1995 | myFilledStatus = Standard_True; | |
1996 | } | |
1997 | ||
1998 | TopoDS_Face FilledCircle::ComputeFace() | |
1999 | { | |
2000 | // Create edge from myCircle | |
2001 | BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ()); | |
2002 | TopoDS_Edge anEdge = anEdgeMaker.Edge(); | |
2003 | ||
2004 | // Create wire from anEdge | |
2005 | BRepBuilderAPI_MakeWire aWireMaker(anEdge); | |
2006 | TopoDS_Wire aWire = aWireMaker.Wire(); | |
2007 | ||
2008 | // Create face from aWire | |
2009 | BRepBuilderAPI_MakeFace aFaceMaker(aWire); | |
2010 | TopoDS_Face aFace = aFaceMaker.Face(); | |
2011 | ||
2012 | return aFace; | |
2013 | } | |
2014 | ||
857ffd5e | 2015 | void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/, |
2016 | const Handle(Prs3d_Presentation) &thePresentation, | |
329843e2 A |
2017 | const Standard_Integer theMode) |
2018 | { | |
2019 | thePresentation->Clear(); | |
2020 | ||
2021 | TopoDS_Face aFace = ComputeFace(); | |
2022 | ||
2023 | if (aFace.IsNull()) return; | |
2024 | if (theMode != 0) return; | |
2025 | ||
2026 | StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer); | |
2027 | } | |
2028 | ||
857ffd5e | 2029 | void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection, |
35e08fe8 | 2030 | const Standard_Integer /*theMode*/) |
329843e2 A |
2031 | { |
2032 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this); | |
7f24b768 | 2033 | Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle (anEntityOwner, myCircle->Circ(), myFilledStatus); |
329843e2 A |
2034 | theSelection->Add(aSensitiveCircle); |
2035 | } | |
7fd59977 | 2036 | |
2037 | //============================================================================== | |
2038 | // Fonction vcircle | |
2039 | // ----------------- Uniquement par parametre. Pas de selection dans le viewer. | |
2040 | //============================================================================== | |
2041 | ||
2042 | //============================================================================== | |
2043 | //function : VCircleBuilder | |
161c4476 | 2044 | //purpose : Build an AIS_Circle |
329843e2 A |
2045 | //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled |
2046 | // PointName PointName PointName IsFilled | |
7fd59977 | 2047 | //============================================================================== |
329843e2 A |
2048 | |
2049 | void DisplayCircle (Handle (Geom_Circle) theGeomCircle, | |
2050 | TCollection_AsciiString theName, | |
2051 | Standard_Boolean isFilled) | |
2052 | { | |
2053 | Handle(AIS_InteractiveObject) aCircle; | |
2054 | if (isFilled) | |
2055 | { | |
2056 | aCircle = new FilledCircle(theGeomCircle); | |
2057 | } | |
2058 | else | |
2059 | { | |
2060 | aCircle = new AIS_Circle(theGeomCircle); | |
9e8804b6 | 2061 | Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False); |
329843e2 A |
2062 | } |
2063 | ||
2064 | // Check if there is an object with given name | |
2065 | // and remove it from context | |
2066 | if (GetMapOfAIS().IsBound2(theName)) | |
2067 | { | |
8f521168 | 2068 | Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName); |
329843e2 A |
2069 | TheAISContext()->Remove(anInterObj, Standard_False); |
2070 | GetMapOfAIS().UnBind2(theName); | |
2071 | } | |
2072 | ||
2073 | // Bind the circle to its name | |
2074 | GetMapOfAIS().Bind(aCircle, theName); | |
2075 | ||
2076 | // Display the circle | |
0577ae8c | 2077 | TheAISContext()->Display (aCircle, Standard_True); |
329843e2 A |
2078 | |
2079 | } | |
7fd59977 | 2080 | |
35e08fe8 | 2081 | static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv) |
7fd59977 | 2082 | { |
329843e2 A |
2083 | // Verification of the arguments |
2084 | if (argc>6 || argc<2) | |
2085 | { | |
23fe70ec | 2086 | Message::SendFail ("Syntax error: wrong number of arguments"); |
2087 | return 1; | |
329843e2 | 2088 | } |
7fd59977 | 2089 | |
329843e2 A |
2090 | // There are all arguments |
2091 | if (argc == 6) | |
2092 | { | |
2093 | // Get arguments | |
2094 | TCollection_AsciiString aName(argv[1]); | |
dde68833 | 2095 | Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0; |
329843e2 | 2096 | |
8f521168 | 2097 | Handle(AIS_InteractiveObject) theShapeA, theShapeB; |
2098 | GetMapOfAIS().Find2 (argv[2], theShapeA); | |
2099 | GetMapOfAIS().Find2 (argv[3], theShapeB); | |
7fd59977 | 2100 | |
2101 | // Arguments: AIS_Point AIS_Point AIS_Point | |
2102 | // ======================================== | |
329843e2 | 2103 | if (!theShapeA.IsNull() && !theShapeB.IsNull() && |
7fd59977 | 2104 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) |
2105 | { | |
329843e2 A |
2106 | if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) |
2107 | { | |
23fe70ec | 2108 | Message::SendFail ("Error: 2d argument is unexpected to be a point"); |
2109 | return 1; | |
7fd59977 | 2110 | } |
329843e2 | 2111 | // The third object must be a point |
8f521168 | 2112 | Handle(AIS_InteractiveObject) theShapeC; |
2113 | GetMapOfAIS().Find2 (argv[4], theShapeC); | |
7fd59977 | 2114 | if (theShapeC.IsNull() || |
329843e2 A |
2115 | theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) |
2116 | { | |
23fe70ec | 2117 | Message::SendFail ("Error: 3d argument is unexpected to be a point"); |
2118 | return 1; | |
329843e2 | 2119 | } |
7fd59977 | 2120 | // tag |
329843e2 A |
2121 | // Verify that the three points are different |
2122 | Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA); | |
2123 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
2124 | Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC); | |
2125 | ||
2126 | Handle(Geom_Point) myGeomPointA = theAISPointA->Component(); | |
2127 | Handle(Geom_CartesianPoint) myCartPointA = | |
2128 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointA); | |
2129 | ||
2130 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
2131 | Handle(Geom_CartesianPoint) myCartPointB = | |
2132 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
2133 | ||
2134 | Handle(Geom_Point) myGeomPointC = theAISPointC->Component(); | |
2135 | Handle(Geom_CartesianPoint) myCartPointC = | |
2136 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointC); | |
7fd59977 | 2137 | |
2138 | // Test A=B | |
91322f44 | 2139 | if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() && |
2140 | Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() && | |
2141 | Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() ) | |
329843e2 | 2142 | { |
23fe70ec | 2143 | Message::SendFail ("Error: Same points"); |
2144 | return 1; | |
7fd59977 | 2145 | } |
2146 | // Test A=C | |
91322f44 | 2147 | if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() && |
2148 | Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
2149 | Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
329843e2 | 2150 | { |
23fe70ec | 2151 | Message::SendFail ("Error: Same points"); |
2152 | return 1; | |
7fd59977 | 2153 | } |
2154 | // Test B=C | |
91322f44 | 2155 | if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() && |
2156 | Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
2157 | Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
329843e2 | 2158 | { |
23fe70ec | 2159 | Message::SendFail ("Error: Same points"); |
2160 | return 1; | |
7fd59977 | 2161 | } |
329843e2 A |
2162 | // Construction of the circle |
2163 | GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(), | |
2164 | myCartPointB->Pnt(), myCartPointC->Pnt() ); | |
2165 | Handle (Geom_Circle) theGeomCircle; | |
2166 | try | |
2167 | { | |
2168 | theGeomCircle = Cir.Value(); | |
2169 | } | |
a738b534 | 2170 | catch (StdFail_NotDone const&) |
329843e2 | 2171 | { |
23fe70ec | 2172 | Message::SendFail ("Error: can't create circle"); |
2173 | return -1; | |
329843e2 | 2174 | } |
23fe70ec | 2175 | |
329843e2 | 2176 | DisplayCircle(theGeomCircle, aName, isFilled); |
7fd59977 | 2177 | } |
2178 | ||
329843e2 | 2179 | // Arguments: AIS_Plane AIS_Point Real |
7fd59977 | 2180 | // =================================== |
329843e2 A |
2181 | else if (theShapeA->Type() == AIS_KOI_Datum && |
2182 | theShapeA->Signature() == 7 ) | |
2183 | { | |
2184 | if (theShapeB->Type() != AIS_KOI_Datum || | |
2185 | theShapeB->Signature() != 1 ) | |
2186 | { | |
23fe70ec | 2187 | Message::SendFail ("Error: 2d element is a unexpected to be a point"); |
2188 | return 1; | |
329843e2 | 2189 | } |
623c29a5 | 2190 | // Check that the radius is >= 0 |
91322f44 | 2191 | if (Draw::Atof(argv[4]) <= 0 ) |
329843e2 | 2192 | { |
23fe70ec | 2193 | Message::SendFail ("Syntax error: the radius must be >=0"); |
2194 | return 1; | |
7fd59977 | 2195 | } |
7fd59977 | 2196 | |
329843e2 A |
2197 | // Recover the normal to the plane |
2198 | Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA); | |
2199 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
7fd59977 | 2200 | |
329843e2 A |
2201 | Handle(Geom_Plane) myGeomPlane = theAISPlane->Component(); |
2202 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
2203 | Handle(Geom_CartesianPoint) myCartPointB = | |
2204 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
7fd59977 | 2205 | |
2206 | gp_Pln mygpPlane = myGeomPlane->Pln(); | |
2207 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
2208 | gp_Dir theDir = thegpAxe.Direction(); | |
329843e2 | 2209 | gp_Pnt theCenter = myCartPointB->Pnt(); |
91322f44 | 2210 | Standard_Real TheR = Draw::Atof(argv[4]); |
329843e2 A |
2211 | GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR); |
2212 | Handle (Geom_Circle) theGeomCircle; | |
2213 | try | |
2214 | { | |
2215 | theGeomCircle = Cir.Value(); | |
2216 | } | |
a738b534 | 2217 | catch (StdFail_NotDone const&) |
329843e2 | 2218 | { |
23fe70ec | 2219 | Message::SendFail ("Error: can't create circle"); |
2220 | return -1; | |
329843e2 A |
2221 | } |
2222 | ||
2223 | DisplayCircle(theGeomCircle, aName, isFilled); | |
7fd59977 | 2224 | |
2225 | } | |
2226 | ||
2227 | // Error | |
329843e2 A |
2228 | else |
2229 | { | |
23fe70ec | 2230 | Message::SendFail ("Error: 1st argument has an unexpected type"); |
2231 | return 1; | |
7fd59977 | 2232 | } |
2233 | ||
2234 | } | |
329843e2 | 2235 | // No arguments: selection in the viewer |
7fd59977 | 2236 | // ========================================= |
329843e2 A |
2237 | else |
2238 | { | |
2239 | // Get the name of the circle | |
2240 | TCollection_AsciiString aName(argv[1]); | |
7fd59977 | 2241 | |
404c8936 | 2242 | TopTools_ListOfShape aShapes; |
2243 | ViewerTest::GetSelectedShapes (aShapes); | |
2244 | if (aShapes.Extent() != 3 && aShapes.Extent() != 2) | |
329843e2 | 2245 | { |
23fe70ec | 2246 | Message::SendFail ("Error: Wrong number of selected shapes."); |
404c8936 | 2247 | return 1; |
7fd59977 | 2248 | } |
2249 | ||
404c8936 | 2250 | const TopoDS_Shape& aShapeA = aShapes.First(); |
2251 | if (aShapeA.ShapeType() == TopAbs_VERTEX ) | |
329843e2 | 2252 | { |
404c8936 | 2253 | if (aShapes.Extent() != 3) |
329843e2 | 2254 | { |
23fe70ec | 2255 | Message::SendFail ("Error: wrong number of selected shapes."); |
404c8936 | 2256 | return 1; |
2257 | } | |
7fd59977 | 2258 | |
404c8936 | 2259 | TopTools_ListOfShape::Iterator anIter (aShapes); |
2260 | ||
2261 | anIter.Next(); | |
2262 | const TopoDS_Shape& aShapeB = anIter.Value(); | |
2263 | ||
2264 | anIter.Next(); | |
2265 | const TopoDS_Shape& aShapeC = anIter.Value(); | |
329843e2 A |
2266 | |
2267 | // Get isFilled | |
2268 | Standard_Boolean isFilled; | |
2269 | std::cout << "Enter filled status (0 or 1)\n"; | |
04232180 | 2270 | std::cin >> isFilled; |
7fd59977 | 2271 | |
329843e2 | 2272 | // Construction of the circle |
404c8936 | 2273 | gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA)); |
2274 | gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB)); | |
2275 | gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC)); | |
329843e2 A |
2276 | |
2277 | GC_MakeCircle Cir = GC_MakeCircle (A, B, C); | |
2278 | Handle (Geom_Circle) theGeomCircle; | |
2279 | try | |
2280 | { | |
2281 | theGeomCircle = Cir.Value(); | |
2282 | } | |
a738b534 | 2283 | catch (StdFail_NotDone const&) |
329843e2 | 2284 | { |
23fe70ec | 2285 | Message::SendFail ("Error: can't create circle"); |
2286 | return -1; | |
329843e2 | 2287 | } |
7fd59977 | 2288 | |
329843e2 | 2289 | DisplayCircle(theGeomCircle, aName, isFilled); |
7fd59977 | 2290 | |
2291 | } | |
404c8936 | 2292 | else if (aShapeA.ShapeType() == TopAbs_FACE) |
329843e2 | 2293 | { |
404c8936 | 2294 | const TopoDS_Shape& aShapeB = aShapes.Last(); |
7fd59977 | 2295 | |
329843e2 A |
2296 | // Recover the radius |
2297 | Standard_Real theRad; | |
2298 | do | |
2299 | { | |
2300 | std::cout << " Enter the value of the radius:\n"; | |
04232180 | 2301 | std::cin >> theRad; |
329843e2 A |
2302 | } while (theRad <= 0); |
2303 | ||
2304 | // Get filled status | |
2305 | Standard_Boolean isFilled; | |
2306 | std::cout << "Enter filled status (0 or 1)\n"; | |
04232180 | 2307 | std::cin >> isFilled; |
7fd59977 | 2308 | |
329843e2 | 2309 | // Recover the normal to the plane. tag |
404c8936 | 2310 | TopoDS_Face myFace = TopoDS::Face(aShapeA); |
329843e2 A |
2311 | BRepAdaptor_Surface mySurface (myFace, Standard_False); |
2312 | gp_Pln myPlane = mySurface.Plane(); | |
2313 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane); | |
7fd59977 | 2314 | gp_Pln mygpPlane = theGeomPlane->Pln(); |
2315 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
2316 | gp_Dir theDir = thegpAxe.Direction(); | |
2317 | ||
329843e2 | 2318 | // Recover the center |
404c8936 | 2319 | gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB)); |
7fd59977 | 2320 | |
623c29a5 | 2321 | // Construct the circle |
329843e2 A |
2322 | GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad); |
2323 | Handle (Geom_Circle) theGeomCircle; | |
2324 | try | |
2325 | { | |
2326 | theGeomCircle = Cir.Value(); | |
2327 | } | |
a738b534 | 2328 | catch (StdFail_NotDone const&) |
329843e2 | 2329 | { |
23fe70ec | 2330 | Message::SendFail ("Error: can't create circle"); |
2331 | return -1; | |
329843e2 | 2332 | } |
7fd59977 | 2333 | |
329843e2 | 2334 | DisplayCircle(theGeomCircle, aName, isFilled); |
7fd59977 | 2335 | } |
404c8936 | 2336 | else |
2337 | { | |
23fe70ec | 2338 | Message::SendFail ("Error: You should select face and vertex or three vertices."); |
404c8936 | 2339 | return 1; |
2340 | } | |
7fd59977 | 2341 | } |
2342 | ||
2343 | return 0; | |
2344 | } | |
2345 | ||
29e2c6d2 | 2346 | //======================================================================= |
7fd59977 | 2347 | //function : VDrawText |
29e2c6d2 | 2348 | //purpose : |
2349 | //======================================================================= | |
2350 | static int VDrawText (Draw_Interpretor& theDI, | |
2351 | Standard_Integer theArgsNb, | |
2352 | const char** theArgVec) | |
7fd59977 | 2353 | { |
29e2c6d2 | 2354 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
2355 | if (theArgsNb < 3) | |
fe551aef | 2356 | { |
23fe70ec | 2357 | Message::SendFail ("Syntax error: wrong number of arguments. See usage:"); |
29e2c6d2 | 2358 | theDI.PrintHelp (theArgVec[0]); |
2359 | return 1; | |
2360 | } | |
2361 | else if (aContext.IsNull()) | |
2362 | { | |
23fe70ec | 2363 | Message::SendFail ("Error: no active viewer"); |
29e2c6d2 | 2364 | return 1; |
fe551aef | 2365 | } |
2366 | ||
29e2c6d2 | 2367 | Standard_Integer anArgIt = 1; |
2368 | TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True); | |
2369 | TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True); | |
2370 | Handle(AIS_TextLabel) aTextPrs; | |
2371 | ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView()); | |
7fd59977 | 2372 | |
1beb58d7 | 2373 | Standard_Boolean isNewPrs = Standard_False; |
29e2c6d2 | 2374 | if (GetMapOfAIS().IsBound2 (aName)) |
7fd59977 | 2375 | { |
1beb58d7 | 2376 | aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName)); |
29e2c6d2 | 2377 | } |
1beb58d7 | 2378 | |
2379 | if (aTextPrs.IsNull()) | |
29e2c6d2 | 2380 | { |
1beb58d7 | 2381 | isNewPrs = Standard_True; |
29e2c6d2 | 2382 | aTextPrs = new AIS_TextLabel(); |
2383 | aTextPrs->SetFont ("Courier"); | |
7fd59977 | 2384 | } |
13a22457 | 2385 | |
29e2c6d2 | 2386 | aTextPrs->SetText (aText); |
13a22457 | 2387 | |
778cd667 | 2388 | Handle(Graphic3d_TransformPers) aTrsfPers; |
61b0191c | 2389 | Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL; |
2390 | ||
ce01ec26 | 2391 | Standard_Boolean aHasPlane = Standard_False; |
2392 | gp_Dir aNormal; | |
2393 | gp_Dir aDirection; | |
2394 | gp_Pnt aPos; | |
2395 | ||
60f7b225 | 2396 | |
2397 | Handle(Font_TextFormatter) aTextFormatter; | |
29e2c6d2 | 2398 | for (; anArgIt < theArgsNb; ++anArgIt) |
161c4476 | 2399 | { |
29e2c6d2 | 2400 | TCollection_AsciiString aParam (theArgVec[anArgIt]); |
2401 | aParam.LowerCase(); | |
2402 | ||
2403 | if (anAutoUpdater.parseRedrawMode (aParam)) | |
13a22457 | 2404 | { |
29e2c6d2 | 2405 | continue; |
13a22457 | 2406 | } |
29e2c6d2 | 2407 | else if (aParam == "-pos" |
2408 | || aParam == "-position") | |
2409 | { | |
2410 | if (anArgIt + 3 >= theArgsNb) | |
2411 | { | |
23fe70ec | 2412 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
29e2c6d2 | 2413 | return 1; |
2414 | } | |
7fd59977 | 2415 | |
29e2c6d2 | 2416 | aPos.SetX (Draw::Atof (theArgVec[++anArgIt])); |
2417 | aPos.SetY (Draw::Atof (theArgVec[++anArgIt])); | |
2418 | aPos.SetZ (Draw::Atof (theArgVec[++anArgIt])); | |
2419 | aTextPrs->SetPosition (aPos); | |
2420 | } | |
2421 | else if (aParam == "-color") | |
2422 | { | |
9196ea9d | 2423 | Quantity_Color aColor; |
dae2a922 | 2424 | Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1, |
2425 | theArgVec + anArgIt + 1, | |
2426 | aColor); | |
9196ea9d | 2427 | if (aNbParsed == 0) |
29e2c6d2 | 2428 | { |
23fe70ec | 2429 | Message::SendFail() << "Syntax error at '" << aParam << "'"; |
29e2c6d2 | 2430 | return 1; |
2431 | } | |
9196ea9d | 2432 | anArgIt += aNbParsed; |
2433 | aTextPrs->SetColor (aColor); | |
29e2c6d2 | 2434 | } |
2435 | else if (aParam == "-halign") | |
2436 | { | |
2437 | if (++anArgIt >= theArgsNb) | |
2438 | { | |
23fe70ec | 2439 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'"; |
29e2c6d2 | 2440 | return 1; |
2441 | } | |
13a22457 | 2442 | |
29e2c6d2 | 2443 | TCollection_AsciiString aType (theArgVec[anArgIt]); |
2444 | aType.LowerCase(); | |
2445 | if (aType == "left") | |
2446 | { | |
2447 | aTextPrs->SetHJustification (Graphic3d_HTA_LEFT); | |
2448 | } | |
2449 | else if (aType == "center") | |
2450 | { | |
2451 | aTextPrs->SetHJustification (Graphic3d_HTA_CENTER); | |
2452 | } | |
2453 | else if (aType == "right") | |
2454 | { | |
2455 | aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT); | |
2456 | } | |
2457 | else | |
2458 | { | |
23fe70ec | 2459 | Message::SendFail() << "Syntax error at '" << aParam << "'"; |
29e2c6d2 | 2460 | return 1; |
2461 | } | |
2462 | } | |
2463 | else if (aParam == "-valign") | |
2464 | { | |
2465 | if (++anArgIt >= theArgsNb) | |
2466 | { | |
23fe70ec | 2467 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; |
29e2c6d2 | 2468 | return 1; |
2469 | } | |
2470 | ||
2471 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
2472 | aType.LowerCase(); | |
2473 | if (aType == "top") | |
2474 | { | |
2475 | aTextPrs->SetVJustification (Graphic3d_VTA_TOP); | |
2476 | } | |
2477 | else if (aType == "center") | |
2478 | { | |
2479 | aTextPrs->SetVJustification (Graphic3d_VTA_CENTER); | |
2480 | } | |
2481 | else if (aType == "bottom") | |
2482 | { | |
2483 | aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM); | |
2484 | } | |
ac84fcf6 | 2485 | else if (aType == "topfirstline") |
2486 | { | |
2487 | aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE); | |
2488 | } | |
29e2c6d2 | 2489 | else |
2490 | { | |
23fe70ec | 2491 | Message::SendFail() << "Syntax error at '" << aParam << "'"; |
29e2c6d2 | 2492 | return 1; |
2493 | } | |
2494 | } | |
2495 | else if (aParam == "-angle") | |
2496 | { | |
2497 | if (++anArgIt >= theArgsNb) | |
2498 | { | |
23fe70ec | 2499 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; |
29e2c6d2 | 2500 | return 1; |
2501 | } | |
13a22457 | 2502 | |
29e2c6d2 | 2503 | aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0)); |
2504 | } | |
2505 | else if (aParam == "-zoom") | |
2506 | { | |
2507 | if (++anArgIt >= theArgsNb) | |
2508 | { | |
23fe70ec | 2509 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; |
29e2c6d2 | 2510 | return 1; |
2511 | } | |
13a22457 | 2512 | |
29e2c6d2 | 2513 | aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1); |
2514 | } | |
2515 | else if (aParam == "-height") | |
2516 | { | |
2517 | if (++anArgIt >= theArgsNb) | |
2518 | { | |
23fe70ec | 2519 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; |
29e2c6d2 | 2520 | return 1; |
2521 | } | |
13a22457 | 2522 | |
29e2c6d2 | 2523 | aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt])); |
2524 | } | |
60f7b225 | 2525 | else if (aParam == "-wrapping") |
2526 | { | |
2527 | if (++anArgIt >= theArgsNb) | |
2528 | { | |
2529 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; | |
2530 | return 1; | |
2531 | } | |
2532 | ||
2533 | if (aTextFormatter.IsNull()) | |
2534 | { | |
2535 | aTextFormatter = new Font_TextFormatter(); | |
2536 | } | |
2537 | aTextFormatter->SetWrapping ((Standard_ShortReal)Draw::Atof(theArgVec[anArgIt])); | |
2538 | } | |
29e2c6d2 | 2539 | else if (aParam == "-aspect") |
2540 | { | |
2541 | if (++anArgIt >= theArgsNb) | |
2542 | { | |
23fe70ec | 2543 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; |
29e2c6d2 | 2544 | return 1; |
2545 | } | |
13a22457 | 2546 | |
29e2c6d2 | 2547 | TCollection_AsciiString anOption (theArgVec[anArgIt]); |
2548 | anOption.LowerCase(); | |
5b377041 | 2549 | Font_FontAspect aFontAspect = Font_FA_Undefined; |
2550 | if (!parseFontStyle (anOption, aFontAspect)) | |
29e2c6d2 | 2551 | { |
23fe70ec | 2552 | Message::SendFail() << "Syntax error: unknown font aspect '" << anOption << "'"; |
5b377041 | 2553 | return 1; |
29e2c6d2 | 2554 | } |
5b377041 | 2555 | aTextPrs->SetFontAspect (aFontAspect); |
29e2c6d2 | 2556 | } |
2557 | else if (aParam == "-font") | |
2558 | { | |
2559 | if (++anArgIt >= theArgsNb) | |
2560 | { | |
23fe70ec | 2561 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; |
29e2c6d2 | 2562 | return 1; |
2563 | } | |
13a22457 | 2564 | |
29e2c6d2 | 2565 | aTextPrs->SetFont (theArgVec[anArgIt]); |
2566 | } | |
ce01ec26 | 2567 | else if (aParam == "-plane") |
2568 | { | |
2569 | if (anArgIt + 6 >= theArgsNb) | |
2570 | { | |
23fe70ec | 2571 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; |
ce01ec26 | 2572 | return 1; |
2573 | } | |
2574 | ||
2575 | Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]); | |
2576 | Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]); | |
2577 | Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]); | |
2578 | aNormal.SetCoord (aX, aY, aZ); | |
2579 | ||
2580 | aX = Draw::Atof (theArgVec[++anArgIt]); | |
2581 | aY = Draw::Atof (theArgVec[++anArgIt]); | |
2582 | aZ = Draw::Atof (theArgVec[++anArgIt]); | |
2583 | aDirection.SetCoord (aX, aY, aZ); | |
2584 | ||
2585 | aHasPlane = Standard_True; | |
2586 | } | |
3f1eb0ab | 2587 | else if (aParam == "-flipping") |
2588 | { | |
2589 | aTextPrs->SetFlipping (Standard_True); | |
2590 | } | |
ab9e277f | 2591 | else if (aParam == "-ownanchor") |
2592 | { | |
2593 | if (++anArgIt >= theArgsNb) | |
2594 | { | |
2595 | std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; | |
2596 | return 1; | |
2597 | } | |
2598 | aTextPrs->SetOwnAnchorPoint (Draw::Atoi (theArgVec[anArgIt]) == 1); | |
2599 | } | |
61b0191c | 2600 | else if (aParam == "-disptype" |
2601 | || aParam == "-displaytype") | |
2602 | { | |
2603 | if (++anArgIt >= theArgsNb) | |
2604 | { | |
23fe70ec | 2605 | Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'"; |
61b0191c | 2606 | return 1; |
2607 | } | |
2608 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
2609 | aType.LowerCase(); | |
2610 | if (aType == "subtitle") | |
2611 | aDisplayType = Aspect_TODT_SUBTITLE; | |
2612 | else if (aType == "decal") | |
2613 | aDisplayType = Aspect_TODT_DEKALE; | |
2614 | else if (aType == "blend") | |
2615 | aDisplayType = Aspect_TODT_BLEND; | |
2616 | else if (aType == "dimension") | |
2617 | aDisplayType = Aspect_TODT_DIMENSION; | |
2618 | else if (aType == "normal") | |
2619 | aDisplayType = Aspect_TODT_NORMAL; | |
3cbd0a8e | 2620 | else if (aType == "shadow") |
2621 | aDisplayType = Aspect_TODT_SHADOW; | |
61b0191c | 2622 | else |
2623 | { | |
23fe70ec | 2624 | Message::SendFail() << "Syntax error: wrong display type '" << aType << "'"; |
61b0191c | 2625 | return 1; |
2626 | } | |
2627 | } | |
2628 | else if (aParam == "-subcolor" | |
2629 | || aParam == "-subtitlecolor") | |
2630 | { | |
9196ea9d | 2631 | Quantity_Color aColor; |
dae2a922 | 2632 | Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1, |
2633 | theArgVec + anArgIt + 1, | |
2634 | aColor); | |
9196ea9d | 2635 | if (aNbParsed == 0) |
61b0191c | 2636 | { |
23fe70ec | 2637 | Message::SendFail() << "Syntax error at '" << aParam << "'"; |
61b0191c | 2638 | return 1; |
2639 | } | |
9196ea9d | 2640 | anArgIt += aNbParsed; |
2641 | aTextPrs->SetColorSubTitle (aColor); | |
61b0191c | 2642 | } |
2643 | else if (aParam == "-2d") | |
2644 | { | |
778cd667 | 2645 | aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d); |
61b0191c | 2646 | } |
2647 | else if (aParam == "-trsfperspos" | |
2648 | || aParam == "-perspos") | |
2649 | { | |
2650 | if (anArgIt + 2 >= theArgsNb) | |
2651 | { | |
23fe70ec | 2652 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'."; |
61b0191c | 2653 | return 1; |
2654 | } | |
2655 | ||
2656 | TCollection_AsciiString aX (theArgVec[++anArgIt]); | |
2657 | TCollection_AsciiString aY (theArgVec[++anArgIt]); | |
2658 | TCollection_AsciiString aZ = "0"; | |
2659 | if (!aX.IsIntegerValue() | |
2660 | || !aY.IsIntegerValue()) | |
2661 | { | |
23fe70ec | 2662 | Message::SendFail() << "Error: wrong syntax at '" << aParam << "'."; |
61b0191c | 2663 | return 1; |
2664 | } | |
2665 | if (anArgIt + 1 < theArgsNb) | |
2666 | { | |
2667 | TCollection_AsciiString aTemp = theArgVec[anArgIt + 1]; | |
2668 | if (aTemp.IsIntegerValue()) | |
2669 | { | |
2670 | aZ = aTemp; | |
2671 | ++anArgIt; | |
2672 | } | |
2673 | } | |
778cd667 | 2674 | |
2675 | aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue())); | |
61b0191c | 2676 | } |
29e2c6d2 | 2677 | else |
2678 | { | |
23fe70ec | 2679 | Message::SendFail() << "Syntax error: unknown argument '" << aParam << "'"; |
29e2c6d2 | 2680 | return 1; |
2681 | } | |
13a22457 S |
2682 | } |
2683 | ||
60f7b225 | 2684 | aTextPrs->SetTextFormatter (aTextFormatter); |
2685 | ||
ce01ec26 | 2686 | if (aHasPlane) |
2687 | { | |
2688 | aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection)); | |
2689 | } | |
2690 | ||
284c9238 | 2691 | aTextPrs->SetDisplayType (aDisplayType); |
2692 | ||
778cd667 | 2693 | if (!aTrsfPers.IsNull()) |
61b0191c | 2694 | { |
778cd667 | 2695 | aContext->SetTransformPersistence (aTextPrs, aTrsfPers); |
61b0191c | 2696 | aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD); |
ce01ec26 | 2697 | if (aTextPrs->Position().Z() != 0) |
61b0191c | 2698 | { |
ce01ec26 | 2699 | aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0)); |
61b0191c | 2700 | } |
2701 | } | |
778cd667 | 2702 | else if (!aTextPrs->TransformPersistence().IsNull()) |
61b0191c | 2703 | { |
778cd667 | 2704 | aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)()); |
61b0191c | 2705 | } |
1beb58d7 | 2706 | |
2707 | if (isNewPrs) | |
2708 | { | |
2709 | ViewerTest::Display (aName, aTextPrs, Standard_False); | |
2710 | } | |
2711 | else | |
2712 | { | |
2713 | aContext->Redisplay (aTextPrs, Standard_False, Standard_True); | |
2714 | } | |
161c4476 | 2715 | return 0; |
7fd59977 | 2716 | } |
2717 | ||
2718 | #include <math.h> | |
2719 | #include <gp_Pnt.hxx> | |
2720 | #include <Graphic3d_ArrayOfPoints.hxx> | |
2721 | #include <Graphic3d_ArrayOfPrimitives.hxx> | |
7fd59977 | 2722 | #include <Graphic3d_ArrayOfTriangles.hxx> |
2723 | #include <Poly_Array1OfTriangle.hxx> | |
2724 | #include <Poly_Triangle.hxx> | |
2725 | #include <Poly_Triangulation.hxx> | |
2726 | #include <TColgp_Array1OfPnt.hxx> | |
2727 | #include <TShort_Array1OfShortReal.hxx> | |
2728 | #include <TShort_HArray1OfShortReal.hxx> | |
2729 | ||
2730 | #include <AIS_Triangulation.hxx> | |
5ad8c033 | 2731 | #include <StdPrs_ToolTriangulatedShape.hxx> |
7fd59977 | 2732 | #include <Poly_Connect.hxx> |
2733 | #include <TColgp_Array1OfDir.hxx> | |
2734 | #include <Graphic3d_GraphicDriver.hxx> | |
2735 | ||
7fd59977 | 2736 | #include <TColStd_Array1OfInteger.hxx> |
2737 | #include <TColStd_HArray1OfInteger.hxx> | |
2738 | #include <Prs3d_ShadingAspect.hxx> | |
2739 | #include <Graphic3d_MaterialAspect.hxx> | |
2740 | #include <Graphic3d_AspectFillArea3d.hxx> | |
2741 | ||
2742 | #include <BRepPrimAPI_MakeCylinder.hxx> | |
2743 | #include <TopoDS_Shape.hxx> | |
2744 | #include <TopExp_Explorer.hxx> | |
2745 | #include <TopAbs.hxx> | |
ec357c5c | 2746 | #include <AIS_InteractiveObject.hxx> |
7fd59977 | 2747 | |
2748 | ||
2749 | //=============================================================================================== | |
2750 | //function : CalculationOfSphere | |
2751 | //author : psn | |
2752 | //purpose : Create a Sphere | |
2753 | //=============================================================================================== | |
2754 | ||
161c4476 | 2755 | Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z , |
7fd59977 | 2756 | int res , |
2757 | double Radius ){ | |
2758 | double mRadius = Radius; | |
2759 | double mCenter[3] = {X,Y,Z}; | |
2760 | int mThetaResolution; | |
2761 | int mPhiResolution; | |
2762 | double mStartTheta = 0;//StartTheta; | |
2763 | double mEndTheta = 360;//EndTheta; | |
2764 | double mStartPhi = 0;//StartPhi; | |
2765 | double mEndPhi = 180;//EndPhi; | |
2766 | res = res < 4 ? 4 : res; | |
2767 | ||
2768 | mThetaResolution = res; | |
2769 | mPhiResolution = res; | |
2770 | ||
2771 | int i, j; | |
2772 | int jStart, jEnd, numOffset; | |
7fd59977 | 2773 | double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius; |
2774 | double startTheta, endTheta, startPhi, endPhi; | |
2775 | int base, numPoles=0, thetaResolution, phiResolution; | |
2776 | ||
2777 | int pts[3]; | |
2778 | int piece = -1; | |
2779 | int numPieces = 1; | |
2780 | if ( numPieces > mThetaResolution ) { | |
2781 | numPieces = mThetaResolution; | |
2782 | } | |
2783 | ||
2784 | int localThetaResolution = mThetaResolution; | |
2785 | double localStartTheta = mStartTheta; | |
2786 | double localEndTheta = mEndTheta; | |
2787 | ||
2788 | while ( localEndTheta < localStartTheta ) { | |
2789 | localEndTheta += 360.0; | |
2790 | } | |
2791 | ||
2792 | deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution; | |
2793 | ||
2794 | // Change the ivars based on pieces. | |
2795 | int start, end; | |
2796 | start = piece * localThetaResolution / numPieces; | |
2797 | end = (piece+1) * localThetaResolution / numPieces; | |
2798 | localEndTheta = localStartTheta + (double)(end) * deltaTheta; | |
2799 | localStartTheta = localStartTheta + (double)(start) * deltaTheta; | |
2800 | localThetaResolution = end - start; | |
2801 | ||
7fd59977 | 2802 | // Create north pole if needed |
2803 | int number_point = 0; | |
2804 | int number_pointArray = 0; | |
2805 | ||
2806 | if ( mStartPhi <= 0.0 ) { | |
2807 | number_pointArray++; | |
2808 | numPoles++; | |
2809 | } | |
2810 | if ( mEndPhi >= 180.0 ) { | |
2811 | number_pointArray++; | |
2812 | numPoles++; | |
2813 | } | |
161c4476 | 2814 | |
7fd59977 | 2815 | // Check data, determine increments, and convert to radians |
2816 | startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta); | |
c6541a0c | 2817 | startTheta *= M_PI / 180.0; |
7fd59977 | 2818 | endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta); |
c6541a0c | 2819 | endTheta *= M_PI / 180.0; |
7fd59977 | 2820 | |
2821 | ||
2822 | startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi); | |
c6541a0c | 2823 | startPhi *= M_PI / 180.0; |
7fd59977 | 2824 | endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi); |
c6541a0c | 2825 | endPhi *= M_PI / 180.0; |
7fd59977 | 2826 | |
2827 | phiResolution = mPhiResolution - numPoles; | |
2828 | deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1); | |
2829 | thetaResolution = localThetaResolution; | |
2830 | if ( fabs(localStartTheta - localEndTheta) < 360.0 ) { | |
2831 | ++localThetaResolution; | |
2832 | } | |
2833 | deltaTheta = (endTheta - startTheta) / thetaResolution; | |
2834 | ||
2835 | jStart = ( mStartPhi <= 0.0 ? 1 : 0); | |
2836 | jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution); | |
2837 | ||
2838 | // Create intermediate points | |
2839 | for ( i = 0; i < localThetaResolution; i++ ) { | |
2840 | for ( j = jStart; j < jEnd; j++ ) { | |
2841 | number_pointArray++; | |
2842 | } | |
2843 | } | |
2844 | ||
2845 | //Generate mesh connectivity | |
2846 | base = phiResolution * localThetaResolution; | |
2847 | ||
2848 | int number_triangle = 0 ; | |
2849 | if ( mStartPhi <= 0.0 ) { // around north pole | |
2850 | number_triangle += localThetaResolution; | |
2851 | } | |
161c4476 | 2852 | |
7fd59977 | 2853 | if ( mEndPhi >= 180.0 ) { // around south pole |
2854 | number_triangle += localThetaResolution; | |
2855 | } | |
2856 | ||
2857 | // bands in-between poles | |
2858 | for ( i=0; i < localThetaResolution; i++){ | |
2859 | for ( j=0; j < (phiResolution-1); j++){ | |
2860 | number_triangle +=2; | |
2861 | } | |
2862 | } | |
2863 | ||
2864 | Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false); | |
2865 | TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes(); | |
2866 | Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles(); | |
2867 | ||
2868 | if ( mStartPhi <= 0.0 ){ | |
2869 | x[0] = mCenter[0]; | |
2870 | x[1] = mCenter[1]; | |
2871 | x[2] = mCenter[2] + mRadius; | |
2872 | PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2])); | |
2873 | } | |
2874 | ||
2875 | // Create south pole if needed | |
2876 | if ( mEndPhi >= 180.0 ){ | |
2877 | x[0] = mCenter[0]; | |
2878 | x[1] = mCenter[1]; | |
2879 | x[2] = mCenter[2] - mRadius; | |
2880 | PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2])); | |
2881 | } | |
2882 | ||
2883 | number_point = 3; | |
2884 | for ( i=0; i < localThetaResolution; i++){ | |
c6541a0c | 2885 | theta = localStartTheta * M_PI / 180.0 + i*deltaTheta; |
7fd59977 | 2886 | for ( j = jStart; j < jEnd; j++){ |
2887 | phi = startPhi + j*deltaPhi; | |
2888 | radius = mRadius * sin((double)phi); | |
2889 | n[0] = radius * cos((double)theta); | |
2890 | n[1] = radius * sin((double)theta); | |
2891 | n[2] = mRadius * cos((double)phi); | |
2892 | x[0] = n[0] + mCenter[0]; | |
2893 | x[1] = n[1] + mCenter[1]; | |
2894 | x[2] = n[2] + mCenter[2]; | |
2895 | PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2])); | |
2896 | number_point++; | |
2897 | } | |
2898 | } | |
2899 | ||
2900 | numPoles = 3; | |
2901 | number_triangle = 1; | |
2902 | if ( mStartPhi <= 0.0 ){// around north pole | |
2903 | for (i=0; i < localThetaResolution; i++){ | |
2904 | pts[0] = phiResolution*i + numPoles; | |
2905 | pts[1] = (phiResolution*(i+1) % base) + numPoles; | |
2906 | pts[2] = 1; | |
2907 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2908 | number_triangle++; | |
2909 | } | |
2910 | } | |
161c4476 | 2911 | |
7fd59977 | 2912 | if ( mEndPhi >= 180.0 ){ // around south pole |
2913 | numOffset = phiResolution - 1 + numPoles; | |
2914 | for (i=0; i < localThetaResolution; i++){ | |
2915 | pts[0] = phiResolution*i + numOffset; | |
2916 | pts[2] = ((phiResolution*(i+1)) % base) + numOffset; | |
2917 | pts[1] = numPoles - 1; | |
2918 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2919 | number_triangle++; | |
2920 | } | |
2921 | } | |
2922 | ||
2923 | // bands in-between poles | |
161c4476 | 2924 | |
7fd59977 | 2925 | for (i=0; i < localThetaResolution; i++){ |
2926 | for (j=0; j < (phiResolution-1); j++){ | |
2927 | pts[0] = phiResolution*i + j + numPoles; | |
2928 | pts[1] = pts[0] + 1; | |
2929 | pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1; | |
2930 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2931 | number_triangle++; | |
2932 | pts[1] = pts[2]; | |
2933 | pts[2] = pts[1] - 1; | |
2934 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2935 | number_triangle++; | |
2936 | } | |
2937 | } | |
2938 | ||
2939 | Poly_Connect* pc = new Poly_Connect(polyTriangulation); | |
2940 | ||
2941 | Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3); | |
2942 | ||
2943 | Standard_Integer index[3]; | |
2944 | Standard_Real Tol = Precision::Confusion(); | |
2945 | ||
2946 | gp_Dir Nor; | |
2947 | for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) { | |
2948 | gp_XYZ eqPlan(0, 0, 0); | |
2949 | for ( pc->Initialize(i); pc->More(); pc->Next()) { | |
2950 | pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]); | |
2951 | gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord()); | |
2952 | gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord()); | |
2953 | gp_XYZ vv = v1^v2; | |
2954 | Standard_Real mod = vv.Modulus(); | |
2955 | if(mod < Tol) continue; | |
2956 | eqPlan += vv/mod; | |
2957 | } | |
2958 | ||
2959 | Standard_Real modmax = eqPlan.Modulus(); | |
2960 | ||
161c4476 | 2961 | if(modmax > Tol) |
7fd59977 | 2962 | Nor = gp_Dir(eqPlan); |
161c4476 | 2963 | else |
7fd59977 | 2964 | Nor = gp_Dir(0., 0., 1.); |
51740958 | 2965 | |
2966 | Standard_Integer k = (i - PointsOfArray.Lower()) * 3; | |
2967 | Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X()); | |
2968 | Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y()); | |
2969 | Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z()); | |
7fd59977 | 2970 | } |
2971 | ||
2972 | delete pc; | |
2973 | polyTriangulation->SetNormals(Normals); | |
2974 | ||
2975 | return polyTriangulation; | |
2976 | } | |
2977 | ||
2978 | //=============================================================================================== | |
2979 | //function : VDrawSphere | |
2980 | //author : psn | |
2981 | //purpose : Create an AIS shape. | |
7fd59977 | 2982 | //=============================================================================================== |
35e08fe8 | 2983 | static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv) |
161c4476 K |
2984 | { |
2985 | // check for errors | |
2986 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
2987 | if (aContextAIS.IsNull()) | |
2988 | { | |
23fe70ec | 2989 | Message::SendFail ("Error: no active viewer"); |
161c4476 K |
2990 | return 1; |
2991 | } | |
2992 | else if (argc < 3) | |
2993 | { | |
23fe70ec | 2994 | Message::SendFail() << "Syntax error: wrong number of arguments.\n" |
2995 | << "Use: " << argv[0] << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]"; | |
161c4476 K |
2996 | return 1; |
2997 | } | |
7fd59977 | 2998 | |
161c4476 K |
2999 | // read the arguments |
3000 | TCollection_AsciiString aShapeName (argv[1]); | |
91322f44 | 3001 | Standard_Integer aResolution = Draw::Atoi (argv[2]); |
3002 | Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0; | |
3003 | Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0; | |
3004 | Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0; | |
3005 | Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0; | |
b7cd4ba7 | 3006 | Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False; |
3007 | Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True; | |
7fd59977 | 3008 | |
161c4476 | 3009 | // remove AIS object with given name from map |
208e6839 | 3010 | VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)()); |
161c4476 | 3011 | |
b7cd4ba7 | 3012 | if (toPrintInfo) |
3013 | std::cout << "Compute Triangulation...\n"; | |
161c4476 K |
3014 | Handle(AIS_Triangulation) aShape |
3015 | = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ, | |
3016 | aResolution, | |
3017 | aRadius)); | |
3018 | Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length(); | |
3019 | Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length(); | |
3020 | ||
161c4476 K |
3021 | // stupid initialization of Green color in RGBA space as integer |
3022 | // probably wrong for big-endian CPUs | |
dcc17419 | 3023 | const Graphic3d_Vec4ub aColor (0, 255, 0, 0); |
161c4476 K |
3024 | |
3025 | // setup colors array per vertex | |
3026 | Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints); | |
3027 | for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId) | |
3028 | { | |
6a657c92 | 3029 | aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (aColor.GetData())); |
7fd59977 | 3030 | } |
161c4476 K |
3031 | aShape->SetColors (aColorArray); |
3032 | ||
3033 | // show statistics | |
3034 | Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
3035 | Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
3036 | Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha | |
3037 | Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint | |
3038 | Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4; | |
3039 | Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize; | |
3040 | aTotalSize >>= 20; //MB | |
3041 | aNormalsSize >>= 20; | |
3042 | aColorsSize >>= 20; | |
3043 | aTrianglesSize >>= 20; | |
3044 | aPolyConnectSize >>= 20; | |
b7cd4ba7 | 3045 | if (toPrintInfo) |
3046 | { | |
3047 | std::cout << "NumberOfPoints: " << aNumberPoints << "\n" | |
3048 | << "NumberOfTriangles: " << aNumberTriangles << "\n" | |
3049 | << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n" | |
3050 | << "Amount of memory for colors: " << aColorsSize << " Mb\n" | |
3051 | << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n" | |
3052 | << "Amount of graphic card memory required: " << aTotalSize << " Mb\n"; | |
3053 | } | |
7fd59977 | 3054 | |
3055 | // Setting material properties, very important for desirable visual result! | |
161c4476 | 3056 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC); |
61168418 | 3057 | aMat.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.04f))); |
3058 | aMat.SetSpecularColor(Quantity_Color (Graphic3d_Vec3 (0.50f))); | |
161c4476 K |
3059 | Handle(Graphic3d_AspectFillArea3d) anAspect |
3060 | = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, | |
3061 | Quantity_NOC_RED, | |
3062 | Quantity_NOC_YELLOW, | |
3063 | Aspect_TOL_SOLID, | |
3064 | 1.0, | |
3065 | aMat, | |
3066 | aMat); | |
7fd59977 | 3067 | Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect(); |
2a332745 | 3068 | anAspect->SetDrawEdges (toShowEdges); |
161c4476 K |
3069 | aShAsp->SetAspect (anAspect); |
3070 | aShape->Attributes()->SetShadingAspect (aShAsp); | |
7fd59977 | 3071 | |
208e6839 | 3072 | VDisplayAISObject (aShapeName, aShape); |
7fd59977 | 3073 | return 0; |
3074 | } | |
3075 | ||
3fc57801 | 3076 | //============================================================================= |
3077 | //function : VComputeHLR | |
3078 | //purpose : | |
3079 | //============================================================================= | |
3080 | ||
c60ec7f5 | 3081 | static int VComputeHLR (Draw_Interpretor& , |
3082 | Standard_Integer theArgNb, | |
3083 | const char** theArgVec) | |
3fc57801 | 3084 | { |
c60ec7f5 | 3085 | TCollection_AsciiString aShapeName, aHlrName; |
3086 | TopoDS_Shape aSh; | |
3fc57801 | 3087 | gp_Pnt anEye; |
3088 | gp_Dir aDir; | |
3089 | gp_Ax2 aProjAx; | |
c60ec7f5 | 3090 | bool hasViewDirArg = false; |
3091 | Prs3d_TypeOfHLR anAlgoType = Prs3d_TOH_PolyAlgo; | |
3977d18a | 3092 | bool toShowCNEdges = false, toShowHiddenEdges = false; |
c60ec7f5 | 3093 | int aNbIsolines = 0; |
3094 | if (Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext()) | |
3fc57801 | 3095 | { |
3096 | gp_Dir aRight; | |
c60ec7f5 | 3097 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
3fc57801 | 3098 | Standard_Integer aWidth, aHeight; |
3099 | Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ; | |
3100 | Standard_Real aRightX, aRightY, aRightZ; | |
3101 | aView->Window()->Size (aWidth, aHeight); | |
3102 | ||
3103 | aView->ConvertWithProj (aWidth, aHeight/2, | |
3104 | aRightX, aRightY, aRightZ, | |
3105 | aDirX, aDirY, aDirZ); | |
3fc57801 | 3106 | aView->ConvertWithProj (aWidth/2, aHeight/2, |
3107 | aCentX, aCentY, aCentZ, | |
3108 | aDirX, aDirY, aDirZ); | |
3109 | ||
3110 | anEye.SetCoord (-aCentX, -aCentY, -aCentZ); | |
3111 | aDir.SetCoord (-aDirX, -aDirY, -aDirZ); | |
3112 | aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ); | |
3113 | aProjAx.SetLocation (anEye); | |
3114 | aProjAx.SetDirection (aDir); | |
3115 | aProjAx.SetXDirection (aRight); | |
3116 | } | |
c60ec7f5 | 3117 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
3118 | { | |
3119 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); | |
3120 | anArgCase.LowerCase(); | |
3121 | if (anArgIter + 1 < theArgNb | |
3122 | && (anArgCase == "-algotype" | |
3123 | || anArgCase == "-algo" | |
3124 | || anArgCase == "-type")) | |
3125 | { | |
3126 | TCollection_AsciiString anArgNext (theArgVec[++anArgIter]); | |
3127 | anArgNext.LowerCase(); | |
3128 | if (anArgNext == "polyalgo") | |
3129 | { | |
3130 | anAlgoType = Prs3d_TOH_PolyAlgo; | |
3131 | } | |
3132 | else if (anArgNext == "algo") | |
3133 | { | |
3134 | anAlgoType = Prs3d_TOH_Algo; | |
3135 | } | |
3136 | else | |
3137 | { | |
23fe70ec | 3138 | Message::SendFail() << "Syntax error: unknown algo type '" << anArgNext << "'"; |
c60ec7f5 | 3139 | return 1; |
3140 | } | |
3141 | } | |
3142 | else if (anArgCase == "-showhiddenedges" | |
3143 | || anArgCase == "-hiddenedges" | |
3144 | || anArgCase == "-hidden") | |
3145 | { | |
3146 | toShowHiddenEdges = true; | |
3147 | if (anArgIter + 1 < theArgNb | |
dae2a922 | 3148 | && Draw::ParseOnOff (theArgVec[anArgIter + 1], toShowHiddenEdges)) |
c60ec7f5 | 3149 | { |
3150 | ++anArgIter; | |
3151 | } | |
3152 | } | |
3153 | else if (anArgCase == "-showtangentedges" | |
3154 | || anArgCase == "-tangentedges" | |
3155 | || anArgCase == "-tangent") | |
3156 | { | |
3977d18a | 3157 | toShowCNEdges = true; |
c60ec7f5 | 3158 | if (anArgIter + 1 < theArgNb |
dae2a922 | 3159 | && Draw::ParseOnOff (theArgVec[anArgIter + 1], toShowCNEdges)) |
c60ec7f5 | 3160 | { |
3161 | ++anArgIter; | |
3162 | } | |
3163 | } | |
3164 | else if (anArgIter + 1 < theArgNb | |
3165 | && (anArgCase == "-nbiso" | |
3166 | || anArgCase == "-nbisolines")) | |
3167 | { | |
3168 | aNbIsolines = Draw::Atoi (theArgVec[++anArgIter]); | |
3169 | } | |
3170 | else if (aSh.IsNull()) | |
3171 | { | |
3172 | aSh = DBRep::Get (theArgVec[anArgIter]); | |
3173 | aShapeName = theArgVec[anArgIter]; | |
3174 | if (aSh.IsNull()) | |
3175 | { | |
3176 | BRep_Builder aBrepBuilder; | |
3177 | BRepTools::Read (aSh, theArgVec[anArgIter], aBrepBuilder); | |
3178 | if (aSh.IsNull()) | |
3179 | { | |
23fe70ec | 3180 | Message::SendFail() << "Syntax error: no shape with name " << theArgVec[anArgIter] << " found"; |
c60ec7f5 | 3181 | return 1; |
3182 | } | |
3183 | } | |
3184 | } | |
3185 | else if (aHlrName.IsEmpty()) | |
3186 | { | |
3187 | aHlrName = theArgVec[anArgIter]; | |
3188 | } | |
3189 | else if (!hasViewDirArg | |
3190 | && anArgIter + 8 < theArgNb) | |
3191 | { | |
3192 | hasViewDirArg = true; | |
3193 | gp_Dir anUp; | |
3194 | anEye.SetCoord (Draw::Atof (theArgVec[anArgIter + 0]), Draw::Atof (theArgVec[anArgIter + 1]), Draw::Atof (theArgVec[anArgIter + 2])); | |
3195 | aDir .SetCoord (Draw::Atof (theArgVec[anArgIter + 3]), Draw::Atof (theArgVec[anArgIter + 4]), Draw::Atof (theArgVec[anArgIter + 5])); | |
3196 | anUp .SetCoord (Draw::Atof (theArgVec[anArgIter + 6]), Draw::Atof (theArgVec[anArgIter + 7]), Draw::Atof (theArgVec[anArgIter + 8])); | |
3197 | aProjAx.SetLocation (anEye); | |
3198 | aProjAx.SetDirection (aDir); | |
3199 | aProjAx.SetYDirection (anUp); | |
3200 | anArgIter += 8; | |
3201 | } | |
3202 | else | |
3203 | { | |
23fe70ec | 3204 | Message::SendFail() << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'"; |
c60ec7f5 | 3205 | return 1; |
3206 | } | |
3207 | } | |
3fc57801 | 3208 | |
c60ec7f5 | 3209 | if (aHlrName.IsEmpty() || aSh.IsNull() |
3210 | || (ViewerTest::GetAISContext().IsNull() && hasViewDirArg)) | |
3211 | { | |
23fe70ec | 3212 | Message::SendFail ("Syntax error: wrong number of arguments"); |
c60ec7f5 | 3213 | return 1; |
3214 | } | |
3fc57801 | 3215 | |
c60ec7f5 | 3216 | HLRAlgo_Projector aProjector (aProjAx); |
3217 | TopoDS_Shape aVisible[6]; | |
3218 | TopoDS_Shape aHidden[6]; | |
3219 | if (anAlgoType == Prs3d_TOH_PolyAlgo) | |
3220 | { | |
3221 | Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo(); | |
3222 | aPolyAlgo->Projector (aProjector); | |
3223 | aPolyAlgo->Load (aSh); | |
3224 | aPolyAlgo->Update(); | |
3fc57801 | 3225 | |
c60ec7f5 | 3226 | HLRBRep_PolyHLRToShape aHLRToShape; |
3227 | aHLRToShape.Update (aPolyAlgo); | |
3fc57801 | 3228 | |
c60ec7f5 | 3229 | aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound(); |
3230 | aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); // extract visible outlines | |
3977d18a | 3231 | aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound(); |
3232 | if (toShowCNEdges) | |
c60ec7f5 | 3233 | { |
3977d18a | 3234 | aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound(); |
c60ec7f5 | 3235 | } |
3236 | if (toShowHiddenEdges) | |
3237 | { | |
3238 | aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound(); | |
3239 | aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound(); | |
3977d18a | 3240 | aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound(); |
3241 | if (toShowCNEdges) | |
c60ec7f5 | 3242 | { |
3977d18a | 3243 | aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound(); |
c60ec7f5 | 3244 | } |
3245 | } | |
3246 | } | |
3247 | else | |
3fc57801 | 3248 | { |
c60ec7f5 | 3249 | Handle(HLRBRep_Algo) aHlrAlgo = new HLRBRep_Algo(); |
3250 | aHlrAlgo->Add (aSh, aNbIsolines); | |
3251 | aHlrAlgo->Projector (aProjector); | |
3252 | aHlrAlgo->Update(); | |
3253 | aHlrAlgo->Hide(); | |
3254 | ||
3255 | HLRBRep_HLRToShape aHLRToShape (aHlrAlgo); | |
3256 | aVisible[HLRBRep_Sharp] = aHLRToShape.VCompound(); | |
3257 | aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound(); | |
3977d18a | 3258 | aVisible[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineVCompound(); |
3259 | if (toShowCNEdges) | |
c60ec7f5 | 3260 | { |
3977d18a | 3261 | aVisible[HLRBRep_RgNLine] = aHLRToShape.RgNLineVCompound(); |
c60ec7f5 | 3262 | } |
3263 | aVisible[HLRBRep_IsoLine] = aHLRToShape.IsoLineVCompound(); | |
3264 | ||
3265 | if (toShowHiddenEdges) | |
3266 | { | |
3267 | aHidden[HLRBRep_Sharp] = aHLRToShape.HCompound(); | |
3268 | aHidden[HLRBRep_OutLine] = aHLRToShape.OutLineHCompound(); | |
3977d18a | 3269 | aHidden[HLRBRep_Rg1Line] = aHLRToShape.Rg1LineHCompound(); |
3270 | if (toShowCNEdges) | |
c60ec7f5 | 3271 | { |
3977d18a | 3272 | aHidden[HLRBRep_RgNLine] = aHLRToShape.RgNLineHCompound(); |
c60ec7f5 | 3273 | } |
3274 | aHidden[HLRBRep_IsoLine] = aHLRToShape.IsoLineHCompound(); | |
3275 | } | |
3276 | // extract 3d | |
3277 | //aVisible[HLRBRep_Sharp] = aHLRToShape.CompoundOfEdges (HLRBRep_Sharp, Standard_True, Standard_True); | |
3278 | //aVisible[HLRBRep_OutLine] = aHLRToShape.OutLineVCompound3d(); | |
3fc57801 | 3279 | } |
c60ec7f5 | 3280 | |
3281 | TopoDS_Compound aCompRes, aCompVis, aCompHid; | |
3282 | BRep_Builder aBuilder; | |
3283 | aBuilder.MakeCompound (aCompVis); | |
3284 | aBuilder.MakeCompound (aCompHid); | |
3285 | aBuilder.MakeCompound (aCompRes); | |
3286 | for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter) | |
3fc57801 | 3287 | { |
c60ec7f5 | 3288 | if (!aVisible[aTypeIter].IsNull()) |
3289 | { | |
3290 | aBuilder.Add (aCompVis, aVisible[aTypeIter]); | |
3291 | } | |
3292 | if (!aHidden[aTypeIter].IsNull()) | |
3293 | { | |
3294 | aBuilder.Add (aCompHid, aHidden[aTypeIter]); | |
3295 | } | |
3fc57801 | 3296 | } |
c60ec7f5 | 3297 | aBuilder.Add (aCompRes, aCompVis); |
3298 | aBuilder.Add (aCompRes, aCompHid); | |
3fc57801 | 3299 | |
3300 | // create an AIS shape and display it | |
c60ec7f5 | 3301 | if (!ViewerTest::GetAISContext().IsNull()) |
3302 | { | |
3303 | Handle(AIS_ColoredShape) anObject = new AIS_ColoredShape (aCompRes); | |
3304 | if (toShowHiddenEdges) | |
3305 | { | |
3306 | Handle(Prs3d_LineAspect) aLineAspect = new Prs3d_LineAspect (Quantity_Color (Quantity_NOC_RED), Aspect_TOL_DASH, 1.0f); | |
3307 | for (int aTypeIter = 0; aTypeIter < 6; ++aTypeIter) | |
3308 | { | |
3309 | if (!aHidden[aTypeIter].IsNull()) | |
3310 | { | |
3311 | Handle(AIS_ColoredDrawer) aDrawer = anObject->CustomAspects (aHidden[aTypeIter]); | |
3312 | aDrawer->SetLineAspect (aLineAspect); | |
3313 | aDrawer->SetWireAspect (aLineAspect); | |
3314 | aDrawer->SetFreeBoundaryAspect (aLineAspect); | |
3315 | aDrawer->SetUnFreeBoundaryAspect (aLineAspect); | |
3316 | } | |
3317 | } | |
3318 | } | |
3319 | ViewerTest::Display (aHlrName, anObject, true); | |
3320 | } | |
3fc57801 | 3321 | |
c60ec7f5 | 3322 | DBRep::Set (aHlrName.ToCString(), aCompRes); |
3fc57801 | 3323 | return 0; |
3324 | } | |
3325 | ||
9558a876 A |
3326 | // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for |
3327 | // manipulating and displaying such an array with AIS context | |
c04c30b3 | 3328 | |
9558a876 A |
3329 | class MyPArrayObject : public AIS_InteractiveObject |
3330 | { | |
3331 | ||
3332 | public: | |
3333 | ||
9427bc1d | 3334 | MyPArrayObject (const Handle(Graphic3d_ArrayOfPrimitives)& thePArray) : myPArray (thePArray) {} |
3335 | ||
da87ddc3 | 3336 | MyPArrayObject (Graphic3d_TypeOfPrimitiveArray thePrimType, |
3337 | const Handle(TColStd_HArray1OfAsciiString)& theDesc, | |
3338 | const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect) | |
3339 | { | |
3340 | Init (thePrimType, theDesc, theMarkerAspect, Standard_False); | |
3341 | } | |
3342 | ||
3343 | //! Initialize the array from specified description. | |
3344 | Standard_Boolean Init (Graphic3d_TypeOfPrimitiveArray thePrimType, | |
3345 | const Handle(TColStd_HArray1OfAsciiString)& theDesc, | |
3346 | const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect, | |
3347 | Standard_Boolean theToPatch); | |
9558a876 | 3348 | |
92efcf78 | 3349 | DEFINE_STANDARD_RTTI_INLINE(MyPArrayObject,AIS_InteractiveObject); |
9558a876 | 3350 | |
9427bc1d | 3351 | virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; } |
3352 | ||
acc6542a | 3353 | //! Sets color to this interactive object |
3354 | //! @param theColor the color to be set | |
3355 | virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE; | |
3356 | ||
9558a876 A |
3357 | private: |
3358 | ||
3359 | void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
3360 | const Handle(Prs3d_Presentation)& aPresentation, | |
79104795 | 3361 | const Standard_Integer aMode) Standard_OVERRIDE; |
9558a876 | 3362 | |
a577aaab | 3363 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
79104795 | 3364 | const Standard_Integer /*theMode*/) Standard_OVERRIDE; |
9558a876 | 3365 | |
eb4320f2 | 3366 | bool CheckInputCommand (const TCollection_AsciiString theCommand, |
da87ddc3 | 3367 | const Handle(TColStd_HArray1OfAsciiString)& theArgsArray, |
eb4320f2 | 3368 | Standard_Integer &theArgIndex, |
3369 | Standard_Integer theArgCount, | |
3370 | Standard_Integer theMaxArgs); | |
3371 | ||
acc6542a | 3372 | //! Sets color for the shading aspect of the drawer used in this interactive object |
3373 | //! @param theColor the color to be set | |
3374 | void setColorForShadingAspect(const Quantity_Color& theColor); | |
3375 | ||
3376 | //! Replaces shading aspect from myDrawer->Link() with the own shading aspect of myDrawer for this interactive object | |
3377 | void replaceShadingAspect(); | |
3378 | ||
9558a876 A |
3379 | protected: |
3380 | ||
a577aaab | 3381 | Handle(Graphic3d_AspectMarker3d) myMarkerAspect; |
9427bc1d | 3382 | Handle(Graphic3d_ArrayOfPrimitives) myPArray; |
9558a876 A |
3383 | |
3384 | }; | |
3385 | ||
35e08fe8 | 3386 | void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
9427bc1d | 3387 | const Handle(Prs3d_Presentation)& thePrs, |
3388 | const Standard_Integer theMode) | |
9558a876 | 3389 | { |
9427bc1d | 3390 | if (myPArray.IsNull() || theMode != 0) |
3391 | { | |
3392 | return; | |
3393 | } | |
3394 | ||
3395 | Handle(Graphic3d_Group) aGroup = thePrs->NewGroup(); | |
3396 | if (!myMarkerAspect.IsNull()) | |
3397 | { | |
3398 | aGroup->SetGroupPrimitivesAspect (myMarkerAspect); | |
3399 | } | |
bf5f0ca2 | 3400 | else |
3401 | { | |
3402 | aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect()); | |
3403 | } | |
9427bc1d | 3404 | aGroup->AddPrimitiveArray (myPArray); |
3405 | } | |
3406 | ||
da87ddc3 | 3407 | Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimType, |
3408 | const Handle(TColStd_HArray1OfAsciiString)& theDesc, | |
3409 | const Handle(Graphic3d_AspectMarker3d)& theMarkerAspect, | |
3410 | Standard_Boolean theToPatch) | |
9427bc1d | 3411 | { |
9427bc1d | 3412 | myMarkerAspect = theMarkerAspect; |
da87ddc3 | 3413 | if (!theToPatch) |
3414 | { | |
3415 | myPArray.Nullify(); | |
3416 | } | |
9558a876 | 3417 | |
eb4320f2 | 3418 | // Parsing array description |
9558a876 | 3419 | Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0; |
34253146 | 3420 | Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None; |
9558a876 | 3421 | |
da87ddc3 | 3422 | const Standard_Integer anArgsCount = theDesc->Length(); |
9558a876 | 3423 | TCollection_AsciiString aCommand; |
da87ddc3 | 3424 | for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); ) |
9558a876 | 3425 | { |
da87ddc3 | 3426 | aCommand = theDesc->Value (anArgIndex); |
9558a876 | 3427 | aCommand.LowerCase(); |
9558a876 | 3428 | |
da87ddc3 | 3429 | if (CheckInputCommand ("-deinterleaved", theDesc, anArgIndex, 0, anArgsCount)) |
3430 | { | |
3431 | anArrayFlags |= Graphic3d_ArrayFlags_AttribsDeinterleaved; | |
3432 | } | |
3433 | else if (CheckInputCommand ("-mutable", theDesc, anArgIndex, 0, anArgsCount)) | |
3434 | { | |
3435 | anArrayFlags |= Graphic3d_ArrayFlags_AttribsMutable; | |
3436 | anArrayFlags |= Graphic3d_ArrayFlags_IndexesMutable; | |
3437 | } | |
9558a876 | 3438 | // vertex command |
da87ddc3 | 3439 | else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3440 | { |
3441 | // vertex has a normal or normal with color or texel | |
da87ddc3 | 3442 | if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount)) |
34253146 | 3443 | { |
3444 | anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal; | |
3445 | } | |
9558a876 A |
3446 | |
3447 | // vertex has a color | |
da87ddc3 | 3448 | if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount)) |
34253146 | 3449 | { |
3450 | anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor; | |
3451 | } | |
9558a876 A |
3452 | |
3453 | // vertex has a texel | |
da87ddc3 | 3454 | if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount)) |
34253146 | 3455 | { |
3456 | anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel; | |
3457 | } | |
9558a876 A |
3458 | |
3459 | aVertexNum++; | |
3460 | } | |
3461 | // bound command | |
da87ddc3 | 3462 | else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount)) |
9558a876 A |
3463 | { |
3464 | // bound has color | |
da87ddc3 | 3465 | if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount)) |
34253146 | 3466 | { |
3467 | anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor; | |
3468 | } | |
9558a876 A |
3469 | |
3470 | aBoundNum++; | |
3471 | } | |
3472 | // edge command | |
da87ddc3 | 3473 | else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount)) |
9558a876 | 3474 | { |
9558a876 A |
3475 | aEdgeNum++; |
3476 | } | |
3477 | // unknown command | |
3478 | else | |
eb4320f2 | 3479 | anArgIndex++; |
9558a876 A |
3480 | } |
3481 | ||
da87ddc3 | 3482 | if (myPArray.IsNull()) |
a577aaab | 3483 | { |
da87ddc3 | 3484 | myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags); |
3485 | } | |
3486 | else | |
3487 | { | |
3488 | if (myPArray->Type() != thePrimType | |
3489 | || aVertexNum > myPArray->VertexNumberAllocated() | |
3490 | || aEdgeNum > myPArray->EdgeNumberAllocated() | |
3491 | || aBoundNum > myPArray->BoundNumberAllocated() | |
3492 | || !myPArray->Attributes()->IsMutable() | |
3493 | || (!myPArray->Indices().IsNull() && !myPArray->Indices()->IsMutable())) | |
3494 | { | |
23fe70ec | 3495 | Message::SendFail ("Syntax error: array cannot be patched"); |
da87ddc3 | 3496 | return Standard_False; |
3497 | } | |
3498 | ||
3499 | myPArray->Attributes()->NbElements = aVertexNum; | |
3500 | if (Handle(Graphic3d_AttribBuffer) anAttribs = Handle(Graphic3d_AttribBuffer)::DownCast (myPArray->Attributes())) | |
3501 | { | |
3502 | anAttribs->Invalidate (0, aVertexNum - 1); | |
3503 | } | |
3504 | if (!myPArray->Indices().IsNull()) | |
3505 | { | |
3506 | myPArray->Indices()->NbElements = aEdgeNum; | |
3507 | } | |
3508 | if (!myPArray->Bounds().IsNull()) | |
3509 | { | |
3510 | myPArray->Bounds()->NbBounds = aBoundNum; | |
3511 | } | |
a577aaab | 3512 | } |
9558a876 | 3513 | |
da87ddc3 | 3514 | Standard_Integer aVertIndex = 0; |
3515 | for (Standard_Integer anArgIndex = theDesc->Lower(); anArgIndex <= theDesc->Upper(); ) | |
9558a876 | 3516 | { |
da87ddc3 | 3517 | aCommand = theDesc->Value (anArgIndex); |
9558a876 | 3518 | aCommand.LowerCase(); |
da87ddc3 | 3519 | if (!aCommand.IsAscii() |
3520 | || aCommand.IsEmpty()) | |
3521 | { | |
9558a876 | 3522 | break; |
da87ddc3 | 3523 | } |
9558a876 | 3524 | |
da87ddc3 | 3525 | // skip beautifiers (syntax is not actually validated) |
3526 | if (aCommand == "-deinterleaved" | |
3527 | || aCommand == "-mutable" | |
3528 | || aCommand.Value (1) == '(' | |
3529 | || aCommand.Value (1) == ')' | |
3530 | || aCommand.Value (1) == ',') | |
3531 | { | |
3532 | ++anArgIndex; | |
3533 | } | |
9558a876 | 3534 | // vertex command |
da87ddc3 | 3535 | else if (CheckInputCommand ("v", theDesc, anArgIndex, 3, anArgsCount)) |
9558a876 | 3536 | { |
da87ddc3 | 3537 | const Graphic3d_Vec3 aVert ((float )theDesc->Value (anArgIndex - 3).RealValue(), |
3538 | (float )theDesc->Value (anArgIndex - 2).RealValue(), | |
3539 | (float )theDesc->Value (anArgIndex - 1).RealValue()); | |
3540 | if ((anArrayFlags & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0 | |
3541 | || (anArrayFlags & Graphic3d_ArrayFlags_AttribsMutable) != 0) | |
3542 | { | |
3543 | ++aVertIndex; | |
3544 | myPArray->SetVertice (aVertIndex, aVert.x(), aVert.y(), aVert.z()); | |
3545 | } | |
3546 | else | |
3547 | { | |
3548 | aVertIndex = myPArray->AddVertex (aVert); | |
3549 | } | |
9558a876 A |
3550 | |
3551 | // vertex has a normal or normal with color or texel | |
da87ddc3 | 3552 | if (CheckInputCommand ("n", theDesc, anArgIndex, 3, anArgsCount)) |
3553 | { | |
3554 | const Graphic3d_Vec3 aNorm ((float )theDesc->Value (anArgIndex - 3).RealValue(), | |
3555 | (float )theDesc->Value (anArgIndex - 2).RealValue(), | |
3556 | (float )theDesc->Value (anArgIndex - 1).RealValue()); | |
3557 | myPArray->SetVertexNormal (aVertIndex, aNorm.x(), aNorm.y(), aNorm.z()); | |
3558 | } | |
9558a876 | 3559 | |
da87ddc3 | 3560 | if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount)) |
3561 | { | |
3562 | const Graphic3d_Vec3d aCol (theDesc->Value (anArgIndex - 3).RealValue(), | |
3563 | theDesc->Value (anArgIndex - 2).RealValue(), | |
3564 | theDesc->Value (anArgIndex - 1).RealValue()); | |
3565 | myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b()); | |
3566 | } | |
3567 | if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount)) | |
3568 | { | |
3569 | const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(), | |
3570 | (float )theDesc->Value (anArgIndex - 1).RealValue()); | |
3571 | myPArray->SetVertexTexel (aVertIndex, aTex.x(), aTex.y()); | |
3572 | } | |
9558a876 A |
3573 | } |
3574 | // bounds command | |
da87ddc3 | 3575 | else if (CheckInputCommand ("b", theDesc, anArgIndex, 1, anArgsCount)) |
9558a876 | 3576 | { |
da87ddc3 | 3577 | Standard_Integer aVertCount = theDesc->Value (anArgIndex - 1).IntegerValue(); |
9558a876 | 3578 | |
da87ddc3 | 3579 | if (CheckInputCommand ("c", theDesc, anArgIndex, 3, anArgsCount)) |
3580 | myPArray->AddBound (aVertCount, | |
3581 | theDesc->Value (anArgIndex - 3).RealValue(), | |
3582 | theDesc->Value (anArgIndex - 2).RealValue(), | |
3583 | theDesc->Value (anArgIndex - 1).RealValue()); | |
9558a876 A |
3584 | |
3585 | else | |
da87ddc3 | 3586 | myPArray->AddBound (aVertCount); |
9558a876 A |
3587 | } |
3588 | // edge command | |
da87ddc3 | 3589 | else if (CheckInputCommand ("e", theDesc, anArgIndex, 1, anArgsCount)) |
9558a876 | 3590 | { |
da87ddc3 | 3591 | const Standard_Integer anEdge = theDesc->Value (anArgIndex - 1).IntegerValue(); |
3592 | myPArray->AddEdge (anEdge); | |
9558a876 A |
3593 | } |
3594 | // unknown command | |
3595 | else | |
da87ddc3 | 3596 | { |
23fe70ec | 3597 | Message::SendFail() << "Syntax error: unknown argument '" << theDesc->Value(anArgIndex) << "'"; |
da87ddc3 | 3598 | return Standard_False; |
3599 | } | |
eb4320f2 | 3600 | } |
da87ddc3 | 3601 | return Standard_True; |
eb4320f2 | 3602 | } |
3603 | ||
acc6542a | 3604 | //======================================================================= |
3605 | // function : SetColor | |
3606 | // purpose : | |
3607 | //======================================================================= | |
3608 | void MyPArrayObject::SetColor (const Quantity_Color& theColor) | |
3609 | { | |
3610 | AIS_InteractiveObject::SetColor (theColor); | |
3611 | setColorForShadingAspect (theColor); | |
3612 | if (myMarkerAspect) | |
3613 | { | |
3614 | myMarkerAspect->SetColor (theColor); | |
3615 | } | |
3616 | SynchronizeAspects(); | |
3617 | } | |
3618 | ||
eb4320f2 | 3619 | void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
9427bc1d | 3620 | const Standard_Integer theMode) |
eb4320f2 | 3621 | { |
9427bc1d | 3622 | if (theMode != 0 |
3623 | || myPArray.IsNull()) | |
3624 | { | |
3625 | return; | |
3626 | } | |
eb4320f2 | 3627 | |
9427bc1d | 3628 | Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this); |
3629 | if (Handle(Graphic3d_ArrayOfTriangles) aTris = Handle(Graphic3d_ArrayOfTriangles)::DownCast (myPArray)) | |
3630 | { | |
3631 | Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner); | |
3632 | aSensitive->InitTriangulation (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true); | |
3633 | theSelection->Add (aSensitive); | |
3634 | } | |
3635 | else if (Handle(Graphic3d_ArrayOfSegments) aSegs = Handle(Graphic3d_ArrayOfSegments)::DownCast (myPArray)) | |
eb4320f2 | 3636 | { |
9427bc1d | 3637 | if (aSegs->EdgeNumber() > 0) |
eb4320f2 | 3638 | { |
9427bc1d | 3639 | for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->EdgeNumber(); aPntIter += 2) |
3640 | { | |
3641 | Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aSegs->Edge (aPntIter)), aSegs->Vertice (aSegs->Edge (aPntIter + 1))); | |
3642 | aSeg->SetSensitivityFactor (4); | |
3643 | theSelection->Add (aSeg); | |
3644 | } | |
eb4320f2 | 3645 | } |
3646 | else | |
3647 | { | |
9427bc1d | 3648 | for (Standard_Integer aPntIter = 1; aPntIter <= aSegs->VertexNumber(); aPntIter += 2) |
3649 | { | |
3650 | Handle(Select3D_SensitiveSegment) aSeg = new Select3D_SensitiveSegment (anOwner, aSegs->Vertice (aPntIter), aSegs->Vertice (aPntIter + 1)); | |
3651 | aSeg->SetSensitivityFactor (4); | |
3652 | theSelection->Add (aSeg); | |
3653 | } | |
eb4320f2 | 3654 | } |
3655 | } | |
9427bc1d | 3656 | else |
3657 | { | |
3658 | Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner); | |
3659 | aSensitive->SetSensitivityFactor (8); | |
3660 | aSensitive->InitPoints (myPArray->Attributes(), myPArray->Indices(), TopLoc_Location(), true); | |
3661 | theSelection->Add (aSensitive); | |
3662 | } | |
eb4320f2 | 3663 | } |
3664 | ||
3665 | bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand, | |
da87ddc3 | 3666 | const Handle(TColStd_HArray1OfAsciiString)& theArgsArray, |
eb4320f2 | 3667 | Standard_Integer &theArgIndex, |
3668 | Standard_Integer theArgCount, | |
3669 | Standard_Integer theMaxArgs) | |
3670 | { | |
3671 | // check if there is more elements than expected | |
3672 | if (theArgIndex >= theMaxArgs) | |
3673 | return false; | |
3674 | ||
3675 | TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex); | |
3676 | aStrCommand.LowerCase(); | |
3677 | if (aStrCommand.Search(theCommand) != 1 || | |
3678 | theArgIndex + (theArgCount - 1) >= theMaxArgs) | |
3679 | return false; | |
3680 | ||
3681 | // go to the first data element | |
3682 | theArgIndex++; | |
3683 | ||
3684 | // check data if it can be converted to numeric | |
3685 | for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++) | |
3686 | { | |
3687 | aStrCommand = theArgsArray->Value (theArgIndex); | |
3688 | if (!aStrCommand.IsRealValue()) | |
3689 | return false; | |
3690 | } | |
3691 | ||
3692 | return true; | |
3693 | } | |
3694 | ||
acc6542a | 3695 | //======================================================================= |
3696 | // function : setColorForShadingAspect | |
3697 | // purpose : | |
3698 | //======================================================================= | |
3699 | void MyPArrayObject::setColorForShadingAspect (const Quantity_Color& theColor) | |
3700 | { | |
3701 | if (myDrawer->SetupOwnShadingAspect()) | |
3702 | { | |
3703 | replaceShadingAspect(); | |
3704 | } | |
3705 | myDrawer->ShadingAspect()->SetColor (theColor); | |
3706 | } | |
3707 | ||
3708 | //======================================================================= | |
3709 | // function : replaceShadingAspect | |
3710 | // purpose : | |
3711 | //======================================================================= | |
3712 | void MyPArrayObject::replaceShadingAspect() | |
3713 | { | |
3714 | if (!myDrawer->Link()) | |
3715 | { | |
3716 | return; | |
3717 | } | |
3718 | Graphic3d_MapOfAspectsToAspects anAspectReplacementMap; | |
3719 | anAspectReplacementMap.Bind (myDrawer->Link()->ShadingAspect()->Aspect(), myDrawer->ShadingAspect()->Aspect()); | |
3720 | replaceAspects (anAspectReplacementMap); | |
3721 | } | |
3722 | ||
eb4320f2 | 3723 | //============================================================================= |
3724 | //function : VDrawPArray | |
3725 | //purpose : Draws primitives array from list of vertexes, bounds, edges | |
3726 | //============================================================================= | |
3727 | ||
3728 | static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3729 | { | |
3730 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3731 | if (aContextAIS.IsNull()) | |
3732 | { | |
23fe70ec | 3733 | Message::SendFail ("Error: no active Viewer"); |
eb4320f2 | 3734 | return 1; |
3735 | } | |
3736 | else if (argc < 3) | |
3737 | { | |
23fe70ec | 3738 | Message::SendFail ("Syntax error: wrong number of arguments"); |
eb4320f2 | 3739 | return 1; |
3740 | } | |
3741 | ||
3742 | // read the arguments | |
da87ddc3 | 3743 | Standard_Integer anArgIndex = 1; |
3744 | TCollection_AsciiString aName (argv[anArgIndex++]); | |
3745 | TCollection_AsciiString anArrayType (argv[anArgIndex++]); | |
3746 | anArrayType.LowerCase(); | |
3747 | Handle(MyPArrayObject) aPObject; | |
4a056d20 | 3748 | if (anArrayType == "-shape") |
3749 | { | |
da87ddc3 | 3750 | Standard_CString aShapeName = argv[anArgIndex++]; |
4a056d20 | 3751 | TopoDS_Shape aShape = DBRep::Get (aShapeName); |
3752 | Handle(Graphic3d_ArrayOfPrimitives) aTris = StdPrs_ShadedShape::FillTriangles (aShape); | |
3753 | if (aShape.IsNull()) | |
3754 | { | |
23fe70ec | 3755 | Message::SendFail() << "Syntax error: shape '" << aShapeName << "' is not found"; |
4a056d20 | 3756 | return 1; |
3757 | } | |
3758 | else if (aTris.IsNull()) | |
3759 | { | |
23fe70ec | 3760 | Message::SendFail() << "Syntax error: shape '" << aShapeName << "' is not triangulated"; |
4a056d20 | 3761 | return 1; |
3762 | } | |
3763 | ||
da87ddc3 | 3764 | aPObject = new MyPArrayObject (aTris); |
4a056d20 | 3765 | ViewerTest::Display (aName, aPObject); |
3766 | return 0; | |
3767 | } | |
da87ddc3 | 3768 | else if (anArrayType == "-patch" |
3769 | || anArrayType == "-modify" | |
3770 | || anArrayType == "-edit") | |
3771 | { | |
3772 | if (argc >= 3) | |
3773 | { | |
3774 | anArrayType = argv[anArgIndex++]; | |
3775 | anArrayType.LowerCase(); | |
3776 | } | |
eb4320f2 | 3777 | |
da87ddc3 | 3778 | if (GetMapOfAIS().IsBound2 (aName)) |
3779 | { | |
3780 | aPObject = Handle(MyPArrayObject)::DownCast (GetMapOfAIS().Find2 (aName)); | |
3781 | } | |
3782 | if (aPObject.IsNull()) | |
3783 | { | |
23fe70ec | 3784 | Message::SendFail() << "Syntax error: object '" << aName << "' cannot be found"; |
da87ddc3 | 3785 | return 1; |
3786 | } | |
3787 | } | |
eb4320f2 | 3788 | |
da87ddc3 | 3789 | Standard_Boolean hasVertex = Standard_False; |
eb4320f2 | 3790 | |
da87ddc3 | 3791 | Graphic3d_TypeOfPrimitiveArray aPrimType = Graphic3d_TOPA_UNDEFINED; |
3792 | if (anArrayType == "points") | |
3793 | { | |
3794 | aPrimType = Graphic3d_TOPA_POINTS; | |
3795 | } | |
3796 | else if (anArrayType == "segments") | |
3797 | { | |
3798 | aPrimType = Graphic3d_TOPA_SEGMENTS; | |
3799 | } | |
3800 | else if (anArrayType == "polylines") | |
3801 | { | |
3802 | aPrimType = Graphic3d_TOPA_POLYLINES; | |
3803 | } | |
3804 | else if (anArrayType == "triangles") | |
3805 | { | |
3806 | aPrimType = Graphic3d_TOPA_TRIANGLES; | |
3807 | } | |
3808 | else if (anArrayType == "trianglefans") | |
eb4320f2 | 3809 | { |
da87ddc3 | 3810 | aPrimType = Graphic3d_TOPA_TRIANGLEFANS; |
3811 | } | |
3812 | else if (anArrayType == "trianglestrips") | |
3813 | { | |
3814 | aPrimType = Graphic3d_TOPA_TRIANGLESTRIPS; | |
3815 | } | |
3816 | else if (anArrayType == "quads") | |
3817 | { | |
3818 | aPrimType = Graphic3d_TOPA_QUADRANGLES; | |
3819 | } | |
3820 | else if (anArrayType == "quadstrips") | |
3821 | { | |
3822 | aPrimType = Graphic3d_TOPA_QUADRANGLESTRIPS; | |
3823 | } | |
3824 | else if (anArrayType == "polygons") | |
3825 | { | |
3826 | aPrimType = Graphic3d_TOPA_POLYGONS; | |
3827 | } | |
3828 | if (aPrimType == Graphic3d_TOPA_UNDEFINED) | |
3829 | { | |
23fe70ec | 3830 | Message::SendFail ("Syntax error: unexpected type of primitives array"); |
eb4320f2 | 3831 | return 1; |
3832 | } | |
3833 | ||
da87ddc3 | 3834 | Standard_Integer aLowerArg = anArgIndex; |
3835 | Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 3); | |
3836 | for (; anArgIndex < argc; ++anArgIndex) | |
eb4320f2 | 3837 | { |
da87ddc3 | 3838 | TCollection_AsciiString aCommand (argv[anArgIndex]); |
eb4320f2 | 3839 | aCommand.LowerCase(); |
3840 | if (!aCommand.IsAscii()) | |
3841 | { | |
da87ddc3 | 3842 | di << "Unexpected argument: #" << anArgIndex - 1 << " , " |
eb4320f2 | 3843 | << "should be an array element: 'v', 'b', 'e' \n"; |
3844 | break; | |
3845 | } | |
3846 | ||
3847 | if (aCommand == "v") | |
3848 | { | |
3849 | hasVertex = Standard_True; | |
3850 | } | |
3851 | ||
da87ddc3 | 3852 | anArgsArray->SetValue (anArgIndex - aLowerArg, aCommand); |
eb4320f2 | 3853 | } |
3854 | ||
3855 | if (!hasVertex) | |
3856 | { | |
3857 | di << "You should pass any verticies in the list of array elements\n"; | |
3858 | return 1; | |
3859 | } | |
3860 | ||
3861 | Handle(Graphic3d_AspectMarker3d) anAspPoints; | |
da87ddc3 | 3862 | if (aPrimType == Graphic3d_TOPA_POINTS) |
eb4320f2 | 3863 | { |
3864 | anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f); | |
9558a876 A |
3865 | } |
3866 | ||
9558a876 | 3867 | // create primitives array object |
da87ddc3 | 3868 | if (aPObject.IsNull()) |
3869 | { | |
3870 | // register the object in map | |
3871 | aPObject = new MyPArrayObject (aPrimType, anArgsArray, anAspPoints); | |
3872 | VDisplayAISObject (aName, aPObject); | |
3873 | } | |
3874 | else | |
3875 | { | |
3876 | aPObject->Init (aPrimType, anArgsArray, anAspPoints, Standard_True); | |
3877 | ViewerTest::CurrentView()->Redraw(); | |
3878 | } | |
9558a876 A |
3879 | return 0; |
3880 | } | |
3881 | ||
1beb58d7 | 3882 | namespace |
3883 | { | |
3884 | //! Auxiliary function for parsing translation vector - either 2D or 3D. | |
3885 | static Standard_Integer parseTranslationVec (Standard_Integer theArgNb, | |
3886 | const char** theArgVec, | |
3887 | gp_Vec& theVec) | |
3888 | { | |
3889 | if (theArgNb < 2) | |
3890 | { | |
3891 | return 0; | |
3892 | } | |
3893 | ||
3894 | TCollection_AsciiString anX (theArgVec[0]); | |
3895 | TCollection_AsciiString anY (theArgVec[1]); | |
3896 | if (!anX.IsRealValue() | |
3897 | || !anY.IsRealValue()) | |
3898 | { | |
3899 | return 0; | |
3900 | } | |
3901 | ||
3902 | theVec.SetX (anX.RealValue()); | |
3903 | theVec.SetY (anY.RealValue()); | |
3904 | if (theArgNb >= 3) | |
3905 | { | |
3906 | TCollection_AsciiString anZ (theArgVec[2]); | |
3907 | if (anZ.IsRealValue()) | |
3908 | { | |
3909 | theVec.SetZ (anZ.RealValue()); | |
3910 | return 3; | |
3911 | } | |
3912 | } | |
3913 | return 2; | |
3914 | } | |
3915 | } | |
3916 | ||
29d43f9c A |
3917 | //======================================================================= |
3918 | //function : VSetLocation | |
3919 | //purpose : Change location of AIS interactive object | |
3920 | //======================================================================= | |
3921 | ||
1beb58d7 | 3922 | static Standard_Integer VSetLocation (Draw_Interpretor& theDI, |
4e18052b | 3923 | Standard_Integer theArgNb, |
3924 | const char** theArgVec) | |
29d43f9c A |
3925 | { |
3926 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4e18052b | 3927 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
29d43f9c A |
3928 | if (aContext.IsNull()) |
3929 | { | |
23fe70ec | 3930 | Message::SendFail ("Error: no active viewer"); |
29d43f9c A |
3931 | return 1; |
3932 | } | |
3933 | ||
1beb58d7 | 3934 | Standard_Boolean toPrintInfo = Standard_True; |
3935 | Handle(AIS_InteractiveObject) anObj; | |
3936 | TCollection_AsciiString aCmdName (theArgVec[0]); | |
3937 | aCmdName.LowerCase(); | |
3938 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
29d43f9c | 3939 | { |
1beb58d7 | 3940 | TCollection_AsciiString anArg = theArgVec[anArgIter]; |
3941 | anArg.LowerCase(); | |
3942 | if (anUpdateTool.parseRedrawMode (anArg)) | |
4e18052b | 3943 | { |
3944 | continue; | |
3945 | } | |
1beb58d7 | 3946 | else if (anObj.IsNull()) |
4e18052b | 3947 | { |
1beb58d7 | 3948 | const TCollection_AsciiString aName (theArgVec[anArgIter]); |
8f521168 | 3949 | GetMapOfAIS().Find2 (aName, anObj); |
1beb58d7 | 3950 | if (anObj.IsNull()) |
3951 | { | |
23fe70ec | 3952 | Message::SendFail() << "Error: object '" << aName << "' is not displayed"; |
1beb58d7 | 3953 | return 1; |
3954 | } | |
4e18052b | 3955 | } |
1beb58d7 | 3956 | else if (anArg == "-reset") |
3957 | { | |
3958 | toPrintInfo = Standard_False; | |
3959 | aContext->SetLocation (anObj, gp_Trsf()); | |
3960 | } | |
3961 | else if (anArg == "-copyfrom" | |
3962 | || anArg == "-copy") | |
4e18052b | 3963 | { |
4e18052b | 3964 | if (anArgIter + 1 >= theArgNb) |
3965 | { | |
23fe70ec | 3966 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
4e18052b | 3967 | return 1; |
3968 | } | |
1beb58d7 | 3969 | |
3970 | const TCollection_AsciiString aName2 (theArgVec[anArgIter + 1]); | |
1beb58d7 | 3971 | Handle(AIS_InteractiveObject) anObj2; |
8f521168 | 3972 | GetMapOfAIS().Find2 (aName2, anObj2); |
1beb58d7 | 3973 | if (anObj2.IsNull()) |
4e18052b | 3974 | { |
23fe70ec | 3975 | Message::SendFail() << "Error: object '" << aName2 << "' is not displayed"; |
1beb58d7 | 3976 | return 1; |
4e18052b | 3977 | } |
1beb58d7 | 3978 | |
3979 | ++anArgIter; | |
3980 | aContext->SetLocation (anObj, anObj2->LocalTransformation()); | |
4e18052b | 3981 | } |
dbc8becf | 3982 | else if (anArg == "-rotate" |
3983 | || anArg == "-prerotate") | |
4e18052b | 3984 | { |
1beb58d7 | 3985 | toPrintInfo = Standard_False; |
3986 | if (anArgIter + 7 >= theArgNb) | |
3987 | { | |
23fe70ec | 3988 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
1beb58d7 | 3989 | return 1; |
3990 | } | |
7d9e854b | 3991 | |
1beb58d7 | 3992 | gp_Trsf aTrsf; |
3993 | aTrsf.SetRotation (gp_Ax1 (gp_Pnt (Draw::Atof (theArgVec[anArgIter + 1]), | |
3994 | Draw::Atof (theArgVec[anArgIter + 2]), | |
3995 | Draw::Atof (theArgVec[anArgIter + 3])), | |
3996 | gp_Vec (Draw::Atof (theArgVec[anArgIter + 4]), | |
3997 | Draw::Atof (theArgVec[anArgIter + 5]), | |
3998 | Draw::Atof (theArgVec[anArgIter + 6]))), | |
3999 | Draw::Atof (theArgVec[anArgIter + 7]) * (M_PI / 180.0)); | |
4000 | anArgIter += 7; | |
7d9e854b | 4001 | |
dbc8becf | 4002 | if (anArg == "-prerotate") |
4003 | { | |
4004 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
4005 | } | |
4006 | else | |
4007 | { | |
4008 | aTrsf = aTrsf * anObj->LocalTransformation(); | |
4009 | } | |
1beb58d7 | 4010 | aContext->SetLocation (anObj, aTrsf); |
7d9e854b | 4011 | } |
dbc8becf | 4012 | else if (anArg == "-translate" |
4013 | || anArg == "-pretranslate") | |
7d9e854b | 4014 | { |
1beb58d7 | 4015 | toPrintInfo = Standard_False; |
4016 | gp_Vec aLocVec; | |
4017 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec); | |
4018 | anArgIter += aNbParsed; | |
4019 | if (aNbParsed == 0) | |
4020 | { | |
23fe70ec | 4021 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
1beb58d7 | 4022 | return 1; |
4023 | } | |
7d9e854b | 4024 | |
1beb58d7 | 4025 | gp_Trsf aTrsf; |
4026 | aTrsf.SetTranslationPart (aLocVec); | |
dbc8becf | 4027 | if (anArg == "-pretranslate") |
4028 | { | |
4029 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
4030 | } | |
4031 | else | |
4032 | { | |
4033 | aTrsf = aTrsf * anObj->LocalTransformation(); | |
4034 | } | |
1beb58d7 | 4035 | aContext->SetLocation (anObj, aTrsf); |
7d9e854b | 4036 | } |
1beb58d7 | 4037 | else if (anArg == "-scale" |
dbc8becf | 4038 | || anArg == "-prescale" |
1beb58d7 | 4039 | || anArg == "-setscale") |
4040 | { | |
4041 | toPrintInfo = Standard_False; | |
4042 | gp_XYZ aScaleLoc; | |
4043 | Standard_Real aScale = 1.0; | |
4044 | Standard_Boolean toPrintScale = Standard_True; | |
4045 | Standard_Boolean hasScaleLoc = Standard_False; | |
4046 | if (anArgIter + 4 < theArgNb) | |
4047 | { | |
4048 | TCollection_AsciiString aScaleArgs[4] = | |
4049 | { | |
4050 | TCollection_AsciiString (theArgVec[anArgIter + 1]), | |
4051 | TCollection_AsciiString (theArgVec[anArgIter + 2]), | |
4052 | TCollection_AsciiString (theArgVec[anArgIter + 3]), | |
4053 | TCollection_AsciiString (theArgVec[anArgIter + 4]) | |
4054 | }; | |
4055 | Standard_Integer aScaleArgIter = 0; | |
4056 | for (; aScaleArgIter < 4; ++aScaleArgIter) | |
4057 | { | |
4058 | if (!aScaleArgs[aScaleArgIter].IsRealValue()) | |
4059 | { | |
4060 | break; | |
4061 | } | |
4062 | } | |
4063 | if (aScaleArgIter == 4) | |
4064 | { | |
4065 | aScaleLoc.SetCoord (aScaleArgs[0].RealValue(), aScaleArgs[1].RealValue(), aScaleArgs[2].RealValue()); | |
4066 | aScale = aScaleArgs[3].RealValue(); | |
4067 | anArgIter += 4; | |
4068 | toPrintScale = Standard_False; | |
4069 | hasScaleLoc = Standard_True; | |
4070 | } | |
4071 | else if (aScaleArgIter >= 1) | |
4072 | { | |
4073 | aScale = aScaleArgs[0].RealValue(); | |
4074 | ++anArgIter; | |
4075 | toPrintScale = Standard_False; | |
4076 | } | |
4077 | } | |
4078 | else if (anArgIter + 1 < theArgNb) | |
4079 | { | |
4080 | TCollection_AsciiString aScaleArg (theArgVec[anArgIter + 1]); | |
4081 | if (aScaleArg.IsRealValue()) | |
4082 | { | |
4083 | aScale = aScaleArg.RealValue(); | |
4084 | ++anArgIter; | |
4085 | toPrintScale = Standard_False; | |
4086 | } | |
4087 | } | |
4088 | ||
4089 | if (toPrintScale) | |
4090 | { | |
dbc8becf | 4091 | if (anArg == "-setscale" |
4092 | || anArg == "-prescale") | |
1beb58d7 | 4093 | { |
23fe70ec | 4094 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
1beb58d7 | 4095 | return 1; |
4096 | } | |
7d9e854b | 4097 | |
1beb58d7 | 4098 | char aText[1024]; |
4099 | Sprintf (aText, "%g ", anObj->LocalTransformation().ScaleFactor()); | |
4100 | theDI << aText; | |
4101 | continue; | |
4102 | } | |
7d9e854b | 4103 | |
1beb58d7 | 4104 | if (anArg == "-setscale") |
4105 | { | |
4106 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
4107 | if (hasScaleLoc) | |
4108 | { | |
4109 | aTrsf.SetScale (aScaleLoc, aScale); | |
4110 | } | |
4111 | else | |
4112 | { | |
4113 | aTrsf.SetScaleFactor (aScale); | |
4114 | } | |
4115 | aContext->SetLocation (anObj, aTrsf); | |
4116 | } | |
4117 | else | |
4118 | { | |
4119 | gp_Trsf aTrsf; | |
4120 | if (hasScaleLoc) | |
4121 | { | |
4122 | aTrsf.SetScale (aScaleLoc, aScale); | |
dbc8becf | 4123 | } |
4124 | else | |
4125 | { | |
4126 | aTrsf.SetScaleFactor (aScale); | |
4127 | } | |
4128 | ||
4129 | if (anArg == "-prescale") | |
4130 | { | |
1beb58d7 | 4131 | aTrsf = anObj->LocalTransformation() * aTrsf; |
4132 | } | |
4133 | else | |
4134 | { | |
dbc8becf | 4135 | aTrsf = aTrsf * anObj->LocalTransformation(); |
1beb58d7 | 4136 | } |
4137 | aContext->SetLocation (anObj, aTrsf); | |
4138 | } | |
7d9e854b | 4139 | } |
dbc8becf | 4140 | else if (anArg == "-mirror" |
4141 | || anArg == "-premirror") | |
7d9e854b | 4142 | { |
1beb58d7 | 4143 | toPrintInfo = Standard_False; |
4144 | if (anArgIter + 6 >= theArgNb) | |
4145 | { | |
23fe70ec | 4146 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
1beb58d7 | 4147 | return 1; |
4148 | } | |
7d9e854b | 4149 | |
1beb58d7 | 4150 | gp_Trsf aTrsf; |
4151 | aTrsf.SetMirror (gp_Ax2 (gp_Pnt (Draw::Atof(theArgVec[theArgNb - 6]), | |
4152 | Draw::Atof(theArgVec[theArgNb - 5]), | |
4153 | Draw::Atof(theArgVec[theArgNb - 4])), | |
4154 | gp_Vec (Draw::Atof(theArgVec[theArgNb - 3]), | |
4155 | Draw::Atof(theArgVec[theArgNb - 2]), | |
4156 | Draw::Atof(theArgVec[theArgNb - 1])))); | |
4157 | anArgIter += 6; | |
dbc8becf | 4158 | if (anArg == "-premirror") |
4159 | { | |
4160 | aTrsf = anObj->LocalTransformation() * aTrsf; | |
4161 | } | |
4162 | else | |
4163 | { | |
4164 | aTrsf = aTrsf * anObj->LocalTransformation(); | |
4165 | } | |
1beb58d7 | 4166 | aContext->SetLocation (anObj, aTrsf); |
7d9e854b | 4167 | } |
1beb58d7 | 4168 | else if (anArg == "-setrotation" |
4169 | || anArg == "-rotation") | |
7d9e854b | 4170 | { |
1beb58d7 | 4171 | toPrintInfo = Standard_False; |
4172 | if (anArgIter + 4 < theArgNb) | |
4173 | { | |
4174 | TCollection_AsciiString aQuatArgs[4] = | |
4175 | { | |
4176 | TCollection_AsciiString (theArgVec[anArgIter + 1]), | |
4177 | TCollection_AsciiString (theArgVec[anArgIter + 2]), | |
4178 | TCollection_AsciiString (theArgVec[anArgIter + 3]), | |
4179 | TCollection_AsciiString (theArgVec[anArgIter + 4]) | |
4180 | }; | |
4181 | Standard_Integer aQuatArgIter = 0; | |
4182 | for (; aQuatArgIter < 4; ++aQuatArgIter) | |
4183 | { | |
4184 | if (!aQuatArgs[aQuatArgIter].IsRealValue()) | |
4185 | { | |
4186 | break; | |
4187 | } | |
4188 | } | |
7d9e854b | 4189 | |
1beb58d7 | 4190 | if (aQuatArgIter == 4) |
4191 | { | |
4192 | anArgIter += 4; | |
4193 | const gp_Quaternion aQuat (aQuatArgs[0].RealValue(), | |
4194 | aQuatArgs[1].RealValue(), | |
4195 | aQuatArgs[2].RealValue(), | |
4196 | aQuatArgs[3].RealValue()); | |
4197 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
dbc8becf | 4198 | aTrsf.SetRotationPart (aQuat); |
1beb58d7 | 4199 | aContext->SetLocation (anObj, aTrsf); |
4200 | continue; | |
4201 | } | |
4202 | else if (anArg == "-setrotation") | |
4203 | { | |
23fe70ec | 4204 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
1beb58d7 | 4205 | return 1; |
4206 | } | |
4207 | } | |
7d9e854b | 4208 | |
1beb58d7 | 4209 | char aText[1024]; |
4210 | const gp_Quaternion aQuat = anObj->LocalTransformation().GetRotation(); | |
4211 | Sprintf (aText, "%g %g %g %g ", aQuat.X(), aQuat.Y(), aQuat.Z(), aQuat.W()); | |
4212 | theDI << aText; | |
7d9e854b | 4213 | } |
1beb58d7 | 4214 | else if (anArg == "-setlocation" |
4215 | || anArg == "-location") | |
7d9e854b | 4216 | { |
1beb58d7 | 4217 | toPrintInfo = Standard_False; |
4218 | gp_Vec aLocVec; | |
4219 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter - 1, theArgVec + anArgIter + 1, aLocVec); | |
4220 | anArgIter += aNbParsed; | |
4221 | if (aNbParsed != 0) | |
4222 | { | |
4223 | gp_Trsf aTrsf = anObj->LocalTransformation(); | |
4224 | aTrsf.SetTranslationPart (aLocVec); | |
4225 | aContext->SetLocation (anObj, aTrsf); | |
4226 | } | |
4227 | else if (anArg == "-setlocation") | |
4228 | { | |
23fe70ec | 4229 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
1beb58d7 | 4230 | return 1; |
4231 | } | |
4232 | ||
4233 | char aText[1024]; | |
4234 | const gp_XYZ aLoc = anObj->LocalTransformation().TranslationPart(); | |
4235 | Sprintf (aText, "%g %g %g ", aLoc.X(), aLoc.Y(), aLoc.Z()); | |
4236 | theDI << aText; | |
7d9e854b | 4237 | } |
1beb58d7 | 4238 | else if (aCmdName == "vsetlocation") |
7d9e854b | 4239 | { |
1beb58d7 | 4240 | // compatibility with old syntax |
4241 | gp_Vec aLocVec; | |
4242 | Standard_Integer aNbParsed = parseTranslationVec (theArgNb - anArgIter, theArgVec + anArgIter, aLocVec); | |
4243 | if (aNbParsed == 0) | |
4244 | { | |
23fe70ec | 4245 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
1beb58d7 | 4246 | return 1; |
4247 | } | |
4248 | anArgIter = anArgIter + aNbParsed - 1; | |
4249 | ||
4250 | gp_Trsf aTrsf; | |
4251 | aTrsf.SetTranslationPart (aLocVec); | |
4252 | aContext->SetLocation (anObj, aTrsf); | |
4253 | toPrintInfo = Standard_False; | |
7d9e854b | 4254 | } |
4255 | else | |
4256 | { | |
23fe70ec | 4257 | Message::SendFail() << "Error: unknown argument '" << anArg << "'"; |
1beb58d7 | 4258 | return 1; |
7d9e854b | 4259 | } |
1beb58d7 | 4260 | } |
7d9e854b | 4261 | |
1beb58d7 | 4262 | if (anObj.IsNull()) |
4263 | { | |
23fe70ec | 4264 | Message::SendFail ("Syntax error - wrong number of arguments"); |
1beb58d7 | 4265 | return 1; |
4266 | } | |
4267 | else if (!toPrintInfo) | |
4268 | { | |
4269 | return 0; | |
7d9e854b | 4270 | } |
4271 | ||
1beb58d7 | 4272 | const gp_Trsf aTrsf = anObj->LocalTransformation(); |
4273 | const gp_XYZ aLoc = aTrsf.TranslationPart(); | |
4274 | const gp_Quaternion aRot = aTrsf.GetRotation(); | |
4275 | char aText[4096]; | |
4276 | Sprintf (aText, "Location: %g %g %g\n" | |
4277 | "Rotation: %g %g %g %g\n" | |
4278 | "Scale: %g\n", | |
4279 | aLoc.X(), aLoc.Y(), aLoc.Z(), | |
4280 | aRot.X(), aRot.Y(), aRot.Z(), aRot.W(), | |
4281 | aTrsf.ScaleFactor()); | |
4282 | theDI << aText; | |
7d9e854b | 4283 | return 0; |
4284 | } | |
4285 | ||
cc99be36 | 4286 | //! Find displayed object. |
4287 | static Handle(AIS_InteractiveObject) findConnectedObject (const TCollection_AsciiString& theName) | |
4288 | { | |
4289 | Handle(AIS_InteractiveObject) aPrs; | |
4290 | if (!GetMapOfAIS().Find2 (theName, aPrs)) | |
4291 | { | |
4292 | return Handle(AIS_InteractiveObject)(); | |
4293 | } | |
4294 | if (Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (aPrs)) | |
4295 | { | |
4296 | return aConnected; | |
4297 | } | |
4298 | else if (Handle(AIS_MultipleConnectedInteractive) aMultiCon = Handle(AIS_MultipleConnectedInteractive)::DownCast (aPrs)) | |
4299 | { | |
4300 | return aMultiCon; | |
4301 | } | |
4302 | ||
4303 | // replace already displayed object with connected one | |
4304 | TheAISContext()->Remove (aPrs, false); | |
4305 | Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive(); | |
4306 | if (aPrs->HasDisplayMode()) | |
4307 | { | |
4308 | aConnected->SetDisplayMode (aPrs->DisplayMode()); | |
4309 | } | |
4310 | aConnected->Connect (aPrs, aPrs->LocalTransformationGeom()); | |
3e9c1d1e | 4311 | if (!aPrs->TransformPersistence().IsNull()) |
4312 | { | |
4313 | aConnected->SetTransformPersistence (aPrs->TransformPersistence()); | |
4314 | } | |
cc99be36 | 4315 | ViewerTest::Display (theName, aConnected, false); |
4316 | return aConnected; | |
4317 | } | |
4318 | ||
ac04d101 SA |
4319 | //=============================================================================================== |
4320 | //function : VConnect | |
cc99be36 | 4321 | //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location |
ac04d101 | 4322 | //=============================================================================================== |
cc99be36 | 4323 | static Standard_Integer VConnect (Draw_Interpretor& /*di*/, |
4324 | Standard_Integer argc, | |
4325 | const char ** argv) | |
ac04d101 | 4326 | { |
792c785c | 4327 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
4328 | if (aContext.IsNull()) | |
ac04d101 | 4329 | { |
23fe70ec | 4330 | Message::SendFail ("Error: no active viewer"); |
cc99be36 | 4331 | return 1; |
ac04d101 | 4332 | } |
0717ddc1 | 4333 | if (argc < 6) |
ac04d101 | 4334 | { |
23fe70ec | 4335 | Message::SendFail ("Syntax error: expect at least 5 arguments"); |
cc99be36 | 4336 | return 1; |
ac04d101 | 4337 | } |
792c785c | 4338 | |
4339 | // Get values | |
4340 | Standard_Integer anArgIter = 1; | |
cc99be36 | 4341 | const TCollection_AsciiString aName (argv[anArgIter++]); |
4342 | Handle(AIS_MultipleConnectedInteractive) aMultiConObject; | |
792c785c | 4343 | TCollection_AsciiString aColorString (argv[argc-1]); |
dae2a922 | 4344 | Quantity_Color aColor; |
792c785c | 4345 | Standard_Boolean hasColor = Standard_False; |
4346 | if (aColorString.Search ("color=") != -1) | |
ac04d101 | 4347 | { |
792c785c | 4348 | hasColor = Standard_True; |
4349 | aColorString.Remove (1, 6); | |
dae2a922 | 4350 | if (!Quantity_Color::ColorFromName (aColorString.ToCString(), aColor)) |
4351 | { | |
4352 | Message::SendFail() << "Syntax error at " << aColorString; | |
4353 | return 1; | |
4354 | } | |
792c785c | 4355 | } |
792c785c | 4356 | |
0717ddc1 | 4357 | const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc; |
4358 | for (Standard_Integer i = 5; i < aNbShapes; ++i) | |
792c785c | 4359 | { |
0717ddc1 | 4360 | TCollection_AsciiString anOriginObjectName (argv[i]); |
cc99be36 | 4361 | Handle(AIS_InteractiveObject) anObject; |
792c785c | 4362 | if (aName.IsEqual (anOriginObjectName)) |
ac04d101 | 4363 | { |
23fe70ec | 4364 | Message::SendFail ("Syntax error: equal names for connected objects"); |
0717ddc1 | 4365 | continue; |
ac04d101 | 4366 | } |
cc99be36 | 4367 | |
4368 | anObject = findConnectedObject (anOriginObjectName); | |
4369 | if (anObject.IsNull()) | |
792c785c | 4370 | { |
cc99be36 | 4371 | TopoDS_Shape aTDShape = DBRep::Get (anOriginObjectName); |
792c785c | 4372 | if (aTDShape.IsNull()) |
4373 | { | |
23fe70ec | 4374 | Message::SendFail() << "Syntax error: object " << anOriginObjectName << " doesn't exist"; |
cc99be36 | 4375 | return 1; |
792c785c | 4376 | } |
cc99be36 | 4377 | Handle(AIS_Shape) aShapePrs = new AIS_Shape (aTDShape); |
4378 | Handle(AIS_ConnectedInteractive) aConnectedOrig = new AIS_ConnectedInteractive(); | |
4379 | aConnectedOrig->Connect (aShapePrs); | |
4380 | anObject = aConnectedOrig; | |
4381 | ||
6262338c | 4382 | aContext->Load (anObject); |
dae2a922 | 4383 | anObject->SetColor (aColor); |
792c785c | 4384 | } |
0717ddc1 | 4385 | |
cc99be36 | 4386 | if (aMultiConObject.IsNull()) |
792c785c | 4387 | { |
cc99be36 | 4388 | aMultiConObject = new AIS_MultipleConnectedInteractive(); |
792c785c | 4389 | } |
0717ddc1 | 4390 | |
cc99be36 | 4391 | aMultiConObject->Connect (anObject); |
0717ddc1 | 4392 | } |
cc99be36 | 4393 | if (aMultiConObject.IsNull()) |
0717ddc1 | 4394 | { |
23fe70ec | 4395 | Message::SendFail ("Syntax error: can't connect input objects"); |
cc99be36 | 4396 | return 1; |
792c785c | 4397 | } |
4398 | ||
ac04d101 | 4399 | // Create transformation |
ac04d101 | 4400 | gp_Trsf aTrsf; |
cc99be36 | 4401 | aTrsf.SetTranslationPart (gp_Vec (Draw::Atof (argv[anArgIter + 0]), |
4402 | Draw::Atof (argv[anArgIter + 1]), | |
4403 | Draw::Atof (argv[anArgIter + 2]))); | |
0717ddc1 | 4404 | TopLoc_Location aLocation (aTrsf); |
cc99be36 | 4405 | anArgIter += 3; |
ac04d101 | 4406 | |
cc99be36 | 4407 | aMultiConObject->SetLocalTransformation (aTrsf); |
ac04d101 | 4408 | |
cc99be36 | 4409 | ViewerTest::Display (aName, aMultiConObject, true); |
ac04d101 SA |
4410 | return 0; |
4411 | } | |
4412 | ||
4413 | //=============================================================================================== | |
0717ddc1 | 4414 | //function : VConnectTo |
4415 | //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location | |
ac04d101 | 4416 | //=============================================================================================== |
cc99be36 | 4417 | static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/, |
4418 | Standard_Integer argc, | |
4419 | const char ** argv) | |
ac04d101 | 4420 | { |
792c785c | 4421 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
d4aaad5b | 4422 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
792c785c | 4423 | if (aContext.IsNull()) |
ac04d101 | 4424 | { |
23fe70ec | 4425 | Message::SendFail ("Error: no active viewer"); |
cc99be36 | 4426 | return 1; |
ac04d101 | 4427 | } |
f751596e | 4428 | if (argc != 6 && argc != 7) |
ac04d101 | 4429 | { |
23fe70ec | 4430 | Message::SendFail ("Syntax error: expect at least 5 arguments"); |
cc99be36 | 4431 | return 1; |
ac04d101 | 4432 | } |
792c785c | 4433 | |
792c785c | 4434 | Standard_Integer anArgIter = 1; |
4435 | TCollection_AsciiString aName (argv[anArgIter++]); | |
0717ddc1 | 4436 | Handle(AIS_InteractiveObject) anOriginObject; |
4437 | ||
4438 | TCollection_AsciiString anOriginObjectName(argv[5]); | |
4439 | if (aName.IsEqual (anOriginObjectName)) | |
792c785c | 4440 | { |
23fe70ec | 4441 | Message::SendFail ("Syntax error: equal names for connected objects"); |
cc99be36 | 4442 | return 1; |
792c785c | 4443 | } |
cc99be36 | 4444 | anOriginObject = findConnectedObject (anOriginObjectName); |
4445 | if (anOriginObject.IsNull()) | |
792c785c | 4446 | { |
cc99be36 | 4447 | TopoDS_Shape aTDShape = DBRep::Get (anOriginObjectName); |
0717ddc1 | 4448 | if (aTDShape.IsNull()) |
792c785c | 4449 | { |
23fe70ec | 4450 | Message::SendFail() << "Syntax error: object " << anOriginObjectName << " doesn't exist"; |
cc99be36 | 4451 | return 1; |
ac04d101 | 4452 | } |
0717ddc1 | 4453 | |
cc99be36 | 4454 | Handle(AIS_Shape) aShapePrs = new AIS_Shape (aTDShape); |
4455 | Handle(AIS_ConnectedInteractive) aConnectedOrig = new AIS_ConnectedInteractive(); | |
4456 | aConnectedOrig->Connect (aShapePrs); | |
0717ddc1 | 4457 | |
cc99be36 | 4458 | anOriginObject = aConnectedOrig; |
4459 | GetMapOfAIS().Bind (aConnectedOrig, anOriginObjectName); | |
ac04d101 SA |
4460 | } |
4461 | ||
cc99be36 | 4462 | // Create transformation |
4463 | gp_Trsf aTrsf; | |
4464 | aTrsf.SetTranslationPart (gp_Vec (Draw::Atof (argv[anArgIter + 0]), | |
4465 | Draw::Atof (argv[anArgIter + 1]), | |
4466 | Draw::Atof (argv[anArgIter + 2]))); | |
4467 | anArgIter += 3; | |
ac04d101 | 4468 | |
cc99be36 | 4469 | Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive(); |
4470 | aConnected->Connect (anOriginObject, aTrsf); | |
f751596e | 4471 | if (argc == 7) |
4472 | { | |
4473 | TCollection_AsciiString anArg = argv[6]; | |
4474 | anArg.LowerCase(); | |
4475 | if (anArg == "-nodisplay") | |
cc99be36 | 4476 | { |
4477 | // bind connected object without displaying it | |
4478 | Handle(AIS_InteractiveObject) anObj; | |
4479 | if (GetMapOfAIS().Find2 (aName, anObj)) | |
4480 | { | |
4481 | TheAISContext()->Remove (anObj, false); | |
4482 | GetMapOfAIS().UnBind2 (aName); | |
4483 | } | |
4484 | GetMapOfAIS().Bind (aConnected, aName); | |
f751596e | 4485 | return 0; |
cc99be36 | 4486 | } |
d4aaad5b | 4487 | |
4488 | if (!anUpdateTool.parseRedrawMode (anArg)) | |
4489 | { | |
23fe70ec | 4490 | Message::SendFail() << "Syntax error: unknown argument '" << anArg << "'"; |
cc99be36 | 4491 | return 1; |
d4aaad5b | 4492 | } |
f751596e | 4493 | } |
4494 | ||
cc99be36 | 4495 | ViewerTest::Display (aName, aConnected, false); |
ac04d101 SA |
4496 | return 0; |
4497 | } | |
4498 | ||
0717ddc1 | 4499 | //======================================================================= |
4500 | //function : VDisconnect | |
4501 | //purpose : | |
4502 | //======================================================================= | |
4503 | static Standard_Integer VDisconnect (Draw_Interpretor& di, | |
4504 | Standard_Integer argc, | |
4505 | const char ** argv) | |
4506 | { | |
4507 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4508 | if (aContext.IsNull()) | |
4509 | { | |
23fe70ec | 4510 | Message::SendFail( "Error: no active viewer"); |
0717ddc1 | 4511 | return 1; |
4512 | } | |
4513 | ||
4514 | if (argc != 3) | |
4515 | { | |
23fe70ec | 4516 | Message::SendFail() << "Syntax error: wrong number of arguments.\nUsage: " << argv[0] << " name object"; |
0717ddc1 | 4517 | return 1; |
4518 | } | |
4519 | ||
4520 | TCollection_AsciiString aName (argv[1]); | |
4521 | TCollection_AsciiString anObject (argv[2]); | |
4522 | Standard_Integer anObjectNumber = Draw::Atoi (argv[2]); | |
4523 | ||
4524 | // find objects | |
4525 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4526 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
4527 | if (!aMap.IsBound2 (aName) ) | |
4528 | { | |
23fe70ec | 4529 | Message::SendFail ("Error: no active viewer"); |
0717ddc1 | 4530 | return 1; |
4531 | } | |
4532 | ||
4533 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
4534 | if (anAssembly.IsNull()) | |
4535 | { | |
586db386 | 4536 | di << "Not an assembly\n"; |
0717ddc1 | 4537 | return 1; |
4538 | } | |
4539 | ||
4540 | Handle(AIS_InteractiveObject) anIObj; | |
8f521168 | 4541 | if (!aMap.Find2 (anObject, anIObj)) |
0717ddc1 | 4542 | { |
4543 | // try to interpret second argument as child number | |
4544 | if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size()) | |
4545 | { | |
4546 | Standard_Integer aCounter = 1; | |
4547 | for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next()) | |
4548 | { | |
4549 | if (aCounter == anObjectNumber) | |
4550 | { | |
4551 | anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); | |
4552 | break; | |
4553 | } | |
4554 | ++aCounter; | |
4555 | } | |
4556 | } | |
4557 | else | |
4558 | { | |
23fe70ec | 4559 | Message::SendFail ("Error: no active viewer"); |
0717ddc1 | 4560 | return 1; |
4561 | } | |
4562 | } | |
4563 | ||
f751596e | 4564 | aContext->Disconnect (anAssembly, anIObj); |
0717ddc1 | 4565 | aContext->UpdateCurrentViewer(); |
0717ddc1 | 4566 | return 0; |
4567 | } | |
4568 | ||
4569 | //======================================================================= | |
4570 | //function : VAddConnected | |
4571 | //purpose : | |
4572 | //======================================================================= | |
cc99be36 | 4573 | static Standard_Integer VAddConnected (Draw_Interpretor& , |
0717ddc1 | 4574 | Standard_Integer argc, |
4575 | const char ** argv) | |
4576 | { | |
4577 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4578 | if (aContext.IsNull()) | |
4579 | { | |
23fe70ec | 4580 | Message::SendFail ("Error: no active viewer"); |
0717ddc1 | 4581 | return 1; |
4582 | } | |
cc99be36 | 4583 | |
0717ddc1 | 4584 | if (argc != 6) |
4585 | { | |
23fe70ec | 4586 | Message::SendFail ("Syntax error: expect 5 arguments"); |
0717ddc1 | 4587 | return 1; |
4588 | } | |
4589 | ||
cc99be36 | 4590 | const TCollection_AsciiString aName (argv[1]); |
4591 | const Standard_Real aX = Draw::Atof (argv[2]); | |
4592 | const Standard_Real aY = Draw::Atof (argv[3]); | |
4593 | const Standard_Real aZ = Draw::Atof (argv[4]); | |
4594 | const TCollection_AsciiString anObjectName (argv[5]); | |
0717ddc1 | 4595 | |
4596 | // find object | |
4597 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4598 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
0717ddc1 | 4599 | { |
cc99be36 | 4600 | Handle(AIS_InteractiveObject) aPrs; |
4601 | aMap.Find2 (aName, aPrs); | |
4602 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aPrs); | |
4603 | if (anAssembly.IsNull()) | |
4604 | { | |
23fe70ec | 4605 | Message::SendFail() << "Syntax error: '" << aName << "' is not an assembly"; |
cc99be36 | 4606 | return 1; |
4607 | } | |
0717ddc1 | 4608 | } |
4609 | ||
cc99be36 | 4610 | Handle(AIS_InteractiveObject) anIObj = findConnectedObject (anObjectName); |
4611 | if (anIObj.IsNull()) | |
0717ddc1 | 4612 | { |
23fe70ec | 4613 | Message::SendFail() << "Syntax error: '" << anObjectName << "' is not displayed"; |
0717ddc1 | 4614 | return 1; |
4615 | } | |
4616 | ||
0717ddc1 | 4617 | gp_Trsf aTrsf; |
4618 | aTrsf.SetTranslation (gp_Vec (aX, aY, aZ)); | |
4619 | ||
4620 | anAssembly->Connect (anIObj, aTrsf); | |
0577ae8c | 4621 | TheAISContext()->Display (anAssembly, Standard_False); |
0717ddc1 | 4622 | TheAISContext()->RecomputeSelectionOnly (anAssembly); |
4623 | aContext->UpdateCurrentViewer(); | |
0717ddc1 | 4624 | return 0; |
4625 | } | |
4626 | ||
4627 | //======================================================================= | |
4628 | //function : VListConnected | |
4629 | //purpose : | |
4630 | //======================================================================= | |
0bd2a43f | 4631 | static Standard_Integer VListConnected (Draw_Interpretor& /*di*/, |
0717ddc1 | 4632 | Standard_Integer argc, |
4633 | const char ** argv) | |
4634 | { | |
4635 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4636 | if (aContext.IsNull()) | |
4637 | { | |
23fe70ec | 4638 | Message::SendFail ("Error: no active viewer"); |
0717ddc1 | 4639 | return 1; |
4640 | } | |
4641 | ||
4642 | if (argc != 2) | |
4643 | { | |
23fe70ec | 4644 | Message::SendFail() << "Syntax error: wrong number of arguments.\nUsage: " << argv[0] << " name"; |
0717ddc1 | 4645 | return 1; |
4646 | } | |
4647 | ||
4648 | TCollection_AsciiString aName (argv[1]); | |
4649 | ||
4650 | // find object | |
4651 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4652 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
4653 | if (!aMap.IsBound2 (aName) ) | |
4654 | { | |
23fe70ec | 4655 | Message::SendFail ("Error: no active viewer"); |
0717ddc1 | 4656 | return 1; |
4657 | } | |
4658 | ||
4659 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
4660 | if (anAssembly.IsNull()) | |
4661 | { | |
23fe70ec | 4662 | Message::SendFail ("Syntax error: Not an assembly"); |
0717ddc1 | 4663 | return 1; |
4664 | } | |
4665 | ||
4666 | std::cout << "Children of " << aName << ":\n"; | |
4667 | ||
4668 | Standard_Integer aCounter = 1; | |
4669 | for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next()) | |
4670 | { | |
8f521168 | 4671 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); |
4672 | if (GetMapOfAIS().IsBound1 (anObj)) | |
0717ddc1 | 4673 | { |
8f521168 | 4674 | TCollection_AsciiString aCuurrentName = GetMapOfAIS().Find1 (anObj); |
51740958 | 4675 | std::cout << aCounter << ") " << aCuurrentName << " (" << anIter.Value()->DynamicType()->Name() << ")"; |
0717ddc1 | 4676 | } |
4677 | ||
4678 | std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name(); | |
4679 | ||
4680 | Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value()); | |
4681 | if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo())) | |
4682 | { | |
4683 | std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo()); | |
4684 | } | |
4685 | std::cout << std::endl; | |
4686 | ||
4687 | ++aCounter; | |
4688 | } | |
4689 | ||
4690 | return 0; | |
4691 | } | |
4692 | ||
245cbf94 | 4693 | //======================================================================= |
4694 | //function : VChild | |
4695 | //purpose : | |
4696 | //======================================================================= | |
4697 | static Standard_Integer VChild (Draw_Interpretor& , | |
4698 | Standard_Integer theNbArgs, | |
4699 | const char** theArgVec) | |
4700 | { | |
4701 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4702 | if (aContext.IsNull()) | |
4703 | { | |
23fe70ec | 4704 | Message::SendFail ("Error: no active viewer"); |
245cbf94 | 4705 | return 1; |
4706 | } | |
4707 | ||
4708 | int toAdd = -1; | |
4709 | Handle(AIS_InteractiveObject) aParent; | |
4710 | bool hasActions = false; | |
52c38ce1 | 4711 | int toInheritTrsf = -1; |
245cbf94 | 4712 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
4713 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
4714 | { | |
4715 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4716 | anArg.LowerCase(); | |
4717 | if (anUpdateTool.parseRedrawMode (anArg)) | |
4718 | { | |
4719 | continue; | |
4720 | } | |
4721 | else if (anArg == "-add") | |
4722 | { | |
4723 | toAdd = 1; | |
4724 | continue; | |
4725 | } | |
4726 | else if (anArg == "-remove") | |
4727 | { | |
4728 | toAdd = 0; | |
4729 | continue; | |
4730 | } | |
52c38ce1 | 4731 | else if (anArg == "-inheritparenttrsf" |
4732 | || anArg == "-inheritparentloc" | |
4733 | || anArg == "-inheritparentlocation" | |
4734 | || anArg == "-inheritparent" | |
4735 | || anArg == "-noinheritparenttrsf" | |
4736 | || anArg == "-noinheritparentloc" | |
4737 | || anArg == "-noinheritparentlocation" | |
4738 | || anArg == "-noinheritparent" | |
4739 | || anArg == "-ignoreparenttrsf" | |
4740 | || anArg == "-ignoreparentloc" | |
4741 | || anArg == "-ignoreparentlocation" | |
4742 | || anArg == "-ignoreparent") | |
4743 | { | |
4744 | bool aVal = true; | |
4745 | if (anArgIter + 1 < theNbArgs | |
dae2a922 | 4746 | && Draw::ParseOnOff(theArgVec[anArgIter + 1], aVal)) |
52c38ce1 | 4747 | { |
4748 | ++anArgIter; | |
4749 | } | |
4750 | if (anArg.StartsWith("-no") | |
4751 | || anArg.StartsWith("-ignore")) | |
4752 | { | |
4753 | aVal = !aVal; | |
4754 | } | |
4755 | toInheritTrsf = aVal ? 1 : 0; | |
4756 | continue; | |
4757 | } | |
245cbf94 | 4758 | |
4759 | Handle(AIS_InteractiveObject) aChild; | |
4760 | if (!GetMapOfAIS().Find2 (theArgVec[anArgIter], aChild)) | |
4761 | { | |
23fe70ec | 4762 | Message::SendFail() << "Syntax error: object '" << theArgVec[anArgIter] << "' is not found"; |
245cbf94 | 4763 | return 1; |
4764 | } | |
4765 | ||
4766 | if (aParent.IsNull()) | |
4767 | { | |
4768 | aParent = aChild; | |
4769 | } | |
4770 | else if (toAdd == -1) | |
4771 | { | |
23fe70ec | 4772 | Message::SendFail ("Syntax error: no action specified"); |
245cbf94 | 4773 | return 1; |
4774 | } | |
4775 | else | |
4776 | { | |
4777 | hasActions = true; | |
4778 | if (toAdd == 1) | |
4779 | { | |
52c38ce1 | 4780 | if(toInheritTrsf == 0) |
4781 | aParent->AddChildWithCurrentTransformation(aChild); | |
4782 | else | |
4783 | aParent->AddChild (aChild); | |
245cbf94 | 4784 | } |
4785 | else | |
4786 | { | |
52c38ce1 | 4787 | if (toInheritTrsf == 0) |
4788 | aParent->RemoveChildWithRestoreTransformation(aChild); | |
4789 | else | |
4790 | aParent->RemoveChild (aChild); | |
245cbf94 | 4791 | } |
4792 | } | |
4793 | } | |
4794 | if (!hasActions) | |
4795 | { | |
23fe70ec | 4796 | Message::SendFail ("Syntax error: not enough arguments"); |
245cbf94 | 4797 | return 1; |
4798 | } | |
4799 | return 0; | |
4800 | } | |
4801 | ||
0d56f743 | 4802 | //======================================================================= |
4803 | //function : VParent | |
4804 | //purpose : | |
4805 | //======================================================================= | |
4806 | static Standard_Integer VParent(Draw_Interpretor&, | |
4807 | Standard_Integer theNbArgs, | |
4808 | const char** theArgVec) | |
4809 | { | |
4810 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4811 | if (aContext.IsNull()) | |
4812 | { | |
23fe70ec | 4813 | Message::SendFail ("Error: no active viewer"); |
0d56f743 | 4814 | return 1; |
4815 | } | |
4816 | ||
4817 | if (theNbArgs < 2 ) | |
4818 | { | |
23fe70ec | 4819 | Message::SendFail ("Syntax error: wrong number of arguments"); |
0d56f743 | 4820 | return 1; |
4821 | } | |
4822 | ||
4823 | TCollection_AsciiString aName(theArgVec[1]); | |
4824 | Handle(AIS_InteractiveObject) aParent; | |
4825 | if (!GetMapOfAIS().Find2(theArgVec[1], aParent)) | |
4826 | { | |
23fe70ec | 4827 | Message::SendFail() << "Syntax error: object '" << theArgVec[1] << "' is not found"; |
0d56f743 | 4828 | return 1; |
4829 | } | |
4830 | ||
4831 | ViewerTest_AutoUpdater anUpdateTool(aContext, ViewerTest::CurrentView()); | |
4832 | for (Standard_Integer anArgIter = 2; anArgIter < theNbArgs; ++anArgIter) | |
4833 | { | |
4834 | TCollection_AsciiString anArg(theArgVec[anArgIter]); | |
4835 | anArg.LowerCase(); | |
4836 | if (anArg == "-ignorevisu") | |
4837 | aParent->SetPropagateVisualState(Standard_False); | |
4838 | } | |
4839 | return 0; | |
4840 | } | |
4841 | ||
ac04d101 SA |
4842 | //=============================================================================================== |
4843 | //function : VSetSelectionMode | |
f47849f4 | 4844 | //purpose : vselmode |
ac04d101 | 4845 | //=============================================================================================== |
9f37b47d | 4846 | static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/, |
f47849f4 | 4847 | Standard_Integer theNbArgs, |
9f37b47d | 4848 | const char** theArgv) |
ac04d101 SA |
4849 | { |
4850 | // Check errors | |
4851 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
9f37b47d | 4852 | if (anAISContext.IsNull()) |
ac04d101 | 4853 | { |
23fe70ec | 4854 | Message::SendFail ("Error: no active Viewer"); |
9f37b47d | 4855 | return 1; |
ac04d101 SA |
4856 | } |
4857 | ||
f47849f4 | 4858 | NCollection_Sequence<TCollection_AsciiString> anObjNames; |
f47849f4 | 4859 | Standard_Integer aSelectionMode = -1; |
4860 | Standard_Boolean toTurnOn = Standard_True; | |
4861 | AIS_SelectionModesConcurrency aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal; | |
4862 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
9f37b47d | 4863 | { |
f47849f4 | 4864 | TCollection_AsciiString anArgCase (theArgv[anArgIter]); |
4865 | anArgCase.LowerCase(); | |
68dcee02 | 4866 | if (anArgCase == "-set" |
4867 | || anArgCase == "-replace" | |
4868 | || anArgCase == "-single" | |
4869 | || anArgCase == "-exclusive") | |
f47849f4 | 4870 | { |
4871 | aSelModeConcurrency = AIS_SelectionModesConcurrency_Single; | |
4872 | } | |
4873 | else if (anArgCase == "-add" | |
4874 | || anArgCase == "-combine" | |
4875 | || anArgCase == "-combination" | |
4876 | || anArgCase == "-multiple") | |
4877 | { | |
4878 | aSelModeConcurrency = AIS_SelectionModesConcurrency_Multiple; | |
4879 | } | |
4880 | else if (anArgCase == "-globalorlocal" | |
4881 | || anArgCase == "-localorglobal") | |
4882 | { | |
4883 | aSelModeConcurrency = AIS_SelectionModesConcurrency_GlobalOrLocal; | |
4884 | } | |
4885 | else | |
4886 | { | |
4887 | anObjNames.Append (theArgv[anArgIter]); | |
ac04d101 | 4888 | } |
9f37b47d | 4889 | } |
f47849f4 | 4890 | if (anObjNames.Size() < 2 |
dae2a922 | 4891 | || !Draw::ParseOnOff (anObjNames.Last().ToCString(), toTurnOn)) |
f47849f4 | 4892 | { |
23fe70ec | 4893 | Message::SendFail ("Syntax error: wrong number of arguments"); |
f47849f4 | 4894 | return 1; |
4895 | } | |
4896 | anObjNames.Remove (anObjNames.Upper()); | |
d2e60688 | 4897 | { |
f47849f4 | 4898 | const TCollection_AsciiString aSelModeString = anObjNames.Last(); |
4899 | anObjNames.Remove (anObjNames.Upper()); | |
d2e60688 | 4900 | TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE; |
4901 | if (aSelModeString.IsIntegerValue()) | |
4902 | { | |
4903 | aSelectionMode = aSelModeString.IntegerValue(); | |
4904 | } | |
4905 | else if (TopAbs::ShapeTypeFromString (aSelModeString.ToCString(), aShapeType)) | |
4906 | { | |
4907 | aSelectionMode = AIS_Shape::SelectionMode (aShapeType); | |
4908 | } | |
4909 | else | |
4910 | { | |
23fe70ec | 4911 | Message::SendFail() << "Syntax error: unknown selection mode '" << aSelModeString << "'"; |
d2e60688 | 4912 | return 1; |
4913 | } | |
4914 | } | |
d2e60688 | 4915 | |
f47849f4 | 4916 | AIS_ListOfInteractive aTargetIOs; |
4917 | for (NCollection_Sequence<TCollection_AsciiString>::Iterator anObjIter (anObjNames); anObjIter.More(); anObjIter.Next()) | |
709e97a0 | 4918 | { |
f47849f4 | 4919 | const TCollection_AsciiString& aNameIO = anObjIter.Value(); |
4920 | Handle(AIS_InteractiveObject) anIO; | |
8f521168 | 4921 | GetMapOfAIS().Find2 (aNameIO, anIO); |
f47849f4 | 4922 | if (anIO.IsNull()) |
709e97a0 | 4923 | { |
23fe70ec | 4924 | Message::SendFail() << "Syntax error: undefined presentable object " << aNameIO; |
f47849f4 | 4925 | return 1; |
709e97a0 | 4926 | } |
f47849f4 | 4927 | aTargetIOs.Append (anIO); |
4928 | } | |
4929 | if (aTargetIOs.IsEmpty()) | |
4930 | { | |
4931 | anAISContext->DisplayedObjects (aTargetIOs); | |
709e97a0 | 4932 | } |
4933 | ||
f47849f4 | 4934 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) |
9f37b47d | 4935 | { |
f47849f4 | 4936 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); |
f47849f4 | 4937 | anAISContext->SetSelectionModeActive (anIO, aSelectionMode, toTurnOn, aSelModeConcurrency); |
ac04d101 SA |
4938 | } |
4939 | return 0; | |
4940 | } | |
4941 | ||
4ca4bbe8 | 4942 | //=============================================================================================== |
4943 | //function : VSelectionNext | |
4944 | //purpose : | |
4945 | //=============================================================================================== | |
4946 | static Standard_Integer VSelectionNext(Draw_Interpretor& /*theDI*/, | |
4947 | Standard_Integer /*theArgsNb*/, | |
4948 | const char** /*theArgVec*/) | |
4949 | { | |
4950 | // Check errors | |
4951 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
4952 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4953 | ||
4954 | if (anAISContext.IsNull()) | |
4955 | { | |
23fe70ec | 4956 | Message::SendFail ("Error: no active viewer"); |
4ca4bbe8 | 4957 | return 1; |
4958 | } | |
4959 | ||
f0cddd16 | 4960 | anAISContext->HilightNextDetected (aView); |
4ca4bbe8 | 4961 | return 0; |
4962 | } | |
4963 | ||
4964 | //=============================================================================================== | |
4965 | //function : VSelectionPrevious | |
4966 | //purpose : | |
4967 | //=============================================================================================== | |
4968 | static Standard_Integer VSelectionPrevious(Draw_Interpretor& /*theDI*/, | |
4969 | Standard_Integer /*theArgsNb*/, | |
4970 | const char** /*theArgVec*/) | |
4971 | { | |
4972 | // Check errors | |
4973 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
4974 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
4975 | ||
4976 | if (anAISContext.IsNull()) | |
4977 | { | |
23fe70ec | 4978 | Message::SendFail ("Error: no active viewer"); |
4ca4bbe8 | 4979 | return 1; |
4980 | } | |
4981 | ||
f0cddd16 | 4982 | anAISContext->HilightPreviousDetected (aView); |
4ca4bbe8 | 4983 | return 0; |
4984 | } | |
4985 | ||
ceae62f0 A |
4986 | //=========================================================================== |
4987 | //function : VTriangle | |
4988 | //Draw arg : vtriangle Name PointName PointName PointName | |
4989 | //purpose : creates and displays Triangle | |
4990 | //=========================================================================== | |
35e08fe8 | 4991 | static Standard_Integer VTriangle (Draw_Interpretor& /*di*/, |
ceae62f0 A |
4992 | Standard_Integer argc, |
4993 | const char ** argv) | |
4994 | { | |
9427bc1d | 4995 | const Standard_Boolean isTri = TCollection_AsciiString (argv[0]) == "vtriangle"; |
4996 | Handle(Graphic3d_ArrayOfPrimitives) aPrims; | |
4997 | if (isTri) | |
ceae62f0 | 4998 | { |
9427bc1d | 4999 | aPrims = new Graphic3d_ArrayOfTriangles (3); |
ceae62f0 | 5000 | } |
9427bc1d | 5001 | else |
ceae62f0 | 5002 | { |
9427bc1d | 5003 | aPrims = new Graphic3d_ArrayOfSegments (2); |
ceae62f0 A |
5004 | } |
5005 | ||
9427bc1d | 5006 | if (argc != (2 + aPrims->VertexNumberAllocated())) |
ceae62f0 | 5007 | { |
23fe70ec | 5008 | Message::SendFail ("Syntax error: wrong number of arguments"); |
9427bc1d | 5009 | return 1; |
ceae62f0 A |
5010 | } |
5011 | ||
9427bc1d | 5012 | gp_Pnt aPnts[3]; |
5013 | for (Standard_Integer aPntIter = 0; aPntIter < aPrims->VertexNumberAllocated(); ++aPntIter) | |
ceae62f0 | 5014 | { |
9427bc1d | 5015 | const TCollection_AsciiString aName (argv[2 + aPntIter]); |
5016 | if (Handle(AIS_Point) aPntPrs = Handle(AIS_Point)::DownCast (GetMapOfAIS().IsBound2 (aName) ? GetMapOfAIS().Find2 (aName) : NULL)) | |
5017 | { | |
5018 | aPnts[aPntIter] = aPntPrs->Component()->Pnt(); | |
5019 | } | |
5020 | else | |
5021 | { | |
5022 | TopoDS_Shape aShape = DBRep::Get (argv[2 + aPntIter]); | |
5023 | if (aShape.IsNull() | |
5024 | || aShape.ShapeType() != TopAbs_VERTEX) | |
5025 | { | |
23fe70ec | 5026 | Message::SendFail() << "Syntax error: argument " << aName << " must be a point"; |
9427bc1d | 5027 | return 1; |
5028 | } | |
5029 | aPnts[aPntIter] = BRep_Tool::Pnt (TopoDS::Vertex (aShape)); | |
5030 | } | |
ceae62f0 | 5031 | |
9427bc1d | 5032 | for (Standard_Integer aPnt2Iter = 0; aPnt2Iter < aPntIter; ++aPnt2Iter) |
5033 | { | |
5034 | if (aPnts[aPnt2Iter].IsEqual (aPnts[aPntIter], Precision::Confusion())) | |
5035 | { | |
23fe70ec | 5036 | Message::SendFail ("Syntax error: points should not be equal"); |
9427bc1d | 5037 | return 1; |
5038 | } | |
5039 | } | |
ceae62f0 | 5040 | |
9427bc1d | 5041 | aPrims->AddVertex (aPnts[aPntIter]); |
ceae62f0 A |
5042 | } |
5043 | ||
bf5f0ca2 | 5044 | Handle(AIS_InteractiveObject) aPrs = new MyPArrayObject (aPrims); |
5045 | if (!isTri) | |
5046 | { | |
5047 | aPrs->Attributes()->SetupOwnShadingAspect(); | |
5048 | aPrs->Attributes()->ShadingAspect()->Aspect()->SetColor (aPrs->Attributes()->LineAspect()->Aspect()->Color()); | |
5049 | } | |
5050 | ViewerTest::Display (argv[1], aPrs); | |
ceae62f0 A |
5051 | return 0; |
5052 | } | |
5053 | ||
113bda70 | 5054 | //=========================================================================== |
5055 | //function : VTorus | |
5056 | //purpose : creates and displays a torus or torus segment | |
5057 | //=========================================================================== | |
5058 | static Standard_Integer VTorus (Draw_Interpretor& /*di*/, | |
6eeb528c | 5059 | Standard_Integer theNbArgs, |
5060 | const char** theArgVec) | |
113bda70 | 5061 | { |
6eeb528c | 5062 | if (ViewerTest::GetAISContext().IsNull()) |
113bda70 | 5063 | { |
6eeb528c | 5064 | Message::SendFail ("Error: no active viewer"); |
113bda70 | 5065 | return 1; |
5066 | } | |
5067 | ||
6eeb528c | 5068 | TCollection_AsciiString aName; |
5069 | Standard_Integer aNbSlices = 100, aNbStacks = 100; | |
5070 | Standard_Real aMajorRad = -1.0, aMinorRad = -1.0; | |
5071 | Standard_Real aPipeAngle = 360.0, aSegAngle1 = 0.0, aSegAngle2 = 360.0; | |
5072 | Standard_Real anAngles[3] = { -1.0, -1.0, -1.0 }; | |
5073 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); | |
5074 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
113bda70 | 5075 | { |
6eeb528c | 5076 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
5077 | anArg.LowerCase(); | |
5078 | if (anUpdateTool.parseRedrawMode (anArg)) | |
5079 | { | |
5080 | continue; | |
5081 | } | |
5082 | else if (anArgIter + 1 < theNbArgs | |
5083 | && (anArg == "-nbslices" | |
5084 | || anArg == "-slices") | |
5085 | && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbSlices)) | |
5086 | { | |
5087 | ++anArgIter; | |
5088 | } | |
5089 | else if (anArgIter + 1 < theNbArgs | |
5090 | && (anArg == "-nbstacks" | |
5091 | || anArg == "-stacks") | |
5092 | && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbStacks)) | |
5093 | { | |
5094 | ++anArgIter; | |
5095 | } | |
5096 | else if (anArgIter + 1 < theNbArgs | |
5097 | && (anArg == "-radius" | |
5098 | || anArg == "-majorradius") | |
5099 | && Draw::ParseReal (theArgVec[anArgIter + 1], aMajorRad)) | |
5100 | { | |
5101 | ++anArgIter; | |
5102 | } | |
5103 | else if (anArgIter + 1 < theNbArgs | |
5104 | && (anArg == "-piperadius" | |
5105 | || anArg == "-minoradius") | |
5106 | && Draw::ParseReal (theArgVec[anArgIter + 1], aMinorRad)) | |
5107 | { | |
5108 | ++anArgIter; | |
5109 | } | |
5110 | else if (anArgIter + 1 < theNbArgs | |
5111 | && (anArg == "-pipeangle" | |
5112 | || anArg == "-angle") | |
5113 | && Draw::ParseReal (theArgVec[anArgIter + 1], aPipeAngle)) | |
5114 | { | |
5115 | ++anArgIter; | |
5116 | } | |
5117 | else if (anArgIter + 1 < theNbArgs | |
5118 | && (anArg == "-segmentanglefrom" | |
5119 | || anArg == "-seganglefrom" | |
5120 | || anArg == "-segmentangle1" | |
5121 | || anArg == "-segangle1") | |
5122 | && Draw::ParseReal (theArgVec[anArgIter + 1], aSegAngle1)) | |
5123 | { | |
5124 | ++anArgIter; | |
5125 | } | |
5126 | else if (anArgIter + 1 < theNbArgs | |
5127 | && (anArg == "-segmentangleto" | |
5128 | || anArg == "-segangleto" | |
5129 | || anArg == "-segmentangle2" | |
5130 | || anArg == "-segangle2") | |
5131 | && Draw::ParseReal (theArgVec[anArgIter + 1], aSegAngle2)) | |
5132 | { | |
5133 | ++anArgIter; | |
5134 | } | |
5135 | else if (aName.IsEmpty()) | |
5136 | { | |
5137 | aName = theArgVec[anArgIter]; | |
5138 | } | |
5139 | else if (aMajorRad < 0.0 | |
5140 | && Draw::ParseReal (theArgVec[anArgIter], aMajorRad)) | |
5141 | { | |
5142 | // | |
5143 | } | |
5144 | else if (aMinorRad < 0.0 | |
5145 | && Draw::ParseReal (theArgVec[anArgIter], aMinorRad)) | |
5146 | { | |
5147 | // | |
5148 | } | |
5149 | else if (anAngles[0] < 0.0 | |
5150 | && Draw::ParseReal (theArgVec[anArgIter], anAngles[0])) | |
5151 | { | |
5152 | // | |
5153 | } | |
5154 | else if (anAngles[1] < 0.0 | |
5155 | && Draw::ParseReal (theArgVec[anArgIter], anAngles[1])) | |
5156 | { | |
5157 | // | |
5158 | } | |
5159 | else if (anAngles[2] < 0.0 | |
5160 | && Draw::ParseReal (theArgVec[anArgIter], anAngles[2])) | |
5161 | { | |
5162 | // | |
5163 | } | |
5164 | else | |
5165 | { | |
5166 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; | |
5167 | return 1; | |
5168 | } | |
113bda70 | 5169 | } |
5170 | ||
6eeb528c | 5171 | if (anAngles[2] > 0.0) |
113bda70 | 5172 | { |
6eeb528c | 5173 | aSegAngle1 = anAngles[0]; |
5174 | aSegAngle2 = anAngles[1]; | |
5175 | aPipeAngle = anAngles[2]; | |
113bda70 | 5176 | } |
6eeb528c | 5177 | else if (anAngles[1] > 0.0) |
113bda70 | 5178 | { |
6eeb528c | 5179 | aSegAngle1 = anAngles[0]; |
5180 | aSegAngle2 = anAngles[1]; | |
113bda70 | 5181 | } |
6eeb528c | 5182 | else if (anAngles[0] > 0.0) |
113bda70 | 5183 | { |
6eeb528c | 5184 | aPipeAngle = anAngles[0]; |
113bda70 | 5185 | } |
6eeb528c | 5186 | |
5187 | aSegAngle1 = aSegAngle1 * (M_PI / 180.0); | |
5188 | aSegAngle2 = aSegAngle2 * (M_PI / 180.0); | |
5189 | aPipeAngle = aPipeAngle * (M_PI / 180.0); | |
5190 | ||
5191 | if (aMajorRad <= 0 || aMinorRad <= 0 || aNbSlices <= 0 || aNbStacks <= 0 | |
5192 | || Abs(aSegAngle2 - aSegAngle1) <= Precision::Angular() | |
5193 | || Abs(aPipeAngle) <= Precision::Angular()) | |
113bda70 | 5194 | { |
6eeb528c | 5195 | Message::SendFail ("Syntax error: wrong parameters"); |
5196 | return 1; | |
113bda70 | 5197 | } |
5198 | ||
6eeb528c | 5199 | Handle(Graphic3d_ArrayOfTriangles) aTriangles = Prs3d_ToolTorus::Create (aMajorRad, aMinorRad, aSegAngle1, aSegAngle2, aPipeAngle, aNbSlices, aNbStacks, gp_Trsf()); |
113bda70 | 5200 | Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles); |
6eeb528c | 5201 | ViewerTest::Display (aName, anIO, false); |
113bda70 | 5202 | return 0; |
5203 | } | |
5204 | ||
5205 | //=========================================================================== | |
5206 | //function : VCylinder | |
5207 | //purpose : creates and displays a cylinder | |
5208 | //=========================================================================== | |
5209 | static Standard_Integer VCylinder (Draw_Interpretor& /*di*/, | |
6eeb528c | 5210 | Standard_Integer theNbArgs, |
5211 | const char** theArgVec) | |
113bda70 | 5212 | { |
6eeb528c | 5213 | if (ViewerTest::GetAISContext().IsNull()) |
113bda70 | 5214 | { |
6eeb528c | 5215 | Message::SendFail ("Error: no active viewer"); |
113bda70 | 5216 | return 1; |
5217 | } | |
5218 | ||
6eeb528c | 5219 | TCollection_AsciiString aName; |
5220 | Standard_Integer aNbSlices = 100, aNbStacks = 1; | |
5221 | Standard_Real aBotRad = -1.0, aTopRad = -1.0, aHeight = -1.0; | |
5222 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); | |
5223 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
113bda70 | 5224 | { |
6eeb528c | 5225 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
5226 | anArg.LowerCase(); | |
5227 | if (anUpdateTool.parseRedrawMode (anArg)) | |
5228 | { | |
5229 | continue; | |
5230 | } | |
5231 | else if (anArgIter + 1 < theNbArgs | |
5232 | && (anArg == "-nbslices" | |
5233 | || anArg == "-slices") | |
5234 | && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbSlices)) | |
5235 | { | |
5236 | ++anArgIter; | |
5237 | } | |
5238 | else if (anArgIter + 1 < theNbArgs | |
5239 | && (anArg == "-nbstacks" | |
5240 | || anArg == "-stacks") | |
5241 | && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbStacks)) | |
5242 | { | |
5243 | ++anArgIter; | |
5244 | } | |
5245 | else if (anArgIter + 1 < theNbArgs | |
5246 | && anArg == "-radius" | |
5247 | && Draw::ParseReal (theArgVec[anArgIter + 1], aBotRad)) | |
5248 | { | |
5249 | aTopRad = aBotRad; | |
5250 | ++anArgIter; | |
5251 | } | |
5252 | else if (anArgIter + 1 < theNbArgs | |
5253 | && anArg == "-bottomradius" | |
5254 | && Draw::ParseReal (theArgVec[anArgIter + 1], aBotRad)) | |
5255 | { | |
5256 | ++anArgIter; | |
5257 | } | |
5258 | else if (anArgIter + 1 < theNbArgs | |
5259 | && anArg == "-topradius" | |
5260 | && Draw::ParseReal (theArgVec[anArgIter + 1], aTopRad)) | |
5261 | { | |
5262 | ++anArgIter; | |
5263 | } | |
5264 | else if (anArgIter + 1 < theNbArgs | |
5265 | && anArg == "-height" | |
5266 | && Draw::ParseReal (theArgVec[anArgIter + 1], aHeight)) | |
5267 | { | |
5268 | ++anArgIter; | |
5269 | } | |
5270 | else if (aName.IsEmpty()) | |
5271 | { | |
5272 | aName = theArgVec[anArgIter]; | |
5273 | } | |
5274 | else if (aBotRad < 0.0 | |
5275 | && Draw::ParseReal (theArgVec[anArgIter], aBotRad)) | |
5276 | { | |
5277 | // | |
5278 | } | |
5279 | else if (aTopRad < 0.0 | |
5280 | && Draw::ParseReal (theArgVec[anArgIter], aTopRad)) | |
5281 | { | |
5282 | // | |
5283 | } | |
5284 | else if (aHeight < 0.0 | |
5285 | && Draw::ParseReal (theArgVec[anArgIter], aHeight)) | |
5286 | { | |
5287 | // | |
5288 | } | |
5289 | else | |
5290 | { | |
5291 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; | |
5292 | return 1; | |
5293 | } | |
113bda70 | 5294 | } |
5295 | ||
6eeb528c | 5296 | if (aBotRad < 0 || aTopRad < 0 || aHeight <= 0 || aNbSlices < 3) |
5297 | { | |
5298 | Message::SendFail ("Syntax error: wrong parameters"); | |
5299 | return 1; | |
5300 | } | |
113bda70 | 5301 | |
6eeb528c | 5302 | Handle(Graphic3d_ArrayOfTriangles) aTriangles = Prs3d_ToolCylinder::Create (aBotRad, aTopRad, aHeight, aNbSlices, aNbStacks, gp_Trsf()); |
113bda70 | 5303 | Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles); |
6eeb528c | 5304 | ViewerTest::Display (aName, anIO, false); |
113bda70 | 5305 | return 0; |
5306 | } | |
5307 | ||
5308 | //=========================================================================== | |
5309 | //function : VSphere | |
5310 | //purpose : creates and displays a sphere | |
5311 | //=========================================================================== | |
5312 | static Standard_Integer VSphere (Draw_Interpretor& /*di*/, | |
6eeb528c | 5313 | Standard_Integer theNbArgs, |
5314 | const char** theArgVec) | |
113bda70 | 5315 | { |
6eeb528c | 5316 | if (ViewerTest::GetAISContext().IsNull()) |
113bda70 | 5317 | { |
6eeb528c | 5318 | Message::SendFail ("Error: no active viewer"); |
113bda70 | 5319 | return 1; |
5320 | } | |
5321 | ||
6eeb528c | 5322 | TCollection_AsciiString aName; |
5323 | Standard_Integer aNbSlices = 100, aNbStacks = 100; | |
5324 | Standard_Real aRad = -1.0; | |
5325 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); | |
5326 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
113bda70 | 5327 | { |
6eeb528c | 5328 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
5329 | anArg.LowerCase(); | |
5330 | if (anUpdateTool.parseRedrawMode (anArg)) | |
5331 | { | |
5332 | continue; | |
5333 | } | |
5334 | else if (anArgIter + 1 < theNbArgs | |
5335 | && (anArg == "-nbslices" | |
5336 | || anArg == "-slices") | |
5337 | && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbSlices)) | |
5338 | { | |
5339 | ++anArgIter; | |
5340 | } | |
5341 | else if (anArgIter + 1 < theNbArgs | |
5342 | && (anArg == "-nbstacks" | |
5343 | || anArg == "-stacks") | |
5344 | && Draw::ParseInteger (theArgVec[anArgIter + 1], aNbStacks)) | |
5345 | { | |
5346 | ++anArgIter; | |
5347 | } | |
5348 | else if (anArgIter + 1 < theNbArgs | |
5349 | && anArg == "-radius" | |
5350 | && Draw::ParseReal (theArgVec[anArgIter + 1], aRad)) | |
5351 | { | |
5352 | ++anArgIter; | |
5353 | } | |
5354 | else if (aName.IsEmpty()) | |
5355 | { | |
5356 | aName = theArgVec[anArgIter]; | |
5357 | } | |
5358 | else if (aRad < 0.0 | |
5359 | && Draw::ParseReal (theArgVec[anArgIter], aRad)) | |
5360 | { | |
5361 | // | |
5362 | } | |
5363 | else | |
5364 | { | |
5365 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; | |
5366 | return 1; | |
5367 | } | |
113bda70 | 5368 | } |
5369 | ||
6eeb528c | 5370 | if (aRad <= 0 || aNbSlices <= 0 || aNbStacks <= 0) |
5371 | { | |
5372 | Message::SendFail ("Syntax error: wrong parameters"); | |
5373 | return 1; | |
5374 | } | |
113bda70 | 5375 | |
6eeb528c | 5376 | Handle(Graphic3d_ArrayOfTriangles) aTriangles = Prs3d_ToolSphere::Create (aRad, aNbSlices, aNbStacks, gp_Trsf()); |
113bda70 | 5377 | Handle(AIS_InteractiveObject) anIO = new MyPArrayObject (aTriangles); |
6eeb528c | 5378 | ViewerTest::Display (aName, anIO, false); |
113bda70 | 5379 | return 0; |
5380 | } | |
5381 | ||
59f45b7c | 5382 | //======================================================================= |
5383 | //function : VObjZLayer | |
5384 | //purpose : Set or get z layer id for presentable object | |
5385 | //======================================================================= | |
5386 | ||
5387 | static Standard_Integer VObjZLayer (Draw_Interpretor& di, | |
5388 | Standard_Integer argc, | |
5389 | const char ** argv) | |
5390 | { | |
5391 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5392 | if (aContext.IsNull()) | |
5393 | { | |
23fe70ec | 5394 | Message::SendFail ("Error: no active viewer"); |
59f45b7c | 5395 | return 1; |
5396 | } | |
5397 | ||
5398 | // get operation | |
5399 | TCollection_AsciiString aOperation; | |
5400 | if (argc >= 2) | |
5401 | aOperation = TCollection_AsciiString (argv [1]); | |
5402 | ||
5403 | // check for correct arguments | |
5404 | if (!(argc == 4 && aOperation.IsEqual ("set")) && | |
5405 | !(argc == 3 && aOperation.IsEqual ("get"))) | |
5406 | { | |
5407 | di << "Usage : " << argv[0] << " set/get object [layerid]\n"; | |
5408 | di << " set - set layer id for interactive object, layerid - z layer id\n"; | |
5409 | di << " get - get layer id of interactive object\n"; | |
5410 | di << " argument layerid should be passed for set operation only\n"; | |
5411 | return 1; | |
5412 | } | |
5413 | ||
5414 | // find object | |
5415 | TCollection_AsciiString aName (argv[2]); | |
8f521168 | 5416 | Handle(AIS_InteractiveObject) anInterObj; |
5417 | GetMapOfAIS().Find2 (aName, anInterObj); | |
59f45b7c | 5418 | if (anInterObj.IsNull()) |
5419 | { | |
23fe70ec | 5420 | Message::SendFail() << "Syntax error: object '" << aName << "' is not displayed"; |
59f45b7c | 5421 | return 1; |
5422 | } | |
5423 | ||
5424 | // process operation | |
5425 | if (aOperation.IsEqual ("set")) | |
5426 | { | |
91322f44 | 5427 | Standard_Integer aLayerId = Draw::Atoi (argv [3]); |
59f45b7c | 5428 | aContext->SetZLayer (anInterObj, aLayerId); |
5429 | } | |
5430 | else if (aOperation.IsEqual ("get")) | |
5431 | { | |
5432 | di << "Z layer id: " << aContext->GetZLayer (anInterObj); | |
5433 | } | |
5434 | ||
5435 | return 0; | |
5436 | } | |
5437 | ||
3ddebf91 | 5438 | //======================================================================= |
5439 | //function : VPolygonOffset | |
5440 | //purpose : Set or get polygon offset parameters | |
5441 | //======================================================================= | |
35e08fe8 | 5442 | static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/, |
3ddebf91 | 5443 | Standard_Integer argc, |
5444 | const char ** argv) | |
5445 | { | |
5446 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5447 | if (aContext.IsNull()) | |
5448 | { | |
23fe70ec | 5449 | Message::SendFail ("Error: no active viewer"); |
3ddebf91 | 5450 | return 1; |
5451 | } | |
5452 | ||
5453 | if (argc > 2 && argc != 5) | |
5454 | { | |
23fe70ec | 5455 | Message::SendFail() << "Syntax error: wrong number of arguments.\n" |
5456 | "Usage: " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object," | |
5457 | "without arguments prints the default values"; | |
3ddebf91 | 5458 | return 1; |
5459 | } | |
5460 | ||
5461 | // find object | |
5462 | Handle(AIS_InteractiveObject) anInterObj; | |
5463 | if (argc >= 2) | |
5464 | { | |
5465 | TCollection_AsciiString aName (argv[1]); | |
8f521168 | 5466 | if (!GetMapOfAIS().Find2 (aName, anInterObj) |
5467 | || anInterObj.IsNull()) | |
3ddebf91 | 5468 | { |
23fe70ec | 5469 | Message::SendFail() << "Syntax error: object '" << aName << "' is not displayed"; |
3ddebf91 | 5470 | return 1; |
5471 | } | |
5472 | } | |
5473 | ||
5474 | Standard_Integer aMode; | |
60be1f9b | 5475 | Standard_ShortReal aFactor, aUnits; |
3ddebf91 | 5476 | if (argc == 5) |
5477 | { | |
91322f44 | 5478 | aMode = Draw::Atoi(argv[2]); |
5479 | aFactor = (Standard_ShortReal) Draw::Atof(argv[3]); | |
5480 | aUnits = (Standard_ShortReal) Draw::Atof(argv[4]); | |
3ddebf91 | 5481 | |
5482 | anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits); | |
5483 | aContext->UpdateCurrentViewer(); | |
5484 | return 0; | |
5485 | } | |
5486 | else if (argc == 2) | |
5487 | { | |
5488 | if (anInterObj->HasPolygonOffsets()) | |
5489 | { | |
5490 | anInterObj->PolygonOffsets(aMode, aFactor, aUnits); | |
5491 | std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl; | |
5492 | std::cout << "\tMode: " << aMode << std::endl; | |
5493 | std::cout << "\tFactor: " << aFactor << std::endl; | |
5494 | std::cout << "\tUnits: " << aUnits << std::endl; | |
5495 | return 0; | |
5496 | } | |
5497 | else | |
5498 | { | |
5499 | std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl; | |
5500 | } | |
5501 | } | |
5502 | ||
5503 | std::cout << "Default polygon offset parameters:" << std::endl; | |
5504 | aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits); | |
5505 | std::cout << "\tMode: " << aMode << std::endl; | |
5506 | std::cout << "\tFactor: " << aFactor << std::endl; | |
5507 | std::cout << "\tUnits: " << aUnits << std::endl; | |
5508 | ||
5509 | return 0; | |
5510 | } | |
5511 | ||
eb4320f2 | 5512 | // This class is used for testing markers. |
eb4320f2 | 5513 | class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject |
5514 | { | |
5515 | ||
5516 | public: | |
5517 | ||
5518 | ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint, | |
5519 | const Standard_Integer& thePointsOnSide, | |
5520 | Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL) | |
5521 | { | |
5522 | myStartPoint = theStartPoint; | |
5523 | myPointsOnSide = thePointsOnSide; | |
5524 | myMarkerAspect = theMarkerAspect; | |
5525 | } | |
5526 | ||
0e9fe060 | 5527 | DEFINE_STANDARD_RTTI_INLINE(ViewerTest_MarkersArrayObject,AIS_InteractiveObject); |
eb4320f2 | 5528 | |
5529 | private: | |
5530 | ||
5531 | void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
5532 | const Handle(Prs3d_Presentation)& aPresentation, | |
79104795 | 5533 | const Standard_Integer aMode) Standard_OVERRIDE; |
eb4320f2 | 5534 | |
5535 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
79104795 | 5536 | const Standard_Integer /*theMode*/) Standard_OVERRIDE; |
eb4320f2 | 5537 | |
5538 | protected: | |
5539 | ||
5540 | gp_XYZ myStartPoint; | |
5541 | Standard_Integer myPointsOnSide; | |
5542 | Handle(Graphic3d_AspectMarker3d) myMarkerAspect; | |
5543 | }; | |
5544 | ||
eb4320f2 | 5545 | |
5546 | void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, | |
5547 | const Handle(Prs3d_Presentation)& aPresentation, | |
5548 | const Standard_Integer /*aMode*/) | |
5549 | { | |
5550 | Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1); | |
5551 | if (myPointsOnSide == 1) | |
5552 | { | |
5553 | anArray->AddVertex (myStartPoint); | |
5554 | } | |
5555 | else | |
5556 | { | |
5557 | for (Standard_Real i = 1; i <= myPointsOnSide; i++) | |
5558 | { | |
5559 | for (Standard_Real j = 1; j <= myPointsOnSide; j++) | |
5560 | { | |
5561 | for (Standard_Real k = 1; k <= myPointsOnSide; k++) | |
5562 | { | |
5563 | anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k); | |
5564 | anArray->SetVertexColor (anArray->VertexNumber(), | |
5565 | i / myPointsOnSide, | |
5566 | j / myPointsOnSide, | |
5567 | k / myPointsOnSide); | |
5568 | } | |
5569 | } | |
5570 | } | |
5571 | } | |
5572 | ||
5573 | aPresentation->Clear(); | |
5574 | if (!myMarkerAspect.IsNull()) | |
5575 | { | |
d6c48921 | 5576 | aPresentation->CurrentGroup()->SetGroupPrimitivesAspect (myMarkerAspect); |
eb4320f2 | 5577 | } |
d6c48921 | 5578 | aPresentation->CurrentGroup()->AddPrimitiveArray (anArray); |
eb4320f2 | 5579 | } |
5580 | ||
5581 | void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
5582 | const Standard_Integer /*theMode*/) | |
5583 | { | |
5584 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this); | |
5585 | ||
5586 | if (myPointsOnSide == 1) | |
5587 | { | |
5588 | gp_Pnt aPoint (myStartPoint); | |
5589 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
5590 | theSelection->Add (aSensetivePoint); | |
5591 | } | |
5592 | else | |
5593 | { | |
5594 | for (Standard_Real i = 1; i <= myPointsOnSide; i++) | |
5595 | { | |
5596 | for (Standard_Real j = 1; j <= myPointsOnSide; j++) | |
5597 | { | |
5598 | for (Standard_Real k = 1; k <= myPointsOnSide; k++) | |
5599 | { | |
5600 | gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k); | |
5601 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
5602 | theSelection->Add (aSensetivePoint); | |
5603 | } | |
5604 | } | |
5605 | } | |
5606 | } | |
5607 | } | |
a577aaab | 5608 | //======================================================================= |
5609 | //function : VMarkersTest | |
5610 | //purpose : Draws an array of markers for testing purposes. | |
5611 | //======================================================================= | |
498ce76b | 5612 | static Standard_Integer VMarkersTest (Draw_Interpretor&, |
a577aaab | 5613 | Standard_Integer theArgNb, |
5614 | const char** theArgVec) | |
5615 | { | |
5616 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5617 | if (aContext.IsNull()) | |
5618 | { | |
23fe70ec | 5619 | Message::SendFail ("Error: no active viewer"); |
a577aaab | 5620 | return 1; |
5621 | } | |
5622 | ||
5623 | if (theArgNb < 5) | |
5624 | { | |
23fe70ec | 5625 | Message::SendFail ("Syntax error: wrong number of arguments"); |
a577aaab | 5626 | return 1; |
5627 | } | |
5628 | ||
5629 | Standard_Integer anArgIter = 1; | |
5630 | ||
5631 | TCollection_AsciiString aName (theArgVec[anArgIter++]); | |
5632 | TCollection_AsciiString aFileName; | |
5633 | gp_XYZ aPnt (Atof (theArgVec[anArgIter]), | |
5634 | Atof (theArgVec[anArgIter + 1]), | |
5635 | Atof (theArgVec[anArgIter + 2])); | |
5636 | anArgIter += 3; | |
5637 | ||
5638 | Standard_Integer aPointsOnSide = 10; | |
5639 | Standard_Integer aMarkerType = -1; | |
5640 | Standard_Real aScale = 1.0; | |
5641 | for (; anArgIter < theArgNb; ++anArgIter) | |
5642 | { | |
5643 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5644 | if (anArg.Search ("PointsOnSide=") > -1) | |
5645 | { | |
5646 | aPointsOnSide = anArg.Token ("=", 2).IntegerValue(); | |
5647 | } | |
5648 | else if (anArg.Search ("MarkerType=") > -1) | |
5649 | { | |
5650 | aMarkerType = anArg.Token ("=", 2).IntegerValue(); | |
5651 | } | |
5652 | else if (anArg.Search ("Scale=") > -1) | |
5653 | { | |
5654 | aScale = anArg.Token ("=", 2).RealValue(); | |
5655 | } | |
5656 | else if (anArg.Search ("FileName=") > -1) | |
5657 | { | |
5658 | aFileName = anArg.Token ("=", 2); | |
5659 | } | |
5660 | else | |
5661 | { | |
23fe70ec | 5662 | Message::SendFail() << "Syntax error: wrong argument '" << anArg << "'"; |
a577aaab | 5663 | return 1; |
5664 | } | |
5665 | } | |
5666 | ||
5667 | Handle(Graphic3d_AspectMarker3d) anAspect; | |
5668 | Handle(Image_AlienPixMap) anImage; | |
5669 | Quantity_Color aColor (Quantity_NOC_GREEN1); | |
5670 | if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0) | |
5671 | && !aFileName.IsEmpty()) | |
5672 | { | |
5673 | anImage = new Image_AlienPixMap(); | |
5674 | if (!anImage->Load (aFileName)) | |
5675 | { | |
23fe70ec | 5676 | Message::SendFail() << "Error: could not load image from file '" << aFileName << "'!"; |
a577aaab | 5677 | return 1; |
5678 | } | |
dc858f4c | 5679 | if (anImage->Format() == Image_Format_Gray) |
076ca35c | 5680 | { |
dc858f4c | 5681 | anImage->SetFormat (Image_Format_Alpha); |
076ca35c | 5682 | } |
dc858f4c | 5683 | else if (anImage->Format() == Image_Format_GrayF) |
076ca35c | 5684 | { |
dc858f4c | 5685 | anImage->SetFormat (Image_Format_AlphaF); |
076ca35c | 5686 | } |
a577aaab | 5687 | anAspect = new Graphic3d_AspectMarker3d (anImage); |
5688 | } | |
5689 | else | |
5690 | { | |
5691 | anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale); | |
5692 | } | |
5693 | ||
eb4320f2 | 5694 | Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect); |
5695 | VDisplayAISObject (aName, aMarkersArray); | |
a577aaab | 5696 | |
5697 | return 0; | |
5698 | } | |
5699 | ||
b514beda | 5700 | //======================================================================= |
5701 | //function : TextToBrep | |
5702 | //purpose : Tool for conversion text to occt-shapes | |
5703 | //======================================================================= | |
b514beda | 5704 | static int TextToBRep (Draw_Interpretor& /*theDI*/, |
5705 | Standard_Integer theArgNb, | |
5706 | const char** theArgVec) | |
5707 | { | |
5708 | // Check arguments | |
ac84fcf6 | 5709 | if (theArgNb < 3) |
b514beda | 5710 | { |
23fe70ec | 5711 | Message::SendFail() << "Error: " << theArgVec[0] << " - invalid syntax"; |
b514beda | 5712 | return 1; |
5713 | } | |
5714 | ||
ac84fcf6 | 5715 | Standard_Integer anArgIt = 1; |
5716 | Standard_CString aName = theArgVec[anArgIt++]; | |
5717 | Standard_CString aText = theArgVec[anArgIt++]; | |
b514beda | 5718 | |
ac84fcf6 | 5719 | Font_BRepFont aFont; |
5720 | TCollection_AsciiString aFontName ("Courier"); | |
5721 | Standard_Real aTextHeight = 16.0; | |
5722 | Font_FontAspect aFontAspect = Font_FA_Regular; | |
5723 | Standard_Boolean anIsCompositeCurve = Standard_False; | |
5724 | gp_Ax3 aPenAx3 (gp::XOY()); | |
5725 | gp_Dir aNormal (0.0, 0.0, 1.0); | |
5726 | gp_Dir aDirection (1.0, 0.0, 0.0); | |
5727 | gp_Pnt aPenLoc; | |
5728 | ||
5729 | Graphic3d_HorizontalTextAlignment aHJustification = Graphic3d_HTA_LEFT; | |
5730 | Graphic3d_VerticalTextAlignment aVJustification = Graphic3d_VTA_BOTTOM; | |
1bbd7c79 | 5731 | Font_StrictLevel aStrictLevel = Font_StrictLevel_Any; |
ac84fcf6 | 5732 | for (; anArgIt < theArgNb; ++anArgIt) |
b514beda | 5733 | { |
ac84fcf6 | 5734 | TCollection_AsciiString aParam (theArgVec[anArgIt]); |
5735 | aParam.LowerCase(); | |
5736 | ||
5737 | if (aParam == "-pos" | |
5738 | || aParam == "-position") | |
b514beda | 5739 | { |
ac84fcf6 | 5740 | if (anArgIt + 3 >= theArgNb) |
5741 | { | |
23fe70ec | 5742 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
ac84fcf6 | 5743 | return 1; |
5744 | } | |
5745 | ||
5746 | aPenLoc.SetX (Draw::Atof(theArgVec[++anArgIt])); | |
5747 | aPenLoc.SetY (Draw::Atof(theArgVec[++anArgIt])); | |
5748 | aPenLoc.SetZ (Draw::Atof(theArgVec[++anArgIt])); | |
b514beda | 5749 | } |
ac84fcf6 | 5750 | else if (aParam == "-halign") |
b514beda | 5751 | { |
ac84fcf6 | 5752 | if (++anArgIt >= theArgNb) |
5753 | { | |
23fe70ec | 5754 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
ac84fcf6 | 5755 | return 1; |
5756 | } | |
5757 | ||
5758 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
5759 | aType.LowerCase(); | |
5760 | if (aType == "left") | |
5761 | { | |
5762 | aHJustification = Graphic3d_HTA_LEFT; | |
5763 | } | |
5764 | else if (aType == "center") | |
5765 | { | |
5766 | aHJustification = Graphic3d_HTA_CENTER; | |
5767 | } | |
5768 | else if (aType == "right") | |
5769 | { | |
5770 | aHJustification = Graphic3d_HTA_RIGHT; | |
5771 | } | |
5772 | else | |
5773 | { | |
23fe70ec | 5774 | Message::SendFail() << "Error: wrong syntax at '" << aParam << "'"; |
ac84fcf6 | 5775 | return 1; |
5776 | } | |
b514beda | 5777 | } |
ac84fcf6 | 5778 | else if (aParam == "-valign") |
b514beda | 5779 | { |
ac84fcf6 | 5780 | if (++anArgIt >= theArgNb) |
5781 | { | |
23fe70ec | 5782 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
ac84fcf6 | 5783 | return 1; |
5784 | } | |
5785 | ||
5786 | TCollection_AsciiString aType (theArgVec[anArgIt]); | |
5787 | aType.LowerCase(); | |
5788 | if (aType == "top") | |
5789 | { | |
5790 | aVJustification = Graphic3d_VTA_TOP; | |
5791 | } | |
5792 | else if (aType == "center") | |
5793 | { | |
5794 | aVJustification = Graphic3d_VTA_CENTER; | |
5795 | } | |
5796 | else if (aType == "bottom") | |
5797 | { | |
5798 | aVJustification = Graphic3d_VTA_BOTTOM; | |
5799 | } | |
5800 | else if (aType == "topfirstline") | |
5801 | { | |
5802 | aVJustification = Graphic3d_VTA_TOPFIRSTLINE; | |
5803 | } | |
5804 | else | |
5805 | { | |
23fe70ec | 5806 | Message::SendFail() << "Error: wrong syntax at '" << aParam << "'"; |
ac84fcf6 | 5807 | return 1; |
5808 | } | |
b514beda | 5809 | } |
ac84fcf6 | 5810 | else if (aParam == "-height") |
b514beda | 5811 | { |
ac84fcf6 | 5812 | if (++anArgIt >= theArgNb) |
5813 | { | |
23fe70ec | 5814 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
ac84fcf6 | 5815 | return 1; |
5816 | } | |
5817 | ||
5818 | aTextHeight = Draw::Atof(theArgVec[anArgIt]); | |
b514beda | 5819 | } |
ac84fcf6 | 5820 | else if (aParam == "-aspect") |
b514beda | 5821 | { |
ac84fcf6 | 5822 | if (++anArgIt >= theArgNb) |
5823 | { | |
23fe70ec | 5824 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
ac84fcf6 | 5825 | return 1; |
5826 | } | |
5827 | ||
5828 | TCollection_AsciiString anOption (theArgVec[anArgIt]); | |
5829 | anOption.LowerCase(); | |
5b377041 | 5830 | if (!parseFontStyle (anOption, aFontAspect)) |
ac84fcf6 | 5831 | { |
23fe70ec | 5832 | Message::SendFail() << "Error: unknown font aspect '" << anOption << "'"; |
ac84fcf6 | 5833 | return 1; |
5834 | } | |
5835 | } | |
5836 | else if (aParam == "-font") | |
5837 | { | |
5838 | if (++anArgIt >= theArgNb) | |
5839 | { | |
23fe70ec | 5840 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
ac84fcf6 | 5841 | return 1; |
5842 | } | |
5843 | ||
5844 | aFontName = theArgVec[anArgIt]; | |
5845 | } | |
1bbd7c79 | 5846 | else if (aParam == "-strict") |
5847 | { | |
5848 | anArgIt += parseFontStrictLevel (theArgNb - anArgIt - 1, | |
5849 | theArgVec + anArgIt + 1, | |
5850 | aStrictLevel); | |
5851 | } | |
ac84fcf6 | 5852 | else if (aParam == "-composite") |
5853 | { | |
5854 | if (++anArgIt >= theArgNb) | |
5855 | { | |
23fe70ec | 5856 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
ac84fcf6 | 5857 | return 1; |
5858 | } | |
5859 | ||
dae2a922 | 5860 | Draw::ParseOnOff (theArgVec[anArgIt], anIsCompositeCurve); |
ac84fcf6 | 5861 | } |
5862 | else if (aParam == "-plane") | |
5863 | { | |
5864 | if (anArgIt + 6 >= theArgNb) | |
5865 | { | |
23fe70ec | 5866 | Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'"; |
ac84fcf6 | 5867 | return 1; |
5868 | } | |
5869 | ||
5870 | Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]); | |
5871 | Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]); | |
5872 | Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]); | |
5873 | aNormal.SetCoord (aX, aY, aZ); | |
5874 | ||
5875 | aX = Draw::Atof (theArgVec[++anArgIt]); | |
5876 | aY = Draw::Atof (theArgVec[++anArgIt]); | |
5877 | aZ = Draw::Atof (theArgVec[++anArgIt]); | |
5878 | aDirection.SetCoord (aX, aY, aZ); | |
b514beda | 5879 | } |
5880 | else | |
5881 | { | |
23fe70ec | 5882 | Message::SendFail() << "Warning! Unknown argument '" << aParam << "'"; |
b514beda | 5883 | } |
5884 | } | |
5885 | ||
ac84fcf6 | 5886 | aFont.SetCompositeCurveMode (anIsCompositeCurve); |
1bbd7c79 | 5887 | if (!aFont.FindAndInit (aFontName.ToCString(), aFontAspect, aTextHeight, aStrictLevel)) |
b514beda | 5888 | { |
23fe70ec | 5889 | Message::SendFail ("Error: unable to load Font"); |
b514beda | 5890 | return 1; |
5891 | } | |
5892 | ||
ac84fcf6 | 5893 | aPenAx3 = gp_Ax3 (aPenLoc, aNormal, aDirection); |
5894 | ||
5895 | Font_BRepTextBuilder aBuilder; | |
5896 | DBRep::Set (aName, aBuilder.Perform (aFont, aText, aPenAx3, aHJustification, aVJustification)); | |
b514beda | 5897 | return 0; |
5898 | } | |
5899 | ||
725ef85e | 5900 | //======================================================================= |
5901 | //function : VFont | |
5902 | //purpose : Font management | |
5903 | //======================================================================= | |
c9983ee8 | 5904 | struct FontComparator |
5905 | { | |
5906 | bool operator() (const Handle(Font_SystemFont)& theFontA, | |
5907 | const Handle(Font_SystemFont)& theFontB) | |
5908 | { | |
5909 | return theFontA->FontKey().IsLess (theFontB->FontKey()); | |
5910 | } | |
5911 | }; | |
725ef85e | 5912 | |
5913 | static int VFont (Draw_Interpretor& theDI, | |
5914 | Standard_Integer theArgNb, | |
5915 | const char** theArgVec) | |
5916 | { | |
5917 | Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance(); | |
15e4e6a2 | 5918 | bool toPrintList = theArgNb < 2, toPrintNames = false; |
1bbd7c79 | 5919 | Font_StrictLevel aStrictLevel = Font_StrictLevel_Any; |
725ef85e | 5920 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
5921 | { | |
5922 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5923 | TCollection_AsciiString anArgCase (anArg); | |
5924 | anArgCase.LowerCase(); | |
1bbd7c79 | 5925 | if (anArgCase == "-strict") |
5926 | { | |
5927 | anArgIter += parseFontStrictLevel (theArgNb - anArgIter - 1, | |
5928 | theArgVec + anArgIter + 1, | |
5929 | aStrictLevel); | |
5930 | } | |
36e28f96 | 5931 | else if (anArgCase == "-clear") |
5932 | { | |
5933 | aMgr->ClearFontDataBase(); | |
5934 | } | |
5935 | else if (anArgCase == "-init") | |
5936 | { | |
5937 | aMgr->InitFontDataBase(); | |
5938 | } | |
15e4e6a2 | 5939 | else if (anArgCase == "-list") |
5940 | { | |
5941 | toPrintList = true; | |
5942 | } | |
5943 | else if (anArgCase == "-names") | |
5944 | { | |
5945 | toPrintList = true; | |
5946 | toPrintNames = true; | |
5947 | } | |
1bbd7c79 | 5948 | else if (anArgIter + 1 < theArgNb |
5949 | && (anArgCase == "-find" | |
15e4e6a2 | 5950 | || anArgCase == "-findinfo" |
5951 | || anArgCase == "-findall" | |
1bbd7c79 | 5952 | || anArgCase == "find")) |
725ef85e | 5953 | { |
15e4e6a2 | 5954 | const TCollection_AsciiString aFontName (theArgVec[++anArgIter]); |
5955 | Font_FontAspect aFontAspect = Font_FA_Undefined; | |
725ef85e | 5956 | if (++anArgIter < theArgNb) |
5957 | { | |
5958 | anArgCase = theArgVec[anArgIter]; | |
5959 | anArgCase.LowerCase(); | |
5960 | if (!parseFontStyle (anArgCase, aFontAspect)) | |
5961 | { | |
5962 | --anArgIter; | |
5963 | } | |
5964 | } | |
5b377041 | 5965 | |
15e4e6a2 | 5966 | const bool toFindAll = (anArgCase == "-findall"); |
5967 | const bool toPrintInfo = (anArgCase == "-findinfo"); | |
5968 | TCollection_AsciiString aResult; | |
5969 | if (toFindAll | |
5970 | || aFontName.Search ("*") != -1) | |
5b377041 | 5971 | { |
15e4e6a2 | 5972 | const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts(); |
5973 | std::vector<Handle(Font_SystemFont)> aFontsSorted; | |
5974 | aFontsSorted.reserve (aFonts.Size()); | |
5975 | for (Font_NListOfSystemFont::Iterator aFontIter (aFonts); aFontIter.More(); aFontIter.Next()) | |
5976 | { | |
5977 | aFontsSorted.push_back (aFontIter.Value()); | |
5978 | } | |
5979 | std::stable_sort (aFontsSorted.begin(), aFontsSorted.end(), FontComparator()); | |
5980 | for (std::vector<Handle(Font_SystemFont)>::iterator aFontIter = aFontsSorted.begin(); aFontIter != aFontsSorted.end(); ++aFontIter) | |
5981 | { | |
5982 | const Handle(Font_SystemFont)& aFont = *aFontIter; | |
5983 | const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match -nocase \"") + aFontName + "\" \"" + aFont->FontName() + "\""; | |
5984 | if (theDI.Eval (aCheck.ToCString()) == 0 | |
5985 | && *theDI.Result() != '1') | |
5986 | { | |
5987 | theDI.Reset(); | |
5988 | continue; | |
5989 | } | |
5990 | ||
5991 | theDI.Reset(); | |
5992 | if (!aResult.IsEmpty()) | |
5993 | { | |
5994 | aResult += "\n"; | |
5995 | } | |
5996 | ||
5997 | aResult += toPrintInfo ? aFont->ToString() : aFont->FontName(); | |
5998 | if (!toFindAll) | |
5999 | { | |
6000 | break; | |
6001 | } | |
6002 | } | |
6003 | } | |
6004 | else if (Handle(Font_SystemFont) aFont = aMgr->FindFont (aFontName, aStrictLevel, aFontAspect)) | |
6005 | { | |
6006 | aResult = toPrintInfo ? aFont->ToString() : aFont->FontName(); | |
6007 | } | |
6008 | ||
6009 | if (!aResult.IsEmpty()) | |
6010 | { | |
6011 | theDI << aResult; | |
5b377041 | 6012 | } |
6013 | else | |
725ef85e | 6014 | { |
23fe70ec | 6015 | Message::SendFail() << "Error: font '" << aFontName << "' is not found"; |
725ef85e | 6016 | } |
725ef85e | 6017 | } |
5b377041 | 6018 | else if (anArgIter + 1 < theArgNb |
6019 | && (anArgCase == "-add" | |
6020 | || anArgCase == "add" | |
6021 | || anArgCase == "-register" | |
6022 | || anArgCase == "register")) | |
725ef85e | 6023 | { |
5b377041 | 6024 | ++anArgIter; |
e4f0cc46 | 6025 | Standard_CString aFontPath = theArgVec[anArgIter++]; |
6026 | TCollection_AsciiString aFontName; | |
725ef85e | 6027 | Font_FontAspect aFontAspect = Font_FA_Undefined; |
e4f0cc46 | 6028 | Standard_Integer isSingelStroke = -1; |
6029 | for (; anArgIter < theArgNb; ++anArgIter) | |
725ef85e | 6030 | { |
e4f0cc46 | 6031 | anArgCase = theArgVec[anArgIter]; |
6032 | anArgCase.LowerCase(); | |
5b377041 | 6033 | if (aFontAspect == Font_FontAspect_UNDEFINED |
e4f0cc46 | 6034 | && parseFontStyle (anArgCase, aFontAspect)) |
6035 | { | |
6036 | continue; | |
6037 | } | |
6038 | else if (anArgCase == "singlestroke" | |
6039 | || anArgCase == "singleline" | |
6040 | || anArgCase == "oneline") | |
6041 | { | |
6042 | isSingelStroke = 1; | |
6043 | } | |
6044 | else if (aFontName.IsEmpty()) | |
725ef85e | 6045 | { |
6046 | aFontName = theArgVec[anArgIter]; | |
6047 | } | |
e4f0cc46 | 6048 | else |
725ef85e | 6049 | { |
e4f0cc46 | 6050 | --anArgIter; |
6051 | break; | |
725ef85e | 6052 | } |
6053 | } | |
6054 | ||
6055 | Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath); | |
6056 | if (aFont.IsNull()) | |
6057 | { | |
23fe70ec | 6058 | Message::SendFail() << "Error: font '" << aFontPath << "' is not found!"; |
725ef85e | 6059 | continue; |
6060 | } | |
6061 | ||
5b377041 | 6062 | if (aFontAspect != Font_FontAspect_UNDEFINED |
e4f0cc46 | 6063 | || !aFontName.IsEmpty()) |
725ef85e | 6064 | { |
5b377041 | 6065 | TCollection_AsciiString aName = aFont->FontName(); |
6066 | if (!aFontName.IsEmpty()) | |
725ef85e | 6067 | { |
5b377041 | 6068 | aName = aFontName; |
725ef85e | 6069 | } |
5b377041 | 6070 | Handle(Font_SystemFont) aFont2 = new Font_SystemFont (aName); |
6071 | if (aFontAspect != Font_FontAspect_UNDEFINED) | |
6072 | { | |
9a90a452 | 6073 | aFont2->SetFontPath (aFontAspect, aFontPath, 0); |
5b377041 | 6074 | } |
6075 | else | |
725ef85e | 6076 | { |
5b377041 | 6077 | for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter) |
6078 | { | |
9a90a452 | 6079 | aFont2->SetFontPath ((Font_FontAspect )anAspectIter, |
6080 | aFont->FontPath ((Font_FontAspect )anAspectIter), | |
6081 | aFont->FontFaceId ((Font_FontAspect )anAspectIter)); | |
5b377041 | 6082 | } |
725ef85e | 6083 | } |
5b377041 | 6084 | aFont = aFont2; |
725ef85e | 6085 | } |
e4f0cc46 | 6086 | if (isSingelStroke != -1) |
6087 | { | |
6088 | aFont->SetSingleStrokeFont (isSingelStroke == 1); | |
6089 | } | |
725ef85e | 6090 | |
6091 | aMgr->RegisterFont (aFont, Standard_True); | |
5b377041 | 6092 | theDI << aFont->ToString(); |
6093 | } | |
f5e758d2 | 6094 | else if (anArgCase == "-aliases") |
6095 | { | |
6096 | TCollection_AsciiString anAliasName; | |
6097 | TColStd_SequenceOfHAsciiString aNames; | |
6098 | if (anArgIter + 1 < theArgNb | |
6099 | && *theArgVec[anArgIter + 1] != '-') | |
6100 | { | |
6101 | anAliasName = theArgVec[++anArgIter]; | |
6102 | } | |
6103 | if (!anAliasName.IsEmpty()) | |
6104 | { | |
6105 | aMgr->GetFontAliases (aNames, anAliasName); | |
6106 | } | |
6107 | else | |
6108 | { | |
6109 | aMgr->GetAllAliases (aNames); | |
6110 | } | |
6111 | for (TColStd_SequenceOfHAsciiString::Iterator aNameIter (aNames); aNameIter.More(); aNameIter.Next()) | |
6112 | { | |
6113 | theDI << "{" << aNameIter.Value()->String() << "} "; | |
6114 | } | |
6115 | } | |
6116 | else if (anArgIter + 2 < theArgNb | |
6117 | && anArgCase == "-addalias") | |
6118 | { | |
6119 | TCollection_AsciiString anAliasName(theArgVec[++anArgIter]); | |
6120 | TCollection_AsciiString aFontName (theArgVec[++anArgIter]); | |
6121 | aMgr->AddFontAlias (anAliasName, aFontName); | |
6122 | } | |
6123 | else if (anArgIter + 2 < theArgNb | |
6124 | && anArgCase == "-removealias") | |
6125 | { | |
6126 | TCollection_AsciiString anAliasName(theArgVec[++anArgIter]); | |
6127 | TCollection_AsciiString aFontName (theArgVec[++anArgIter]); | |
6128 | aMgr->RemoveFontAlias (anAliasName, aFontName); | |
6129 | } | |
6130 | else if (anArgIter + 1 < theArgNb | |
6131 | && anArgCase == "-clearalias") | |
6132 | { | |
6133 | TCollection_AsciiString anAliasName(theArgVec[++anArgIter]); | |
6134 | aMgr->RemoveFontAlias (anAliasName, ""); | |
6135 | } | |
6136 | else if (anArgCase == "-clearaliases") | |
6137 | { | |
6138 | aMgr->RemoveFontAlias ("", ""); | |
6139 | } | |
5b377041 | 6140 | else if (anArgCase == "-verbose" |
6141 | || anArgCase == "-trace") | |
6142 | { | |
6143 | bool toEnable = true; | |
6144 | if (anArgIter + 1 < theArgNb | |
dae2a922 | 6145 | && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) |
5b377041 | 6146 | { |
6147 | ++anArgIter; | |
6148 | } | |
6149 | aMgr->SetTraceAliases (toEnable); | |
725ef85e | 6150 | } |
912761ea | 6151 | else if (anArgCase == "-unicodefallback" |
6152 | || anArgCase == "-fallback" | |
6153 | || anArgCase == "-touseunicodesubsetfallback") | |
6154 | { | |
6155 | bool toEnable = true; | |
6156 | if (anArgIter + 1 < theArgNb | |
dae2a922 | 6157 | && Draw::ParseOnOff (theArgVec[anArgIter + 1], toEnable)) |
912761ea | 6158 | { |
6159 | ++anArgIter; | |
6160 | } | |
6161 | Font_FontMgr::ToUseUnicodeSubsetFallback() = toEnable; | |
6162 | } | |
725ef85e | 6163 | else |
6164 | { | |
23fe70ec | 6165 | Message::SendFail() << "Warning! Unknown argument '" << anArg << "'"; |
725ef85e | 6166 | } |
6167 | } | |
6168 | ||
15e4e6a2 | 6169 | if (toPrintList) |
6170 | { | |
6171 | // just print the list of available fonts | |
6172 | Standard_Boolean isFirst = Standard_True; | |
6173 | const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts(); | |
6174 | std::vector<Handle(Font_SystemFont)> aFontsSorted; | |
6175 | aFontsSorted.reserve (aFonts.Size()); | |
6176 | for (Font_NListOfSystemFont::Iterator aFontIter (aFonts); aFontIter.More(); aFontIter.Next()) | |
6177 | { | |
6178 | aFontsSorted.push_back (aFontIter.Value()); | |
6179 | } | |
6180 | std::stable_sort (aFontsSorted.begin(), aFontsSorted.end(), FontComparator()); | |
6181 | for (std::vector<Handle(Font_SystemFont)>::iterator aFontIter = aFontsSorted.begin(); aFontIter != aFontsSorted.end(); ++aFontIter) | |
6182 | { | |
6183 | const Handle(Font_SystemFont)& aFont = *aFontIter; | |
6184 | ||
6185 | if (toPrintNames) | |
6186 | { | |
6187 | if (!isFirst) | |
6188 | { | |
6189 | theDI << "\n"; | |
6190 | } | |
6191 | theDI << "\"" << aFont->FontName() << "\""; | |
6192 | } | |
6193 | else | |
6194 | { | |
6195 | if (!isFirst) | |
6196 | { | |
6197 | theDI << "\n"; | |
6198 | } | |
6199 | theDI << aFont->ToString(); | |
6200 | } | |
6201 | isFirst = Standard_False; | |
6202 | } | |
6203 | return 0; | |
6204 | } | |
6205 | ||
725ef85e | 6206 | return 0; |
6207 | } | |
6208 | ||
53b15292 | 6209 | //======================================================================= |
6210 | //function : VVertexMode | |
6211 | //purpose : Switches vertex display mode for AIS_Shape or displays the current value | |
6212 | //======================================================================= | |
6213 | ||
6214 | static int VVertexMode (Draw_Interpretor& theDI, | |
6215 | Standard_Integer theArgNum, | |
6216 | const char** theArgs) | |
6217 | { | |
6218 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6219 | if (aContext.IsNull()) | |
6220 | { | |
23fe70ec | 6221 | Message::SendFail ("Error: no active viewer"); |
53b15292 | 6222 | return 1; |
6223 | } | |
6224 | ||
6225 | // No arguments --> print the current default vertex draw mode | |
6226 | if (theArgNum == 1) | |
6227 | { | |
6228 | Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode(); | |
6229 | theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; | |
6230 | return 0; | |
6231 | } | |
6232 | ||
6233 | // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s) | |
6234 | TCollection_AsciiString aParam (theArgs[1]); | |
6235 | if (aParam == "-set") | |
6236 | { | |
6237 | if (theArgNum == 2) | |
6238 | { | |
23fe70ec | 6239 | Message::SendFail ("Error: '-set' option not followed by the mode and optional object name(s)\n" |
6240 | "Type 'help vvertexmode' for usage hints"); | |
53b15292 | 6241 | return 1; |
6242 | } | |
6243 | ||
6244 | TCollection_AsciiString aModeStr (theArgs[2]); | |
6245 | Prs3d_VertexDrawMode aNewMode = | |
6246 | aModeStr == "isolated" ? Prs3d_VDM_Isolated : | |
6247 | (aModeStr == "all" ? Prs3d_VDM_All : | |
6248 | Prs3d_VDM_Inherited); | |
6249 | ||
6250 | Standard_Boolean aRedrawNeeded = Standard_False; | |
6251 | AIS_ListOfInteractive anObjs; | |
6252 | ||
6253 | // No object(s) specified -> use all displayed | |
6254 | if (theArgNum == 3) | |
6255 | { | |
6256 | theDI << "Setting the default vertex draw mode and updating all displayed objects...\n"; | |
6257 | aContext->DisplayedObjects (anObjs); | |
6258 | aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode); | |
6259 | aRedrawNeeded = Standard_True; | |
6260 | } | |
6261 | ||
6262 | Handle(AIS_InteractiveObject) anObject; | |
6263 | for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++) | |
6264 | { | |
6265 | TCollection_AsciiString aName (theArgs[aCount]); | |
8f521168 | 6266 | if (!GetMapOfAIS().Find2 (aName, anObject)) |
53b15292 | 6267 | { |
6268 | theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n"; | |
6269 | continue; | |
6270 | } | |
53b15292 | 6271 | anObjs.Append (anObject); |
6272 | } | |
6273 | ||
6274 | for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next()) | |
6275 | { | |
6276 | anObject = anIt.Value(); | |
6277 | anObject->Attributes()->SetVertexDrawMode (aNewMode); | |
6278 | aContext->Redisplay (anObject, Standard_False); | |
6279 | aRedrawNeeded = Standard_True; | |
6280 | } | |
6281 | ||
6282 | if (aRedrawNeeded) | |
6283 | ViewerTest::CurrentView()->Redraw(); | |
6284 | ||
6285 | return 0; | |
6286 | } | |
6287 | ||
8f521168 | 6288 | Handle(AIS_InteractiveObject) anObject; |
6289 | if (theArgNum > 2 | |
6290 | || !GetMapOfAIS().Find2 (aParam, anObject)) | |
53b15292 | 6291 | { |
23fe70ec | 6292 | Message::SendFail ("Syntax error: invalid number of arguments"); |
53b15292 | 6293 | return 1; |
6294 | } | |
6295 | ||
6296 | // One argument (object name) --> print the current vertex draw mode for the object | |
53b15292 | 6297 | Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode(); |
6298 | theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; | |
6299 | return 0; | |
6300 | } | |
6301 | ||
d33222c1 | 6302 | //======================================================================= |
6303 | //function : VPointCloud | |
6304 | //purpose : Create interactive object for arbitary set of points. | |
6305 | //======================================================================= | |
6306 | static Standard_Integer VPointCloud (Draw_Interpretor& theDI, | |
6307 | Standard_Integer theArgNum, | |
6308 | const char** theArgs) | |
6309 | { | |
6310 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
6311 | if (anAISContext.IsNull()) | |
6312 | { | |
23fe70ec | 6313 | Message::SendFail ("Error: no active view!"); |
d33222c1 | 6314 | return 1; |
6315 | } | |
6316 | ||
6317 | // command to execute | |
6318 | enum Command | |
6319 | { | |
6320 | CloudForShape, // generate point cloud for shape | |
6321 | CloudSphere, // generate point cloud for generic sphere | |
6322 | Unknow | |
6323 | }; | |
6324 | ||
6325 | // count number of non-optional command arguments | |
6326 | Command aCmd = Unknow; | |
6327 | Standard_Integer aCmdArgs = 0; | |
6328 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter) | |
6329 | { | |
6330 | Standard_CString anArg = theArgs[anArgIter]; | |
6331 | TCollection_AsciiString aFlag (anArg); | |
6332 | aFlag.LowerCase(); | |
6333 | if (aFlag.IsRealValue() || aFlag.Search ("-") != 1) | |
6334 | { | |
6335 | aCmdArgs++; | |
6336 | } | |
6337 | } | |
6338 | switch (aCmdArgs) | |
6339 | { | |
6340 | case 2 : aCmd = CloudForShape; break; | |
6341 | case 7 : aCmd = CloudSphere; break; | |
6342 | default : | |
23fe70ec | 6343 | Message::SendFail ("Syntax error: wrong number of arguments! See usage:"); |
d33222c1 | 6344 | theDI.PrintHelp (theArgs[0]); |
6345 | return 1; | |
6346 | } | |
6347 | ||
6348 | // parse options | |
6349 | Standard_Boolean toRandColors = Standard_False; | |
6350 | Standard_Boolean hasNormals = Standard_True; | |
6351 | Standard_Boolean isSetArgNorm = Standard_False; | |
737e9a8d | 6352 | Standard_Boolean hasUV = Standard_False; |
d33222c1 | 6353 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter) |
6354 | { | |
6355 | Standard_CString anArg = theArgs[anArgIter]; | |
6356 | TCollection_AsciiString aFlag (anArg); | |
6357 | aFlag.LowerCase(); | |
6358 | if (aFlag == "-randcolors" | |
6359 | || aFlag == "-randcolor") | |
6360 | { | |
6361 | if (isSetArgNorm && hasNormals) | |
6362 | { | |
23fe70ec | 6363 | Message::SendFail ("Syntax error: normals can not be enabled with colors at the same time"); |
d33222c1 | 6364 | return 1; |
6365 | } | |
6366 | toRandColors = Standard_True; | |
6367 | hasNormals = Standard_False; | |
6368 | } | |
6369 | else if (aFlag == "-normals" | |
6370 | || aFlag == "-normal") | |
6371 | { | |
6372 | if (toRandColors) | |
6373 | { | |
23fe70ec | 6374 | Message::SendFail ("Syntax error: normals can not be enabled with colors at the same time"); |
d33222c1 | 6375 | return 1; |
6376 | } | |
6377 | isSetArgNorm = Standard_True; | |
6378 | hasNormals = Standard_True; | |
6379 | } | |
6380 | else if (aFlag == "-nonormals" | |
6381 | || aFlag == "-nonormal") | |
6382 | { | |
6383 | isSetArgNorm = Standard_True; | |
6384 | hasNormals = Standard_False; | |
6385 | } | |
737e9a8d | 6386 | else if (aFlag == "-uv" |
6387 | || aFlag == "-texels") | |
6388 | { | |
6389 | hasUV = Standard_True; | |
6390 | } | |
d33222c1 | 6391 | } |
6392 | ||
6393 | Standard_CString aName = theArgs[1]; | |
737e9a8d | 6394 | Graphic3d_ArrayFlags aFlags = Graphic3d_ArrayFlags_None; |
6395 | if (hasNormals) | |
6396 | { | |
6397 | aFlags |= Graphic3d_ArrayFlags_VertexNormal; | |
6398 | } | |
6399 | if (toRandColors) | |
6400 | { | |
6401 | aFlags |= Graphic3d_ArrayFlags_VertexColor; | |
6402 | } | |
6403 | if (hasUV) | |
6404 | { | |
6405 | aFlags |= Graphic3d_ArrayFlags_VertexTexel; | |
6406 | } | |
d33222c1 | 6407 | |
6408 | // generate arbitrary set of points | |
6409 | Handle(Graphic3d_ArrayOfPoints) anArrayPoints; | |
6410 | if (aCmd == CloudForShape) | |
6411 | { | |
6412 | Standard_CString aShapeName = theArgs[2]; | |
6413 | TopoDS_Shape aShape = DBRep::Get (aShapeName); | |
6414 | ||
6415 | if (aShape.IsNull()) | |
6416 | { | |
23fe70ec | 6417 | Message::SendFail() << "Error: no shape with name '" << aShapeName << "' found"; |
d33222c1 | 6418 | return 1; |
6419 | } | |
6420 | ||
6421 | // calculate number of points | |
6422 | TopLoc_Location aLocation; | |
6423 | Standard_Integer aNbPoints = 0; | |
6424 | for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) | |
6425 | { | |
6426 | const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current()); | |
5ad8c033 | 6427 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation); |
d33222c1 | 6428 | if (!aTriangulation.IsNull()) |
6429 | { | |
6430 | aNbPoints += aTriangulation->NbNodes(); | |
6431 | } | |
6432 | } | |
6433 | if (aNbPoints < 3) | |
6434 | { | |
23fe70ec | 6435 | Message::SendFail ("Error: shape should be triangulated"); |
d33222c1 | 6436 | return 1; |
6437 | } | |
6438 | ||
737e9a8d | 6439 | anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags); |
d33222c1 | 6440 | for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) |
6441 | { | |
6442 | const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current()); | |
5ad8c033 | 6443 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (aFace, aLocation); |
d33222c1 | 6444 | if (aTriangulation.IsNull()) |
6445 | { | |
6446 | continue; | |
6447 | } | |
6448 | ||
6449 | const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); | |
6450 | const gp_Trsf& aTrsf = aLocation.Transformation(); | |
6451 | ||
6452 | // extract normals from nodes | |
6453 | TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower()); | |
6454 | if (hasNormals) | |
6455 | { | |
6456 | Poly_Connect aPolyConnect (aTriangulation); | |
5ad8c033 | 6457 | StdPrs_ToolTriangulatedShape::Normal (aFace, aPolyConnect, aNormals); |
d33222c1 | 6458 | } |
6459 | ||
6460 | for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) | |
6461 | { | |
6462 | gp_Pnt aPoint = aNodes (aNodeIter); | |
6463 | if (!aLocation.IsIdentity()) | |
6464 | { | |
6465 | aPoint.Transform (aTrsf); | |
6466 | if (hasNormals) | |
6467 | { | |
6468 | aNormals (aNodeIter).Transform (aTrsf); | |
6469 | } | |
6470 | } | |
6471 | ||
6472 | // add vertex into array of points | |
6473 | const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint); | |
6474 | if (toRandColors) | |
6475 | { | |
6476 | Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints), | |
6477 | 1.0, 0.5, Quantity_TOC_HLS); | |
6478 | anArrayPoints->SetVertexColor (anIndexOfPoint, aColor); | |
6479 | } | |
6480 | ||
6481 | if (hasNormals) | |
6482 | { | |
6483 | anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter)); | |
6484 | } | |
737e9a8d | 6485 | if (hasUV |
6486 | && aTriangulation->HasUVNodes()) | |
6487 | { | |
6488 | anArrayPoints->SetVertexTexel (anIndexOfPoint, aTriangulation->UVNode (aNodeIter)); | |
6489 | } | |
d33222c1 | 6490 | } |
6491 | } | |
6492 | } | |
6493 | else if (aCmd == CloudSphere) | |
6494 | { | |
6495 | Standard_Real aCenterX = Draw::Atof (theArgs[2]); | |
6496 | Standard_Real aCenterY = Draw::Atof (theArgs[3]); | |
6497 | Standard_Real aCenterZ = Draw::Atof (theArgs[4]); | |
6498 | Standard_Real aRadius = Draw::Atof (theArgs[5]); | |
6499 | Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]); | |
6500 | ||
6501 | TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]); | |
6502 | aDistribution.LowerCase(); | |
6503 | if ( aDistribution != "surface" && aDistribution != "volume" ) | |
6504 | { | |
23fe70ec | 6505 | Message::SendFail ("Syntax error: wrong arguments. See usage:"); |
d33222c1 | 6506 | theDI.PrintHelp (theArgs[0]); |
6507 | return 1; | |
6508 | } | |
6509 | Standard_Boolean isSurface = aDistribution == "surface"; | |
6510 | ||
6511 | gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ); | |
6512 | ||
737e9a8d | 6513 | anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, aFlags); |
d33222c1 | 6514 | for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt) |
6515 | { | |
6516 | Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI; | |
6517 | Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI; | |
6518 | Standard_Real aDistance = isSurface ? | |
6519 | aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius; | |
6520 | ||
6521 | gp_Dir aDir (Cos (anAlpha) * Sin (aBeta), | |
6522 | Sin (anAlpha), | |
6523 | Cos (anAlpha) * Cos (aBeta)); | |
6524 | gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance); | |
6525 | ||
6526 | const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint); | |
6527 | if (toRandColors) | |
6528 | { | |
6529 | Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints), | |
6530 | 1.0, 0.5, Quantity_TOC_HLS); | |
6531 | anArrayPoints->SetVertexColor (anIndexOfPoint, aColor); | |
6532 | } | |
6533 | ||
6534 | if (hasNormals) | |
6535 | { | |
6536 | anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir); | |
6537 | } | |
737e9a8d | 6538 | if (hasUV) |
6539 | { | |
6540 | anArrayPoints->SetVertexTexel (anIndexOfPoint, gp_Pnt2d (anAlpha / 2.0 * M_PI, | |
6541 | aBeta / 2.0 * M_PI)); | |
6542 | } | |
d33222c1 | 6543 | } |
6544 | } | |
6545 | ||
6546 | // set array of points in point cloud object | |
6547 | Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud(); | |
6548 | aPointCloud->SetPoints (anArrayPoints); | |
6549 | VDisplayAISObject (aName, aPointCloud); | |
6550 | return 0; | |
6551 | } | |
6552 | ||
a0c20252 | 6553 | //======================================================================= |
6554 | //function : VPriority | |
6555 | //purpose : Prints or sets the display priority for an object | |
6556 | //======================================================================= | |
6557 | ||
6558 | static int VPriority (Draw_Interpretor& theDI, | |
6559 | Standard_Integer theArgNum, | |
6560 | const char** theArgs) | |
6561 | { | |
6562 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6563 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); | |
6564 | if (aContext.IsNull()) | |
6565 | { | |
23fe70ec | 6566 | Message::SendFail ("Error: no active viewer"); |
a0c20252 | 6567 | return 1; |
6568 | } | |
6569 | ||
6570 | TCollection_AsciiString aLastArg (theArgs[theArgNum - 1]); | |
6571 | Standard_Integer aPriority = -1; | |
6572 | Standard_Integer aNbArgs = theArgNum; | |
6573 | if (aLastArg.IsIntegerValue()) | |
6574 | { | |
6575 | aPriority = aLastArg.IntegerValue(); | |
6576 | --aNbArgs; | |
6577 | if (aPriority < 0 || aPriority > 10) | |
6578 | { | |
23fe70ec | 6579 | Message::SendFail() << "Syntax error: the specified display priority value '" << aLastArg |
6580 | << "' is outside the valid range [0..10]"; | |
a0c20252 | 6581 | return 1; |
6582 | } | |
6583 | } | |
6584 | else | |
6585 | { | |
6586 | anUpdateTool.Invalidate(); | |
6587 | } | |
6588 | ||
6589 | if (aNbArgs < 2) | |
6590 | { | |
23fe70ec | 6591 | Message::SendFail ("Syntax error: wrong number of arguments! See usage:"); |
a0c20252 | 6592 | theDI.PrintHelp (theArgs[0]); |
6593 | return 1; | |
6594 | } | |
6595 | ||
6596 | for (Standard_Integer anArgIter = 1; anArgIter < aNbArgs; ++anArgIter) | |
6597 | { | |
6598 | if (anUpdateTool.parseRedrawMode (theArgs[anArgIter])) | |
6599 | { | |
6600 | continue; | |
6601 | } | |
6602 | ||
6603 | TCollection_AsciiString aName (theArgs[anArgIter]); | |
6604 | Handle(AIS_InteractiveObject) anIObj; | |
8f521168 | 6605 | GetMapOfAIS().Find2 (aName, anIObj); |
a0c20252 | 6606 | if (anIObj.IsNull()) |
6607 | { | |
23fe70ec | 6608 | Message::SendFail() << "Error: the object '" << theArgs[1] << "' is not displayed"; |
a0c20252 | 6609 | return 1; |
6610 | } | |
6611 | ||
6612 | if (aPriority < 1) | |
6613 | { | |
6614 | theDI << aContext->DisplayPriority (anIObj) << " "; | |
6615 | } | |
6616 | else | |
6617 | { | |
6618 | aContext->SetDisplayPriority (anIObj, aPriority); | |
6619 | } | |
6620 | } | |
6621 | return 0; | |
6622 | } | |
6623 | ||
68ef63f9 | 6624 | //! Auxiliary class for command vnormals. |
6625 | class MyShapeWithNormals : public AIS_Shape | |
6626 | { | |
6627 | DEFINE_STANDARD_RTTI_INLINE(MyShapeWithNormals, AIS_Shape); | |
6628 | public: | |
6629 | ||
6630 | Standard_Real NormalLength; | |
6631 | Standard_Integer NbAlongU; | |
6632 | Standard_Integer NbAlongV; | |
6633 | Standard_Boolean ToUseMesh; | |
6634 | Standard_Boolean ToOrient; | |
6635 | ||
6636 | public: | |
6637 | ||
6638 | //! Main constructor. | |
6639 | MyShapeWithNormals (const TopoDS_Shape& theShape) | |
6640 | : AIS_Shape (theShape), | |
6641 | NormalLength(10), | |
6642 | NbAlongU (1), | |
6643 | NbAlongV (1), | |
6644 | ToUseMesh (Standard_False), | |
6645 | ToOrient (Standard_False) {} | |
6646 | ||
6647 | protected: | |
6648 | ||
6649 | //! Comnpute presentation. | |
6650 | virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, | |
6651 | const Handle(Prs3d_Presentation)& thePrs, | |
6652 | const Standard_Integer theMode) Standard_OVERRIDE | |
6653 | { | |
6654 | AIS_Shape::Compute (thePrsMgr, thePrs, theMode); | |
6655 | ||
6656 | NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormalMap; | |
6657 | if (ToUseMesh) | |
6658 | { | |
6659 | DBRep_DrawableShape::addMeshNormals (aNormalMap, myshape, NormalLength); | |
6660 | } | |
6661 | else | |
6662 | { | |
6663 | DBRep_DrawableShape::addSurfaceNormals (aNormalMap, myshape, NormalLength, NbAlongU, NbAlongV); | |
6664 | } | |
6665 | ||
d6c48921 | 6666 | Handle(Graphic3d_Group) aPrsGroup = thePrs->NewGroup(); |
68ef63f9 | 6667 | aPrsGroup->SetGroupPrimitivesAspect (myDrawer->ArrowAspect()->Aspect()); |
6668 | ||
6669 | const Standard_Real aArrowAngle = myDrawer->ArrowAspect()->Angle(); | |
6670 | const Standard_Real aArrowLength = myDrawer->ArrowAspect()->Length(); | |
6671 | for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormalMap); | |
6672 | aFaceIt.More(); aFaceIt.Next()) | |
6673 | { | |
6674 | const Standard_Boolean toReverse = ToOrient && aFaceIt.Key().Orientation() == TopAbs_REVERSED; | |
6675 | Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (2 * aFaceIt.Value().Size()); | |
6676 | for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aPntIt (aFaceIt.Value()); aPntIt.More(); aPntIt.Next()) | |
6677 | { | |
6678 | std::pair<gp_Pnt, gp_Pnt> aPair = aPntIt.Value(); | |
6679 | if (toReverse) | |
6680 | { | |
6681 | const gp_Vec aDir = aPair.first.XYZ() - aPair.second.XYZ(); | |
6682 | aPair.second = aPair.first.XYZ() + aDir.XYZ(); | |
6683 | } | |
6684 | ||
6685 | aSegments->AddVertex (aPair.first); | |
6686 | aSegments->AddVertex (aPair.second); | |
6687 | Prs3d_Arrow::Draw (aPrsGroup, aPair.second, gp_Vec(aPair.first, aPair.second), aArrowAngle, aArrowLength); | |
6688 | } | |
6689 | ||
6690 | aPrsGroup->AddPrimitiveArray (aSegments); | |
6691 | } | |
6692 | } | |
6693 | ||
6694 | }; | |
6695 | ||
6696 | //======================================================================= | |
6697 | //function : VNormals | |
6698 | //purpose : Displays/Hides normals calculated on shape geometry or retrieved from triangulation | |
6699 | //======================================================================= | |
6700 | static int VNormals (Draw_Interpretor& theDI, | |
6701 | Standard_Integer theArgNum, | |
6702 | const char** theArgs) | |
6703 | { | |
6704 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
6705 | if (aContext.IsNull()) | |
6706 | { | |
23fe70ec | 6707 | Message::SendFail ("Error: no active viewer"); |
68ef63f9 | 6708 | return 1; |
6709 | } | |
6710 | else if (theArgNum < 2) | |
6711 | { | |
23fe70ec | 6712 | Message::SendFail ("Syntax error: wrong number of arguments. See usage:"); |
68ef63f9 | 6713 | theDI.PrintHelp (theArgs[0]); |
6714 | return 1; | |
6715 | } | |
6716 | ||
6717 | Standard_Integer anArgIter = 1; | |
6718 | Standard_CString aShapeName = theArgs[anArgIter++]; | |
6719 | TopoDS_Shape aShape = DBRep::Get (aShapeName); | |
6720 | Standard_Boolean isOn = Standard_True; | |
6721 | if (aShape.IsNull()) | |
6722 | { | |
23fe70ec | 6723 | Message::SendFail() << "Error: shape with name '" << aShapeName << "' is not found"; |
68ef63f9 | 6724 | return 1; |
6725 | } | |
6726 | ||
6727 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
6728 | Handle(MyShapeWithNormals) aShapePrs; | |
6729 | if (aMap.IsBound2 (aShapeName)) | |
6730 | { | |
6731 | aShapePrs = Handle(MyShapeWithNormals)::DownCast (aMap.Find2 (aShapeName)); | |
6732 | } | |
6733 | ||
6734 | Standard_Boolean isUseMesh = Standard_False; | |
6735 | Standard_Real aLength = 10.0; | |
6736 | Standard_Integer aNbAlongU = 1, aNbAlongV = 1; | |
6737 | Standard_Boolean isOriented = Standard_False; | |
6738 | for (; anArgIter < theArgNum; ++anArgIter) | |
6739 | { | |
6740 | TCollection_AsciiString aParam (theArgs[anArgIter]); | |
6741 | aParam.LowerCase(); | |
6742 | if (anArgIter == 2 | |
dae2a922 | 6743 | && Draw::ParseOnOff (aParam.ToCString(), isOn)) |
68ef63f9 | 6744 | { |
6745 | continue; | |
6746 | } | |
6747 | else if (aParam == "-usemesh" | |
6748 | || aParam == "-mesh") | |
6749 | { | |
6750 | isUseMesh = Standard_True; | |
6751 | } | |
6752 | else if (aParam == "-length" | |
6753 | || aParam == "-len") | |
6754 | { | |
6755 | ++anArgIter; | |
6756 | aLength = anArgIter < theArgNum ? Draw::Atof (theArgs[anArgIter]) : 0.0; | |
6757 | if (Abs (aLength) <= gp::Resolution()) | |
6758 | { | |
23fe70ec | 6759 | Message::SendFail ("Syntax error: length should not be zero"); |
68ef63f9 | 6760 | return 1; |
6761 | } | |
6762 | } | |
6763 | else if (aParam == "-orient" | |
6764 | || aParam == "-oriented") | |
6765 | { | |
6766 | isOriented = Standard_True; | |
6767 | if (anArgIter + 1 < theArgNum | |
dae2a922 | 6768 | && Draw::ParseOnOff (theArgs[anArgIter + 1], isOriented)) |
68ef63f9 | 6769 | { |
6770 | ++anArgIter; | |
6771 | } | |
6772 | } | |
6773 | else if (aParam == "-nbalongu" | |
6774 | || aParam == "-nbu") | |
6775 | { | |
6776 | ++anArgIter; | |
6777 | aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
6778 | if (aNbAlongU < 1) | |
6779 | { | |
23fe70ec | 6780 | Message::SendFail ("Syntax error: NbAlongU should be >=1"); |
68ef63f9 | 6781 | return 1; |
6782 | } | |
6783 | } | |
6784 | else if (aParam == "-nbalongv" | |
6785 | || aParam == "-nbv") | |
6786 | { | |
6787 | ++anArgIter; | |
6788 | aNbAlongV = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
6789 | if (aNbAlongV < 1) | |
6790 | { | |
23fe70ec | 6791 | Message::SendFail ("Syntax error: NbAlongV should be >=1"); |
68ef63f9 | 6792 | return 1; |
6793 | } | |
6794 | } | |
6795 | else if (aParam == "-nbalong" | |
6796 | || aParam == "-nbuv") | |
6797 | { | |
6798 | ++anArgIter; | |
6799 | aNbAlongU = anArgIter < theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
6800 | aNbAlongV = aNbAlongU; | |
6801 | if (aNbAlongU < 1) | |
6802 | { | |
23fe70ec | 6803 | Message::SendFail ("Syntax error: NbAlong should be >=1"); |
68ef63f9 | 6804 | return 1; |
6805 | } | |
6806 | } | |
6807 | else | |
6808 | { | |
23fe70ec | 6809 | Message::SendFail() << "Syntax error: unknown argument '" << aParam << "'"; |
68ef63f9 | 6810 | return 1; |
6811 | } | |
6812 | } | |
6813 | ||
6814 | if (isOn) | |
6815 | { | |
6816 | if (aShapePrs.IsNull()) | |
6817 | { | |
6818 | aShapePrs = new MyShapeWithNormals (aShape); | |
6819 | } | |
6820 | aShapePrs->ToUseMesh = isUseMesh; | |
6821 | aShapePrs->ToOrient = isOriented; | |
6822 | aShapePrs->NormalLength = aLength; | |
6823 | aShapePrs->NbAlongU = aNbAlongU; | |
6824 | aShapePrs->NbAlongV = aNbAlongV; | |
6825 | VDisplayAISObject (aShapeName, aShapePrs); | |
6826 | } | |
6827 | else if (!aShapePrs.IsNull()) | |
6828 | { | |
6829 | VDisplayAISObject (aShapeName, new AIS_Shape (aShape)); | |
6830 | } | |
6831 | ||
6832 | return 0; | |
6833 | } | |
6834 | ||
7fd59977 | 6835 | //======================================================================= |
6836 | //function : ObjectsCommands | |
161c4476 | 6837 | //purpose : |
7fd59977 | 6838 | //======================================================================= |
6839 | ||
6840 | void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) | |
6841 | { | |
6842 | const char *group ="AISObjects"; | |
bc001a40 | 6843 | |
6844 | theCommands.Add ("vtrihedron", | |
6845 | "vtrihedron : vtrihedron name" | |
6846 | "\n\t\t: [-dispMode {wireframe|shading} ]" | |
6847 | "\n\t\t: [-origin x y z ]" | |
6848 | "\n\t\t: [-zaxis u v w -xaxis u v w ]" | |
fae1ae11 ZA |
6849 | "\n\t\t: [-drawAxes {X|Y|Z|XY|YZ|XZ|XYZ}]" |
6850 | "\n\t\t: [-hideLabels {on|off}]" | |
6851 | "\n\t\t: [-hideArrows {on|off}]" | |
bc001a40 | 6852 | "\n\t\t: [-label {XAxis|YAxis|ZAxis} value]" |
6853 | "\n\t\t: [-attribute {XAxisLength|YAxisLength|ZAxisLength" | |
6854 | "\n\t\t: |TubeRadiusPercent|ConeRadiusPercent" | |
6855 | "\n\t\t: |ConeLengthPercent|OriginRadiusPercent" | |
6856 | "\n\t\t: |ShadingNumberOfFacettes} value]" | |
6857 | "\n\t\t: [-color {Origin|XAxis|YAxis|ZAxis|XOYAxis|YOZAxis" | |
6858 | "\n\t\t: |XOZAxis|Whole} {r g b | colorName}]" | |
fae1ae11 ZA |
6859 | "\n\t\t: [-textColor {r g b | colorName}]" |
6860 | "\n\t\t: [-arrowColor {r g b | colorName}]" | |
bc001a40 | 6861 | "\n\t\t: [-priority {Origin|XAxis|YAxis|ZAxis|XArrow" |
6862 | "\n\t\t: |YArrow|ZArrow|XOYAxis|YOZAxis" | |
6863 | "\n\t\t: |XOZAxis|Whole} value]" | |
6864 | "\n\t\t:" | |
6865 | "\n\t\t: Creates a new *AIS_Trihedron* object or changes parameters of " | |
6866 | "\n\t\t: existing trihedron. If no argument is set," | |
6867 | "\n\t\t: the default trihedron (0XYZ) is created." | |
6868 | "\n\t\t: -dispMode mode of visualization: wf - wireframe," | |
6869 | "\n\t\t: sh - shading." | |
6870 | "\n\t\t: Default value is wireframe." | |
6871 | "\n\t\t: -origin allows to set trihedron location." | |
6872 | "\n\t\t: -zaxis/-xaxis allows to set trihedron X and Z" | |
6873 | "\n\t\t: directions. The directions should" | |
6874 | "\n\t\t: be orthogonal. Y direction is calculated." | |
fae1ae11 | 6875 | "\n\t\t: -drawAxes allows to set what axes are drawn in the" |
bc001a40 | 6876 | "\n\t\t: trihedron, default state is XYZ" |
fae1ae11 ZA |
6877 | "\n\t\t: -hideLabels allows to show/hide trihedron labels" |
6878 | "\n\t\t: -hideArrows allows to show/hide trihedron arrows" | |
169c944c | 6879 | "\n\t\t: -label allows to change default X/Y/Z titles of axes" |
bc001a40 | 6880 | "\n\t\t: -attribute sets parameters of trihedron" |
6881 | "\n\t\t: -color sets color properties of parts of trihedron" | |
fae1ae11 ZA |
6882 | "\n\t\t: -textColor sets color properties of trihedron labels" |
6883 | "\n\t\t: -arrowColor sets color properties of trihedron arrows" | |
bc001a40 | 6884 | "\n\t\t: -priority allows to change default selection priority" |
6885 | "\n\t\t: of trihedron components", | |
6886 | __FILE__,VTrihedron,group); | |
7fd59977 | 6887 | |
161c4476 | 6888 | theCommands.Add("vtri2d", |
faea8b40 | 6889 | "vtri2d Name" |
6890 | "\n\t\t: Creates a plane with a 2D trihedron from an interactively selected face.", | |
7fd59977 | 6891 | __FILE__,VTrihedron2D ,group); |
6892 | ||
161c4476 | 6893 | theCommands.Add("vplanetri", |
faea8b40 | 6894 | "vplanetri name" |
6895 | "\n\t\t: Create a plane from a trihedron selection. If no arguments are set, the default", | |
7fd59977 | 6896 | __FILE__,VPlaneTrihedron ,group); |
6897 | ||
6898 | theCommands.Add("vsize", | |
faea8b40 | 6899 | "vsize : vsize [name(Default=Current)] [size(Default=100)] " |
6900 | "\n\t\t: Changes the size of a named or selected trihedron." | |
6901 | "\n\t\t: If the name is not defined: it affects the selected trihedrons otherwise nothing is done." | |
6902 | "\n\t\t: If the value is not defined: it is set to 100 by default.", | |
7fd59977 | 6903 | __FILE__,VSize,group); |
6904 | ||
6905 | theCommands.Add("vaxis", | |
faea8b40 | 6906 | "vaxis name [Xa] [Ya] [Za] [Xb] [Yb] [Zb]" |
6907 | "\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 | 6908 | __FILE__,VAxisBuilder,group); |
6909 | ||
161c4476 | 6910 | theCommands.Add("vaxispara", |
faea8b40 | 6911 | "vaxispara name " |
6912 | "\n\t\t: Creates an axis by interactive selection of an edge and a vertex.", | |
7fd59977 | 6913 | __FILE__,VAxisBuilder,group); |
6914 | ||
6915 | theCommands.Add("vaxisortho", | |
faea8b40 | 6916 | "vaxisortho name " |
6917 | "\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 | 6918 | __FILE__,VAxisBuilder,group); |
6919 | ||
6920 | theCommands.Add("vpoint", | |
2ff1d580 | 6921 | "vpoint name [X Y [Z]] [-2d] [-nosel]" |
6922 | "\n\t\t: Creates a point from coordinates." | |
6923 | "\n\t\t: If the values are not defined, a point is created from selected vertex or edge (center)." | |
6924 | "\n\t\t: -2d defines on-screen 2D point from top-left window corner" | |
6925 | "\n\t\t: -nosel creates non-selectable presentation", | |
7fd59977 | 6926 | __FILE__,VPointBuilder,group); |
6927 | ||
6928 | theCommands.Add("vplane", | |
faea8b40 | 6929 | "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity {0|1}]" |
6930 | "\n\t\t: Creates a plane from named or interactively selected entities." | |
6931 | "\n\t\t: TypeOfSensitivity:" | |
6932 | "\n\t\t: 0 - Interior" | |
6933 | "\n\t\t: 1 - Boundary", | |
7fd59977 | 6934 | __FILE__,VPlaneBuilder,group); |
6935 | ||
f3889691 | 6936 | theCommands.Add ("vchangeplane", "vchangeplane usage: \n" |
6937 | " vchangeplane <plane_name>" | |
6938 | " [x=center_x y=center_y z=center_z]" | |
6939 | " [dx=dir_x dy=dir_y dz=dir_z]" | |
6940 | " [sx=size_x sy=size_y]" | |
6941 | " [noupdate]\n" | |
6942 | " - changes parameters of the plane:\n" | |
6943 | " - x y z - center\n" | |
6944 | " - dx dy dz - normal\n" | |
6945 | " - sx sy - plane sizes\n" | |
6946 | " - noupdate - do not update/redisplay the plane in context\n" | |
6947 | " Please enter coordinates in format \"param=value\" in arbitrary order.", | |
6948 | __FILE__, VChangePlane, group); | |
6949 | ||
7fd59977 | 6950 | theCommands.Add("vplanepara", |
faea8b40 | 6951 | "vplanepara PlaneName " |
6952 | "\n\t\t: Creates a plane from interactively selected vertex and face.", | |
7fd59977 | 6953 | __FILE__,VPlaneBuilder,group); |
6954 | ||
6955 | theCommands.Add("vplaneortho", | |
faea8b40 | 6956 | "vplaneortho PlaneName " |
6957 | "\n\t\t: Creates a plane from interactive selected face and coplanar edge. ", | |
7fd59977 | 6958 | __FILE__,VPlaneBuilder,group); |
6959 | ||
161c4476 | 6960 | theCommands.Add("vline", |
faea8b40 | 6961 | "vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] " |
6962 | "\n\t\t: Creates a line from coordinates, named or interactively selected vertices. ", | |
7fd59977 | 6963 | __FILE__,VLineBuilder,group); |
6964 | ||
6965 | theCommands.Add("vcircle", | |
faea8b40 | 6966 | "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]" |
6967 | "\n\t\t: Creates a circle from named or interactively selected entities." | |
6968 | "\n\t\t: Parameter IsFilled is defined as 0 or 1.", | |
7fd59977 | 6969 | __FILE__,VCircleBuilder,group); |
6970 | ||
29e2c6d2 | 6971 | theCommands.Add ("vdrawtext", |
6972 | "vdrawtext name text" | |
6973 | "\n\t\t: [-pos X=0 Y=0 Z=0]" | |
6974 | "\n\t\t: [-color {R G B|name}=yellow]" | |
6975 | "\n\t\t: [-halign {left|center|right}=left]" | |
ac84fcf6 | 6976 | "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]" |
29e2c6d2 | 6977 | "\n\t\t: [-angle angle=0]" |
6978 | "\n\t\t: [-zoom {0|1}=0]" | |
6979 | "\n\t\t: [-height height=16]" | |
60f7b225 | 6980 | "\n\t\t: [-wrapping width=40]" |
5b377041 | 6981 | "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]" |
29e2c6d2 | 6982 | "\n\t\t: [-font font=Times]" |
61b0191c | 6983 | "\n\t\t: [-2d]" |
6984 | "\n\t\t: [-perspos {X Y Z}=0 0 0], where" | |
6985 | "\n\t\t X and Y define the coordinate origin in 2d space relative to the view window" | |
6986 | "\n\t\t Example: X=0 Y=0 is center, X=1 Y=1 is upper right corner etc..." | |
6987 | "\n\t\t Z coordinate defines the gap from border of view window (except center position)." | |
3cbd0a8e | 6988 | "\n\t\t: [-disptype {blend|decal|shadow|subtitle|dimension|normal}=normal}" |
61b0191c | 6989 | "\n\t\t: [-subcolor {R G B|name}=white]" |
29e2c6d2 | 6990 | "\n\t\t: [-noupdate]" |
ce01ec26 | 6991 | "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]" |
3f1eb0ab | 6992 | "\n\t\t: [-flipping]" |
ab9e277f | 6993 | "\n\t\t: [-ownanchor {0|1}=1]" |
29e2c6d2 | 6994 | "\n\t\t: Display text label at specified position.", |
6995 | __FILE__, VDrawText, group); | |
7fd59977 | 6996 | |
6997 | theCommands.Add("vdrawsphere", | |
b7cd4ba7 | 6998 | "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n", |
7fd59977 | 6999 | __FILE__,VDrawSphere,group); |
7000 | ||
1beb58d7 | 7001 | theCommands.Add ("vlocation", |
7002 | "vlocation name" | |
dbc8becf | 7003 | "\n\t\t: [-reset] [-copyFrom otherName]" |
7004 | "\n\t\t: [-translate X Y [Z]] [-rotate x y z dx dy dz angle] [-scale [X Y Z] scale]" | |
7005 | "\n\t\t: [-pretranslate X Y [Z]] [-prerotate x y z dx dy dz angle] [-prescale [X Y Z] scale]" | |
7006 | "\n\t\t: [-mirror x y z dx dy dz] [-premirror x y z dx dy dz]" | |
7007 | "\n\t\t: [-setLocation X Y [Z]] [-setRotation QX QY QZ QW] [-setScale [X Y Z] scale]" | |
1beb58d7 | 7008 | "\n\t\t: Object local transformation management:" |
dbc8becf | 7009 | "\n\t\t: -reset resets transformation to identity" |
7010 | "\n\t\t: -translate applies translation vector" | |
7011 | "\n\t\t: -rotate applies rotation around axis" | |
7012 | "\n\t\t: -scale applies scale factor with optional anchor" | |
7013 | "\n\t\t: -mirror applies mirror transformation" | |
7014 | "\n\t\t: -pretranslate pre-multiplies translation vector" | |
7015 | "\n\t\t: -prerotate pre-multiplies rotation around axis" | |
7016 | "\n\t\t: -prescale pre-multiplies scale transformation" | |
7017 | "\n\t\t: -premirror pre-multiplies mirror transformation" | |
7018 | "\n\t\t: -setLocation overrides translation part" | |
7019 | "\n\t\t: -setRotation overrides rotation part with specified quaternion" | |
7020 | "\n\t\t: -setScale overrides scale factor", | |
1beb58d7 | 7021 | __FILE__, VSetLocation, group); |
29d43f9c | 7022 | theCommands.Add ("vsetlocation", |
1beb58d7 | 7023 | "alias for vlocation", |
29d43f9c | 7024 | __FILE__, VSetLocation, group); |
245cbf94 | 7025 | theCommands.Add ("vchild", |
52c38ce1 | 7026 | "vchild parent [-add] [-remove] [-ignoreParentTrsf {0|1}] child1 [child2] [...]" |
245cbf94 | 7027 | "\n\t\t: Command for testing low-level presentation connections." |
7028 | "\n\t\t: vconnect command should be used instead.", | |
7029 | __FILE__, VChild, group); | |
0d56f743 | 7030 | theCommands.Add("vparent", |
7031 | "vparent parent [-ignoreVisu]" | |
7032 | "\n\t\t: Command for testing object properties as parent in the hierarchy." | |
7033 | "\n\t\t: Arguments:" | |
7034 | "\n\t\t: -ignoreVisu do not propagate the visual state (display/erase/color) to children objects", | |
7035 | __FILE__, VParent, group); | |
c60ec7f5 | 7036 | theCommands.Add ("vcomputehlr", |
7037 | "vcomputehlr shapeInput hlrResult [-algoType {algo|polyAlgo}=polyAlgo]" | |
7038 | "\n\t\t: [eyeX eyeY eyeZ dirX dirY dirZ upX upY upZ]" | |
7039 | "\n\t\t: [-showTangentEdges {on|off}=off] [-nbIsolines N=0] [-showHiddenEdges {on|off}=off]" | |
7040 | "\n\t\t: Arguments:" | |
7041 | "\n\t\t: shapeInput - name of the initial shape" | |
7042 | "\n\t\t: hlrResult - result HLR object from initial shape" | |
7043 | "\n\t\t: eye, dir are eye position and look direction" | |
7044 | "\n\t\t: up is the look up direction vector" | |
7045 | "\n\t\t: -algoType HLR algorithm to use" | |
7046 | "\n\t\t: -showTangentEdges include tangent edges" | |
7047 | "\n\t\t: -nbIsolines include isolines" | |
7048 | "\n\t\t: -showHiddenEdges include hidden edges" | |
7049 | "\n\t\t: Use vtop to see projected HLR shape.", | |
3fc57801 | 7050 | __FILE__, VComputeHLR, group); |
7051 | ||
9558a876 | 7052 | theCommands.Add("vdrawparray", |
4a056d20 | 7053 | "vdrawparray name TypeOfArray={points|segments|polylines|triangles" |
7054 | "\n\t\t: |trianglefans|trianglestrips|quads|quadstrips|polygons}" | |
da87ddc3 | 7055 | "\n\t\t: [-deinterleaved|-mutable]" |
4a056d20 | 7056 | "\n\t\t: [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]" |
7057 | "\n\t\t: [bound= {'b' nbVertices [bound_color={'c' r g b}]]" | |
7058 | "\n\t\t: [edge= {'e' vertexId]" | |
da87ddc3 | 7059 | "\n\t\t: [-shape shapeName] [-patch]" |
4a056d20 | 7060 | "\n\t\t: Commands create an Interactive Object for specified Primitive Array definition (Graphic3d_ArrayOfPrimitives)" |
7061 | "\n\t\t: with the main purpose is covering various combinations by tests", | |
9558a876 | 7062 | __FILE__,VDrawPArray,group); |
ac04d101 SA |
7063 | |
7064 | theCommands.Add("vconnect", | |
faea8b40 | 7065 | "vconnect name Xo Yo Zo object1 object2 ... [color=NAME]" |
7066 | "\n\t\t: Creates and displays AIS_ConnectedInteractive object from input object and location.", | |
ac04d101 SA |
7067 | __FILE__, VConnect, group); |
7068 | ||
0717ddc1 | 7069 | theCommands.Add("vconnectto", |
d4aaad5b | 7070 | "vconnectto : instance_name Xo Yo Zo object [-nodisplay|-noupdate|-update]" |
f751596e | 7071 | " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo)." |
7072 | "\n\t\t: -nodisplay - only creates interactive object, but not displays it", | |
0717ddc1 | 7073 | __FILE__, VConnectTo,group); |
7074 | ||
7075 | theCommands.Add("vdisconnect", | |
7076 | "vdisconnect assembly_name (object_name | object_number | 'all')" | |
7077 | " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).", | |
7078 | __FILE__,VDisconnect,group); | |
7079 | ||
7080 | theCommands.Add("vaddconnected", | |
7081 | "vaddconnected assembly_name object_name" | |
7082 | "Adds object to assembly.", | |
7083 | __FILE__,VAddConnected,group); | |
7084 | ||
7085 | theCommands.Add("vlistconnected", | |
7086 | "vlistconnected assembly_name" | |
7087 | "Lists objects in assembly.", | |
7088 | __FILE__,VListConnected,group); | |
7089 | ||
ac04d101 SA |
7090 | |
7091 | theCommands.Add("vselmode", | |
f47849f4 | 7092 | "vselmode [object] selectionMode {on|off}" |
7093 | "\n\t\t: [{-add|-set|-globalOrLocal}=-globalOrLocal]" | |
7094 | "\n\t\t: Switches selection mode for the specified object or for all objects in context." | |
7095 | "\n\t\t: Selection mode is either an integer number specific to Interactive Object," | |
7096 | "\n\t\t: or sub-shape type in case of AIS_Shape:" | |
7097 | "\n\t\t: Shape, Vertex, Edge, Wire, Face, Shell, Solid, CompSolid, Compound" | |
7098 | "\n\t\t: The integer mode 0 (Shape in case of AIS_Shape) is reserved for selecting object as whole." | |
7099 | "\n\t\t: Additional options:" | |
7100 | "\n\t\t: -add already activated selection modes will be left activated" | |
7101 | "\n\t\t: -set already activated selection modes will be deactivated" | |
7102 | "\n\t\t: -globalOrLocal (default) if new mode is Global selection mode," | |
7103 | "\n\t\t: then active local selection modes will be deactivated" | |
7104 | "\n\t\t: and the samthen active local selection modes will be deactivated", | |
ac04d101 | 7105 | __FILE__, VSetSelectionMode, group); |
ceae62f0 | 7106 | |
4ca4bbe8 | 7107 | theCommands.Add("vselnext", |
7108 | "vselnext : hilight next detected", | |
7109 | __FILE__, VSelectionNext, group); | |
7110 | ||
7111 | theCommands.Add("vselprev", | |
7112 | "vselnext : hilight previous detected", | |
7113 | __FILE__, VSelectionPrevious, group); | |
7114 | ||
ceae62f0 | 7115 | theCommands.Add("vtriangle", |
faea8b40 | 7116 | "vtriangle Name PointName PointName PointName" |
7117 | "\n\t\t: Creates and displays a filled triangle from named points.", | |
ceae62f0 A |
7118 | __FILE__, VTriangle,group); |
7119 | ||
7120 | theCommands.Add("vsegment", | |
faea8b40 | 7121 | "vsegment Name PointName PointName" |
7122 | "\n\t\t: Creates and displays a segment from named points.", | |
9427bc1d | 7123 | __FILE__, VTriangle,group); |
59f45b7c | 7124 | |
113bda70 | 7125 | theCommands.Add ("vtorus", |
6eeb528c | 7126 | "vtorus name [R1 R2 [Angle1=0 Angle2=360] [Angle=360]]" |
7127 | "\n\t\t: [-radius R1] [-pipeRadius R2]" | |
7128 | "\n\t\t: [-pipeAngle Angle=360] [-segmentAngle1 Angle1=0 -segmentAngle2 Angle2=360]" | |
7129 | "\n\t\t: [-nbSlices Number=100] [-nbStacks Number=100] [-noupdate]" | |
113bda70 | 7130 | "\n\t\t: Creates and displays a torus or torus segment." |
7131 | "\n\t\t: Parameters of the torus :" | |
7132 | "\n\t\t: - R1 distance from the center of the pipe to the center of the torus" | |
7133 | "\n\t\t: - R2 radius of the pipe" | |
6eeb528c | 7134 | "\n\t\t: - Angle1 first angle to create a torus ring segment" |
7135 | "\n\t\t: - Angle2 second angle to create a torus ring segment" | |
7136 | "\n\t\t: - Angle angle to create a torus pipe segment", | |
113bda70 | 7137 | __FILE__, VTorus, group); |
7138 | ||
7139 | theCommands.Add ("vcylinder", | |
6eeb528c | 7140 | "vcylinder name [R1 R2 Height] [-height H] [-radius R] [-bottomRadius R1 -topRadius R2]" |
7141 | "\n\t\t: [-nbSlices Number=100] [-noupdate]" | |
113bda70 | 7142 | "\n\t\t: Creates and displays a cylinder." |
7143 | "\n\t\t: Parameters of the cylinder :" | |
7144 | "\n\t\t: - R1 cylinder bottom radius" | |
7145 | "\n\t\t: - R2 cylinder top radius" | |
6eeb528c | 7146 | "\n\t\t: - Height cylinder height", |
113bda70 | 7147 | __FILE__, VCylinder, group); |
7148 | ||
7149 | theCommands.Add ("vsphere", | |
6eeb528c | 7150 | "vsphere name [-radius] R" |
7151 | "\n\t\t: [-nbSlices Number=100] [-nbStacks Number=100] [-noupdate]" | |
113bda70 | 7152 | "\n\t\t: Creates and displays a sphere.", |
7153 | __FILE__, VSphere, group); | |
7154 | ||
59f45b7c | 7155 | theCommands.Add("vobjzlayer", |
7156 | "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object", | |
7157 | __FILE__, VObjZLayer, group); | |
3ddebf91 | 7158 | |
7159 | theCommands.Add("vpolygonoffset", | |
7160 | "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values", | |
7161 | __FILE__, VPolygonOffset, group); | |
a2d5ab2e | 7162 | |
a577aaab | 7163 | theCommands.Add ("vmarkerstest", |
7164 | "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n", | |
7165 | __FILE__, VMarkersTest, group); | |
b514beda | 7166 | |
7167 | theCommands.Add ("text2brep", | |
ac84fcf6 | 7168 | "text2brep: name text" |
7169 | "\n\t\t: [-pos X=0 Y=0 Z=0]" | |
7170 | "\n\t\t: [-halign {left|center|right}=left]" | |
7171 | "\n\t\t: [-valign {top|center|bottom|topfirstline}=bottom}]" | |
7172 | "\n\t\t: [-height height=16]" | |
5b377041 | 7173 | "\n\t\t: [-aspect {regular|bold|italic|boldItalic}=regular]" |
1bbd7c79 | 7174 | "\n\t\t: [-font font=Courier] [-strict {strict|aliases|any}=any]" |
ac84fcf6 | 7175 | "\n\t\t: [-composite {on|off}=off]" |
7176 | "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]", | |
b514beda | 7177 | __FILE__, TextToBRep, group); |
725ef85e | 7178 | theCommands.Add ("vfont", |
5b377041 | 7179 | "vfont [-add pathToFont [fontName] [regular,bold,italic,boldItalic=undefined] [singleStroke]]" |
912761ea | 7180 | "\n\t\t: [-strict {any|aliases|strict}] [-find fontName [regular,bold,italic,boldItalic=undefined]] [-verbose {on|off}]" |
15e4e6a2 | 7181 | "\n\t\t: [-findAll fontNameMask] [-findInfo fontName]" |
36e28f96 | 7182 | "\n\t\t: [-unicodeFallback {on|off}]" |
15e4e6a2 | 7183 | "\n\t\t: [-clear] [-init] [-list] [-names]" |
f5e758d2 | 7184 | "\n\t\t: [-aliases [aliasName]] [-addAlias Alias FontName] [-removeAlias Alias FontName] [-clearAlias Alias] [-clearAliases]" |
15e4e6a2 | 7185 | "\n\t\t: Work with font registry - register font, list available fonts, find font." |
7186 | "\n\t\t: -findAll is same as -find, but can print more than one font when mask is passed." | |
7187 | "\n\t\t: -findInfo is same as -find, but prints complete font information instead of family name.", | |
725ef85e | 7188 | __FILE__, VFont, group); |
53b15292 | 7189 | |
7190 | theCommands.Add ("vvertexmode", | |
7191 | "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n" | |
7192 | "vvertexmode - prints the default vertex draw mode\n" | |
7193 | "vvertexmode name - prints the vertex draw mode of the given object\n" | |
7194 | "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n" | |
7195 | "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n", | |
7196 | __FILE__, VVertexMode, group); | |
d33222c1 | 7197 | |
7198 | theCommands.Add ("vpointcloud", | |
737e9a8d | 7199 | "vpointcloud name shape [-randColor] [-normals] [-noNormals] [-uv]" |
d33222c1 | 7200 | "\n\t\t: Create an interactive object for arbitary set of points" |
7201 | "\n\t\t: from triangulated shape." | |
7202 | "\n" | |
7203 | "vpointcloud name x y z r npts {surface|volume}\n" | |
737e9a8d | 7204 | " ... [-randColor] [-normals] [-noNormals] [-uv]" |
d33222c1 | 7205 | "\n\t\t: Create arbitrary set of points (npts) randomly distributed" |
7206 | "\n\t\t: on spheric surface or within spheric volume (x y z r)." | |
7207 | "\n\t\t:" | |
7208 | "\n\t\t: Additional options:" | |
7209 | "\n\t\t: -randColor - generate random color per point" | |
7210 | "\n\t\t: -normals - generate normal per point (default)" | |
7211 | "\n\t\t: -noNormals - do not generate normal per point" | |
7212 | "\n", | |
7213 | __FILE__, VPointCloud, group); | |
7d9e854b | 7214 | |
a0c20252 | 7215 | theCommands.Add("vpriority", |
7216 | "vpriority [-noupdate|-update] name [value]\n\t\t prints or sets the display priority for an object", | |
7217 | __FILE__, | |
7218 | VPriority, group); | |
68ef63f9 | 7219 | |
7220 | theCommands.Add ("vnormals", | |
7221 | "vnormals usage:\n" | |
7222 | "vnormals Shape [{on|off}=on] [-length {10}] [-nbAlongU {1}] [-nbAlongV {1}] [-nbAlong {1}]" | |
7223 | "\n\t\t: [-useMesh] [-oriented {0}1}=0]" | |
7224 | "\n\t\t: Displays/Hides normals calculated on shape geometry or retrieved from triangulation", | |
7225 | __FILE__, VNormals, group); | |
7fd59977 | 7226 | } |