0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[occt.git] / src / PrsDim / PrsDim_MinRadiusDimension.cxx
CommitLineData
b311480e 1// Created on: 1998-01-27
2// Created by: Sergey ZARITCHNY
3// Copyright (c) 1998-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.
7fd59977 16
787ff240 17#include <PrsDim_MinRadiusDimension.hxx>
7fd59977 18
787ff240 19#include <PrsDim.hxx>
20#include <PrsDim_EllipseRadiusDimension.hxx>
42cf5bc1 21#include <BRepAdaptor_Curve.hxx>
22#include <BRepAdaptor_Surface.hxx>
23#include <DsgPrs_EllipseRadiusPresentation.hxx>
7fd59977 24#include <ElCLib.hxx>
25#include <ElSLib.hxx>
42cf5bc1 26#include <Geom_CylindricalSurface.hxx>
7fd59977 27#include <Geom_Ellipse.hxx>
c04c30b3 28#include <Geom_OffsetCurve.hxx>
7fd59977 29#include <Geom_Plane.hxx>
30#include <Geom_Surface.hxx>
7fd59977 31#include <Geom_SurfaceOfLinearExtrusion.hxx>
42cf5bc1 32#include <Geom_SurfaceOfRevolution.hxx>
42cf5bc1 33#include <Geom_TrimmedCurve.hxx>
7fd59977 34#include <gp_Ax1.hxx>
35#include <gp_Dir.hxx>
42cf5bc1 36#include <gp_Lin.hxx>
37#include <gp_Pln.hxx>
38#include <gp_Pnt.hxx>
7fd59977 39#include <gp_Vec.hxx>
7fd59977 40#include <Precision.hxx>
42cf5bc1 41#include <Prs3d_ArrowAspect.hxx>
42#include <Prs3d_DimensionAspect.hxx>
43#include <Prs3d_Drawer.hxx>
44#include <Prs3d_Presentation.hxx>
42cf5bc1 45#include <Prs3d_Text.hxx>
46#include <Prs3d_TextAspect.hxx>
47#include <Select3D_SensitiveBox.hxx>
48#include <Select3D_SensitiveCurve.hxx>
49#include <Select3D_SensitiveSegment.hxx>
50#include <SelectMgr_EntityOwner.hxx>
51#include <SelectMgr_Selection.hxx>
52#include <Standard_ConstructionError.hxx>
53#include <Standard_NotImplemented.hxx>
42cf5bc1 54#include <TCollection_ExtendedString.hxx>
55#include <TopoDS.hxx>
56#include <TopoDS_Shape.hxx>
7fd59977 57
787ff240 58IMPLEMENT_STANDARD_RTTIEXT(PrsDim_MinRadiusDimension, PrsDim_EllipseRadiusDimension)
92efcf78 59
7fd59977 60//=======================================================================
787ff240 61//function : PrsDim_MinRadiusDimension
7fd59977 62//purpose :
63//=======================================================================
787ff240 64PrsDim_MinRadiusDimension::PrsDim_MinRadiusDimension(const TopoDS_Shape& aShape,
7fd59977 65 const Standard_Real aVal,
66 const TCollection_ExtendedString& aText)
787ff240 67:PrsDim_EllipseRadiusDimension(aShape, aText)
7fd59977 68{
69 myVal = aVal;
70 mySymbolPrs = DsgPrs_AS_LASTAR;
71 myAutomaticPosition = Standard_True;
72 myArrowSize = myVal / 100.;
73}
74
75//=======================================================================
787ff240 76//function : PrsDim_MinRadiusDimension
7fd59977 77//purpose :
78//=======================================================================
79
787ff240 80PrsDim_MinRadiusDimension::PrsDim_MinRadiusDimension(const TopoDS_Shape& aShape,
7fd59977 81 const Standard_Real aVal,
82 const TCollection_ExtendedString& aText,
83 const gp_Pnt& aPosition,
84 const DsgPrs_ArrowSide aSymbolPrs,
85 const Standard_Real anArrowSize)
787ff240 86:PrsDim_EllipseRadiusDimension(aShape, aText)
7fd59977 87{
88 myVal = aVal;
89 mySymbolPrs = aSymbolPrs;
90 myPosition = aPosition;
91 myAutomaticPosition = Standard_False;
7fd59977 92 SetArrowSize( anArrowSize );
7fd59977 93}
94
95//=======================================================================
96//function : Compute
97//purpose :
98//=======================================================================
99
787ff240 100void PrsDim_MinRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
7fd59977 101 const Handle(Prs3d_Presentation)& aPresentation,
102 const Standard_Integer /*aMode*/)
103{
7fd59977 104// if( myAutomaticPosition )
105 //{ //ota : recompute ellipse always
106 ComputeGeometry();
107 myEllipse.SetMinorRadius(myVal);
108 gp_Vec v1(myEllipse.YAxis().Direction());
109 v1 *=myVal;
110 myApexP = myEllipse.Location().Translated(v1);
111 myApexN = myEllipse.Location().Translated(-v1);
112// }
113 if(myIsAnArc) ComputeArcOfEllipse(aPresentation);
114 else
115 ComputeEllipse(aPresentation);
116}
117
118//=======================================================================
7fd59977 119//function : ComputeEllipse
120//purpose :
121//=======================================================================
122
787ff240 123void PrsDim_MinRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 124{
125
a6eb515f 126 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
127 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 128
129 // size
7fd59977 130 if( !myArrowSizeIsDefined ) {
131 myArrowSize = Min(myArrowSize,myVal/5.);
132 }
133 arr->SetLength(myArrowSize);
7fd59977 134
135 Standard_Real U;//,V;
136 gp_Pnt curPos, Center;
137 Center = myEllipse.Location();
138 if( myAutomaticPosition )
139 {
140 myPosition = Center;
141 myEndOfArrow = myApexP;
142 myAutomaticPosition = Standard_True;
143
144 if ( myIsSetBndBox )
787ff240 145 myPosition = PrsDim::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
7fd59977 146 myBndBox );
147 curPos = myPosition;
148 }
149 else //!AutomaticPosition
150 {
151 curPos = myPosition;
152 gp_Lin L1(myEllipse.YAxis());
153 U = ElCLib::Parameter ( L1, curPos );
154 curPos = ElCLib::Value (U, L1);
155 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
156 myEndOfArrow = myApexP ;
157 else
158 myEndOfArrow = myApexN ;
159 myPosition = curPos;
160 }
161
162 // Presenatation
163 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
164 myEndOfArrow, Center, Standard_False, mySymbolPrs);
165
166}
167
168//=======================================================================
169//function : ComputeArcOfEllipse
170//purpose :
171//=======================================================================
172
787ff240 173void PrsDim_MinRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 174{
175
a6eb515f 176 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
177 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 178
179 // size
7fd59977 180 if( !myArrowSizeIsDefined ) {
181 myArrowSize = Min(myArrowSize,myVal/5.);
182 }
183 arr->SetLength(myArrowSize);
7fd59977 184
185 Standard_Real par;
186 gp_Pnt curPos, Center;
187 Center = myEllipse.Location();
188 Standard_Boolean IsInDomain = Standard_True;
189 if( myAutomaticPosition )
190 {
787ff240 191 myEndOfArrow = PrsDim::NearestApex(myEllipse, myApexP, myApexN,
7fd59977 192 myFirstPar, myLastPar, IsInDomain);
193 myPosition = Center;
194 myAutomaticPosition = Standard_True;
195 if ( myIsSetBndBox )
787ff240 196 myPosition = PrsDim::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
7fd59977 197 myBndBox );
198 curPos = myPosition;
199
200 }
201 else //!AutomaticPosition
202 {
203 curPos = myPosition;
204 gp_Lin L1(myEllipse.YAxis());
205 par = ElCLib::Parameter ( L1, curPos );
206 curPos = ElCLib::Value (par, L1);
207 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
208 myEndOfArrow = myApexP ;
209 else
210 myEndOfArrow = myApexN ;
211 par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
787ff240 212 IsInDomain = PrsDim::InDomain(myFirstPar, myLastPar, par);
7fd59977 213 myPosition = curPos;
214 }
215
216 Standard_Real parStart =0.;
217 if( !IsInDomain )
218 {
787ff240 219 if(PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
220 PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
7fd59977 221 parStart = myFirstPar;
222 else
223 parStart = myLastPar;
224
225 }
226
227 if(!myIsOffset)
228 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
229 curPos, myEndOfArrow, Center, parStart, IsInDomain,
230 Standard_True, mySymbolPrs);
231 else
232 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
233 curPos, myEndOfArrow, Center, parStart, IsInDomain,
234 Standard_True, mySymbolPrs);
235}
236
237
238//=======================================================================
239//function : ComputeSelection
240//purpose :
241//=======================================================================
242
787ff240 243void PrsDim_MinRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
7fd59977 244 const Standard_Integer /*aMode*/)
245{
246
247 gp_Pnt center = myEllipse.Location();
248 gp_Pnt AttachmentPoint = myPosition;
249 Standard_Real dist = center.Distance(AttachmentPoint);
250 Standard_Real aRadius = myVal;
251 //Standard_Real inside = Standard_False;
252 gp_Pnt pt1;
253 if (dist > aRadius) pt1 = AttachmentPoint;
254 else
255 pt1 = myEndOfArrow;
256 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
257 Handle(Select3D_SensitiveSegment)
258 seg = new Select3D_SensitiveSegment(own, center , pt1);
259 aSelection->Add(seg);
260
261 // Text
262 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
263 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
264 AttachmentPoint.X(),
265 AttachmentPoint.Y(),
266 AttachmentPoint.Z(),
267 AttachmentPoint.X()+size,
268 AttachmentPoint.Y()+size,
269 AttachmentPoint.Z()+size);
270 aSelection->Add(box);
271
272 // Arc of Ellipse
273 if(myIsAnArc)
274 {
275
276 Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
787ff240 277 if(!PrsDim::InDomain(myFirstPar, myLastPar, parEnd))
7fd59977 278 {
279 Standard_Real parStart, par;
787ff240 280 if(PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
281 PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
7fd59977 282 par = myFirstPar;
283 else
284 par = myLastPar;
285 gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
286 gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
287 gp_Dir dir(Vpnt ^ Vapex);
288 if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
289 parStart = parEnd;
290 parEnd = par;
291 }
292 else
293 parStart = par;
c04c30b3 294 Handle(Geom_Curve)TrimCurve;
7fd59977 295 if(myIsOffset)
296 {
297 Handle(Geom_Curve) aCurve = myOffsetCurve;
298 TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd );
299 }
300 else
301 {
302 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
303 TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd );
304 }
305 Handle( Select3D_SensitiveCurve ) SensArc;
306 SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
307 aSelection->Add( SensArc );
308 }
309 }
310
311}