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