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