Integration of OCCT 6.5.0 from SVN
[occt.git] / src / AIS / AIS_MinRadiusDimension.cxx
... / ...
CommitLineData
1// File: AIS_MinRadiusDimension.cxx
2// Created: Tue Jan 27 11:17:01 1998
3// Author: Sergey ZARITCHNY
4// <szy@androx.nnov.matra-dtv.fr>
5
6#define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
7// if any in all dimensions.
8
9#include <Standard_NotImplemented.hxx>
10
11#include <AIS_MinRadiusDimension.ixx>
12
13#include <AIS_EllipseRadiusDimension.hxx>
14#include <TCollection_ExtendedString.hxx>
15
16#include <Prs3d_LengthAspect.hxx>
17#include <Prs3d_ArrowAspect.hxx>
18#include <Prs3d_Drawer.hxx>
19#include <Prs3d_TextAspect.hxx>
20#include <Prs3d_Text.hxx>
21
22#include <Select3D_SensitiveSegment.hxx>
23#include <Select3D_SensitiveCurve.hxx>
24#include <Select3D_SensitiveBox.hxx>
25#include <SelectMgr_EntityOwner.hxx>
26
27#include <ElCLib.hxx>
28#include <ElSLib.hxx>
29
30#include <TopoDS.hxx>
31
32#include <BRepAdaptor_Surface.hxx>
33#include <BRepAdaptor_Curve.hxx>
34
35#include <Geom_Ellipse.hxx>
36#include <Geom_TrimmedCurve.hxx>
37#include <Geom_Plane.hxx>
38#include <Geom_Surface.hxx>
39#include <Geom_CylindricalSurface.hxx>
40#include <Geom_SurfaceOfRevolution.hxx>
41#include <Geom_CylindricalSurface.hxx>
42#include <Geom_SurfaceOfLinearExtrusion.hxx>
43
44#include <gp_Pln.hxx>
45#include <gp_Pnt.hxx>
46#include <gp_Lin.hxx>
47#include <gp_Ax1.hxx>
48#include <gp_Dir.hxx>
49#include <gp_Vec.hxx>
50
51#include <AIS.hxx>
52#include <AIS_Drawer.hxx>
53
54#include <Precision.hxx>
55#include <DsgPrs_EllipseRadiusPresentation.hxx>
56
57
58//=======================================================================
59//function : AIS_MinRadiusDimension
60//purpose :
61//=======================================================================
62
63AIS_MinRadiusDimension::AIS_MinRadiusDimension(const TopoDS_Shape& aShape,
64 const Standard_Real aVal,
65 const TCollection_ExtendedString& aText)
66:AIS_EllipseRadiusDimension(aShape, aText)
67{
68 myVal = aVal;
69 mySymbolPrs = DsgPrs_AS_LASTAR;
70 myAutomaticPosition = Standard_True;
71 myArrowSize = myVal / 100.;
72}
73
74//=======================================================================
75//function : AIS_MinRadiusDimension
76//purpose :
77//=======================================================================
78
79AIS_MinRadiusDimension::AIS_MinRadiusDimension(const TopoDS_Shape& aShape,
80 const Standard_Real aVal,
81 const TCollection_ExtendedString& aText,
82 const gp_Pnt& aPosition,
83 const DsgPrs_ArrowSide aSymbolPrs,
84 const Standard_Real anArrowSize)
85:AIS_EllipseRadiusDimension(aShape, aText)
86{
87 myVal = aVal;
88 mySymbolPrs = aSymbolPrs;
89 myPosition = aPosition;
90 myAutomaticPosition = Standard_False;
91#ifdef BUC60915
92 SetArrowSize( anArrowSize );
93#else
94 myArrowSize = anArrowSize;
95#endif
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
135//=======================================================================
136//function : Compute
137//purpose : to avoid warning
138//=======================================================================
139
140void AIS_MinRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager,
141 const Handle(Graphic2d_GraphicObject)& aPresentation,
142 const Standard_Integer aMode)
143{
144// Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager, const Handle(Graphic2d_GraphicObject)& aPresentation, const Standard_Integer aMode)");
145 PrsMgr_PresentableObject::Compute( aPresentationManager ,aPresentation,aMode) ;
146}
147
148//=======================================================================
149//function : Compute
150//purpose :
151//=======================================================================
152
153void AIS_MinRadiusDimension::Compute(const Handle_Prs3d_Projector& aProjector,
154 const Handle_Geom_Transformation& aTransformation,
155 const Handle_Prs3d_Presentation& aPresentation)
156{
157// Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
158 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
159}
160
161//=======================================================================
162//function : ComputeEllipse
163//purpose :
164//=======================================================================
165
166void AIS_MinRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
167{
168
169 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
170 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
171
172 // size
173#ifdef BUC60915
174 if( !myArrowSizeIsDefined ) {
175 myArrowSize = Min(myArrowSize,myVal/5.);
176 }
177 arr->SetLength(myArrowSize);
178#else
179 if (myVal/5. > myArrowSize) {
180 arr->SetLength(myArrowSize);
181 }
182 else {
183 arr->SetLength(myVal/5.);
184 }
185#endif
186
187 Standard_Real U;//,V;
188 gp_Pnt curPos, Center;
189 Center = myEllipse.Location();
190 if( myAutomaticPosition )
191 {
192 myPosition = Center;
193 myEndOfArrow = myApexP;
194 myAutomaticPosition = Standard_True;
195
196 if ( myIsSetBndBox )
197 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
198 myBndBox );
199 curPos = myPosition;
200 }
201 else //!AutomaticPosition
202 {
203 curPos = myPosition;
204 gp_Lin L1(myEllipse.YAxis());
205 U = ElCLib::Parameter ( L1, curPos );
206 curPos = ElCLib::Value (U, L1);
207 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
208 myEndOfArrow = myApexP ;
209 else
210 myEndOfArrow = myApexN ;
211 myPosition = curPos;
212 }
213
214 // Presenatation
215 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
216 myEndOfArrow, Center, Standard_False, mySymbolPrs);
217
218}
219
220//=======================================================================
221//function : ComputeArcOfEllipse
222//purpose :
223//=======================================================================
224
225void AIS_MinRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
226{
227
228 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
229 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
230
231 // size
232#ifdef BUC60915
233 if( !myArrowSizeIsDefined ) {
234 myArrowSize = Min(myArrowSize,myVal/5.);
235 }
236 arr->SetLength(myArrowSize);
237#else
238 if (myVal/5. > myArrowSize) {
239 arr->SetLength(myArrowSize);
240 }
241 else {
242 arr->SetLength(myVal/5.);
243 }
244#endif
245
246 Standard_Real par;
247 gp_Pnt curPos, Center;
248 Center = myEllipse.Location();
249 Standard_Boolean IsInDomain = Standard_True;
250 if( myAutomaticPosition )
251 {
252 myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN,
253 myFirstPar, myLastPar, IsInDomain);
254 myPosition = Center;
255 myAutomaticPosition = Standard_True;
256 if ( myIsSetBndBox )
257 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
258 myBndBox );
259 curPos = myPosition;
260
261 }
262 else //!AutomaticPosition
263 {
264 curPos = myPosition;
265 gp_Lin L1(myEllipse.YAxis());
266 par = ElCLib::Parameter ( L1, curPos );
267 curPos = ElCLib::Value (par, L1);
268 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
269 myEndOfArrow = myApexP ;
270 else
271 myEndOfArrow = myApexN ;
272 par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
273 IsInDomain = AIS::InDomain(myFirstPar, myLastPar, par);
274 myPosition = curPos;
275 }
276
277 Standard_Real parStart =0.;
278 if( !IsInDomain )
279 {
280 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
281 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
282 parStart = myFirstPar;
283 else
284 parStart = myLastPar;
285
286 }
287
288 if(!myIsOffset)
289 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
290 curPos, myEndOfArrow, Center, parStart, IsInDomain,
291 Standard_True, mySymbolPrs);
292 else
293 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
294 curPos, myEndOfArrow, Center, parStart, IsInDomain,
295 Standard_True, mySymbolPrs);
296}
297
298
299//=======================================================================
300//function : ComputeSelection
301//purpose :
302//=======================================================================
303
304void AIS_MinRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
305 const Standard_Integer /*aMode*/)
306{
307
308 gp_Pnt center = myEllipse.Location();
309 gp_Pnt AttachmentPoint = myPosition;
310 Standard_Real dist = center.Distance(AttachmentPoint);
311 Standard_Real aRadius = myVal;
312 //Standard_Real inside = Standard_False;
313 gp_Pnt pt1;
314 if (dist > aRadius) pt1 = AttachmentPoint;
315 else
316 pt1 = myEndOfArrow;
317 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
318 Handle(Select3D_SensitiveSegment)
319 seg = new Select3D_SensitiveSegment(own, center , pt1);
320 aSelection->Add(seg);
321
322 // Text
323 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
324 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
325 AttachmentPoint.X(),
326 AttachmentPoint.Y(),
327 AttachmentPoint.Z(),
328 AttachmentPoint.X()+size,
329 AttachmentPoint.Y()+size,
330 AttachmentPoint.Z()+size);
331 aSelection->Add(box);
332
333 // Arc of Ellipse
334 if(myIsAnArc)
335 {
336
337 Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
338 if(!AIS::InDomain(myFirstPar, myLastPar, parEnd))
339 {
340 Standard_Real parStart, par;
341 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
342 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
343 par = myFirstPar;
344 else
345 par = myLastPar;
346 gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
347 gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
348 gp_Dir dir(Vpnt ^ Vapex);
349 if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
350 parStart = parEnd;
351 parEnd = par;
352 }
353 else
354 parStart = par;
355 Handle(Geom_TrimmedCurve)TrimCurve;
356 if(myIsOffset)
357 {
358 Handle(Geom_Curve) aCurve = myOffsetCurve;
359 TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd );
360 }
361 else
362 {
363 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
364 TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd );
365 }
366 Handle( Select3D_SensitiveCurve ) SensArc;
367 SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
368 aSelection->Add( SensArc );
369 }
370 }
371
372}