0020716: Eliminate usage of "config.h" header file
[occt.git] / src / ViewerTest / ViewerTest_RelationCommands.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.
7fd59977 16
17#include <ViewerTest.hxx>
7fd59977 18
a6eb515f 19#include <AIS_AngleDimension.hxx>
20#include <AIS_Circle.hxx>
21#include <AIS_DiameterDimension.hxx>
22#include <AIS_DisplayMode.hxx>
7fd59977 23#include <AIS_InteractiveContext.hxx>
a6eb515f 24#include <AIS_LengthDimension.hxx>
25#include <AIS_ListIteratorOfListOfInteractive.hxx>
26#include <AIS_ListOfInteractive.hxx>
27#include <AIS_MapOfInteractive.hxx>
28#include <AIS_Point.hxx>
29#include <AIS_RadiusDimension.hxx>
30#include <AIS_Relation.hxx>
31#include <AIS_Shape.hxx>
32#include <BRepAdaptor_Curve.hxx>
33#include <BRep_Builder.hxx>
34#include <BRep_Tool.hxx>
35#include <BRepTools.hxx>
7fd59977 36#include <Draw_Interpretor.hxx>
37#include <Draw.hxx>
38#include <Draw_Appli.hxx>
a6eb515f 39#include <Draw_Window.hxx>
7fd59977 40#include <DBRep.hxx>
a6eb515f 41#include <ElSLib.hxx>
42#include <GC_MakePlane.hxx>
43#include <Geom_CartesianPoint.hxx>
44#include <Geom_Circle.hxx>
af203d54 45#include <Geom_Line.hxx>
a6eb515f 46#include <Geom_Plane.hxx>
af203d54 47#include <GeomAPI_IntCS.hxx>
48#include <gce_MakeLin.hxx>
49#include <gce_MakePln.hxx>
a6eb515f 50#include <gp_Circ.hxx>
51#include <gp_Pln.hxx>
52#include <IntAna_IntConicQuad.hxx>
53#include <IntAna_Quadric.hxx>
54#include <Precision.hxx>
55#include <Select3D_Projector.hxx>
56#include <StdSelect.hxx>
7fd59977 57#include <TCollection_AsciiString.hxx>
a6eb515f 58#include <TCollection_ExtendedString.hxx>
59#include <TColStd_MapOfInteger.hxx>
60#include <TopAbs.hxx>
61#include <TopAbs_ShapeEnum.hxx>
62#include <TopExp.hxx>
63#include <TopoDS.hxx>
64#include <TopoDS_Face.hxx>
65#include <TopoDS_Solid.hxx>
66#include <TopoDS_Vertex.hxx>
7fd59977 67#include <V3d_Viewer.hxx>
68#include <V3d_View.hxx>
69#include <V3d.hxx>
7fd59977 70#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
71#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
72#include <ViewerTest_EventManager.hxx>
73
af203d54 74extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
75 const Handle(AIS_InteractiveObject)& theAISObj,
76 Standard_Boolean theReplaceIfExists = Standard_True);
7fd59977 77extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
78extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
79extern Handle(AIS_InteractiveContext)& TheAISContext ();
80
7fd59977 81#define VertexMask 0x01
82#define EdgeMask 0x02
83#define FaceMask 0x04
84
7fd59977 85//=======================================================================
86//function : Get3DPointAtMousePosition
af203d54 87//purpose : Calculates the 3D points corresponding to the mouse position
88// in the plane of the view
7fd59977 89//=======================================================================
af203d54 90static gp_Pnt Get3DPointAtMousePosition()
a6eb515f 91{
af203d54 92 Handle(V3d_View) aView = ViewerTest::CurrentView();
93 static Select3D_Projector aProjector;
94 aProjector.SetView (aView);
95
7fd59977 96 Standard_Real xv,yv,zv;
af203d54 97 aView->Proj (xv,yv,zv);
7fd59977 98 Standard_Real xat,yat,zat;
af203d54 99 aView->At(xat,yat,zat);
100 gp_Pln aPlane (gp_Pnt(xat,yat,zat), gp_Dir(xv,yv,zv));
101
102 Standard_Integer aPixX, aPixY;
103 Standard_Real aX, aY, aZ, aDX, aDY, aDZ;
104
105 ViewerTest::GetMousePosition (aPixX, aPixY);
106 aView->ConvertWithProj (aPixX, aPixY, aX, aY, aZ, aDX, aDY, aDZ);
107 gp_Lin aLine( gp_Pnt(aX, aY, aZ), gp_Dir(aDX, aDY, aDZ) );
108
109 // Compute intersection
110 Handle(Geom_Line) aGeomLine = new Geom_Line (aLine);
111 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
112 GeomAPI_IntCS anIntersector (aGeomLine, aGeomPlane);
113 if (!anIntersector.IsDone() || anIntersector.NbPoints() == 0)
114 {
115 return gp::Origin();
116 }
117 return anIntersector.Point (1);
7fd59977 118}
119
7fd59977 120//=======================================================================
af203d54 121//function : Get3DPointAtMousePosition
122//purpose : Calculates the 3D points corresponding to the mouse position
123// in the plane of the view
7fd59977 124//=======================================================================
af203d54 125static Standard_Boolean Get3DPointAtMousePosition (const gp_Pnt& theFirstPoint,
126 const gp_Pnt& theSecondPoint,
127 gp_Pnt& theOutputPoint)
7fd59977 128{
af203d54 129 theOutputPoint = gp::Origin();
130
131 Handle(V3d_View) aView = ViewerTest::CurrentView();
132
133 Standard_Integer aPixX, aPixY;
134 Standard_Real aX, aY, aZ, aDx, aDy, aDz, aUx, aUy, aUz;
135
136 // Get 3D point in view coordinates and projection vector from the pixel point.
137 ViewerTest::GetMousePosition (aPixX, aPixY);
138 aView->ConvertWithProj (aPixX, aPixY, aX, aY, aZ, aDx, aDy, aDz);
139 gp_Lin aProjLin (gp_Pnt(aX, aY, aZ), gp_Dir(aDx, aDy, aDz));
140
141 // Get plane
142 gp_Vec aDimVec (theFirstPoint, theSecondPoint);
143 aView->Up (aUx, aUy, aUz);
144 gp_Vec aViewUp (aUx, aUy, aUz);
145
146 if (aDimVec.IsParallel (aViewUp, Precision::Angular()))
147 {
148 theOutputPoint = Get3DPointAtMousePosition();
149 return Standard_True;
7fd59977 150 }
af203d54 151
152 gp_Vec aDimNormal = aDimVec ^ aViewUp;
153 gp_Pln aViewPlane= gce_MakePln (theFirstPoint, aDimNormal);
154
155 // Get intersection of view plane and projection line
156 Handle(Geom_Plane) aPlane = new Geom_Plane (aViewPlane);
157 Handle(Geom_Line) aProjLine = new Geom_Line (aProjLin);
158 GeomAPI_IntCS anIntersector (aProjLine, aPlane);
159 if (!anIntersector.IsDone() || anIntersector.NbPoints() == 0)
160 {
161 return Standard_False;
7fd59977 162 }
af203d54 163
164 theOutputPoint = anIntersector.Point (1);
165 return Standard_True;
7fd59977 166}
167
a6eb515f 168//=======================================================================
169//function : VDimBuilder
1d7ca641 170//purpose : Command for building dimension presentations: angle,
171// length, radius, diameter
a6eb515f 172//=======================================================================
a6eb515f 173static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgs)
174{
175 if (theArgsNb < 2)
176 {
1d7ca641 177 std::cerr << theArgs[0] << ": command argument is required. Type help for more information.\n";
a6eb515f 178 return 1;
179 }
180
181 // Parse parameters
182 TCollection_AsciiString aDimType(theArgs[1]);
183 AIS_KindOfDimension aKindOfDimension;
1d7ca641 184 if (aDimType == "length")
a6eb515f 185 {
186 aKindOfDimension = AIS_KOD_LENGTH;
187 }
1d7ca641 188 else if (aDimType == "angle")
a6eb515f 189 {
190 aKindOfDimension = AIS_KOD_PLANEANGLE;
191 }
1d7ca641 192 else if (aDimType == "radius")
a6eb515f 193 {
194 aKindOfDimension = AIS_KOD_RADIUS;
195 }
1d7ca641 196 else if (aDimType == "diameter" || aDimType == "diam")
a6eb515f 197 {
198 aKindOfDimension = AIS_KOD_DIAMETER;
199 }
200 else
201 {
1d7ca641 202 std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n";
a6eb515f 203 return 1;
204 }
205 NCollection_List<Handle(AIS_InteractiveObject)> aShapes;
206 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect;
207 Standard_Boolean isPlaneCustom = Standard_False;
208 TCollection_AsciiString aName;
209 gp_Pln aWorkingPlane;
1d7ca641 210 Standard_Boolean isCustomFlyout = Standard_False;
211 Standard_Real aCustomFlyout = 0.0;
212
a6eb515f 213 for (Standard_Integer anIt = 2; anIt < theArgsNb; ++anIt)
214 {
1d7ca641 215 TCollection_AsciiString anArgString = theArgs[anIt];
216 TCollection_AsciiString aParamName;
217 TCollection_AsciiString aParamValue;
218 if (ViewerTest::SplitParameter (anArgString, aParamName, aParamValue))
a6eb515f 219 {
1d7ca641 220 aParamName.LowerCase();
221 aParamValue.LowerCase();
222
223 if (aParamName == "text")
a6eb515f 224 {
1d7ca641 225 anAspect->MakeText3d (aParamValue == "3d");
226 }
227 else if (aParamName == "name")
228 {
229 if (aParamValue.IsEmpty())
230 {
231 std::cerr << theArgs[0] << ": no name for dimension.\n";
232 return 1;
233 }
234
235 aName = aParamValue;
236 }
237 else if (aParamName == "plane")
238 {
239 if (aParamValue == "xoy")
240 {
241 aWorkingPlane = gp_Pln (gp_Ax3 (gp::XOY()));
242 }
243 else if (aParamValue == "zox")
244 {
245 aWorkingPlane = gp_Pln (gp_Ax3 (gp::ZOX()));
246 }
247 else if (aParamValue == "yoz")
248 {
249 aWorkingPlane = gp_Pln (gp_Ax3 (gp::YOZ()));
250 }
251 else
252 {
253 std::cerr << theArgs[0] << ": wrong plane.\n";
254 return 1;
255 }
256
257 isPlaneCustom = Standard_True;
258 }
259 else if (aParamName == "label")
260 {
261 NCollection_List<TCollection_AsciiString> aListOfLabelVals;
262 while (aParamValue.Length() > 0)
263 {
264 TCollection_AsciiString aValue = aParamValue;
265
266 Standard_Integer aSeparatorPos = aParamValue.Search (",");
267 if (aSeparatorPos >= 0)
268 {
269 aValue.Trunc (aSeparatorPos - 1);
270 aParamValue.Remove (aSeparatorPos, 1);
271 }
272
273 aListOfLabelVals.Append (aValue);
274
275 aParamValue.Remove (1, aValue.Length());
276 }
277
278 NCollection_List<TCollection_AsciiString>::Iterator aLabelValueIt (aListOfLabelVals);
279 for ( ; aLabelValueIt.More(); aLabelValueIt.Next())
280 {
281 aParamValue = aLabelValueIt.Value();
282
283 if (aParamValue == "left")
284 {
285 anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Left);
286 }
287 else if (aParamValue == "right")
288 {
289 anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Right);
290 }
291 else if (aParamValue == "hcenter")
292 {
293 anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Center);
294 }
295 else if (aParamValue == "hfit")
296 {
297 anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Fit);
298 }
299 else if (aParamValue == "above")
300 {
301 anAspect->SetTextVerticalPosition (Prs3d_DTVP_Above);
302 }
303 else if (aParamValue == "below")
304 {
305 anAspect->SetTextVerticalPosition (Prs3d_DTVP_Below);
306 }
307 else if (aParamValue == "vcenter")
308 {
309 anAspect->SetTextVerticalPosition (Prs3d_DTVP_Center);
310 }
311 else
312 {
313 std::cerr << theArgs[0] << ": invalid label position: \"" << aParamValue << "\".\n";
314 return 1;
315 }
316 }
317 }
318 else if (aParamName == "flyout")
319 {
320 if (!aParamValue.IsRealValue())
321 {
322 std::cerr << theArgs[0] << ": numeric value expected for flyout.\n";
323 return 1;
324 }
325
326 aCustomFlyout = aParamValue.RealValue();
327
328 isCustomFlyout = Standard_True;
329 }
330 else if (aParamName == "arrows")
331 {
332 if (aParamValue == "external")
333 {
334 anAspect->SetArrowOrientation (Prs3d_DAO_External);
335 }
336 else if (aParamValue == "internal")
337 {
338 anAspect->SetArrowOrientation (Prs3d_DAO_Internal);
339 }
340 else if (aParamValue == "fit")
341 {
342 anAspect->SetArrowOrientation (Prs3d_DAO_Fit);
343 }
a6eb515f 344 }
a6eb515f 345 else
346 {
1d7ca641 347 std::cerr << theArgs[0] << ": unknow parameter: \"" << aParamName << "\".\n";
a6eb515f 348 return 1;
349 }
350 }
1d7ca641 351 else // Shape
a6eb515f 352 {
1d7ca641 353 if (!GetMapOfAIS().IsBound2 (anArgString))
a6eb515f 354 {
1d7ca641 355 std::cerr << theArgs[0] << ": wrong name of shape. May be here is a wrong parameter.\n";
a6eb515f 356 return 1;
357 }
1d7ca641 358
359 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anArgString));
a6eb515f 360 if (aShape.IsNull())
1d7ca641 361 {
362 std::cerr << theArgs[0] << ": wrong name of shape. Not a shape.\n";
a6eb515f 363 return 1;
1d7ca641 364 }
365
a6eb515f 366 aShapes.Append (aShape);
367 }
368 }
369
1d7ca641 370 if (aName.IsEmpty())
371 {
372 std::cerr << theArgs[0] << ": no name for dimension.\n";
373 return 1;
374 }
375
a6eb515f 376 // Build dimension
377 Handle(AIS_Dimension) aDim;
378 switch (aKindOfDimension)
379 {
1d7ca641 380 case AIS_KOD_LENGTH:
a6eb515f 381 {
382 if (!isPlaneCustom)
383 {
1d7ca641 384 std::cerr << theArgs[0] << ": can not build dimension without working plane.\n";
a6eb515f 385 return 1;
386 }
387 if (aShapes.Extent() == 1)
388 {
389 if (aShapes.First()->Type() == AIS_KOI_Shape
390 && (Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape().ShapeType() != TopAbs_EDGE)
391 {
1d7ca641 392 std::cerr << theArgs[0] << ": wrong shape type.\n";
a6eb515f 393 return 1;
394 }
395 aDim = new AIS_LengthDimension (TopoDS::Edge ((Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape()), aWorkingPlane);
396 }
397 else if (aShapes.Extent() == 2)
398 {
399 if (aShapes.First()->Type() == AIS_KOI_Shape && aShapes.Last()->Type() == AIS_KOI_Shape)
400 aDim = new AIS_LengthDimension ((Handle(AIS_Shape)::DownCast(aShapes.First ()))->Shape(),
401 (Handle(AIS_Shape)::DownCast(aShapes.Last ()))->Shape(),
402 aWorkingPlane);
403 else// AIS_Point
404 {
405 Handle(AIS_Point) aPoint1 = Handle(AIS_Point)::DownCast(aShapes.First ());
406 Handle(AIS_Point) aPoint2 = Handle(AIS_Point)::DownCast(aShapes.Last ());
407 aDim = new AIS_LengthDimension (aPoint1->Component()->Pnt(),
408 aPoint2->Component()->Pnt(),
409 aWorkingPlane);
410 }
411 }
412 else
413 {
1d7ca641 414 std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
a6eb515f 415 return 1;
416 }
1d7ca641 417
418 break;
a6eb515f 419 }
1d7ca641 420
421 case AIS_KOD_PLANEANGLE:
a6eb515f 422 {
423 if (aShapes.Extent() == 1 && aShapes.First()->Type()==AIS_KOI_Shape)
424 {
425 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aShapes.First());
426 if (aShape->Shape().ShapeType() == TopAbs_FACE)
427 aDim = new AIS_AngleDimension (TopoDS::Face(aShape->Shape()));
428 }
429 if (aShapes.Extent() == 2)
430 {
431 Handle(AIS_Shape) aShape1 = Handle(AIS_Shape)::DownCast(aShapes.First());
432 Handle(AIS_Shape) aShape2 = Handle(AIS_Shape)::DownCast(aShapes.Last());
433 if (!aShape1.IsNull() && !aShape2.IsNull()
434 && aShape1->Shape().ShapeType() == TopAbs_EDGE
435 && aShape2->Shape().ShapeType() == TopAbs_EDGE)
436 aDim = new AIS_AngleDimension (TopoDS::Edge(aShape1->Shape()),TopoDS::Edge(aShape2->Shape()));
437 else
438 {
1d7ca641 439 std::cerr << theArgs[0] << ": wrong shapes for angle dimension.\n";
a6eb515f 440 return 1;
441 }
442 }
443 else if (aShapes.Extent() == 3)
444 {
445 gp_Pnt aP1, aP2, aP3;
446 Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
447 if (aPoint.IsNull())
448 return 1;
449 aP1 = aPoint->Component()->Pnt();
450 aShapes.RemoveFirst();
451 aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
452 if (aPoint.IsNull())
453 return 1;
454 aP2 = aPoint->Component()->Pnt();
455 aShapes.RemoveFirst();
456 aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
457 if (aPoint.IsNull())
458 return 1;
459 aP3 = aPoint->Component()->Pnt();
460 aDim = new AIS_AngleDimension (aP1, aP2, aP3);
461 }
462 else
463 {
1d7ca641 464 std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
a6eb515f 465 return 1;
466 }
1d7ca641 467
468 break;
a6eb515f 469 }
1d7ca641 470
471 case AIS_KOD_RADIUS: // radius of the circle
a6eb515f 472 {
473 if (aShapes.Extent() == 1)
474 {
475 Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
476 gp_Circ aCircle = aShape->Circle()->Circ();
477 aDim = new AIS_RadiusDimension (aCircle);
478 }
479 else
480 {
1d7ca641 481 std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
a6eb515f 482 return 1;
483 }
1d7ca641 484
485 break;
a6eb515f 486 }
1d7ca641 487
488 case AIS_KOD_DIAMETER:
a6eb515f 489 {
490 if (aShapes.Extent() == 1)
491 {
492 Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
493 gp_Circ aCircle = aShape->Circle()->Circ();
494 aDim = new AIS_DiameterDimension (aCircle);
495 }
496 else
497 {
1d7ca641 498 std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
a6eb515f 499 return 1;
500 }
1d7ca641 501
502 break;
a6eb515f 503 }
1d7ca641 504
505 default:
a6eb515f 506 {
1d7ca641 507 std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n";
a6eb515f 508 return 1;
509 }
510 }
1d7ca641 511
a6eb515f 512 aDim->SetDimensionAspect (anAspect);
1d7ca641 513
514 if (isCustomFlyout)
515 {
516 aDim->SetFlyout (aCustomFlyout);
517 }
518
a6eb515f 519 if (GetMapOfAIS().IsBound2(aName))
520 {
521 theDi << theArgs[0] << ": shape with name " << aName.ToCString ()<< " already exists. It will be replaced\n";
522 Handle(AIS_InteractiveObject) anObj =
523 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
524 TheAISContext()->Remove(anObj, Standard_False);
525 GetMapOfAIS().UnBind2(aName);
526 }
1d7ca641 527
a6eb515f 528 GetMapOfAIS().Bind (aDim,aName);
1d7ca641 529
a6eb515f 530 return 0;
531}
7fd59977 532
533//=======================================================================
534//function : VAngleDimBuilder
535//purpose :
536//=======================================================================
a6eb515f 537
7fd59977 538static int VAngleDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
539{
af203d54 540 Standard_Integer aCurrentIndex;
541 if (argc!=2)
542 {
543 di << argv[0] << " error : wrong number of parameters.\n";
544 return 1;
545 }
546
7fd59977 547 TheAISContext()->CloseAllContexts();
af203d54 548 aCurrentIndex = TheAISContext()->OpenLocalContext();
549 // Set selection mode for edges.
550 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
551 di << "Select two edges coplanar or not.\n";
552
553 Standard_Integer anArgsNum = 5;
554 const char *aBuffer[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
555 const char **anArgsVec = (const char **) aBuffer;
556 while (ViewerMainLoop (anArgsNum, anArgsVec)) { }
557
558 TopoDS_Shape aFirstShape;
559 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
560 {
561 aFirstShape = TheAISContext()->SelectedShape();
7fd59977 562 }
af203d54 563
564 if (aFirstShape.IsNull())
565 {
566 di << argv[0] << " error : no picked shape.\n";
567 return 1;
568 }
569
570 if (aFirstShape.ShapeType()== TopAbs_EDGE)
571 {
572 while (ViewerMainLoop (anArgsNum, anArgsVec)) { }
573
574 TopoDS_Shape aSecondShape;
575 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
576 {
577 aSecondShape = TheAISContext()->SelectedShape();
7fd59977 578 }
af203d54 579
580 if (aSecondShape.IsNull())
581 {
582 di << argv[0] << " error : no picked shape.\n";
583 return 1;
584 }
585
586 if (aSecondShape.ShapeType() != TopAbs_EDGE)
587 {
588 di << argv[0] <<" error: you should have selected an edge.\n"; return 1;
7fd59977 589 }
7fd59977 590
af203d54 591 // Close local context to draw dimension in the neutral point.
592 TheAISContext()->CloseLocalContext (aCurrentIndex);
7fd59977 593
af203d54 594 // Construct the dimension.
595 Handle (AIS_AngleDimension) aDim= new AIS_AngleDimension (TopoDS::Edge(aFirstShape) ,TopoDS::Edge(aSecondShape));
596 VDisplayAISObject (argv[1], aDim);
7fd59977 597 }
af203d54 598 else
599 {
600 di << argv[0] << " error: you must select 2 edges.\n";
601 return 1;
602 }
603
7fd59977 604 return 0;
605}
606
607//==============================================================================
608//function : VDiameterDim
609//purpose : Display the diameter dimension of a face or an edge.
610//Draw arg : vdiameterdim Name
611//==============================================================================
7fd59977 612
613static int VDiameterDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
614{
615 // Declarations
af203d54 616 Standard_Integer aCurrentIndex;
617 Standard_Real aRadius;
618
7fd59977 619 // Verification
af203d54 620 if (argc != 2)
621 {
622 di<<" vdiameterdim error"<<"\n";
623 return 1;
624 }
625
626 // Close all local contexts
7fd59977 627 TheAISContext()->CloseAllContexts();
af203d54 628 // Open local context and get its index for recovery
7fd59977 629 TheAISContext()->OpenLocalContext();
af203d54 630 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 631
af203d54 632 // Activate 'edge' selection mode
7fd59977 633 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
634 di<<" Select an circled edge."<<"\n";
635
af203d54 636 // Loop that will handle the picking.
7fd59977 637 Standard_Integer argcc = 5;
638 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
639 const char **argvv = (const char **) buff;
640 while (ViewerMainLoop( argcc, argvv) ) { }
af203d54 641 // end of the loop.
7fd59977 642
af203d54 643 TopoDS_Shape aShape;
644 for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
645 {
646 aShape = TheAISContext()->SelectedShape();
7fd59977 647 }
af203d54 648
649 if (aShape.IsNull())
650 {
651 di << argv[0] << ": no shape is selected." << "\n";
652 return 1;
7fd59977 653 }
af203d54 654
655 if (aShape.ShapeType() != TopAbs_EDGE)
656 {
657 di << " vdiameterdim error: the selection of a face or an edge was expected." << "\n";
658 return 1;
7fd59977 659 }
af203d54 660
661 // Compute the radius
662 BRepAdaptor_Curve aCurve (TopoDS::Edge (aShape));
663
664 if (aCurve.GetType() != GeomAbs_Circle)
665 {
666 di << "vdiameterdim error: the edge is not a circular one." << "\n";
667 return 1;
668 }
669
670 gp_Circ aCircle = aCurve.Circle();
671 aRadius = 2.0 * aCircle.Radius();
672
673 // Construction of the diameter dimension.
674 TheAISContext()->CloseLocalContext (aCurrentIndex);
675 Handle (AIS_DiameterDimension) aDiamDim= new AIS_DiameterDimension (aShape);
676 VDisplayAISObject (argv[1], aDiamDim);
677
7fd59977 678 return 0;
7fd59977 679}
680
681
682//==============================================================================
683// Fonction vconcentric
684// ----------------- Uniquement par selection dans le viewer.
685//==============================================================================
686
687//==============================================================================
688//function : VConcentric
689//purpose : Display the concentric relation between two surfaces.
690//Draw arg : vconcentric Name
691//==============================================================================
692#include <AIS_ConcentricRelation.hxx>
693#include <Geom_Plane.hxx>
694#include <gp_Pln.hxx>
695#include <GC_MakePlane.hxx>
696#include <BRepAdaptor_Curve.hxx>
697#include <TopExp_Explorer.hxx>
698
699
700static int VConcentricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
701{
702 // Declarations
703 Standard_Integer myCurrentIndex;
704
705 // Verification
706 if (argc!=2) {di<<"vconcentric error."<<"\n";return 1;}
707 // Fermeture des contextes locaux
708 TheAISContext()->CloseAllContexts();
709 // Ouverture d'un contexte local et recuperation de son index.
710 TheAISContext()->OpenLocalContext();
711 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
712
713 // On active les modes de selections Edges et Faces.
714 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
715 di<<" Select a circled edge."<<"\n";
716
717 // Boucle d'attente waitpick.
718 Standard_Integer argcc = 5;
719 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
720 const char **argvv = (const char **) buff;
721 while (ViewerMainLoop( argcc, argvv) ) { }
722 // fin de la boucle
723
724 TopoDS_Shape ShapeA;
725 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
726 ShapeA = TheAISContext()->SelectedShape();
727 }
728 // ShapeA est un edge
729 // ==================
730 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
731 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
732 di<<" Select an edge."<<"\n";
733
734 // Boucle d'attente waitpick.
735 Standard_Integer argccc = 5;
736 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
737 const char **argvvv = (const char **) bufff;
738 while (ViewerMainLoop( argccc, argvvv) ) { }
739 // fin de la boucle
740
741 TopoDS_Shape ShapeB;
742 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
743 ShapeB = TheAISContext()->SelectedShape();
744 }
745 if (ShapeB.ShapeType()!=TopAbs_EDGE ) {
746 di<<" vconcentric error: select an edge."<<"\n";return 1;
747 }
748
749 // Construction du plane.
750 // On recupere le centre du cercle A.
751 BRepAdaptor_Curve theCurveA(TopoDS::Edge(ShapeA) );
752 gp_Circ theCircleA=theCurveA.Circle();
753 gp_Pnt theCenterA=theCircleA.Location();
754 // On recupere deux points sur le cercle A
755 gp_Pnt B= theCurveA.Value(0.25);
756 gp_Pnt C= theCurveA.Value(0.75);
757 // Construction du plane.
758 GC_MakePlane MkPlane(theCenterA ,B ,C );
759 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
760
761 // Fermeture du context local
762 TheAISContext()->CloseLocalContext(myCurrentIndex);
763
764 Handle (AIS_ConcentricRelation) myConcentry= new AIS_ConcentricRelation(ShapeA, ShapeB, theGeomPlane );
765 TheAISContext()->Display(myConcentry );
766 GetMapOfAIS().Bind (myConcentry,argv[1]);
767 }
768
769
770 else {
771 di<<" vconcentric error: the selection of a face or an edge was expected."<<"\n";return 1;
772 }
773
774 return 0;
775
776
777
778
779}
780
781//==============================================================================
782//function : VEqualDistRelation
783//purpose :
784//Draw arg : vdiameterdim Name DiameterValue
785//==============================================================================
786#include <AIS_EqualDistanceRelation.hxx>
787#include <BRepExtrema_ExtCC.hxx>
788#include <GC_MakePlane.hxx>
789
790
791static int VEqualDistRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
792{
793 // Declarations
794 Standard_Integer myCurrentIndex;
795
796 // Verification
797 if (argc!=2) {di<<" vequaldistrelation error: no arguments allowed."<<"\n";return 1;}
798
799 // Fermeture des contextes locaux
800 TheAISContext()->CloseAllContexts();
801
802 // Ouverture d'un contexte local et recuperation de son index.
803 TheAISContext()->OpenLocalContext();
804 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
805
806 // On active les modes de selections Edges et Vertexes.
807 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
808 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
809 di<<" Select an edge or a vertex"<<"\n";
810
811 // Boucle d'attente waitpick.
812 Standard_Integer argc1 = 5;
813 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
814 const char **argv1 = (const char **) buf1;
815 while (ViewerMainLoop( argc1, argv1) ) { }
816 // fin de la boucle
817
818 TopoDS_Shape ShapeA;
819 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
820 ShapeA = TheAISContext()->SelectedShape();
821 }
822
823 di<<" Select an edge or a vertex"<<"\n";
824 // Boucle d'attente waitpick.
825 Standard_Integer argc2 = 5;
826 const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
827 const char **argv2 = (const char **) buf2;
828 while (ViewerMainLoop( argc2, argv2) ) { }
829 // fin de la boucle
830
831 TopoDS_Shape ShapeB;
832 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
833 ShapeB = TheAISContext()->SelectedShape();
834 }
835
836 // Verification des resultats.
837 if (ShapeA.ShapeType()==TopAbs_EDGE && ShapeB.ShapeType()==TopAbs_EDGE ) {
838 // A et B sont des edges ils doivent etre paralleles
839 BRepExtrema_ExtCC myDeltaEdge (TopoDS::Edge(ShapeA) ,TopoDS::Edge(ShapeB) );
840 // on verifie qu'ils sont pas paralleles.
841 if (!myDeltaEdge.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; }
842
843 }
844
845
846 di<<" Select an edge or a vertex"<<"\n";
847 // Boucle d'attente waitpick.
848 Standard_Integer argc3 = 5;
849 const char *buf3[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
850 const char **argv3 = (const char **) buf3;
851 while (ViewerMainLoop( argc3, argv3) ) { }
852 // fin de la boucle
853
854 TopoDS_Shape ShapeC;
855 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
856 ShapeC = TheAISContext()->SelectedShape();
857 }
858
859 di<<" Select an edge or a vertex"<<"\n";
860 // Boucle d'attente waitpick.
861 Standard_Integer argc4 = 5;
862 const char *buf4[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
863 const char **argv4 = (const char **) buf4;
864 while (ViewerMainLoop( argc4, argv4) ) { }
865 // fin de la boucle
866
867 TopoDS_Shape ShapeD;
868 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
869 ShapeD = TheAISContext()->SelectedShape();
870 }
871 // Verification des resultats.
872 if (ShapeC.ShapeType()==TopAbs_EDGE && ShapeD.ShapeType()==TopAbs_EDGE ) {
873 // C et D sont des edges ils doivent etre paralleles
874 BRepExtrema_ExtCC myDeltaEdge2 (TopoDS::Edge(ShapeC) ,TopoDS::Edge(ShapeD) );
875 // on verifie qu'ils sont pas paralleles.
876 if (!myDeltaEdge2.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; }
877
878 }
879
880 // Creation du plan porteur de la contrainte.Methode lourde!
881 gp_Pnt A,B,C;
882 if (ShapeA.ShapeType()==TopAbs_EDGE) {
883 // A est un edge
884 TopoDS_Vertex Va,Vb;
885 TopExp::Vertices (TopoDS::Edge(ShapeA) ,Va ,Vb );
886 A=BRep_Tool::Pnt(Va);
887 B=BRep_Tool::Pnt(Vb);
888
889 if (ShapeB.ShapeType()==TopAbs_EDGE) {
890 // B est un edge aussi
891 TopoDS_Vertex Vc,Vd;
892 TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vc ,Vd );
893 // besoin que de 1 point.
894 C=BRep_Tool::Pnt(Vc);
895
896 }
897 else {
898 // B est un vertex
899 C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
900 }
901 }
902 else {
903 // A est un vertex
904 A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
905
906 if (ShapeB.ShapeType()==TopAbs_EDGE ) {
907 // B est un edge
908 TopoDS_Vertex Vb,Vc;
909 TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vb ,Vc );
910 // besoin que de 2 points.
911 B=BRep_Tool::Pnt(Vb);
912 C=BRep_Tool::Pnt(Vc);
913
914 }
915 else {
916 // B est un vertex
917 B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
918 C.SetX(B.X()+5.);
919 C.SetY(B.Y()+5.);
920 C.SetZ(B.Z()+5.);
921
922 }
923 }
924
925 // Fermeture du context local.
926 TheAISContext()->CloseLocalContext(myCurrentIndex);
927
928 // construction du plane
929 GC_MakePlane MkPlane(A ,B ,C );
930 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
931
932 // Construction de l'AIS_EqualDistanceRelation
933 Handle (AIS_EqualDistanceRelation ) myRelation= new AIS_EqualDistanceRelation (ShapeA, ShapeB, ShapeC ,ShapeD , theGeomPlane );
934 TheAISContext()->Display(myRelation );
935 GetMapOfAIS().Bind (myRelation,argv[1]);
936
937
938
939 return 0;
940
941}
942
943//==============================================================================
944//function : VEqualRadiusRelation
945//purpose :
946//Draw arg : vdiameterdim Name DiameterValue
947//==============================================================================
948#include <AIS_EqualRadiusRelation.hxx>
949#include <GC_MakePlane.hxx>
950#include <BRepAdaptor_Curve.hxx>
951
952
953static int VEqualRadiusRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
954{
955 // Declarations
956 Standard_Integer myCurrentIndex;
957
958 // Verification
959 if (argc!=2) {di<<" vequalrad error: no arguments allowed."<<"\n";return 1;}
960
961 // Fermeture des contextes locaux
962 TheAISContext()->CloseAllContexts();
963
964 // Ouverture d'un contexte local et recuperation de son index.
965 TheAISContext()->OpenLocalContext();
966 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
967
968 // On active les modes de selections Edges.
969 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
970 di<<" Select an circled edge "<<"\n";
971
972 // Boucle d'attente waitpick.
973 Standard_Integer argc1 = 5;
974 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
975 const char **argv1 = (const char **) buf1;
976 while (ViewerMainLoop( argc1, argv1) ) { }
977 // fin de la boucle
978
979 TopoDS_Shape ShapeA;
980 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
981 ShapeA = TheAISContext()->SelectedShape();
982 }
983
984 di<<" Select the last circled edge."<<"\n";
985 // Boucle d'attente waitpick.
986 Standard_Integer argc2 = 5;
987 const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
988 const char **argv2 = (const char **) buf2;
989 while (ViewerMainLoop( argc2, argv2) ) { }
990 // fin de la boucle
991
992 TopoDS_Shape ShapeB;
993 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
994 ShapeB = TheAISContext()->SelectedShape();
995 }
996 // creation du plan qui contient la contrainte.
997 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
998 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
999 BRepAdaptor_Curve theCurveA(EdgeA);
1000 // On recupere 3 points A,B,C de la curve.
1001 gp_Pnt A=theCurveA.Value(0.1);
1002 gp_Pnt B=theCurveA.Value(0.5);
1003 gp_Pnt C=theCurveA.Value(0.9);
1004
1005 // fermeture du contexte local.
1006 TheAISContext()->CloseLocalContext(myCurrentIndex);
1007
1008 // Creation du plane.
1009 GC_MakePlane MkPlane (A ,B ,C );
1010 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1011 // Construction de l'AIS_EqualRadiusRelation
1012 Handle (AIS_EqualRadiusRelation ) myRelation= new AIS_EqualRadiusRelation (EdgeA,EdgeB, theGeomPlane );
1013 TheAISContext()->Display(myRelation );
1014 GetMapOfAIS().Bind (myRelation,argv[1]);
1015
1016 return 0;
1017
1018}
1019
1020
1021//==============================================================================
1022//function : VFixRelation
1023//purpose :
1024//Draw arg : vdiameterdim Name DiameterValue
1025//==============================================================================
1026#include <AIS_FixRelation.hxx>
1027#include <GC_MakePlane.hxx>
1028#include <BRepAdaptor_Curve.hxx>
1029
1030static int VFixRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1031{
1032 // Declarations
1033 Standard_Integer myCurrentIndex;
1034
1035 // Verification
1036 if (argc!=2) {di<<" vfix error: no arguments allowed."<<"\n";return 1;}
1037
1038 // Fermeture des contextes locaux
1039 TheAISContext()->CloseAllContexts();
1040
1041 // Ouverture d'un contexte local et recuperation de son index.
1042 TheAISContext()->OpenLocalContext();
1043 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1044
1045 // On active les modes de selections edge.
1046 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1047 di<<" Select an edge. "<<"\n";
1048
1049 // Boucle d'attente waitpick.
1050 Standard_Integer argc1 = 5;
1051 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1052 const char **argv1 = (const char **) buf1;
1053 while (ViewerMainLoop( argc1, argv1) ) { }
1054 // fin de la boucle
1055
1056 TopoDS_Shape ShapeA;
1057 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1058 ShapeA = TheAISContext()->SelectedShape();
1059 }
1060
1061 // creation du plan qui contient la contrainte.
1062 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1063 BRepAdaptor_Curve theCurveA(EdgeA);
1064 // On recupere 3 points A,B,C de la curve.
1065 gp_Pnt A=theCurveA.Value(0.1);
1066 gp_Pnt B=theCurveA.Value(0.5);
1067 gp_Pnt D=theCurveA.Value(0.9);
1068 gp_Pnt C(B.X()+5,B.Y()+5,B.Z()+5);
1069
1070 // fermeture du contexte local.
1071 TheAISContext()->CloseLocalContext(myCurrentIndex);
1072
1073 // Creation du plane.
1074 GC_MakePlane MkPlane (A ,D ,C );
1075 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1076 // Construction de l'AIS_EqualRadiusRelation
1077 Handle (AIS_FixRelation) myRelation= new AIS_FixRelation (EdgeA,theGeomPlane );
1078 TheAISContext()->Display(myRelation );
1079 GetMapOfAIS().Bind (myRelation,argv[1]);
1080
1081
1082 return 0;
1083
1084}
1085
1086//==============================================================================
1087//function : VIdenticRelation
1088//purpose :
1089//Draw arg : vdiameterdim Name DiameterValue
1090//==============================================================================
1091#include <AIS_IdenticRelation.hxx>
1092#include <BRepAdaptor_Curve.hxx>
1093#include <TopExp_Explorer.hxx>
1094
1095
1096static int VIdenticRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1097{
1098 // Declarations
1099 Standard_Integer myCurrentIndex;
1100
1101 // Verification
1102 if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;}
1103
1104 // Fermeture des contextes locaux
1105 TheAISContext()->CloseAllContexts();
1106
1107 // Ouverture d'un contexte local et recuperation de son index.
1108 TheAISContext()->OpenLocalContext();
1109 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1110
1111 // On active les modes de selections vertex et face.
1112 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1113 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1114 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1115 di<<" Select an edge, a face or a vertex. "<<"\n";
1116
1117 // Boucle d'attente waitpick.
1118 Standard_Integer argc1 = 5;
1119 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1120 const char **argv1 = (const char **) buf1;
1121 while (ViewerMainLoop( argc1, argv1) ) { }
1122 // fin de la boucle
1123
1124 TopoDS_Shape ShapeA;
1125 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1126 ShapeA = TheAISContext()->SelectedShape();
1127 }
1128
1129 di<<" Select an edge, a face or a vertex. "<<"\n";
1130 // Boucle d'attente waitpick.
1131 Standard_Integer argc2 = 5;
1132 const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1133 const char **argv2 = (const char **) buf2;
1134 while (ViewerMainLoop( argc2, argv2) ) { }
1135 // fin de la boucle
1136
1137 TopoDS_Shape ShapeB;
1138 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1139 ShapeB = TheAISContext()->SelectedShape();
1140 }
1141
1142 // Recuperation de points pour construir le Geom_Plnae.
1143 gp_Pnt A,B,C;
1144 if (ShapeA.ShapeType()==TopAbs_EDGE) {
1145 // A est un edge; on peut supposer qu'il sera element d'une face ou possesseur d'un vertex ou identic a un autre edge.
1146 // on recupere deux points sur l'edge (il peut etre rectiligne)
1147 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1148 BRepAdaptor_Curve theCurveA(EdgeA);
1149 // Creation des 3 points.
1150 A=theCurveA.Value(0.1);
1151 B=theCurveA.Value(0.9);
1152 C.SetX(B.X()+5.);
1153 C.SetY(B.Y()+5.);
1154 C.SetZ(B.Z()+5.);
1155 }
1156 else if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1157 // SahpeA est un Vertex
1158 // On va utiliser ShapeB
1159 if (ShapeB.ShapeType()==TopAbs_EDGE) {
1160 // B est un edge
1161 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1162 BRepAdaptor_Curve theCurveB(EdgeB);
1163 // Creation des 3 points.
1164 A=theCurveB.Value(0.1);
1165 B=theCurveB.Value(0.9);
1166 C.SetX(B.X()+5.);
1167 C.SetY(B.Y()+5.);
1168 C.SetZ(B.Z()+5.);
1169
1170 }
1171 else if (ShapeB.ShapeType()==TopAbs_FACE ) {
1172 // Shape B est une face
1173 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1174 // On recupere 1 edge de FaceB(la face n'a pas forcement de vertex) (l'element A est forcement dans B).
1175 TopExp_Explorer FaceExp(FaceB,TopAbs_EDGE);
1176 TopoDS_Edge EdgeFromB=TopoDS::Edge(FaceExp.Current() );
1177 // On recupere les 3 points de l'edge de face B
1178 BRepAdaptor_Curve theCurveB(EdgeFromB);
1179 // On recupere 3 points A,B,C de la curve.
1180 A=theCurveB.Value(0.1);
1181 B=theCurveB.Value(0.5);
1182 C=theCurveB.Value(0.9);
1183
1184 }
1185 else {
1186 // B ets un vetex aussi
1187 A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1188 B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1189 C.SetX(B.X()+5.);
1190 C.SetY(B.Y()+5.);
1191 C.SetZ(B.Z()+5.);
1192
1193 }
1194
1195 }
1196 else {
1197 // A est une face.
1198 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1199 // On recupere 1 edge de FaceA
1200 TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE);
1201 TopoDS_Edge EdgeFromA=TopoDS::Edge(FaceExp.Current() );
1202 // On recupere les 3 points de l'edge
1203 BRepAdaptor_Curve theCurveA(EdgeFromA);
1204 // On recupere 3 points A,B,C de la curve.
1205 A=theCurveA.Value(0.1);
1206 B=theCurveA.Value(0.5);
1207 C=theCurveA.Value(0.9);
1208
1209 }
1210
1211 // Fermeture du context local.
1212 TheAISContext()->CloseLocalContext(myCurrentIndex);
1213 // On construit le plane
1214 GC_MakePlane MkPlane (A ,B ,C );
1215 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1216
1217 // Construction de l'AIS_IdenticRelation
1218 Handle ( AIS_IdenticRelation ) myRelation= new AIS_IdenticRelation (ShapeA ,ShapeB, theGeomPlane );
1219 TheAISContext()->Display(myRelation );
1220 GetMapOfAIS().Bind (myRelation,argv[1]);
1221
1222
1223
1224 return 0;
1225
1226}
1227//==============================================================================
1228//function : VLengthDimension
1229//purpose : Display the diameter dimension of a face or an edge.
1230//Draw arg : vdiameterdim Name DiameterValue
1231//==============================================================================
1232#include <AIS_LengthDimension.hxx>
1233#include <BRepExtrema_ExtCC.hxx>
1234#include <BRepExtrema_ExtPC.hxx>
1235#include <BRepExtrema_ExtCF.hxx>
1236#include <BRepExtrema_ExtPF.hxx>
1237#include <BRepExtrema_ExtFF.hxx>
1238#include <TCollection_ExtendedString.hxx>
1239#include <BRepExtrema_DistShapeShape.hxx>
af203d54 1240#include <gce_MakePln.hxx>
7fd59977 1241#include <TopExp_Explorer.hxx>
1242#include <BRepBuilderAPI_MakeVertex.hxx>
af203d54 1243
7fd59977 1244static int VLenghtDimension(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1245{
1246 // Declarations
af203d54 1247 Standard_Integer aCurrentIndex;
7fd59977 1248 // Verification
af203d54 1249 if (argc != 2)
1250 {
1251 di << argv[0] << " error: wrong number of arguments.\n";
1252 return 1;
1253 }
1254
1255 // Close all local contexts
7fd59977 1256 TheAISContext()->CloseAllContexts();
af203d54 1257
1258 // Open local context
1259 aCurrentIndex = TheAISContext()->OpenLocalContext();
1260 // Activate 'edge', 'face' and 'vertex' selection modes.
1261 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1262 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1263 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1264
1265 // First shape picking
1266 di << " Select an edge, a face or a vertex. " << "\n";
1267 // Loop that will handle the picking.
7fd59977 1268 Standard_Integer argc1 = 5;
1269 const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1270 const char **argv1 = (const char **) buf1;
1271 while (ViewerMainLoop( argc1, argv1) ) { }
af203d54 1272 // end of the loop.
7fd59977 1273
af203d54 1274 TopoDS_Shape aFirstShape;
1275 for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
1276 {
1277 aFirstShape = TheAISContext()->SelectedShape();
7fd59977 1278 }
af203d54 1279
1280 if (aFirstShape.IsNull())
1281 {
1282 di << argv[0] << "error: no first picked shape.\n";
1283 return 1;
1284 }
1285
1286 // Second shape picking
1287 di << " Select an edge, a face or a vertex. " << "\n";
1288 // Loop that will handle the picking.
7fd59977 1289 Standard_Integer argc2 = 5;
1290 const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1291 const char **argv2 = (const char **) buf2;
1292 while (ViewerMainLoop( argc2, argv2) ) { }
af203d54 1293
1294 TopoDS_Shape aSecondShape;
1295 for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
1296 {
1297 aSecondShape = TheAISContext()->SelectedShape();
7fd59977 1298 }
af203d54 1299
1300 if (aSecondShape.IsNull())
1301 {
1302 di << argv[0] << "error: no second picked shape.\n";
1303 return 1;
1304 }
1305
1306 if (aFirstShape.ShapeType() == TopAbs_EDGE)
1307 {
1308 TopoDS_Edge EdgeA = TopoDS::Edge (aFirstShape);
1309
1310 if (aSecondShape.ShapeType() == TopAbs_EDGE)
1311 {
1312 TopoDS_Edge EdgeB = TopoDS::Edge (aSecondShape);
1313 BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB);
1314
1315 if (!myDeltaEdge.IsParallel())
1316 {
1317 di << argv[0] << " error: non parallel edges." << "\n";
1318 return 1;
1319 }
1320
1321 // 3 points of edges is recovered to build a plane
1322 TopoDS_Vertex aVertex1, aVertex2, aVertex3, aVertex4;
1323 TopExp::Vertices (EdgeA, aVertex1, aVertex2);
1324 TopExp::Vertices (EdgeB, aVertex3, aVertex4);
1325 gp_Pnt A = BRep_Tool::Pnt (aVertex1);
1326 gp_Pnt B = BRep_Tool::Pnt (aVertex2);
1327 gp_Pnt C = BRep_Tool::Pnt (aVertex3);
1328
1329 gce_MakePln aMakePlane (A,B,C);
1330 gp_Pln aPlane= aMakePlane.Value();
1331
1332 // Close local context
1333 TheAISContext()->CloseLocalContext (aCurrentIndex);
1334
1335 // Construct the dimension
1336 Handle(AIS_LengthDimension ) aLenghtDim = new AIS_LengthDimension (EdgeA, EdgeB, aPlane);
1337 TheAISContext()->Display (aLenghtDim);
1338 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
7fd59977 1339 }
af203d54 1340
1341 else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1342 {
1343 TopoDS_Vertex aVertex = TopoDS::Vertex (aSecondShape);
1344 BRepExtrema_ExtPC myDeltaEdgeVertex (aVertex ,EdgeA);
1345
1346 TopoDS_Vertex aVertex1, aVertex2;
1347 TopExp::Vertices (EdgeA, aVertex1, aVertex2);
1348 gp_Pnt A=BRep_Tool::Pnt (aVertex1);
1349 gp_Pnt B=BRep_Tool::Pnt (aVertex2);
1350 gp_Pnt C=BRep_Tool::Pnt (aVertex);
1351
1352 gce_MakePln aMakePlane (A,B,C);
1353 gp_Pln aPlane= aMakePlane.Value();
1354
1355 TheAISContext()->CloseLocalContext (aCurrentIndex);
1356 Handle(AIS_LengthDimension) aLenghtDim=new AIS_LengthDimension (EdgeA, aVertex, aPlane);
1357 TheAISContext()->Display (aLenghtDim);
1358 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
7fd59977 1359 }
af203d54 1360
1361 // Second shape is a face
a6eb515f 1362 else
1363 {
af203d54 1364 TopoDS_Face FaceB = TopoDS::Face (aSecondShape);
1365 BRepExtrema_ExtCF aDeltaEdgeFace (EdgeA,FaceB);
1366
1367 if (!aDeltaEdgeFace.IsParallel())
1368 {
1369 di << argv[0] << "error: the edge isn't parallel to the face;can't compute the distance." << "\n";
1370 return 1;
1371 }
1372
1373 Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceB, EdgeA);
1374 TheAISContext()->Display (aLenghtDim);
1375 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
7fd59977 1376 }
7fd59977 1377 }
af203d54 1378 else if (aFirstShape.ShapeType() == TopAbs_VERTEX)
1379 {
1380 TopoDS_Vertex VertexA = TopoDS::Vertex (aFirstShape);
1381 if (aSecondShape.ShapeType() == TopAbs_EDGE )
1382 {
1383 TopoDS_Edge EdgeB=TopoDS::Edge (aSecondShape);
1384 BRepExtrema_ExtPC aDeltaEdgeVertex (VertexA, EdgeB);
a6eb515f 1385
af203d54 1386 TopoDS_Vertex aVertex1, aVertex2;
1387 TopExp::Vertices(EdgeB, aVertex1, aVertex2);
1388 gp_Pnt A = BRep_Tool::Pnt (aVertex1);
1389 gp_Pnt B = BRep_Tool::Pnt (aVertex2);
1390 gp_Pnt C = BRep_Tool::Pnt (VertexA);
7fd59977 1391
af203d54 1392 gce_MakePln aMakePlane (A,B,C);
1393 gp_Pln aPlane = aMakePlane.Value();
1394
1395 // Close local contex by its index.
1396 TheAISContext()->CloseLocalContext (aCurrentIndex);
1397
1398 // Construct the dimension.
1399 Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (EdgeB,VertexA, aPlane);
1400 TheAISContext()->Display (aLenghtDim);
1401 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
7fd59977 1402 }
af203d54 1403
1404 else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1405 {
1406 TopoDS_Vertex VertexB = TopoDS::Vertex (aSecondShape);
1407
1408 gp_Pnt A = BRep_Tool::Pnt (VertexA);
1409 gp_Pnt B = BRep_Tool::Pnt (VertexB);
1410 gp_Pnt C(B.X() + 10.0, B.Y() + 10.0, B.Z() + 10.0);
1411
1412 gce_MakePln aMakePlane (A,B,C);
1413 gp_Pln aPlane= aMakePlane.Value();
1414
1415 TheAISContext()->CloseLocalContext (aCurrentIndex);
1416
1417 Handle(AIS_LengthDimension ) aLenghtDim = new AIS_LengthDimension (VertexA, VertexB, aPlane);
1418 TheAISContext()->Display (aLenghtDim);
1419 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1420 }
1421 // The second shape is face
1422 else
1423 {
1424 TopoDS_Face FaceB = TopoDS::Face (aSecondShape);
1425
1426 BRepExtrema_ExtPF aDeltaVertexFace (VertexA, FaceB);
1427
1428 gp_Pnt A = BRep_Tool::Pnt (VertexA);
1429
1430 // Recover edge from face.
1431 TopExp_Explorer aFaceExp (FaceB,TopAbs_EDGE);
1432 TopoDS_Edge aSecondEdge = TopoDS::Edge (aFaceExp.Current());
1433
1434 TopoDS_Vertex aVertex1, aVertex2;
1435 TopExp::Vertices (aSecondEdge, aVertex1, aVertex2);
1436 gp_Pnt C = BRep_Tool::Pnt (aVertex2);
1437
1438 gp_Pnt aProjA = aDeltaVertexFace.Point(1);
1439 BRepBuilderAPI_MakeVertex aVertexMaker (aProjA);
1440 TopoDS_Vertex aVertexAProj = aVertexMaker.Vertex();
1441
1442 // Create working plane for the dimension.
1443 gce_MakePln aMakePlane (A, aProjA, C);
1444 gp_Pln aPlane = aMakePlane.Value();
1445
1446 TheAISContext()->CloseLocalContext (aCurrentIndex);
1447
1448 // Construct the dimension.
1449 Handle(AIS_LengthDimension ) aLenghtDim = new AIS_LengthDimension (VertexA, aVertexAProj, aPlane);
1450 TheAISContext()->Display (aLenghtDim);
1451 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
7fd59977 1452 }
7fd59977 1453 }
af203d54 1454
1455 // The first shape is a face.
1456 else
1457 {
1458 TopoDS_Face FaceA = TopoDS::Face (aFirstShape);
1459
1460 if (aSecondShape.ShapeType() == TopAbs_EDGE)
1461 {
1462 TopoDS_Edge EdgeB = TopoDS::Edge (aSecondShape);
1463 BRepExtrema_ExtCF aDeltaEdgeFace (EdgeB,FaceA );
1464
1465 if (!aDeltaEdgeFace.IsParallel())
1466 {
1467 di << argv[0] << " error: the edge isn't parallel to the face;can't compute the distance. " << "\n";
1468 return 1;
1469 }
1470
1471 Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceA, EdgeB);
1472 TheAISContext()->Display (aLenghtDim);
1473 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
7fd59977 1474 }
af203d54 1475
1476 else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1477 {
1478 TopoDS_Vertex VertexB = TopoDS::Vertex (aSecondShape);
1479 BRepExtrema_ExtPF aDeltaVertexFace (VertexB, FaceA);
1480
1481 gp_Pnt B = BRep_Tool::Pnt (VertexB);
1482
1483 TopExp_Explorer aFaceExp (FaceA, TopAbs_EDGE);
1484 TopoDS_Edge anEdgeFromA = TopoDS::Edge (aFaceExp.Current());
1485 TopoDS_Vertex aVertex1, aVertex2;
1486 TopExp::Vertices(anEdgeFromA, aVertex1, aVertex2);
1487 gp_Pnt A=BRep_Tool::Pnt(aVertex1);
60bf98ae 1488
7fd59977 1489#ifdef DEB
af203d54 1490 gp_Pnt C = BRep_Tool::Pnt(aVertex2);
7fd59977 1491#endif
7fd59977 1492
af203d54 1493 gp_Pnt aProjB = aDeltaVertexFace.Point(1);
1494 BRepBuilderAPI_MakeVertex aVertexMaker (aProjB);
1495 TopoDS_Vertex aVertexBProj = aVertexMaker.Vertex();
1496 gce_MakePln aMakePlane (A, B, aProjB);
1497 gp_Pln aPlane= aMakePlane.Value();
1498
1499 TheAISContext()->CloseLocalContext(aCurrentIndex);
1500
1501 Handle(AIS_LengthDimension) aLenghtDim =new AIS_LengthDimension (VertexB, aVertexBProj, aPlane);
1502 TheAISContext()->Display (aLenghtDim);
1503 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
7fd59977 1504 }
af203d54 1505 // the second shape is face.
1506 else
1507 {
1508 TopoDS_Face FaceB = TopoDS::Face (aSecondShape);
1509 BRepExtrema_ExtFF aDeltaFaceFace (FaceA, FaceB);
1510
1511 if (!aDeltaFaceFace.IsParallel())
1512 {
1513 di << argv[0] << " error: the faces are not parallel. "<<"\n";
1514 return 1;
1515 }
1516
1517 TheAISContext()->CloseLocalContext (aCurrentIndex);
1518
1519 Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceA,FaceB);
1520 TheAISContext()->Display (aLenghtDim);
1521 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
7fd59977 1522 }
7fd59977 1523 }
af203d54 1524
7fd59977 1525 return 0;
7fd59977 1526}
1527
1528
1529//==============================================================================
1530//function : VRadiusDim
1531//purpose : Display the radius dimension of a face or an edge.
1532//Draw arg : vradiusdim Name
1533//==============================================================================
1534#include <AIS_RadiusDimension.hxx>
1535#include <TCollection_ExtendedString.hxx>
1536#include <BRepAdaptor_Curve.hxx>
1537#include <gp_Circ.hxx>
1538
1539
1540static int VRadiusDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1541{
1542 // Declarations
af203d54 1543 Standard_Integer aCurrentIndex;
1544 Standard_Real aRadius;
1545 TopoDS_Edge anEdge;
7fd59977 1546 // Verification
af203d54 1547 if (argc != 2)
1548 {
1549 di << argv[0] << " error: wrong number of parameters." << "\n";
1550 return 1;
1551 }
1552
1553 // Close all local contexts
7fd59977 1554 TheAISContext()->CloseAllContexts();
af203d54 1555
1556 // Open local context and get its index for recovery.
7fd59977 1557 TheAISContext()->OpenLocalContext();
af203d54 1558 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1559
1560 // Current selection modes - faces and edges
1561 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1562 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1563 di << " Select a circled edge or face." << "\n";
1564
1565 // Loop that will be handle picking.
7fd59977 1566 Standard_Integer argcc = 5;
1567 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1568 const char **argvv = (const char **) buff;
af203d54 1569 while (ViewerMainLoop (argcc, argvv)) { }
1570 // end of the loop
1571
1572 TopoDS_Shape aShape;
1573
1574 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() )
1575 {
1576 aShape = TheAISContext()->SelectedShape();
7fd59977 1577 }
af203d54 1578
1579 if (aShape.IsNull())
1580 {
1581 di << argv[0] << ": no shape is selected." << "\n";
1582 return 1;
7fd59977 1583 }
af203d54 1584
1585 if (aShape.ShapeType() != TopAbs_EDGE && aShape.ShapeType() != TopAbs_FACE)
1586 {
1587 di << argv[0] << " error: the selection of a face or an edge was expected." << "\n";
1588 return 1;
7fd59977 1589 }
af203d54 1590
1591 if (aShape.ShapeType() == TopAbs_EDGE)
1592 {
1593 anEdge = TopoDS::Edge (aShape);
7fd59977 1594 }
af203d54 1595 else // Face
1596 {
1597 // Recover an edge of the face.
1598 TopoDS_Face aFace = TopoDS::Face (aShape);
1599
1600 TopExp_Explorer aFaceExp (aFace,TopAbs_EDGE);
1601 anEdge = TopoDS::Edge (aFaceExp.Current());
1602 }
1603
1604 // Compute the radius
1605 BRepAdaptor_Curve aCurve (anEdge);
1606 if (aCurve.GetType() != GeomAbs_Circle)
1607 {
1608 di << argv[0] << " error: the edge is not a circular one." << "\n";
1609 return 1;
1610 }
1611 else
1612 {
1613 gp_Circ aCircle = aCurve.Circle();
1614 aRadius = aCircle.Radius();
1615 aRadius = Round (aRadius * 10.0) / 10.0;
1616 }
1617 // Close the context
1618 TheAISContext()->CloseLocalContext (aCurrentIndex);
1619
1620 // Construct radius dimension
1621 Handle (AIS_RadiusDimension) aRadDim= new AIS_RadiusDimension (aShape);
1622 VDisplayAISObject (argv[1], aRadDim);
1623
7fd59977 1624 return 0;
7fd59977 1625}
1626
1627
1628
1629//==============================================================================
1630//function : VOffsetDim
1631//purpose : Display the offset dimension
1632//Draw arg : voffsetdim Name
1633//==============================================================================
1634#include <AIS_OffsetDimension.hxx>
1635#include <TCollection_ExtendedString.hxx>
1636#include <BRepExtrema_ExtFF.hxx>
1637
1638
1639static int VOffsetDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1640{
1641 // Declarations
1642 Standard_Integer myCurrentIndex;
1643 Standard_Real theDist;
1644
1645 // Verification
1646 if (argc!=2) {di<<" voffsetdim error"<<"\n";return 1;}
1647
1648 // Fermeture des contextes locaux
1649 TheAISContext()->CloseAllContexts();
1650
1651 // Ouverture d'un contexte local et recuperation de son index.
1652 TheAISContext()->OpenLocalContext();
1653 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1654
1655 // On active les modes de selections Faces.
1656 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1657 di<<" Select a face."<<"\n";
1658
1659 // Boucle d'attente waitpick.
1660 Standard_Integer argcc = 5;
1661 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1662 const char **argvv = (const char **) buff;
1663 while (ViewerMainLoop( argcc, argvv) ) { }
1664 // fin de la boucle
1665
1666 TopoDS_Shape ShapeA;
1667 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1668 ShapeA = TheAISContext()->SelectedShape();
1669 }
1670
1671 di<<" Select a face."<<"\n";
1672 // Boucle d'attente waitpick.
1673 Standard_Integer argccc = 5;
1674 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1675 const char **argvvv = (const char **) bufff;
1676 while (ViewerMainLoop( argccc, argvvv) ) { }
1677 // fin de la boucle
1678
1679 TopoDS_Shape ShapeB;
1680 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1681 ShapeB = TheAISContext()->SelectedShape();
1682 }
1683
1684
1685 // Shape A et B est une face
1686 if (ShapeA.ShapeType()==TopAbs_FACE && ShapeB.ShapeType()==TopAbs_FACE ) {
1687
1688 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1689 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1690
1691 BRepExtrema_ExtFF myDeltaFaceFace (FaceA ,FaceB );
1692 // On verifie que les deux faces sont bien parelles.
1693 if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1694
1695 // On saisit la distance et on l'arrondit!
1696 theDist=Round (sqrt (myDeltaFaceFace.SquareDistance(1))*10. )/10.;
1697 // Fermeture du contexte local.
1698 TheAISContext()->CloseLocalContext(myCurrentIndex);
1699 // Construction du texte.
1700 TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("offset=")+TCollection_ExtendedString(theDist ) );
1701
1702 // on construit l'AIS_OffsetDimension
1703 Handle(AIS_OffsetDimension) myOffsetDim=new AIS_OffsetDimension (FaceA,FaceB,theDist,TheMessage_Str );
1704 TheAISContext()->Display(myOffsetDim );
1705 GetMapOfAIS().Bind (myOffsetDim ,argv[1]);
1706
1707
1708
1709 }
1710
1711 else {
1712 di<<" voffsetdim error: the selection of a face was expected."<<"\n";return 1;
1713 }
1714
1715 return 0;
1716
1717}
1718
1719
1720
1721
1722//==============================================================================
1723//function : VParallel
1724//purpose : Display the parallel relation
1725//Draw arg : vparallel Name
1726//==============================================================================
1727#include <AIS_ParallelRelation.hxx>
1728#include <TCollection_ExtendedString.hxx>
1729#include <BRepExtrema_ExtFF.hxx>
1730#include <BRepExtrema_ExtCC.hxx>
1731#include <GC_MakePlane.hxx>
1732#include <BRepAdaptor_Curve.hxx>
1733#include <TopExp_Explorer.hxx>
1734
1735
1736static int VParallelBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1737{
1738 // Declarations
1739 Standard_Integer myCurrentIndex;
1740
1741 // Verification
1742 if (argc!=2) {di<<" vparallel error"<<"\n";return 1;}
1743
1744 // Fermeture des contextes locaux
1745 TheAISContext()->CloseAllContexts();
1746
1747 // Ouverture d'un contexte local et recuperation de son index.
1748 TheAISContext()->OpenLocalContext();
1749 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1750
1751 // On active les modes de selections Edges.
1752 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1753 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1754 di<<" Select an edge or a face "<<"\n";
1755
1756 // Boucle d'attente waitpick.
1757 Standard_Integer argcc = 5;
1758 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1759 const char **argvv = (const char **) buff;
1760 while (ViewerMainLoop( argcc, argvv) ) { }
1761 // fin de la boucle
1762
1763 TopoDS_Shape ShapeA;
1764 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1765 ShapeA = TheAISContext()->SelectedShape();
1766 }
1767
1768 // SahpeA est un edge.
1769 // ===================
1770 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1771
1772 // desactivation du mode face
1773 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1774 di<<" Select a second edge"<<"\n";
1775 // Boucle d'attente waitpick.
1776 Standard_Integer argccc = 5;
1777 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1778 const char **argvvv = (const char **) bufff;
1779 while (ViewerMainLoop( argccc, argvvv) ) { }
1780 // fin de la boucle
1781
1782 TopoDS_Shape ShapeB;
1783 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1784 ShapeB = TheAISContext()->SelectedShape();
1785 }
1786
1787 // recuperation des edges.
1788 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1789 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1790 BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB );
1791 // on verifie qu'ils ne sont pas paralleles.
1792 if (!myDeltaEdge.IsParallel() ) {di<<"vparallel error: non parallel edges."<<"\n";return 1; }
1793
1794
1795 // On recupere les vertexes extremites des edge A et B.
1796 BRepAdaptor_Curve theCurveA(EdgeA);
1797 BRepAdaptor_Curve theCurveB(EdgeB);
1798 // On recupere 3 points A,B,C des curves.
1799 gp_Pnt A=theCurveA.Value(0.1);
1800 gp_Pnt B=theCurveA.Value(0.9);
1801 gp_Pnt C=theCurveB.Value(0.5);
1802
1803 // Construction du Geom_Plane
1804 GC_MakePlane MkPlane(A,B,C);
1805 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1806 // Fermeture du contexte local.
1807 TheAISContext()->CloseLocalContext(myCurrentIndex);
1808 // Construction de l'AIS_ParallelRelation
1809 Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(EdgeA ,EdgeB ,theGeomPlane );
1810 TheAISContext()->Display(myParaRelation );
1811 GetMapOfAIS().Bind (myParaRelation ,argv[1]);
1812
1813
1814 }
1815
1816 // Shape A est une face
1817 // ====================
1818 else {
1819
1820 // desactivation du mode edge
1821 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1822 di<<" Select a second edge"<<"\n";
1823 // Boucle d'attente waitpick.
1824 Standard_Integer argccc = 5;
1825 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1826 const char **argvvv = (const char **) bufff;
1827 while (ViewerMainLoop( argccc, argvvv) ) { }
1828 // fin de la boucle
1829
1830 TopoDS_Shape ShapeB;
1831 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1832 ShapeB = TheAISContext()->SelectedShape();
1833 }
1834
1835 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1836 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1837
1838 BRepExtrema_ExtFF myDeltaFaceFace (FaceA ,FaceB );
1839 // On verifie que les deux faces sont bien parelles.
1840 if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1841
1842 // recuperation des edges des faces.
1843 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
1844 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
1845
1846 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
1847 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
1848
1849 // On recupere les vertexes extremites des edge A et B.
1850 BRepAdaptor_Curve theCurveA(EdgeA);
1851 BRepAdaptor_Curve theCurveB(EdgeB);
1852 // On recupere 3 points A,B,C des curves.
1853 gp_Pnt A=theCurveA.Value(0.1);
1854 gp_Pnt B=theCurveA.Value(0.9);
1855 gp_Pnt C=theCurveB.Value(0.5);
1856
1857 // Construction du Geom_Plane
1858 GC_MakePlane MkPlane(A,B,C);
1859 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1860 // Fermeture du contexte local.
1861 TheAISContext()->CloseLocalContext(myCurrentIndex);
1862 // Construction de l'AIS_ParallelRelation
1863 Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(FaceA ,FaceB ,theGeomPlane );
1864 TheAISContext()->Display(myParaRelation );
1865 GetMapOfAIS().Bind (myParaRelation ,argv[1]);
1866
1867
1868
1869 }
1870
1871
1872 return 0;
1873
1874}
1875
1876
1877
1878
1879//==============================================================================
1880//function : VPerpendicularRelation
1881//purpose : Display the Perpendicular Relation
1882//Draw arg : vperpendicular Name
1883//==============================================================================
1884#include <AIS_PerpendicularRelation.hxx>
1885#include <TCollection_ExtendedString.hxx>
1886#include <GC_MakePlane.hxx>
1887#include <BRepAdaptor_Curve.hxx>
1888#include <TopExp_Explorer.hxx>
1889
1890
1891
1892static int VPerpendicularBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1893{
1894 // Declarations
1895 Standard_Integer myCurrentIndex;
1896
1897 // Verification
1898 if (argc!=2) {di<<" vortho error"<<"\n";return 1;}
1899
1900 // Fermeture des contextes locaux
1901 TheAISContext()->CloseAllContexts();
1902
1903 // Ouverture d'un contexte local et recuperation de son index.
1904 TheAISContext()->OpenLocalContext();
1905 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1906
1907 // On active les modes de selections Edges.
1908 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1909 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1910 di<<" Select an edge or a face "<<"\n";
1911
1912 // Boucle d'attente waitpick.
1913 Standard_Integer argcc = 5;
1914 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1915 const char **argvv = (const char **) buff;
1916 while (ViewerMainLoop( argcc, argvv) ) { }
1917 // fin de la boucle
1918
1919 TopoDS_Shape ShapeA;
1920 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1921 ShapeA = TheAISContext()->SelectedShape();
1922 }
1923
1924 // ShapeA est un edge.
1925 // ===================
1926 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1927
1928 // desactivation du mode face
1929 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1930 di<<" Select a second edge"<<"\n";
1931 // Boucle d'attente waitpick.
1932 Standard_Integer argccc = 5;
1933 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1934 const char **argvvv = (const char **) bufff;
1935 while (ViewerMainLoop( argccc, argvvv) ) { }
1936 // fin de la boucle
1937
1938 TopoDS_Shape ShapeB;
1939 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1940 ShapeB = TheAISContext()->SelectedShape();
1941 }
1942
1943 // recuperation des edges.
1944 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1945 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1946
1947 // On recupere les curves
1948 BRepAdaptor_Curve theCurveA(EdgeA);
1949 BRepAdaptor_Curve theCurveB(EdgeB);
1950 // on verifie si les edges sont orthogonaux.
1951 //gp_Lin theLineA=theCurveA.Line();
1952 //gp_Lin theLineB=theCurveB.Line();
c6541a0c 1953 //if (abs(theLineA.Angle(theLineB) ) != M_PI/2 ) {cout<<"vperpendicular error: Edges are not othogonals."<<endl;return 1;}
7fd59977 1954
1955 // On recupere 3 points A,B,C des curves.
1956 gp_Pnt A=theCurveA.Value(0.1);
1957 gp_Pnt B=theCurveA.Value(0.9);
1958 gp_Pnt C=theCurveB.Value(0.5);
1959 // Construction du Geom_Plane
1960 GC_MakePlane MkPlane(A,B,C);
1961 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1962 // Fermeture du contexte local.
1963 TheAISContext()->CloseLocalContext(myCurrentIndex);
1964 // Construction de l'AIS_ParallelRelation
1965 Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation (EdgeA ,EdgeB ,theGeomPlane );
1966 TheAISContext()->Display(myOrthoRelation );
1967 GetMapOfAIS().Bind (myOrthoRelation ,argv[1]);
1968
1969
1970 }
1971
1972 // Shape A est une face
1973 // ====================
1974 else {
1975
1976 // desactivation du mode edge
1977 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1978 di<<" Select a second edge"<<"\n";
1979 // Boucle d'attente waitpick.
1980 Standard_Integer argccc = 5;
1981 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1982 const char **argvvv = (const char **) bufff;
1983 while (ViewerMainLoop( argccc, argvvv) ) { }
1984 // fin de la boucle
1985
1986 TopoDS_Shape ShapeB;
1987 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1988 ShapeB = TheAISContext()->SelectedShape();
1989 }
1990
1991 // pas de verification d'orthogonalite.
1992 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1993 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1994
1995 // recuperation des edges des faces.
1996 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
1997 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
1998
1999 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
2000 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
2001
2002 // On recupere les vertexes extremites des edge A et B.
2003 BRepAdaptor_Curve theCurveA(EdgeA);
2004 BRepAdaptor_Curve theCurveB(EdgeB);
2005 // On recupere 3 points A,B,C des curves.
2006 gp_Pnt A=theCurveA.Value(0.1);
2007 gp_Pnt B=theCurveA.Value(0.9);
2008 gp_Pnt C=theCurveB.Value(0.5);
2009 // Construction du Geom_Plane
2010 GC_MakePlane MkPlane(A,B,C);
2011 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2012 // Fermeture du contexte local.
2013 TheAISContext()->CloseLocalContext(myCurrentIndex);
2014 // Construction de l'AIS_PerpendicularRelation
2015 Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation(FaceA ,FaceB );
2016 TheAISContext()->Display(myOrthoRelation );
2017 GetMapOfAIS().Bind (myOrthoRelation ,argv[1]);
2018
2019
2020
2021 }
2022
2023
2024 return 0;
2025
2026}
2027
2028
2029//==============================================================================
2030//function : VTangentRelation
2031//purpose : Display the tangent Relation
2032//Draw arg : vtangent Name
2033//==============================================================================
2034#include <AIS_TangentRelation.hxx>
2035
2036
2037static int VTangentBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2038{
2039 // Declarations
2040 Standard_Integer myCurrentIndex;
2041
2042 // Verification
2043 if (argc!=2) {di<<" vtangent error"<<"\n";return 1;}
2044
2045 // Fermeture des contextes locaux
2046 TheAISContext()->CloseAllContexts();
2047
2048 // Ouverture d'un contexte local et recuperation de son index.
2049 TheAISContext()->OpenLocalContext();
2050 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
2051
2052 // On active les modes de selections Edges.
2053 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
2054 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2055 di<<" Select two coplanar edges(First the circular edge then the tangent edge) or two faces "<<"\n";
2056
2057 // Boucle d'attente waitpick.
2058 Standard_Integer argcc = 5;
2059 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2060 const char **argvv = (const char **) buff;
2061 while (ViewerMainLoop( argcc, argvv) ) { }
2062 // fin de la boucle
2063
2064 TopoDS_Shape ShapeA;
2065 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2066 ShapeA = TheAISContext()->SelectedShape();
2067 }
2068
2069 // ShapeA est un edge.
2070 // ===================
2071 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
2072
2073 // desactivation du mode face
2074 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2075 di<<" Select a second edge"<<"\n";
2076 // Boucle d'attente waitpick.
2077 Standard_Integer argccc = 5;
2078 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2079 const char **argvvv = (const char **) bufff;
2080 while (ViewerMainLoop( argccc, argvvv) ) { }
2081 // fin de la boucle
2082
2083 TopoDS_Shape ShapeB;
2084 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2085 ShapeB = TheAISContext()->SelectedShape();
2086 }
2087
2088 // recuperation des edges.
2089 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
2090 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
2091
2092 // On recupere les curves
2093 BRepAdaptor_Curve theCurveA(EdgeA);
2094 BRepAdaptor_Curve theCurveB(EdgeB);
2095
2096 // On recupere 3 points A,B,C des curves.
2097 gp_Pnt A=theCurveA.Value(0.1);
2098 gp_Pnt B=theCurveA.Value(0.9);
2099 gp_Pnt C=theCurveB.Value(0.5);
2100
2101 // Construction du Geom_Plane
2102 GC_MakePlane MkPlane(A,B,C);
2103 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2104 // Fermeture du contexte local.
2105 TheAISContext()->CloseLocalContext(myCurrentIndex);
2106 // Construction de l'AIS_TangentRelation
2107 Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation (EdgeA ,EdgeB ,theGeomPlane );
2108 TheAISContext()->Display(myTanRelation );
2109 GetMapOfAIS().Bind (myTanRelation ,argv[1]);
2110
2111
2112 }
2113
2114 // Shape A est une face
2115 // ====================
2116 else {
2117
2118 // desactivation du mode edge
2119 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
2120 di<<" Select a second edge"<<"\n";
2121 // Boucle d'attente waitpick.
2122 Standard_Integer argccc = 5;
2123 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2124 const char **argvvv = (const char **) bufff;
2125 while (ViewerMainLoop( argccc, argvvv) ) { }
2126 // fin de la boucle
2127
2128 TopoDS_Shape ShapeB;
2129 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2130 ShapeB = TheAISContext()->SelectedShape();
2131 }
2132
2133 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
2134 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
2135
2136 // recuperation des edges des faces.
2137 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
2138 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
2139
2140 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
2141 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
2142
2143 // On recupere les vertexes extremites des edge A et B.
2144 BRepAdaptor_Curve theCurveA(EdgeA);
2145 BRepAdaptor_Curve theCurveB(EdgeB);
2146 // On recupere 3 points A,B,C des curves.
2147 gp_Pnt A=theCurveA.Value(0.1);
2148 gp_Pnt B=theCurveA.Value(0.9);
2149 gp_Pnt C=theCurveB.Value(0.5);
2150
2151 // Construction du Geom_Plane
2152 GC_MakePlane MkPlane(A,B,C);
2153 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2154 // Fermeture du contexte local.
2155 TheAISContext()->CloseLocalContext(myCurrentIndex);
2156 // Construction de l'AIS_PerpendicularRelation
2157 Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation(FaceA ,FaceB,theGeomPlane );
2158 TheAISContext()->Display(myTanRelation );
2159 GetMapOfAIS().Bind (myTanRelation ,argv[1]);
2160
2161
2162
2163 }
2164
2165
2166 return 0;
2167
2168}
2169
2170//==============================================================================
2171//function : VSymetricalRelation
2172//purpose : Display the Symetrical Relation
2173//Draw arg : vsymetric Name
2174//==============================================================================
2175#include <AIS_SymmetricRelation.hxx>
2176
2177
2178static int VSymmetricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2179{
2180 // Declarations
2181 Standard_Integer myCurrentIndex;
2182
2183 // Verification
2184 if (argc!=2) {di<<" vSymmetric error"<<"\n";return 1;}
2185
2186 // Fermeture des contextes locaux
2187 TheAISContext()->CloseAllContexts();
2188
2189 // Ouverture d'un contexte local et recuperation de son index.
2190 TheAISContext()->OpenLocalContext();
2191 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
2192
2193 // On active les modes de selections
2194 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
2195 di<<" Select an edge:the axis of symetry "<<"\n";
2196
2197 // Boucle d'attente waitpick.
2198 Standard_Integer argcc = 5;
2199 const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2200 const char **argvv = (const char **) buff;
2201 while (ViewerMainLoop( argcc, argvv) ) { }
2202 // fin de la boucle
2203
2204 TopoDS_Shape ShapeA;
2205 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2206 ShapeA = TheAISContext()->SelectedShape();
2207 }
2208 // recuperation des edges.
2209 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
2210
2211 // On active les modes de selections
2212 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
2213 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2214 di<<" Select two edges or two vertices. "<<"\n";
2215
2216 // Boucle d'attente waitpick.
2217 Standard_Integer argcc2 = 5;
2218// const char *buff2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2219 const char **argvv2 = (const char **) buff;
2220 while (ViewerMainLoop( argcc2, argvv2) ) { }
2221 // fin de la boucle
2222
2223 TopoDS_Shape ShapeB;
2224 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2225 ShapeB = TheAISContext()->SelectedShape();
2226 }
2227
2228
2229
2230
2231
2232 // ShapeB est un edge.
2233 // ===================
2234 if (ShapeB.ShapeType()==TopAbs_EDGE ) {
2235
2236 // desactivation du mode vertex
2237 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) );
2238 di<<" Select a second edge"<<"\n";
2239 // Boucle d'attente waitpick.
2240 Standard_Integer argccc = 5;
2241 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2242 const char **argvvv = (const char **) bufff;
2243 while (ViewerMainLoop( argccc, argvvv) ) { }
2244 // fin de la boucle
2245
2246 TopoDS_Shape ShapeC;
2247 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2248 ShapeC = TheAISContext()->SelectedShape();
2249 }
2250
2251 // recuperation des edges.
2252 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
2253 TopoDS_Edge EdgeC=TopoDS::Edge(ShapeC);
2254 // on verifie que les edges sont paralleles
2255 BRepExtrema_ExtCC myDeltaEdgeAB (EdgeA ,EdgeB );
2256 BRepExtrema_ExtCC myDeltaEdgeAC (EdgeA ,EdgeC );
2257 // on verifie qu'ils sont paralleles.
2258 if (!myDeltaEdgeAB.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; }
2259 if (!myDeltaEdgeAC.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; }
2260 // on recupere les vertexs
2261 TopoDS_Vertex Va,Vb,Vc,Vd;
2262 TopExp::Vertices(EdgeB,Va,Vb );
2263 TopExp::Vertices(EdgeC,Vc,Vd );
2264 gp_Pnt A=BRep_Tool::Pnt(Va);
2265 gp_Pnt B=BRep_Tool::Pnt(Vc);
2266 gp_Pnt C = Get3DPointAtMousePosition();
2267
2268 // gp_Pnt C=BRep_Tool::Pnt(Vc);
2269 // Construction du Geom_Plane
2270 GC_MakePlane MkPlane(A,B,C);
2271 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2272 // Fermeture du contexte local.
2273 TheAISContext()->CloseLocalContext(myCurrentIndex);
2274 // Construction de l'AIS_SymmetricRelation
2275 Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,EdgeB ,EdgeC, theGeomPlane );
2276 TheAISContext()->Display(mySymRelation );
2277 GetMapOfAIS().Bind (mySymRelation ,argv[1]);
2278
2279
2280 }
2281
2282 // Shape B est un vertex
2283 // =====================
2284 else {
2285
2286 // desactivation du mode edge
2287 TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
2288 di<<" Select a second edge"<<"\n";
2289 // Boucle d'attente waitpick.
2290 Standard_Integer argccc = 5;
2291 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2292 const char **argvvv = (const char **) bufff;
2293 while (ViewerMainLoop( argccc, argvvv) ) { }
2294 // fin de la boucle
2295
2296 TopoDS_Shape ShapeC;
2297 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2298 ShapeC = TheAISContext()->SelectedShape();
2299 }
2300
2301 // recuperation des Vertex
2302 TopoDS_Vertex VertexB=TopoDS::Vertex(ShapeB);
2303 TopoDS_Vertex VertexC=TopoDS::Vertex(ShapeC);
2304 // transfo en gp_Pnt
2305 gp_Pnt B=BRep_Tool::Pnt(VertexB);
2306 gp_Pnt C=BRep_Tool::Pnt(VertexC);
2307
2308 // on recupere les vertexes de l'axe de sym
2309 TopoDS_Vertex Va,Vb;
2310 TopExp::Vertices(EdgeA,Va,Vb );
2311 gp_Pnt A=BRep_Tool::Pnt(Va);
2312 // Construction du Geom_Plane
2313 GC_MakePlane MkPlane(A,B,C);
2314 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2315 // Fermeture du contexte local.
2316 TheAISContext()->CloseLocalContext(myCurrentIndex);
2317 // Construction de l'AIS_SymmetricRelation
2318 Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,VertexB ,VertexC, theGeomPlane );
2319 TheAISContext()->Display(mySymRelation );
2320 GetMapOfAIS().Bind (mySymRelation ,argv[1]);
2321
2322
2323
2324 }
2325
2326
2327 return 0;
2328
2329}
af203d54 2330
7fd59977 2331//=======================================================================
af203d54 2332//function : VDimParam
2333//purpose : Moves dimension or relation text label to defined or picked
2334// position and updates the object.
7fd59977 2335//=======================================================================
af203d54 2336static int VDimParam (Draw_Interpretor& theDi, Standard_Integer theArgNum, const char** theArgVec)
7fd59977 2337{
af203d54 2338 if (theArgNum < 3)
2339 {
2340 theDi << theArgVec[0] << " error: the wrong number of input parameters.\n";
2341 return 1;
2342 }
2343
2344 // Get dimension name
2345 TCollection_AsciiString aName (theArgVec[1]);
2346 if (!GetMapOfAIS().IsBound2 (aName))
2347 {
2348 theDi << theArgVec[0] << "error: no object with this name.\n";
2349 return 1;
2350 }
2351
2352 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
2353 if (anObject->Type() != AIS_KOI_Dimension)
2354 {
2355 theDi << theArgVec[0] << "error: no dimension with this name.\n";
2356 return 1;
2357 }
2358 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (anObject);
2359 Handle(Prs3d_DimensionAspect) anAspect = aDim->DimensionAspect();
2360
2361 // Parse parameters
2362 gp_Pln aWorkingPlane;
2363 Standard_Real aCustomFlyout = 0.0;
2364
2365 for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
2366 {
2367 TCollection_AsciiString anArgString = theArgVec[anIt];
2368 TCollection_AsciiString aParamName;
2369 TCollection_AsciiString aParamValue;
2370 if (ViewerTest::SplitParameter (anArgString, aParamName, aParamValue))
2371 {
2372 aParamName.LowerCase();
2373 aParamValue.LowerCase();
2374
2375 if (aParamName == "text")
2376 {
2377 anAspect->MakeText3d (aParamValue == "3d");
2378 }
2379 else if (aParamName == "name")
2380 {
2381 if (aParamValue.IsEmpty())
2382 {
2383 std::cerr << theArgVec[0] << ": no name for dimension.\n";
2384 return 1;
2385 }
2386
2387 aName = aParamValue;
2388 }
2389 else if (aParamName == "plane")
2390 {
2391 if (aParamValue == "xoy")
2392 {
2393 aWorkingPlane = gp_Pln (gp_Ax3 (gp::XOY()));
2394 }
2395 else if (aParamValue == "zox")
2396 {
2397 aWorkingPlane = gp_Pln (gp_Ax3 (gp::ZOX()));
2398 }
2399 else if (aParamValue == "yoz")
2400 {
2401 aWorkingPlane = gp_Pln (gp_Ax3 (gp::YOZ()));
2402 }
2403 else
2404 {
2405 std::cerr << theArgVec[0] << ": wrong plane.\n";
2406 return 1;
2407 }
2408 }
2409 else if (aParamName == "label")
2410 {
2411 NCollection_List<TCollection_AsciiString> aListOfLabelVals;
2412 while (aParamValue.Length() > 0)
2413 {
2414 TCollection_AsciiString aValue = aParamValue;
2415
2416 Standard_Integer aSeparatorPos = aParamValue.Search (",");
2417 if (aSeparatorPos >= 0)
2418 {
2419 aValue.Trunc (aSeparatorPos - 1);
2420 aParamValue.Remove (aSeparatorPos, 1);
2421 }
2422
2423 aListOfLabelVals.Append (aValue);
2424
2425 aParamValue.Remove (1, aValue.Length());
2426 }
2427
2428 NCollection_List<TCollection_AsciiString>::Iterator aLabelValueIt (aListOfLabelVals);
2429 for ( ; aLabelValueIt.More(); aLabelValueIt.Next())
2430 {
2431 aParamValue = aLabelValueIt.Value();
2432
2433 if (aParamValue == "left")
2434 {
2435 anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Left);
2436 }
2437 else if (aParamValue == "right")
2438 {
2439 anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Right);
2440 }
2441 else if (aParamValue == "hcenter")
2442 {
2443 anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Center);
2444 }
2445 else if (aParamValue == "hfit")
2446 {
2447 anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Fit);
2448 }
2449 else if (aParamValue == "above")
2450 {
2451 anAspect->SetTextVerticalPosition (Prs3d_DTVP_Above);
2452 }
2453 else if (aParamValue == "below")
2454 {
2455 anAspect->SetTextVerticalPosition (Prs3d_DTVP_Below);
2456 }
2457 else if (aParamValue == "vcenter")
2458 {
2459 anAspect->SetTextVerticalPosition (Prs3d_DTVP_Center);
2460 }
2461 else
2462 {
2463 std::cerr << theArgVec[0] << ": invalid label position: \"" << aParamValue << "\".\n";
2464 return 1;
2465 }
2466 }
2467 }
2468 else if (aParamName == "flyout")
2469 {
2470 if (!aParamValue.IsRealValue())
2471 {
2472 std::cerr << theArgVec[0] << ": numeric value expected for flyout.\n";
2473 return 1;
2474 }
2475
2476 aCustomFlyout = aParamValue.RealValue();
2477 aDim->SetFlyout (aCustomFlyout);
2478 }
2479 else if (aParamName == "arrows")
2480 {
2481 if (aParamValue == "external")
2482 {
2483 anAspect->SetArrowOrientation (Prs3d_DAO_External);
2484 }
2485 else if (aParamValue == "internal")
2486 {
2487 anAspect->SetArrowOrientation (Prs3d_DAO_Internal);
2488 }
2489 else if (aParamValue == "fit")
2490 {
2491 anAspect->SetArrowOrientation (Prs3d_DAO_Fit);
2492 }
2493 }
2494 else
2495 {
2496 std::cerr << theArgVec[0] << ": unknow parameter: \"" << aParamName << "\".\n";
2497 return 1;
2498 }
7fd59977 2499 }
7fd59977 2500 }
af203d54 2501
2502 // Redisplay a dimension after parameter changing.
2503 ViewerTest::GetAISContext()->Redisplay (aDim);
2504 return 0;
2505}
2506
2507//=======================================================================
2508//function : VMoveDim
2509//purpose : Moves dimension or relation text label to defined or picked
2510// position and updates the object.
2511//draw args: vmovedim [name] [x y z]
2512//=======================================================================
2513static int VMoveDim (Draw_Interpretor& theDi, Standard_Integer theArgNum, const char** theArgVec)
2514{
2515 if (theArgNum > 5)
2516 {
2517 theDi << theArgVec[0] << " error: the wrong number of parameters.\n";
7fd59977 2518 return 1;
af203d54 2519 }
2520
2521 // Parameters parsing
2522 Standard_Boolean isNameSet = (theArgNum ==2 || theArgNum == 5);
2523 Standard_Boolean isPointSet = (theArgNum == 4 || theArgNum == 5);
2524
2525 Handle(AIS_InteractiveObject) aPickedObj;
2526 gp_Pnt aPoint (gp::Origin());
2527 Standard_Integer aCurrentIndex = 0;
2528 Standard_Integer aMaxPickNum = 5;
2529
2530 // Find object
2531 if (isNameSet)
2532 {
2533 TCollection_AsciiString aName (theArgVec[1]);
2534 if (!GetMapOfAIS().IsBound2 (aName))
2535 {
2536 theDi << theArgVec[0] << " error: no object with this name.\n";
2537 return 1;
2538 }
2539
2540 aPickedObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2541
2542 if (aPickedObj.IsNull())
2543 {
2544 theDi << theArgVec[0] << " error: the object with this name is not valid.\n";
2545 return 1;
2546 }
2547
2548 if (aPickedObj->Type() != AIS_KOI_Dimension && aPickedObj->Type() != AIS_KOI_Relation)
2549 {
2550 theDi << theArgVec[0] << " error: no dimension or relation with this name.\n";
2551 return 1;
2552 }
2553 }
2554 else // Pick dimension or relation
2555 {
2556 // Close all local contexts
2557 TheAISContext()->CloseAllContexts();
2558
2559 // Open local context and get its index for recovery.
2560 TheAISContext()->OpenLocalContext();
2561 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
7fd59977 2562
af203d54 2563 // Loop that will be handle picking.
2564 Standard_Integer anArgNum = 5;
2565 const char *aBuffer[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2566 const char **anArgVec = (const char **) aBuffer;
2567
2568 Standard_Boolean isPicked = Standard_False;
2569 Standard_Integer aPickNum = 0;
2570 while (!isPicked && aPickNum < aMaxPickNum)
2571 {
2572 while (ViewerMainLoop (anArgNum, anArgVec)) { }
2573
2574 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
2575 {
2576 aPickedObj = TheAISContext()->SelectedInteractive();
2577 }
2578
2579 isPicked = (!aPickedObj.IsNull() && (aPickedObj->Type() == AIS_KOI_Dimension || aPickedObj->Type() == AIS_KOI_Relation));
2580
2581 if (isPicked)
2582 {
2583 break;
2584 }
2585 aPickNum++;
7fd59977 2586 }
af203d54 2587 if (!isPicked)
2588 {
2589 theDi << theArgVec[0] << ": no dimension or relation is selected." << "\n";
2590 return 1;
7fd59977 2591 }
af203d54 2592 }
2593
2594 // Find point
2595 if (isPointSet)
2596 {
2597 aPoint = theArgNum == 4 ? gp_Pnt (atoi (theArgVec[1]), atoi (theArgVec[2]), atoi (theArgVec[3]))
2598 : gp_Pnt (atoi (theArgVec[2]), atoi (theArgVec[3]), atoi (theArgVec[4]));
2599 }
2600 else // Pick the point
2601 {
2602 Standard_Integer aPickArgNum = 5;
2603 const char *aPickBuff[] = {"VPick", "X", "VPickY", "VPickZ", "VPickShape"};
2604 const char **aPickArgVec = (const char **) aPickBuff;
2605
2606 while (ViewerMainLoop (aPickArgNum, aPickArgVec)) { }
2607
2608 // Set text position, update relation or dimension.
2609 if (aPickedObj->Type() == AIS_KOI_Relation)
2610 {
2611 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (aPickedObj);
2612 aPoint = Get3DPointAtMousePosition();
2613 aRelation->SetPosition (aPoint);
2614 TheAISContext()->Redisplay (aRelation);
2615 }
2616 else
2617 {
2618 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (aPickedObj);
2619 gp_Pnt aFirstPoint, aSecondPoint;
2620 if (aDim->KindOfDimension() == AIS_KOD_PLANEANGLE)
2621 {
2622 Handle(AIS_AngleDimension) anAngleDim = Handle(AIS_AngleDimension)::DownCast (aDim);
2623 aFirstPoint = anAngleDim->FirstPoint();
2624 aSecondPoint = anAngleDim->SecondPoint();
2625 }
2626 else if (aDim->KindOfDimension() == AIS_KOD_LENGTH)
2627 {
2628 Handle(AIS_LengthDimension) aLengthDim = Handle(AIS_LengthDimension)::DownCast (aDim);
2629 aFirstPoint = aLengthDim->FirstPoint();
2630 aSecondPoint = aLengthDim->SecondPoint();
2631 }
2632 else if (aDim->KindOfDimension() == AIS_KOD_RADIUS)
2633 {
2634 Handle(AIS_RadiusDimension) aRadiusDim = Handle(AIS_RadiusDimension)::DownCast (aDim);
2635 aFirstPoint = aRadiusDim->AnchorPoint();
2636 aSecondPoint = aRadiusDim->Circle().Location();
2637 }
2638 else if (aDim->KindOfDimension() == AIS_KOD_DIAMETER)
2639 {
2640 Handle(AIS_DiameterDimension) aDiameterDim = Handle(AIS_DiameterDimension)::DownCast (aDim);
2641 aFirstPoint = aDiameterDim->AnchorPoint();
2642 aSecondPoint = aDiameterDim->Circle().Location();
2643 }
2644
2645 if (!Get3DPointAtMousePosition (aFirstPoint, aSecondPoint, aPoint))
2646 {
2647 return 1;
7fd59977 2648 }
af203d54 2649
2650 aDim->SetTextPosition (aPoint);
2651 TheAISContext()->Redisplay (aDim);
7fd59977 2652 }
af203d54 2653
7fd59977 2654 }
af203d54 2655
2656 // Set text position, update relation or dimension.
2657 if (aPickedObj->Type() == AIS_KOI_Relation)
2658 {
2659 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (aPickedObj);
2660 aRelation->SetPosition (aPoint);
2661 TheAISContext()->Redisplay (aRelation);
2662 }
2663 else
2664 {
2665 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (aPickedObj);
2666 aDim->SetTextPosition (aPoint);
2667 TheAISContext()->Redisplay (aDim);
2668 }
2669
7fd59977 2670 return 0;
2671}
a6eb515f 2672
7fd59977 2673//=======================================================================
2674//function : RelationsCommands
2675//purpose :
2676//=======================================================================
2677
2678
2679void ViewerTest::RelationCommands(Draw_Interpretor& theCommands)
2680{
2681 const char *group = "AISRelations";
2682
1d7ca641 2683 theCommands.Add("vdimension",
2684 "vdimension {angle|length|radius|diameter} name={Dim_Name} shape1 [shape2 [shape3]]\n"
2685 " [text={2d|3d}] [plane={xoy|yoz|zox}]\n"
2686 " [label={left|right|hcenter|hfit},{above|below|vcenter}]\n"
2687 " [flyout=value] [arrows={external|internal|fit}]\n"
af203d54 2688 " -Builds angle, length, radius and diameter dimensions.\n",
a6eb515f 2689 __FILE__,VDimBuilder,group);
2690
af203d54 2691 theCommands.Add("vdimparam",
2692 "vdimparam Dim_Name"
2693 " [text={2d|3d}] [plane={xoy|yoz|zox}]\n"
2694 " [label={left|right|hcenter|hfit},{above|below|vcenter}]\n"
2695 " [flyout=value] [arrows={external|internal|fit}]\n"
2696 " -Sets parameters for angle, length, radius and diameter dimensions.\n",
2697 __FILE__,VDimParam,group);
2698
7fd59977 2699 theCommands.Add("vangledim",
2700 "vangledim Name:Selection in the viewer only ",
2701 __FILE__,VAngleDimBuilder,group);
2702
2703 theCommands.Add("vdiameterdim",
2704 "vdiameterdim Name : Selection in the viewer only ",
2705 __FILE__,VDiameterDimBuilder,group);
2706
2707 theCommands.Add("vconcentric",
2708 "vconcentric Name : Selection in the viewer only ",
2709 __FILE__,VConcentricBuilder,group);
2710
2711 theCommands.Add("vequaldist",
2712 "vequaldist Name Selection in the viewer only ",
2713 __FILE__,VEqualDistRelation ,group);
2714
2715 theCommands.Add("vequalrad",
2716 "vequalrad Name Selection in the viewer only ",
2717 __FILE__,VEqualRadiusRelation ,group);
2718
2719 theCommands.Add("vfix",
2720 "vfix Name Selection in the viewer only ",
2721 __FILE__,VFixRelation ,group);
2722
2723 theCommands.Add("videntity",
2724 "videntity Name Selection in the viewer only ",
2725 __FILE__,VIdenticRelation ,group);
2726
2727 theCommands.Add("vdistdim",
2728 "vdistdim Name Selection in the viewer only ",
2729 __FILE__,VLenghtDimension ,group);
2730
2731 theCommands.Add("vradiusdim",
2732 "vradiusdim Name Selection in the viewer only ",
2733 __FILE__,VRadiusDimBuilder ,group);
2734
2735 theCommands.Add("voffsetdim",
2736 "voffsetdim Name Selection in the viewer only ",
2737 __FILE__,VOffsetDimBuilder ,group);
2738
2739 theCommands.Add("vparallel",
2740 "vparallel Name Selection in the viewer only ",
2741 __FILE__,VParallelBuilder ,group);
2742
2743 theCommands.Add("vortho",
2744 "vortho Name Selection in the viewer only ",
2745 __FILE__,VPerpendicularBuilder ,group);
2746
2747 theCommands.Add("vtangent",
2748 "vtangent Name Selection in the viewer only ",
2749 __FILE__,VTangentBuilder ,group);
2750
2751
2752 theCommands.Add("vsymetric",
2753 "vsymetric Name Selection in the viewer only ",
2754 __FILE__,VSymmetricBuilder ,group);
2755
2756 theCommands.Add("vmovedim",
2757 "vmovedim [name] : move Mouse in the viewer; click MB1 to stop motion...",
2758 __FILE__,VMoveDim,group);
2759
2760}