0029367: Visualization - simplify interface of V3d_View and V3d_Viewer
[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
60bf98ae 72//=======================================================================
73//function : SetMeasuredGeometry
74//purpose :
75//=======================================================================
76void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle,
d29b2469 77 const gp_Pnt& theAnchorPoint,
78 const Standard_Boolean theHasAnchor)
a6eb515f 79{
91b16a64 80 myCircle = theCircle;
81 myGeometryType = GeometryType_Edge;
82 myShape = BRepLib_MakeEdge (theCircle);
d29b2469 83 myAnchorPoint = theHasAnchor ? theAnchorPoint : ElCLib::Value (0, myCircle);
84 myIsGeometryValid = IsValidCircle (myCircle) && IsValidAnchor (myCircle, myAnchorPoint);
60bf98ae 85
91b16a64 86 if (myIsGeometryValid)
60bf98ae 87 {
88 ComputePlane();
89 }
a6eb515f 90
60bf98ae 91 SetToUpdate();
92}
93
94//=======================================================================
95//function : SetMeasuredGeometry
96//purpose :
97//=======================================================================
d29b2469 98void AIS_RadiusDimension::SetMeasuredGeometry (const TopoDS_Shape& theShape,
99 const gp_Pnt& theAnchorPoint,
100 const Standard_Boolean theHasAnchor)
60bf98ae 101{
102 Standard_Boolean isClosed = Standard_False;
91b16a64 103 myShape = theShape;
104 myGeometryType = GeometryType_UndefShapes;
105 myIsGeometryValid = InitCircularDimension (theShape, myCircle, myAnchorPoint, isClosed)
d29b2469 106 && IsValidCircle (myCircle);
107 if (theHasAnchor)
108 {
109 myAnchorPoint = theAnchorPoint;
110 myIsGeometryValid = myIsGeometryValid && IsValidAnchor (myCircle, myAnchorPoint);
111 }
60bf98ae 112
91b16a64 113 if (myIsGeometryValid)
60bf98ae 114 {
115 ComputePlane();
116 }
117
60bf98ae 118 SetToUpdate();
119}
120
121//=======================================================================
122//function : CheckPlane
123//purpose :
124//=======================================================================
125Standard_Boolean AIS_RadiusDimension::CheckPlane (const gp_Pln& thePlane) const
126{
127 // Check if anchor point and circle center point belong to plane.
128 if (!thePlane.Contains (myAnchorPoint, Precision::Confusion()) &&
129 !thePlane.Contains (myCircle.Location(), Precision::Confusion()))
a6eb515f 130 {
60bf98ae 131 return Standard_False;
a6eb515f 132 }
a6eb515f 133
60bf98ae 134 return Standard_True;
135}
136
137//=======================================================================
138//function : ComputePlane
139//purpose :
140//=======================================================================
141void AIS_RadiusDimension::ComputePlane()
142{
91b16a64 143 if (!myIsGeometryValid)
a6eb515f 144 {
60bf98ae 145 return;
a6eb515f 146 }
147
60bf98ae 148 gp_Dir aDimensionX = gce_MakeDir (myAnchorPoint, myCircle.Location());
149
150 myPlane = gp_Pln (gp_Ax3 (myCircle.Location(),
151 myCircle.Axis().Direction(),
152 aDimensionX));
7fd59977 153}
154
155//=======================================================================
60bf98ae 156//function : GetModelUnits
157//purpose :
158//=======================================================================
159const TCollection_AsciiString& AIS_RadiusDimension::GetModelUnits() const
160{
161 return myDrawer->DimLengthModelUnits();
162}
163
164//=======================================================================
165//function : GetDisplayUnits
166//purpose :
167//=======================================================================
168const TCollection_AsciiString& AIS_RadiusDimension::GetDisplayUnits() const
169{
170 return myDrawer->DimLengthDisplayUnits();
171}
172
173//=======================================================================
174//function : SetModelUnits
175//purpose :
176//=======================================================================
177void AIS_RadiusDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
178{
179 myDrawer->SetDimLengthModelUnits (theUnits);
180}
181
182//=======================================================================
183//function : SetDisplayUnits
184//purpose :
185//=======================================================================
186void AIS_RadiusDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
187{
188 myDrawer->SetDimLengthDisplayUnits(theUnits);
189}
190
191//=======================================================================
192//function : ComputeValue
a6eb515f 193//purpose :
7fd59977 194//=======================================================================
60bf98ae 195Standard_Real AIS_RadiusDimension::ComputeValue() const
196{
197 if (!IsValid())
198 {
199 return 0.0;
200 }
a6eb515f 201
60bf98ae 202 return myCircle.Radius();
203}
204
205//=======================================================================
206//function : Compute
207//purpose :
208//=======================================================================
209void AIS_RadiusDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
210 const Handle(Prs3d_Presentation)& thePresentation,
211 const Standard_Integer theMode)
7fd59977 212{
60bf98ae 213 mySelectionGeom.Clear (theMode);
214
215 if (!IsValid())
216 {
217 return;
218 }
219
220 DrawLinearDimension (thePresentation, theMode, myAnchorPoint, myCircle.Location(), Standard_True);
7fd59977 221}
222
7fd59977 223//=======================================================================
60bf98ae 224//function : IsValidCircle
7fd59977 225//purpose :
226//=======================================================================
60bf98ae 227Standard_Boolean AIS_RadiusDimension::IsValidCircle (const gp_Circ& theCircle) const
228{
229 return theCircle.Radius() > Precision::Confusion();
230}
7fd59977 231
60bf98ae 232//=======================================================================
233//function : IsValidAnchor
234//purpose :
235//=======================================================================
236Standard_Boolean AIS_RadiusDimension::IsValidAnchor (const gp_Circ& theCircle,
237 const gp_Pnt& theAnchor) const
7fd59977 238{
60bf98ae 239 gp_Pln aCirclePlane (theCircle.Location(), theCircle.Axis().Direction());
240 Standard_Real anAnchorDist = theAnchor.Distance (theCircle.Location());
60bf98ae 241
6ca66a7d 242 return anAnchorDist > Precision::Confusion()
60bf98ae 243 && aCirclePlane.Contains (theAnchor, Precision::Confusion());
7fd59977 244}
af203d54 245
246//=======================================================================
247//function : GetTextPosition
248//purpose :
249//=======================================================================
250const gp_Pnt AIS_RadiusDimension::GetTextPosition() const
251{
252 if (IsTextPositionCustom())
253 {
254 return myFixedTextPosition;
255 }
256
257 // Counts text position according to the dimension parameters
258 return GetTextPositionForLinear (myAnchorPoint, myCircle.Location(), Standard_True);
259}
260
261//=======================================================================
262//function : GetTextPosition
263//purpose :
264//=======================================================================
265void AIS_RadiusDimension::SetTextPosition (const gp_Pnt& theTextPos)
266{
91b16a64 267 if (!myIsGeometryValid)
af203d54 268 {
269 return;
270 }
271
272 myIsTextPositionFixed = Standard_True;
273 myFixedTextPosition = theTextPos;
274
275 SetToUpdate();
276}