0024728: A lot of tests are crashed on vdump command on Windows in debug mode
[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
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};
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 myIsValid = IsValidCircle (myCircle);
83
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)
100{
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 }
111
112 myIsValid &= CheckPlane (myPlane);
113
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()))
148 {
149 return Standard_False;
150 }
151
152 return Standard_True;
153}
154
155//=======================================================================
156//function : ComputePlane
157//purpose :
158//=======================================================================
159void AIS_RadiusDimension::ComputePlane()
160{
161 if (!IsValid())
162 {
163 return;
164 }
165
166 gp_Dir aDimensionX = gce_MakeDir (myAnchorPoint, myCircle.Location());
167
168 myPlane = gp_Pln (gp_Ax3 (myCircle.Location(),
169 myCircle.Axis().Direction(),
170 aDimensionX));
171}
172
173//=======================================================================
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
211//purpose :
212//=======================================================================
213Standard_Real AIS_RadiusDimension::ComputeValue() const
214{
215 if (!IsValid())
216 {
217 return 0.0;
218 }
219
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)
230{
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);
240}
241
242//=======================================================================
243//function : IsValidCircle
244//purpose :
245//=======================================================================
246Standard_Boolean AIS_RadiusDimension::IsValidCircle (const gp_Circ& theCircle) const
247{
248 return theCircle.Radius() > Precision::Confusion();
249}
250
251//=======================================================================
252//function : IsValidAnchor
253//purpose :
254//=======================================================================
255Standard_Boolean AIS_RadiusDimension::IsValidAnchor (const gp_Circ& theCircle,
256 const gp_Pnt& theAnchor) const
257{
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());
264}
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}