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