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 <PrsDim_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>
55 IMPLEMENT_STANDARD_RTTIEXT(PrsDim_AngleDimension, PrsDim_Dimension)
59 static const TCollection_ExtendedString THE_EMPTY_LABEL_STRING;
60 static const Standard_Real THE_EMPTY_LABEL_WIDTH = 0.0;
61 static const Standard_ExtCharacter THE_DEGREE_SYMBOL (0x00B0);
62 static const Standard_Real THE_3D_TEXT_MARGIN = 0.1;
64 //! Returns true if the given points lie on a same line.
65 static Standard_Boolean isSameLine (const gp_Pnt& theFirstPoint,
66 const gp_Pnt& theCenterPoint,
67 const gp_Pnt& theSecondPoint)
69 gp_Vec aVec1 (theFirstPoint, theCenterPoint);
70 gp_Vec aVec2 (theCenterPoint, theSecondPoint);
72 return aVec1.IsParallel (aVec2, Precision::Angular());
76 //=======================================================================
77 //function : Constructor
79 //=======================================================================
80 PrsDim_AngleDimension::PrsDim_AngleDimension (const TopoDS_Edge& theFirstEdge,
81 const TopoDS_Edge& theSecondEdge)
82 : PrsDim_Dimension (PrsDim_KOD_PLANEANGLE)
85 SetMeasuredGeometry (theFirstEdge, theSecondEdge);
88 //=======================================================================
89 //function : Constructor
91 //=======================================================================
92 PrsDim_AngleDimension::PrsDim_AngleDimension (const gp_Pnt& theFirstPoint,
93 const gp_Pnt& theSecondPoint,
94 const gp_Pnt& theThirdPoint)
95 : PrsDim_Dimension (PrsDim_KOD_PLANEANGLE)
98 SetMeasuredGeometry (theFirstPoint, theSecondPoint, theThirdPoint);
101 //=======================================================================
102 //function : Constructor
104 //=======================================================================
105 PrsDim_AngleDimension::PrsDim_AngleDimension (const TopoDS_Vertex& theFirstVertex,
106 const TopoDS_Vertex& theSecondVertex,
107 const TopoDS_Vertex& theThirdVertex)
108 : PrsDim_Dimension (PrsDim_KOD_PLANEANGLE)
111 SetMeasuredGeometry (theFirstVertex, theSecondVertex, theThirdVertex);
114 //=======================================================================
115 //function : Constructor
117 //=======================================================================
118 PrsDim_AngleDimension::PrsDim_AngleDimension (const TopoDS_Face& theCone)
119 : PrsDim_Dimension (PrsDim_KOD_PLANEANGLE)
122 SetMeasuredGeometry (theCone);
125 //=======================================================================
126 //function : Constructor
128 //=======================================================================
129 PrsDim_AngleDimension::PrsDim_AngleDimension (const TopoDS_Face& theFirstFace,
130 const TopoDS_Face& theSecondFace)
131 : PrsDim_Dimension (PrsDim_KOD_PLANEANGLE)
134 SetMeasuredGeometry (theFirstFace, theSecondFace);
137 //=======================================================================
138 //function : Constructor
140 //=======================================================================
141 PrsDim_AngleDimension::PrsDim_AngleDimension (const TopoDS_Face& theFirstFace,
142 const TopoDS_Face& theSecondFace,
143 const gp_Pnt& thePoint)
144 : PrsDim_Dimension (PrsDim_KOD_PLANEANGLE)
147 SetMeasuredGeometry (theFirstFace, theSecondFace, thePoint);
150 //=======================================================================
151 //function : SetMeasuredGeometry
153 //=======================================================================
154 void PrsDim_AngleDimension::SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
155 const TopoDS_Edge& theSecondEdge)
157 gp_Pln aComputedPlane;
159 myFirstShape = theFirstEdge;
160 mySecondShape = theSecondEdge;
161 myThirdShape = TopoDS_Shape();
162 myGeometryType = GeometryType_Edges;
163 myIsGeometryValid = InitTwoEdgesAngle (aComputedPlane);
165 if (myIsGeometryValid && !myIsPlaneCustom)
167 myPlane = aComputedPlane;
173 //=======================================================================
174 //function : SetMeasuredGeometry
176 //=======================================================================
177 void PrsDim_AngleDimension::SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
178 const gp_Pnt& theSecondPoint,
179 const gp_Pnt& theThirdPoint)
181 myFirstPoint = theFirstPoint;
182 myCenterPoint = theSecondPoint;
183 mySecondPoint = theThirdPoint;
184 myFirstShape = BRepLib_MakeVertex (myFirstPoint);
185 mySecondShape = BRepLib_MakeVertex (myCenterPoint);
186 myThirdShape = BRepLib_MakeVertex (mySecondPoint);
187 myGeometryType = GeometryType_Points;
188 myIsGeometryValid = IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
190 Standard_Boolean anIsSameLine = isSameLine (myFirstPoint, myCenterPoint, mySecondPoint);
191 if (myIsGeometryValid && !myIsPlaneCustom && !anIsSameLine)
199 //=======================================================================
200 //function : SetMeasuredGeometry
202 //=======================================================================
203 void PrsDim_AngleDimension::SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
204 const TopoDS_Vertex& theSecondVertex,
205 const TopoDS_Vertex& theThirdVertex)
207 myFirstShape = theFirstVertex;
208 mySecondShape = theSecondVertex;
209 myThirdShape = theThirdVertex;
210 myFirstPoint = BRep_Tool::Pnt (theFirstVertex);
211 myCenterPoint = BRep_Tool::Pnt (theSecondVertex);
212 mySecondPoint = BRep_Tool::Pnt (theThirdVertex);
213 myGeometryType = GeometryType_Points;
214 myIsGeometryValid = IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
216 Standard_Boolean anIsSameLine = isSameLine (myFirstPoint, myCenterPoint, mySecondPoint);
217 if (myIsGeometryValid && !myIsPlaneCustom && !anIsSameLine)
225 //=======================================================================
226 //function : SetMeasuredGeometry
228 //=======================================================================
229 void PrsDim_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theCone)
231 myFirstShape = theCone;
232 mySecondShape = TopoDS_Shape();
233 myThirdShape = TopoDS_Shape();
234 myGeometryType = GeometryType_Face;
235 myIsGeometryValid = InitConeAngle();
237 if (myIsGeometryValid && !myIsPlaneCustom)
245 //=======================================================================
246 //function : SetMeasuredGeometry
248 //=======================================================================
249 void PrsDim_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
250 const TopoDS_Face& theSecondFace)
252 myFirstShape = theFirstFace;
253 mySecondShape = theSecondFace;
254 myThirdShape = TopoDS_Shape();
255 myGeometryType = GeometryType_Faces;
256 myIsGeometryValid = InitTwoFacesAngle();
258 if (myIsGeometryValid && !myIsPlaneCustom)
266 //=======================================================================
267 //function : SetMeasuredGeometry
269 //=======================================================================
270 void PrsDim_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
271 const TopoDS_Face& theSecondFace,
272 const gp_Pnt& thePoint)
274 myFirstShape = theFirstFace;
275 mySecondShape = theSecondFace;
276 myThirdShape = TopoDS_Shape();
277 myGeometryType = GeometryType_Faces;
278 myIsGeometryValid = InitTwoFacesAngle (thePoint);
280 if (myIsGeometryValid && !myIsPlaneCustom)
288 //=======================================================================
291 //=======================================================================
292 void PrsDim_AngleDimension::Init()
294 SetType (PrsDim_TypeOfAngle_Interior);
295 SetArrowsVisibility (PrsDim_TypeOfAngleArrowVisibility_Both);
296 SetSpecialSymbol (THE_DEGREE_SYMBOL);
297 SetDisplaySpecialSymbol (PrsDim_DisplaySpecialSymbol_After);
301 //=======================================================================
302 //function: GetCenterOnArc
304 //=======================================================================
305 gp_Pnt PrsDim_AngleDimension::GetCenterOnArc (const gp_Pnt& theFirstAttach,
306 const gp_Pnt& theSecondAttach,
307 const gp_Pnt& theCenter) const
309 // construct plane where the circle and the arc are located
310 gce_MakePln aConstructPlane (theFirstAttach, theSecondAttach, theCenter);
311 if (!aConstructPlane.IsDone())
316 gp_Pln aPlane = aConstructPlane.Value();
317 // to have an exterior angle presentation, a plane for further constructed circle should be reversed
318 if (myType == PrsDim_TypeOfAngle_Exterior)
320 gp_Ax1 anAxis = aPlane.Axis();
321 gp_Dir aDir = anAxis.Direction();
323 aPlane.SetAxis(gp_Ax1(anAxis.Location(), aDir));
326 Standard_Real aRadius = theFirstAttach.Distance (theCenter);
328 // construct circle forming the arc
329 gce_MakeCirc aConstructCircle (theCenter, aPlane, aRadius);
330 if (!aConstructCircle.IsDone())
335 gp_Circ aCircle = aConstructCircle.Value();
337 // compute angle parameters of arc end-points on circle
338 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, theFirstAttach);
339 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, theSecondAttach);
340 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
342 return ElCLib::Value ((aParamBeg + aParamEnd) * 0.5, aCircle);
345 //=======================================================================
346 //function : GetNormalForMinAngle
348 //=======================================================================
349 gp_Dir PrsDim_AngleDimension::GetNormalForMinAngle() const
351 const gp_Dir& aNormal = myPlane.Axis().Direction();
352 gp_Dir aFirst (gp_Vec (myCenterPoint, myFirstPoint) );
353 gp_Dir aSecond (gp_Vec (myCenterPoint, mySecondPoint) );
355 return aFirst.AngleWithRef (aSecond, aNormal) < 0.0
360 //=======================================================================
362 //purpose : draws the arc between two attach points
363 //=======================================================================
364 void PrsDim_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
365 const gp_Pnt& theFirstAttach,
366 const gp_Pnt& theSecondAttach,
367 const gp_Pnt& theCenter,
368 const Standard_Real theRadius,
369 const Standard_Integer theMode)
371 gp_Pln aPlane (myCenterPoint, GetNormalForMinAngle());
373 // to have an exterior angle presentation, a plane for further constructed circle should be reversed
374 if (myType == PrsDim_TypeOfAngle_Exterior)
376 gp_Ax1 anAxis = aPlane.Axis();
377 gp_Dir aDir = anAxis.Direction();
379 aPlane.SetAxis(gp_Ax1(anAxis.Location(), aDir));
382 // construct circle forming the arc
383 gce_MakeCirc aConstructCircle (theCenter, aPlane, theRadius);
384 if (!aConstructCircle.IsDone())
389 gp_Circ aCircle = aConstructCircle.Value();
392 GC_MakeArcOfCircle aConstructArc (aCircle, theFirstAttach, theSecondAttach, Standard_True);
393 if (!aConstructArc.IsDone())
398 // generate points with specified deflection
399 const Handle(Geom_TrimmedCurve)& anArcCurve = aConstructArc.Value();
401 GeomAdaptor_Curve anArcAdaptor (anArcCurve, anArcCurve->FirstParameter(), anArcCurve->LastParameter());
403 // compute number of discretization elements in old-fanshioned way
404 gp_Vec aCenterToFirstVec (theCenter, theFirstAttach);
405 gp_Vec aCenterToSecondVec (theCenter, theSecondAttach);
406 Standard_Real anAngle = aCenterToFirstVec.Angle (aCenterToSecondVec);
407 if (myType == PrsDim_TypeOfAngle_Exterior)
408 anAngle = 2.0 * M_PI - anAngle;
409 // it sets 50 points on PI, and a part of points if angle is less
410 const Standard_Integer aNbPoints = Max (4, Standard_Integer (50.0 * anAngle / M_PI));
412 GCPnts_UniformAbscissa aMakePnts (anArcAdaptor, aNbPoints);
413 if (!aMakePnts.IsDone())
418 // init data arrays for graphical and selection primitives
419 Handle(Graphic3d_ArrayOfPolylines) aPrimSegments = new Graphic3d_ArrayOfPolylines (aNbPoints);
421 SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve();
423 // load data into arrays
424 for (Standard_Integer aPntIt = 1; aPntIt <= aMakePnts.NbPoints(); ++aPntIt)
426 gp_Pnt aPnt = anArcAdaptor.Value (aMakePnts.Parameter (aPntIt));
428 aPrimSegments->AddVertex (aPnt);
430 aSensitiveCurve.Append (aPnt);
433 // add display presentation
434 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All)
436 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True);
438 Handle(Graphic3d_AspectLine3d) aDimensionLineStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect();
439 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionLineStyle);
440 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
441 if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All)
443 Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False);
447 //=======================================================================
448 //function: DrawArcWithText
450 //=======================================================================
451 void PrsDim_AngleDimension::DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
452 const gp_Pnt& theFirstAttach,
453 const gp_Pnt& theSecondAttach,
454 const gp_Pnt& theCenter,
455 const TCollection_ExtendedString& theText,
456 const Standard_Real theTextWidth,
457 const Standard_Integer theMode,
458 const Standard_Integer theLabelPosition)
460 gp_Pln aPlane (myCenterPoint, GetNormalForMinAngle());
462 Standard_Real aRadius = theFirstAttach.Distance (myCenterPoint);
464 // construct circle forming the arc
465 gce_MakeCirc aConstructCircle (theCenter, aPlane, aRadius);
466 if (!aConstructCircle.IsDone())
471 gp_Circ aCircle = aConstructCircle.Value();
473 // compute angle parameters of arc end-points on circle
474 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, theFirstAttach);
475 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, theSecondAttach);
476 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
478 // middle point of arc parameter on circle
479 Standard_Real aParamMid = (aParamBeg + aParamEnd) * 0.5;
481 // add text graphical primitives
482 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
484 gp_Pnt aTextPos = ElCLib::Value (aParamMid, aCircle);
485 gp_Dir aTextDir = gce_MakeDir (theFirstAttach, theSecondAttach);
488 drawText (thePresentation,
495 if (theMode != ComputeMode_All && theMode != ComputeMode_Line)
500 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
502 Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center
503 && aDimensionAspect->IsText3d();
507 // compute gap for label as parameteric size of sector on circle segment
508 Standard_Real aSectorOfText = theTextWidth / aRadius;
509 Standard_Real aTextBegin = aParamMid - aSectorOfText * 0.5;
510 Standard_Real aTextEnd = aParamMid + aSectorOfText * 0.5;
511 gp_Pnt aTextPntBeg = ElCLib::Value (aTextBegin, aCircle);
512 gp_Pnt aTextPntEnd = ElCLib::Value (aTextEnd, aCircle);
515 if (aTextBegin > aParamBeg)
517 DrawArc (thePresentation, theFirstAttach, aTextPntBeg, theCenter, aRadius, theMode);
519 if (aTextEnd < aParamEnd)
521 DrawArc (thePresentation, aTextPntEnd, theSecondAttach, theCenter, aRadius, theMode);
526 DrawArc (thePresentation, theFirstAttach, theSecondAttach, theCenter, aRadius, theMode);
530 //=======================================================================
531 //function : CheckPlane
533 //=======================================================================
534 Standard_Boolean PrsDim_AngleDimension::CheckPlane (const gp_Pln& thePlane)const
536 if (!thePlane.Contains (myFirstPoint, Precision::Confusion()) &&
537 !thePlane.Contains (mySecondPoint, Precision::Confusion()) &&
538 !thePlane.Contains (myCenterPoint, Precision::Confusion()))
540 return Standard_False;
543 return Standard_True;
546 //=======================================================================
547 //function : ComputePlane
549 //=======================================================================
550 void PrsDim_AngleDimension::ComputePlane()
552 if (!myIsGeometryValid)
557 // Compute working plane so that Y axis is codirectional
558 // with Y axis of text coordinate system (necessary for text alignment)
559 gp_Vec aFirstVec = gp_Vec (myCenterPoint, myFirstPoint);
560 gp_Vec aSecondVec = gp_Vec (myCenterPoint, mySecondPoint);
561 gp_Vec aDirectionN = aSecondVec ^ aFirstVec;
562 gp_Vec aDirectionY = aFirstVec + aSecondVec;
563 gp_Vec aDirectionX = aDirectionY ^ aDirectionN;
565 myPlane = gp_Pln (gp_Ax3 (myCenterPoint, gp_Dir (aDirectionN), gp_Dir (aDirectionX)));
568 //=======================================================================
569 //function : GetModelUnits
571 //=======================================================================
572 const TCollection_AsciiString& PrsDim_AngleDimension::GetModelUnits() const
574 return myDrawer->DimAngleModelUnits();
577 //=======================================================================
578 //function : GetDisplayUnits
580 //=======================================================================
581 const TCollection_AsciiString& PrsDim_AngleDimension::GetDisplayUnits() const
583 return myDrawer->DimAngleDisplayUnits();
586 //=======================================================================
587 //function : SetModelUnits
589 //=======================================================================
590 void PrsDim_AngleDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
592 myDrawer->SetDimAngleModelUnits (theUnits);
595 //=======================================================================
596 //function : SetDisplayUnits
598 //=======================================================================
599 void PrsDim_AngleDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
601 myDrawer->SetDimAngleDisplayUnits (theUnits);
604 //=======================================================================
605 //function : ComputeValue
607 //=======================================================================
608 Standard_Real PrsDim_AngleDimension::ComputeValue() const
615 gp_Vec aVec1 (myCenterPoint, myFirstPoint);
616 gp_Vec aVec2 (myCenterPoint, mySecondPoint);
618 Standard_Real anAngle = aVec1.AngleWithRef (aVec2, GetNormalForMinAngle());
620 return anAngle > 0.0 ? anAngle : (2.0 * M_PI + anAngle);
623 //=======================================================================
625 //purpose : Having three gp_Pnt points compute presentation
626 //=======================================================================
627 void PrsDim_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
628 const Handle(Prs3d_Presentation)& thePresentation,
629 const Standard_Integer theMode)
631 mySelectionGeom.Clear (theMode);
638 // Parameters for presentation
639 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
641 Prs3d_Root::CurrentGroup(thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
643 Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length();
645 // prepare label string and compute its geometrical width
646 Standard_Real aLabelWidth;
647 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
649 // add margins to label width
650 if (aDimensionAspect->IsText3d())
652 aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
655 // Get parameters from aspect or adjust it according with custom text position
656 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
657 Prs3d_DimensionTextHorizontalPosition aHorisontalTextPos = aDimensionAspect->TextHorizontalPosition();
659 if (IsTextPositionCustom())
661 AdjustParameters (myFixedTextPosition,anExtensionSize, aHorisontalTextPos, myFlyout);
664 // Handle user-defined and automatic arrow placement
665 Standard_Boolean isArrowsExternal = Standard_False;
666 Standard_Integer aLabelPosition = LabelPosition_None;
668 FitTextAlignment (aHorisontalTextPos, aLabelPosition, isArrowsExternal);
670 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
671 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
673 //Arrows positions and directions
674 gp_Vec aWorkingPlaneDir (GetNormalForMinAngle());
676 gp_Dir aFirstExtensionDir = aWorkingPlaneDir.Reversed() ^ gp_Vec (myCenterPoint, aFirstAttach);
677 gp_Dir aSecondExtensionDir = aWorkingPlaneDir ^ gp_Vec (myCenterPoint, aSecondAttach);
679 gp_Vec aFirstArrowVec = gp_Vec (aFirstExtensionDir) * anArrowLength;
680 gp_Vec aSecondArrowVec = gp_Vec (aSecondExtensionDir) * anArrowLength;
682 if (isArrowsExternal)
684 aFirstArrowVec.Reverse();
685 aSecondArrowVec.Reverse();
688 gp_Pnt aFirstArrowBegin (0.0, 0.0, 0.0);
689 gp_Pnt aFirstArrowEnd (0.0, 0.0, 0.0);
690 gp_Pnt aSecondArrowBegin (0.0, 0.0, 0.0);
691 gp_Pnt aSecondArrowEnd (0.0, 0.0, 0.0);
693 aFirstArrowBegin = aFirstAttach;
694 aSecondArrowBegin = aSecondAttach;
695 aFirstArrowEnd = aFirstAttach.Translated (-aFirstArrowVec);
696 aSecondArrowEnd = aSecondAttach.Translated (-aSecondArrowVec);
698 // Group1: stenciling text and the angle dimension arc
699 Prs3d_Root::NewGroup (thePresentation);
701 Standard_Integer aHPosition = aLabelPosition & LabelPosition_HMask;
706 case LabelPosition_HCenter :
708 Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center
709 && aDimensionAspect->IsText3d();
713 DrawArcWithText (thePresentation,
724 // compute text primitives
725 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
727 gp_Vec aDimensionDir (aFirstAttach, aSecondAttach);
728 gp_Pnt aTextPos = IsTextPositionCustom() ? myFixedTextPosition
729 : GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
730 gp_Dir aTextDir = aDimensionDir;
732 drawText (thePresentation,
739 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
741 DrawArc (thePresentation,
742 (isArrowsExternal || !isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_First)) ? aFirstAttach : aFirstArrowEnd,
743 (isArrowsExternal || !isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_Second)) ? aSecondAttach : aSecondArrowEnd,
751 case LabelPosition_Left :
753 DrawExtension (thePresentation,
755 (isArrowsExternal && isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_First)) ? aFirstArrowEnd : aFirstAttach,
764 case LabelPosition_Right :
766 DrawExtension (thePresentation,
768 (isArrowsExternal && isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_Second)) ? aSecondArrowEnd : aSecondAttach,
778 // dimension arc without text
779 if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && aHPosition != LabelPosition_HCenter)
781 Prs3d_Root::NewGroup (thePresentation);
783 DrawArc (thePresentation,
784 (isArrowsExternal || !isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_First)) ? aFirstAttach : aFirstArrowEnd,
785 (isArrowsExternal || !isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_Second)) ? aSecondAttach : aSecondArrowEnd,
791 // arrows and arrow extensions
792 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
794 Prs3d_Root::NewGroup (thePresentation);
796 if (isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_First))
797 DrawArrow (thePresentation, aFirstArrowBegin, gp_Dir (aFirstArrowVec));
798 if (isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_Second))
799 DrawArrow (thePresentation, aSecondArrowBegin, gp_Dir (aSecondArrowVec));
802 if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && isArrowsExternal)
804 Prs3d_Root::NewGroup (thePresentation);
806 if (aHPosition != LabelPosition_Left && isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_First))
808 DrawExtension (thePresentation,
809 aDimensionAspect->ArrowTailSize(),
812 THE_EMPTY_LABEL_STRING,
813 THE_EMPTY_LABEL_WIDTH,
818 if (aHPosition != LabelPosition_Right && isArrowVisible(PrsDim_TypeOfAngleArrowVisibility_Second))
820 DrawExtension (thePresentation,
821 aDimensionAspect->ArrowTailSize(),
824 THE_EMPTY_LABEL_STRING,
825 THE_EMPTY_LABEL_WIDTH,
832 if (theMode == ComputeMode_All)
834 Prs3d_Root::NewGroup (thePresentation);
836 Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (4);
837 aPrimSegments->AddVertex (myCenterPoint);
838 aPrimSegments->AddVertex (aFirstAttach);
839 aPrimSegments->AddVertex (myCenterPoint);
840 aPrimSegments->AddVertex (aSecondAttach);
842 Handle(Graphic3d_AspectLine3d) aFlyoutStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect();
843 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aFlyoutStyle);
844 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
847 mySelectionGeom.IsComputed = Standard_True;
850 //=======================================================================
851 //function : ComputeFlyoutSelection
852 //purpose : computes selection for flyouts
853 //=======================================================================
854 void PrsDim_AngleDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
855 const Handle(SelectMgr_EntityOwner)& theOwner)
857 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
858 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
860 Handle(Select3D_SensitiveGroup) aSensitiveEntity = new Select3D_SensitiveGroup (theOwner);
861 aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, myCenterPoint, aFirstAttach));
862 aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, myCenterPoint, aSecondAttach));
864 theSelection->Add (aSensitiveEntity);
867 //=======================================================================
868 //function : InitTwoEdgesAngle
870 //=======================================================================
871 Standard_Boolean PrsDim_AngleDimension::InitTwoEdgesAngle (gp_Pln& theComputedPlane)
873 TopoDS_Edge aFirstEdge = TopoDS::Edge (myFirstShape);
874 TopoDS_Edge aSecondEdge = TopoDS::Edge (mySecondShape);
876 BRepAdaptor_Curve aMakeFirstLine (aFirstEdge);
877 BRepAdaptor_Curve aMakeSecondLine (aSecondEdge);
879 if (aMakeFirstLine.GetType() != GeomAbs_Line || aMakeSecondLine.GetType() != GeomAbs_Line)
881 return Standard_False;
884 Handle(Geom_Line) aFirstLine = new Geom_Line (aMakeFirstLine.Line());
885 Handle(Geom_Line) aSecondLine = new Geom_Line (aMakeSecondLine.Line());
887 gp_Lin aFirstLin = aFirstLine->Lin();
888 gp_Lin aSecondLin = aSecondLine->Lin();
890 Standard_Boolean isParallelLines = aFirstLin.Direction().IsParallel (aSecondLin.Direction(), Precision::Angular());
892 theComputedPlane = isParallelLines ? gp_Pln(gp::XOY())
893 : gp_Pln (aSecondLin.Location(), gp_Vec (aFirstLin.Direction()) ^ gp_Vec (aSecondLin.Direction()));
895 // Compute geometry for this plane and edges
896 Standard_Boolean isInfinite1,isInfinite2;
897 gp_Pnt aFirstPoint1, aLastPoint1, aFirstPoint2, aLastPoint2;
898 Handle(Geom_Curve) aFirstCurve = aFirstLine, aSecondCurve = aSecondLine;
899 if (!PrsDim::ComputeGeometry (aFirstEdge, aSecondEdge,
900 aFirstCurve, aSecondCurve,
901 aFirstPoint1, aLastPoint1,
902 aFirstPoint2, aLastPoint2,
903 isInfinite1, isInfinite2))
905 return Standard_False;
908 Standard_Boolean isSameLines = aFirstLin.Direction().IsEqual (aSecondLin.Direction(), Precision::Angular())
909 && aFirstLin.Location().IsEqual (aSecondLin.Location(),Precision::Confusion());
911 // It can be the same gp_Lin geometry but the different begin and end parameters
912 Standard_Boolean isSameEdges =
913 (aFirstPoint1.IsEqual (aFirstPoint2, Precision::Confusion()) && aLastPoint1.IsEqual (aLastPoint2, Precision::Confusion()))
914 || (aFirstPoint1.IsEqual (aLastPoint2, Precision::Confusion()) && aLastPoint1.IsEqual (aFirstPoint2, Precision::Confusion()));
918 // Zero angle, it could not handle this geometry
919 if (isSameLines && isSameEdges)
921 return Standard_False;
924 // Handle the case of Pi angle
925 const Standard_Real aParam11 = ElCLib::Parameter (aFirstLin, aFirstPoint1);
926 const Standard_Real aParam12 = ElCLib::Parameter (aFirstLin, aLastPoint1);
927 const Standard_Real aParam21 = ElCLib::Parameter (aFirstLin, aFirstPoint2);
928 const Standard_Real aParam22 = ElCLib::Parameter (aFirstLin, aLastPoint2);
929 myCenterPoint = ElCLib::Value ( (Min (aParam11, aParam12) + Max (aParam21, aParam22)) * 0.5, aFirstLin);
930 myFirstPoint = myCenterPoint.Translated (gp_Vec (aFirstLin.Direction()) * Abs (GetFlyout()));
931 mySecondPoint = myCenterPoint.XYZ() + (aFirstLin.Direction().IsEqual (aSecondLin.Direction(), Precision::Angular())
932 ? aFirstLin.Direction().Reversed().XYZ() * Abs (GetFlyout())
933 : aSecondLin.Direction().XYZ() * Abs (GetFlyout()));
938 gp_Lin2d aFirstLin2d = ProjLib::Project (theComputedPlane, aFirstLin);
939 gp_Lin2d aSecondLin2d = ProjLib::Project (theComputedPlane, aSecondLin);
941 IntAna2d_AnaIntersection anInt2d (aFirstLin2d, aSecondLin2d);
942 gp_Pnt2d anIntersectPoint;
943 if (!anInt2d.IsDone() || anInt2d.IsEmpty())
945 return Standard_False;
948 anIntersectPoint = gp_Pnt2d (anInt2d.Point(1).Value());
949 myCenterPoint = ElCLib::To3d (theComputedPlane.Position().Ax2(), anIntersectPoint);
951 if (isInfinite1 || isInfinite2)
953 myFirstPoint = myCenterPoint.Translated (gp_Vec (aFirstLin.Direction()) * Abs (GetFlyout()));
954 mySecondPoint = myCenterPoint.Translated (gp_Vec (aSecondLin.Direction()) * Abs (GetFlyout()));
956 return IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
960 // | <- dimension should be here
962 myFirstPoint = myCenterPoint.Distance (aFirstPoint1) > myCenterPoint.Distance (aLastPoint1)
966 mySecondPoint = myCenterPoint.Distance (aFirstPoint2) > myCenterPoint.Distance (aLastPoint2)
971 return IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
974 //=======================================================================
975 //function : InitTwoFacesAngle
976 //purpose : initialization of angle dimension between two faces
977 //=======================================================================
978 Standard_Boolean PrsDim_AngleDimension::InitTwoFacesAngle()
980 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
981 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
983 gp_Dir aFirstDir, aSecondDir;
984 gp_Pln aFirstPln, aSecondPln;
985 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
986 PrsDim_KindOfSurface aFirstSurfType, aSecondSurfType;
987 Standard_Real aFirstOffset, aSecondOffset;
989 PrsDim::GetPlaneFromFace (aFirstFace, aFirstPln,
990 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
992 PrsDim::GetPlaneFromFace (aSecondFace, aSecondPln,
993 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
995 if (aFirstSurfType == PrsDim_KOS_Plane && aSecondSurfType == PrsDim_KOS_Plane)
998 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (aFirstBasisSurf);
999 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (aSecondBasisSurf);
1000 return PrsDim::InitAngleBetweenPlanarFaces (aFirstFace, aSecondFace,
1001 myCenterPoint, myFirstPoint, mySecondPoint)
1002 && IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
1006 // Curvilinear faces angle
1007 return PrsDim::InitAngleBetweenCurvilinearFaces (aFirstFace, aSecondFace,
1008 aFirstSurfType, aSecondSurfType,
1009 myCenterPoint, myFirstPoint, mySecondPoint)
1010 && IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
1014 //=======================================================================
1015 //function : InitTwoFacesAngle
1016 //purpose : initialization of angle dimension between two faces
1017 //=======================================================================
1018 Standard_Boolean PrsDim_AngleDimension::InitTwoFacesAngle (const gp_Pnt& thePointOnFirstFace)
1020 TopoDS_Face aFirstFace = TopoDS::Face (myFirstShape);
1021 TopoDS_Face aSecondFace = TopoDS::Face (mySecondShape);
1023 gp_Dir aFirstDir, aSecondDir;
1024 gp_Pln aFirstPln, aSecondPln;
1025 Handle(Geom_Surface) aFirstBasisSurf, aSecondBasisSurf;
1026 PrsDim_KindOfSurface aFirstSurfType, aSecondSurfType;
1027 Standard_Real aFirstOffset, aSecondOffset;
1029 PrsDim::GetPlaneFromFace (aFirstFace, aFirstPln,
1030 aFirstBasisSurf,aFirstSurfType,aFirstOffset);
1032 PrsDim::GetPlaneFromFace (aSecondFace, aSecondPln,
1033 aSecondBasisSurf, aSecondSurfType, aSecondOffset);
1035 myFirstPoint = thePointOnFirstFace;
1036 if (aFirstSurfType == PrsDim_KOS_Plane && aSecondSurfType == PrsDim_KOS_Plane)
1038 //Planar faces angle
1039 Handle(Geom_Plane) aFirstPlane = Handle(Geom_Plane)::DownCast (aFirstBasisSurf);
1040 Handle(Geom_Plane) aSecondPlane = Handle(Geom_Plane)::DownCast (aSecondBasisSurf);
1041 return PrsDim::InitAngleBetweenPlanarFaces (aFirstFace, aSecondFace,
1042 myCenterPoint, myFirstPoint, mySecondPoint,
1044 && IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
1048 // Curvilinear faces angle
1049 return PrsDim::InitAngleBetweenCurvilinearFaces (aFirstFace, aSecondFace,
1050 aFirstSurfType, aSecondSurfType,
1051 myCenterPoint, myFirstPoint, mySecondPoint,
1053 && IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
1057 //=======================================================================
1058 //function : InitConeAngle
1059 //purpose : initialization of the cone angle
1060 //=======================================================================
1061 Standard_Boolean PrsDim_AngleDimension::InitConeAngle()
1063 if (myFirstShape.IsNull())
1065 return Standard_False;
1068 TopoDS_Face aConeShape = TopoDS::Face (myFirstShape);
1072 // A surface from the Face
1073 Handle(Geom_Surface) aSurf;
1074 Handle(Geom_OffsetSurface) aOffsetSurf;
1075 Handle(Geom_ConicalSurface) aConicalSurf;
1076 Handle(Geom_SurfaceOfRevolution) aRevSurf;
1077 Handle(Geom_Line) aLine;
1078 BRepAdaptor_Surface aConeAdaptor (aConeShape);
1080 PrsDim_KindOfSurface aSurfType;
1081 Standard_Real anOffset = 0.;
1082 Handle(Standard_Type) aType;
1084 const Standard_Real aMaxV = aConeAdaptor.FirstVParameter();
1085 const Standard_Real aMinV = aConeAdaptor.LastVParameter();
1086 PrsDim::GetPlaneFromFace (aConeShape, aPln, aSurf, aSurfType, anOffset);
1087 if (aSurfType == PrsDim_KOS_Revolution)
1089 // Surface of revolution
1090 aRevSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(aSurf);
1091 gp_Lin aLin (aRevSurf->Axis());
1092 Handle(Geom_Curve) aBasisCurve = aRevSurf->BasisCurve();
1093 //Must be a part of line (basis curve should be linear)
1094 if (aBasisCurve ->DynamicType() != STANDARD_TYPE(Geom_Line))
1095 return Standard_False;
1097 gp_Pnt aFirst1 = aConeAdaptor.Value (0., aMinV);
1098 gp_Pnt aLast1 = aConeAdaptor.Value (0., aMaxV);
1099 gp_Vec aVec1 (aFirst1, aLast1);
1101 //Projection <aFirst> on <aLin>
1102 gp_Pnt aFirst2 = ElCLib::Value (ElCLib::Parameter (aLin, aFirst1), aLin);
1103 // Projection <aLast> on <aLin>
1104 gp_Pnt aLast2 = ElCLib::Value (ElCLib::Parameter (aLin, aLast1), aLin);
1106 gp_Vec aVec2 (aFirst2, aLast2);
1108 // Check if two parts of revolution are parallel (it's a cylinder) or normal (it's a circle).
1109 if (aVec1.IsParallel (aVec2, Precision::Angular())
1110 || aVec1.IsNormal (aVec2,Precision::Angular()))
1111 return Standard_False;
1113 gce_MakeCone aMkCone (aRevSurf->Axis(), aFirst1, aLast1);
1114 aCone = aMkCone.Value();
1115 myCenterPoint = aCone.Apex();
1119 aType = aSurf->DynamicType();
1120 if (aType == STANDARD_TYPE(Geom_OffsetSurface) || anOffset > 0.01)
1123 aOffsetSurf = new Geom_OffsetSurface (aSurf, anOffset);
1124 aSurf = aOffsetSurf->Surface();
1125 BRepBuilderAPI_MakeFace aMkFace(aSurf, Precision::Confusion());
1127 if (!aMkFace.IsDone())
1128 return Standard_False;
1129 aConeAdaptor.Initialize (aMkFace.Face());
1131 aCone = aConeAdaptor.Cone();
1132 aConicalSurf = Handle(Geom_ConicalSurface)::DownCast (aSurf);
1133 myCenterPoint = aConicalSurf->Apex();
1136 // A circle where the angle is drawn
1137 Handle(Geom_Curve) aCurve;
1138 Standard_Real aMidV = ( aMinV + aMaxV ) / 2.5;
1139 aCurve = aSurf->VIso (aMidV);
1140 aCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
1142 aCurve = aSurf->VIso(aMaxV);
1143 gp_Circ aCircVmax = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
1144 aCurve = aSurf->VIso(aMinV);
1145 gp_Circ aCircVmin = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
1147 if (aCircVmax.Radius() < aCircVmin.Radius())
1149 gp_Circ aTmpCirc = aCircVmax;
1150 aCircVmax = aCircVmin;
1151 aCircVmin = aTmpCirc;
1154 myFirstPoint = ElCLib::Value (0, aCircle);
1155 mySecondPoint = ElCLib::Value (M_PI, aCircle);
1156 return Standard_True;
1159 //=======================================================================
1160 //function : IsValidPoints
1162 //=======================================================================
1163 Standard_Boolean PrsDim_AngleDimension::IsValidPoints (const gp_Pnt& theFirstPoint,
1164 const gp_Pnt& theCenterPoint,
1165 const gp_Pnt& theSecondPoint) const
1167 return theFirstPoint.Distance (theCenterPoint) > Precision::Confusion()
1168 && theSecondPoint.Distance (theCenterPoint) > Precision::Confusion()
1169 && gp_Vec (theCenterPoint, theFirstPoint).Angle (
1170 gp_Vec (theCenterPoint, theSecondPoint)) > Precision::Angular();
1173 //=======================================================================
1174 //function : isArrowVisible
1175 //purpose : compares given and internal arrows types, returns true if the the type should be shown
1176 //=======================================================================
1177 Standard_Boolean PrsDim_AngleDimension::isArrowVisible(const PrsDim_TypeOfAngleArrowVisibility theArrowType) const
1179 switch (theArrowType)
1181 case PrsDim_TypeOfAngleArrowVisibility_Both:
1182 return myArrowsVisibility == PrsDim_TypeOfAngleArrowVisibility_Both;
1183 case PrsDim_TypeOfAngleArrowVisibility_First:
1184 return myArrowsVisibility == PrsDim_TypeOfAngleArrowVisibility_Both || myArrowsVisibility == PrsDim_TypeOfAngleArrowVisibility_First;
1185 case PrsDim_TypeOfAngleArrowVisibility_Second:
1186 return myArrowsVisibility == PrsDim_TypeOfAngleArrowVisibility_Both || myArrowsVisibility == PrsDim_TypeOfAngleArrowVisibility_Second;
1187 case PrsDim_TypeOfAngleArrowVisibility_None:
1193 //=======================================================================
1194 //function : GetTextPosition
1196 //=======================================================================
1197 gp_Pnt PrsDim_AngleDimension::GetTextPosition() const
1201 return gp::Origin();
1204 if (IsTextPositionCustom())
1206 return myFixedTextPosition;
1209 // Counts text position according to the dimension parameters
1210 gp_Pnt aTextPosition (gp::Origin());
1212 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1214 // Prepare label string and compute its geometrical width
1215 Standard_Real aLabelWidth;
1216 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
1218 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
1219 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
1221 // Handle user-defined and automatic arrow placement
1222 Standard_Boolean isArrowsExternal = Standard_False;
1223 Standard_Integer aLabelPosition = LabelPosition_None;
1224 FitTextAlignment (aDimensionAspect->TextHorizontalPosition(),
1225 aLabelPosition, isArrowsExternal);
1227 // Get text position
1228 switch (aLabelPosition & LabelPosition_HMask)
1230 case LabelPosition_HCenter:
1232 aTextPosition = GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
1235 case LabelPosition_Left:
1237 gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
1238 gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aFirstAttach);
1239 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
1240 Standard_Real anOffset = isArrowsExternal
1241 ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
1243 gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * -anOffset;
1244 aTextPosition = aFirstAttach.Translated (anExtensionVec);
1247 case LabelPosition_Right:
1249 gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
1250 gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aSecondAttach);
1251 Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
1252 Standard_Real anOffset = isArrowsExternal
1253 ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
1255 gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * anOffset;
1256 aTextPosition = aSecondAttach.Translated (anExtensionVec);
1261 return aTextPosition;
1264 //=======================================================================
1265 //function : SetTextPosition
1267 //=======================================================================
1268 void PrsDim_AngleDimension::SetTextPosition (const gp_Pnt& theTextPos)
1275 // The text position point for angle dimension should belong to the working plane.
1276 if (!GetPlane().Contains (theTextPos, Precision::Confusion()))
1278 throw Standard_ProgramError("The text position point for angle dimension doesn't belong to the working plane.");
1281 myIsTextPositionFixed = Standard_True;
1282 myFixedTextPosition = theTextPos;
1285 //=======================================================================
1286 //function : AdjustParameters
1288 //=======================================================================
1289 void PrsDim_AngleDimension::AdjustParameters (const gp_Pnt& theTextPos,
1290 Standard_Real& theExtensionSize,
1291 Prs3d_DimensionTextHorizontalPosition& theAlignment,
1292 Standard_Real& theFlyout) const
1294 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1295 Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length();
1297 // Build circle with radius that is equal to distance from text position to the center point.
1298 Standard_Real aRadius = gp_Vec (myCenterPoint, theTextPos).Magnitude();
1300 // Set attach points in positive direction of the flyout.
1301 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * aRadius);
1302 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * aRadius);
1304 gce_MakeCirc aConstructCircle (myCenterPoint, GetPlane(), aRadius);
1305 if (!aConstructCircle.IsDone())
1309 gp_Circ aCircle = aConstructCircle.Value();
1312 theExtensionSize = aDimensionAspect->ArrowAspect()->Length();
1313 theAlignment = Prs3d_DTHP_Center;
1315 Standard_Real aParamBeg = ElCLib::Parameter (aCircle, aFirstAttach);
1316 Standard_Real aParamEnd = ElCLib::Parameter (aCircle, aSecondAttach);
1317 if (aParamEnd < aParamBeg)
1319 Standard_Real aParam = aParamEnd;
1320 aParamEnd = aParamBeg;
1324 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
1325 Standard_Real aTextPar = ElCLib::Parameter (aCircle , theTextPos);
1327 // Horizontal center
1328 if (aTextPar > aParamBeg && aTextPar < aParamEnd)
1330 theFlyout = aRadius;
1336 ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
1338 if (aTextPar > aParamBeg && aTextPar < aParamEnd)
1340 theFlyout = -aRadius;
1344 // Text on the extensions
1345 gp_Lin aFirstLine = gce_MakeLin (myCenterPoint, myFirstPoint);
1346 gp_Lin aSecondLine = gce_MakeLin (myCenterPoint, mySecondPoint);
1347 gp_Pnt aFirstTextProj = PrsDim::Nearest (aFirstLine, theTextPos);
1348 gp_Pnt aSecondTextProj = PrsDim::Nearest (aSecondLine, theTextPos);
1349 Standard_Real aFirstDist = aFirstTextProj.Distance (theTextPos);
1350 Standard_Real aSecondDist = aSecondTextProj.Distance (theTextPos);
1352 if (aFirstDist <= aSecondDist)
1354 aRadius = myCenterPoint.Distance (aFirstTextProj);
1355 Standard_Real aNewExtensionSize = aFirstDist - anArrowLength;
1356 theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
1358 theAlignment = Prs3d_DTHP_Left;
1360 gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, myFirstPoint).Normalized().Scaled (aRadius);
1362 theFlyout = aFirstTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
1363 ? -aRadius : aRadius;
1367 aRadius = myCenterPoint.Distance (aSecondTextProj);
1369 Standard_Real aNewExtensionSize = aSecondDist - anArrowLength;
1371 theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
1373 theAlignment = Prs3d_DTHP_Right;
1375 gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, mySecondPoint).Normalized().Scaled (aRadius);
1377 theFlyout = aSecondTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
1378 ? -aRadius : aRadius;
1382 //=======================================================================
1383 //function : FitTextAlignment
1385 //=======================================================================
1386 void PrsDim_AngleDimension::FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
1387 Standard_Integer& theLabelPosition,
1388 Standard_Boolean& theIsArrowsExternal) const
1390 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
1392 Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length();
1394 // Prepare label string and compute its geometrical width
1395 Standard_Real aLabelWidth;
1396 TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
1398 // add margins to label width
1399 if (aDimensionAspect->IsText3d())
1401 aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
1404 gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
1405 gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
1407 // Handle user-defined and automatic arrow placement
1408 switch (aDimensionAspect->ArrowOrientation())
1410 case Prs3d_DAO_External: theIsArrowsExternal = true; break;
1411 case Prs3d_DAO_Internal: theIsArrowsExternal = false; break;
1414 gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
1415 Standard_Real aDimensionWidth = anAttachVector.Magnitude();
1417 // Add margin to ensure a small tail between text and arrow
1418 Standard_Real anArrowMargin = aDimensionAspect->IsText3d()
1419 ? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN
1422 Standard_Real anArrowsWidth = (anArrowLength + anArrowMargin) * 2.0;
1424 theIsArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth;
1429 // Handle user-defined and automatic text placement
1430 switch (theHorizontalTextPos)
1432 case Prs3d_DTHP_Left : theLabelPosition |= LabelPosition_Left; break;
1433 case Prs3d_DTHP_Right : theLabelPosition |= LabelPosition_Right; break;
1434 case Prs3d_DTHP_Center: theLabelPosition |= LabelPosition_HCenter; break;
1435 case Prs3d_DTHP_Fit:
1437 gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
1438 Standard_Real aDimensionWidth = anAttachVector.Magnitude();
1439 Standard_Real anArrowsWidth = anArrowLength * 2.0;
1440 Standard_Real aContentWidth = theIsArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth;
1442 theLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter;
1447 switch (aDimensionAspect->TextVerticalPosition())
1449 case Prs3d_DTVP_Above : theLabelPosition |= LabelPosition_Above; break;
1450 case Prs3d_DTVP_Below : theLabelPosition |= LabelPosition_Below; break;
1451 case Prs3d_DTVP_Center : theLabelPosition |= LabelPosition_VCenter; break;