1 // Created on: 1996-12-05
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 #include <AIS_AngleDimension.hxx>
24 #include <AIS_Dimension.hxx>
25 #include <AIS_DimensionOwner.hxx>
26 #include <AIS_Drawer.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepBuilderAPI_MakeFace.hxx>
29 #include <BRepAdaptor_Curve.hxx>
30 #include <BRepAdaptor_Surface.hxx>
31 #include <BRepLib_MakeVertex.hxx>
34 #include <DsgPrs_AnglePresentation.hxx>
39 #include <GC_MakeCircle.hxx>
40 #include <GC_MakeConicalSurface.hxx>
41 #include <gce_MakeLin.hxx>
42 #include <gce_MakeLin2d.hxx>
43 #include <gce_MakePln.hxx>
44 #include <gce_MakeCirc.hxx>
45 #include <gce_MakeCone.hxx>
46 #include <Geom2d_Circle.hxx>
47 #include <Geom2d_Curve.hxx>
48 #include <Geom2d_Line.hxx>
49 #include <Geom2dAPI_ExtremaCurveCurve.hxx>
50 #include <GeomAPI.hxx>
51 #include <Geom_Circle.hxx>
52 #include <Geom_Line.hxx>
53 #include <Geom_Plane.hxx>
54 #include <Geom_TrimmedCurve.hxx>
55 #include <Geom_Surface.hxx>
56 #include <Geom_CylindricalSurface.hxx>
57 #include <Geom_ConicalSurface.hxx>
58 #include <Geom_SurfaceOfRevolution.hxx>
59 #include <Geom_SurfaceOfLinearExtrusion.hxx>
60 #include <Geom_OffsetSurface.hxx>
61 #include <GeomAPI_ExtremaCurveCurve.hxx>
62 #include <Graphic3d_ArrayOfSegments.hxx>
63 #include <Graphic3d_AspectLine3d.hxx>
67 #include <gp_Cone.hxx>
70 #include <gp_Pnt2d.hxx>
73 #include <Graphic3d_Group.hxx>
74 #include <Graphic3d_ArrayOfPrimitives.hxx>
75 #include <Graphic3d_ArrayOfPolylines.hxx>
77 #include <IntAna2d_AnaIntersection.hxx>
78 #include <IntAna2d_IntPoint.hxx>
79 #include <IntAna_QuadQuadGeo.hxx>
80 #include <IntAna_ResultType.hxx>
81 #include <Poly_Polygon3D.hxx>
82 #include <Precision.hxx>
83 #include <ProjLib.hxx>
84 #include <Prs3d_ArrowAspect.hxx>
85 #include <Prs3d_DimensionAspect.hxx>
86 #include <Prs3d_Drawer.hxx>
87 #include <Prs3d_Root.hxx>
88 #include <PrsMgr_PresentationManager3d.hxx>
89 #include <Select3D_SensitiveCurve.hxx>
90 #include <Select3D_SensitiveSegment.hxx>
91 #include <Select3D_SensitiveBox.hxx>
92 #include <SelectMgr_EntityOwner.hxx>
93 #include <SelectMgr_Selection.hxx>
94 #include <Standard_NotImplemented.hxx>
95 #include <Standard_Type.hxx>
96 #include <Standard_Macro.hxx>
97 #include <Standard_DefineHandle.hxx>
99 #include <TColStd_Array1OfReal.hxx>
100 #include <TopExp.hxx>
101 #include <TopExp_Explorer.hxx>
102 #include <TopoDS.hxx>
103 #include <TopoDS_Shape.hxx>
104 #include <TopoDS_Vertex.hxx>
105 #include <UnitsAPI.hxx>
107 IMPLEMENT_STANDARD_HANDLE (AIS_AngleDimension, AIS_Dimension)
108 IMPLEMENT_STANDARD_RTTIEXT (AIS_AngleDimension, AIS_Dimension)
110 //=======================================================================
112 //purpose : Private constructor for default initialization
113 //=======================================================================
115 void AIS_AngleDimension::init()
117 // Default values of units
118 UnitsAPI::SetLocalSystem (UnitsAPI_SI);
119 SetUnitsQuantity ("PLANE ANGLE");
120 SetModelUnits ("rad");
121 SetDisplayUnits ("deg");
122 SetSpecialSymbol (0x00B0);
123 SetDisplaySpecialSymbol (AIS_DSS_After);
124 MakeUnitsDisplayed (Standard_False);
127 //=======================================================================
128 //function : Constructor
129 //purpose : Two edges dimension
130 //=======================================================================
132 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Edge& theFirstEdge,
133 const TopoDS_Edge& theSecondEdge)
135 myIsFlyoutLines (Standard_True),
140 SetKindOfDimension (AIS_KOD_PLANEANGLE);
141 myFirstShape = theFirstEdge;
142 mySecondShape = theSecondEdge;
145 //=======================================================================
146 //function : Constructor
147 //purpose : Two edges dimension
148 // <thePlane> is used in case of Angle=PI
149 //=======================================================================
151 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Edge& theFirstEdge,
152 const TopoDS_Edge& theSecondEdge,
153 const gp_Pln& thePlane)
155 myIsFlyoutLines (Standard_True),
160 SetKindOfDimension (AIS_KOD_PLANEANGLE);
161 myFirstShape = theFirstEdge;
162 mySecondShape = theSecondEdge;
163 SetWorkingPlane (thePlane);
166 //=======================================================================
167 //function : Constructor
168 //purpose : Two edges dimension with aspect
169 // <thePlane> is used in case of Angle=PI
170 //=======================================================================
172 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Edge& theFirstEdge,
173 const TopoDS_Edge& theSecondEdge,
174 const gp_Pln& thePlane,
175 const Handle(Prs3d_DimensionAspect)& theDimensionAspect,
176 const Standard_Real theExtensionSize)
177 : AIS_Dimension (theDimensionAspect,theExtensionSize),
178 myIsFlyoutLines (Standard_True),
182 SetKindOfDimension (AIS_KOD_PLANEANGLE);
183 myFirstShape = theFirstEdge;
184 mySecondShape = theSecondEdge;
185 SetWorkingPlane (thePlane);
188 //=======================================================================
189 //function : Constructor
190 //purpose : Three points dimension
191 //=======================================================================
193 AIS_AngleDimension::AIS_AngleDimension (const gp_Pnt& theFirstPoint,
194 const gp_Pnt& theSecondPoint,
195 const gp_Pnt& theThirdPoint)
197 myIsFlyoutLines (Standard_True),
201 myIsInitialized = Standard_True;
202 SetKindOfDimension (AIS_KOD_PLANEANGLE);
203 myFirstPoint = theFirstPoint;
204 myCenter = theSecondPoint;
205 mySecondPoint = theThirdPoint;
209 //=======================================================================
210 //function : Constructor
211 //purpose : Three points dimension
212 //=======================================================================
214 AIS_AngleDimension::AIS_AngleDimension (const gp_Pnt& theFirstPoint,
215 const gp_Pnt& theSecondPoint,
216 const gp_Pnt& theThirdPoint,
217 const Handle(Prs3d_DimensionAspect)& theDimensionAspect,
218 const Standard_Real theExtensionSize)
219 : AIS_Dimension (theDimensionAspect,theExtensionSize),
220 myIsFlyoutLines (Standard_True),
223 myIsInitialized = Standard_True;
224 SetKindOfDimension (AIS_KOD_PLANEANGLE);
225 myFirstPoint = theFirstPoint;
226 myCenter = theSecondPoint;
227 mySecondPoint = theThirdPoint;
231 //=======================================================================
232 //function : Constructor
233 //purpose : Cone dimension
234 //=======================================================================
236 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Face& theCone)
238 myIsFlyoutLines (Standard_True),
242 myIsInitialized = Standard_False;
243 SetKindOfDimension (AIS_KOD_PLANEANGLE);
244 myFirstShape = theCone;
248 //=======================================================================
249 //function : Constructor
250 //purpose : Two faces dimension
251 //=======================================================================
253 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Face& theFirstFace,
254 const TopoDS_Face& theSecondFace,
255 const gp_Ax1& theAxis)
257 myIsFlyoutLines (Standard_True),
261 myIsInitialized = Standard_False;
262 SetKindOfDimension (AIS_KOD_PLANEANGLE);
263 myFirstShape = theFirstFace;
264 mySecondShape = theSecondFace;
267 aPlane.SetAxis (theAxis);
268 SetWorkingPlane (aPlane);
271 //=======================================================================
272 //function : SetFirstShape
274 //=======================================================================
276 void AIS_AngleDimension::SetFirstShape (const TopoDS_Shape& theShape,
277 const Standard_Boolean isSingleShape /*= Standard_False*/)
279 AIS_Dimension::SetFirstShape (theShape);
284 //=======================================================================
285 //function : aboveInBelowCone
286 //purpose : Returns 1 if <theC> center is above of <theCMin> center;
287 // 0 if <theC> center is between <theCMin> and
288 // <theCMax> centers;
289 // -1 if <theC> center is below <theCMax> center.
290 //=======================================================================
292 Standard_Integer AIS_AngleDimension::aboveInBelowCone (const gp_Circ &theCMax,
293 const gp_Circ &theCMin,
296 const Standard_Real aD = theCMax.Location().Distance (theCMin.Location());
297 const Standard_Real aD1 = theCMax.Location().Distance (theC.Location());
298 const Standard_Real aD2 = theCMin.Location().Distance (theC.Location());
300 if (aD >= aD1 && aD >= aD2) return 0;
301 if (aD < aD2 && aD1 < aD2) return -1;
302 if (aD < aD1 && aD2 < aD1) return 1;
306 //=======================================================================
307 //function : initConeAngle
308 //purpose : initialization of the cone angle
309 //=======================================================================
311 Standard_Boolean AIS_AngleDimension::initConeAngle (const TopoDS_Face& theCone)
313 if (theCone.IsNull ())
314 return Standard_False;
319 // A surface from the Face
320 Handle(Geom_Surface) aSurf;
321 Handle(Geom_OffsetSurface) aOffsetSurf;
322 Handle(Geom_ConicalSurface) aConicalSurf;
323 Handle(Geom_SurfaceOfRevolution) aRevSurf;
324 Handle(Geom_Line) aLine;
325 BRepAdaptor_Surface aConeAdaptor (theCone);
327 AIS_KindOfSurface aSurfType;
328 Standard_Real anOffset = 0.;
329 Handle(Standard_Type) aType;
331 Standard_Real aMaxV = aConeAdaptor.FirstVParameter();
332 Standard_Real aMinV = aConeAdaptor.LastVParameter();
334 AIS::GetPlaneFromFace(theCone, aPln, aSurf, aSurfType, anOffset);
336 if (aSurfType == AIS_KOS_Revolution)
338 // Surface of revolution
339 aRevSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(aSurf);
340 gp_Lin aLin (aRevSurf->Axis());
341 Handle(Geom_Curve) aBasisCurve = aRevSurf->BasisCurve();
342 //Must be a part of line (basis curve should be linear)
343 if (aBasisCurve ->DynamicType() != STANDARD_TYPE(Geom_Line))
344 return Standard_False;
346 gp_Pnt aFirst1 = aConeAdaptor.Value (0., aMinV);
347 gp_Pnt aLast1 = aConeAdaptor.Value (0., aMaxV);
348 gp_Vec aVec1 (aFirst1, aLast1);
350 //Projection <aFirst> on <aLin>
351 gp_Pnt aFirst2 = ElCLib::Value (ElCLib::Parameter (aLin, aFirst1), aLin);
352 // Projection <aLast> on <aLin>
353 gp_Pnt aLast2 = ElCLib::Value (ElCLib::Parameter (aLin, aLast1), aLin);
355 gp_Vec aVec2 (aFirst2, aLast2);
357 // Check if two parts of revolution are parallel (it's a cylinder) or normal (it's a circle).
358 if (aVec1.IsParallel (aVec2, Precision::Angular())
359 || aVec1.IsNormal (aVec2,Precision::Angular()))
360 return Standard_False;
362 gce_MakeCone aMkCone (aRevSurf->Axis(), aFirst1, aLast1);
363 aCone = aMkCone.Value();
364 myCenter = aCone.Apex();
368 aType = aSurf->DynamicType();
369 if (aType == STANDARD_TYPE(Geom_OffsetSurface) || anOffset > 0.01)
372 aOffsetSurf = new Geom_OffsetSurface (aSurf, anOffset);
373 aSurf = aOffsetSurf->Surface();
374 BRepBuilderAPI_MakeFace aMkFace(aSurf, Precision::Confusion());
376 if (!aMkFace.IsDone())
377 return Standard_False;
378 aConeAdaptor.Initialize (aMkFace.Face());
380 aCone = aConeAdaptor.Cone();
381 aConicalSurf = Handle(Geom_ConicalSurface)::DownCast (aSurf);
382 myCenter = aConicalSurf->Apex();
385 // A circle where the angle is drawn
386 Handle(Geom_Curve) aCurve;
387 Standard_Real aMidV = ( aMinV + aMaxV ) / 2.5;
388 aCurve = aSurf->VIso (aMidV);
389 aCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
391 aCurve = aSurf->VIso(aMaxV);
392 gp_Circ aCircVmax = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
393 aCurve = aSurf->VIso(aMinV);
394 gp_Circ aCircVmin = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
397 if (aCircVmax.Radius() < aCircVmin.Radius())
399 gp_Circ aTmpCirc = aCircVmax;
400 aCircVmax = aCircVmin;
401 aCircVmin = aTmpCirc;
404 myFirstPoint = ElCLib::Value (0, aCircle);
405 mySecondPoint = ElCLib::Value (M_PI, aCircle);
406 return Standard_True;
409 //=======================================================================
410 //function : initTwoFacesAngle
411 //purpose : initialization of angle dimension between two faces
412 //=======================================================================
414 Standard_Boolean AIS_AngleDimension::initTwoFacesAngle ()
416 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
417 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
418 gp_Dir aFirstDir, aSecondDir;
419 gp_Pln aFirstPlane, aSecondPlane;
420 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
421 AIS_KindOfSurface aFirstSurfType, aSecondSurfType;
422 Standard_Real aFirstOffset, aSecondOffset;
424 AIS::GetPlaneFromFace (aFirstFace, aFirstPlane,
425 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
426 AIS::GetPlaneFromFace (aSecondFace, aSecondPlane,
427 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
429 if (aFirstSurfType == AIS_KOS_Plane)
432 AIS::ComputeAngleBetweenPlanarFaces (aFirstFace,
435 GetWorkingPlane().Axis(),
438 myGeom.myTextPosition,
447 // Curvilinear faces angle
448 Handle(Geom_Plane) aPlane = new Geom_Plane (GetWorkingPlane());
449 AIS::ComputeAngleBetweenCurvilinearFaces (aFirstFace,
455 GetWorkingPlane().Axis(),
458 myGeom.myTextPosition,
465 SetWorkingPlane (aPlane->Pln());
467 return Standard_True;
470 //=======================================================================
471 //function : SetFlyout
473 //=======================================================================
475 void AIS_AngleDimension::SetFlyout (const Standard_Real theFlyout)
477 myFlyout = theFlyout;
480 //=======================================================================
481 //function : GetFlyout
483 //=======================================================================
485 Standard_Real AIS_AngleDimension::GetFlyout () const
490 //=======================================================================
491 //function : countDefaultPlane
493 //=======================================================================
495 void AIS_AngleDimension::countDefaultPlane ()
497 if (!myIsInitialized)
499 // Compute normal of the default plane.
500 gp_Vec aVec1(myCenter, myFirstPoint),
501 aVec2(myCenter, mySecondPoint);
502 myDefaultPlane = gp_Pln(myCenter, aVec1^aVec2);
503 // Set computed value to <myWorkingPlane>
504 ResetWorkingPlane ();
507 //=======================================================================
508 //function : computeValue
510 //=======================================================================
512 void AIS_AngleDimension::computeValue ()
514 gp_Vec aVec1 (myCenter, myFirstPoint),
515 aVec2 (myCenter, mySecondPoint);
516 myValue = aVec1.Angle (aVec2);
518 AIS_Dimension::computeValue();
521 //=======================================================================
522 //function : initTwoEdgesAngle
523 //purpose : Fill gp_Pnt fields for further presentation computation
524 // If intersection between two edges doesn't exist
525 // <myIsInitialized> is set to false
526 //=======================================================================
528 Standard_Boolean AIS_AngleDimension::initTwoEdgesAngle ()
530 // Data initialization
531 TopoDS_Edge aFirstEdge = TopoDS::Edge (myFirstShape);
532 TopoDS_Edge aSecondEdge = TopoDS::Edge (mySecondShape);
533 BRepAdaptor_Curve aMakeFirstLine (aFirstEdge);
534 BRepAdaptor_Curve aMakeSecondLine (aSecondEdge);
536 if (aMakeFirstLine.GetType() != GeomAbs_Line || aMakeSecondLine.GetType() != GeomAbs_Line)
538 return Standard_False;
541 Handle(Geom_Line) aFirstLine = new Geom_Line (aMakeFirstLine.Line());
542 Handle(Geom_Line) aSecondLine = new Geom_Line (aMakeSecondLine.Line());
544 gp_Lin aFirstLin = aFirstLine->Lin ();
545 gp_Lin aSecondLin = aSecondLine->Lin ();
546 gp_Lin2d aFirstLin2d, aSecondLin2d;
547 Standard_Boolean isParallelLines = aFirstLin.Direction().IsParallel (aSecondLin.Direction(), Precision::Angular());
548 Standard_Boolean isSameLines = isParallelLines && aFirstLin.Distance (aSecondLin.Location()) <= Precision::Confusion();
549 // In case where we can't compute plane automatically
550 if ((isParallelLines || isSameLines) && !myIsWorkingPlaneCustom)
552 return Standard_False;
557 /// PART 1 is for automatic plane computation from two edges if it is possible
559 if (!myIsWorkingPlaneCustom)
561 gp_Pnt aPoint = aFirstLine->Value (0.);
562 gp_Dir aNormal = isParallelLines
563 ? gp_Vec(aSecondLin.Normal (aPoint).Direction()) ^ gp_Vec (aSecondLin.Direction())
564 : gp_Vec (aFirstLin.Direction()) ^ gp_Vec (aSecondLin.Direction());
565 aPlane = gp_Pln (aPoint, aNormal);
566 resetWorkingPlane (aPlane);
570 aPlane = GetWorkingPlane();
573 // Compute geometry for this plane and edges
574 Standard_Boolean isInfinite1,isInfinite2;
575 gp_Pnt aFirstPoint1, aLastPoint1, aFirstPoint2, aLastPoint2;
576 Standard_Integer anExtIndex = -1;
577 Handle(Geom_Curve) anExtCurve;
578 Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
579 if (!AIS::ComputeGeometry (aFirstEdge, aSecondEdge,
581 aFirstLine, aSecondLine,
582 aFirstPoint1, aLastPoint1,
583 aFirstPoint2, aLastPoint2,
585 isInfinite1, isInfinite2,
588 return Standard_False;
591 // Check if both edges are on this plane
592 if (!anExtCurve.IsNull())
594 if (anExtIndex == 1) // First curve is out of the plane
596 // Project curve on the plane
597 if (myIsWorkingPlaneCustom)
599 aFirstLin2d = ProjLib::Project (aPlane, aFirstLin);
600 aFirstLin = ElCLib::To3d (aPlane.Position().Ax2(), aFirstLin2d);
604 aFirstLin.Translate (gp_Vec (aFirstLin.Location(), aSecondLin.Location()));
607 aFirstLine = new Geom_Line (aFirstLin);
609 else if (anExtIndex == 2) // Second curve is out of the plane
611 if (myIsWorkingPlaneCustom)
613 aSecondLin2d = ProjLib::Project (aPlane, aSecondLin);
614 aSecondLin = ElCLib::To3d (aPlane.Position().Ax2(), aSecondLin2d);
618 aSecondLin.Translate (gp_Vec (aSecondLin.Location(), aFirstLin.Location()));
621 aSecondLine = new Geom_Line (aSecondLin);
625 /// PART 2 is for dimension computation using the working plane
627 if (aFirstLin.Direction ().IsParallel (aSecondLin.Direction (), Precision::Angular ()))
630 isSameLines = aFirstLin.Distance(aSecondLin.Location()) <= Precision::Confusion();
632 return Standard_False;
634 myFirstPoint = aFirstLin.Location();
635 mySecondPoint = ElCLib::Value (ElCLib::Parameter (aFirstLin, myFirstPoint), aSecondLin);
636 if (mySecondPoint.Distance (mySecondPoint) <= Precision::Confusion ())
637 mySecondPoint.Translate (gp_Vec (aSecondLin.Direction ())*Abs(GetFlyout()));
638 myCenter.SetXYZ( (myFirstPoint.XYZ() + mySecondPoint.XYZ()) / 2. );
643 aFirstLin2d = ProjLib::Project (aPlane, aFirstLin);
644 aSecondLin2d = ProjLib::Project (aPlane, aSecondLin);
646 IntAna2d_AnaIntersection anInt2d (aFirstLin2d, aSecondLin2d);
647 gp_Pnt2d anIntersectPoint;
648 if (!anInt2d.IsDone() || anInt2d.IsEmpty())
650 return Standard_False;
653 anIntersectPoint = gp_Pnt2d (anInt2d.Point(1).Value());
654 myCenter = ElCLib::To3d(aPlane.Position().Ax2(), anIntersectPoint);
656 if (isInfinite1 || isInfinite2)
658 myFirstPoint = myCenter.Translated (gp_Vec (aFirstLin.Direction())*Abs (GetFlyout()));
659 mySecondPoint = myCenter.Translated (gp_Vec (aSecondLin.Direction())*Abs (GetFlyout()));
660 return Standard_True;
664 // | <- dimension should be here
666 myFirstPoint = myCenter.Distance (aFirstPoint1) > myCenter.Distance (aLastPoint1) ? aFirstPoint1 : aLastPoint1;
667 mySecondPoint = myCenter.Distance (aFirstPoint2) > myCenter.Distance (aLastPoint2) ? aFirstPoint2 : aLastPoint2;
669 return Standard_True;
672 //=======================================================================
673 //function : canTextBeInCenter
674 //purpose : Auxiliary method to arrange text and arrows
675 //=======================================================================
677 Standard_Boolean AIS_AngleDimension::canTextBeInCenter (const gp_Pnt& theFirstAttach,
678 const gp_Pnt& theSecondAttach,
679 const Quantity_Length& theTextLength,
680 const Quantity_Length& theArrowLength)
682 gp_Vec anAttachVector (theFirstAttach, theSecondAttach);
683 Standard_Real aValue = anAttachVector.Magnitude();
684 return (aValue < theTextLength + 2.*theArrowLength) ? Standard_False : Standard_True;
687 //=======================================================================
688 //function: getCenterOnArc
690 //=======================================================================
691 gp_Pnt AIS_AngleDimension::getCenterOnArc (const gp_Pnt& theFirstAttach,
692 const gp_Pnt& theSecondAttach)
694 gp_Pnt2d aCenter2d = ProjLib::Project (GetWorkingPlane(), myCenter),
695 aFirstAttach2d = ProjLib::Project (GetWorkingPlane(), theFirstAttach),
696 aSecondAttach2d = ProjLib::Project (GetWorkingPlane(), theSecondAttach);
697 gp_Lin2d anAttachLine2d = gce_MakeLin2d (aFirstAttach2d, aSecondAttach2d);
699 // Getting text center
700 gp_Pnt2d aTextCenterPnt = ElCLib::Value ((ElCLib::Parameter (anAttachLine2d, aFirstAttach2d) + ElCLib::Parameter (anAttachLine2d, aSecondAttach2d)) / 2., anAttachLine2d);
701 gp_Lin2d aCenterToTextCenterLin = gce_MakeLin2d (aCenter2d, aTextCenterPnt);
704 Standard_Real aRadius = theFirstAttach.Distance (myCenter);
705 gp_Circ2d aCircle (gp_Ax22d (aCenter2d, gp_Dir2d (1, 0)), aRadius);
707 // Getting text position in the center of arc
708 IntAna2d_AnaIntersection anInt2d (aCenterToTextCenterLin, aCircle);
709 gp_Pnt2d aTextCenterOnArc2d;
710 if (anInt2d.IsDone())
711 if (!anInt2d.IsEmpty())
712 aTextCenterOnArc2d = gp_Pnt2d (anInt2d.Point (1).Value());
713 gp_Pnt aCenterOnArc = ElCLib::To3d (GetWorkingPlane().Position().Ax2(), aTextCenterOnArc2d);
717 //=======================================================================
718 //function: drawArcWithText
720 //=======================================================================
722 void AIS_AngleDimension::drawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
723 const gp_Pnt& theFirstAttach,
724 const gp_Pnt& theSecondAttach,
725 const TCollection_ExtendedString& theText,
726 const AIS_DimensionDisplayMode theMode)
728 gp_Pnt2d aCenter2d = ProjLib::Project (GetWorkingPlane(), myCenter),
729 aFirstAttach2d = ProjLib::Project (GetWorkingPlane(), theFirstAttach),
730 aSecondAttach2d = ProjLib::Project (GetWorkingPlane(), theSecondAttach);
731 gp_Lin2d anAttachLine2d = gce_MakeLin2d (aFirstAttach2d, aSecondAttach2d);
733 // Getting text center
734 gp_Pnt2d aTextCenterPnt = ElCLib::Value ((ElCLib::Parameter (anAttachLine2d, aFirstAttach2d) + ElCLib::Parameter (anAttachLine2d, aSecondAttach2d)) / 2., anAttachLine2d);
735 gp_Lin2d aCenterToTextCenterLin = gce_MakeLin2d (aCenter2d, aTextCenterPnt);
738 Standard_Real aRadius = theFirstAttach.Distance (myCenter);
739 gp_Circ2d aCircle (gp_Ax22d (aCenter2d, gp_Dir2d (1, 0)), aRadius);
741 // Getting text position in the center of arc
742 IntAna2d_AnaIntersection anInt2d (aCenterToTextCenterLin, aCircle);
743 gp_Pnt2d aTextCenterOnArc2d;
744 if (anInt2d.IsDone())
745 if (!anInt2d.IsEmpty())
746 aTextCenterOnArc2d = gp_Pnt2d (anInt2d.Point (1).Value());
747 myGeom.myTextPosition = ElCLib::To3d (GetWorkingPlane().Position().Ax2(), aTextCenterOnArc2d);
750 gp_Vec aVec (theFirstAttach, theSecondAttach);
751 Standard_Real aTextWidth = drawText (thePresentation,
752 myIsTextReversed ? aVec.Reversed() : aVec,
755 // Getting text begin and end points
756 gp_Pnt2d aTextBeginPnt = ElCLib::Value ((ElCLib::Parameter (anAttachLine2d, aFirstAttach2d) +
757 ElCLib::Parameter (anAttachLine2d, aSecondAttach2d) -
758 aTextWidth) / 2., anAttachLine2d),
759 aTextEndPnt = ElCLib::Value (ElCLib::Parameter (anAttachLine2d,aTextBeginPnt) + aTextWidth, anAttachLine2d);
762 gp_Lin2d aCenterToTextBeginLin = gce_MakeLin2d (aCenter2d, aTextBeginPnt),
763 aCenterToTextEndLin = gce_MakeLin2d (aCenter2d, aTextEndPnt);
765 // Text begin and end on the dimension arc
766 gp_Pnt2d aTextBeginOnArc2d, aTextEndOnArc2d;
767 anInt2d.Perform (aCenterToTextBeginLin, aCircle);
768 if (anInt2d.IsDone())
769 if (!anInt2d.IsEmpty())
770 aTextBeginOnArc2d = gp_Pnt2d (anInt2d.Point (1).Value());
772 anInt2d.Perform (aCenterToTextEndLin, aCircle);
773 if (anInt2d.IsDone())
774 if (!anInt2d.IsEmpty())
775 aTextEndOnArc2d = gp_Pnt2d (anInt2d.Point (1).Value());
777 gp_Pnt aTextBeginOnArc = ElCLib::To3d (GetWorkingPlane().Position().Ax2(), aTextBeginOnArc2d);
778 gp_Pnt aTextEndOnArc = ElCLib::To3d (GetWorkingPlane().Position().Ax2(), aTextEndOnArc2d);
781 if (theMode != AIS_DDM_Text)
783 drawArc (thePresentation, theFirstAttach, aTextBeginOnArc, myCenter, aRadius, theMode);
784 drawArc (thePresentation, aTextEndOnArc, theSecondAttach, myCenter, aRadius, theMode);
789 //=======================================================================
791 //purpose : draws the arc between two attach points
792 //=======================================================================
794 void AIS_AngleDimension::drawArc (const Handle(Prs3d_Presentation)& thePresentation,
795 const gp_Pnt& theFirstAttach,
796 const gp_Pnt& theSecondAttach,
797 const gp_Pnt& theCenter,
798 const Standard_Real theRadius,
799 const AIS_DimensionDisplayMode theMode)
801 Handle(SelectMgr_EntityOwner) anEmptyOwner;
802 Prs3d_Root::CurrentGroup (thePresentation)->
803 SetPrimitivesAspect(myDrawer->DimensionAspect()->LineAspect()->Aspect());
805 gp_Vec aCenterToFirstVec (theCenter,theFirstAttach);
806 gp_Vec aCenterToSecondVec (theCenter,theSecondAttach);
807 gp_Dir aCenterToFirstDir (aCenterToFirstVec);
808 gp_Dir aPlaneNormal = GetWorkingPlane().Axis().Direction();
809 gp_Dir aCenterToSecondDir = aPlaneNormal.Crossed (aCenterToFirstDir);
811 const Standard_Real anAngle = aCenterToFirstVec.Angle(aCenterToSecondVec);
812 const Standard_Integer aPointsOnArc = Max (4 , Standard_Integer (50. * anAngle / M_PI));
813 const Standard_Real anAngleStep = anAngle / (aPointsOnArc - 1);
814 TColgp_Array1OfPnt aPointArray (0,aPointsOnArc-1);
815 Handle(Graphic3d_ArrayOfPolylines) aPrimSegments = new Graphic3d_ArrayOfPolylines (aPointsOnArc,2);
816 aPrimSegments->AddVertex (theFirstAttach);
817 aPointArray.SetValue(0, theFirstAttach);
818 gp_Pnt aPoint = theFirstAttach;
821 for (Standard_Integer anI = 1; anI < aPointsOnArc - 1; ++anI)
823 aVector = (gp_Vec(aCenterToFirstDir) * Cos ( (anI - 1) * anAngleStep) + gp_Vec(aCenterToSecondDir) * Sin ( (anI - 1) * anAngleStep)) * theRadius;
824 aPoint = theCenter.Translated(aVector);
825 aPrimSegments->AddVertex(aPoint);
826 aPointArray.SetValue (anI,aPoint);
828 aPrimSegments->AddVertex (theSecondAttach);
829 aPointArray.SetValue (aPointsOnArc - 1,theSecondAttach);
831 // Fill sensitive list
832 myGeom.mySensitiveSegments.Append(new Select3D_SensitiveCurve(anEmptyOwner,aPointArray));
834 // Fill display presentation
835 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == AIS_DDM_All)
837 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True);
839 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
840 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == AIS_DDM_All)
842 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False);
846 //=======================================================================
848 //purpose : Having three gp_Pnt points compute presentation
849 //=======================================================================
851 void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
852 const Handle(Prs3d_Presentation)& thePresentation,
853 const Standard_Integer theMode)
855 thePresentation->Clear();
856 myGeom.mySensitiveSegments.Clear();
857 Handle(SelectMgr_EntityOwner) anEmptyOwner;
859 if (!myIsInitialized)
861 if (myShapesNumber == 1)
863 myIsInitialized = initConeAngle (TopoDS::Face (myFirstShape));
865 else if (myShapesNumber == 2)
867 switch (myFirstShape.ShapeType())
871 myIsInitialized = initTwoFacesAngle ();
876 myIsInitialized = initTwoEdgesAngle ();
887 // If initialization failed
888 if (!myIsInitialized)
891 // Parameters for presentation
892 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
893 Prs3d_Root::CurrentGroup(thePresentation)->
894 SetPrimitivesAspect(aDimensionAspect->LineAspect()->Aspect());
895 Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
896 if (!myIsValueCustom)
898 TCollection_ExtendedString aValueString;
899 Standard_Real aTextLength;
900 getTextWidthAndString (aTextLength, aValueString);
901 if (!myIsWorkingPlaneCustom)
903 gp_Pnt aFirstAttach = myCenter.Translated (gp_Vec(myCenter, myFirstPoint).Normalized() * GetFlyout());
904 gp_Pnt aSecondAttach = myCenter.Translated (gp_Vec(myCenter, mySecondPoint).Normalized() * GetFlyout());
905 // Attach points and radius
906 if (aDimensionAspect->HorizontalTextAlignment () == Prs3d_HTA_Center)
908 aDimensionAspect->SetArrowOrientation (Prs3d_DAO_Internal);
910 if (!canTextBeInCenter (aFirstAttach, aSecondAttach, aTextLength, anArrowLength))
912 aDimensionAspect->SetArrowOrientation (Prs3d_DAO_External);
913 aDimensionAspect->SetHorizontalTextAlignment (Prs3d_HTA_Left);
917 aDimensionAspect->SetArrowOrientation (Prs3d_DAO_External);
919 //Arrows positions and directions
920 gp_Vec aFirstArrowVec = (gp_Vec(myCenter, aFirstAttach)^gp_Vec(GetWorkingPlane().Axis().Direction())).Normalized().Reversed()*anArrowLength;
921 gp_Vec aSecondArrowVec = (gp_Vec(myCenter, aSecondAttach)^gp_Vec(GetWorkingPlane().Axis().Direction())).Normalized()*anArrowLength;
923 gp_Pnt aFirstArrowBegin,
928 if (aDimensionAspect->GetArrowOrientation() == Prs3d_DAO_External)
930 aFirstArrowVec.Reverse();
931 aSecondArrowVec.Reverse();
933 aFirstArrowBegin = aFirstAttach.Translated (aFirstArrowVec);
934 aFirstArrowEnd = aFirstAttach;
935 aSecondArrowBegin = aSecondAttach;
936 aSecondArrowEnd = aSecondAttach.Translated (aSecondArrowVec);
940 aFirstArrowBegin = aFirstAttach;
941 aFirstArrowEnd = aFirstAttach.Translated (aFirstArrowVec);
942 aSecondArrowBegin = aSecondAttach.Translated (aSecondArrowVec);
943 aSecondArrowEnd = aSecondAttach;
947 Handle(Graphic3d_ArrayOfSegments) aPrimSegments;
948 Standard_Boolean isTextInCenter = aDimensionAspect->VerticalTextAlignment() == Prs3d_VTA_Center;
949 if (aDimensionAspect->HorizontalTextAlignment() == Prs3d_HTA_Center)
951 // Important! Current implementation doesn't draw the extensions here
952 aPrimSegments = new Graphic3d_ArrayOfSegments (4);
953 // Get text begin and end positions (text is positioned in the center between two attach points)
954 gp_Pnt aTextBeginOnArc, aTextEndOnArc, anArcCenter;
955 if (isTextInCenter && aDimensionAspect->IsText3d())
957 drawArcWithText (thePresentation, aFirstAttach, aSecondAttach, aValueString, (AIS_DimensionDisplayMode)theMode);
961 gp_Vec aTextDir (aFirstArrowEnd, aSecondArrowBegin);
962 myGeom.myTextPosition = getCenterOnArc (aFirstArrowEnd, aSecondArrowBegin);
963 drawText (thePresentation,
964 myIsTextReversed ? aTextDir.Reversed() : aTextDir,
965 aValueString, (AIS_DimensionDisplayMode)theMode);
966 if (theMode != AIS_DDM_Text)
967 drawArc (thePresentation, aFirstArrowEnd, aSecondArrowBegin, myCenter, Abs (GetFlyout()), (AIS_DimensionDisplayMode)theMode);
972 // Lines for extensions
973 gp_Lin aLeftExtension (aFirstAttach,gp_Dir(aFirstArrowVec));
974 gp_Lin aRightExtension (aSecondAttach, gp_Dir(aSecondArrowVec));
975 aPrimSegments = new Graphic3d_ArrayOfSegments (6);
977 if (aDimensionAspect->HorizontalTextAlignment() == Prs3d_HTA_Left)
979 aStartPoint = aFirstArrowBegin;
981 aPrimSegments->AddVertex (aSecondArrowEnd);
982 aPrimSegments->AddVertex (aSecondArrowEnd.Translated(gp_Vec(aRightExtension.Direction())*anArrowLength));
983 myGeom.mySensitiveSegments.Append (new Select3D_SensitiveSegment(anEmptyOwner,
985 aSecondArrowEnd.Translated(gp_Vec(aRightExtension.Direction())*anArrowLength)));
988 drawExtensionWithText (thePresentation, aStartPoint, aLeftExtension, aValueString, (AIS_DimensionDisplayMode)theMode);
990 else // Prs3d_HTA_Right
992 aStartPoint = aSecondArrowEnd;
994 aPrimSegments->AddVertex (aFirstArrowBegin);
995 aPrimSegments->AddVertex (aFirstArrowBegin.Translated (gp_Vec (aLeftExtension.Direction()) * anArrowLength));
996 myGeom.mySensitiveSegments.Append (new Select3D_SensitiveSegment(anEmptyOwner,
998 aFirstArrowBegin.Translated (gp_Vec (aLeftExtension.Direction()) * anArrowLength)));
1001 drawExtensionWithText (thePresentation, aStartPoint, aRightExtension, aValueString, (AIS_DimensionDisplayMode)theMode);
1004 if (theMode != AIS_DDM_Text)
1007 drawArc (thePresentation, aFirstArrowEnd, aSecondArrowBegin, myCenter, Abs(GetFlyout ()), (AIS_DimensionDisplayMode)theMode);
1011 // Draw flyout lines and arrows in new group.
1012 Prs3d_Root::NewGroup (thePresentation)
1013 ->SetPrimitivesAspect (myDrawer->DimensionAspect()->LineAspect()->Aspect());
1014 if (theMode == AIS_DDM_All && myIsFlyoutLines)
1016 aPrimSegments->AddVertex (myCenter);
1017 aPrimSegments->AddVertex (aFirstAttach);
1018 aPrimSegments->AddVertex (myCenter);
1019 aPrimSegments->AddVertex (aSecondAttach);
1021 if (theMode != AIS_DDM_Text)
1023 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
1024 drawArrow (thePresentation, aFirstAttach, gp_Dir (aFirstArrowVec));
1025 drawArrow (thePresentation, aSecondAttach, gp_Dir (aSecondArrowVec));
1028 setComputed (Standard_True);