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