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-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 #include <AIS_RadiusDimension.hxx>
24 #include <BRepLib_MakeEdge.hxx>
26 #include <gce_MakeDir.hxx>
28 IMPLEMENT_STANDARD_HANDLE (AIS_RadiusDimension, AIS_Dimension)
29 IMPLEMENT_STANDARD_RTTIEXT (AIS_RadiusDimension, AIS_Dimension)
33 static const Standard_ExtCharacter THE_RADIUS_SYMBOL ('R');
36 //=======================================================================
37 //function : Constructor
39 //=======================================================================
40 AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle)
41 : AIS_Dimension (AIS_KOD_RADIUS)
43 SetMeasuredGeometry (theCircle);
44 SetSpecialSymbol (THE_RADIUS_SYMBOL);
45 SetDisplaySpecialSymbol (AIS_DSS_Before);
49 //=======================================================================
50 //function : Constructor
52 //=======================================================================
53 AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
54 const gp_Pnt& theAttachPoint)
55 : AIS_Dimension (AIS_KOD_RADIUS)
57 SetMeasuredGeometry (theCircle, theAttachPoint);
58 SetSpecialSymbol (THE_RADIUS_SYMBOL);
59 SetDisplaySpecialSymbol (AIS_DSS_Before);
63 //=======================================================================
64 //function : Constructor
66 //=======================================================================
67 AIS_RadiusDimension::AIS_RadiusDimension (const TopoDS_Shape& theShape)
68 : AIS_Dimension (AIS_KOD_RADIUS)
70 SetMeasuredGeometry (theShape);
71 SetSpecialSymbol (THE_RADIUS_SYMBOL);
72 SetDisplaySpecialSymbol (AIS_DSS_Before);
76 //=======================================================================
77 //function : SetMeasuredGeometry
79 //=======================================================================
80 void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle)
83 myGeometryType = GeometryType_Edge;
84 myShape = BRepLib_MakeEdge (theCircle);
85 myAnchorPoint = ElCLib::Value (0, myCircle);
86 myIsValid = IsValidCircle (myCircle);
93 myIsValid &= CheckPlane (myPlane);
98 //=======================================================================
99 //function : SetMeasuredGeometry
101 //=======================================================================
102 void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle,
103 const gp_Pnt& theAnchorPoint)
105 myCircle = theCircle;
106 myGeometryType = GeometryType_Edge;
107 myShape = BRepLib_MakeEdge (theCircle);
108 myAnchorPoint = theAnchorPoint;
109 myIsValid = IsValidCircle (myCircle) && IsValidAnchor (myCircle, theAnchorPoint);
116 myIsValid &= CheckPlane (myPlane);
121 //=======================================================================
122 //function : SetMeasuredGeometry
124 //=======================================================================
125 void AIS_RadiusDimension::SetMeasuredGeometry (const TopoDS_Shape& theShape)
127 Standard_Boolean isClosed = Standard_False;
129 myGeometryType = GeometryType_UndefShapes;
130 myIsValid = InitCircularDimension (theShape, myCircle, myAnchorPoint, isClosed)
131 && IsValidCircle (myCircle);
138 myIsValid &= CheckPlane (myPlane);
143 //=======================================================================
144 //function : CheckPlane
146 //=======================================================================
147 Standard_Boolean AIS_RadiusDimension::CheckPlane (const gp_Pln& thePlane) const
149 // Check if anchor point and circle center point belong to plane.
150 if (!thePlane.Contains (myAnchorPoint, Precision::Confusion()) &&
151 !thePlane.Contains (myCircle.Location(), Precision::Confusion()))
153 return Standard_False;
156 return Standard_True;
159 //=======================================================================
160 //function : ComputePlane
162 //=======================================================================
163 void AIS_RadiusDimension::ComputePlane()
170 gp_Dir aDimensionX = gce_MakeDir (myAnchorPoint, myCircle.Location());
172 myPlane = gp_Pln (gp_Ax3 (myCircle.Location(),
173 myCircle.Axis().Direction(),
177 //=======================================================================
178 //function : GetModelUnits
180 //=======================================================================
181 const TCollection_AsciiString& AIS_RadiusDimension::GetModelUnits() const
183 return myDrawer->DimLengthModelUnits();
186 //=======================================================================
187 //function : GetDisplayUnits
189 //=======================================================================
190 const TCollection_AsciiString& AIS_RadiusDimension::GetDisplayUnits() const
192 return myDrawer->DimLengthDisplayUnits();
195 //=======================================================================
196 //function : SetModelUnits
198 //=======================================================================
199 void AIS_RadiusDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
201 myDrawer->SetDimLengthModelUnits (theUnits);
204 //=======================================================================
205 //function : SetDisplayUnits
207 //=======================================================================
208 void AIS_RadiusDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
210 myDrawer->SetDimLengthDisplayUnits(theUnits);
213 //=======================================================================
214 //function : ComputeValue
216 //=======================================================================
217 Standard_Real AIS_RadiusDimension::ComputeValue() const
224 return myCircle.Radius();
227 //=======================================================================
230 //=======================================================================
231 void AIS_RadiusDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
232 const Handle(Prs3d_Presentation)& thePresentation,
233 const Standard_Integer theMode)
235 thePresentation->Clear();
236 mySelectionGeom.Clear (theMode);
243 DrawLinearDimension (thePresentation, theMode, myAnchorPoint, myCircle.Location(), Standard_True);
246 //=======================================================================
247 //function : IsValidCircle
249 //=======================================================================
250 Standard_Boolean AIS_RadiusDimension::IsValidCircle (const gp_Circ& theCircle) const
252 return theCircle.Radius() > Precision::Confusion();
255 //=======================================================================
256 //function : IsValidAnchor
258 //=======================================================================
259 Standard_Boolean AIS_RadiusDimension::IsValidAnchor (const gp_Circ& theCircle,
260 const gp_Pnt& theAnchor) const
262 gp_Pln aCirclePlane (theCircle.Location(), theCircle.Axis().Direction());
263 Standard_Real anAnchorDist = theAnchor.Distance (theCircle.Location());
264 Standard_Real aRadius = myCircle.Radius();
266 return Abs (anAnchorDist - aRadius) > Precision::Confusion()
267 && aCirclePlane.Contains (theAnchor, Precision::Confusion());