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 SetAngleReversed (Standard_False);
281 SetArrowVisible (Standard_True, Standard_True);
282 SetSpecialSymbol (THE_DEGREE_SYMBOL);
283 SetDisplaySpecialSymbol (AIS_DSS_After);
287 //=======================================================================
288 //function: GetCenterOnArc
290 //=======================================================================
291 gp_Pnt AIS_AngleDimension::GetCenterOnArc (const gp_Pnt& theFirstAttach,
292 const gp_Pnt& theSecondAttach,
293 const gp_Pnt& theCenter) const
295 // construct plane where the circle and the arc are located
296 gce_MakePln aConstructPlane (theFirstAttach, theSecondAttach, theCenter);
297 if (!aConstructPlane.IsDone())
302 gp_Pln aPlane = aConstructPlane.Value();
304 gp_Ax1 anAxis = aPlane.Axis();
305 gp_Dir aDir = anAxis.Direction();
307 aPlane.SetAxis(gp_Ax1(anAxis.Location(), aDir));
310 Standard_Real aRadius = theFirstAttach.Distance (theCenter);
312 // construct circle forming the arc
313 gce_MakeCirc aConstructCircle (theCenter, aPlane, aRadius);
314 if (!aConstructCircle.IsDone())
319 gp_Circ aCircle = aConstructCircle.Value();
321 // compute angle parameters of arc end-points on circle
322 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, theFirstAttach);
323 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, theSecondAttach);
324 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
326 return ElCLib::Value ((aParamBeg + aParamEnd) * 0.5, aCircle);
329 //=======================================================================
331 //purpose : draws the arc between two attach points
332 //=======================================================================
333 void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
334 const gp_Pnt& theFirstAttach,
335 const gp_Pnt& theSecondAttach,
336 const gp_Pnt& theCenter,
337 const Standard_Real theRadius,
338 const Standard_Integer theMode)
340 // construct plane where the circle and the arc are located
341 gce_MakePln aConstructPlane (theFirstAttach, theSecondAttach, theCenter);
342 if (!aConstructPlane.IsDone())
347 gp_Pln aPlane = aConstructPlane.Value();
349 gp_Ax1 anAxis = aPlane.Axis();
350 gp_Dir aDir = anAxis.Direction();
352 aPlane.SetAxis(gp_Ax1(anAxis.Location(), aDir));
355 // construct circle forming the arc
356 gce_MakeCirc aConstructCircle (theCenter, aPlane, theRadius);
357 if (!aConstructCircle.IsDone())
362 gp_Circ aCircle = aConstructCircle.Value();
365 GC_MakeArcOfCircle aConstructArc(aCircle, theFirstAttach, theSecondAttach, Standard_True);
366 if (!aConstructArc.IsDone())
371 // generate points with specified deflection
372 const Handle(Geom_TrimmedCurve)& anArcCurve = aConstructArc.Value();
374 GeomAdaptor_Curve anArcAdaptor (anArcCurve, anArcCurve->FirstParameter(), anArcCurve->LastParameter());
376 // compute number of discretization elements in old-fanshioned way
377 gp_Vec aCenterToFirstVec (theCenter, theFirstAttach);
378 gp_Vec aCenterToSecondVec (theCenter, theSecondAttach);
380 gp_Ax1 anAxis = aPlane.Axis();
381 gp_Dir aDir = anAxis.Direction();
382 gp_Vec aRefVec(aDir);
383 Standard_Real anAngle = aCenterToFirstVec.AngleWithRef (aCenterToSecondVec, aRefVec);
385 anAngle = 2.0 * M_PI + anAngle;
386 const Standard_Integer aNbPoints = Max (4, Standard_Integer (50.0 * anAngle / M_PI));
388 GCPnts_UniformAbscissa aMakePnts (anArcAdaptor, aNbPoints);
389 if (!aMakePnts.IsDone())
394 // init data arrays for graphical and selection primitives
395 Handle(Graphic3d_ArrayOfPolylines) aPrimSegments = new Graphic3d_ArrayOfPolylines (aNbPoints);
397 SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve();
399 // load data into arrays
400 for (Standard_Integer aPntIt = 1; aPntIt <= aMakePnts.NbPoints(); ++aPntIt)
402 gp_Pnt aPnt = anArcAdaptor.Value (aMakePnts.Parameter (aPntIt));
404 aPrimSegments->AddVertex (aPnt);
406 aSensitiveCurve.Append (aPnt);
409 // add display presentation
410 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All)
412 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True);
414 Handle(Graphic3d_AspectLine3d) aDimensionLineStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect();
415 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionLineStyle);
416 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
417 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All)
419 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False);
423 //=======================================================================
424 //function: DrawArcWithText
426 //=======================================================================
427 void AIS_AngleDimension::DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
428 const gp_Pnt& theFirstAttach,
429 const gp_Pnt& theSecondAttach,
430 const gp_Pnt& theCenter,
431 const TCollection_ExtendedString& theText,
432 const Standard_Real theTextWidth,
433 const Standard_Integer theMode,
434 const Standard_Integer theLabelPosition)
436 // construct plane where the circle and the arc are located
437 gce_MakePln aConstructPlane (theFirstAttach, theSecondAttach, theCenter);
438 if (!aConstructPlane.IsDone())
443 gp_Pln aPlane = aConstructPlane.Value();
445 Standard_Real aRadius = theFirstAttach.Distance (myCenterPoint);
447 // construct circle forming the arc
448 gce_MakeCirc aConstructCircle (theCenter, aPlane, aRadius);
449 if (!aConstructCircle.IsDone())
454 gp_Circ aCircle = aConstructCircle.Value();
456 // compute angle parameters of arc end-points on circle
457 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, theFirstAttach);
458 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, theSecondAttach);
459 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
461 // middle point of arc parameter on circle
462 Standard_Real aParamMid = (aParamBeg + aParamEnd) * 0.5;
464 // add text graphical primitives
465 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
467 gp_Pnt aTextPos = ElCLib::Value (aParamMid, aCircle);
468 gp_Dir aTextDir = gce_MakeDir (theFirstAttach, theSecondAttach);
471 DrawText (thePresentation,
478 if (theMode != ComputeMode_All && theMode != ComputeMode_Line)
483 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
485 Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center
486 && aDimensionAspect->IsText3d();
490 // compute gap for label as parameteric size of sector on circle segment
491 Standard_Real aSectorOnCircle = theTextWidth / aRadius;
493 gp_Pnt aTextPntBeg = ElCLib::Value (aParamMid - aSectorOnCircle * 0.5, aCircle);
494 gp_Pnt aTextPntEnd = ElCLib::Value (aParamMid + aSectorOnCircle * 0.5, aCircle);
497 DrawArc (thePresentation, theFirstAttach, aTextPntBeg, theCenter, aRadius, theMode);
498 DrawArc (thePresentation, theSecondAttach, aTextPntEnd, theCenter, aRadius, theMode);
502 DrawArc (thePresentation, theFirstAttach, theSecondAttach, theCenter, aRadius, theMode);
506 //=======================================================================
507 //function : CheckPlane
509 //=======================================================================
510 Standard_Boolean AIS_AngleDimension::CheckPlane (const gp_Pln& thePlane)const
512 if (!thePlane.Contains (myFirstPoint, Precision::Confusion()) &&
513 !thePlane.Contains (mySecondPoint, Precision::Confusion()) &&
514 !thePlane.Contains (myCenterPoint, Precision::Confusion()))
516 return Standard_False;
519 return Standard_True;
522 //=======================================================================
523 //function : ComputePlane
525 //=======================================================================
526 void AIS_AngleDimension::ComputePlane()
528 if (!myIsGeometryValid)
533 gp_Vec aFirstVec = gp_Vec (myCenterPoint, myFirstPoint).Normalized();
534 gp_Vec aSecondVec = gp_Vec (myCenterPoint, mySecondPoint).Normalized();
535 gp_Vec aDirectionN = aSecondVec.Crossed (aFirstVec).Normalized();
536 gp_Vec aDirectionY = (aFirstVec + aSecondVec).Normalized();
537 gp_Vec aDirectionX = aDirectionY.Crossed (aDirectionN).Normalized();
539 myPlane = gp_Pln (gp_Ax3 (myCenterPoint, gp_Dir (aDirectionN), gp_Dir (aDirectionX)));
542 //=======================================================================
543 //function : GetModelUnits
545 //=======================================================================
546 const TCollection_AsciiString& AIS_AngleDimension::GetModelUnits() const
548 return myDrawer->DimAngleModelUnits();
551 //=======================================================================
552 //function : GetDisplayUnits
554 //=======================================================================
555 const TCollection_AsciiString& AIS_AngleDimension::GetDisplayUnits() const
557 return myDrawer->DimAngleDisplayUnits();
560 //=======================================================================
561 //function : SetModelUnits
563 //=======================================================================
564 void AIS_AngleDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
566 myDrawer->SetDimAngleModelUnits (theUnits);
569 //=======================================================================
570 //function : SetDisplayUnits
572 //=======================================================================
573 void AIS_AngleDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
575 myDrawer->SetDimAngleDisplayUnits (theUnits);
578 //=======================================================================
579 //function : ComputeValue
581 //=======================================================================
582 Standard_Real AIS_AngleDimension::ComputeValue() const
589 gp_Vec aVec1 (myCenterPoint, myFirstPoint);
590 gp_Vec aVec2 (myCenterPoint, mySecondPoint);
592 Standard_Real anAngle = aVec2.AngleWithRef (aVec1, GetPlane().Axis().Direction());
594 return anAngle > 0.0 ? anAngle : (2.0 * M_PI + anAngle);
597 //=======================================================================
599 //purpose : Having three gp_Pnt points compute presentation
600 //=======================================================================
601 void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
602 const Handle(Prs3d_Presentation)& thePresentation,
603 const Standard_Integer theMode)
605 thePresentation->Clear();
606 mySelectionGeom.Clear (theMode);
613 // Parameters for presentation
614 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
616 Prs3d_Root::CurrentGroup(thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
618 Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
620 // prepare label string and compute its geometrical width
621 Standard_Real aLabelWidth;
622 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
624 // add margins to label width
625 if (aDimensionAspect->IsText3d())
627 aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
630 // Get parameters from aspect or adjust it according with custom text position
631 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
632 Prs3d_DimensionTextHorizontalPosition aHorisontalTextPos = aDimensionAspect->TextHorizontalPosition();
634 if (IsTextPositionCustom())
636 AdjustParameters (myFixedTextPosition,anExtensionSize, aHorisontalTextPos, myFlyout);
639 // Handle user-defined and automatic arrow placement
640 Standard_Boolean isArrowsExternal = Standard_False;
641 Standard_Integer aLabelPosition = LabelPosition_None;
643 FitTextAlignment (aHorisontalTextPos, aLabelPosition, isArrowsExternal);
645 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
646 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
648 //Arrows positions and directions
649 gp_Vec aWPDir = gp_Vec (GetPlane().Axis().Direction());
651 gp_Dir aFirstExtensionDir = aWPDir ^ gp_Vec (myCenterPoint, aFirstAttach);
652 gp_Dir aSecondExtensionDir = aWPDir.Reversed() ^ gp_Vec (myCenterPoint, aSecondAttach);
654 gp_Vec aFirstArrowVec = gp_Vec (aFirstExtensionDir) * anArrowLength;
655 gp_Vec aSecondArrowVec = gp_Vec (aSecondExtensionDir) * anArrowLength;
657 gp_Pnt aFirstArrowBegin (0.0, 0.0, 0.0);
658 gp_Pnt aFirstArrowEnd (0.0, 0.0, 0.0);
659 gp_Pnt aSecondArrowBegin (0.0, 0.0, 0.0);
660 gp_Pnt aSecondArrowEnd (0.0, 0.0, 0.0);
662 if (isArrowsExternal)
664 aFirstArrowVec.Reverse();
665 aSecondArrowVec.Reverse();
668 aFirstArrowBegin = aFirstAttach;
669 aSecondArrowBegin = aSecondAttach;
670 aFirstArrowEnd = aFirstAttach.Translated (-aFirstArrowVec);
671 aSecondArrowEnd = aSecondAttach.Translated (-aSecondArrowVec);
673 // Group1: stenciling text and the angle dimension arc
674 Prs3d_Root::NewGroup (thePresentation);
676 Standard_Integer aHPosition = aLabelPosition & LabelPosition_HMask;
681 case LabelPosition_HCenter :
683 Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center
684 && aDimensionAspect->IsText3d();
688 DrawArcWithText (thePresentation,
699 // compute text primitives
700 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
702 gp_Vec aDimensionDir (aFirstAttach, aSecondAttach);
703 gp_Pnt aTextPos = IsTextPositionCustom() ? myFixedTextPosition
704 : GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
705 gp_Dir aTextDir = aDimensionDir;
707 DrawText (thePresentation,
714 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
716 DrawArc (thePresentation,
717 (isArrowsExternal || !myFirstArrowVisible) ? aFirstAttach : aFirstArrowEnd,
718 (isArrowsExternal || !mySecondArrowVisible) ? aSecondAttach : aSecondArrowEnd,
726 case LabelPosition_Left :
728 DrawExtension (thePresentation,
730 (isArrowsExternal && myFirstArrowVisible) ? aFirstArrowEnd : aFirstAttach,
739 case LabelPosition_Right :
741 DrawExtension (thePresentation,
743 (isArrowsExternal && mySecondArrowVisible) ? aSecondArrowEnd : aSecondAttach,
753 // dimension arc without text
754 if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && aHPosition != LabelPosition_HCenter)
756 Prs3d_Root::NewGroup (thePresentation);
758 DrawArc (thePresentation,
759 (isArrowsExternal || !myFirstArrowVisible) ? aFirstAttach : aFirstArrowEnd,
760 (isArrowsExternal || !mySecondArrowVisible) ? aSecondAttach : aSecondArrowEnd,
766 // arrows and arrow extensions
767 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
769 Prs3d_Root::NewGroup (thePresentation);
771 if (myFirstArrowVisible)
772 DrawArrow (thePresentation, aFirstArrowBegin, gp_Dir (aFirstArrowVec));
773 if (mySecondArrowVisible)
774 DrawArrow (thePresentation, aSecondArrowBegin, gp_Dir (aSecondArrowVec));
777 if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && isArrowsExternal)
779 Prs3d_Root::NewGroup (thePresentation);
781 if (aHPosition != LabelPosition_Left && myFirstArrowVisible)
783 DrawExtension (thePresentation,
784 aDimensionAspect->ArrowTailSize(),
787 THE_EMPTY_LABEL_STRING,
788 THE_EMPTY_LABEL_WIDTH,
793 if (aHPosition != LabelPosition_Right && mySecondArrowVisible)
795 DrawExtension (thePresentation,
796 aDimensionAspect->ArrowTailSize(),
799 THE_EMPTY_LABEL_STRING,
800 THE_EMPTY_LABEL_WIDTH,
807 if (theMode == ComputeMode_All)
809 Prs3d_Root::NewGroup (thePresentation);
811 Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (4);
812 aPrimSegments->AddVertex (myCenterPoint);
813 aPrimSegments->AddVertex (aFirstAttach);
814 aPrimSegments->AddVertex (myCenterPoint);
815 aPrimSegments->AddVertex (aSecondAttach);
817 Handle(Graphic3d_AspectLine3d) aFlyoutStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect();
818 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aFlyoutStyle);
819 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
822 mySelectionGeom.IsComputed = Standard_True;
825 //=======================================================================
826 //function : ComputeFlyoutSelection
827 //purpose : computes selection for flyouts
828 //=======================================================================
829 void AIS_AngleDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
830 const Handle(SelectMgr_EntityOwner)& theOwner)
832 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
833 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
835 Handle(Select3D_SensitiveGroup) aSensitiveEntity = new Select3D_SensitiveGroup (theOwner);
836 aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, myCenterPoint, aFirstAttach));
837 aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, myCenterPoint, aSecondAttach));
839 theSelection->Add (aSensitiveEntity);
842 //=======================================================================
843 //function : InitTwoEdgesAngle
845 //=======================================================================
846 Standard_Boolean AIS_AngleDimension::InitTwoEdgesAngle (gp_Pln& theComputedPlane)
848 TopoDS_Edge aFirstEdge = TopoDS::Edge (myFirstShape);
849 TopoDS_Edge aSecondEdge = TopoDS::Edge (mySecondShape);
851 BRepAdaptor_Curve aMakeFirstLine (aFirstEdge);
852 BRepAdaptor_Curve aMakeSecondLine (aSecondEdge);
854 if (aMakeFirstLine.GetType() != GeomAbs_Line || aMakeSecondLine.GetType() != GeomAbs_Line)
856 return Standard_False;
859 Handle(Geom_Line) aFirstLine = new Geom_Line (aMakeFirstLine.Line());
860 Handle(Geom_Line) aSecondLine = new Geom_Line (aMakeSecondLine.Line());
862 gp_Lin aFirstLin = aFirstLine->Lin();
863 gp_Lin aSecondLin = aSecondLine->Lin();
865 Standard_Boolean isParallelLines = Abs (aFirstLin.Angle (aSecondLin) - M_PI) <= Precision::Angular();
867 gp_Pnt aPoint = aFirstLine->Value (0.0);
868 gp_Dir aNormal = isParallelLines
869 ? gp_Vec (aSecondLin.Normal (aPoint).Direction()) ^ gp_Vec (aSecondLin.Direction())
870 : gp_Vec (aFirstLin.Direction()) ^ gp_Vec (aSecondLin.Direction());
872 theComputedPlane = gp_Pln (aPoint, aNormal);
874 // Compute geometry for this plane and edges
875 Standard_Boolean isInfinite1,isInfinite2;
876 gp_Pnt aFirstPoint1, aLastPoint1, aFirstPoint2, aLastPoint2;
877 gp_Lin2d aFirstLin2d, aSecondLin2d;
879 if (!AIS::ComputeGeometry (aFirstEdge, aSecondEdge,
880 aFirstLine, aSecondLine,
881 aFirstPoint1, aLastPoint1,
882 aFirstPoint2, aLastPoint2,
883 isInfinite1, isInfinite2))
885 return Standard_False;
888 if (aFirstLin.Direction().IsParallel (aSecondLin.Direction(), Precision::Angular()))
890 myFirstPoint = aFirstLin.Location();
891 mySecondPoint = ElCLib::Value (ElCLib::Parameter (aFirstLin, myFirstPoint), aSecondLin);
893 if (mySecondPoint.Distance (myFirstPoint) <= Precision::Confusion())
895 mySecondPoint.Translate (gp_Vec (aSecondLin.Direction()) * Abs (GetFlyout()));
898 myCenterPoint.SetXYZ ((myFirstPoint.XYZ() + mySecondPoint.XYZ()) / 2.0);
903 gp_Lin2d aFirstLin2d = ProjLib::Project (theComputedPlane, aFirstLin);
904 gp_Lin2d aSecondLin2d = ProjLib::Project (theComputedPlane, aSecondLin);
906 IntAna2d_AnaIntersection anInt2d (aFirstLin2d, aSecondLin2d);
907 gp_Pnt2d anIntersectPoint;
908 if (!anInt2d.IsDone() || anInt2d.IsEmpty())
910 return Standard_False;
913 anIntersectPoint = gp_Pnt2d (anInt2d.Point(1).Value());
914 myCenterPoint = ElCLib::To3d (theComputedPlane.Position().Ax2(), anIntersectPoint);
916 if (isInfinite1 || isInfinite2)
918 myFirstPoint = myCenterPoint.Translated (gp_Vec (aFirstLin.Direction()) * Abs (GetFlyout()));
919 mySecondPoint = myCenterPoint.Translated (gp_Vec (aSecondLin.Direction()) * Abs (GetFlyout()));
921 return IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
925 // | <- dimension should be here
927 myFirstPoint = !myCenterPoint.IsEqual(aFirstPoint1, Precision::Confusion())
930 mySecondPoint = !myCenterPoint.IsEqual(aFirstPoint2, Precision::Confusion())
935 return IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
938 //=======================================================================
939 //function : InitTwoFacesAngle
940 //purpose : initialization of angle dimension between two faces
941 //=======================================================================
942 Standard_Boolean AIS_AngleDimension::InitTwoFacesAngle()
944 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
945 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
947 gp_Dir aFirstDir, aSecondDir;
948 gp_Pln aFirstPlane, aSecondPlane;
949 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
950 AIS_KindOfSurface aFirstSurfType, aSecondSurfType;
951 Standard_Real aFirstOffset, aSecondOffset;
953 AIS::GetPlaneFromFace (aFirstFace, aFirstPlane,
954 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
956 AIS::GetPlaneFromFace (aSecondFace, aSecondPlane,
957 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
959 if (aFirstSurfType == AIS_KOS_Plane && aSecondSurfType == AIS_KOS_Plane)
962 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (aFirstBasisSurf);
963 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (aSecondBasisSurf);
964 return AIS::InitAngleBetweenPlanarFaces (aFirstFace,
969 && IsValidPoints (myFirstPoint,
975 // Curvilinear faces angle
976 return AIS::InitAngleBetweenCurvilinearFaces (aFirstFace,
983 && IsValidPoints (myFirstPoint,
989 //=======================================================================
990 //function : InitTwoFacesAngle
991 //purpose : initialization of angle dimension between two faces
992 //=======================================================================
993 Standard_Boolean AIS_AngleDimension::InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace)
995 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
996 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
998 gp_Dir aFirstDir, aSecondDir;
999 gp_Pln aFirstPlane, aSecondPlane;
1000 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
1001 AIS_KindOfSurface aFirstSurfType, aSecondSurfType;
1002 Standard_Real aFirstOffset, aSecondOffset;
1004 AIS::GetPlaneFromFace (aFirstFace, aFirstPlane,
1005 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
1007 AIS::GetPlaneFromFace (aSecondFace, aSecondPlane,
1008 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
1010 myFirstPoint = thePointOnFirstFace;
1011 if (aFirstSurfType == AIS_KOS_Plane && aSecondSurfType == AIS_KOS_Plane)
1013 //Planar faces angle
1014 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (aFirstBasisSurf);
1015 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (aSecondBasisSurf);
1016 return AIS::InitAngleBetweenPlanarFaces (aFirstFace,
1022 && IsValidPoints (myFirstPoint,
1028 // Curvilinear faces angle
1029 return AIS::InitAngleBetweenCurvilinearFaces (aFirstFace,
1037 && IsValidPoints (myFirstPoint,
1043 //=======================================================================
1044 //function : InitConeAngle
1045 //purpose : initialization of the cone angle
1046 //=======================================================================
1047 Standard_Boolean AIS_AngleDimension::InitConeAngle()
1049 if (myFirstShape.IsNull())
1051 return Standard_False;
1054 TopoDS_Face aConeShape = TopoDS::Face (myFirstShape);
1058 // A surface from the Face
1059 Handle(Geom_Surface) aSurf;
1060 Handle(Geom_OffsetSurface) aOffsetSurf;
1061 Handle(Geom_ConicalSurface) aConicalSurf;
1062 Handle(Geom_SurfaceOfRevolution) aRevSurf;
1063 Handle(Geom_Line) aLine;
1064 BRepAdaptor_Surface aConeAdaptor (aConeShape);
1066 AIS_KindOfSurface aSurfType;
1067 Standard_Real anOffset = 0.;
1068 Handle(Standard_Type) aType;
1070 Standard_Real aMaxV = aConeAdaptor.FirstVParameter();
1071 Standard_Real aMinV = aConeAdaptor.LastVParameter();
1073 AIS::GetPlaneFromFace (aConeShape, aPln, aSurf, aSurfType, anOffset);
1075 if (aSurfType == AIS_KOS_Revolution)
1077 // Surface of revolution
1078 aRevSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(aSurf);
1079 gp_Lin aLin (aRevSurf->Axis());
1080 Handle(Geom_Curve) aBasisCurve = aRevSurf->BasisCurve();
1081 //Must be a part of line (basis curve should be linear)
1082 if (aBasisCurve ->DynamicType() != STANDARD_TYPE(Geom_Line))
1083 return Standard_False;
1085 gp_Pnt aFirst1 = aConeAdaptor.Value (0., aMinV);
1086 gp_Pnt aLast1 = aConeAdaptor.Value (0., aMaxV);
1087 gp_Vec aVec1 (aFirst1, aLast1);
1089 //Projection <aFirst> on <aLin>
1090 gp_Pnt aFirst2 = ElCLib::Value (ElCLib::Parameter (aLin, aFirst1), aLin);
1091 // Projection <aLast> on <aLin>
1092 gp_Pnt aLast2 = ElCLib::Value (ElCLib::Parameter (aLin, aLast1), aLin);
1094 gp_Vec aVec2 (aFirst2, aLast2);
1096 // Check if two parts of revolution are parallel (it's a cylinder) or normal (it's a circle).
1097 if (aVec1.IsParallel (aVec2, Precision::Angular())
1098 || aVec1.IsNormal (aVec2,Precision::Angular()))
1099 return Standard_False;
1101 gce_MakeCone aMkCone (aRevSurf->Axis(), aFirst1, aLast1);
1102 aCone = aMkCone.Value();
1103 myCenterPoint = aCone.Apex();
1107 aType = aSurf->DynamicType();
1108 if (aType == STANDARD_TYPE(Geom_OffsetSurface) || anOffset > 0.01)
1111 aOffsetSurf = new Geom_OffsetSurface (aSurf, anOffset);
1112 aSurf = aOffsetSurf->Surface();
1113 BRepBuilderAPI_MakeFace aMkFace(aSurf, Precision::Confusion());
1115 if (!aMkFace.IsDone())
1116 return Standard_False;
1117 aConeAdaptor.Initialize (aMkFace.Face());
1119 aCone = aConeAdaptor.Cone();
1120 aConicalSurf = Handle(Geom_ConicalSurface)::DownCast (aSurf);
1121 myCenterPoint = aConicalSurf->Apex();
1124 // A circle where the angle is drawn
1125 Handle(Geom_Curve) aCurve;
1126 Standard_Real aMidV = ( aMinV + aMaxV ) / 2.5;
1127 aCurve = aSurf->VIso (aMidV);
1128 aCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
1130 aCurve = aSurf->VIso(aMaxV);
1131 gp_Circ aCircVmax = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
1132 aCurve = aSurf->VIso(aMinV);
1133 gp_Circ aCircVmin = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
1135 if (aCircVmax.Radius() < aCircVmin.Radius())
1137 gp_Circ aTmpCirc = aCircVmax;
1138 aCircVmax = aCircVmin;
1139 aCircVmin = aTmpCirc;
1142 myFirstPoint = ElCLib::Value (0, aCircle);
1143 mySecondPoint = ElCLib::Value (M_PI, aCircle);
1144 return Standard_True;
1147 //=======================================================================
1148 //function : IsValidPoints
1150 //=======================================================================
1151 Standard_Boolean AIS_AngleDimension::IsValidPoints (const gp_Pnt& theFirstPoint,
1152 const gp_Pnt& theCenterPoint,
1153 const gp_Pnt& theSecondPoint) const
1155 return theFirstPoint.Distance (theCenterPoint) > Precision::Confusion()
1156 && theSecondPoint.Distance (theCenterPoint) > Precision::Confusion()
1157 && gp_Vec (theCenterPoint, theFirstPoint).Angle (
1158 gp_Vec (theCenterPoint, theSecondPoint)) > Precision::Angular();
1161 //=======================================================================
1162 //function : GetTextPosition
1164 //=======================================================================
1165 const gp_Pnt AIS_AngleDimension::GetTextPosition() const
1169 return gp::Origin();
1172 if (IsTextPositionCustom())
1174 return myFixedTextPosition;
1177 // Counts text position according to the dimension parameters
1178 gp_Pnt aTextPosition (gp::Origin());
1180 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1182 // Prepare label string and compute its geometrical width
1183 Standard_Real aLabelWidth;
1184 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
1186 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
1187 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
1189 // Handle user-defined and automatic arrow placement
1190 Standard_Boolean isArrowsExternal = Standard_False;
1191 Standard_Integer aLabelPosition = LabelPosition_None;
1192 FitTextAlignment (aDimensionAspect->TextHorizontalPosition(),
1193 aLabelPosition, isArrowsExternal);
1195 // Get text position
1196 switch (aLabelPosition & LabelPosition_HMask)
1198 case LabelPosition_HCenter:
1200 aTextPosition = GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
1203 case LabelPosition_Left:
1205 gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
1206 gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aFirstAttach);
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 = aFirstAttach.Translated (anExtensionVec);
1215 case LabelPosition_Right:
1217 gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
1218 gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aSecondAttach);
1219 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
1220 Standard_Real anOffset = isArrowsExternal
1221 ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
1223 gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * anOffset;
1224 aTextPosition = aSecondAttach.Translated (anExtensionVec);
1229 return aTextPosition;
1232 //=======================================================================
1233 //function : SetTextPosition
1235 //=======================================================================
1236 void AIS_AngleDimension::SetTextPosition (const gp_Pnt& theTextPos)
1243 // The text position point for angle dimension should belong to the working plane.
1244 if (!GetPlane().Contains (theTextPos, Precision::Confusion()))
1246 Standard_ProgramError::Raise ("The text position point for angle dimension doesn't belong to the working plane.");
1249 myIsTextPositionFixed = Standard_True;
1250 myFixedTextPosition = theTextPos;
1253 //=======================================================================
1254 //function : SetAngleReversed
1256 //=======================================================================
1257 void AIS_AngleDimension::SetAngleReversed(const Standard_Boolean& theUseReverse)
1259 myUseReverse = theUseReverse;
1262 //=======================================================================
1263 //function : SetArrowVisible
1265 //=======================================================================
1266 void AIS_AngleDimension::SetArrowVisible(const Standard_Boolean& theFirstArrowVisible,
1267 const Standard_Boolean& theSecondArrowVisible)
1269 myFirstArrowVisible = theFirstArrowVisible;
1270 mySecondArrowVisible = theSecondArrowVisible;
1273 //=======================================================================
1274 //function : AdjustParameters
1276 //=======================================================================
1277 void AIS_AngleDimension::AdjustParameters (const gp_Pnt& theTextPos,
1278 Standard_Real& theExtensionSize,
1279 Prs3d_DimensionTextHorizontalPosition& theAlignment,
1280 Standard_Real& theFlyout) const
1282 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1283 Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length();
1285 // Build circle with radius that is equal to distance from text position to the center point.
1286 Standard_Real aRadius = gp_Vec (myCenterPoint, theTextPos).Magnitude();
1288 // Set attach points in positive direction of the flyout.
1289 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * aRadius);
1290 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * aRadius);
1292 gce_MakeCirc aConstructCircle (myCenterPoint, GetPlane(), aRadius);
1293 if (!aConstructCircle.IsDone())
1297 gp_Circ aCircle = aConstructCircle.Value();
1300 theExtensionSize = aDimensionAspect->ArrowAspect()->Length();
1301 theAlignment = Prs3d_DTHP_Center;
1303 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, aFirstAttach);
1304 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, aSecondAttach);
1305 if (aParamEnd < aParamBeg)
1307 Standard_Real aParam = aParamEnd;
1308 aParamEnd = aParamBeg;
1312 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
1313 Standard_Real aTextPar = ElCLib::Parameter (aCircle , theTextPos);
1315 // Horizontal center
1316 if (aTextPar > aParamBeg && aTextPar < aParamEnd)
1318 theFlyout = aRadius;
1324 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
1326 if (aTextPar > aParamBeg && aTextPar < aParamEnd)
1328 theFlyout = -aRadius;
1332 // Text on the extensions
1333 gp_Lin aFirstLine = gce_MakeLin (myCenterPoint, myFirstPoint);
1334 gp_Lin aSecondLine = gce_MakeLin (myCenterPoint, mySecondPoint);
1335 gp_Pnt aFirstTextProj = AIS::Nearest (aFirstLine, theTextPos);
1336 gp_Pnt aSecondTextProj = AIS::Nearest (aSecondLine, theTextPos);
1337 Standard_Real aFirstDist = aFirstTextProj.Distance (theTextPos);
1338 Standard_Real aSecondDist = aSecondTextProj.Distance (theTextPos);
1340 if (aFirstDist <= aSecondDist)
1342 aRadius = myCenterPoint.Distance (aFirstTextProj);
1343 Standard_Real aNewExtensionSize = aFirstDist - anArrowLength;
1344 theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
1346 theAlignment = Prs3d_DTHP_Left;
1348 gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, myFirstPoint).Normalized().Scaled (aRadius);
1350 theFlyout = aFirstTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
1351 ? -aRadius : aRadius;
1355 aRadius = myCenterPoint.Distance (aSecondTextProj);
1357 Standard_Real aNewExtensionSize = aSecondDist - anArrowLength;
1359 theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
1361 theAlignment = Prs3d_DTHP_Right;
1363 gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, mySecondPoint).Normalized().Scaled (aRadius);
1365 theFlyout = aSecondTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
1366 ? -aRadius : aRadius;
1370 //=======================================================================
1371 //function : FitTextAlignment
1373 //=======================================================================
1374 void AIS_AngleDimension::FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
1375 Standard_Integer& theLabelPosition,
1376 Standard_Boolean& theIsArrowsExternal) const
1378 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1380 Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
1382 // Prepare label string and compute its geometrical width
1383 Standard_Real aLabelWidth;
1384 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
1386 // add margins to label width
1387 if (aDimensionAspect->IsText3d())
1389 aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
1392 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
1393 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
1395 // Handle user-defined and automatic arrow placement
1396 switch (aDimensionAspect->ArrowOrientation())
1398 case Prs3d_DAO_External: theIsArrowsExternal = true; break;
1399 case Prs3d_DAO_Internal: theIsArrowsExternal = false; break;
1402 gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
1403 Standard_Real aDimensionWidth = anAttachVector.Magnitude();
1405 // Add margin to ensure a small tail between text and arrow
1406 Standard_Real anArrowMargin = aDimensionAspect->IsText3d()
1407 ? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN
1410 Standard_Real anArrowsWidth = (anArrowLength + anArrowMargin) * 2.0;
1412 theIsArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth;
1417 // Handle user-defined and automatic text placement
1418 switch (theHorizontalTextPos)
1420 case Prs3d_DTHP_Left : theLabelPosition |= LabelPosition_Left; break;
1421 case Prs3d_DTHP_Right : theLabelPosition |= LabelPosition_Right; break;
1422 case Prs3d_DTHP_Center: theLabelPosition |= LabelPosition_HCenter; break;
1423 case Prs3d_DTHP_Fit:
1425 gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
1426 Standard_Real aDimensionWidth = anAttachVector.Magnitude();
1427 Standard_Real anArrowsWidth = anArrowLength * 2.0;
1428 Standard_Real aContentWidth = theIsArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth;
1430 theLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter;
1435 switch (aDimensionAspect->TextVerticalPosition())
1437 case Prs3d_DTVP_Above : theLabelPosition |= LabelPosition_Above; break;
1438 case Prs3d_DTVP_Below : theLabelPosition |= LabelPosition_Below; break;
1439 case Prs3d_DTVP_Center : theLabelPosition |= LabelPosition_VCenter; break;