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