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