0023365: Name collision of global IsEqual() leads to overriding user's definition
[occt.git] / src / AIS / AIS_MaxRadiusDimension.cxx
1 // Created on: 1998-01-23
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #define BUC60915        //GG 05/06/01 Enable to compute the requested arrow size
23 //                      if any in all dimensions.
24
25 #include <Standard_NotImplemented.hxx>
26
27 #include <AIS_MaxRadiusDimension.ixx>
28 #include <AIS_EllipseRadiusDimension.hxx>
29 #include <TCollection_ExtendedString.hxx>
30
31 #include <Prs3d_LengthAspect.hxx>
32 #include <Prs3d_ArrowAspect.hxx>
33 #include <Prs3d_Drawer.hxx>
34 #include <Prs3d_TextAspect.hxx>
35 #include <Prs3d_Text.hxx> 
36
37 #include <Select3D_SensitiveSegment.hxx>
38 #include <Select3D_SensitiveCurve.hxx>
39 #include <Select3D_SensitiveBox.hxx>
40 #include <SelectMgr_EntityOwner.hxx>
41
42 #include <ElCLib.hxx>
43 #include <ElSLib.hxx>
44
45 #include <TopoDS.hxx>
46
47 #include <BRepAdaptor_Surface.hxx>
48 #include <BRepAdaptor_Curve.hxx>
49
50 #include <Geom_Ellipse.hxx>
51 #include <Geom_TrimmedCurve.hxx>
52 #include <Geom_Plane.hxx>
53 #include <Geom_Surface.hxx>
54 #include <Geom_CylindricalSurface.hxx>
55 #include <Geom_SurfaceOfRevolution.hxx>
56 #include <Geom_CylindricalSurface.hxx>
57 #include <Geom_SurfaceOfLinearExtrusion.hxx>
58
59 #include <gp_Pln.hxx>
60 #include <gp_Pnt.hxx>
61 #include <gp_Lin.hxx>
62 #include <gp_Ax1.hxx>
63 #include <gp_Dir.hxx>
64 #include <gp_Vec.hxx>
65
66 #include <AIS.hxx>
67 #include <AIS_Drawer.hxx>
68
69 #include <Precision.hxx>
70 #include <DsgPrs_EllipseRadiusPresentation.hxx>
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 :AIS_EllipseRadiusDimension(aShape, aText)
81 {
82   myVal = aVal;
83   mySymbolPrs = DsgPrs_AS_LASTAR;
84   myAutomaticPosition = Standard_True;
85   myArrowSize = myVal / 100.;
86 }
87
88 //=======================================================================
89 //function : AIS_MaxRadiusDimension
90 //purpose  : 
91 //=======================================================================
92
93 AIS_MaxRadiusDimension::AIS_MaxRadiusDimension(const TopoDS_Shape& aShape, 
94                                                const Standard_Real aVal, 
95                                                const TCollection_ExtendedString& aText,
96                                                const gp_Pnt& aPosition, 
97                                                const DsgPrs_ArrowSide aSymbolPrs,
98                                                const Standard_Real anArrowSize)
99 :AIS_EllipseRadiusDimension(aShape, aText)
100 {
101   myVal = aVal;
102   mySymbolPrs = aSymbolPrs;
103   myPosition = aPosition;
104   myAutomaticPosition = Standard_False;
105 #ifdef BUC60915
106   SetArrowSize( anArrowSize );
107 #else
108   myArrowSize = anArrowSize;
109 #endif
110 }
111
112 //=======================================================================
113 //function : Compute
114 //purpose  : 
115 //=======================================================================
116
117 void AIS_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
118                                      const Handle(Prs3d_Presentation)& aPresentation, 
119                                      const Standard_Integer /*aMode*/)
120 {
121   aPresentation->Clear();
122
123 //  if( myAutomaticPosition )
124     {//ota : recompute in any case 
125       ComputeGeometry();
126       myEllipse.SetMajorRadius(myVal);
127       gp_Vec v1(myEllipse.XAxis().Direction());
128       v1 *=myVal;
129       myApexP = myEllipse.Location().Translated(v1); 
130       myApexN = myEllipse.Location().Translated(-v1); 
131     }
132   if(myIsAnArc) ComputeArcOfEllipse(aPresentation);
133   else 
134     ComputeEllipse(aPresentation);
135 }
136
137 //=======================================================================
138 //function : Compute
139 //purpose  : to avoid warning
140 //=======================================================================
141
142 void  AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
143                                       const Handle(Prs3d_Presentation)& aPresentation)
144 {
145 // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)");
146  PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
147 }
148
149 //=======================================================================
150 //function : Compute
151 //purpose  : to avoid warning
152 //=======================================================================
153
154 void  AIS_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager,
155                                       const Handle(Graphic2d_GraphicObject)& aPresentation,
156                                       const Standard_Integer aMode)
157 {
158 // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager, const Handle(Graphic2d_GraphicObject)& aPresentation, const Standard_Integer aMode)");
159  PrsMgr_PresentableObject::Compute( aPresentationManager ,aPresentation,aMode) ;
160 }
161
162 //=======================================================================
163 //function : Compute
164 //purpose  : 
165 //=======================================================================
166
167 void AIS_MaxRadiusDimension::Compute(const Handle_Prs3d_Projector& aProjector,
168                                      const Handle_Geom_Transformation& aTransformation,
169                                      const Handle_Prs3d_Presentation& aPresentation)
170 {
171 // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
172  PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
173 }
174
175
176 //=======================================================================
177 //function : ComputeEllipse
178 //purpose  : 
179 //=======================================================================
180
181 void AIS_MaxRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
182 {
183
184   Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
185   Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
186   
187   // size
188 #ifdef BUC60915
189   if( !myArrowSizeIsDefined ) {
190     myArrowSize = Min(myArrowSize,myVal / 5.);
191   }
192   arr->SetLength(myArrowSize);
193 #else
194   if (myVal / 5. > myArrowSize) {
195     arr->SetLength(myArrowSize);
196   }
197   else {
198     arr->SetLength(myVal / 5.);
199   }
200 #endif
201
202   Standard_Real U;//,V;
203   gp_Pnt curPos, Center;
204   Center = myEllipse.Location();
205   if( myAutomaticPosition )
206     {
207       myPosition = Center;
208       myEndOfArrow = myApexP;
209       myAutomaticPosition = Standard_True;   
210       
211       if ( myIsSetBndBox )
212         myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
213                                                 myBndBox );        
214       curPos = myPosition;  
215     }
216   else //!AutomaticPosition
217     {
218       curPos = myPosition;
219       gp_Lin L1(myEllipse.XAxis());
220       U = ElCLib::Parameter ( L1, curPos );
221       curPos = ElCLib::Value (U, L1);
222       if (curPos.Distance(myApexP) < curPos.Distance(myApexN)) 
223         myEndOfArrow = myApexP ;
224       else
225         myEndOfArrow = myApexN ;
226     }
227  
228   // Presenatation  
229   DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
230                                         myEndOfArrow, Center, Standard_True, mySymbolPrs);
231
232 }
233
234 //=======================================================================
235 //function : ComputeArcOfEllipse
236 //purpose  : 
237 //=======================================================================
238
239 void AIS_MaxRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
240 {
241
242   Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
243   Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
244   
245   // size
246 #ifdef BUC60915
247   if( !myArrowSizeIsDefined ) {
248     myArrowSize = Min(myArrowSize,myVal / 5.);
249   }
250   arr->SetLength(myArrowSize);
251 #else
252   if (myVal / 5. > myArrowSize) {
253     arr->SetLength(myArrowSize);
254   }
255   else {
256     arr->SetLength(myVal / 5.);
257   }
258 #endif
259   
260   Standard_Real par;
261   gp_Pnt curPos, Center;
262   Center = myEllipse.Location();
263   Standard_Boolean IsInDomain = Standard_True;
264   if( myAutomaticPosition )
265     {
266       myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN,
267                                       myFirstPar, myLastPar, IsInDomain);
268       myPosition = Center;
269       myAutomaticPosition = Standard_True;
270       if ( myIsSetBndBox )
271         myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
272                                                 myBndBox );
273       curPos = myPosition;  
274     }
275   else //!AutomaticPosition
276     {
277       curPos = myPosition;
278 //      ElSLib::Parameters ( myPlane->Pln(), curPos, U, V );
279 //      curPos = ElSLib::Value (U, V, myPlane->Pln());
280       gp_Lin L1(myEllipse.XAxis());
281       par = ElCLib::Parameter ( L1, curPos );
282       curPos = ElCLib::Value (par, L1);
283       if (curPos.Distance(myApexP) < curPos.Distance(myApexN)) 
284         myEndOfArrow = myApexP ;
285       else
286         myEndOfArrow = myApexN ;
287       par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
288       IsInDomain = AIS::InDomain( myFirstPar, myLastPar, par );
289       myPosition = curPos;
290     }
291
292 //  Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
293   Standard_Real parStart = 0.;
294   if( !IsInDomain )
295     {
296       if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
297          AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
298         parStart = myFirstPar;
299       else
300         parStart = myLastPar;
301     }
302   if(!myIsOffset)
303     DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
304                                           curPos, myEndOfArrow, Center, parStart, IsInDomain,
305                                           Standard_True, mySymbolPrs);
306   else 
307     DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
308                                           curPos, myEndOfArrow, Center, parStart, IsInDomain,
309                                           Standard_True, mySymbolPrs);
310 }
311
312 //=======================================================================
313 //function : ComputeSelection
314 //purpose  : 
315 //=======================================================================
316
317 void AIS_MaxRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, 
318                                               const Standard_Integer /*aMode*/)
319 {
320
321     gp_Pnt        center  = myEllipse.Location();
322     gp_Pnt AttachmentPoint = myPosition;
323     Standard_Real dist    = center.Distance(AttachmentPoint);
324     Standard_Real aRadius = myVal;
325     //Standard_Real inside  = Standard_False;
326     gp_Pnt pt1;
327     if (dist > aRadius) pt1 = AttachmentPoint; 
328     else 
329       pt1 = myEndOfArrow;
330     Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
331     Handle(Select3D_SensitiveSegment) 
332       seg = new Select3D_SensitiveSegment(own, center , pt1);
333     aSelection->Add(seg);
334
335     // Text
336     Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
337     Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
338                                                                      AttachmentPoint.X(),
339                                                                      AttachmentPoint.Y(),
340                                                                      AttachmentPoint.Z(),
341                                                                      AttachmentPoint.X()+size,
342                                                                      AttachmentPoint.Y()+size,
343                                                                      AttachmentPoint.Z()+size);
344   aSelection->Add(box);
345
346   // Arc of Ellipse
347     if(myIsAnArc)
348       {
349         
350         Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
351         if(!AIS::InDomain(myFirstPar, myLastPar, parEnd))
352           {
353             Standard_Real parStart, par;
354             if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
355                AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
356               par = myFirstPar;
357             else
358               par = myLastPar;
359             gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
360             gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
361             gp_Dir dir(Vpnt ^ Vapex);
362             if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
363               parStart = parEnd;
364               parEnd   = par;
365             }
366             else 
367               parStart = par;
368
369             Handle(Geom_TrimmedCurve)TrimCurve;
370             if(myIsOffset)
371               {
372                 Handle(Geom_Curve) aCurve = myOffsetCurve;
373                 TrimCurve = new Geom_TrimmedCurve( aCurve,  parStart, parEnd );
374               }
375             else
376               {
377                 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
378                 TrimCurve = new Geom_TrimmedCurve( Ellipse,  parStart, parEnd );
379               }
380             Handle( Select3D_SensitiveCurve ) SensArc;
381             SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
382             aSelection->Add( SensArc );
383           }
384     }
385
386 }