0031848: [REGRESSION] Visualization - MoveTo() triggers exception "gp_Dir() - input...
[occt.git] / src / ViewerTest / ViewerTest_ObjectCommands.cxx
CommitLineData
b311480e 1// Created on: 1998-11-12
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17#include <ViewerTest.hxx>
18
bc001a40 19#include <AIS_PlaneTrihedron.hxx>
20
7fd59977 21#include <Quantity_NameOfColor.hxx>
22#include <Draw_Interpretor.hxx>
23#include <Draw.hxx>
24#include <Draw_Appli.hxx>
25#include <DBRep.hxx>
68ef63f9 26#include <DBRep_DrawableShape.hxx>
7fd59977 27
b514beda 28#include <Font_BRepFont.hxx>
ac84fcf6 29#include <Font_BRepTextBuilder.hxx>
725ef85e 30#include <Font_FontMgr.hxx>
23fe70ec 31#include <Message.hxx>
bc001a40 32#include <NCollection_List.hxx>
33
161c4476 34#include <OSD_Chronometer.hxx>
7fd59977 35#include <TCollection_AsciiString.hxx>
36#include <V3d_Viewer.hxx>
37#include <V3d_View.hxx>
38#include <V3d.hxx>
39
40#include <AIS_Shape.hxx>
41#include <AIS_DisplayMode.hxx>
d33222c1 42#include <AIS_PointCloud.hxx>
7fd59977 43#include <TColStd_MapOfInteger.hxx>
44#include <AIS_MapOfInteractive.hxx>
4e18052b 45#include <ViewerTest_AutoUpdater.hxx>
7fd59977 46#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
47#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
48#include <ViewerTest_EventManager.hxx>
49
50#include <TopoDS_Solid.hxx>
51#include <BRepTools.hxx>
52#include <BRep_Builder.hxx>
53#include <TopAbs_ShapeEnum.hxx>
54
55#include <TopoDS.hxx>
56#include <BRep_Tool.hxx>
57#include <TopExp_Explorer.hxx>
58
59#include <BRepAdaptor_Curve.hxx>
60#include <BRepAdaptor_Surface.hxx>
61
62#include <TopAbs.hxx>
63#include <TopExp.hxx>
64#include <TopoDS_Vertex.hxx>
65#include <TopoDS_Shape.hxx>
66#include <TopoDS_Face.hxx>
67
68#include <Draw_Window.hxx>
69#include <AIS_ListIteratorOfListOfInteractive.hxx>
70#include <AIS_ListOfInteractive.hxx>
c60ec7f5 71#include <AIS_ColoredShape.hxx>
7fd59977 72#include <AIS_DisplayMode.hxx>
73#include <AIS_Shape.hxx>
74
75#include <AIS_InteractiveContext.hxx>
76#include <Geom_Plane.hxx>
77#include <gp_Pln.hxx>
7fd59977 78#include <TCollection_ExtendedString.hxx>
725ef85e 79#include <TCollection_HAsciiString.hxx>
7fd59977 80#include <GC_MakePlane.hxx>
81#include <gp_Circ.hxx>
82#include <AIS_Axis.hxx>
83#include <Geom_Axis2Placement.hxx>
84#include <Geom_Axis1Placement.hxx>
85#include <AIS_Trihedron.hxx>
86#include <AIS_Axis.hxx>
29d43f9c 87#include <gp_Trsf.hxx>
1beb58d7 88#include <gp_Quaternion.hxx>
29d43f9c 89#include <TopLoc_Location.hxx>
3fc57801 90
91#include <HLRAlgo_Projector.hxx>
c60ec7f5 92#include <HLRBRep_Algo.hxx>
3fc57801 93#include <HLRBRep_PolyAlgo.hxx>
94#include <HLRBRep_PolyHLRToShape.hxx>
c60ec7f5 95#include <HLRBRep_HLRToShape.hxx>
3fc57801 96#include <Aspect_Window.hxx>
97
9558a876
A
98#include <Graphic3d_ArrayOfPoints.hxx>
99#include <Graphic3d_ArrayOfSegments.hxx>
100#include <Graphic3d_ArrayOfPolylines.hxx>
101#include <Graphic3d_ArrayOfTriangles.hxx>
102#include <Graphic3d_ArrayOfTriangleFans.hxx>
103#include <Graphic3d_ArrayOfTriangleStrips.hxx>
104#include <Graphic3d_ArrayOfQuadrangles.hxx>
105#include <Graphic3d_ArrayOfQuadrangleStrips.hxx>
106#include <Graphic3d_ArrayOfPolygons.hxx>
da87ddc3 107#include <Graphic3d_AttribBuffer.hxx>
a577aaab 108#include <Graphic3d_AspectMarker3d.hxx>
9558a876
A
109#include <Graphic3d_Group.hxx>
110#include <Standard_Real.hxx>
111
329843e2 112#include <AIS_Circle.hxx>
329843e2
A
113#include <BRepBuilderAPI_MakeEdge.hxx>
114#include <BRepBuilderAPI_MakeFace.hxx>
115#include <BRepBuilderAPI_MakeWire.hxx>
116#include <Geom_Circle.hxx>
117#include <GC_MakeCircle.hxx>
329843e2
A
118#include <Select3D_SensitiveCircle.hxx>
119#include <SelectMgr_EntityOwner.hxx>
120#include <SelectMgr_Selection.hxx>
121#include <StdFail_NotDone.hxx>
122#include <StdPrs_ShadedShape.hxx>
a2d5ab2e 123#include <TopoDS_Wire.hxx>
ac04d101 124
792c785c 125#include <AIS_MultipleConnectedInteractive.hxx>
0717ddc1 126#include <AIS_ConnectedInteractive.hxx>
29e2c6d2 127#include <AIS_TextLabel.hxx>
ac04d101
SA
128#include <TopLoc_Location.hxx>
129#include <TColStd_ListOfInteger.hxx>
130#include <TColStd_ListIteratorOfListOfInteger.hxx>
329843e2 131
9427bc1d 132#include <Select3D_SensitiveSegment.hxx>
133#include <Select3D_SensitivePrimitiveArray.hxx>
a577aaab 134#include <Select3D_SensitivePoint.hxx>
ceae62f0
A
135#include <BRepAdaptor_Curve.hxx>
136#include <StdPrs_Curve.hxx>
137
138#include <BRepExtrema_ExtPC.hxx>
139#include <BRepExtrema_ExtPF.hxx>
140
68ef63f9 141#include <Prs3d_Arrow.hxx>
142#include <Prs3d_ArrowAspect.hxx>
bc001a40 143#include <Prs3d_DatumAttribute.hxx>
046a1c9d 144#include <Prs3d_DatumAspect.hxx>
6262338c 145#include <Prs3d_Drawer.hxx>
53b15292 146#include <Prs3d_VertexDrawMode.hxx>
a2d5ab2e 147#include <Prs3d_LineAspect.hxx>
a577aaab 148#include <Prs3d_PointAspect.hxx>
bc001a40 149#include <Prs3d_Presentation.hxx>
61b0191c 150#include <Prs3d_TextAspect.hxx>
113bda70 151#include <Prs3d_ToolCylinder.hxx>
152#include <Prs3d_ToolSphere.hxx>
153#include <Prs3d_ToolTorus.hxx>
a577aaab 154
155#include <Image_AlienPixMap.hxx>
eb4320f2 156#include <TColStd_HArray1OfAsciiString.hxx>
046a1c9d 157#include <TColStd_HSequenceOfAsciiString.hxx>
a2d5ab2e 158
7fd59977 159extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
9558a876
A
160extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
161 const Handle(AIS_InteractiveObject)& theAISObj,
162 Standard_Boolean theReplaceIfExists = Standard_True);
7fd59977 163extern Handle(AIS_InteractiveContext)& TheAISContext();
164
bc001a40 165namespace
166{
167 static bool convertToColor (const Handle(TColStd_HSequenceOfAsciiString)& theColorValues,
168 Quantity_Color& theColor)
169 {
170 const char* anArgs[3] =
171 {
172 theColorValues->Size() >= 1 ? theColorValues->Value (1).ToCString() : "",
173 theColorValues->Size() >= 2 ? theColorValues->Value (2).ToCString() : "",
174 theColorValues->Size() >= 3 ? theColorValues->Value (3).ToCString() : ""
175 };
dae2a922 176 return Draw::ParseColor (theColorValues->Size(), anArgs, theColor) != 0;
bc001a40 177 }
178
179 static bool convertToDatumPart (const TCollection_AsciiString& theValue,
180 Prs3d_DatumParts& theDatumPart)
181 {
182 TCollection_AsciiString aValue = theValue;
183 aValue.LowerCase();
184 if (aValue == "origin") theDatumPart = Prs3d_DP_Origin;
185 else if (aValue == "xaxis") theDatumPart = Prs3d_DP_XAxis;
186 else if (aValue == "yaxis") theDatumPart = Prs3d_DP_YAxis;
187 else if (aValue == "zaxis") theDatumPart = Prs3d_DP_ZAxis;
188 else if (aValue == "xarrow") theDatumPart = Prs3d_DP_XArrow;
189 else if (aValue == "yarrow") theDatumPart = Prs3d_DP_YArrow;
190 else if (aValue == "zarrow") theDatumPart = Prs3d_DP_ZArrow;
191 else if (aValue == "xoyaxis") theDatumPart = Prs3d_DP_XOYAxis;
192 else if (aValue == "yozaxis") theDatumPart = Prs3d_DP_YOZAxis;
193 else if (aValue == "xozaxis") theDatumPart = Prs3d_DP_XOZAxis;
194 else if (aValue == "whole") theDatumPart = Prs3d_DP_None;
195 else
196 {
197 return false;
198 }
199 return true;
200 }
201
202 static void convertToDatumParts (const TCollection_AsciiString& theValue,
203 NCollection_List<Prs3d_DatumParts>& theParts)
204 {
205 TCollection_AsciiString aValue = theValue;
206 const Standard_Integer aSplitPos = theValue.Search ("|");
207 Prs3d_DatumParts aPart = Prs3d_DP_None;
208 if (aSplitPos > 0)
209 {
210 convertToDatumParts (theValue.SubString (aSplitPos + 1, theValue.Length()), theParts);
211 if (aSplitPos == 1) // first symbol
212 {
213 return;
214 }
215 aValue = theValue.SubString (1, aSplitPos - 1);
216 }
217 if (convertToDatumPart (aValue, aPart))
218 {
219 theParts.Append (aPart);
220 }
221 }
222
223 static bool convertToDatumAttribute (const TCollection_AsciiString& theValue,
224 Prs3d_DatumAttribute& theAttribute)
225 {
226 TCollection_AsciiString aValue = theValue;
227 aValue.LowerCase();
228 if (aValue == "xaxislength") theAttribute = Prs3d_DA_XAxisLength;
229 else if (aValue == "yaxislength") theAttribute = Prs3d_DA_YAxisLength;
230 else if (aValue == "zaxislength") theAttribute = Prs3d_DA_ZAxisLength;
231 else if (aValue == "tuberadiuspercent") theAttribute = Prs3d_DP_ShadingTubeRadiusPercent;
232 else if (aValue == "coneradiuspercent") theAttribute = Prs3d_DP_ShadingConeRadiusPercent;
233 else if (aValue == "conelengthpercent") theAttribute = Prs3d_DP_ShadingConeLengthPercent;
234 else if (aValue == "originradiuspercent") theAttribute = Prs3d_DP_ShadingOriginRadiusPercent;
235 else if (aValue == "shadingnumberoffacettes") theAttribute = Prs3d_DP_ShadingNumberOfFacettes;
236 else
237 return false;
238 return true;
239 }
240
241 static void convertToDatumAttributes (const TCollection_AsciiString& theValue,
242 NCollection_List<Prs3d_DatumAttribute>& theAttributes)
243 {
244 TCollection_AsciiString aValue = theValue;
245 const Standard_Integer aSplitPos = theValue.Search ("|");
246 Prs3d_DatumAttribute anAttribute = Prs3d_DA_XAxisLength;
247 if (aSplitPos > 0)
248 {
249 convertToDatumAttributes (theValue.SubString (aSplitPos + 1, theValue.Length()), theAttributes);
250 if (aSplitPos == 1) // first symbol
251 {
252 return;
253 }
254 aValue = theValue.SubString (1, aSplitPos - 1);
255 }
256 if (convertToDatumAttribute (aValue, anAttribute))
257 {
258 theAttributes.Append (anAttribute);
259 }
260 }
261
262 static bool convertToDatumAxes (const TCollection_AsciiString& theValue,
263 Prs3d_DatumAxes& theDatumAxes)
264 {
265 TCollection_AsciiString aValue = theValue;
266 aValue.LowerCase();
267 if (aValue == "x") theDatumAxes = Prs3d_DA_XAxis;
268 else if (aValue == "y") theDatumAxes = Prs3d_DA_YAxis;
269 else if (aValue == "z") theDatumAxes = Prs3d_DA_ZAxis;
270 else if (aValue == "xy") theDatumAxes = Prs3d_DA_XYAxis;
271 else if (aValue == "zy") theDatumAxes = Prs3d_DA_YZAxis;
272 else if (aValue == "xz") theDatumAxes = Prs3d_DA_XZAxis;
273 else if (aValue == "xyz") theDatumAxes = Prs3d_DA_XYZAxis;
274 else
275 {
276 return false;
277 }
278 return true;
279 }
280
281 static Standard_Boolean setTrihedronParams (Standard_Integer theArgsNb,
282 const char** theArgVec,
283 Handle(AIS_Trihedron) theTrihedron)
284 {
285 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
286 TCollection_AsciiString aParseKey;
287 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
288 {
289 TCollection_AsciiString anArg (theArgVec [anArgIt]);
290 if (anArg.Value (1) == '-'
291 && !anArg.IsRealValue())
292 {
293 aParseKey = anArg;
294 aParseKey.Remove (1);
295 aParseKey.LowerCase();
296 std::string aKey = aParseKey.ToCString();
297 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString());
298 continue;
299 }
300
301 if (aParseKey.IsEmpty())
302 {
303 continue;
304 }
305
306 aMapOfArgs (aParseKey)->Append (anArg);
307 }
308
309 // Check parameters
310 if ((aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis"))
311 || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")))
312 {
23fe70ec 313 Message::SendFail ("Syntax error: -xaxis and -zaxis parameters are to set together");
bc001a40 314 return Standard_False;
315 }
316
317 Handle(TColStd_HSequenceOfAsciiString) aValues;
318 Handle(Geom_Axis2Placement) aComponent = theTrihedron->Component();
319 if (aMapOfArgs.Find ("origin", aValues))
320 {
321 aComponent->SetLocation (gp_Pnt (aValues->Value (1).RealValue(),
322 aValues->Value (2).RealValue(),
323 aValues->Value (3).RealValue()));
324 }
325 Handle(TColStd_HSequenceOfAsciiString) aXValues, aZValues;
326 if (aMapOfArgs.Find ("xaxis", aXValues) && aMapOfArgs.Find ("zaxis", aZValues))
327 {
328 gp_Dir aXDir (aXValues->Value (1).RealValue(),
329 aXValues->Value (2).RealValue(),
330 aXValues->Value (3).RealValue());
331
332 gp_Dir aZDir (aZValues->Value (1).RealValue(),
333 aZValues->Value (2).RealValue(),
334 aZValues->Value (3).RealValue());
335
336 if (!aZDir.IsNormal (aXDir, M_PI / 180.0))
337 {
23fe70ec 338 Message::SendFail ("Syntax error - parameters 'xaxis' and 'zaxis' are not applied as VectorX is not normal to VectorZ");
bc001a40 339 return Standard_False;
340 }
341
169c944c 342 aComponent->SetAx2 (gp_Ax2 (aComponent->Location(), aZDir, aXDir));
bc001a40 343 }
344
345 if (aMapOfArgs.Find ("dispmode", aValues))
346 {
347 TCollection_AsciiString aValue (aValues->Value (1));
348 bool isWireframe = true;
349 if (aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
350 isWireframe = false;
351 theTrihedron->SetDatumDisplayMode (isWireframe ? Prs3d_DM_WireFrame
352 : Prs3d_DM_Shaded);
353 }
354
355 if (aMapOfArgs.Find ("hidelabels", aValues))
356 {
fae1ae11
ZA
357 Standard_Boolean toHideLabels = Standard_True;
358 if (aValues->Size() == 1)
359 {
dae2a922 360 Draw::ParseOnOff (aValues->First().ToCString(), toHideLabels);
fae1ae11
ZA
361 }
362 else if (aValues->Size() != 0)
bc001a40 363 {
23fe70ec 364 Message::SendFail ("Syntax error: -hidelabels expects parameter 'on' or 'off' after");
bc001a40 365 return Standard_False;
366 }
367
bc001a40 368 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
fae1ae11
ZA
369 {
370 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
371 }
372 theTrihedron->Attributes()->DatumAspect()->SetDrawLabels (!toHideLabels);
373 }
374
375 if (aMapOfArgs.Find ("hidearrows", aValues))
376 {
377 Standard_Boolean toHideArrows = Standard_True;
378 if (aValues->Size() == 1)
379 {
dae2a922 380 Draw::ParseOnOff (aValues->First().ToCString(), toHideArrows);
fae1ae11
ZA
381 }
382 else if (aValues->Size() != 0)
383 {
23fe70ec 384 Message::SendFail ("Syntax error: -hidearrows expects parameter 'on' or 'off' after");
fae1ae11
ZA
385 return Standard_False;
386 }
387
388 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
389 {
390 theTrihedron->Attributes()->SetDatumAspect (new Prs3d_DatumAspect());
391 }
392 theTrihedron->Attributes()->DatumAspect()->SetDrawArrows (!toHideArrows);
bc001a40 393 }
394
395 if (aMapOfArgs.Find ("color", aValues))
396 {
397 NCollection_List<Prs3d_DatumParts> aParts;
398 if (aValues->Size() < 2)
399 {
23fe70ec 400 Message::SendFail ("Syntax error: -color wrong parameters");
bc001a40 401 return Standard_False;
402 }
403
404 convertToDatumParts (aValues->Value(1), aParts);
405 aValues->Remove (1); // datum part is processed
406 Quantity_Color aColor;
407 if (!convertToColor (aValues, aColor))
408 {
23fe70ec 409 Message::SendFail ("Syntax error: -color wrong parameters");
bc001a40 410 return Standard_False;
411 }
412
413 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (aParts); anIterator.More(); anIterator.Next())
414 {
415 Prs3d_DatumParts aDatumPart = anIterator.Value();
416 if (aDatumPart == Prs3d_DP_None)
417 {
418 theTrihedron->SetColor (aColor);
419 }
420 else
421 {
422 theTrihedron->SetDatumPartColor (aDatumPart, aColor);
423 }
424 }
425 }
426
427 if (aMapOfArgs.Find ("textcolor", aValues))
428 {
429 Quantity_Color aColor;
430 if (!convertToColor (aValues, aColor))
431 {
23fe70ec 432 Message::SendFail ("Syntax error: -textcolor wrong parameters");
bc001a40 433 return Standard_False;
434 }
435 theTrihedron->SetTextColor (aColor);
436 }
437
438 if (aMapOfArgs.Find ("arrowcolor", aValues))
439 {
440 Quantity_Color aColor;
441 if (!convertToColor (aValues, aColor))
442 {
23fe70ec 443 Message::SendFail ("Syntax error: -arrowcolor wrong parameters");
bc001a40 444 return Standard_False;
445 }
446 theTrihedron->SetArrowColor (aColor);
447 }
448
449 if (aMapOfArgs.Find ("attribute", aValues))
450 {
451 NCollection_List<Prs3d_DatumAttribute> anAttributes;
452 if (aValues->Size() != 2)
453 {
23fe70ec 454 Message::SendFail ("Syntax error: -attribute wrong parameters");
bc001a40 455 return Standard_False;
456 }
457
458 convertToDatumAttributes (aValues->Value (1), anAttributes);
459 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
460 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
461 for (NCollection_List<Prs3d_DatumAttribute>::Iterator anIterator (anAttributes); anIterator.More(); anIterator.Next())
462 {
463 theTrihedron->Attributes()->DatumAspect()->SetAttribute (anIterator.Value(), aValues->Value (2).RealValue());
464 }
465 }
466
467 if (aMapOfArgs.Find ("priority", aValues))
468 {
469 Prs3d_DatumParts aDatumPart;
470 if (aValues->Size() < 2
471 || !convertToDatumPart (aValues->Value (1), aDatumPart))
472 {
23fe70ec 473 Message::SendFail ("Syntax error: -priority wrong parameters");
bc001a40 474 return Standard_False;
475 }
476 theTrihedron->SetSelectionPriority (aDatumPart, aValues->Value (2).IntegerValue());
477 }
478
169c944c 479 if (aMapOfArgs.Find ("labels", aValues)
480 || aMapOfArgs.Find ("label", aValues))
bc001a40 481 {
482 Prs3d_DatumParts aDatumPart = Prs3d_DP_None;
169c944c 483 if (aValues->Size() >= 2
bc001a40 484 && convertToDatumPart(aValues->Value(1), aDatumPart)
485 && aDatumPart >= Prs3d_DP_XAxis
486 && aDatumPart <= Prs3d_DP_ZAxis) // labels are set to axes only
487 {
488 theTrihedron->SetLabel (aDatumPart, aValues->Value (2));
489 }
490 else
491 {
23fe70ec 492 Message::SendFail ("Syntax error: -labels wrong parameters");
bc001a40 493 return Standard_False;
494 }
495 }
496
497 if (aMapOfArgs.Find ("drawaxes", aValues))
498 {
499 Prs3d_DatumAxes aDatumAxes = Prs3d_DA_XAxis;
500 if (aValues->Size() < 1
501 || !convertToDatumAxes (aValues->Value (1), aDatumAxes))
502 {
23fe70ec 503 Message::SendFail ("Syntax error: -drawaxes wrong parameters");
bc001a40 504 return Standard_False;
505 }
506 if (!theTrihedron->Attributes()->HasOwnDatumAspect())
507 theTrihedron->Attributes()->SetDatumAspect(new Prs3d_DatumAspect());
508 theTrihedron->Attributes()->DatumAspect()->SetDrawDatumAxes (aDatumAxes);
509 }
510 return Standard_True;
511 }
5b377041 512
513 //! Auxiliary function to parse font aspect style argument
514 static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg,
515 Font_FontAspect& theAspect)
516 {
517 if (theArg == "regular"
518 || *theArg.ToCString() == 'r')
519 {
520 theAspect = Font_FA_Regular;
521 return Standard_True;
522 }
523 else if (theArg == "bolditalic"
524 || theArg == "bold-italic"
525 || theArg == "italic-bold"
526 || theArg == "italicbold")
527 {
528 theAspect = Font_FA_BoldItalic;
529 return Standard_True;
530 }
531 else if (theArg == "bold"
532 || *theArg.ToCString() == 'b')
533 {
534 theAspect = Font_FA_Bold;
535 return Standard_True;
536 }
537 else if (theArg == "italic"
538 || *theArg.ToCString() == 'i')
539 {
540 theAspect = Font_FA_Italic;
541 return Standard_True;
542 }
543 return Standard_False;
544 }
1bbd7c79 545
546 //! Auxiliary function to parse font strict level argument
547 static Standard_Integer parseFontStrictLevel (const Standard_Integer theArgNb,
548 const char** theArgVec,
549 Font_StrictLevel& theLevel)
550 {
551 if (theArgNb >= 1)
552 {
553 TCollection_AsciiString anArg (theArgVec[0]);
554 anArg.LowerCase();
555 if (anArg == "any")
556 {
557 theLevel = Font_StrictLevel_Any;
558 return 1;
559 }
560 else if (anArg == "aliases")
561 {
562 theLevel = Font_StrictLevel_Aliases;
563 return 1;
564 }
565 else if (anArg == "strict")
566 {
567 theLevel = Font_StrictLevel_Strict;
568 return 1;
569 }
570 }
571 theLevel = Font_StrictLevel_Strict;
572 return 0;
573 }
bc001a40 574}
575
7fd59977 576//==============================================================================
577//function : Vtrihedron 2d
578//purpose : Create a plane with a 2D trihedron from a faceselection
161c4476 579//Draw arg : vtri2d name
7fd59977 580//==============================================================================
404c8936 581static int VTrihedron2D (Draw_Interpretor& /*theDI*/,
582 Standard_Integer theArgsNum,
583 const char** theArgVec)
584{
585 if (theArgsNum != 2)
586 {
23fe70ec 587 Message::SendFail() << "Syntax error: wrong number of arguments.";
404c8936 588 return 1;
589 }
7fd59977 590
404c8936 591 TopTools_ListOfShape aShapes;
592 ViewerTest::GetSelectedShapes (aShapes);
7fd59977 593
404c8936 594 if (aShapes.Extent() != 1)
595 {
23fe70ec 596 Message::SendFail ("Error: wrong number of selected shapes.");
404c8936 597 return 1;
598 }
7fd59977 599
404c8936 600 const TopoDS_Shape& aShape = aShapes.First();
7fd59977 601
404c8936 602 TopoDS_Face aFace = TopoDS::Face (aShape);
603 TopExp_Explorer aFaceExp (aFace, TopAbs_EDGE);
604 TopoDS_Edge anEdge0 = TopoDS::Edge (aFaceExp.Current());
7fd59977 605
7fd59977 606 gp_Pnt A,B,C;
404c8936 607 if (aFaceExp.More())
608 {
609 aFaceExp.Next();
610 TopoDS_Edge anEdge1 = TopoDS::Edge (aFaceExp.Current() );
611 BRepAdaptor_Curve aCurve0 (anEdge0);
612 BRepAdaptor_Curve aCurve1 (anEdge1);
613 A = aCurve1.Value (0.1);
614 B = aCurve1.Value (0.9);
615 C = aCurve0.Value (0.5);
7fd59977 616 }
404c8936 617 else
618 {
619 BRepAdaptor_Curve aCurve0 (anEdge0);
620 A = aCurve0.Value (0.1);
621 B = aCurve0.Value (0.9);
622 C = aCurve0.Value (0.5);
7fd59977 623 }
7fd59977 624
404c8936 625 GC_MakePlane aMkPlane (A,B,C);
7fd59977 626
404c8936 627 Handle(AIS_PlaneTrihedron) anAISPlaneTri = new AIS_PlaneTrihedron (aMkPlane.Value());
628 TCollection_AsciiString aName (theArgVec[1]);
7fd59977 629
404c8936 630 VDisplayAISObject (aName, anAISPlaneTri);
7fd59977 631
161c4476 632 return 0;
7fd59977 633}
634
bc001a40 635//=======================================================================
636//function : VTrihedron
637//purpose :
638//=======================================================================
639static int VTrihedron (Draw_Interpretor& ,
640 Standard_Integer theArgsNb,
641 const char** theArgVec)
7fd59977 642{
bc001a40 643 if (theArgsNb < 2)
dc9b6d23 644 {
23fe70ec 645 Message::SendFail ("Syntax error: the wrong number of input parameters");
dc9b6d23 646 return 1;
7fd59977 647 }
7fd59977 648
bc001a40 649 TCollection_AsciiString aName (theArgVec[1]);
650 gp_Pln aWorkingPlane;
651 Standard_Boolean toUpdate = Standard_True;
046a1c9d 652
bc001a40 653 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
654 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
046a1c9d 655
bc001a40 656 Handle(AIS_Trihedron) aTrihedron;
8f521168 657 Handle(AIS_InteractiveObject) anObject;
658 if (GetMapOfAIS().Find2 (aName, anObject))
046a1c9d 659 {
bc001a40 660 aTrihedron = Handle(AIS_Trihedron)::DownCast (anObject);
661 if (aTrihedron.IsNull())
046a1c9d 662 {
23fe70ec 663 Message::SendFail ("Syntax error: no trihedron with this name");
bc001a40 664 return 1;
046a1c9d 665 }
666 }
bc001a40 667 else
dc9b6d23 668 {
bc001a40 669 Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (gp_Pnt (0.0, 0.0, 0.0),
670 gp::DZ(), gp::DX());
671 aTrihedron = new AIS_Trihedron (aPlacement);
046a1c9d 672 }
dc9b6d23 673
bc001a40 674 if (!setTrihedronParams (theArgsNb, theArgVec, aTrihedron))
046a1c9d 675 {
bc001a40 676 return 1;
dc9b6d23 677 }
7fd59977 678
bc001a40 679 // Redisplay a dimension after parameter changing.
680 if (ViewerTest::GetAISContext()->IsDisplayed (aTrihedron))
dc9b6d23 681 {
bc001a40 682 ViewerTest::GetAISContext()->Redisplay (aTrihedron, toUpdate);
dc9b6d23 683 }
bc001a40 684 else
046a1c9d 685 {
bc001a40 686 VDisplayAISObject (theArgVec[1], aTrihedron);
046a1c9d 687 }
688
161c4476 689 return 0;
7fd59977 690}
691
7fd59977 692//==============================================================================
693//function : VSize
694//author : ege
695//purpose : Change the size of a named or selected trihedron
696// if no name : it affects the trihedrons witch are selected otherwise nothing is donne
697// if no value, the value is set at 100 by default
698//Draw arg : vsize [name] [size]
699//==============================================================================
700
701static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
702
703{
704 // Declaration de booleens
705 Standard_Boolean ThereIsName;
706 Standard_Boolean ThereIsCurrent;
707 Standard_Real value;
161c4476 708 Standard_Boolean hascol;
1d47d8d0 709
87432b82 710 Quantity_Color col = Quantity_NOC_BLACK;
7fd59977 711
712 // Verification des arguments
586db386 713 if ( argc>3 ) {di<<argv[0]<<" Syntaxe error\n"; return 1;}
7fd59977 714
715 // Verification du nombre d'arguments
716 if (argc==1) {ThereIsName=Standard_False;value=100;}
91322f44 717 else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);}
718 else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);}
7fd59977 719
7fd59977 720 // On set le booleen ThereIsCurrent
c3282ec1 721 if (TheAISContext() -> NbSelected() > 0) {ThereIsCurrent=Standard_True;}
7fd59977 722 else {ThereIsCurrent=Standard_False;}
723
724
725
726 //===============================================================
727 // Il n'y a pas de nom mais des objets selectionnes
728 //===============================================================
161c4476 729 if (!ThereIsName && ThereIsCurrent)
7fd59977 730 {
731
732 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
733 it (GetMapOfAIS());
734
735 while ( it.More() ) {
736
8f521168 737 Handle(AIS_InteractiveObject) aShape = it.Key1();
7fd59977 738
c3282ec1 739 if (!aShape.IsNull() && TheAISContext()->IsSelected(aShape) )
7fd59977 740 {
741
161c4476 742 // On verifie que l'AIS InteraciveObject selectionne est bien
7fd59977 743 // un AIS_Trihedron
744 if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) {
745
87432b82 746 if (aShape->HasColor())
747 {
748 hascol = Standard_True;
7fd59977 749
750 // On recupere la couleur de aShape
87432b82 751 aShape->Color (col);
752 }
753 else
754 {
755 hascol = Standard_False;
756 }
7fd59977 757
758 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
759 // pour lui appliquer la methode SetSize()
c5f3a425 760 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
7fd59977 761
762 // C'est bien un triedre,on chage sa valeur!
763 aTrihedron->SetSize(value);
764
765 // On donne la couleur au Trihedron
766 if(hascol) aTrihedron->SetColor(col);
767 else aTrihedron->UnsetColor();
768
769
770 // The trihedron hasn't be errased from the map
771 // so you just have to redisplay it
772 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
773
774 }
775
776 }
777
778 it.Next();
779 }
780
781 TheAISContext() ->UpdateCurrentViewer();
782 }
783
784 //===============================================================
785 // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire!
786 //===============================================================
787
788
789
790 //===============================================================
791 // Il y a un nom de triedre passe en argument
792 //===============================================================
793 if (ThereIsName) {
794 TCollection_AsciiString name=argv[1];
795
796 // on verifie que ce nom correspond bien a une shape
8f521168 797 Handle(AIS_InteractiveObject) aShape;
798 if (GetMapOfAIS().Find2(name, aShape))
799 {
161c4476 800 // On verifie que l'AIS InteraciveObject est bien
7fd59977 801 // un AIS_Trihedron
802 if (!aShape.IsNull() &&
803 aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3)
804 {
87432b82 805 if (aShape->HasColor())
806 {
7fd59977 807 hascol=Standard_True;
808
809 // On recupere la couleur de aShape
87432b82 810 aShape->Color (col);
811 }
812 else
813 {
814 hascol = Standard_False;
815 }
7fd59977 816
817 // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron
818 // pour lui appliquer la methode SetSize()
c5f3a425 819 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast (aShape);
7fd59977 820
821 // C'est bien un triedre,on chage sa valeur
822 aTrihedron->SetSize(value);
823
824 // On donne la couleur au Trihedron
825 if(hascol) aTrihedron->SetColor(col);
826 else aTrihedron->UnsetColor();
827
828 // The trihedron hasn't be errased from the map
829 // so you just have to redisplay it
830 TheAISContext() ->Redisplay(aTrihedron,Standard_False);
831
832 TheAISContext() ->UpdateCurrentViewer();
833 }
834 }
835 }
161c4476 836 return 0;
7fd59977 837}
838
839
840//==============================================================================
841
842//==============================================================================
843//function : VPlaneTrihedron
844//purpose : Create a plane from a trihedron selection. If no arguments are set, the default
161c4476 845//Draw arg : vplanetri name
7fd59977 846//==============================================================================
847#include <AIS_Plane.hxx>
848
849
850
851static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
852
853{
854 // Verification des arguments
586db386 855 if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
7fd59977 856
404c8936 857 if (TheAISContext()->NbSelected() != 1)
858 {
23fe70ec 859 Message::SendFail ("Error: Wrong number of selected shapes.");
404c8936 860 return 1;
7fd59977 861 }
862
404c8936 863 TheAISContext()->InitSelected();
864 Handle(AIS_InteractiveObject) aTest = TheAISContext()->SelectedInteractive();
865 Handle(AIS_Plane) aPlane = Handle(AIS_Plane)::DownCast (aTest);
866 if (aPlane.IsNull())
867 {
23fe70ec 868 Message::SendFail ("Error: Selected shape is not a plane.");
404c8936 869 return 1;
7fd59977 870 }
7fd59977 871
404c8936 872 VDisplayAISObject (argv[1], aPlane);
7fd59977 873
161c4476 874 return 0;
7fd59977 875}
876
877
878
879//==============================================================================
880// Fonction First click 2de click
161c4476 881//
7fd59977 882// vaxis vertex vertex
883// edge None
884// vaxispara edge vertex
885// vaxisortho edge Vertex
886// vaxisinter Face Face
887//==============================================================================
888
889//==============================================================================
890//function : VAxisBuilder
161c4476 891//purpose :
7fd59977 892//Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb
893//==============================================================================
894#include <TopoDS_Edge.hxx>
895#include <TopoDS_Vertex.hxx>
896#include <TopExp.hxx>
897#include <Geom_Line.hxx>
898
161c4476 899static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 900{
901 // Declarations
902 Standard_Boolean HasArg;
903 TCollection_AsciiString name;
7fd59977 904
905 // Verification
586db386 906 if (argc<2 || argc>8 ) {di<<" Syntaxe error\n";return 1;}
7fd59977 907 if (argc==8) HasArg=Standard_True;
908 else HasArg=Standard_False;
909
910 name=argv[1];
404c8936 911
912 TopTools_ListOfShape aShapes;
913 ViewerTest::GetSelectedShapes (aShapes);
7fd59977 914
915 // Cas ou il y a des arguments
916 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom)
917 if (HasArg) {
918 Standard_Real coord[6];
919 for(Standard_Integer i=0;i<=5;i++){
91322f44 920 coord[i]=Draw::Atof(argv[2+i]);
7fd59977 921 }
922 gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ;
923
924 gp_Vec myVect (p1,p2);
925 Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect );
926 Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine );
927 GetMapOfAIS().Bind (TheAxis,name);
0577ae8c 928 TheAISContext()->Display(TheAxis, Standard_True);
7fd59977 929 }
930
931 // Pas d'arguments
932 else {
933 // fonction vaxis
934 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom)
935 if ( !strcasecmp(argv[0], "vaxis")) {
404c8936 936 if (aShapes.Extent() != 2 && aShapes.Extent() != 1)
937 {
23fe70ec 938 Message::SendFail ("Error: Wrong number of selected shapes.");
404c8936 939 return 1;
7fd59977 940 }
7fd59977 941
404c8936 942 const TopoDS_Shape& aShapeA = aShapes.First();
943 if (aShapeA.ShapeType() == TopAbs_VERTEX)
944 {
945 if (aShapes.Extent() != 2)
946 {
23fe70ec 947 Message::SendFail ("Error: Wrong number of selected shapes.");
404c8936 948 return 1;
949 }
7fd59977 950
404c8936 951 const TopoDS_Shape& aShapeB = aShapes.Last();
952 if (aShapeB.ShapeType() != TopAbs_VERTEX)
953 {
23fe70ec 954 Message::SendFail ("Syntax error: You should select two vertices or one edge.");
404c8936 955 return 1;
956 }
7fd59977 957
161c4476 958 // Construction de l'axe
404c8936 959 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
960 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
961 gp_Vec V (A,B);
962 gp_Dir D (V);
7fd59977 963 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
964 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
965 GetMapOfAIS().Bind (TheAxis,name);
0577ae8c 966 TheAISContext()->Display (TheAxis, Standard_True);
161c4476 967 }
404c8936 968 else
969 {
970 TopoDS_Edge ed =TopoDS::Edge (aShapeA);
7fd59977 971 TopoDS_Vertex Va,Vb;
972 TopExp::Vertices(ed,Va,Vb );
973 gp_Pnt A=BRep_Tool::Pnt(Va);
974 gp_Pnt B=BRep_Tool::Pnt(Vb);
975 gp_Vec V (A,B);
976 gp_Dir D (V);
977 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D);
978 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
979 GetMapOfAIS().Bind (TheAxis,name);
0577ae8c 980 TheAISContext()->Display (TheAxis, Standard_True);
7fd59977 981 }
982
983 }
984
985 // Fonction axispara
986 // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS)
404c8936 987 else if ( !strcasecmp(argv[0], "vaxispara"))
988 {
989 if (aShapes.Extent() != 2)
990 {
23fe70ec 991 Message::SendFail ("Error: Wrong number of selected shapes.");
404c8936 992 return 1;
7fd59977 993 }
404c8936 994
995 const TopoDS_Shape& aShapeA = aShapes.First();
996 const TopoDS_Shape& aShapeB = aShapes.Last();
997 if (!(aShapeA.ShapeType() == TopAbs_EDGE
998 && aShapeB.ShapeType() == TopAbs_VERTEX))
999 {
23fe70ec 1000 Message::SendFail ("Syntax error: You should select face and then vertex.");
404c8936 1001 return 1;
7fd59977 1002 }
7fd59977 1003
404c8936 1004 TopoDS_Edge ed=TopoDS::Edge (aShapeA);
1005 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
7fd59977 1006 TopoDS_Vertex Va,Vc;
1007 TopExp::Vertices(ed,Va,Vc );
1008 gp_Pnt A=BRep_Tool::Pnt(Va);
1009 gp_Pnt C=BRep_Tool::Pnt(Vc);
1010 gp_Vec V (A,C);
1011 gp_Dir D (V);
1012 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1013 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1014 GetMapOfAIS().Bind (TheAxis,name);
0577ae8c 1015 TheAISContext()->Display (TheAxis, Standard_True);
7fd59977 1016
1017 }
1018
1019 // Fonction axisortho
404c8936 1020 else
1021 {
1022 if (aShapes.Extent() != 2)
1023 {
23fe70ec 1024 Message::SendFail ("Error: Wrong number of selected shapes.");
404c8936 1025 return 1;
7fd59977 1026 }
404c8936 1027
1028 const TopoDS_Shape& aShapeA = aShapes.First();
1029 const TopoDS_Shape& aShapeB = aShapes.Last();
1030 if (!(aShapeA.ShapeType() == TopAbs_EDGE
1031 && aShapeB.ShapeType() == TopAbs_VERTEX))
1032 {
23fe70ec 1033 Message::SendFail ("Syntax error: You should select face and then vertex.");
404c8936 1034 return 1;
7fd59977 1035 }
7fd59977 1036
1037 // Construction de l'axe
404c8936 1038 TopoDS_Edge ed=TopoDS::Edge(aShapeA) ;
1039 gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(aShapeB) );
7fd59977 1040 TopoDS_Vertex Va,Vc;
1041 TopExp::Vertices(ed,Va,Vc );
1042 gp_Pnt A=BRep_Tool::Pnt(Va);
1043 gp_Pnt C=BRep_Tool::Pnt(Vc);
1044 gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() );
1045 gp_Vec V (A,E);
1046 gp_Dir D (V);
1047 Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D);
1048 Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect);
1049 GetMapOfAIS().Bind (TheAxis,name);
0577ae8c 1050 TheAISContext()->Display (TheAxis, Standard_True);
7fd59977 1051
1052 }
1053
1054 }
1055 return 0;
1056}
1057
1058
1059//==============================================================================
1060// Fonction First click Result
161c4476 1061//
7fd59977 1062// vpoint vertex AIS_Point=Vertex
1063// edge AIS_Point=Middle of the edge
1064//==============================================================================
1065
1066//==============================================================================
1067//function : VPointBuilder
2ff1d580 1068//purpose :
7fd59977 1069//==============================================================================
1070#include <TopoDS_Edge.hxx>
1071#include <TopoDS_Vertex.hxx>
1072#include <TopExp.hxx>
1073#include <AIS_Point.hxx>
1074#include <Geom_CartesianPoint.hxx>
1075
2ff1d580 1076static int VPointBuilder(Draw_Interpretor& ,
1077 Standard_Integer theArgNb,
1078 const char** theArgVec)
7fd59977 1079{
2ff1d580 1080 TCollection_AsciiString aName;
1081 gp_Pnt aPnt (RealLast(), 0.0, 0.0);
1082 bool is2d = false, isNoSel = false;
1083 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
404c8936 1084 {
2ff1d580 1085 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1086 anArg.LowerCase();
1087 if (anArg == "-2d")
1088 {
1089 is2d = true;
1090 }
1091 else if (anArg == "-nosel"
1092 || anArg == "-noselection")
1093 {
1094 isNoSel = true;
1095 }
1096 else if (aName.IsEmpty())
1097 {
1098 aName = theArgVec[anArgIter];
1099 }
1100 else if (aPnt.X() == RealLast()
1101 && anArgIter + 1 < theArgNb
1102 && Draw::ParseReal (theArgVec[anArgIter + 0], aPnt.ChangeCoord().ChangeCoord (1))
1103 && Draw::ParseReal (theArgVec[anArgIter + 1], aPnt.ChangeCoord().ChangeCoord (2)))
1104 {
1105 if (anArgIter + 2 < theArgNb
1106 && TCollection_AsciiString (theArgVec[anArgIter + 2]) != "-2d"
1107 && Draw::ParseReal (theArgVec[anArgIter + 2], aPnt.ChangeCoord().ChangeCoord (3)))
1108 {
1109 anArgIter += 2;
1110 }
1111 else
1112 {
1113 anArgIter += 1;
1114 }
1115 }
1116 else
404c8936 1117 {
2ff1d580 1118 Message::SendFail() << "Syntax error at argument '" << anArg << "'\n";
404c8936 1119 return 1;
7fd59977 1120 }
2ff1d580 1121 }
7fd59977 1122
2ff1d580 1123 if (aPnt.X() == RealLast())
1124 {
1125 TopTools_ListOfShape aShapes;
1126 ViewerTest::GetSelectedShapes (aShapes);
1127 TopoDS_Shape aShapeA;
1128 if (aShapes.Extent() == 1)
404c8936 1129 {
2ff1d580 1130 aShapeA = aShapes.First();
7fd59977 1131 }
2ff1d580 1132 switch (!aShapeA.IsNull() ? aShapeA.ShapeType() : TopAbs_SHAPE)
404c8936 1133 {
2ff1d580 1134 case TopAbs_VERTEX:
1135 {
1136 aPnt = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1137 break;
1138 }
1139 case TopAbs_EDGE: // edge middle point
1140 {
1141 const TopoDS_Edge& anEdge = TopoDS::Edge (aShapeA);
1142 TopoDS_Vertex aVertPair[2];
1143 TopExp::Vertices (anEdge, aVertPair[0], aVertPair[1]);
1144 const gp_Pnt A = BRep_Tool::Pnt (aVertPair[0]);
1145 const gp_Pnt B = BRep_Tool::Pnt (aVertPair[1]);
1146 aPnt = (A.XYZ() + B.XYZ()) / 2;
1147 break;
1148 }
1149 default:
1150 {
1151 Message::SendFail() << "Error: Wrong number of selected shapes.\n"
1152 << "\tYou should select one edge or vertex.";
1153 return 1;
1154 }
7fd59977 1155 }
2ff1d580 1156 }
7fd59977 1157
2ff1d580 1158 if (is2d)
1159 {
1160 aPnt.SetY (-aPnt.Y());
1161 }
1162 Handle(Geom_CartesianPoint ) aGeomPoint = new Geom_CartesianPoint (aPnt);
1163 Handle(AIS_Point) aPointPrs = new AIS_Point (aGeomPoint);
1164 if (is2d)
1165 {
1166 aPointPrs->SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_UPPER));
1167 aPointPrs->SetZLayer (Graphic3d_ZLayerId_TopOSD);
1168 }
1169 ViewerTest::Display (aName, aPointPrs);
1170 if (isNoSel)
1171 {
1172 ViewerTest::GetAISContext()->Deactivate (aPointPrs);
7fd59977 1173 }
1174 return 0;
7fd59977 1175}
1176
1177//==============================================================================
ceae62f0 1178// Function 1st click 2de click 3de click
7fd59977 1179// vplane Vertex Vertex Vertex
1180// Vertex Edge
1181// Edge Vertex
1182// Face
1183// vplanepara Face Vertex
1184// Vertex Face
1185// vplaneortho Face Edge
1186// Edge Face
1187//==============================================================================
1188
1189//==============================================================================
1190//function : VPlaneBuilder
ceae62f0 1191//purpose : Build an AIS_Plane from selected entities or Named AIS components
9e8804b6 1192//Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity]
1193// [PointName] [PointName] [PointName] [TypeOfSensitivity]
1194// [PlaneName] [PointName] [TypeOfSensitivity]
7fd59977 1195//==============================================================================
1196
35e08fe8 1197static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/,
ceae62f0
A
1198 Standard_Integer argc,
1199 const char** argv)
7fd59977 1200{
1201 // Declarations
ceae62f0
A
1202 Standard_Boolean hasArg;
1203 TCollection_AsciiString aName;
7fd59977 1204
1205 // Verification
9e8804b6 1206 if (argc<2 || argc>6 )
ceae62f0 1207 {
23fe70ec 1208 Message::SendFail ("Syntax error: wrong number of arguments");
ceae62f0
A
1209 return 1;
1210 }
9e8804b6 1211 if (argc == 6 || argc==5 || argc==4)
ceae62f0
A
1212 hasArg=Standard_True;
1213 else
1214 hasArg=Standard_False;
7fd59977 1215
ceae62f0 1216 aName=argv[1];
7fd59977 1217
ceae62f0
A
1218 // There are some arguments
1219 if (hasArg)
1220 {
8f521168 1221 Handle(AIS_InteractiveObject) aShapeA;
1222 if (!GetMapOfAIS().Find2 (argv[2], aShapeA))
ceae62f0 1223 {
23fe70ec 1224 Message::SendFail ("Syntax error: 1st name is not displayed");
ceae62f0
A
1225 return 1;
1226 }
7fd59977 1227
ceae62f0
A
1228 // The first argument is an AIS_Point
1229 if (!aShapeA.IsNull() &&
1230 aShapeA->Type()==AIS_KOI_Datum &&
1231 aShapeA->Signature()==1)
1232 {
1233 // The second argument must also be an AIS_Point
8f521168 1234 Handle(AIS_InteractiveObject) aShapeB;
1235 if (argc<5 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
ceae62f0 1236 {
23fe70ec 1237 Message::SendFail ("Syntax error: 2nd name is not displayed");
ceae62f0
A
1238 return 1;
1239 }
ceae62f0
A
1240 // If B is not an AIS_Point
1241 if (aShapeB.IsNull() ||
1242 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1243 {
23fe70ec 1244 Message::SendFail ("Syntax error: 2nd object is expected to be an AIS_Point");
7fd59977 1245 return 1;
1246 }
ceae62f0 1247 // The third object is an AIS_Point
8f521168 1248 Handle(AIS_InteractiveObject) aShapeC;
1249 if (!GetMapOfAIS().Find2(argv[4], aShapeC))
ceae62f0 1250 {
23fe70ec 1251 Message::SendFail ("Syntax error: 3d name is not displayed");
ceae62f0
A
1252 return 1;
1253 }
ceae62f0
A
1254 // If C is not an AIS_Point
1255 if (aShapeC.IsNull() ||
1256 (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
7fd59977 1257 {
23fe70ec 1258 Message::SendFail ("Syntax error: 3d object is expected to be an AIS_Point");
7fd59977 1259 return 1;
1260 }
1261
ceae62f0
A
1262 // Treatment of objects A, B, C
1263 // Downcast an AIS_IO to AIS_Point
1264 Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
1265 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
1266 Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
7fd59977 1267
ceae62f0
A
1268 Handle(Geom_CartesianPoint ) aCartPointA =
1269 Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
7fd59977 1270
ceae62f0
A
1271 Handle(Geom_CartesianPoint ) aCartPointB =
1272 Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
7fd59977 1273
ceae62f0
A
1274 Handle(Geom_CartesianPoint ) aCartPointC =
1275 Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
7fd59977 1276
ceae62f0 1277 // Verification that the three points are different
91322f44 1278 if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
1279 Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1280 Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
ceae62f0 1281 {
7fd59977 1282 // B=A
23fe70ec 1283 Message::SendFail ("Error: same points");
1284 return 1;
7fd59977 1285 }
91322f44 1286 if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
1287 Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
1288 Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
ceae62f0 1289 {
7fd59977 1290 // C=A
23fe70ec 1291 Message::SendFail ("Error: same points");
1292 return 1;
7fd59977 1293 }
91322f44 1294 if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
1295 Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
1296 Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
ceae62f0 1297 {
7fd59977 1298 // C=B
23fe70ec 1299 Message::SendFail ("Error: same points");
1300 return 1;
7fd59977 1301 }
1302
ceae62f0
A
1303 gp_Pnt A = aCartPointA->Pnt();
1304 gp_Pnt B = aCartPointB->Pnt();
1305 gp_Pnt C = aCartPointC->Pnt();
7fd59977 1306
ceae62f0 1307 // Construction of AIS_Plane
7fd59977 1308 GC_MakePlane MkPlane (A,B,C);
ceae62f0
A
1309 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1310 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
1311 GetMapOfAIS().Bind (anAISPlane,aName );
9e8804b6 1312 if (argc == 6)
1313 {
1314 Standard_Integer aType = Draw::Atoi (argv[5]);
1315 if (aType != 0 && aType != 1)
1316 {
23fe70ec 1317 Message::SendFail("Syntax error: wrong type of sensitivity.\n"
1318 "Should be one of the following values:\n"
1319 "0 - Interior\n"
1320 "1 - Boundary");
9e8804b6 1321 return 1;
1322 }
1323 else
1324 {
1325 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1326 }
1327 }
0577ae8c 1328 TheAISContext()->Display (anAISPlane, Standard_True);
7fd59977 1329 }
1330
ceae62f0
A
1331 // The first argument is an AIS_Axis
1332 // Creation of a plane orthogonal to the axis through a point
1333 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
1334 // The second argument should be an AIS_Point
8f521168 1335 Handle(AIS_InteractiveObject) aShapeB;
1336 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
7fd59977 1337 {
23fe70ec 1338 Message::SendFail ("Syntax error: 2d name is not displayed");
7fd59977 1339 return 1;
1340 }
ceae62f0
A
1341 // If B is not an AIS_Point
1342 if (aShapeB.IsNull() ||
1343 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1344 {
23fe70ec 1345 Message::SendFail ("Syntax error: 2d object is expected to be an AIS_Point");
7fd59977 1346 return 1;
1347 }
1348
ceae62f0
A
1349 // Treatment of objects A and B
1350 Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
1351 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
7fd59977 1352
ceae62f0
A
1353 Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
1354 Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
7fd59977 1355
ceae62f0
A
1356 gp_Ax1 anAxis = aGeomLineA->Position();
1357 Handle(Geom_CartesianPoint) aCartPointB =
1358 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
7fd59977 1359
ceae62f0
A
1360 gp_Dir D =anAxis.Direction();
1361 gp_Pnt B = aCartPointB->Pnt();
7fd59977 1362
ceae62f0
A
1363 // Construction of AIS_Plane
1364 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
1365 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
1366 GetMapOfAIS().Bind (anAISPlane,aName );
9e8804b6 1367 if (argc == 5)
1368 {
1369 Standard_Integer aType = Draw::Atoi (argv[4]);
1370 if (aType != 0 && aType != 1)
1371 {
23fe70ec 1372 Message::SendFail ("Syntax error: wrong type of sensitivity!\n"
1373 "Should be one of the following values:\n"
1374 "0 - Interior\n"
1375 "1 - Boundary");
9e8804b6 1376 return 1;
1377 }
1378 else
1379 {
1380 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1381 }
1382 }
0577ae8c 1383 TheAISContext()->Display (anAISPlane, Standard_True);
7fd59977 1384
1385 }
ceae62f0
A
1386 // The first argumnet is an AIS_Plane
1387 // Creation of a plane parallel to the plane passing through the point
1388 else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
1389 {
1390 // The second argument should be an AIS_Point
8f521168 1391 Handle(AIS_InteractiveObject) aShapeB;
1392 if (argc!=4 || !GetMapOfAIS().Find2 (argv[3], aShapeB))
ceae62f0 1393 {
23fe70ec 1394 Message::SendFail ("Syntax error: 2d name is not displayed");
7fd59977 1395 return 1;
1396 }
ceae62f0
A
1397 // B should be an AIS_Point
1398 if (aShapeB.IsNull() ||
1399 (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
7fd59977 1400 {
23fe70ec 1401 Message::SendFail ("Syntax error: 2d object is expected to be an AIS_Point");
7fd59977 1402 return 1;
1403 }
1404
ceae62f0
A
1405 // Treatment of objects A and B
1406 Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
1407 Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
7fd59977 1408
ceae62f0
A
1409 Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
1410 Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
7fd59977 1411
ceae62f0
A
1412 Handle(Geom_CartesianPoint) aCartPointB =
1413 Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
1414 gp_Pnt B= aCartPointB->Pnt();
7fd59977 1415
ceae62f0
A
1416 // Construction of an AIS_Plane
1417 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
1418 GetMapOfAIS().Bind (anAISPlane, aName);
9e8804b6 1419 if (argc == 5)
1420 {
1421 Standard_Integer aType = Draw::Atoi (argv[4]);
1422 if (aType != 0 && aType != 1)
1423 {
23fe70ec 1424 Message::SendFail ("Syntax error: wrong type of sensitivity!\n"
1425 "Should be one of the following values:\n"
1426 "0 - Interior\n"
1427 "1 - Boundary");
9e8804b6 1428 return 1;
1429 }
1430 else
1431 {
1432 anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType));
1433 }
1434 }
0577ae8c 1435 TheAISContext()->Display (anAISPlane, Standard_True);
ceae62f0
A
1436 }
1437 // Error
1438 else
1439 {
23fe70ec 1440 Message::SendFail ("Syntax error: 1st object is not an AIS");
ceae62f0 1441 return 1;
7fd59977 1442 }
7fd59977 1443 }
ceae62f0
A
1444 // There are no arguments
1445 else
1446 {
404c8936 1447 TopTools_ListOfShape aShapes;
1448 ViewerTest::GetSelectedShapes (aShapes);
1449
ceae62f0
A
1450 // Function vplane
1451 // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
1452 if (!strcasecmp(argv[0], "vplane"))
1453 {
404c8936 1454 if (aShapes.Extent() < 1 || aShapes.Extent() > 3)
ceae62f0 1455 {
23fe70ec 1456 Message::SendFail() << "Error: Wront number of selected shapes.\n"
1457 << "\tYou should one of variant: face, edge and vertex or three vertices.";
404c8936 1458 return 1;
7fd59977 1459 }
1460
404c8936 1461 const TopoDS_Shape& aShapeA = aShapes.First();
1462 if (aShapeA.ShapeType() == TopAbs_VERTEX)
ceae62f0 1463 {
404c8936 1464 if (aShapes.Extent() == 2)
ceae62f0 1465 {
404c8936 1466 const TopoDS_Shape& aShapeB = aShapes.Last();
1467 if (aShapeB.ShapeType() != TopAbs_EDGE)
ceae62f0 1468 {
23fe70ec 1469 Message::SendFail ("Syntax error: Together with vertex should be edge.");
ceae62f0 1470 return 1;
7fd59977 1471 }
7fd59977 1472
ceae62f0
A
1473 // Verify that the vertex is not on the edge ShapeB
1474 TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
1475 TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
7fd59977 1476
ceae62f0
A
1477 BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
1478 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1479 {
1480 // The vertex is on the edge
23fe70ec 1481 Message::SendFail ("Error: point is on the edge");
ceae62f0
A
1482 return 1;
1483 }
1484 else
1485 {
ceae62f0
A
1486 gp_Pnt A = BRep_Tool::Pnt(aVertA);
1487 TopoDS_Vertex aVBa, aVBb;
1488 TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
1489 gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
1490 gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
1491 GC_MakePlane MkPlane (A, aBa, aBb);
1492 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1493 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1494 GetMapOfAIS().Bind (anAISPlane, aName);
0577ae8c 1495 TheAISContext()->Display (anAISPlane, Standard_True);
7fd59977 1496 }
7fd59977 1497 }
404c8936 1498 else if (aShapes.Extent() == 3)
1499 {
1500 TopTools_ListOfShape::Iterator anIter (aShapes);
1501
1502 anIter.Next();
1503 const TopoDS_Shape& aShapeB = anIter.Value();
1504
1505 anIter.Next();
1506 const TopoDS_Shape& aShapeC = anIter.Value();
1507
1508 if (!(aShapeB.ShapeType() == TopAbs_VERTEX
1509 && aShapeC.ShapeType() == TopAbs_VERTEX))
1510 {
23fe70ec 1511 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices.");
404c8936 1512 return 1;
1513 }
1514
1515 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
1516 gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
1517 gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
1518 GC_MakePlane MkPlane(A, B, C);
1519 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1520 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1521 GetMapOfAIS().Bind (anAISPlane, aName);
0577ae8c 1522 TheAISContext()->Display (anAISPlane, Standard_True);
404c8936 1523 }
1524 else
1525 {
23fe70ec 1526 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices.");
404c8936 1527 return 1;
1528 }
7fd59977 1529 }
404c8936 1530 else if (aShapeA.ShapeType() == TopAbs_EDGE)
ceae62f0 1531 {
404c8936 1532 if (aShapes.Extent() != 2)
ceae62f0 1533 {
23fe70ec 1534 Message::SendFail ("Error: wrong number of selected shapes.");
404c8936 1535 return 1;
1536 }
1537
1538 const TopoDS_Shape& aShapeB = aShapes.Last();
1539 if (aShapeB.ShapeType() != TopAbs_VERTEX)
1540 {
23fe70ec 1541 Message::SendFail ("Syntax error: Together with edge should be vertex.");
404c8936 1542 return 1;
7fd59977 1543 }
404c8936 1544
ceae62f0
A
1545 // Check that the vertex aShapeB is not on the edge
1546 TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
1547 TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
1548
1549 BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
1550 if (OrthoProj.SquareDistance(1)<Precision::Approximation())
1551 {
1552 // The vertex is on the edge
23fe70ec 1553 Message::SendFail ("Error point is on the edge");
ceae62f0 1554 return 1;
7fd59977 1555 }
404c8936 1556
1557 gp_Pnt B = BRep_Tool::Pnt(aVertB);
1558 TopoDS_Vertex aVAa, aVAb;
1559 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1560 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1561 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1562 GC_MakePlane MkPlane (B,Aa,Ab);
1563 Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
1564 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
1565 GetMapOfAIS().Bind (anAISPlane ,aName);
0577ae8c 1566 TheAISContext()->Display (anAISPlane, Standard_True);
7fd59977 1567 }
404c8936 1568 else if (aShapeA.ShapeType() == TopAbs_FACE)
ceae62f0 1569 {
ceae62f0
A
1570 TopoDS_Face aFace = TopoDS::Face(aShapeA);
1571 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1572 if (aSurface.GetType()==GeomAbs_Plane)
1573 {
1574 gp_Pln aPlane = aSurface.Plane();
1575 Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
1576 Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
1577 GetMapOfAIS().Bind (anAISPlane, aName);
0577ae8c 1578 TheAISContext()->Display (anAISPlane, Standard_True);
7fd59977 1579 }
ceae62f0
A
1580 else
1581 {
23fe70ec 1582 Message::SendFail ("Error: surface is not Plane");
ceae62f0 1583 return 1;
7fd59977 1584 }
7fd59977 1585 }
404c8936 1586 else
1587 {
23fe70ec 1588 Message::SendFail ("Syntax error: You should one of variant: face, edge and vertex or three vertices");
404c8936 1589 return 1;
1590 }
7fd59977 1591 }
1592
ceae62f0 1593 // Function vPlanePara
7fd59977 1594 // ===================
ceae62f0
A
1595 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
1596 else if (!strcasecmp(argv[0], "vplanepara"))
1597 {
404c8936 1598 if (aShapes.Extent() != 2)
ceae62f0 1599 {
23fe70ec 1600 Message::SendFail ("Error: Wrong number of selected shapes.");
404c8936 1601 return 1;
7fd59977 1602 }
1603
404c8936 1604 const TopoDS_Shape* aShapeA = &aShapes.First();
1605 const TopoDS_Shape* aShapeB = &aShapes.Last();
1606 if (aShapeA->ShapeType() != TopAbs_VERTEX)
ceae62f0 1607 {
404c8936 1608 std::swap (aShapeA, aShapeB);
1609 }
7fd59977 1610
404c8936 1611 if (!(aShapeA->ShapeType() == TopAbs_VERTEX
1612 && aShapeB->ShapeType() == TopAbs_FACE))
1613 {
23fe70ec 1614 Message::SendFail ("Syntax error: you should select face and vertex.");
404c8936 1615 return 1;
1616 }
7fd59977 1617
404c8936 1618 gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(*aShapeA));
ceae62f0 1619
404c8936 1620 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1621 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1622 if (aSurface.GetType() == GeomAbs_Plane)
1623 {
1624 gp_Pln aPlane = aSurface.Plane();
1625 // Construct a plane parallel to aGeomPlane through A
1626 aPlane.SetLocation(A);
1627 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1628 Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
1629 GetMapOfAIS().Bind (aAISPlane ,aName);
0577ae8c 1630 TheAISContext()->Display (aAISPlane, Standard_True);
7fd59977 1631 }
ceae62f0
A
1632 else
1633 {
23fe70ec 1634 Message::SendFail ("Error: Builded surface is not a plane.");
404c8936 1635 return 1;
7fd59977 1636 }
7fd59977 1637 }
1638
ceae62f0 1639 // Function vplaneortho
7fd59977 1640 // ====================
ceae62f0
A
1641 // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
1642 else
1643 {
404c8936 1644 if (aShapes.Extent() != 2)
ceae62f0 1645 {
23fe70ec 1646 Message::SendFail ("Error: wrong number of selected shapes.");
404c8936 1647 return 1;
7fd59977 1648 }
1649
404c8936 1650 const TopoDS_Shape* aShapeA = &aShapes.First();
1651 const TopoDS_Shape* aShapeB = &aShapes.Last();
7fd59977 1652
404c8936 1653 if (aShapeA->ShapeType() != TopAbs_EDGE)
1654 {
1655 std::swap (aShapeA, aShapeB);
1656 }
7fd59977 1657
404c8936 1658 if (!(aShapeA->ShapeType() == TopAbs_EDGE
1659 && aShapeB->ShapeType() == TopAbs_FACE))
1660 {
23fe70ec 1661 Message::SendFail ("Error: you should select edge and face.");
404c8936 1662 return 1;
1663 }
ceae62f0 1664
404c8936 1665 // Construction of plane
1666 TopoDS_Edge anEdgeA = TopoDS::Edge(*aShapeA);
1667 TopoDS_Vertex aVAa, aVAb;
1668 TopExp::Vertices(anEdgeA, aVAa, aVAb);
1669 gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
1670 gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
1671 gp_Vec ab (Aa,Ab);
1672
1673 gp_Dir Dab (ab);
1674 // Creation of rotation axis
1675 gp_Ax1 aRotAxis (Aa,Dab);
1676
1677 TopoDS_Face aFace = TopoDS::Face(*aShapeB);
1678 // The edge must be parallel to the face
1679 BRepExtrema_ExtPF aHeightA (aVAa, aFace);
1680 BRepExtrema_ExtPF aHeightB (aVAb, aFace);
1681 // Compare to heights
1682 if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
1683 >Precision::Confusion())
1684 {
1685 // the edge is not parallel to the face
23fe70ec 1686 Message::SendFail ("Error: the edge is not parallel to the face");
404c8936 1687 return 1;
1688 }
1689 // the edge is OK
1690 BRepAdaptor_Surface aSurface (aFace, Standard_False);
1691 if (aSurface.GetType()==GeomAbs_Plane)
1692 {
1693 gp_Pln aPlane = aSurface.Plane();
1694 // It rotates a half turn round the axis of rotation
1695 aPlane.Rotate(aRotAxis , M_PI/2);
1696
1697 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
1698 // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
1699 gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
1700 Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
1701 GetMapOfAIS().Bind (anAISPlane, aName);
0577ae8c 1702 TheAISContext()->Display (anAISPlane, Standard_True);
7fd59977 1703 }
ceae62f0
A
1704 else
1705 {
23fe70ec 1706 Message::SendFail ("Error: surface is not Plane");
404c8936 1707 return 1;
7fd59977 1708 }
7fd59977 1709 }
7fd59977 1710 }
1711 return 0;
7fd59977 1712}
1713
f3889691 1714//===============================================================================================
1715//function : VChangePlane
1716//purpose :
1717//===============================================================================================
1718static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
1719{
1720 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
1721 if (aContextAIS.IsNull())
1722 {
23fe70ec 1723 Message::SendFail ("Error: no active viewer.");
f3889691 1724 return 1;
1725 }
1726
1727 if (theArgsNb < 3 || theArgsNb > 11)
1728 {
23fe70ec 1729 Message::SendFail ("Syntax error: wrong number of arguments.");
f3889691 1730 return 1;
1731 }
1732
1733 TCollection_AsciiString aName (theArgVec[1]);
1734
1735 Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName)
1736 ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName))
1737 : NULL;
1738
1739 if ( aPlane.IsNull() )
1740 {
23fe70ec 1741 Message::SendFail() << "Syntax error: there is no interactive plane with the given name '" << aName << "'.";
f3889691 1742 return 1;
1743 }
1744
1745 Standard_Real aCenterX = aPlane->Center().X();
1746 Standard_Real aCenterY = aPlane->Center().Y();
1747 Standard_Real aCenterZ = aPlane->Center().Z();
1748
1749 Standard_Real aDirX = aPlane->Component()->Axis().Direction().X();
1750 Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y();
1751 Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z();
1752
1753 Standard_Real aSizeX = 0.0;
1754 Standard_Real aSizeY = 0.0;
1755 aPlane->Size (aSizeX, aSizeY);
1756 Standard_Boolean isUpdate = Standard_True;
1757
1758 TCollection_AsciiString aPName, aPValue;
1759 for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
1760 {
1761 const TCollection_AsciiString anArg = theArgVec[anArgIt];
1762 TCollection_AsciiString anArgCase = anArg;
1763 anArgCase.UpperCase();
1764 if (ViewerTest::SplitParameter (anArg, aPName, aPValue))
1765 {
1766 aPName.UpperCase();
1767 if (aPName.IsEqual ("X"))
1768 {
1769 aCenterX = aPValue.RealValue();
1770 }
1771 else if (aPName.IsEqual ("Y"))
1772 {
1773 aCenterY = aPValue.RealValue();
1774 }
1775 else if (aPName.IsEqual ("Z"))
1776 {
1777 aCenterZ = aPValue.RealValue();
1778 }
1779 else if (aPName.IsEqual ("DX"))
1780 {
1781 aDirX = aPValue.RealValue();
1782 }
1783 else if (aPName.IsEqual ("DY"))
1784 {
1785 aDirY = aPValue.RealValue();
1786 }
1787 else if (aPName.IsEqual ("DZ"))
1788 {
1789 aDirZ = aPValue.RealValue();
1790 }
1791 else if (aPName.IsEqual ("SX"))
1792 {
1793 aSizeX = aPValue.RealValue();
1794 }
1795 else if (aPName.IsEqual ("SY"))
1796 {
1797 aSizeY = aPValue.RealValue();
1798 }
1799 }
1800 else if (anArg.IsEqual ("NOUPDATE"))
1801 {
1802 isUpdate = Standard_False;
1803 }
1804 }
1805
1806 gp_Dir aDirection (aDirX, aDirY, aDirZ);
1807 gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ);
1808 aPlane->SetCenter (aCenterPnt);
1809 aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection));
1810 aPlane->SetSize (aSizeX, aSizeY);
1811
f751596e 1812 aContextAIS->Update (aPlane, isUpdate);
f3889691 1813
1814 return 0;
1815}
7fd59977 1816
1817//==============================================================================
1818// Fonction vline
1819// --------------- Uniquement par parametre. Pas de selection dans le viewer.
1820//==============================================================================
1821
1822//==============================================================================
1823//function : VLineBuilder
161c4476 1824//purpose : Build an AIS_Line
7fd59977 1825//Draw arg : vline LineName [AIS_PointName] [AIS_PointName]
1826// [Xa] [Ya] [Za] [Xb] [Yb] [Zb]
1827//==============================================================================
1828#include <Geom_CartesianPoint.hxx>
1829#include <AIS_Line.hxx>
1830
1831
161c4476 1832static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 1833{
7fd59977 1834 // Verifications
586db386 1835 if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct \n";return 1; }
7fd59977 1836
1837 // On recupere les parametres
1838 Handle(AIS_InteractiveObject) theShapeA;
1839 Handle(AIS_InteractiveObject) theShapeB;
1840
1841 // Parametres: AIS_Point AIS_Point
1842 // ===============================
1843 if (argc==4) {
8f521168 1844 GetMapOfAIS().Find2 (argv[2], theShapeA);
7fd59977 1845 // On verifie que c'est bien une AIS_Point
1846 if (!theShapeA.IsNull() &&
1847 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
1848 // on recupere le deuxieme AIS_Point
8f521168 1849 GetMapOfAIS().Find2 (argv[3], theShapeB);
1850 if (theShapeB.IsNull() ||
7fd59977 1851 (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
1852 {
586db386 1853 di <<"vline error: wrong type of 2de argument.\n";
7fd59977 1854 return 1;
1855 }
1856 }
586db386 1857 else {di <<"vline error: wrong type of 1st argument.\n";return 1; }
7fd59977 1858 // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus
c5f3a425 1859 Handle(AIS_Point) theAISPointA= Handle(AIS_Point)::DownCast (theShapeA);
1860 Handle(AIS_Point) theAISPointB= Handle(AIS_Point)::DownCast (theShapeB);
7fd59977 1861
1862 Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component();
c5f3a425 1863 Handle(Geom_CartesianPoint ) myCartPointA= Handle(Geom_CartesianPoint)::DownCast (myGeomPointBA);
7fd59977 1864 // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
1865
1866 Handle(Geom_Point ) myGeomPointB= theAISPointB->Component();
c5f3a425 1867 Handle(Geom_CartesianPoint ) myCartPointB= Handle(Geom_CartesianPoint)::DownCast (myGeomPointB);
7fd59977 1868 // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
1869
1870 if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
1871 // B=A
586db386 1872 di<<"vline error: same points\n";return 1;
7fd59977 1873 }
1874 // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB)
1875 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1876 GetMapOfAIS().Bind(theAISLine,argv[1] );
0577ae8c 1877 TheAISContext()->Display (theAISLine, Standard_True);
7fd59977 1878
1879 }
1880
1881 // Parametres 6 Reals
1882 // ==================
1883
1884 else if (argc==8) {
161c4476 1885 // On verifie que les deux points ne sont pas confondus
7fd59977 1886
1887 Standard_Real coord[6];
1888 for(Standard_Integer i=0;i<=2;i++){
91322f44 1889 coord[i]=Draw::Atof(argv[2+i]);
1890 coord[i+3]=Draw::Atof(argv[5+i]);
7fd59977 1891 }
1892
1893 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] );
1894 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] );
1895
1896 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1897 GetMapOfAIS().Bind(theAISLine,argv[1] );
0577ae8c 1898 TheAISContext()->Display (theAISLine, Standard_True);
7fd59977 1899
1900 }
1901
1902 // Pas de parametres: Selection dans le viewer.
1903 // ============================================
1904
404c8936 1905 else
1906 {
1907 TopTools_ListOfShape aShapes;
1908 ViewerTest::GetSelectedShapes (aShapes);
1909 if (aShapes.Extent() != 2)
1910 {
23fe70ec 1911 Message::SendFail ("Error: wrong number of selected shapes.");
404c8936 1912 return 1;
7fd59977 1913 }
1914
404c8936 1915 const TopoDS_Shape& aShapeA = aShapes.First();
1916 const TopoDS_Shape& aShapeB = aShapes.Last();
7fd59977 1917
404c8936 1918 if (!(aShapeA.ShapeType() == TopAbs_VERTEX
1919 && aShapeB.ShapeType() == TopAbs_VERTEX))
1920 {
23fe70ec 1921 Message::SendFail ("Error: you should select two different vertex.");
404c8936 1922 return 1;
1923 }
7fd59977 1924
404c8936 1925 // Construction de la line
1926 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
1927 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
7fd59977 1928
404c8936 1929 Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A);
1930 Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B);
7fd59977 1931
404c8936 1932 Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB );
1933 GetMapOfAIS().Bind(theAISLine,argv[1] );
0577ae8c 1934 TheAISContext()->Display (theAISLine, Standard_True);
7fd59977 1935 }
1936
1937 return 0;
1938}
1939
329843e2
A
1940//==============================================================================
1941// class : FilledCircle
1942// purpose : creates filled circle based on AIS_InteractiveObject
1943// and Geom_Circle.
1944// This class is used to check method Matches() of class
1945// Select3D_SensitiveCircle with member myFillStatus = Standard_True,
1946// because none of AIS classes provides creation of
1947// Select3D_SensitiveCircle with member myFillStatus = Standard_True
1948// (look method ComputeSelection() )
1949//==============================================================================
1950
1951Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius)
1952{
1953 gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.)));
1954 gp_Circ aCirc(anAxes, theRadius);
1955 Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc);
1956 return aCircle;
1957}
1958
329843e2
A
1959class FilledCircle : public AIS_InteractiveObject
1960{
1961public:
1962 // CASCADE RTTI
92efcf78 1963 DEFINE_STANDARD_RTTI_INLINE(FilledCircle,AIS_InteractiveObject);
329843e2
A
1964
1965 FilledCircle(gp_Pnt theCenter, Standard_Real theRadius);
1966 FilledCircle(Handle(Geom_Circle) theCircle);
1967
1968private:
1969 TopoDS_Face ComputeFace();
1970
1971 // Virtual methods implementation
1972 void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
1973 const Handle(Prs3d_Presentation)& thePresentation,
79104795 1974 const Standard_Integer theMode) Standard_OVERRIDE;
329843e2
A
1975
1976 void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
79104795 1977 const Standard_Integer theMode) Standard_OVERRIDE;
329843e2
A
1978
1979protected:
1980 Handle(Geom_Circle) myCircle;
1981 Standard_Boolean myFilledStatus;
1982
1983};
1984
329843e2
A
1985
1986FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius)
1987{
1988 myCircle = CreateCircle(theCenter, theRadius);
1989 myFilledStatus = Standard_True;
1990}
1991
1992FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle)
1993{
1994 myCircle = theCircle;
1995 myFilledStatus = Standard_True;
1996}
1997
1998TopoDS_Face FilledCircle::ComputeFace()
1999{
2000 // Create edge from myCircle
2001 BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ());
2002 TopoDS_Edge anEdge = anEdgeMaker.Edge();
2003
2004 // Create wire from anEdge
2005 BRepBuilderAPI_MakeWire aWireMaker(anEdge);
2006 TopoDS_Wire aWire = aWireMaker.Wire();
2007
2008 // Create face from aWire
2009 BRepBuilderAPI_MakeFace aFaceMaker(aWire);
2010 TopoDS_Face aFace = aFaceMaker.Face();
2011
2012 return aFace;
2013}
2014
857ffd5e 2015void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/,
2016 const Handle(Prs3d_Presentation) &thePresentation,
329843e2
A
2017 const Standard_Integer theMode)
2018{
2019 thePresentation->Clear();
2020
2021 TopoDS_Face aFace = ComputeFace();
2022
2023 if (aFace.IsNull()) return;
2024 if (theMode != 0) return;
2025
2026 StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
2027}
2028
857ffd5e 2029void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection,
35e08fe8 2030 const Standard_Integer /*theMode*/)
329843e2
A
2031{
2032 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
7f24b768 2033 Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle (anEntityOwner, myCircle->Circ(), myFilledStatus);
329843e2
A
2034 theSelection->Add(aSensitiveCircle);
2035}
7fd59977 2036
2037//==============================================================================
2038// Fonction vcircle
2039// ----------------- Uniquement par parametre. Pas de selection dans le viewer.
2040//==============================================================================
2041
2042//==============================================================================
2043//function : VCircleBuilder
161c4476 2044//purpose : Build an AIS_Circle
329843e2
A
2045//Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled
2046// PointName PointName PointName IsFilled
7fd59977 2047//==============================================================================
329843e2
A
2048
2049void DisplayCircle (Handle (Geom_Circle) theGeomCircle,
2050 TCollection_AsciiString theName,
2051 Standard_Boolean isFilled)
2052{
2053 Handle(AIS_InteractiveObject) aCircle;
2054 if (isFilled)
2055 {
2056 aCircle = new FilledCircle(theGeomCircle);
2057 }
2058 else
2059 {
2060 aCircle = new AIS_Circle(theGeomCircle);
9e8804b6 2061 Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False);
329843e2
A
2062 }
2063
2064 // Check if there is an object with given name
2065 // and remove it from context
2066 if (GetMapOfAIS().IsBound2(theName))
2067 {
8f521168 2068 Handle(AIS_InteractiveObject) anInterObj = GetMapOfAIS().Find2(theName);
329843e2
A
2069 TheAISContext()->Remove(anInterObj, Standard_False);
2070 GetMapOfAIS().UnBind2(theName);
2071 }
2072
2073 // Bind the circle to its name
2074 GetMapOfAIS().Bind(aCircle, theName);
2075
2076 // Display the circle
0577ae8c 2077 TheAISContext()->Display (aCircle, Standard_True);
329843e2
A
2078
2079}
7fd59977 2080
35e08fe8 2081static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
7fd59977 2082{
329843e2
A
2083 // Verification of the arguments
2084 if (argc>6 || argc<2)
2085 {
23fe70ec 2086 Message::SendFail ("Syntax error: wrong number of arguments");
2087 return 1;
329843e2 2088 }
7fd59977 2089
329843e2
A
2090 // There are all arguments
2091 if (argc == 6)
2092 {
2093 // Get arguments
2094 TCollection_AsciiString aName(argv[1]);
dde68833 2095 Standard_Boolean isFilled = Draw::Atoi(argv[5]) != 0;
329843e2 2096
8f521168 2097 Handle(AIS_InteractiveObject) theShapeA, theShapeB;
2098 GetMapOfAIS().Find2 (argv[2], theShapeA);
2099 GetMapOfAIS().Find2 (argv[3], theShapeB);
7fd59977 2100
2101 // Arguments: AIS_Point AIS_Point AIS_Point
2102 // ========================================
329843e2 2103 if (!theShapeA.IsNull() && !theShapeB.IsNull() &&
7fd59977 2104 theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1)
2105 {
329843e2
A
2106 if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 )
2107 {
23fe70ec 2108 Message::SendFail ("Error: 2d argument is unexpected to be a point");
2109 return 1;
7fd59977 2110 }
329843e2 2111 // The third object must be a point
8f521168 2112 Handle(AIS_InteractiveObject) theShapeC;
2113 GetMapOfAIS().Find2 (argv[4], theShapeC);
7fd59977 2114 if (theShapeC.IsNull() ||
329843e2
A
2115 theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 )
2116 {
23fe70ec 2117 Message::SendFail ("Error: 3d argument is unexpected to be a point");
2118 return 1;
329843e2 2119 }
7fd59977 2120 // tag
329843e2
A
2121 // Verify that the three points are different
2122 Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA);
2123 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
2124 Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC);
2125
2126 Handle(Geom_Point) myGeomPointA = theAISPointA->Component();
2127 Handle(Geom_CartesianPoint) myCartPointA =
2128 Handle(Geom_CartesianPoint)::DownCast(myGeomPointA);
2129
2130 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2131 Handle(Geom_CartesianPoint) myCartPointB =
2132 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
2133
2134 Handle(Geom_Point) myGeomPointC = theAISPointC->Component();
2135 Handle(Geom_CartesianPoint) myCartPointC =
2136 Handle(Geom_CartesianPoint)::DownCast(myGeomPointC);
7fd59977 2137
2138 // Test A=B
91322f44 2139 if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() &&
2140 Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() &&
2141 Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() )
329843e2 2142 {
23fe70ec 2143 Message::SendFail ("Error: Same points");
2144 return 1;
7fd59977 2145 }
2146 // Test A=C
91322f44 2147 if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() &&
2148 Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2149 Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() )
329843e2 2150 {
23fe70ec 2151 Message::SendFail ("Error: Same points");
2152 return 1;
7fd59977 2153 }
2154 // Test B=C
91322f44 2155 if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() &&
2156 Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() &&
2157 Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() )
329843e2 2158 {
23fe70ec 2159 Message::SendFail ("Error: Same points");
2160 return 1;
7fd59977 2161 }
329843e2
A
2162 // Construction of the circle
2163 GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(),
2164 myCartPointB->Pnt(), myCartPointC->Pnt() );
2165 Handle (Geom_Circle) theGeomCircle;
2166 try
2167 {
2168 theGeomCircle = Cir.Value();
2169 }
a738b534 2170 catch (StdFail_NotDone const&)
329843e2 2171 {
23fe70ec 2172 Message::SendFail ("Error: can't create circle");
2173 return -1;
329843e2 2174 }
23fe70ec 2175
329843e2 2176 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2177 }
2178
329843e2 2179 // Arguments: AIS_Plane AIS_Point Real
7fd59977 2180 // ===================================
329843e2
A
2181 else if (theShapeA->Type() == AIS_KOI_Datum &&
2182 theShapeA->Signature() == 7 )
2183 {
2184 if (theShapeB->Type() != AIS_KOI_Datum ||
2185 theShapeB->Signature() != 1 )
2186 {
23fe70ec 2187 Message::SendFail ("Error: 2d element is a unexpected to be a point");
2188 return 1;
329843e2 2189 }
623c29a5 2190 // Check that the radius is >= 0
91322f44 2191 if (Draw::Atof(argv[4]) <= 0 )
329843e2 2192 {
23fe70ec 2193 Message::SendFail ("Syntax error: the radius must be >=0");
2194 return 1;
7fd59977 2195 }
7fd59977 2196
329843e2
A
2197 // Recover the normal to the plane
2198 Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA);
2199 Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB);
7fd59977 2200
329843e2
A
2201 Handle(Geom_Plane) myGeomPlane = theAISPlane->Component();
2202 Handle(Geom_Point) myGeomPointB = theAISPointB->Component();
2203 Handle(Geom_CartesianPoint) myCartPointB =
2204 Handle(Geom_CartesianPoint)::DownCast(myGeomPointB);
7fd59977 2205
2206 gp_Pln mygpPlane = myGeomPlane->Pln();
2207 gp_Ax1 thegpAxe = mygpPlane.Axis();
2208 gp_Dir theDir = thegpAxe.Direction();
329843e2 2209 gp_Pnt theCenter = myCartPointB->Pnt();
91322f44 2210 Standard_Real TheR = Draw::Atof(argv[4]);
329843e2
A
2211 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR);
2212 Handle (Geom_Circle) theGeomCircle;
2213 try
2214 {
2215 theGeomCircle = Cir.Value();
2216 }
a738b534 2217 catch (StdFail_NotDone const&)
329843e2 2218 {
23fe70ec 2219 Message::SendFail ("Error: can't create circle");
2220 return -1;
329843e2
A
2221 }
2222
2223 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2224
2225 }
2226
2227 // Error
329843e2
A
2228 else
2229 {
23fe70ec 2230 Message::SendFail ("Error: 1st argument has an unexpected type");
2231 return 1;
7fd59977 2232 }
2233
2234 }
329843e2 2235 // No arguments: selection in the viewer
7fd59977 2236 // =========================================
329843e2
A
2237 else
2238 {
2239 // Get the name of the circle
2240 TCollection_AsciiString aName(argv[1]);
7fd59977 2241
404c8936 2242 TopTools_ListOfShape aShapes;
2243 ViewerTest::GetSelectedShapes (aShapes);
2244 if (aShapes.Extent() != 3 && aShapes.Extent() != 2)
329843e2 2245 {
23fe70ec 2246 Message::SendFail ("Error: Wrong number of selected shapes.");
404c8936 2247 return 1;
7fd59977 2248 }
2249
404c8936 2250 const TopoDS_Shape& aShapeA = aShapes.First();
2251 if (aShapeA.ShapeType() == TopAbs_VERTEX )
329843e2 2252 {
404c8936 2253 if (aShapes.Extent() != 3)
329843e2 2254 {
23fe70ec 2255 Message::SendFail ("Error: wrong number of selected shapes.");
404c8936 2256 return 1;
2257 }
7fd59977 2258
404c8936 2259 TopTools_ListOfShape::Iterator anIter (aShapes);
2260
2261 anIter.Next();
2262 const TopoDS_Shape& aShapeB = anIter.Value();
2263
2264 anIter.Next();
2265 const TopoDS_Shape& aShapeC = anIter.Value();
329843e2
A
2266
2267 // Get isFilled
2268 Standard_Boolean isFilled;
2269 std::cout << "Enter filled status (0 or 1)\n";
04232180 2270 std::cin >> isFilled;
7fd59977 2271
329843e2 2272 // Construction of the circle
404c8936 2273 gp_Pnt A = BRep_Tool::Pnt (TopoDS::Vertex (aShapeA));
2274 gp_Pnt B = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
2275 gp_Pnt C = BRep_Tool::Pnt (TopoDS::Vertex (aShapeC));
329843e2
A
2276
2277 GC_MakeCircle Cir = GC_MakeCircle (A, B, C);
2278 Handle (Geom_Circle) theGeomCircle;
2279 try
2280 {
2281 theGeomCircle = Cir.Value();
2282 }
a738b534 2283 catch (StdFail_NotDone const&)
329843e2 2284 {
23fe70ec 2285 Message::SendFail ("Error: can't create circle");
2286 return -1;
329843e2 2287 }
7fd59977 2288
329843e2 2289 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2290
2291 }
404c8936 2292 else if (aShapeA.ShapeType() == TopAbs_FACE)
329843e2 2293 {
404c8936 2294 const TopoDS_Shape& aShapeB = aShapes.Last();
7fd59977 2295
329843e2
A
2296 // Recover the radius
2297 Standard_Real theRad;
2298 do
2299 {
2300 std::cout << " Enter the value of the radius:\n";
04232180 2301 std::cin >> theRad;
329843e2
A
2302 } while (theRad <= 0);
2303
2304 // Get filled status
2305 Standard_Boolean isFilled;
2306 std::cout << "Enter filled status (0 or 1)\n";
04232180 2307 std::cin >> isFilled;
7fd59977 2308
329843e2 2309 // Recover the normal to the plane. tag
404c8936 2310 TopoDS_Face myFace = TopoDS::Face(aShapeA);
329843e2
A
2311 BRepAdaptor_Surface mySurface (myFace, Standard_False);
2312 gp_Pln myPlane = mySurface.Plane();
2313 Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane);
7fd59977 2314 gp_Pln mygpPlane = theGeomPlane->Pln();
2315 gp_Ax1 thegpAxe = mygpPlane.Axis();
2316 gp_Dir theDir = thegpAxe.Direction();
2317
329843e2 2318 // Recover the center
404c8936 2319 gp_Pnt theCenter = BRep_Tool::Pnt (TopoDS::Vertex (aShapeB));
7fd59977 2320
623c29a5 2321 // Construct the circle
329843e2
A
2322 GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad);
2323 Handle (Geom_Circle) theGeomCircle;
2324 try
2325 {
2326 theGeomCircle = Cir.Value();
2327 }
a738b534 2328 catch (StdFail_NotDone const&)
329843e2 2329 {
23fe70ec 2330 Message::SendFail ("Error: can't create circle");
2331 return -1;
329843e2 2332 }
7fd59977 2333
329843e2 2334 DisplayCircle(theGeomCircle, aName, isFilled);
7fd59977 2335 }
404c8936 2336 else
2337 {
23fe70ec 2338 Message::SendFail ("Error: You should select face and vertex or three vertices.");
404c8936 2339 return 1;
2340 }
7fd59977 2341 }
2342
2343 return 0;
2344}
2345
29e2c6d2 2346//=======================================================================
7fd59977 2347//function : VDrawText
29e2c6d2 2348//purpose :
2349//=======================================================================
2350static int VDrawText (Draw_Interpretor& theDI,
2351 Standard_Integer theArgsNb,
2352 const char** theArgVec)
7fd59977 2353{
29e2c6d2 2354 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
2355 if (theArgsNb < 3)
fe551aef 2356 {
23fe70ec 2357 Message::SendFail ("Syntax error: wrong number of arguments. See usage:");
29e2c6d2 2358 theDI.PrintHelp (theArgVec[0]);
2359 return 1;
2360 }
2361 else if (aContext.IsNull())
2362 {
23fe70ec 2363 Message::SendFail ("Error: no active viewer");
29e2c6d2 2364 return 1;
fe551aef 2365 }
2366
29e2c6d2 2367 Standard_Integer anArgIt = 1;
2368 TCollection_ExtendedString aName (theArgVec[anArgIt++], Standard_True);
2369 TCollection_ExtendedString aText (theArgVec[anArgIt++], Standard_True);
2370 Handle(AIS_TextLabel) aTextPrs;
2371 ViewerTest_AutoUpdater anAutoUpdater (aContext, ViewerTest::CurrentView());
7fd59977 2372
1beb58d7 2373 Standard_Boolean isNewPrs = Standard_False;
29e2c6d2 2374 if (GetMapOfAIS().IsBound2 (aName))
7fd59977 2375 {
1beb58d7 2376 aTextPrs = Handle(AIS_TextLabel)::DownCast (GetMapOfAIS().Find2 (aName));
29e2c6d2 2377 }
1beb58d7 2378
2379 if (aTextPrs.IsNull())
29e2c6d2 2380 {
1beb58d7 2381 isNewPrs = Standard_True;
29e2c6d2 2382 aTextPrs = new AIS_TextLabel();
2383 aTextPrs->SetFont ("Courier");
7fd59977 2384 }
13a22457 2385
29e2c6d2 2386 aTextPrs->SetText (aText);
13a22457 2387
778cd667 2388 Handle(Graphic3d_TransformPers) aTrsfPers;
61b0191c 2389 Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL;
2390
ce01ec26 2391 Standard_Boolean aHasPlane = Standard_False;
2392 gp_Dir aNormal;
2393 gp_Dir aDirection;
2394 gp_Pnt aPos;
2395
60f7b225 2396
2397 Handle(Font_TextFormatter) aTextFormatter;
29e2c6d2 2398 for (; anArgIt < theArgsNb; ++anArgIt)
161c4476 2399 {
29e2c6d2 2400 TCollection_AsciiString aParam (theArgVec[anArgIt]);
2401 aParam.LowerCase();
2402
2403 if (anAutoUpdater.parseRedrawMode (aParam))
13a22457 2404 {
29e2c6d2 2405 continue;
13a22457 2406 }
29e2c6d2 2407 else if (aParam == "-pos"
2408 || aParam == "-position")
2409 {
2410 if (anArgIt + 3 >= theArgsNb)
2411 {
23fe70ec 2412 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'";
29e2c6d2 2413 return 1;
2414 }
7fd59977 2415
29e2c6d2 2416 aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
2417 aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
2418 aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
2419 aTextPrs->SetPosition (aPos);
2420 }
2421 else if (aParam == "-color")
2422 {
9196ea9d 2423 Quantity_Color aColor;
dae2a922 2424 Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1,
2425 theArgVec + anArgIt + 1,
2426 aColor);
9196ea9d 2427 if (aNbParsed == 0)
29e2c6d2 2428 {
23fe70ec 2429 Message::SendFail() << "Syntax error at '" << aParam << "'";
29e2c6d2 2430 return 1;
2431 }
9196ea9d 2432 anArgIt += aNbParsed;
2433 aTextPrs->SetColor (aColor);
29e2c6d2 2434 }
2435 else if (aParam == "-halign")
2436 {
2437 if (++anArgIt >= theArgsNb)
2438 {
23fe70ec 2439 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'";
29e2c6d2 2440 return 1;
2441 }
13a22457 2442
29e2c6d2 2443 TCollection_AsciiString aType (theArgVec[anArgIt]);
2444 aType.LowerCase();
2445 if (aType == "left")
2446 {
2447 aTextPrs->SetHJustification (Graphic3d_HTA_LEFT);
2448 }
2449 else if (aType == "center")
2450 {
2451 aTextPrs->SetHJustification (Graphic3d_HTA_CENTER);
2452 }
2453 else if (aType == "right")
2454 {
2455 aTextPrs->SetHJustification (Graphic3d_HTA_RIGHT);
2456 }
2457 else
2458 {
23fe70ec 2459 Message::SendFail() << "Syntax error at '" << aParam << "'";
29e2c6d2 2460 return 1;
2461 }
2462 }
2463 else if (aParam == "-valign")
2464 {
2465 if (++anArgIt >= theArgsNb)
2466 {
23fe70ec 2467 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
29e2c6d2 2468 return 1;
2469 }
2470
2471 TCollection_AsciiString aType (theArgVec[anArgIt]);
2472 aType.LowerCase();
2473 if (aType == "top")
2474 {
2475 aTextPrs->SetVJustification (Graphic3d_VTA_TOP);
2476 }
2477 else if (aType == "center")
2478 {
2479 aTextPrs->SetVJustification (Graphic3d_VTA_CENTER);
2480 }
2481 else if (aType == "bottom")
2482 {
2483 aTextPrs->SetVJustification (Graphic3d_VTA_BOTTOM);
2484 }
ac84fcf6 2485 else if (aType == "topfirstline")
2486 {
2487 aTextPrs->SetVJustification (Graphic3d_VTA_TOPFIRSTLINE);
2488 }
29e2c6d2 2489 else
2490 {
23fe70ec 2491 Message::SendFail() << "Syntax error at '" << aParam << "'";
29e2c6d2 2492 return 1;
2493 }
2494 }
2495 else if (aParam == "-angle")
2496 {
2497 if (++anArgIt >= theArgsNb)
2498 {
23fe70ec 2499 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
29e2c6d2 2500 return 1;
2501 }
13a22457 2502
29e2c6d2 2503 aTextPrs->SetAngle (Draw::Atof (theArgVec[anArgIt]) * (M_PI / 180.0));
2504 }
2505 else if (aParam == "-zoom")
2506 {
2507 if (++anArgIt >= theArgsNb)
2508 {
23fe70ec 2509 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
29e2c6d2 2510 return 1;
2511 }
13a22457 2512
29e2c6d2 2513 aTextPrs->SetZoomable (Draw::Atoi (theArgVec[anArgIt]) == 1);
2514 }
2515 else if (aParam == "-height")
2516 {
2517 if (++anArgIt >= theArgsNb)
2518 {
23fe70ec 2519 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
29e2c6d2 2520 return 1;
2521 }
13a22457 2522
29e2c6d2 2523 aTextPrs->SetHeight (Draw::Atof(theArgVec[anArgIt]));
2524 }
60f7b225 2525 else if (aParam == "-wrapping")
2526 {
2527 if (++anArgIt >= theArgsNb)
2528 {
2529 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
2530 return 1;
2531 }
2532
2533 if (aTextFormatter.IsNull())
2534 {
2535 aTextFormatter = new Font_TextFormatter();
2536 }
2537 aTextFormatter->SetWrapping ((Standard_ShortReal)Draw::Atof(theArgVec[anArgIt]));
2538 }
29e2c6d2 2539 else if (aParam == "-aspect")
2540 {
2541 if (++anArgIt >= theArgsNb)
2542 {
23fe70ec 2543 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
29e2c6d2 2544 return 1;
2545 }
13a22457 2546
29e2c6d2 2547 TCollection_AsciiString anOption (theArgVec[anArgIt]);
2548 anOption.LowerCase();
5b377041 2549 Font_FontAspect aFontAspect = Font_FA_Undefined;
2550 if (!parseFontStyle (anOption, aFontAspect))
29e2c6d2 2551 {
23fe70ec 2552 Message::SendFail() << "Syntax error: unknown font aspect '" << anOption << "'";
5b377041 2553 return 1;
29e2c6d2 2554 }
5b377041 2555 aTextPrs->SetFontAspect (aFontAspect);
29e2c6d2 2556 }
2557 else if (aParam == "-font")
2558 {
2559 if (++anArgIt >= theArgsNb)
2560 {
23fe70ec 2561 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
29e2c6d2 2562 return 1;
2563 }
13a22457 2564
29e2c6d2 2565 aTextPrs->SetFont (theArgVec[anArgIt]);
2566 }
ce01ec26 2567 else if (aParam == "-plane")
2568 {
2569 if (anArgIt + 6 >= theArgsNb)
2570 {
23fe70ec 2571 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
ce01ec26 2572 return 1;
2573 }
2574
2575 Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]);
2576 Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]);
2577 Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]);
2578 aNormal.SetCoord (aX, aY, aZ);
2579
2580 aX = Draw::Atof (theArgVec[++anArgIt]);
2581 aY = Draw::Atof (theArgVec[++anArgIt]);
2582 aZ = Draw::Atof (theArgVec[++anArgIt]);
2583 aDirection.SetCoord (aX, aY, aZ);
2584
2585 aHasPlane = Standard_True;
2586 }
3f1eb0ab 2587 else if (aParam == "-flipping")
2588 {
2589 aTextPrs->SetFlipping (Standard_True);
2590 }
ab9e277f 2591 else if (aParam == "-ownanchor")
2592 {
2593 if (++anArgIt >= theArgsNb)
2594 {
2595 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
2596 return 1;
2597 }
2598 aTextPrs->SetOwnAnchorPoint (Draw::Atoi (theArgVec[anArgIt]) == 1);
2599 }
61b0191c 2600 else if (aParam == "-disptype"
2601 || aParam == "-displaytype")
2602 {
2603 if (++anArgIt >= theArgsNb)
2604 {
23fe70ec 2605 Message::SendFail() << "Syntax error: wrong number of values for parameter '" << aParam << "'";
61b0191c 2606 return 1;
2607 }
2608 TCollection_AsciiString aType (theArgVec[anArgIt]);
2609 aType.LowerCase();
2610 if (aType == "subtitle")
2611 aDisplayType = Aspect_TODT_SUBTITLE;
2612 else if (aType == "decal")
2613 aDisplayType = Aspect_TODT_DEKALE;
2614 else if (aType == "blend")
2615 aDisplayType = Aspect_TODT_BLEND;
2616 else if (aType == "dimension")
2617 aDisplayType = Aspect_TODT_DIMENSION;
2618 else if (aType == "normal")
2619 aDisplayType = Aspect_TODT_NORMAL;
3cbd0a8e 2620 else if (aType == "shadow")
2621 aDisplayType = Aspect_TODT_SHADOW;
61b0191c 2622 else
2623 {
23fe70ec 2624 Message::SendFail() << "Syntax error: wrong display type '" << aType << "'";
61b0191c 2625 return 1;
2626 }
2627 }
2628 else if (aParam == "-subcolor"
2629 || aParam == "-subtitlecolor")
2630 {
9196ea9d 2631 Quantity_Color aColor;
dae2a922 2632 Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1,
2633 theArgVec + anArgIt + 1,
2634 aColor);
9196ea9d 2635 if (aNbParsed == 0)
61b0191c 2636 {
23fe70ec 2637 Message::SendFail() << "Syntax error at '" << aParam << "'";
61b0191c 2638 return 1;
2639 }
9196ea9d 2640 anArgIt += aNbParsed;
2641 aTextPrs->SetColorSubTitle (aColor);
61b0191c 2642 }
2643 else if (aParam == "-2d")
2644 {
778cd667 2645 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d);
61b0191c 2646 }
2647 else if (aParam == "-trsfperspos"
2648 || aParam == "-perspos")
2649 {
2650 if (anArgIt + 2 >= theArgsNb)
2651 {
23fe70ec 2652 Message::SendFail() << "Error: wrong number of values for parameter '" << aParam << "'.";
61b0191c 2653 return 1;
2654 }
2655
2656 TCollection_AsciiString aX (theArgVec[++anArgIt]);
2657 TCollection_AsciiString aY (theArgVec[++anArgIt]);
2658 TCollection_AsciiString aZ = "0";
2659 if (!aX.IsIntegerValue()
2660 || !aY.IsIntegerValue())
2661 {
23fe70ec 2662 Message::SendFail() << "Error: wrong syntax at '" << aParam << "'.";
61b0191c 2663 return 1;
2664 }
2665 if (anArgIt + 1 < theArgsNb)
2666 {
2667 TCollection_AsciiString aTemp = theArgVec[anArgIt + 1];
2668 if (aTemp.IsIntegerValue())
2669 {
2670 aZ = aTemp;
2671 ++anArgIt;
2672 }
2673 }
778cd667 2674
2675 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()));
61b0191c 2676 }
29e2c6d2 2677 else
2678 {
23fe70ec 2679 Message::SendFail() << "Syntax error: unknown argument '" << aParam << "'";
29e2c6d2 2680 return 1;
2681 }
13a22457
S
2682 }
2683
60f7b225 2684 aTextPrs->SetTextFormatter (aTextFormatter);
2685
ce01ec26 2686 if (aHasPlane)
2687 {
2688 aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
2689 }
2690
284c9238 2691 aTextPrs->SetDisplayType (aDisplayType);
2692
778cd667 2693 if (!aTrsfPers.IsNull())
61b0191c 2694 {
778cd667 2695 aContext->SetTransformPersistence (aTextPrs, aTrsfPers);
61b0191c 2696 aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD);
ce01ec26 2697 if (aTextPrs->Position().Z() != 0)
61b0191c 2698 {
ce01ec26 2699 aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0));
61b0191c 2700 }
2701 }
778cd667 2702 else if (!aTextPrs->TransformPersistence().IsNull())
61b0191c 2703 {
778cd667 2704 aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)());
61b0191c 2705 }
1beb58d7 2706
2707 if (isNewPrs)
2708 {
2709 ViewerTest::Display (aName, aTextPrs, Standard_False);
2710 }
2711 else
2712 {
2713 aContext->Redisplay (aTextPrs, Standard_False, Standard_True);
2714 }
161c4476 2715 return 0;
7fd59977 2716}
2717
2718#include <math.h>
2719#include <gp_Pnt.hxx>
2720#include <Graphic3d_ArrayOfPoints.hxx>
2721#include <Graphic3d_ArrayOfPrimitives.hxx>
7fd59977 2722#include <Graphic3d_ArrayOfTriangles.hxx>
2723#include <Poly_Array1OfTriangle.hxx>
2724#include <Poly_Triangle.hxx>
2725#include <Poly_Triangulation.hxx>
2726#include <TColgp_Array1OfPnt.hxx>
2727#include <TShort_Array1OfShortReal.hxx>
2728#include <TShort_HArray1OfShortReal.hxx>
2729
2730#include <AIS_Triangulation.hxx>
5ad8c033 2731#include <StdPrs_ToolTriangulatedShape.hxx>
7fd59977 2732#include <Poly_Connect.hxx>
2733#include <TColgp_Array1OfDir.hxx>
2734#include <Graphic3d_GraphicDriver.hxx>
2735
7fd59977 2736#include <TColStd_Array1OfInteger.hxx>
2737#include <TColStd_HArray1OfInteger.hxx>
2738#include <Prs3d_ShadingAspect.hxx>
2739#include <Graphic3d_MaterialAspect.hxx>
2740#include <Graphic3d_AspectFillArea3d.hxx>
2741
2742#include <BRepPrimAPI_MakeCylinder.hxx>
2743#include <TopoDS_Shape.hxx>
2744#include <TopExp_Explorer.hxx>
2745#include <TopAbs.hxx>
ec357c5c 2746#include <AIS_InteractiveObject.hxx>
7fd59977 2747
2748
2749//===============================================================================================
2750//function : CalculationOfSphere
2751//author : psn
2752//purpose : Create a Sphere
2753//===============================================================================================
2754
161c4476 2755Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z ,
7fd59977 2756 int res ,
2757 double Radius ){
2758 double mRadius = Radius;
2759 double mCenter[3] = {X,Y,Z};
2760 int mThetaResolution;
2761 int mPhiResolution;
2762 double mStartTheta = 0;//StartTheta;
2763 double mEndTheta = 360;//EndTheta;
2764 double mStartPhi = 0;//StartPhi;
2765 double mEndPhi = 180;//EndPhi;
2766 res = res < 4 ? 4 : res;
2767
2768 mThetaResolution = res;
2769 mPhiResolution = res;
2770
2771 int i, j;
2772 int jStart, jEnd, numOffset;
7fd59977 2773 double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius;
2774 double startTheta, endTheta, startPhi, endPhi;
2775 int base, numPoles=0, thetaResolution, phiResolution;
2776
2777 int pts[3];
2778 int piece = -1;
2779 int numPieces = 1;
2780 if ( numPieces > mThetaResolution ) {
2781 numPieces = mThetaResolution;
2782 }
2783
2784 int localThetaResolution = mThetaResolution;
2785 double localStartTheta = mStartTheta;
2786 double localEndTheta = mEndTheta;
2787
2788 while ( localEndTheta < localStartTheta ) {
2789 localEndTheta += 360.0;
2790 }
2791
2792 deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution;
2793
2794 // Change the ivars based on pieces.
2795 int start, end;
2796 start = piece * localThetaResolution / numPieces;
2797 end = (piece+1) * localThetaResolution / numPieces;
2798 localEndTheta = localStartTheta + (double)(end) * deltaTheta;
2799 localStartTheta = localStartTheta + (double)(start) * deltaTheta;
2800 localThetaResolution = end - start;
2801
7fd59977 2802 // Create north pole if needed
2803 int number_point = 0;
2804 int number_pointArray = 0;
2805
2806 if ( mStartPhi <= 0.0 ) {
2807 number_pointArray++;
2808 numPoles++;
2809 }
2810 if ( mEndPhi >= 180.0 ) {
2811 number_pointArray++;
2812 numPoles++;
2813 }
161c4476 2814
7fd59977 2815 // Check data, determine increments, and convert to radians
2816 startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta);
c6541a0c 2817 startTheta *= M_PI / 180.0;
7fd59977 2818 endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta);
c6541a0c 2819 endTheta *= M_PI / 180.0;
7fd59977 2820
2821
2822 startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi);
c6541a0c 2823 startPhi *= M_PI / 180.0;
7fd59977 2824 endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi);
c6541a0c 2825 endPhi *= M_PI / 180.0;
7fd59977 2826
2827 phiResolution = mPhiResolution - numPoles;
2828 deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1);
2829 thetaResolution = localThetaResolution;
2830 if ( fabs(localStartTheta - localEndTheta) < 360.0 ) {
2831 ++localThetaResolution;
2832 }
2833 deltaTheta = (endTheta - startTheta) / thetaResolution;
2834
2835 jStart = ( mStartPhi <= 0.0 ? 1 : 0);
2836 jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution);
2837
2838 // Create intermediate points
2839 for ( i = 0; i < localThetaResolution; i++ ) {
2840 for ( j = jStart; j < jEnd; j++ ) {
2841 number_pointArray++;
2842 }
2843 }
2844
2845 //Generate mesh connectivity
2846 base = phiResolution * localThetaResolution;
2847
2848 int number_triangle = 0 ;
2849 if ( mStartPhi <= 0.0 ) { // around north pole
2850 number_triangle += localThetaResolution;
2851 }
161c4476 2852
7fd59977 2853 if ( mEndPhi >= 180.0 ) { // around south pole
2854 number_triangle += localThetaResolution;
2855 }
2856
2857 // bands in-between poles
2858 for ( i=0; i < localThetaResolution; i++){
2859 for ( j=0; j < (phiResolution-1); j++){
2860 number_triangle +=2;
2861 }
2862 }
2863
2864 Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false);
2865 TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes();
2866 Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles();
2867
2868 if ( mStartPhi <= 0.0 ){
2869 x[0] = mCenter[0];
2870 x[1] = mCenter[1];
2871 x[2] = mCenter[2] + mRadius;
2872 PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2]));
2873 }
2874
2875 // Create south pole if needed
2876 if ( mEndPhi >= 180.0 ){
2877 x[0] = mCenter[0];
2878 x[1] = mCenter[1];
2879 x[2] = mCenter[2] - mRadius;
2880 PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2]));
2881 }
2882
2883 number_point = 3;
2884 for ( i=0; i < localThetaResolution; i++){
c6541a0c 2885 theta = localStartTheta * M_PI / 180.0 + i*deltaTheta;
7fd59977 2886 for ( j = jStart; j < jEnd; j++){
2887 phi = startPhi + j*deltaPhi;
2888 radius = mRadius * sin((double)phi);
2889 n[0] = radius * cos((double)theta);
2890 n[1] = radius * sin((double)theta);
2891 n[2] = mRadius * cos((double)phi);
2892 x[0] = n[0] + mCenter[0];
2893 x[1] = n[1] + mCenter[1];
2894 x[2] = n[2] + mCenter[2];
2895 PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2]));
2896 number_point++;
2897 }
2898 }
2899
2900 numPoles = 3;
2901 number_triangle = 1;
2902 if ( mStartPhi <= 0.0 ){// around north pole
2903 for (i=0; i < localThetaResolution; i++){
2904 pts[0] = phiResolution*i + numPoles;
2905 pts[1] = (phiResolution*(i+1) % base) + numPoles;
2906 pts[2] = 1;
2907 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2908 number_triangle++;
2909 }
2910 }
161c4476 2911
7fd59977 2912 if ( mEndPhi >= 180.0 ){ // around south pole
2913 numOffset = phiResolution - 1 + numPoles;
2914 for (i=0; i < localThetaResolution; i++){
2915 pts[0] = phiResolution*i + numOffset;
2916 pts[2] = ((phiResolution*(i+1)) % base) + numOffset;
2917 pts[1] = numPoles - 1;
2918 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2919 number_triangle++;
2920 }
2921 }
2922
2923 // bands in-between poles
161c4476 2924
7fd59977 2925 for (i=0; i < localThetaResolution; i++){
2926 for (j=0; j < (phiResolution-1); j++){
2927 pts[0] = phiResolution*i + j + numPoles;
2928 pts[1] = pts[0] + 1;
2929 pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1;
2930 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2931 number_triangle++;
2932 pts[1] = pts[2];
2933 pts[2] = pts[1] - 1;
2934 pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2]));
2935 number_triangle++;
2936 }
2937 }
2938
2939 Poly_Connect* pc = new Poly_Connect(polyTriangulation);
2940
2941 Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3);
2942
2943 Standard_Integer index[3];
2944 Standard_Real Tol = Precision::Confusion();
2945
2946 gp_Dir Nor;
2947 for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) {
2948 gp_XYZ eqPlan(0, 0, 0);
2949 for ( pc->Initialize(i); pc->More(); pc->Next()) {
2950 pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]);
2951 gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord());
2952 gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord());
2953 gp_XYZ vv = v1^v2;
2954 Standard_Real mod = vv.Modulus();
2955 if(mod < Tol) continue;
2956 eqPlan += vv/mod;
2957 }
2958
2959 Standard_Real modmax = eqPlan.Modulus();
2960
161c4476 2961 if(modmax > Tol)
7fd59977 2962 Nor = gp_Dir(eqPlan);
161c4476 2963 else
7fd59977 2964 Nor = gp_Dir(0., 0., 1.);
51740958 2965
2966 Standard_Integer k = (i - PointsOfArray.Lower()) * 3;
2967 Normals->SetValue(k + 1, (Standard_ShortReal)Nor.X());
2968 Normals->SetValue(k + 2, (Standard_ShortReal)Nor.Y());
2969 Normals->SetValue(k + 3, (Standard_ShortReal)Nor.Z());
7fd59977 2970 }
2971
2972 delete pc;
2973 polyTriangulation->SetNormals(Normals);
2974
2975 return polyTriangulation;
2976}
2977
2978//===============================================================================================
2979//function : VDrawSphere
2980//author : psn
2981//purpose : Create an AIS shape.
7fd59977 2982//===============================================================================================
35e08fe8 2983static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv)
161c4476
K
2984{
2985 // check for errors
2986 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
2987 if (aContextAIS.IsNull())
2988 {
23fe70ec 2989 Message::SendFail ("Error: no active viewer");
161c4476
K
2990 return 1;
2991 }
2992 else if (argc < 3)
2993 {
23fe70ec 2994 Message::SendFail() << "Syntax error: wrong number of arguments.\n"
2995 << "Use: " << argv[0] << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]";
161c4476
K
2996 return 1;
2997 }
7fd59977 2998
161c4476
K
2999 // read the arguments
3000 TCollection_AsciiString aShapeName (argv[1]);
91322f44 3001 Standard_Integer aResolution = Draw::Atoi (argv[2]);
3002 Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0;
3003 Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0;
3004 Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0;
3005 Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0;
b7cd4ba7 3006 Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False;
3007 Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True;
7fd59977 3008
161c4476 3009 // remove AIS object with given name from map
208e6839 3010 VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)());
161c4476 3011
b7cd4ba7 3012 if (toPrintInfo)
3013 std::cout << "Compute Triangulation...\n";
161c4476
K
3014 Handle(AIS_Triangulation) aShape
3015 = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ,
3016 aResolution,
3017 aRadius));
3018 Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length();
3019 Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length();
3020
161c4476
K
3021 // stupid initialization of Green color in RGBA space as integer
3022 // probably wrong for big-endian CPUs
dcc17419 3023 const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
161c4476
K
3024
3025 // setup colors array per vertex
3026