1 // Created on: 1996-12-05
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2013 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_LengthDimension.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRepAdaptor_Curve.hxx>
22 #include <BRepExtrema_DistShapeShape.hxx>
23 #include <BRepLib_MakeVertex.hxx>
24 #include <BRepTopAdaptor_FClass2d.hxx>
25 #include <BRepTools.hxx>
28 #include <gce_MakeDir.hxx>
29 #include <gce_MakePln.hxx>
30 #include <Geom_TrimmedCurve.hxx>
31 #include <GeomAPI_ExtremaCurveCurve.hxx>
32 #include <GeomAPI_ExtremaSurfaceSurface.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom_Line.hxx>
36 #include <TopExp_Explorer.hxx>
38 IMPLEMENT_STANDARD_RTTIEXT(PrsDim_LengthDimension, PrsDim_Dimension)
40 //=======================================================================
41 //function : Constructor
42 //purpose : Dimension between two faces
43 //=======================================================================
44 PrsDim_LengthDimension::PrsDim_LengthDimension (const TopoDS_Face& theFirstFace,
45 const TopoDS_Face& theSecondFace)
46 : PrsDim_Dimension (PrsDim_KOD_LENGTH),
47 myHasCustomDirection (Standard_False)
49 SetMeasuredGeometry (theFirstFace, theSecondFace);
53 //=======================================================================
54 //function : Constructor
55 //purpose : Dimension between two shape
56 //=======================================================================
57 PrsDim_LengthDimension::PrsDim_LengthDimension (const TopoDS_Face& theFace,
58 const TopoDS_Edge& theEdge)
59 : PrsDim_Dimension (PrsDim_KOD_LENGTH),
60 myHasCustomDirection (Standard_False)
62 SetMeasuredGeometry (theFace, theEdge);
66 //=======================================================================
67 //function : Constructor
68 //purpose : Dimension between two points
69 //=======================================================================
70 PrsDim_LengthDimension::PrsDim_LengthDimension (const gp_Pnt& theFirstPoint,
71 const gp_Pnt& theSecondPoint,
72 const gp_Pln& thePlane)
73 : PrsDim_Dimension (PrsDim_KOD_LENGTH),
74 myHasCustomDirection (Standard_False)
76 SetMeasuredGeometry (theFirstPoint, theSecondPoint, thePlane);
80 //=======================================================================
81 //function : Constructor
82 //purpose : Dimension between two shape
83 //=======================================================================
84 PrsDim_LengthDimension::PrsDim_LengthDimension (const TopoDS_Shape& theFirstShape,
85 const TopoDS_Shape& theSecondShape,
86 const gp_Pln& thePlane)
87 : PrsDim_Dimension (PrsDim_KOD_LENGTH),
88 myHasCustomDirection (Standard_False)
90 SetCustomPlane (thePlane);
91 SetMeasuredShapes (theFirstShape, theSecondShape);
95 //=======================================================================
96 //function : Constructor
97 //purpose : Dimension of one edge
98 //=======================================================================
99 PrsDim_LengthDimension::PrsDim_LengthDimension (const TopoDS_Edge& theEdge,
100 const gp_Pln& thePlane)
101 : PrsDim_Dimension (PrsDim_KOD_LENGTH),
102 myHasCustomDirection (Standard_False)
104 SetMeasuredGeometry (theEdge, thePlane);
108 //=======================================================================
109 //function : SetMeasuredGeometry
111 //=======================================================================
112 void PrsDim_LengthDimension::SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
113 const gp_Pnt& theSecondPoint,
114 const gp_Pln& thePlane)
116 myFirstPoint = theFirstPoint;
117 mySecondPoint = theSecondPoint;
118 myFirstShape = BRepLib_MakeVertex (myFirstPoint);
119 mySecondShape = BRepLib_MakeVertex (mySecondPoint);
120 myGeometryType = GeometryType_Points;
121 SetCustomPlane (thePlane);
122 myIsGeometryValid = IsValidPoints (theFirstPoint, theSecondPoint);
127 //=======================================================================
128 //function : SetMeasuredGeometry
130 //=======================================================================
131 void PrsDim_LengthDimension::SetMeasuredGeometry (const TopoDS_Edge& theEdge,
132 const gp_Pln& thePlane)
134 myFirstShape = theEdge;
135 mySecondShape = TopoDS_Shape();
136 myGeometryType = GeometryType_Edge;
137 SetCustomPlane (thePlane);
138 myIsGeometryValid = InitOneShapePoints (myFirstShape);
143 //=======================================================================
144 //function : SetMeasuredGeometry
146 //=======================================================================
147 void PrsDim_LengthDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
148 const TopoDS_Face& theSecondFace)
150 SetMeasuredShapes (theFirstFace, theSecondFace);
153 //=======================================================================
154 //function : SetMeasuredGeometry
156 //=======================================================================
157 void PrsDim_LengthDimension::SetMeasuredGeometry (const TopoDS_Face& theFace,
158 const TopoDS_Edge& theEdge)
160 SetMeasuredShapes (theFace, theEdge);
163 //=======================================================================
164 //function : SetMeasuredShapes
166 //=======================================================================
167 void PrsDim_LengthDimension::SetMeasuredShapes (const TopoDS_Shape& theFirstShape,
168 const TopoDS_Shape& theSecondShape)
170 gp_Pln aComputedPlane;
171 Standard_Boolean isPlaneReturned = Standard_False;
173 myFirstShape = theFirstShape;
174 mySecondShape = theSecondShape;
175 myIsGeometryValid = InitTwoShapesPoints (myFirstShape, mySecondShape, aComputedPlane, isPlaneReturned);
177 if (myIsGeometryValid && !myIsPlaneCustom)
181 myPlane = aComputedPlane;
185 myIsGeometryValid = Standard_False;
192 //=======================================================================
193 //function : CheckPlane
195 //=======================================================================
196 Standard_Boolean PrsDim_LengthDimension::CheckPlane (const gp_Pln& thePlane) const
198 Standard_Boolean anIsFaultyNormal =
199 thePlane.Axis().Direction().IsParallel(gce_MakeDir (myFirstPoint, mySecondPoint), Precision::Angular());
201 if ((!thePlane.Contains (myFirstPoint, Precision::Confusion()) && !thePlane.Contains (mySecondPoint, Precision::Confusion()))
204 return Standard_False;
207 return Standard_True;
210 //=======================================================================
211 //function : ComputePlane
213 //=======================================================================
214 gp_Pln PrsDim_LengthDimension::ComputePlane (const gp_Dir& theAttachDir) const
216 if (!IsValidPoints (myFirstPoint, mySecondPoint))
221 gp_Pnt aThirdPoint (myFirstPoint.Translated (gp_Vec(theAttachDir)));
222 gce_MakePln aPlaneConstrustor (myFirstPoint, mySecondPoint, aThirdPoint);
223 return aPlaneConstrustor.Value();
226 //=======================================================================
227 //function : GetModelUnits
229 //=======================================================================
230 const TCollection_AsciiString& PrsDim_LengthDimension::GetModelUnits() const
232 return myDrawer->DimLengthModelUnits();
235 //=======================================================================
236 //function : GetDisplayUnits
238 //=======================================================================
239 const TCollection_AsciiString& PrsDim_LengthDimension::GetDisplayUnits() const
241 return myDrawer->DimLengthDisplayUnits();
244 //=======================================================================
245 //function : SetModelUnits
247 //=======================================================================
248 void PrsDim_LengthDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
250 myDrawer->SetDimLengthModelUnits (theUnits);
253 //=======================================================================
254 //function : SetDisplayUnits
256 //=======================================================================
257 void PrsDim_LengthDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
259 myDrawer->SetDimLengthDisplayUnits (theUnits);
262 //=======================================================================
263 //function : ComputeValue
265 //=======================================================================
266 Standard_Real PrsDim_LengthDimension::ComputeValue() const
271 if (!myHasCustomDirection)
272 return myFirstPoint.Distance (mySecondPoint);
274 return fabs (gp_Vec(myFirstPoint, mySecondPoint).Dot (myDirection));
277 //=======================================================================
280 //=======================================================================
281 void PrsDim_LengthDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
282 const Handle(Prs3d_Presentation)& thePresentation,
283 const Standard_Integer theMode)
285 mySelectionGeom.Clear (theMode);
292 DrawLinearDimension (thePresentation, theMode, myFirstPoint, mySecondPoint);
295 //=======================================================================
296 //function : ComputeFlyoutLinePoints
298 //=======================================================================
299 void PrsDim_LengthDimension::ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint,
300 gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint)
302 if (!myHasCustomDirection)
304 PrsDim_Dimension::ComputeFlyoutLinePoints (theFirstPoint, theSecondPoint, theLineBegPoint, theLineEndPoint);
308 // find scalar of projection target vector (from start to second point) to flyout vector
309 gp_Ax1 aPlaneNormal = GetPlane().Axis();
310 gp_Vec aFlyoutNormalizedDir(aPlaneNormal.Direction() ^ myDirection);
311 aFlyoutNormalizedDir.Normalize();
312 Standard_Real aTargetProjectedToFlyout = gp_Vec(theFirstPoint, theSecondPoint).Dot (aFlyoutNormalizedDir);
314 gp_Dir aFlyoutVector = aFlyoutNormalizedDir;
315 // create lines for layouts
316 gp_Lin aLine1 (theFirstPoint, aFlyoutVector);
317 gp_Lin aLine2 (theSecondPoint, aFlyoutVector);
319 // Get flyout end points
320 theLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout() + aTargetProjectedToFlyout, aLine1);
321 theLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2);
324 //=======================================================================
325 //function : ComputeFlyoutSelection
327 //=======================================================================
328 void PrsDim_LengthDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
329 const Handle(SelectMgr_EntityOwner)& theEntityOwner)
336 ComputeLinearFlyouts (theSelection, theEntityOwner, myFirstPoint, mySecondPoint);
339 //=======================================================================
340 //function : IsValidPoints
342 //=======================================================================
343 Standard_Boolean PrsDim_LengthDimension::IsValidPoints (const gp_Pnt& theFirstPoint,
344 const gp_Pnt& theSecondPoint) const
346 return theFirstPoint.Distance (theSecondPoint) > Precision::Confusion();
349 //=======================================================================
350 //function : InitTwoEdgesLength
351 //purpose : Initialization of dimension between two linear edges
352 //=======================================================================
353 Standard_Boolean PrsDim_LengthDimension::InitTwoEdgesLength (const TopoDS_Edge& theFirstEdge,
354 const TopoDS_Edge& theSecondEdge,
355 gp_Dir& theDirAttach)
357 BRepAdaptor_Curve aFirstCurveAdapt (theFirstEdge);
358 if (aFirstCurveAdapt.GetType() != GeomAbs_Line)
360 return Standard_False;
363 BRepAdaptor_Curve aSecondCurveAdapt (theSecondEdge);
364 if (aSecondCurveAdapt.GetType() != GeomAbs_Line)
366 return Standard_False;
369 Handle(Geom_Curve) aFirstCurve;
370 Handle(Geom_Curve) aSecondCurve;
372 gp_Pnt aPoint11 (gp::Origin());
373 gp_Pnt aPoint12 (gp::Origin());
374 gp_Pnt aPoint21 (gp::Origin());
375 gp_Pnt aPoint22 (gp::Origin());
376 Standard_Boolean isFirstInfinite = Standard_False;
377 Standard_Boolean isSecondInfinite = Standard_False;
379 if (!PrsDim::ComputeGeometry (theFirstEdge, theSecondEdge,
380 aFirstCurve, aSecondCurve,
386 return Standard_False;
389 const Handle(Geom_Line) aFirstLine = Handle(Geom_Line)::DownCast (aFirstCurve);
390 const Handle(Geom_Line) aSecondLine = Handle(Geom_Line)::DownCast (aSecondCurve);
392 if (!aFirstLine->Lin().Direction().IsParallel (aSecondLine->Lin().Direction(),Precision::Angular()))
394 return Standard_False;
397 theDirAttach = aFirstLine->Lin().Direction();
401 if (!isFirstInfinite)
403 if (PrsDim::Nearest (aSecondCurve, aPoint11, aPoint21, aPoint22, aPoint))
405 myFirstPoint = aPoint11;
406 mySecondPoint = aPoint;
407 return IsValidPoints (myFirstPoint, mySecondPoint);
409 else if (PrsDim::Nearest (aSecondCurve, aPoint12, aPoint21, aPoint22, aPoint))
411 myFirstPoint = aPoint12;
412 mySecondPoint = aPoint;
413 return IsValidPoints (myFirstPoint, mySecondPoint);
417 if (!isSecondInfinite)
419 if (PrsDim::Nearest (aFirstCurve, aPoint21, aPoint11, aPoint12, aPoint))
421 myFirstPoint = aPoint;
422 mySecondPoint = aPoint21;
423 return IsValidPoints (myFirstPoint, mySecondPoint);
425 if (PrsDim::Nearest (aFirstCurve, aPoint22, aPoint11, aPoint12, aPoint))
427 myFirstPoint = aPoint;
428 mySecondPoint = aPoint22;
429 return IsValidPoints (myFirstPoint, mySecondPoint);
433 GeomAPI_ExtremaCurveCurve anExtrema (aFirstCurve, aSecondCurve);
434 anExtrema.NearestPoints (myFirstPoint, mySecondPoint);
435 return IsValidPoints (myFirstPoint, mySecondPoint);
438 //=======================================================================
439 //function : InitEdgeVertexLength
440 //purpose : for first edge and second vertex shapes
441 //=======================================================================
442 Standard_Boolean PrsDim_LengthDimension::InitEdgeVertexLength (const TopoDS_Edge& theEdge,
443 const TopoDS_Vertex& theVertex,
445 Standard_Boolean isInfinite)
447 gp_Pnt anEdgePoint1 (gp::Origin());
448 gp_Pnt anEdgePoint2 (gp::Origin());
449 Handle(Geom_Curve) aCurve;
451 if (!PrsDim::ComputeGeometry (theEdge, aCurve, anEdgePoint1, anEdgePoint2, isInfinite))
453 return Standard_False;
456 myFirstPoint = BRep_Tool::Pnt (theVertex);
458 Handle(Geom_Line) aGeomLine (Handle(Geom_Line)::DownCast (aCurve));
459 const gp_Lin& aLin = aGeomLine->Lin();
461 // Get direction of edge to build plane automatically.
462 theEdgeDir = aLin.Direction();
464 mySecondPoint = PrsDim::Nearest (aLin, myFirstPoint);
466 return IsValidPoints (myFirstPoint, mySecondPoint);
469 //=======================================================================
470 //function : InitEdgeFaceLength
472 //=======================================================================
473 Standard_Boolean PrsDim_LengthDimension::InitEdgeFaceLength (const TopoDS_Edge& theEdge,
474 const TopoDS_Face& theFace,
477 theEdgeDir = gp::DX();
479 // Find attachment points (closest distance between the edge and the face)
480 BRepExtrema_DistShapeShape aDistAdaptor (theEdge, theFace, Extrema_ExtFlag_MIN);
481 if (!aDistAdaptor.IsDone() || aDistAdaptor.NbSolution() <1)
483 return Standard_False;
485 myFirstPoint = aDistAdaptor.PointOnShape1 (1);
486 mySecondPoint = aDistAdaptor.PointOnShape2 (1);
488 // Take direction for dimension line (will be orthogonalized later) parallel to edge
489 BRepAdaptor_Curve aCurveAdaptor (theEdge);
490 Standard_Real aParam;
491 if (aDistAdaptor.SupportOnShape1 (1).ShapeType() == TopAbs_EDGE)
493 aDistAdaptor.ParOnEdgeS1 (1, aParam);
497 Standard_Real aD1 = aCurveAdaptor.Value(aCurveAdaptor.FirstParameter()).SquareDistance (myFirstPoint);
498 Standard_Real aD2 = aCurveAdaptor.Value(aCurveAdaptor.LastParameter()).SquareDistance (myFirstPoint);
499 aParam = (aD1 < aD2 ? aCurveAdaptor.FirstParameter() : aCurveAdaptor.LastParameter());
503 aCurveAdaptor.D1 (aParam, aP, aV);
504 if (aV.SquareMagnitude() > gp::Resolution())
509 // reverse direction if parameter is close to the end of the curve,
510 // to reduce chances to have overlapping between dimension line and edge
511 if (Abs (aParam - aCurveAdaptor.FirstParameter()) < Abs (aParam - aCurveAdaptor.LastParameter()))
513 theEdgeDir.Reverse();
516 return IsValidPoints (myFirstPoint, mySecondPoint);
519 //=======================================================================
520 //function : InitTwoShapesPoints
521 //purpose : Initialization of two points where dimension layouts
523 //=======================================================================
524 Standard_Boolean PrsDim_LengthDimension::InitTwoShapesPoints (const TopoDS_Shape& theFirstShape,
525 const TopoDS_Shape& theSecondShape,
526 gp_Pln& theComputedPlane,
527 Standard_Boolean& theIsPlaneComputed)
529 theIsPlaneComputed = Standard_False;
531 Standard_Boolean isInfinite = Standard_False;
532 Standard_Boolean isSuccess = Standard_False;
533 switch (theFirstShape.ShapeType())
537 // Initialization for face
539 Handle(Geom_Surface) aFirstSurface;
540 PrsDim_KindOfSurface aFirstSurfKind;
541 Standard_Real aFirstOffset;
543 TopoDS_Face aFirstFace = TopoDS::Face (theFirstShape);
545 PrsDim::InitFaceLength (TopoDS::Face (theFirstShape),
551 if (theSecondShape.ShapeType() == TopAbs_FACE)
553 // Initialization for face
554 myGeometryType = GeometryType_Faces;
556 Handle(Geom_Surface) aSecondSurface;
557 PrsDim_KindOfSurface aSecondSurfKind;
558 Standard_Real aSecondOffset;
560 TopoDS_Face aSecondFace = TopoDS::Face (theSecondShape);
562 PrsDim::InitFaceLength (aSecondFace,
568 if (aFirstSurfKind == PrsDim_KOS_Plane)
570 if (!aFirstPlane.Axis().Direction().IsParallel (aSecondPlane.Axis().Direction(), Precision::Angular()))
572 return Standard_False;
575 TopExp_Explorer anExplorer (theFirstShape, TopAbs_VERTEX);
577 // In case of infinite planes
578 if (!anExplorer.More())
580 myFirstPoint = aFirstPlane.Location();
584 myFirstPoint = BRep_Tool::Pnt (TopoDS::Vertex (anExplorer.Current()));
587 mySecondPoint = PrsDim::ProjectPointOnPlane (myFirstPoint, aSecondPlane);
589 Standard_Real anU, aV;
590 ElSLib::Parameters (aSecondPlane, mySecondPoint, anU, aV);
592 BRepTopAdaptor_FClass2d aClassifier (aSecondFace, Precision::Confusion());
593 TopAbs_State aState = aClassifier.Perform (gp_Pnt2d (anU, aV), Standard_False);
595 if (aState == TopAbs_OUT || aState == TopAbs_UNKNOWN)
597 mySecondPoint = PrsDim::Nearest (aSecondFace, myFirstPoint);
600 isSuccess = IsValidPoints (myFirstPoint, mySecondPoint);
603 theComputedPlane = ComputePlane (aFirstPlane.Position().XDirection());
604 theIsPlaneComputed = Standard_True;
607 else // curvilinear faces
609 Standard_Real aU1Min, aV1Min, aU1Max, aV1Max;
610 Standard_Real aU2Min, aV2Min, aU2Max, aV2Max;
611 BRepTools::UVBounds (aFirstFace, aU1Min, aU1Max, aV1Min, aV1Max);
612 BRepTools::UVBounds (aSecondFace, aU2Min, aU2Max, aV2Min, aV2Max);
614 GeomAPI_ExtremaSurfaceSurface anExtrema (aFirstSurface, aSecondSurface,
615 aU1Min, aU1Max, aV1Min, aV1Max,
616 aU2Min, aU2Max, aV2Min, aV2Max);
618 Standard_Real aU1, aV1, aU2, aV2;
619 anExtrema.LowerDistanceParameters (aU1, aV1, aU2, aV2);
620 myFirstPoint = BRep_Tool::Surface (aFirstFace)->Value (aU1, aV1);
621 mySecondPoint = BRep_Tool::Surface (aSecondFace)->Value (aU2, aV2);
623 // Adjust automatic plane
624 gp_Ax2 aLocalAxes (myFirstPoint, gce_MakeDir (myFirstPoint, mySecondPoint));
625 aDirAttach = gce_MakeDir (aLocalAxes.XDirection ());
628 isSuccess = IsValidPoints (myFirstPoint, mySecondPoint);
631 theComputedPlane = ComputePlane (aDirAttach);
632 theIsPlaneComputed = Standard_True;
636 return isSuccess && IsValidPoints (myFirstPoint, mySecondPoint);
638 else if (theSecondShape.ShapeType() == TopAbs_EDGE)
640 myGeometryType = GeometryType_EdgeFace;
641 isSuccess = InitEdgeFaceLength (TopoDS::Edge (theSecondShape),
642 TopoDS::Face (theFirstShape),
647 theComputedPlane = ComputePlane (aDirAttach);
648 theIsPlaneComputed = Standard_True;
658 if (theSecondShape.ShapeType() == TopAbs_VERTEX)
660 myGeometryType = GeometryType_EdgeVertex;
661 isSuccess = InitEdgeVertexLength (TopoDS::Edge (theFirstShape),
662 TopoDS::Vertex (theSecondShape),
668 theComputedPlane = ComputePlane (aDirAttach);
669 theIsPlaneComputed = Standard_True;
674 else if (theSecondShape.ShapeType() == TopAbs_EDGE)
676 myGeometryType = GeometryType_Edges;
677 isSuccess = InitTwoEdgesLength (TopoDS::Edge (theFirstShape),
678 TopoDS::Edge (theSecondShape),
683 theComputedPlane = ComputePlane (aDirAttach);
684 theIsPlaneComputed = Standard_True;
689 else if (theSecondShape.ShapeType() == TopAbs_FACE)
691 myGeometryType = GeometryType_EdgeFace;
692 isSuccess = InitEdgeFaceLength (TopoDS::Edge (theFirstShape),
693 TopoDS::Face (theSecondShape),
698 theComputedPlane = ComputePlane (aDirAttach);
699 theIsPlaneComputed = Standard_True;
709 if (theSecondShape.ShapeType() == TopAbs_VERTEX)
711 myGeometryType = GeometryType_Points;
712 myFirstPoint = BRep_Tool::Pnt (TopoDS::Vertex (theFirstShape));
713 mySecondPoint = BRep_Tool::Pnt (TopoDS::Vertex (theSecondShape));
715 return IsValidPoints (myFirstPoint, mySecondPoint);
717 else if (theSecondShape.ShapeType() == TopAbs_EDGE)
719 myGeometryType = GeometryType_EdgeVertex;
720 isSuccess = InitEdgeVertexLength (TopoDS::Edge(theSecondShape),
721 TopoDS::Vertex(theFirstShape),
726 theComputedPlane = ComputePlane (aDirAttach);
727 theIsPlaneComputed = Standard_True;
735 case TopAbs_COMPOUND:
736 case TopAbs_COMPSOLID:
744 return Standard_False;
747 //=======================================================================
748 //function : InitOneShapePoints
749 //purpose : Initialization of two points where dimension layouts
751 // Attention: 1) <theShape> can be only the edge in currect implementation
752 // 2) No length for infinite edge
753 //=======================================================================
754 Standard_Boolean PrsDim_LengthDimension::InitOneShapePoints (const TopoDS_Shape& theShape)
756 if (theShape.ShapeType() != TopAbs_EDGE)
758 return Standard_False;
761 TopoDS_Edge anEdge = TopoDS::Edge (theShape);
763 BRepAdaptor_Curve aBrepCurve(anEdge);
764 Standard_Real aFirst = aBrepCurve.FirstParameter();
765 Standard_Real aLast = aBrepCurve.LastParameter();
767 if (aBrepCurve.GetType() != GeomAbs_Line)
769 return Standard_False;
772 Standard_Boolean isInfinite = (Precision::IsInfinite (aFirst) || Precision::IsInfinite (aLast));
775 return Standard_False;
778 myFirstPoint = aBrepCurve.Value (aBrepCurve.FirstParameter());
779 mySecondPoint = aBrepCurve.Value (aBrepCurve.LastParameter());
781 return IsValidPoints (myFirstPoint, mySecondPoint);
784 //=======================================================================
785 //function : GetTextPosition
787 //=======================================================================
788 gp_Pnt PrsDim_LengthDimension::GetTextPosition() const
790 if (IsTextPositionCustom())
792 return myFixedTextPosition;
795 // Counts text position according to the dimension parameters
796 return GetTextPositionForLinear (myFirstPoint, mySecondPoint);
799 //=======================================================================
800 //function : SetTextPosition
802 //=======================================================================
803 void PrsDim_LengthDimension::SetTextPosition (const gp_Pnt& theTextPos)
810 myIsTextPositionFixed = Standard_True;
811 myFixedTextPosition = theTextPos;
816 //=======================================================================
817 //function : SetDirection
819 //=======================================================================
820 void PrsDim_LengthDimension::SetDirection (const gp_Dir& theDirection, const Standard_Boolean theUseDirection)
822 myHasCustomDirection = theUseDirection;
823 if (myHasCustomDirection)
824 myDirection = theDirection;