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