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