0027724: Visualization, TKV3d - Null handle check missing in AIS_InteractiveContext...
[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
92efcf78 25IMPLEMENT_STANDARD_RTTIEXT(AIS_RadiusDimension,AIS_Dimension)
26
60bf98ae 27namespace
28{
29 static const Standard_ExtCharacter THE_RADIUS_SYMBOL ('R');
a3f6f591 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{
91b16a64 78 myCircle = theCircle;
79 myGeometryType = GeometryType_Edge;
80 myShape = BRepLib_MakeEdge (theCircle);
81 myAnchorPoint = ElCLib::Value (0, myCircle);
82 myIsGeometryValid = IsValidCircle (myCircle);
7fd59977 83
91b16a64 84 if (myIsGeometryValid)
60bf98ae 85 {
86 ComputePlane();
87 }
88
60bf98ae 89 SetToUpdate();
90}
91
92//=======================================================================
93//function : SetMeasuredGeometry
94//purpose :
95//=======================================================================
96void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle,
97 const gp_Pnt& theAnchorPoint)
a6eb515f 98{
91b16a64 99 myCircle = theCircle;
100 myGeometryType = GeometryType_Edge;
101 myShape = BRepLib_MakeEdge (theCircle);
102 myAnchorPoint = theAnchorPoint;
103 myIsGeometryValid = IsValidCircle (myCircle) && IsValidAnchor (myCircle, theAnchorPoint);
60bf98ae 104
91b16a64 105 if (myIsGeometryValid)
60bf98ae 106 {
107 ComputePlane();
108 }
a6eb515f 109
60bf98ae 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;
91b16a64 120 myShape = theShape;
121 myGeometryType = GeometryType_UndefShapes;
122 myIsGeometryValid = InitCircularDimension (theShape, myCircle, myAnchorPoint, isClosed)
123 && IsValidCircle (myCircle);
60bf98ae 124
91b16a64 125 if (myIsGeometryValid)
60bf98ae 126 {
127 ComputePlane();
128 }
129
60bf98ae 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()))
a6eb515f 142 {
60bf98ae 143 return Standard_False;
a6eb515f 144 }
a6eb515f 145
60bf98ae 146 return Standard_True;
147}
148
149//=======================================================================
150//function : ComputePlane
151//purpose :
152//=======================================================================
153void AIS_RadiusDimension::ComputePlane()
154{
91b16a64 155 if (!myIsGeometryValid)
a6eb515f 156 {
60bf98ae 157 return;
a6eb515f 158 }
159
60bf98ae 160 gp_Dir aDimensionX = gce_MakeDir (myAnchorPoint, myCircle.Location());
161
162 myPlane = gp_Pln (gp_Ax3 (myCircle.Location(),
163 myCircle.Axis().Direction(),
164 aDimensionX));
7fd59977 165}
166
167//=======================================================================
60bf98ae 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
a6eb515f 205//purpose :
7fd59977 206//=======================================================================
60bf98ae 207Standard_Real AIS_RadiusDimension::ComputeValue() const
208{
209 if (!IsValid())
210 {
211 return 0.0;
212 }
a6eb515f 213
60bf98ae 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)
7fd59977 224{
60bf98ae 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);
7fd59977 234}
235
7fd59977 236//=======================================================================
60bf98ae 237//function : IsValidCircle
7fd59977 238//purpose :
239//=======================================================================
60bf98ae 240Standard_Boolean AIS_RadiusDimension::IsValidCircle (const gp_Circ& theCircle) const
241{
242 return theCircle.Radius() > Precision::Confusion();
243}
7fd59977 244
60bf98ae 245//=======================================================================
246//function : IsValidAnchor
247//purpose :
248//=======================================================================
249Standard_Boolean AIS_RadiusDimension::IsValidAnchor (const gp_Circ& theCircle,
250 const gp_Pnt& theAnchor) const
7fd59977 251{
60bf98ae 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());
7fd59977 258}
af203d54 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{
91b16a64 281 if (!myIsGeometryValid)
af203d54 282 {
283 return;
284 }
285
286 myIsTextPositionFixed = Standard_True;
287 myFixedTextPosition = theTextPos;
288
289 SetToUpdate();
290}