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