0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- manual
[occt.git] / src / AIS / AIS_RadiusDimension.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <AIS_RadiusDimension.hxx>
18
19 #include <AIS.hxx>
20 #include <BRepLib_MakeEdge.hxx>
21 #include <ElCLib.hxx>
22 #include <gce_MakeDir.hxx>
23
24
25 namespace
26 {
27   static const Standard_ExtCharacter THE_RADIUS_SYMBOL ('R');
28 };
29
30 //=======================================================================
31 //function : Constructor
32 //purpose  : 
33 //=======================================================================
34 AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle)
35 : AIS_Dimension (AIS_KOD_RADIUS)
36 {
37   SetMeasuredGeometry (theCircle);
38   SetSpecialSymbol (THE_RADIUS_SYMBOL);
39   SetDisplaySpecialSymbol (AIS_DSS_Before);
40   SetFlyout (0.0);
41 }
42
43 //=======================================================================
44 //function : Constructor
45 //purpose  : 
46 //=======================================================================
47 AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
48                                           const gp_Pnt& theAttachPoint)
49 : AIS_Dimension (AIS_KOD_RADIUS)
50 {
51   SetMeasuredGeometry (theCircle, theAttachPoint);
52   SetSpecialSymbol (THE_RADIUS_SYMBOL);
53   SetDisplaySpecialSymbol (AIS_DSS_Before);
54   SetFlyout (0.0);
55 }
56
57 //=======================================================================
58 //function : Constructor
59 //purpose  :
60 //=======================================================================
61 AIS_RadiusDimension::AIS_RadiusDimension (const TopoDS_Shape& theShape)
62 : AIS_Dimension (AIS_KOD_RADIUS)
63 {
64   SetMeasuredGeometry (theShape);
65   SetSpecialSymbol (THE_RADIUS_SYMBOL);
66   SetDisplaySpecialSymbol (AIS_DSS_Before);
67   SetFlyout (0.0);
68 }
69
70 //=======================================================================
71 //function : SetMeasuredGeometry
72 //purpose  : 
73 //=======================================================================
74 void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle)
75 {
76   myCircle          = theCircle;
77   myGeometryType    = GeometryType_Edge;
78   myShape           = BRepLib_MakeEdge (theCircle);
79   myAnchorPoint     = ElCLib::Value (0, myCircle);
80   myIsGeometryValid = IsValidCircle (myCircle);
81
82   if (myIsGeometryValid)
83   {
84     ComputePlane();
85   }
86
87   SetToUpdate();
88 }
89
90 //=======================================================================
91 //function : SetMeasuredGeometry
92 //purpose  : 
93 //=======================================================================
94 void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle,
95                                                const gp_Pnt&  theAnchorPoint)
96 {
97   myCircle          = theCircle;
98   myGeometryType    = GeometryType_Edge;
99   myShape           = BRepLib_MakeEdge (theCircle);
100   myAnchorPoint     = theAnchorPoint;
101   myIsGeometryValid = IsValidCircle (myCircle) && IsValidAnchor (myCircle, theAnchorPoint);
102
103   if (myIsGeometryValid)
104   {
105     ComputePlane();
106   }
107
108   SetToUpdate();
109 }
110
111 //=======================================================================
112 //function : SetMeasuredGeometry
113 //purpose  : 
114 //=======================================================================
115 void AIS_RadiusDimension::SetMeasuredGeometry (const TopoDS_Shape& theShape)
116 {
117   Standard_Boolean isClosed = Standard_False;
118   myShape                   = theShape;
119   myGeometryType            = GeometryType_UndefShapes;
120   myIsGeometryValid         = InitCircularDimension (theShape, myCircle, myAnchorPoint, isClosed) 
121                               && IsValidCircle (myCircle);
122
123   if (myIsGeometryValid)
124   {
125     ComputePlane();
126   }
127
128   SetToUpdate();
129 }
130
131 //=======================================================================
132 //function : CheckPlane
133 //purpose  : 
134 //=======================================================================
135 Standard_Boolean AIS_RadiusDimension::CheckPlane (const gp_Pln& thePlane) const
136 {
137   // Check if anchor point and circle center point belong to plane.
138   if (!thePlane.Contains (myAnchorPoint, Precision::Confusion()) &&
139       !thePlane.Contains (myCircle.Location(), Precision::Confusion()))
140   {
141     return Standard_False;
142   }
143
144   return Standard_True;
145 }
146
147 //=======================================================================
148 //function : ComputePlane
149 //purpose  : 
150 //=======================================================================
151 void AIS_RadiusDimension::ComputePlane()
152 {
153   if (!myIsGeometryValid)
154   {
155     return;
156   }
157
158   gp_Dir aDimensionX = gce_MakeDir (myAnchorPoint, myCircle.Location());
159
160   myPlane = gp_Pln (gp_Ax3 (myCircle.Location(),
161                             myCircle.Axis().Direction(),
162                             aDimensionX));
163 }
164
165 //=======================================================================
166 //function : GetModelUnits
167 //purpose  :
168 //=======================================================================
169 const TCollection_AsciiString& AIS_RadiusDimension::GetModelUnits() const
170 {
171   return myDrawer->DimLengthModelUnits();
172 }
173
174 //=======================================================================
175 //function : GetDisplayUnits
176 //purpose  :
177 //=======================================================================
178 const TCollection_AsciiString& AIS_RadiusDimension::GetDisplayUnits() const
179 {
180   return myDrawer->DimLengthDisplayUnits();
181 }
182
183 //=======================================================================
184 //function : SetModelUnits
185 //purpose  :
186 //=======================================================================
187 void AIS_RadiusDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
188 {
189   myDrawer->SetDimLengthModelUnits (theUnits);
190 }
191
192 //=======================================================================
193 //function : SetDisplayUnits
194 //purpose  :
195 //=======================================================================
196 void AIS_RadiusDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
197 {
198   myDrawer->SetDimLengthDisplayUnits(theUnits);
199 }
200
201 //=======================================================================
202 //function : ComputeValue
203 //purpose  : 
204 //=======================================================================
205 Standard_Real AIS_RadiusDimension::ComputeValue() const
206 {
207   if (!IsValid())
208   {
209     return 0.0;
210   }
211
212   return myCircle.Radius();
213 }
214
215 //=======================================================================
216 //function : Compute
217 //purpose  : 
218 //=======================================================================
219 void AIS_RadiusDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
220                                    const Handle(Prs3d_Presentation)& thePresentation,
221                                    const Standard_Integer theMode)
222 {
223   thePresentation->Clear();
224   mySelectionGeom.Clear (theMode);
225
226   if (!IsValid())
227   {
228     return;
229   }
230
231   DrawLinearDimension (thePresentation, theMode, myAnchorPoint, myCircle.Location(), Standard_True);
232 }
233
234 //=======================================================================
235 //function : IsValidCircle
236 //purpose  : 
237 //=======================================================================
238 Standard_Boolean AIS_RadiusDimension::IsValidCircle (const gp_Circ& theCircle) const
239 {
240   return theCircle.Radius() > Precision::Confusion();
241 }
242
243 //=======================================================================
244 //function : IsValidAnchor
245 //purpose  : 
246 //=======================================================================
247 Standard_Boolean AIS_RadiusDimension::IsValidAnchor (const gp_Circ& theCircle,
248                                                      const gp_Pnt& theAnchor) const
249 {
250   gp_Pln aCirclePlane (theCircle.Location(), theCircle.Axis().Direction());
251   Standard_Real anAnchorDist = theAnchor.Distance (theCircle.Location());
252   Standard_Real aRadius      = myCircle.Radius();
253
254   return Abs (anAnchorDist - aRadius) > Precision::Confusion()
255       && aCirclePlane.Contains (theAnchor, Precision::Confusion());
256 }
257
258 //=======================================================================
259 //function : GetTextPosition
260 //purpose  : 
261 //=======================================================================
262 const gp_Pnt AIS_RadiusDimension::GetTextPosition() const
263 {
264   if (IsTextPositionCustom())
265   {
266     return myFixedTextPosition;
267   }
268
269   // Counts text position according to the dimension parameters
270   return GetTextPositionForLinear (myAnchorPoint, myCircle.Location(), Standard_True);
271 }
272
273 //=======================================================================
274 //function : GetTextPosition
275 //purpose  : 
276 //=======================================================================
277 void AIS_RadiusDimension::SetTextPosition (const gp_Pnt& theTextPos)
278 {
279   if (!myIsGeometryValid)
280   {
281     return;
282   }
283
284   myIsTextPositionFixed = Standard_True;
285   myFixedTextPosition = theTextPos;
286
287   SetToUpdate();
288 }