1 // Created on: 1996-12-05
2 // Created by: Jean-Pierre COMBE/Odile Olivier/Serguei Zaritchny
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_RadiusDimension.hxx>
20 #include <BRepLib_MakeEdge.hxx>
22 #include <gce_MakeDir.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(AIS_RadiusDimension,AIS_Dimension)
29 static const Standard_ExtCharacter THE_RADIUS_SYMBOL ('R');
32 //=======================================================================
33 //function : Constructor
35 //=======================================================================
36 AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle)
37 : AIS_Dimension (AIS_KOD_RADIUS)
39 SetMeasuredGeometry (theCircle);
40 SetSpecialSymbol (THE_RADIUS_SYMBOL);
41 SetDisplaySpecialSymbol (AIS_DSS_Before);
45 //=======================================================================
46 //function : Constructor
48 //=======================================================================
49 AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
50 const gp_Pnt& theAttachPoint)
51 : AIS_Dimension (AIS_KOD_RADIUS)
53 SetMeasuredGeometry (theCircle, theAttachPoint);
54 SetSpecialSymbol (THE_RADIUS_SYMBOL);
55 SetDisplaySpecialSymbol (AIS_DSS_Before);
59 //=======================================================================
60 //function : Constructor
62 //=======================================================================
63 AIS_RadiusDimension::AIS_RadiusDimension (const TopoDS_Shape& theShape)
64 : AIS_Dimension (AIS_KOD_RADIUS)
66 SetMeasuredGeometry (theShape);
67 SetSpecialSymbol (THE_RADIUS_SYMBOL);
68 SetDisplaySpecialSymbol (AIS_DSS_Before);
72 //=======================================================================
73 //function : SetMeasuredGeometry
75 //=======================================================================
76 void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle)
79 myGeometryType = GeometryType_Edge;
80 myShape = BRepLib_MakeEdge (theCircle);
81 myAnchorPoint = ElCLib::Value (0, myCircle);
82 myIsGeometryValid = IsValidCircle (myCircle);
84 if (myIsGeometryValid)
92 //=======================================================================
93 //function : SetMeasuredGeometry
95 //=======================================================================
96 void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle,
97 const gp_Pnt& theAnchorPoint)
100 myGeometryType = GeometryType_Edge;
101 myShape = BRepLib_MakeEdge (theCircle);
102 myAnchorPoint = theAnchorPoint;
103 myIsGeometryValid = IsValidCircle (myCircle) && IsValidAnchor (myCircle, theAnchorPoint);
105 if (myIsGeometryValid)
113 //=======================================================================
114 //function : SetMeasuredGeometry
116 //=======================================================================
117 void AIS_RadiusDimension::SetMeasuredGeometry (const TopoDS_Shape& theShape)
119 Standard_Boolean isClosed = Standard_False;
121 myGeometryType = GeometryType_UndefShapes;
122 myIsGeometryValid = InitCircularDimension (theShape, myCircle, myAnchorPoint, isClosed)
123 && IsValidCircle (myCircle);
125 if (myIsGeometryValid)
133 //=======================================================================
134 //function : CheckPlane
136 //=======================================================================
137 Standard_Boolean AIS_RadiusDimension::CheckPlane (const gp_Pln& thePlane) const
139 // Check if anchor point and circle center point belong to plane.
140 if (!thePlane.Contains (myAnchorPoint, Precision::Confusion()) &&
141 !thePlane.Contains (myCircle.Location(), Precision::Confusion()))
143 return Standard_False;
146 return Standard_True;
149 //=======================================================================
150 //function : ComputePlane
152 //=======================================================================
153 void AIS_RadiusDimension::ComputePlane()
155 if (!myIsGeometryValid)
160 gp_Dir aDimensionX = gce_MakeDir (myAnchorPoint, myCircle.Location());
162 myPlane = gp_Pln (gp_Ax3 (myCircle.Location(),
163 myCircle.Axis().Direction(),
167 //=======================================================================
168 //function : GetModelUnits
170 //=======================================================================
171 const TCollection_AsciiString& AIS_RadiusDimension::GetModelUnits() const
173 return myDrawer->DimLengthModelUnits();
176 //=======================================================================
177 //function : GetDisplayUnits
179 //=======================================================================
180 const TCollection_AsciiString& AIS_RadiusDimension::GetDisplayUnits() const
182 return myDrawer->DimLengthDisplayUnits();
185 //=======================================================================
186 //function : SetModelUnits
188 //=======================================================================
189 void AIS_RadiusDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
191 myDrawer->SetDimLengthModelUnits (theUnits);
194 //=======================================================================
195 //function : SetDisplayUnits
197 //=======================================================================
198 void AIS_RadiusDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
200 myDrawer->SetDimLengthDisplayUnits(theUnits);
203 //=======================================================================
204 //function : ComputeValue
206 //=======================================================================
207 Standard_Real AIS_RadiusDimension::ComputeValue() const
214 return myCircle.Radius();
217 //=======================================================================
220 //=======================================================================
221 void AIS_RadiusDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
222 const Handle(Prs3d_Presentation)& thePresentation,
223 const Standard_Integer theMode)
225 thePresentation->Clear();
226 mySelectionGeom.Clear (theMode);
233 DrawLinearDimension (thePresentation, theMode, myAnchorPoint, myCircle.Location(), Standard_True);
236 //=======================================================================
237 //function : IsValidCircle
239 //=======================================================================
240 Standard_Boolean AIS_RadiusDimension::IsValidCircle (const gp_Circ& theCircle) const
242 return theCircle.Radius() > Precision::Confusion();
245 //=======================================================================
246 //function : IsValidAnchor
248 //=======================================================================
249 Standard_Boolean AIS_RadiusDimension::IsValidAnchor (const gp_Circ& theCircle,
250 const gp_Pnt& theAnchor) const
252 gp_Pln aCirclePlane (theCircle.Location(), theCircle.Axis().Direction());
253 Standard_Real anAnchorDist = theAnchor.Distance (theCircle.Location());
254 Standard_Real aRadius = myCircle.Radius();
256 return Abs (anAnchorDist - aRadius) > Precision::Confusion()
257 && aCirclePlane.Contains (theAnchor, Precision::Confusion());
260 //=======================================================================
261 //function : GetTextPosition
263 //=======================================================================
264 const gp_Pnt AIS_RadiusDimension::GetTextPosition() const
266 if (IsTextPositionCustom())
268 return myFixedTextPosition;
271 // Counts text position according to the dimension parameters
272 return GetTextPositionForLinear (myAnchorPoint, myCircle.Location(), Standard_True);
275 //=======================================================================
276 //function : GetTextPosition
278 //=======================================================================
279 void AIS_RadiusDimension::SetTextPosition (const gp_Pnt& theTextPos)
281 if (!myIsGeometryValid)
286 myIsTextPositionFixed = Standard_True;
287 myFixedTextPosition = theTextPos;