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