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