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