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