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>
52 #include <Geom_Line.hxx>
53 #include <Geom_Plane.hxx>
56 IMPLEMENT_STANDARD_RTTIEXT(AIS_AngleDimension,AIS_Dimension)
60 static const TCollection_ExtendedString THE_EMPTY_LABEL_STRING;
61 static const Standard_Real THE_EMPTY_LABEL_WIDTH = 0.0;
62 static const Standard_ExtCharacter THE_DEGREE_SYMBOL (0x00B0);
63 static const Standard_Real THE_3D_TEXT_MARGIN = 0.1;
66 //=======================================================================
67 //function : Constructor
69 //=======================================================================
70 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Edge& theFirstEdge,
71 const TopoDS_Edge& theSecondEdge)
72 : AIS_Dimension (AIS_KOD_PLANEANGLE)
75 SetMeasuredGeometry (theFirstEdge, theSecondEdge);
78 //=======================================================================
79 //function : Constructor
81 //=======================================================================
82 AIS_AngleDimension::AIS_AngleDimension (const gp_Pnt& theFirstPoint,
83 const gp_Pnt& theSecondPoint,
84 const gp_Pnt& theThirdPoint)
85 : AIS_Dimension (AIS_KOD_PLANEANGLE)
88 SetMeasuredGeometry (theFirstPoint, theSecondPoint, theThirdPoint);
91 //=======================================================================
92 //function : Constructor
94 //=======================================================================
95 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Vertex& theFirstVertex,
96 const TopoDS_Vertex& theSecondVertex,
97 const TopoDS_Vertex& theThirdVertex)
98 : AIS_Dimension (AIS_KOD_PLANEANGLE)
101 SetMeasuredGeometry (theFirstVertex, theSecondVertex, theThirdVertex);
104 //=======================================================================
105 //function : Constructor
107 //=======================================================================
108 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Face& theCone)
109 : AIS_Dimension (AIS_KOD_PLANEANGLE)
112 SetMeasuredGeometry (theCone);
115 //=======================================================================
116 //function : Constructor
118 //=======================================================================
119 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Face& theFirstFace,
120 const TopoDS_Face& theSecondFace)
121 : AIS_Dimension (AIS_KOD_PLANEANGLE)
124 SetMeasuredGeometry (theFirstFace, theSecondFace);
127 //=======================================================================
128 //function : Constructor
130 //=======================================================================
131 AIS_AngleDimension::AIS_AngleDimension (const TopoDS_Face& theFirstFace,
132 const TopoDS_Face& theSecondFace,
133 const gp_Pnt& thePoint)
134 : AIS_Dimension (AIS_KOD_PLANEANGLE)
137 SetMeasuredGeometry (theFirstFace, theSecondFace, thePoint);
140 //=======================================================================
141 //function : SetMeasuredGeometry
143 //=======================================================================
144 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
145 const TopoDS_Edge& theSecondEdge)
147 gp_Pln aComputedPlane;
149 myFirstShape = theFirstEdge;
150 mySecondShape = theSecondEdge;
151 myThirdShape = TopoDS_Shape();
152 myGeometryType = GeometryType_Edges;
153 myIsGeometryValid = InitTwoEdgesAngle (aComputedPlane);
155 if (myIsGeometryValid && !myIsPlaneCustom)
157 myPlane = aComputedPlane;
163 //=======================================================================
164 //function : SetMeasuredGeometry
166 //=======================================================================
167 void AIS_AngleDimension::SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
168 const gp_Pnt& theSecondPoint,
169 const gp_Pnt& theThirdPoint)
171 myFirstPoint = theFirstPoint;
172 myCenterPoint = theSecondPoint;
173 mySecondPoint = theThirdPoint;
174 myFirstShape = BRepLib_MakeVertex (myFirstPoint);
175 mySecondShape = BRepLib_MakeVertex (myCenterPoint);
176 myThirdShape = BRepLib_MakeVertex (mySecondPoint);
177 myGeometryType = GeometryType_Points;
178 myIsGeometryValid = IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
180 if (myIsGeometryValid && !myIsPlaneCustom)
188 //=======================================================================
189 //function : SetMeasuredGeometry
191 //=======================================================================
192 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
193 const TopoDS_Vertex& theSecondVertex,
194 const TopoDS_Vertex& theThirdVertex)
196 myFirstShape = theFirstVertex;
197 mySecondShape = theSecondVertex;
198 myThirdShape = theThirdVertex;
199 myFirstPoint = BRep_Tool::Pnt (theFirstVertex);
200 myCenterPoint = BRep_Tool::Pnt (theSecondVertex);
201 mySecondPoint = BRep_Tool::Pnt (theThirdVertex);
202 myGeometryType = GeometryType_Points;
203 myIsGeometryValid = IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
205 if (myIsGeometryValid && !myIsPlaneCustom)
213 //=======================================================================
214 //function : SetMeasuredGeometry
216 //=======================================================================
217 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theCone)
219 myFirstShape = theCone;
220 mySecondShape = TopoDS_Shape();
221 myThirdShape = TopoDS_Shape();
222 myGeometryType = GeometryType_Face;
223 myIsGeometryValid = InitConeAngle();
225 if (myIsGeometryValid && !myIsPlaneCustom)
233 //=======================================================================
234 //function : SetMeasuredGeometry
236 //=======================================================================
237 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
238 const TopoDS_Face& theSecondFace)
240 myFirstShape = theFirstFace;
241 mySecondShape = theSecondFace;
242 myThirdShape = TopoDS_Shape();
243 myGeometryType = GeometryType_Faces;
244 myIsGeometryValid = InitTwoFacesAngle();
246 if (myIsGeometryValid && !myIsPlaneCustom)
254 //=======================================================================
255 //function : SetMeasuredGeometry
257 //=======================================================================
258 void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
259 const TopoDS_Face& theSecondFace,
260 const gp_Pnt& thePoint)
262 myFirstShape = theFirstFace;
263 mySecondShape = theSecondFace;
264 myThirdShape = TopoDS_Shape();
265 myGeometryType = GeometryType_Faces;
266 myIsGeometryValid = InitTwoFacesAngle (thePoint);
268 if (myIsGeometryValid && !myIsPlaneCustom)
276 //=======================================================================
279 //=======================================================================
280 void AIS_AngleDimension::Init()
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 Standard_Real aRadius = theFirstAttach.Distance (theCenter);
306 // construct circle forming the arc
307 gce_MakeCirc aConstructCircle (theCenter, aPlane, aRadius);
308 if (!aConstructCircle.IsDone())
313 gp_Circ aCircle = aConstructCircle.Value();
315 // compute angle parameters of arc end-points on circle
316 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, theFirstAttach);
317 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, theSecondAttach);
318 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
320 return ElCLib::Value ((aParamBeg + aParamEnd) * 0.5, aCircle);
323 //=======================================================================
324 //function : GetNormalForMinAngle
326 //=======================================================================
327 gp_Dir AIS_AngleDimension::GetNormalForMinAngle() const
329 const gp_Dir& aNormal = myPlane.Axis().Direction();
330 gp_Dir aFirst (gp_Vec (myCenterPoint, myFirstPoint) );
331 gp_Dir aSecond (gp_Vec (myCenterPoint, mySecondPoint) );
333 return aFirst.AngleWithRef (aSecond, aNormal) < 0.0
338 //=======================================================================
340 //purpose : draws the arc between two attach points
341 //=======================================================================
342 void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
343 const gp_Pnt& theFirstAttach,
344 const gp_Pnt& theSecondAttach,
345 const gp_Pnt& theCenter,
346 const Standard_Real theRadius,
347 const Standard_Integer theMode)
349 gp_Pln aPlane (myCenterPoint, GetNormalForMinAngle());
351 // construct circle forming the arc
352 gce_MakeCirc aConstructCircle (theCenter, aPlane, theRadius);
353 if (!aConstructCircle.IsDone())
358 gp_Circ aCircle = aConstructCircle.Value();
361 GC_MakeArcOfCircle aConstructArc (aCircle, theFirstAttach, theSecondAttach, Standard_True);
362 if (!aConstructArc.IsDone())
367 // generate points with specified deflection
368 const Handle(Geom_TrimmedCurve)& anArcCurve = aConstructArc.Value();
370 GeomAdaptor_Curve anArcAdaptor (anArcCurve, anArcCurve->FirstParameter(), anArcCurve->LastParameter());
372 // compute number of discretization elements in old-fanshioned way
373 gp_Vec aCenterToFirstVec (theCenter, theFirstAttach);
374 gp_Vec aCenterToSecondVec (theCenter, theSecondAttach);
375 const Standard_Real anAngle = aCenterToFirstVec.Angle (aCenterToSecondVec);
376 const Standard_Integer aNbPoints = Max (4, Standard_Integer (50.0 * anAngle / M_PI));
378 GCPnts_UniformAbscissa aMakePnts (anArcAdaptor, aNbPoints);
379 if (!aMakePnts.IsDone())
384 // init data arrays for graphical and selection primitives
385 Handle(Graphic3d_ArrayOfPolylines) aPrimSegments = new Graphic3d_ArrayOfPolylines (aNbPoints);
387 SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve();
389 // load data into arrays
390 for (Standard_Integer aPntIt = 1; aPntIt <= aMakePnts.NbPoints(); ++aPntIt)
392 gp_Pnt aPnt = anArcAdaptor.Value (aMakePnts.Parameter (aPntIt));
394 aPrimSegments->AddVertex (aPnt);
396 aSensitiveCurve.Append (aPnt);
399 // add display presentation
400 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All)
402 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True);
404 Handle(Graphic3d_AspectLine3d) aDimensionLineStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect();
405 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionLineStyle);
406 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
407 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All)
409 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False);
413 //=======================================================================
414 //function: DrawArcWithText
416 //=======================================================================
417 void AIS_AngleDimension::DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
418 const gp_Pnt& theFirstAttach,
419 const gp_Pnt& theSecondAttach,
420 const gp_Pnt& theCenter,
421 const TCollection_ExtendedString& theText,
422 const Standard_Real theTextWidth,
423 const Standard_Integer theMode,
424 const Standard_Integer theLabelPosition)
426 gp_Pln aPlane (myCenterPoint, GetNormalForMinAngle());
428 Standard_Real aRadius = theFirstAttach.Distance (myCenterPoint);
430 // construct circle forming the arc
431 gce_MakeCirc aConstructCircle (theCenter, aPlane, aRadius);
432 if (!aConstructCircle.IsDone())
437 gp_Circ aCircle = aConstructCircle.Value();
439 // compute angle parameters of arc end-points on circle
440 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, theFirstAttach);
441 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, theSecondAttach);
442 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
444 // middle point of arc parameter on circle
445 Standard_Real aParamMid = (aParamBeg + aParamEnd) * 0.5;
447 // add text graphical primitives
448 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
450 gp_Pnt aTextPos = ElCLib::Value (aParamMid, aCircle);
451 gp_Dir aTextDir = gce_MakeDir (theFirstAttach, theSecondAttach);
454 DrawText (thePresentation,
461 if (theMode != ComputeMode_All && theMode != ComputeMode_Line)
466 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
468 Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center
469 && aDimensionAspect->IsText3d();
473 // compute gap for label as parameteric size of sector on circle segment
474 Standard_Real aSectorOfText = theTextWidth / aRadius;
475 Standard_Real aTextBegin = aParamMid - aSectorOfText * 0.5;
476 Standard_Real aTextEnd = aParamMid + aSectorOfText * 0.5;
477 gp_Pnt aTextPntBeg = ElCLib::Value (aTextBegin, aCircle);
478 gp_Pnt aTextPntEnd = ElCLib::Value (aTextEnd, aCircle);
481 if (aTextBegin > aParamBeg)
483 DrawArc (thePresentation, theFirstAttach, aTextPntBeg, theCenter, aRadius, theMode);
485 if (aTextEnd < aParamEnd)
487 DrawArc (thePresentation, aTextPntEnd, theSecondAttach, theCenter, aRadius, theMode);
492 DrawArc (thePresentation, theFirstAttach, theSecondAttach, theCenter, aRadius, theMode);
496 //=======================================================================
497 //function : CheckPlane
499 //=======================================================================
500 Standard_Boolean AIS_AngleDimension::CheckPlane (const gp_Pln& thePlane)const
502 if (!thePlane.Contains (myFirstPoint, Precision::Confusion()) &&
503 !thePlane.Contains (mySecondPoint, Precision::Confusion()) &&
504 !thePlane.Contains (myCenterPoint, Precision::Confusion()))
506 return Standard_False;
509 return Standard_True;
512 //=======================================================================
513 //function : ComputePlane
515 //=======================================================================
516 void AIS_AngleDimension::ComputePlane()
518 if (!myIsGeometryValid)
523 // Compute working plane so that Y axis is codirectional
524 // with Y axis of text coordinate system (necessary for text alignment)
525 gp_Vec aFirstVec = gp_Vec (myCenterPoint, myFirstPoint);
526 gp_Vec aSecondVec = gp_Vec (myCenterPoint, mySecondPoint);
527 gp_Vec aDirectionN = aSecondVec ^ aFirstVec;
528 gp_Vec aDirectionY = aFirstVec + aSecondVec;
529 gp_Vec aDirectionX = aDirectionY ^ aDirectionN;
531 myPlane = gp_Pln (gp_Ax3 (myCenterPoint, gp_Dir (aDirectionN), gp_Dir (aDirectionX)));
534 //=======================================================================
535 //function : GetModelUnits
537 //=======================================================================
538 const TCollection_AsciiString& AIS_AngleDimension::GetModelUnits() const
540 return myDrawer->DimAngleModelUnits();
543 //=======================================================================
544 //function : GetDisplayUnits
546 //=======================================================================
547 const TCollection_AsciiString& AIS_AngleDimension::GetDisplayUnits() const
549 return myDrawer->DimAngleDisplayUnits();
552 //=======================================================================
553 //function : SetModelUnits
555 //=======================================================================
556 void AIS_AngleDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
558 myDrawer->SetDimAngleModelUnits (theUnits);
561 //=======================================================================
562 //function : SetDisplayUnits
564 //=======================================================================
565 void AIS_AngleDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
567 myDrawer->SetDimAngleDisplayUnits (theUnits);
570 //=======================================================================
571 //function : ComputeValue
573 //=======================================================================
574 Standard_Real AIS_AngleDimension::ComputeValue() const
581 gp_Vec aVec1 (myCenterPoint, myFirstPoint);
582 gp_Vec aVec2 (myCenterPoint, mySecondPoint);
584 Standard_Real anAngle = aVec1.AngleWithRef (aVec2, GetNormalForMinAngle());
586 return anAngle > 0.0 ? anAngle : (2.0 * M_PI + anAngle);
589 //=======================================================================
591 //purpose : Having three gp_Pnt points compute presentation
592 //=======================================================================
593 void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
594 const Handle(Prs3d_Presentation)& thePresentation,
595 const Standard_Integer theMode)
597 thePresentation->Clear();
598 mySelectionGeom.Clear (theMode);
605 // Parameters for presentation
606 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
608 Prs3d_Root::CurrentGroup(thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
610 Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
612 // prepare label string and compute its geometrical width
613 Standard_Real aLabelWidth;
614 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
616 // add margins to label width
617 if (aDimensionAspect->IsText3d())
619 aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
622 // Get parameters from aspect or adjust it according with custom text position
623 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
624 Prs3d_DimensionTextHorizontalPosition aHorisontalTextPos = aDimensionAspect->TextHorizontalPosition();
626 if (IsTextPositionCustom())
628 AdjustParameters (myFixedTextPosition,anExtensionSize, aHorisontalTextPos, myFlyout);
631 // Handle user-defined and automatic arrow placement
632 Standard_Boolean isArrowsExternal = Standard_False;
633 Standard_Integer aLabelPosition = LabelPosition_None;
635 FitTextAlignment (aHorisontalTextPos, aLabelPosition, isArrowsExternal);
637 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
638 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
640 //Arrows positions and directions
641 gp_Vec aWorkingPlaneDir (GetNormalForMinAngle());
643 gp_Dir aFirstExtensionDir = aWorkingPlaneDir.Reversed() ^ gp_Vec (myCenterPoint, aFirstAttach);
644 gp_Dir aSecondExtensionDir = aWorkingPlaneDir ^ gp_Vec (myCenterPoint, aSecondAttach);
646 gp_Vec aFirstArrowVec = gp_Vec (aFirstExtensionDir) * anArrowLength;
647 gp_Vec aSecondArrowVec = gp_Vec (aSecondExtensionDir) * anArrowLength;
649 if (isArrowsExternal)
651 aFirstArrowVec.Reverse();
652 aSecondArrowVec.Reverse();
655 gp_Pnt aFirstArrowBegin (0.0, 0.0, 0.0);
656 gp_Pnt aFirstArrowEnd (0.0, 0.0, 0.0);
657 gp_Pnt aSecondArrowBegin (0.0, 0.0, 0.0);
658 gp_Pnt aSecondArrowEnd (0.0, 0.0, 0.0);
660 aFirstArrowBegin = aFirstAttach;
661 aSecondArrowBegin = aSecondAttach;
662 aFirstArrowEnd = aFirstAttach.Translated (-aFirstArrowVec);
663 aSecondArrowEnd = aSecondAttach.Translated (-aSecondArrowVec);
665 // Group1: stenciling text and the angle dimension arc
666 Prs3d_Root::NewGroup (thePresentation);
668 Standard_Integer aHPosition = aLabelPosition & LabelPosition_HMask;
673 case LabelPosition_HCenter :
675 Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center
676 && aDimensionAspect->IsText3d();
680 DrawArcWithText (thePresentation,
691 // compute text primitives
692 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
694 gp_Vec aDimensionDir (aFirstAttach, aSecondAttach);
695 gp_Pnt aTextPos = IsTextPositionCustom() ? myFixedTextPosition
696 : GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
697 gp_Dir aTextDir = aDimensionDir;
699 DrawText (thePresentation,
706 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
708 DrawArc (thePresentation,
709 isArrowsExternal ? aFirstAttach : aFirstArrowEnd,
710 isArrowsExternal ? aSecondAttach : aSecondArrowEnd,
718 case LabelPosition_Left :
720 DrawExtension (thePresentation,
722 isArrowsExternal ? aFirstArrowEnd : aFirstAttach,
731 case LabelPosition_Right :
733 DrawExtension (thePresentation,
735 isArrowsExternal ? aSecondArrowEnd : aSecondAttach,
745 // dimension arc without text
746 if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && aHPosition != LabelPosition_HCenter)
748 Prs3d_Root::NewGroup (thePresentation);
750 DrawArc (thePresentation,
751 isArrowsExternal ? aFirstAttach : aFirstArrowEnd,
752 isArrowsExternal ? aSecondAttach : aSecondArrowEnd,
758 // arrows and arrow extensions
759 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
761 Prs3d_Root::NewGroup (thePresentation);
763 DrawArrow (thePresentation, aFirstArrowBegin, gp_Dir (aFirstArrowVec));
764 DrawArrow (thePresentation, aSecondArrowBegin, gp_Dir (aSecondArrowVec));
767 if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && isArrowsExternal)
769 Prs3d_Root::NewGroup (thePresentation);
771 if (aHPosition != LabelPosition_Left)
773 DrawExtension (thePresentation,
774 aDimensionAspect->ArrowTailSize(),
777 THE_EMPTY_LABEL_STRING,
778 THE_EMPTY_LABEL_WIDTH,
783 if (aHPosition != LabelPosition_Right)
785 DrawExtension (thePresentation,
786 aDimensionAspect->ArrowTailSize(),
789 THE_EMPTY_LABEL_STRING,
790 THE_EMPTY_LABEL_WIDTH,
797 if (theMode == ComputeMode_All)
799 Prs3d_Root::NewGroup (thePresentation);
801 Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (4);
802 aPrimSegments->AddVertex (myCenterPoint);
803 aPrimSegments->AddVertex (aFirstAttach);
804 aPrimSegments->AddVertex (myCenterPoint);
805 aPrimSegments->AddVertex (aSecondAttach);
807 Handle(Graphic3d_AspectLine3d) aFlyoutStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect();
808 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aFlyoutStyle);
809 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
812 mySelectionGeom.IsComputed = Standard_True;
815 //=======================================================================
816 //function : ComputeFlyoutSelection
817 //purpose : computes selection for flyouts
818 //=======================================================================
819 void AIS_AngleDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
820 const Handle(SelectMgr_EntityOwner)& theOwner)
822 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
823 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
825 Handle(Select3D_SensitiveGroup) aSensitiveEntity = new Select3D_SensitiveGroup (theOwner);
826 aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, myCenterPoint, aFirstAttach));
827 aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, myCenterPoint, aSecondAttach));
829 theSelection->Add (aSensitiveEntity);
832 //=======================================================================
833 //function : InitTwoEdgesAngle
835 //=======================================================================
836 Standard_Boolean AIS_AngleDimension::InitTwoEdgesAngle (gp_Pln& theComputedPlane)
838 TopoDS_Edge aFirstEdge = TopoDS::Edge (myFirstShape);
839 TopoDS_Edge aSecondEdge = TopoDS::Edge (mySecondShape);
841 BRepAdaptor_Curve aMakeFirstLine (aFirstEdge);
842 BRepAdaptor_Curve aMakeSecondLine (aSecondEdge);
844 if (aMakeFirstLine.GetType() != GeomAbs_Line || aMakeSecondLine.GetType() != GeomAbs_Line)
846 return Standard_False;
849 Handle(Geom_Line) aFirstLine = new Geom_Line (aMakeFirstLine.Line());
850 Handle(Geom_Line) aSecondLine = new Geom_Line (aMakeSecondLine.Line());
852 gp_Lin aFirstLin = aFirstLine->Lin();
853 gp_Lin aSecondLin = aSecondLine->Lin();
855 Standard_Boolean isParallelLines = aFirstLin.Direction().IsParallel (aSecondLin.Direction(), Precision::Angular());
857 theComputedPlane = isParallelLines ? gp_Pln(gp::XOY())
858 : gp_Pln (aSecondLin.Location(), gp_Vec (aFirstLin.Direction()) ^ gp_Vec (aSecondLin.Direction()));
860 // Compute geometry for this plane and edges
861 Standard_Boolean isInfinite1,isInfinite2;
862 gp_Pnt aFirstPoint1, aLastPoint1, aFirstPoint2, aLastPoint2;
863 Handle(Geom_Curve) aFirstCurve = aFirstLine, aSecondCurve = aSecondLine;
864 if (!AIS::ComputeGeometry (aFirstEdge, aSecondEdge,
865 aFirstCurve, aSecondCurve,
866 aFirstPoint1, aLastPoint1,
867 aFirstPoint2, aLastPoint2,
868 isInfinite1, isInfinite2))
870 return Standard_False;
873 Standard_Boolean isSameLines = aFirstLin.Direction().IsEqual (aSecondLin.Direction(), Precision::Angular())
874 && aFirstLin.Location().IsEqual (aSecondLin.Location(),Precision::Confusion());
876 // It can be the same gp_Lin geometry but the different begin and end parameters
877 Standard_Boolean isSameEdges =
878 (aFirstPoint1.IsEqual (aFirstPoint2, Precision::Confusion()) && aLastPoint1.IsEqual (aLastPoint2, Precision::Confusion()))
879 || (aFirstPoint1.IsEqual (aLastPoint2, Precision::Confusion()) && aLastPoint1.IsEqual (aFirstPoint2, Precision::Confusion()));
883 // Zero angle, it could not handle this geometry
884 if (isSameLines && isSameEdges)
886 return Standard_False;
889 // Handle the case of Pi angle
890 const Standard_Real aParam11 = ElCLib::Parameter (aFirstLin, aFirstPoint1);
891 const Standard_Real aParam12 = ElCLib::Parameter (aFirstLin, aLastPoint1);
892 const Standard_Real aParam21 = ElCLib::Parameter (aFirstLin, aFirstPoint2);
893 const Standard_Real aParam22 = ElCLib::Parameter (aFirstLin, aLastPoint2);
894 myCenterPoint = ElCLib::Value ( (Min (aParam11, aParam12) + Max (aParam21, aParam22)) * 0.5, aFirstLin);
895 myFirstPoint = myCenterPoint.Translated (gp_Vec (aFirstLin.Direction()) * Abs (GetFlyout()));
896 mySecondPoint = myCenterPoint.XYZ() + (aFirstLin.Direction().IsEqual (aSecondLin.Direction(), Precision::Angular())
897 ? aFirstLin.Direction().Reversed().XYZ() * Abs (GetFlyout())
898 : aSecondLin.Direction().XYZ() * Abs (GetFlyout()));
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.Distance (aFirstPoint1) > myCenterPoint.Distance (aLastPoint1)
931 mySecondPoint = myCenterPoint.Distance (aFirstPoint2) > myCenterPoint.Distance (aLastPoint2)
936 return IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
939 //=======================================================================
940 //function : InitTwoFacesAngle
941 //purpose : initialization of angle dimension between two faces
942 //=======================================================================
943 Standard_Boolean AIS_AngleDimension::InitTwoFacesAngle()
945 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
946 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
948 gp_Dir aFirstDir, aSecondDir;
949 gp_Pln aFirstPln, aSecondPln;
950 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
951 AIS_KindOfSurface aFirstSurfType, aSecondSurfType;
952 Standard_Real aFirstOffset, aSecondOffset;
954 AIS::GetPlaneFromFace (aFirstFace, aFirstPln,
955 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
957 AIS::GetPlaneFromFace (aSecondFace, aSecondPln,
958 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
960 if (aFirstSurfType == AIS_KOS_Plane && aSecondSurfType == AIS_KOS_Plane)
963 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (aFirstBasisSurf);
964 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (aSecondBasisSurf);
965 return AIS::InitAngleBetweenPlanarFaces (aFirstFace,
970 && IsValidPoints (myFirstPoint,
976 // Curvilinear faces angle
977 return AIS::InitAngleBetweenCurvilinearFaces (aFirstFace,
984 && IsValidPoints (myFirstPoint,
990 //=======================================================================
991 //function : InitTwoFacesAngle
992 //purpose : initialization of angle dimension between two faces
993 //=======================================================================
994 Standard_Boolean AIS_AngleDimension::InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace)
996 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
997 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
999 gp_Dir aFirstDir, aSecondDir;
1000 gp_Pln aFirstPln, aSecondPln;
1001 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
1002 AIS_KindOfSurface aFirstSurfType, aSecondSurfType;
1003 Standard_Real aFirstOffset, aSecondOffset;
1005 AIS::GetPlaneFromFace (aFirstFace, aFirstPln,
1006 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
1008 AIS::GetPlaneFromFace (aSecondFace, aSecondPln,
1009 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
1011 myFirstPoint = thePointOnFirstFace;
1012 if (aFirstSurfType == AIS_KOS_Plane && aSecondSurfType == AIS_KOS_Plane)
1014 //Planar faces angle
1015 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (aFirstBasisSurf);
1016 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (aSecondBasisSurf);
1017 return AIS::InitAngleBetweenPlanarFaces (aFirstFace,
1023 && IsValidPoints (myFirstPoint,
1029 // Curvilinear faces angle
1030 return AIS::InitAngleBetweenCurvilinearFaces (aFirstFace,
1038 && IsValidPoints (myFirstPoint,
1044 //=======================================================================
1045 //function : InitConeAngle
1046 //purpose : initialization of the cone angle
1047 //=======================================================================
1048 Standard_Boolean AIS_AngleDimension::InitConeAngle()
1050 if (myFirstShape.IsNull())
1052 return Standard_False;
1055 TopoDS_Face aConeShape = TopoDS::Face (myFirstShape);
1059 // A surface from the Face
1060 Handle(Geom_Surface) aSurf;
1061 Handle(Geom_OffsetSurface) aOffsetSurf;
1062 Handle(Geom_ConicalSurface) aConicalSurf;
1063 Handle(Geom_SurfaceOfRevolution) aRevSurf;
1064 Handle(Geom_Line) aLine;
1065 BRepAdaptor_Surface aConeAdaptor (aConeShape);
1067 AIS_KindOfSurface aSurfType;
1068 Standard_Real anOffset = 0.;
1069 Handle(Standard_Type) aType;
1071 Standard_Real aMaxV = aConeAdaptor.FirstVParameter();
1072 Standard_Real aMinV = aConeAdaptor.LastVParameter();
1074 AIS::GetPlaneFromFace (aConeShape, aPln, aSurf, aSurfType, anOffset);
1076 if (aSurfType == AIS_KOS_Revolution)
1078 // Surface of revolution
1079 aRevSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(aSurf);
1080 gp_Lin aLin (aRevSurf->Axis());
1081 Handle(Geom_Curve) aBasisCurve = aRevSurf->BasisCurve();
1082 //Must be a part of line (basis curve should be linear)
1083 if (aBasisCurve ->DynamicType() != STANDARD_TYPE(Geom_Line))
1084 return Standard_False;
1086 gp_Pnt aFirst1 = aConeAdaptor.Value (0., aMinV);
1087 gp_Pnt aLast1 = aConeAdaptor.Value (0., aMaxV);
1088 gp_Vec aVec1 (aFirst1, aLast1);
1090 //Projection <aFirst> on <aLin>
1091 gp_Pnt aFirst2 = ElCLib::Value (ElCLib::Parameter (aLin, aFirst1), aLin);
1092 // Projection <aLast> on <aLin>
1093 gp_Pnt aLast2 = ElCLib::Value (ElCLib::Parameter (aLin, aLast1), aLin);
1095 gp_Vec aVec2 (aFirst2, aLast2);
1097 // Check if two parts of revolution are parallel (it's a cylinder) or normal (it's a circle).
1098 if (aVec1.IsParallel (aVec2, Precision::Angular())
1099 || aVec1.IsNormal (aVec2,Precision::Angular()))
1100 return Standard_False;
1102 gce_MakeCone aMkCone (aRevSurf->Axis(), aFirst1, aLast1);
1103 aCone = aMkCone.Value();
1104 myCenterPoint = aCone.Apex();
1108 aType = aSurf->DynamicType();
1109 if (aType == STANDARD_TYPE(Geom_OffsetSurface) || anOffset > 0.01)
1112 aOffsetSurf = new Geom_OffsetSurface (aSurf, anOffset);
1113 aSurf = aOffsetSurf->Surface();
1114 BRepBuilderAPI_MakeFace aMkFace(aSurf, Precision::Confusion());
1116 if (!aMkFace.IsDone())
1117 return Standard_False;
1118 aConeAdaptor.Initialize (aMkFace.Face());
1120 aCone = aConeAdaptor.Cone();
1121 aConicalSurf = Handle(Geom_ConicalSurface)::DownCast (aSurf);
1122 myCenterPoint = aConicalSurf->Apex();
1125 // A circle where the angle is drawn
1126 Handle(Geom_Curve) aCurve;
1127 Standard_Real aMidV = ( aMinV + aMaxV ) / 2.5;
1128 aCurve = aSurf->VIso (aMidV);
1129 aCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
1131 aCurve = aSurf->VIso(aMaxV);
1132 gp_Circ aCircVmax = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
1133 aCurve = aSurf->VIso(aMinV);
1134 gp_Circ aCircVmin = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
1136 if (aCircVmax.Radius() < aCircVmin.Radius())
1138 gp_Circ aTmpCirc = aCircVmax;
1139 aCircVmax = aCircVmin;
1140 aCircVmin = aTmpCirc;
1143 myFirstPoint = ElCLib::Value (0, aCircle);
1144 mySecondPoint = ElCLib::Value (M_PI, aCircle);
1145 return Standard_True;
1148 //=======================================================================
1149 //function : IsValidPoints
1151 //=======================================================================
1152 Standard_Boolean AIS_AngleDimension::IsValidPoints (const gp_Pnt& theFirstPoint,
1153 const gp_Pnt& theCenterPoint,
1154 const gp_Pnt& theSecondPoint) const
1156 return theFirstPoint.Distance (theCenterPoint) > Precision::Confusion()
1157 && theSecondPoint.Distance (theCenterPoint) > Precision::Confusion()
1158 && gp_Vec (theCenterPoint, theFirstPoint).Angle (
1159 gp_Vec (theCenterPoint, theSecondPoint)) > Precision::Angular();
1162 //=======================================================================
1163 //function : GetTextPosition
1165 //=======================================================================
1166 const gp_Pnt AIS_AngleDimension::GetTextPosition() const
1170 return gp::Origin();
1173 if (IsTextPositionCustom())
1175 return myFixedTextPosition;
1178 // Counts text position according to the dimension parameters
1179 gp_Pnt aTextPosition (gp::Origin());
1181 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1183 // Prepare label string and compute its geometrical width
1184 Standard_Real aLabelWidth;
1185 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
1187 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
1188 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
1190 // Handle user-defined and automatic arrow placement
1191 Standard_Boolean isArrowsExternal = Standard_False;
1192 Standard_Integer aLabelPosition = LabelPosition_None;
1193 FitTextAlignment (aDimensionAspect->TextHorizontalPosition(),
1194 aLabelPosition, isArrowsExternal);
1196 // Get text position
1197 switch (aLabelPosition & LabelPosition_HMask)
1199 case LabelPosition_HCenter:
1201 aTextPosition = GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
1204 case LabelPosition_Left:
1206 gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
1207 gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aFirstAttach);
1208 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
1209 Standard_Real anOffset = isArrowsExternal
1210 ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
1212 gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * -anOffset;
1213 aTextPosition = aFirstAttach.Translated (anExtensionVec);
1216 case LabelPosition_Right:
1218 gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
1219 gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aSecondAttach);
1220 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
1221 Standard_Real anOffset = isArrowsExternal
1222 ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
1224 gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * anOffset;
1225 aTextPosition = aSecondAttach.Translated (anExtensionVec);
1230 return aTextPosition;
1233 //=======================================================================
1234 //function : SetTextPosition
1236 //=======================================================================
1237 void AIS_AngleDimension::SetTextPosition (const gp_Pnt& theTextPos)
1244 // The text position point for angle dimension should belong to the working plane.
1245 if (!GetPlane().Contains (theTextPos, Precision::Confusion()))
1247 Standard_ProgramError::Raise ("The text position point for angle dimension doesn't belong to the working plane.");
1250 myIsTextPositionFixed = Standard_True;
1251 myFixedTextPosition = theTextPos;
1254 //=======================================================================
1255 //function : AdjustParameters
1257 //=======================================================================
1258 void AIS_AngleDimension::AdjustParameters (const gp_Pnt& theTextPos,
1259 Standard_Real& theExtensionSize,
1260 Prs3d_DimensionTextHorizontalPosition& theAlignment,
1261 Standard_Real& theFlyout) const
1263 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1264 Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length();
1266 // Build circle with radius that is equal to distance from text position to the center point.
1267 Standard_Real aRadius = gp_Vec (myCenterPoint, theTextPos).Magnitude();
1269 // Set attach points in positive direction of the flyout.
1270 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * aRadius);
1271 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * aRadius);
1273 gce_MakeCirc aConstructCircle (myCenterPoint, GetPlane(), aRadius);
1274 if (!aConstructCircle.IsDone())
1278 gp_Circ aCircle = aConstructCircle.Value();
1281 theExtensionSize = aDimensionAspect->ArrowAspect()->Length();
1282 theAlignment = Prs3d_DTHP_Center;
1284 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, aFirstAttach);
1285 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, aSecondAttach);
1286 if (aParamEnd < aParamBeg)
1288 Standard_Real aParam = aParamEnd;
1289 aParamEnd = aParamBeg;
1293 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
1294 Standard_Real aTextPar = ElCLib::Parameter (aCircle , theTextPos);
1296 // Horizontal center
1297 if (aTextPar > aParamBeg && aTextPar < aParamEnd)
1299 theFlyout = aRadius;
1305 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
1307 if (aTextPar > aParamBeg && aTextPar < aParamEnd)
1309 theFlyout = -aRadius;
1313 // Text on the extensions
1314 gp_Lin aFirstLine = gce_MakeLin (myCenterPoint, myFirstPoint);
1315 gp_Lin aSecondLine = gce_MakeLin (myCenterPoint, mySecondPoint);
1316 gp_Pnt aFirstTextProj = AIS::Nearest (aFirstLine, theTextPos);
1317 gp_Pnt aSecondTextProj = AIS::Nearest (aSecondLine, theTextPos);
1318 Standard_Real aFirstDist = aFirstTextProj.Distance (theTextPos);
1319 Standard_Real aSecondDist = aSecondTextProj.Distance (theTextPos);
1321 if (aFirstDist <= aSecondDist)
1323 aRadius = myCenterPoint.Distance (aFirstTextProj);
1324 Standard_Real aNewExtensionSize = aFirstDist - anArrowLength;
1325 theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
1327 theAlignment = Prs3d_DTHP_Left;
1329 gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, myFirstPoint).Normalized().Scaled (aRadius);
1331 theFlyout = aFirstTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
1332 ? -aRadius : aRadius;
1336 aRadius = myCenterPoint.Distance (aSecondTextProj);
1338 Standard_Real aNewExtensionSize = aSecondDist - anArrowLength;
1340 theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
1342 theAlignment = Prs3d_DTHP_Right;
1344 gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, mySecondPoint).Normalized().Scaled (aRadius);
1346 theFlyout = aSecondTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
1347 ? -aRadius : aRadius;
1351 //=======================================================================
1352 //function : FitTextAlignment
1354 //=======================================================================
1355 void AIS_AngleDimension::FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
1356 Standard_Integer& theLabelPosition,
1357 Standard_Boolean& theIsArrowsExternal) const
1359 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1361 Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
1363 // Prepare label string and compute its geometrical width
1364 Standard_Real aLabelWidth;
1365 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
1367 // add margins to label width
1368 if (aDimensionAspect->IsText3d())
1370 aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
1373 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
1374 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
1376 // Handle user-defined and automatic arrow placement
1377 switch (aDimensionAspect->ArrowOrientation())
1379 case Prs3d_DAO_External: theIsArrowsExternal = true; break;
1380 case Prs3d_DAO_Internal: theIsArrowsExternal = false; break;
1383 gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
1384 Standard_Real aDimensionWidth = anAttachVector.Magnitude();
1386 // Add margin to ensure a small tail between text and arrow
1387 Standard_Real anArrowMargin = aDimensionAspect->IsText3d()
1388 ? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN
1391 Standard_Real anArrowsWidth = (anArrowLength + anArrowMargin) * 2.0;
1393 theIsArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth;
1398 // Handle user-defined and automatic text placement
1399 switch (theHorizontalTextPos)
1401 case Prs3d_DTHP_Left : theLabelPosition |= LabelPosition_Left; break;
1402 case Prs3d_DTHP_Right : theLabelPosition |= LabelPosition_Right; break;
1403 case Prs3d_DTHP_Center: theLabelPosition |= LabelPosition_HCenter; break;
1404 case Prs3d_DTHP_Fit:
1406 gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
1407 Standard_Real aDimensionWidth = anAttachVector.Magnitude();
1408 Standard_Real anArrowsWidth = anArrowLength * 2.0;
1409 Standard_Real aContentWidth = theIsArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth;
1411 theLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter;
1416 switch (aDimensionAspect->TextVerticalPosition())
1418 case Prs3d_DTVP_Above : theLabelPosition |= LabelPosition_Above; break;
1419 case Prs3d_DTVP_Below : theLabelPosition |= LabelPosition_Below; break;
1420 case Prs3d_DTVP_Center : theLabelPosition |= LabelPosition_VCenter; break;