1 // Created on: 1996-12-05
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_AngleDimension.hxx>
20 #include <BRepBuilderAPI_MakeFace.hxx>
21 #include <BRepAdaptor_Curve.hxx>
22 #include <BRepAdaptor_Surface.hxx>
23 #include <BRepLib_MakeVertex.hxx>
24 #include <BRep_Tool.hxx>
26 #include <GCPnts_UniformAbscissa.hxx>
27 #include <GC_MakeArcOfCircle.hxx>
28 #include <gce_MakeLin2d.hxx>
29 #include <gce_MakeLin.hxx>
30 #include <gce_MakeCirc.hxx>
31 #include <gce_MakeCone.hxx>
32 #include <gce_MakePln.hxx>
33 #include <gce_MakeDir.hxx>
34 #include <Geom_Circle.hxx>
35 #include <Geom_TrimmedCurve.hxx>
36 #include <Geom_ConicalSurface.hxx>
37 #include <Geom_SurfaceOfRevolution.hxx>
38 #include <Geom_OffsetSurface.hxx>
39 #include <Graphic3d_ArrayOfSegments.hxx>
40 #include <Graphic3d_Group.hxx>
41 #include <Graphic3d_ArrayOfPolylines.hxx>
42 #include <IntAna2d_AnaIntersection.hxx>
43 #include <ProjLib.hxx>
44 #include <Prs3d_Root.hxx>
45 #include <Prs3d_ShadingAspect.hxx>
46 #include <PrsMgr_PresentationManager3d.hxx>
47 #include <Select3D_SensitiveGroup.hxx>
48 #include <Select3D_SensitiveSegment.hxx>
49 #include <SelectMgr_Selection.hxx>
50 #include <Standard_ProgramError.hxx>
51 #include <UnitsAPI.hxx>
53 IMPLEMENT_STANDARD_HANDLE (AIS_AngleDimension, AIS_Dimension)
54 IMPLEMENT_STANDARD_RTTIEXT (AIS_AngleDimension, AIS_Dimension)
58 static const TCollection_ExtendedString THE_EMPTY_LABEL_STRING;
59 static const Standard_Real THE_EMPTY_LABEL_WIDTH = 0.0;
60 static const Standard_ExtCharacter THE_DEGREE_SYMBOL (0x00B0);
61 static const Standard_Real THE_3D_TEXT_MARGIN = 0.1;
64 //=======================================================================
65 //function : Constructor
67 //=======================================================================
68 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Edge& theFirstEdge,
69 const TopoDS_Edge& theSecondEdge)
70 : AIS_Dimension (AIS_KOD_PLANEANGLE)
73 SetMeasuredGeometry (theFirstEdge, theSecondEdge);
76 //=======================================================================
77 //function : Constructor
79 //=======================================================================
80 AIS_AngleDimension::AIS_AngleDimension (const gp_Pnt& theFirstPoint,
81 const gp_Pnt& theSecondPoint,
82 const gp_Pnt& theThirdPoint)
83 : AIS_Dimension (AIS_KOD_PLANEANGLE)
86 SetMeasuredGeometry (theFirstPoint, theSecondPoint, theThirdPoint);
89 //=======================================================================
90 //function : Constructor
92 //=======================================================================
93 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Vertex& theFirstVertex,
94 const TopoDS_Vertex& theSecondVertex,
95 const TopoDS_Vertex& theThirdVertex)
96 : AIS_Dimension (AIS_KOD_PLANEANGLE)
99 SetMeasuredGeometry (theFirstVertex, theSecondVertex, theThirdVertex);
102 //=======================================================================
103 //function : Constructor
105 //=======================================================================
106 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Face& theCone)
107 : AIS_Dimension (AIS_KOD_PLANEANGLE)
110 SetMeasuredGeometry (theCone);
113 //=======================================================================
114 //function : Constructor
116 //=======================================================================
117 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Face& theFirstFace,
118 const TopoDS_Face& theSecondFace)
119 : AIS_Dimension (AIS_KOD_PLANEANGLE)
122 SetMeasuredGeometry (theFirstFace, theSecondFace);
125 //=======================================================================
126 //function : Constructor
128 //=======================================================================
129 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Face& theFirstFace,
130 const TopoDS_Face& theSecondFace,
131 const gp_Pnt& thePoint)
132 : AIS_Dimension (AIS_KOD_PLANEANGLE)
135 SetMeasuredGeometry (theFirstFace, theSecondFace, thePoint);
138 //=======================================================================
139 //function : SetMeasuredGeometry
141 //=======================================================================
142 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
143 const TopoDS_Edge& theSecondEdge)
145 gp_Pln aComputedPlane;
147 myFirstShape = theFirstEdge;
148 mySecondShape = theSecondEdge;
149 myThirdShape = TopoDS_Shape();
150 myGeometryType = GeometryType_Edges;
151 myIsGeometryValid = InitTwoEdgesAngle (aComputedPlane);
153 if (myIsGeometryValid && !myIsPlaneCustom)
161 //=======================================================================
162 //function : SetMeasuredGeometry
164 //=======================================================================
165 void AIS_AngleDimension::SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
166 const gp_Pnt& theSecondPoint,
167 const gp_Pnt& theThirdPoint)
169 myFirstPoint = theFirstPoint;
170 myCenterPoint = theSecondPoint;
171 mySecondPoint = theThirdPoint;
172 myFirstShape = BRepLib_MakeVertex (myFirstPoint);
173 mySecondShape = BRepLib_MakeVertex (myCenterPoint);
174 myThirdShape = BRepLib_MakeVertex (mySecondPoint);
175 myGeometryType = GeometryType_Points;
176 myIsGeometryValid = IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
178 if (myIsGeometryValid && !myIsPlaneCustom)
186 //=======================================================================
187 //function : SetMeasuredGeometry
189 //=======================================================================
190 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
191 const TopoDS_Vertex& theSecondVertex,
192 const TopoDS_Vertex& theThirdVertex)
194 myFirstShape = theFirstVertex;
195 mySecondShape = theSecondVertex;
196 myThirdShape = theThirdVertex;
197 myFirstPoint = BRep_Tool::Pnt (theFirstVertex);
198 myCenterPoint = BRep_Tool::Pnt (theSecondVertex);
199 mySecondPoint = BRep_Tool::Pnt (theThirdVertex);
200 myGeometryType = GeometryType_Points;
201 myIsGeometryValid = IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
203 if (myIsGeometryValid && !myIsPlaneCustom)
211 //=======================================================================
212 //function : SetMeasuredGeometry
214 //=======================================================================
215 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theCone)
217 myFirstShape = theCone;
218 mySecondShape = TopoDS_Shape();
219 myThirdShape = TopoDS_Shape();
220 myGeometryType = GeometryType_Face;
221 myIsGeometryValid = InitConeAngle();
223 if (myIsGeometryValid && !myIsPlaneCustom)
231 //=======================================================================
232 //function : SetMeasuredGeometry
234 //=======================================================================
235 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
236 const TopoDS_Face& theSecondFace)
238 myFirstShape = theFirstFace;
239 mySecondShape = theSecondFace;
240 myThirdShape = TopoDS_Shape();
241 myGeometryType = GeometryType_Faces;
242 myIsGeometryValid = InitTwoFacesAngle();
244 if (myIsGeometryValid && !myIsPlaneCustom)
252 //=======================================================================
253 //function : SetMeasuredGeometry
255 //=======================================================================
256 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
257 const TopoDS_Face& theSecondFace,
258 const gp_Pnt& thePoint)
260 myFirstShape = theFirstFace;
261 mySecondShape = theSecondFace;
262 myThirdShape = TopoDS_Shape();
263 myGeometryType = GeometryType_Faces;
264 myIsGeometryValid = InitTwoFacesAngle (thePoint);
266 if (myIsGeometryValid && !myIsPlaneCustom)
274 //=======================================================================
277 //=======================================================================
278 void AIS_AngleDimension::Init()
280 SetGeometryOrientedAngle (Standard_False);
281 SetSpecialSymbol (THE_DEGREE_SYMBOL);
282 SetDisplaySpecialSymbol (AIS_DSS_After);
286 //=======================================================================
287 //function: GetCenterOnArc
289 //=======================================================================
290 gp_Pnt AIS_AngleDimension::GetCenterOnArc (const gp_Pnt& theFirstAttach,
291 const gp_Pnt& theSecondAttach,
292 const gp_Pnt& theCenter) const
294 // construct plane where the circle and the arc are located
295 gce_MakePln aConstructPlane (theFirstAttach, theSecondAttach, theCenter);
296 if (!aConstructPlane.IsDone())
301 gp_Pln aPlane = aConstructPlane.Value();
303 Standard_Real aRadius = theFirstAttach.Distance (theCenter);
305 // construct circle forming the arc
306 gce_MakeCirc aConstructCircle (theCenter, aPlane, aRadius);
307 if (!aConstructCircle.IsDone())
312 gp_Circ aCircle = aConstructCircle.Value();
314 // compute angle parameters of arc end-points on circle
315 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, theFirstAttach);
316 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, theSecondAttach);
317 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
319 return ElCLib::Value ((aParamBeg + aParamEnd) * 0.5, aCircle);
322 //=======================================================================
324 //purpose : draws the arc between two attach points
325 //=======================================================================
326 void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
327 const gp_Pnt& theFirstAttach,
328 const gp_Pnt& theSecondAttach,
329 const gp_Pnt& theCenter,
330 const Standard_Real theRadius,
331 const Standard_Integer theMode)
333 // construct plane where the circle and the arc are located
334 gce_MakePln aConstructPlane (theFirstAttach, theSecondAttach, theCenter);
335 if (!aConstructPlane.IsDone())
340 gp_Pln aPlane = aConstructPlane.Value();
341 if (myGeometryOrientedAngle) {
342 gp_Ax1 anAxis = aPlane.Axis();
343 gp_Dir aDir = anAxis.Direction();
345 aPlane.SetAxis(gp_Ax1(anAxis.Location(), aDir));
348 // construct circle forming the arc
349 gce_MakeCirc aConstructCircle (theCenter, aPlane, theRadius);
350 if (!aConstructCircle.IsDone())
355 gp_Circ aCircle = aConstructCircle.Value();
358 Standard_Boolean isArcSense = !myGeometryOrientedAngle;
359 GC_MakeArcOfCircle aConstructArc(aCircle, theFirstAttach, theSecondAttach, isArcSense);
360 if (!aConstructArc.IsDone())
365 // generate points with specified deflection
366 const Handle(Geom_TrimmedCurve)& anArcCurve = aConstructArc.Value();
368 GeomAdaptor_Curve anArcAdaptor (anArcCurve, anArcCurve->FirstParameter(), anArcCurve->LastParameter());
370 // compute number of discretization elements in old-fanshioned way
371 gp_Vec aCenterToFirstVec (theCenter, theFirstAttach);
372 gp_Vec aCenterToSecondVec (theCenter, theSecondAttach);
373 const Standard_Real anAngle = aCenterToFirstVec.Angle (aCenterToSecondVec);
374 const Standard_Integer aNbPoints = myGeometryOrientedAngle ? 40 :
375 Max (4, Standard_Integer (50.0 * anAngle / M_PI));
377 GCPnts_UniformAbscissa aMakePnts (anArcAdaptor, aNbPoints);
378 if (!aMakePnts.IsDone())
383 // init data arrays for graphical and selection primitives
384 Handle(Graphic3d_ArrayOfPolylines) aPrimSegments = new Graphic3d_ArrayOfPolylines (aNbPoints);
386 SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve();
388 // load data into arrays
389 for (Standard_Integer aPntIt = 1; aPntIt <= aMakePnts.NbPoints(); ++aPntIt)
391 gp_Pnt aPnt = anArcAdaptor.Value (aMakePnts.Parameter (aPntIt));
393 aPrimSegments->AddVertex (aPnt);
395 aSensitiveCurve.Append (aPnt);
398 // add display presentation
399 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All)
401 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True);
403 Handle(Graphic3d_AspectLine3d) aDimensionLineStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect();
404 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionLineStyle);
405 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
406 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All)
408 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False);
412 //=======================================================================
413 //function: DrawArcWithText
415 //=======================================================================
416 void AIS_AngleDimension::DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
417 const gp_Pnt& theFirstAttach,
418 const gp_Pnt& theSecondAttach,
419 const gp_Pnt& theCenter,
420 const TCollection_ExtendedString& theText,
421 const Standard_Real theTextWidth,
422 const Standard_Integer theMode,
423 const Standard_Integer theLabelPosition)
425 // construct plane where the circle and the arc are located
426 gce_MakePln aConstructPlane (theFirstAttach, theSecondAttach, theCenter);
427 if (!aConstructPlane.IsDone())
432 gp_Pln aPlane = aConstructPlane.Value();
434 Standard_Real aRadius = theFirstAttach.Distance (myCenterPoint);
436 // construct circle forming the arc
437 gce_MakeCirc aConstructCircle (theCenter, aPlane, aRadius);
438 if (!aConstructCircle.IsDone())
443 gp_Circ aCircle = aConstructCircle.Value();
445 // compute angle parameters of arc end-points on circle
446 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, theFirstAttach);
447 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, theSecondAttach);
448 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
450 // middle point of arc parameter on circle
451 Standard_Real aParamMid = (aParamBeg + aParamEnd) * 0.5;
453 // add text graphical primitives
454 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
456 gp_Pnt aTextPos = ElCLib::Value (aParamMid, aCircle);
457 gp_Dir aTextDir = gce_MakeDir (theFirstAttach, theSecondAttach);
460 DrawText (thePresentation,
467 if (theMode != ComputeMode_All && theMode != ComputeMode_Line)
472 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
474 Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center
475 && aDimensionAspect->IsText3d();
479 // compute gap for label as parameteric size of sector on circle segment
480 Standard_Real aSectorOnCircle = theTextWidth / aRadius;
482 gp_Pnt aTextPntBeg = ElCLib::Value (aParamMid - aSectorOnCircle * 0.5, aCircle);
483 gp_Pnt aTextPntEnd = ElCLib::Value (aParamMid + aSectorOnCircle * 0.5, aCircle);
486 DrawArc (thePresentation, theFirstAttach, aTextPntBeg, theCenter, aRadius, theMode);
487 DrawArc (thePresentation, theSecondAttach, aTextPntEnd, theCenter, aRadius, theMode);
491 DrawArc (thePresentation, theFirstAttach, theSecondAttach, theCenter, aRadius, theMode);
495 //=======================================================================
496 //function : CheckPlane
498 //=======================================================================
499 Standard_Boolean AIS_AngleDimension::CheckPlane (const gp_Pln& thePlane)const
501 if (!thePlane.Contains (myFirstPoint, Precision::Confusion()) &&
502 !thePlane.Contains (mySecondPoint, Precision::Confusion()) &&
503 !thePlane.Contains (myCenterPoint, Precision::Confusion()))
505 return Standard_False;
508 return Standard_True;
511 //=======================================================================
512 //function : ComputePlane
514 //=======================================================================
515 void AIS_AngleDimension::ComputePlane()
517 if (!myIsGeometryValid)
522 gp_Vec aFirstVec = gp_Vec (myCenterPoint, myFirstPoint).Normalized();
523 gp_Vec aSecondVec = gp_Vec (myCenterPoint, mySecondPoint).Normalized();
524 gp_Vec aDirectionN = aSecondVec.Crossed (aFirstVec).Normalized();
525 gp_Vec aDirectionY = (aFirstVec + aSecondVec).Normalized();
526 gp_Vec aDirectionX = aDirectionY.Crossed (aDirectionN).Normalized();
528 myPlane = gp_Pln (gp_Ax3 (myCenterPoint, gp_Dir (aDirectionN), gp_Dir (aDirectionX)));
531 //=======================================================================
532 //function : GetModelUnits
534 //=======================================================================
535 const TCollection_AsciiString& AIS_AngleDimension::GetModelUnits() const
537 return myDrawer->DimAngleModelUnits();
540 //=======================================================================
541 //function : GetDisplayUnits
543 //=======================================================================
544 const TCollection_AsciiString& AIS_AngleDimension::GetDisplayUnits() const
546 return myDrawer->DimAngleDisplayUnits();
549 //=======================================================================
550 //function : SetModelUnits
552 //=======================================================================
553 void AIS_AngleDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
555 myDrawer->SetDimAngleModelUnits (theUnits);
558 //=======================================================================
559 //function : SetDisplayUnits
561 //=======================================================================
562 void AIS_AngleDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
564 myDrawer->SetDimAngleDisplayUnits (theUnits);
567 //=======================================================================
568 //function : ComputeValue
570 //=======================================================================
571 Standard_Real AIS_AngleDimension::ComputeValue() const
578 gp_Vec aVec1 (myCenterPoint, myFirstPoint);
579 gp_Vec aVec2 (myCenterPoint, mySecondPoint);
581 Standard_Real anAngle = aVec2.AngleWithRef (aVec1, GetPlane().Axis().Direction());
583 return anAngle > 0.0 ? anAngle : (2.0 * M_PI + anAngle);
586 //=======================================================================
588 //purpose : Having three gp_Pnt points compute presentation
589 //=======================================================================
590 void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
591 const Handle(Prs3d_Presentation)& thePresentation,
592 const Standard_Integer theMode)
594 thePresentation->Clear();
595 mySelectionGeom.Clear (theMode);
602 // Parameters for presentation
603 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
605 Prs3d_Root::CurrentGroup(thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
607 Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
609 // prepare label string and compute its geometrical width
610 Standard_Real aLabelWidth;
611 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
613 // add margins to label width
614 if (aDimensionAspect->IsText3d())
616 aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
619 // Get parameters from aspect or adjust it according with custom text position
620 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
621 Prs3d_DimensionTextHorizontalPosition aHorisontalTextPos = aDimensionAspect->TextHorizontalPosition();
623 if (IsTextPositionCustom())
625 AdjustParameters (myFixedTextPosition,anExtensionSize, aHorisontalTextPos, myFlyout);
628 // Handle user-defined and automatic arrow placement
629 Standard_Boolean isArrowsExternal = Standard_False;
630 Standard_Integer aLabelPosition = LabelPosition_None;
632 FitTextAlignment (aHorisontalTextPos, aLabelPosition, isArrowsExternal);
634 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
635 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
637 //Arrows positions and directions
638 gp_Vec aWPDir = gp_Vec (GetPlane().Axis().Direction());
640 gp_Dir aFirstExtensionDir = aWPDir ^ gp_Vec (myCenterPoint, aFirstAttach);
641 gp_Dir aSecondExtensionDir = aWPDir.Reversed() ^ gp_Vec (myCenterPoint, aSecondAttach);
643 gp_Vec aFirstArrowVec = gp_Vec (aFirstExtensionDir) * anArrowLength;
644 gp_Vec aSecondArrowVec = gp_Vec (aSecondExtensionDir) * anArrowLength;
646 gp_Pnt aFirstArrowBegin (0.0, 0.0, 0.0);
647 gp_Pnt aFirstArrowEnd (0.0, 0.0, 0.0);
648 gp_Pnt aSecondArrowBegin (0.0, 0.0, 0.0);
649 gp_Pnt aSecondArrowEnd (0.0, 0.0, 0.0);
651 if (isArrowsExternal)
653 aFirstArrowVec.Reverse();
654 aSecondArrowVec.Reverse();
657 aFirstArrowBegin = aFirstAttach;
658 aSecondArrowBegin = aSecondAttach;
659 aFirstArrowEnd = aFirstAttach.Translated (-aFirstArrowVec);
660 aSecondArrowEnd = aSecondAttach.Translated (-aSecondArrowVec);
662 // Group1: stenciling text and the angle dimension arc
663 Prs3d_Root::NewGroup (thePresentation);
665 Standard_Integer aHPosition = aLabelPosition & LabelPosition_HMask;
670 case LabelPosition_HCenter :
672 Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center
673 && aDimensionAspect->IsText3d();
677 DrawArcWithText (thePresentation,
688 // compute text primitives
689 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
691 gp_Vec aDimensionDir (aFirstAttach, aSecondAttach);
692 gp_Pnt aTextPos = IsTextPositionCustom() ? myFixedTextPosition
693 : GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
694 gp_Dir aTextDir = aDimensionDir;
696 DrawText (thePresentation,
703 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
705 DrawArc (thePresentation,
706 isArrowsExternal ? aFirstAttach : aFirstArrowEnd,
707 isArrowsExternal ? aSecondAttach : aSecondArrowEnd,
715 case LabelPosition_Left :
717 DrawExtension (thePresentation,
719 isArrowsExternal ? aFirstArrowEnd : aFirstAttach,
728 case LabelPosition_Right :
730 DrawExtension (thePresentation,
732 isArrowsExternal ? aSecondArrowEnd : aSecondAttach,
742 // dimension arc without text
743 if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && aHPosition != LabelPosition_HCenter)
745 Prs3d_Root::NewGroup (thePresentation);
747 DrawArc (thePresentation,
748 isArrowsExternal ? aFirstAttach : aFirstArrowEnd,
749 isArrowsExternal ? aSecondAttach : aSecondArrowEnd,
755 // arrows and arrow extensions
756 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
758 Prs3d_Root::NewGroup (thePresentation);
760 DrawArrow (thePresentation, aFirstArrowBegin, gp_Dir (aFirstArrowVec));
761 DrawArrow (thePresentation, aSecondArrowBegin, gp_Dir (aSecondArrowVec));
764 if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && isArrowsExternal)
766 Prs3d_Root::NewGroup (thePresentation);
768 if (aHPosition != LabelPosition_Left)
770 DrawExtension (thePresentation,
771 aDimensionAspect->ArrowTailSize(),
774 THE_EMPTY_LABEL_STRING,
775 THE_EMPTY_LABEL_WIDTH,
780 if (aHPosition != LabelPosition_Right)
782 DrawExtension (thePresentation,
783 aDimensionAspect->ArrowTailSize(),
786 THE_EMPTY_LABEL_STRING,
787 THE_EMPTY_LABEL_WIDTH,
794 if (theMode == ComputeMode_All)
796 Prs3d_Root::NewGroup (thePresentation);
798 Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (4);
799 aPrimSegments->AddVertex (myCenterPoint);
800 aPrimSegments->AddVertex (aFirstAttach);
801 aPrimSegments->AddVertex (myCenterPoint);
802 aPrimSegments->AddVertex (aSecondAttach);
804 Handle(Graphic3d_AspectLine3d) aFlyoutStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect();
805 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aFlyoutStyle);
806 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
809 mySelectionGeom.IsComputed = Standard_True;
812 //=======================================================================
813 //function : ComputeFlyoutSelection
814 //purpose : computes selection for flyouts
815 //=======================================================================
816 void AIS_AngleDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
817 const Handle(SelectMgr_EntityOwner)& theOwner)
819 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
820 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
822 Handle(Select3D_SensitiveGroup) aSensitiveEntity = new Select3D_SensitiveGroup (theOwner);
823 aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, myCenterPoint, aFirstAttach));
824 aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, myCenterPoint, aSecondAttach));
826 theSelection->Add (aSensitiveEntity);
829 //=======================================================================
830 //function : InitTwoEdgesAngle
832 //=======================================================================
833 Standard_Boolean AIS_AngleDimension::InitTwoEdgesAngle (gp_Pln& theComputedPlane)
835 TopoDS_Edge aFirstEdge = TopoDS::Edge (myFirstShape);
836 TopoDS_Edge aSecondEdge = TopoDS::Edge (mySecondShape);
838 BRepAdaptor_Curve aMakeFirstLine (aFirstEdge);
839 BRepAdaptor_Curve aMakeSecondLine (aSecondEdge);
841 if (aMakeFirstLine.GetType() != GeomAbs_Line || aMakeSecondLine.GetType() != GeomAbs_Line)
843 return Standard_False;
846 Handle(Geom_Line) aFirstLine = new Geom_Line (aMakeFirstLine.Line());
847 Handle(Geom_Line) aSecondLine = new Geom_Line (aMakeSecondLine.Line());
849 gp_Lin aFirstLin = aFirstLine->Lin();
850 gp_Lin aSecondLin = aSecondLine->Lin();
852 Standard_Boolean isParallelLines = Abs (aFirstLin.Angle (aSecondLin) - M_PI) <= Precision::Angular();
854 gp_Pnt aPoint = aFirstLine->Value (0.0);
855 gp_Dir aNormal = isParallelLines
856 ? gp_Vec (aSecondLin.Normal (aPoint).Direction()) ^ gp_Vec (aSecondLin.Direction())
857 : gp_Vec (aFirstLin.Direction()) ^ gp_Vec (aSecondLin.Direction());
859 theComputedPlane = gp_Pln (aPoint, aNormal);
861 // Compute geometry for this plane and edges
862 Standard_Boolean isInfinite1,isInfinite2;
863 gp_Pnt aFirstPoint1, aLastPoint1, aFirstPoint2, aLastPoint2;
864 gp_Lin2d aFirstLin2d, aSecondLin2d;
866 if (!AIS::ComputeGeometry (aFirstEdge, aSecondEdge,
867 aFirstLine, aSecondLine,
868 aFirstPoint1, aLastPoint1,
869 aFirstPoint2, aLastPoint2,
870 isInfinite1, isInfinite2))
872 return Standard_False;
875 if (aFirstLin.Direction().IsParallel (aSecondLin.Direction(), Precision::Angular()))
877 myFirstPoint = aFirstLin.Location();
878 mySecondPoint = ElCLib::Value (ElCLib::Parameter (aFirstLin, myFirstPoint), aSecondLin);
880 if (mySecondPoint.Distance (myFirstPoint) <= Precision::Confusion())
882 mySecondPoint.Translate (gp_Vec (aSecondLin.Direction()) * Abs (GetFlyout()));
885 myCenterPoint.SetXYZ ((myFirstPoint.XYZ() + mySecondPoint.XYZ()) / 2.0);
890 gp_Lin2d aFirstLin2d = ProjLib::Project (theComputedPlane, aFirstLin);
891 gp_Lin2d aSecondLin2d = ProjLib::Project (theComputedPlane, aSecondLin);
893 IntAna2d_AnaIntersection anInt2d (aFirstLin2d, aSecondLin2d);
894 gp_Pnt2d anIntersectPoint;
895 if (!anInt2d.IsDone() || anInt2d.IsEmpty())
897 return Standard_False;
900 anIntersectPoint = gp_Pnt2d (anInt2d.Point(1).Value());
901 myCenterPoint = ElCLib::To3d (theComputedPlane.Position().Ax2(), anIntersectPoint);
903 if (isInfinite1 || isInfinite2)
905 myFirstPoint = myCenterPoint.Translated (gp_Vec (aFirstLin.Direction()) * Abs (GetFlyout()));
906 mySecondPoint = myCenterPoint.Translated (gp_Vec (aSecondLin.Direction()) * Abs (GetFlyout()));
908 return IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
912 // | <- dimension should be here
914 myFirstPoint = myCenterPoint.Distance (aFirstPoint1) > myCenterPoint.Distance (aLastPoint1)
918 mySecondPoint = myCenterPoint.Distance (aFirstPoint2) > myCenterPoint.Distance (aLastPoint2)
923 return IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
926 //=======================================================================
927 //function : InitTwoFacesAngle
928 //purpose : initialization of angle dimension between two faces
929 //=======================================================================
930 Standard_Boolean AIS_AngleDimension::InitTwoFacesAngle()
932 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
933 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
935 gp_Dir aFirstDir, aSecondDir;
936 gp_Pln aFirstPlane, aSecondPlane;
937 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
938 AIS_KindOfSurface aFirstSurfType, aSecondSurfType;
939 Standard_Real aFirstOffset, aSecondOffset;
941 AIS::GetPlaneFromFace (aFirstFace, aFirstPlane,
942 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
944 AIS::GetPlaneFromFace (aSecondFace, aSecondPlane,
945 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
947 if (aFirstSurfType == AIS_KOS_Plane && aSecondSurfType == AIS_KOS_Plane)
950 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (aFirstBasisSurf);
951 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (aSecondBasisSurf);
952 return AIS::InitAngleBetweenPlanarFaces (aFirstFace,
957 && IsValidPoints (myFirstPoint,
963 // Curvilinear faces angle
964 return AIS::InitAngleBetweenCurvilinearFaces (aFirstFace,
971 && IsValidPoints (myFirstPoint,
977 //=======================================================================
978 //function : InitTwoFacesAngle
979 //purpose : initialization of angle dimension between two faces
980 //=======================================================================
981 Standard_Boolean AIS_AngleDimension::InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace)
983 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
984 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
986 gp_Dir aFirstDir, aSecondDir;
987 gp_Pln aFirstPlane, aSecondPlane;
988 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
989 AIS_KindOfSurface aFirstSurfType, aSecondSurfType;
990 Standard_Real aFirstOffset, aSecondOffset;
992 AIS::GetPlaneFromFace (aFirstFace, aFirstPlane,
993 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
995 AIS::GetPlaneFromFace (aSecondFace, aSecondPlane,
996 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
998 myFirstPoint = thePointOnFirstFace;
999 if (aFirstSurfType == AIS_KOS_Plane && aSecondSurfType == AIS_KOS_Plane)
1001 //Planar faces angle
1002 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (aFirstBasisSurf);
1003 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (aSecondBasisSurf);
1004 return AIS::InitAngleBetweenPlanarFaces (aFirstFace,
1010 && IsValidPoints (myFirstPoint,
1016 // Curvilinear faces angle
1017 return AIS::InitAngleBetweenCurvilinearFaces (aFirstFace,
1025 && IsValidPoints (myFirstPoint,
1031 //=======================================================================
1032 //function : InitConeAngle
1033 //purpose : initialization of the cone angle
1034 //=======================================================================
1035 Standard_Boolean AIS_AngleDimension::InitConeAngle()
1037 if (myFirstShape.IsNull())
1039 return Standard_False;
1042 TopoDS_Face aConeShape = TopoDS::Face (myFirstShape);
1046 // A surface from the Face
1047 Handle(Geom_Surface) aSurf;
1048 Handle(Geom_OffsetSurface) aOffsetSurf;
1049 Handle(Geom_ConicalSurface) aConicalSurf;
1050 Handle(Geom_SurfaceOfRevolution) aRevSurf;
1051 Handle(Geom_Line) aLine;
1052 BRepAdaptor_Surface aConeAdaptor (aConeShape);
1054 AIS_KindOfSurface aSurfType;
1055 Standard_Real anOffset = 0.;
1056 Handle(Standard_Type) aType;
1058 Standard_Real aMaxV = aConeAdaptor.FirstVParameter();
1059 Standard_Real aMinV = aConeAdaptor.LastVParameter();
1061 AIS::GetPlaneFromFace (aConeShape, aPln, aSurf, aSurfType, anOffset);
1063 if (aSurfType == AIS_KOS_Revolution)
1065 // Surface of revolution
1066 aRevSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(aSurf);
1067 gp_Lin aLin (aRevSurf->Axis());
1068 Handle(Geom_Curve) aBasisCurve = aRevSurf->BasisCurve();
1069 //Must be a part of line (basis curve should be linear)
1070 if (aBasisCurve ->DynamicType() != STANDARD_TYPE(Geom_Line))
1071 return Standard_False;
1073 gp_Pnt aFirst1 = aConeAdaptor.Value (0., aMinV);
1074 gp_Pnt aLast1 = aConeAdaptor.Value (0., aMaxV);
1075 gp_Vec aVec1 (aFirst1, aLast1);
1077 //Projection <aFirst> on <aLin>
1078 gp_Pnt aFirst2 = ElCLib::Value (ElCLib::Parameter (aLin, aFirst1), aLin);
1079 // Projection <aLast> on <aLin>
1080 gp_Pnt aLast2 = ElCLib::Value (ElCLib::Parameter (aLin, aLast1), aLin);
1082 gp_Vec aVec2 (aFirst2, aLast2);
1084 // Check if two parts of revolution are parallel (it's a cylinder) or normal (it's a circle).
1085 if (aVec1.IsParallel (aVec2, Precision::Angular())
1086 || aVec1.IsNormal (aVec2,Precision::Angular()))
1087 return Standard_False;
1089 gce_MakeCone aMkCone (aRevSurf->Axis(), aFirst1, aLast1);
1090 aCone = aMkCone.Value();
1091 myCenterPoint = aCone.Apex();
1095 aType = aSurf->DynamicType();
1096 if (aType == STANDARD_TYPE(Geom_OffsetSurface) || anOffset > 0.01)
1099 aOffsetSurf = new Geom_OffsetSurface (aSurf, anOffset);
1100 aSurf = aOffsetSurf->Surface();
1101 BRepBuilderAPI_MakeFace aMkFace(aSurf, Precision::Confusion());
1103 if (!aMkFace.IsDone())
1104 return Standard_False;
1105 aConeAdaptor.Initialize (aMkFace.Face());
1107 aCone = aConeAdaptor.Cone();
1108 aConicalSurf = Handle(Geom_ConicalSurface)::DownCast (aSurf);
1109 myCenterPoint = aConicalSurf->Apex();
1112 // A circle where the angle is drawn
1113 Handle(Geom_Curve) aCurve;
1114 Standard_Real aMidV = ( aMinV + aMaxV ) / 2.5;
1115 aCurve = aSurf->VIso (aMidV);
1116 aCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
1118 aCurve = aSurf->VIso(aMaxV);
1119 gp_Circ aCircVmax = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
1120 aCurve = aSurf->VIso(aMinV);
1121 gp_Circ aCircVmin = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
1123 if (aCircVmax.Radius() < aCircVmin.Radius())
1125 gp_Circ aTmpCirc = aCircVmax;
1126 aCircVmax = aCircVmin;
1127 aCircVmin = aTmpCirc;
1130 myFirstPoint = ElCLib::Value (0, aCircle);
1131 mySecondPoint = ElCLib::Value (M_PI, aCircle);
1132 return Standard_True;
1135 //=======================================================================
1136 //function : IsValidPoints
1138 //=======================================================================
1139 Standard_Boolean AIS_AngleDimension::IsValidPoints (const gp_Pnt& theFirstPoint,
1140 const gp_Pnt& theCenterPoint,
1141 const gp_Pnt& theSecondPoint) const
1143 return theFirstPoint.Distance (theCenterPoint) > Precision::Confusion()
1144 && theSecondPoint.Distance (theCenterPoint) > Precision::Confusion()
1145 && gp_Vec (theCenterPoint, theFirstPoint).Angle (
1146 gp_Vec (theCenterPoint, theSecondPoint)) > Precision::Angular();
1149 //=======================================================================
1150 //function : GetTextPosition
1152 //=======================================================================
1153 const gp_Pnt AIS_AngleDimension::GetTextPosition() const
1157 return gp::Origin();
1160 if (IsTextPositionCustom())
1162 return myFixedTextPosition;
1165 // Counts text position according to the dimension parameters
1166 gp_Pnt aTextPosition (gp::Origin());
1168 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1170 // Prepare label string and compute its geometrical width
1171 Standard_Real aLabelWidth;
1172 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
1174 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
1175 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
1177 // Handle user-defined and automatic arrow placement
1178 Standard_Boolean isArrowsExternal = Standard_False;
1179 Standard_Integer aLabelPosition = LabelPosition_None;
1180 FitTextAlignment (aDimensionAspect->TextHorizontalPosition(),
1181 aLabelPosition, isArrowsExternal);
1183 // Get text position
1184 switch (aLabelPosition & LabelPosition_HMask)
1186 case LabelPosition_HCenter:
1188 aTextPosition = GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
1191 case LabelPosition_Left:
1193 gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
1194 gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aFirstAttach);
1195 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
1196 Standard_Real anOffset = isArrowsExternal
1197 ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
1199 gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * -anOffset;
1200 aTextPosition = aFirstAttach.Translated (anExtensionVec);
1203 case LabelPosition_Right:
1205 gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
1206 gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aSecondAttach);
1207 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
1208 Standard_Real anOffset = isArrowsExternal
1209 ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
1211 gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * anOffset;
1212 aTextPosition = aSecondAttach.Translated (anExtensionVec);
1217 return aTextPosition;
1220 //=======================================================================
1221 //function : SetTextPosition
1223 //=======================================================================
1224 void AIS_AngleDimension::SetTextPosition (const gp_Pnt& theTextPos)
1231 // The text position point for angle dimension should belong to the working plane.
1232 if (!GetPlane().Contains (theTextPos, Precision::Confusion()))
1234 Standard_ProgramError::Raise ("The text position point for angle dimension doesn't belong to the working plane.");
1237 myIsTextPositionFixed = Standard_True;
1238 myFixedTextPosition = theTextPos;
1241 //=======================================================================
1242 //function : SetGeometryOrientedAngle
1244 //=======================================================================
1245 void AIS_AngleDimension::SetGeometryOrientedAngle(const Standard_Boolean& theState)
1247 myGeometryOrientedAngle = theState;
1250 //=======================================================================
1251 //function : AdjustParameters
1253 //=======================================================================
1254 void AIS_AngleDimension::AdjustParameters (const gp_Pnt& theTextPos,
1255 Standard_Real& theExtensionSize,
1256 Prs3d_DimensionTextHorizontalPosition& theAlignment,
1257 Standard_Real& theFlyout) const
1259 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1260 Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length();
1262 // Build circle with radius that is equal to distance from text position to the center point.
1263 Standard_Real aRadius = gp_Vec (myCenterPoint, theTextPos).Magnitude();
1265 // Set attach points in positive direction of the flyout.
1266 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * aRadius);
1267 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * aRadius);
1269 gce_MakeCirc aConstructCircle (myCenterPoint, GetPlane(), aRadius);
1270 if (!aConstructCircle.IsDone())
1274 gp_Circ aCircle = aConstructCircle.Value();
1277 theExtensionSize = aDimensionAspect->ArrowAspect()->Length();
1278 theAlignment = Prs3d_DTHP_Center;
1280 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, aFirstAttach);
1281 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, aSecondAttach);
1282 if (aParamEnd < aParamBeg)
1284 Standard_Real aParam = aParamEnd;
1285 aParamEnd = aParamBeg;
1289 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
1290 Standard_Real aTextPar = ElCLib::Parameter (aCircle , theTextPos);
1292 // Horizontal center
1293 if (aTextPar > aParamBeg && aTextPar < aParamEnd)
1295 theFlyout = aRadius;
1301 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
1303 if (aTextPar > aParamBeg && aTextPar < aParamEnd)
1305 theFlyout = -aRadius;
1309 // Text on the extensions
1310 gp_Lin aFirstLine = gce_MakeLin (myCenterPoint, myFirstPoint);
1311 gp_Lin aSecondLine = gce_MakeLin (myCenterPoint, mySecondPoint);
1312 gp_Pnt aFirstTextProj = AIS::Nearest (aFirstLine, theTextPos);
1313 gp_Pnt aSecondTextProj = AIS::Nearest (aSecondLine, theTextPos);
1314 Standard_Real aFirstDist = aFirstTextProj.Distance (theTextPos);
1315 Standard_Real aSecondDist = aSecondTextProj.Distance (theTextPos);
1317 if (aFirstDist <= aSecondDist)
1319 aRadius = myCenterPoint.Distance (aFirstTextProj);
1320 Standard_Real aNewExtensionSize = aFirstDist - anArrowLength;
1321 theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
1323 theAlignment = Prs3d_DTHP_Left;
1325 gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, myFirstPoint).Normalized().Scaled (aRadius);
1327 theFlyout = aFirstTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
1328 ? -aRadius : aRadius;
1332 aRadius = myCenterPoint.Distance (aSecondTextProj);
1334 Standard_Real aNewExtensionSize = aSecondDist - anArrowLength;
1336 theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
1338 theAlignment = Prs3d_DTHP_Right;
1340 gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, mySecondPoint).Normalized().Scaled (aRadius);
1342 theFlyout = aSecondTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
1343 ? -aRadius : aRadius;
1347 //=======================================================================
1348 //function : FitTextAlignment
1350 //=======================================================================
1351 void AIS_AngleDimension::FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
1352 Standard_Integer& theLabelPosition,
1353 Standard_Boolean& theIsArrowsExternal) const
1355 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1357 Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
1359 // Prepare label string and compute its geometrical width
1360 Standard_Real aLabelWidth;
1361 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
1363 // add margins to label width
1364 if (aDimensionAspect->IsText3d())
1366 aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
1369 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
1370 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
1372 // Handle user-defined and automatic arrow placement
1373 switch (aDimensionAspect->ArrowOrientation())
1375 case Prs3d_DAO_External: theIsArrowsExternal = true; break;
1376 case Prs3d_DAO_Internal: theIsArrowsExternal = false; break;
1379 gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
1380 Standard_Real aDimensionWidth = anAttachVector.Magnitude();
1382 // Add margin to ensure a small tail between text and arrow
1383 Standard_Real anArrowMargin = aDimensionAspect->IsText3d()
1384 ? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN
1387 Standard_Real anArrowsWidth = (anArrowLength + anArrowMargin) * 2.0;
1389 theIsArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth;
1394 // Handle user-defined and automatic text placement
1395 switch (theHorizontalTextPos)
1397 case Prs3d_DTHP_Left : theLabelPosition |= LabelPosition_Left; break;
1398 case Prs3d_DTHP_Right : theLabelPosition |= LabelPosition_Right; break;
1399 case Prs3d_DTHP_Center: theLabelPosition |= LabelPosition_HCenter; break;
1400 case Prs3d_DTHP_Fit:
1402 gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
1403 Standard_Real aDimensionWidth = anAttachVector.Magnitude();
1404 Standard_Real anArrowsWidth = anArrowLength * 2.0;
1405 Standard_Real aContentWidth = theIsArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth;
1407 theLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter;
1412 switch (aDimensionAspect->TextVerticalPosition())
1414 case Prs3d_DTVP_Above : theLabelPosition |= LabelPosition_Above; break;
1415 case Prs3d_DTVP_Below : theLabelPosition |= LabelPosition_Below; break;
1416 case Prs3d_DTVP_Center : theLabelPosition |= LabelPosition_VCenter; break;