0023365: Name collision of global IsEqual() leads to overriding user's definition
[occt.git] / src / AIS / AIS_Chamf3dDimension.cxx
1 // Created on: 1996-12-05
2 // Created by: Odile Olivier
3 // Copyright (c) 1996-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_Chamf3dDimension.ixx>
28
29 #include <DsgPrs_Chamf2dPresentation.hxx>
30
31 #include <Prs3d_ArrowAspect.hxx>
32 #include <Prs3d_LengthAspect.hxx>
33 #include <Prs3d_Drawer.hxx>
34
35 #include <SelectMgr_EntityOwner.hxx>
36 #include <Select3D_SensitiveSegment.hxx>
37
38 #include <TopoDS.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
41
42 #include <TopAbs_Orientation.hxx>
43
44 #include <Bnd_Box.hxx>
45 #include <BRepBndLib.hxx>
46
47 #include <gp_Dir.hxx>
48 #include <gp_Pln.hxx>
49 #include <gp_Vec.hxx>
50
51 #include <Geom_Line.hxx>
52
53 #include <ElCLib.hxx>
54
55 #include <Precision.hxx>
56
57 #include <TCollection_AsciiString.hxx>
58 #include <TCollection_ExtendedString.hxx>
59
60 #include <BRepTools_WireExplorer.hxx>
61
62 #include <AIS.hxx>
63 #include <AIS_Drawer.hxx>
64
65 #include <BRepAdaptor_Surface.hxx>
66 #include <ProjLib.hxx>
67 #include <Select3D_SensitiveBox.hxx>
68
69 //=======================================================================
70 //function : Constructor
71 //purpose  : 
72 //=======================================================================
73 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape, 
74                                            const Standard_Real aVal, 
75                                            const TCollection_ExtendedString& aText)
76 :AIS_Relation()
77 {
78   myFShape = aFShape;
79   myVal = aVal;
80   myText = aText;
81   mySymbolPrs = DsgPrs_AS_LASTAR;
82   myAutomaticPosition = Standard_True;
83
84   myArrowSize = myVal / 100.;
85 }
86 //=======================================================================
87 //function : Constructor
88 //purpose  : 
89 //=======================================================================
90 AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape, 
91                                            const Standard_Real aVal, 
92                                            const TCollection_ExtendedString& aText,
93                                            const gp_Pnt& aPosition, 
94                                            const DsgPrs_ArrowSide aSymbolPrs ,
95                                            const Standard_Real anArrowSize)
96 :AIS_Relation()
97 {
98   myFShape = aFShape;
99   myVal = aVal;
100   myText = aText;
101   myPosition = aPosition;
102   mySymbolPrs = aSymbolPrs;
103 #ifdef BUC60915
104   SetArrowSize( anArrowSize );
105 #else
106   myArrowSize = anArrowSize;
107 #endif
108   myAutomaticPosition = Standard_False;
109 }
110
111
112 //=======================================================================
113 //function : Compute
114 //purpose  : 
115 //=======================================================================
116
117 void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& , 
118                                    const Handle(Prs3d_Presentation)& aPresentation, 
119                                    const Standard_Integer)
120 {
121   aPresentation->Clear();
122
123   //----------------------------
124   // Calcul du centre de la face
125   //----------------------------
126   BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
127   Standard_Real uFirst, uLast, vFirst, vLast;
128   uFirst = surfAlgo.FirstUParameter();
129   uLast = surfAlgo.LastUParameter();
130   vFirst = surfAlgo.FirstVParameter();
131   vLast = surfAlgo.LastVParameter();
132   Standard_Real uMoy = (uFirst + uLast)/2;
133   Standard_Real vMoy = (vFirst + vLast)/2;
134   gp_Pnt apos ;
135   gp_Vec d1u, d1v;
136   surfAlgo.D1(uMoy, vMoy, apos, d1u, d1v);
137   myPntAttach = apos;
138
139   myDir = d1u ^ d1v;
140 //  myDir = surfAlgo.Plane().Axis().Direction();
141
142
143  
144    
145   //--------------------------------------------
146   //Calcul du point de positionnement du texte
147   //--------------------------------------------
148   gp_Pnt curpos;
149   if (myAutomaticPosition) {
150     gp_Vec transVec(myDir);
151     transVec*=myVal;
152     curpos = myPntAttach.Translated(transVec);
153     
154     if (myIsSetBndBox)
155       curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
156     
157     myPosition = curpos;
158   }
159   else {
160     
161     Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
162     Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
163     curpos = ElCLib::Value(parcurpos,dimLin->Lin());
164
165     if ( curpos.Distance(myPntAttach) < 5. ) {
166       gp_Vec transVec(myDir);
167       transVec*=5.;
168       curpos = myPntAttach.Translated(transVec);
169     }
170     myPosition = curpos;
171   }
172     
173   Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
174   Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
175     
176   //-------------------------------------------------
177   //Calcul de la boite englobante du component pour
178   //determiner la taille de la fleche
179   //-------------------------------------------------
180 #ifdef BUC60915
181   if( !myArrowSizeIsDefined ) {
182 #endif
183     Standard_Real arrsize = myArrowSize;
184     if ( (myVal/4) < arrsize)
185       arrsize = myVal/4;
186     if (arrsize > 30.) 
187       arrsize = 30.;
188     else if (arrsize < 8.)
189       arrsize = 8.;
190 #ifdef BUC60915
191     myArrowSize = arrsize;
192   }
193   arr->SetLength(myArrowSize);
194 #else
195   arr->SetLength(arrsize);
196 #endif
197   
198   //Calcul de la presentation
199   DsgPrs_Chamf2dPresentation::Add(aPresentation,
200                                   myDrawer,
201                                   myPntAttach,
202                                   curpos,
203                                   myText,
204                                   mySymbolPrs);
205   
206 }
207
208 //=======================================================================
209 //function : Compute
210 //purpose  : to avoid warning
211 //=======================================================================
212
213 void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
214                                    const Handle(Prs3d_Presentation)& aPresentation)
215 {
216 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
217  PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
218 }
219
220 //=======================================================================
221 //function : Compute
222 //purpose  : to avoid warning
223 //=======================================================================
224
225 void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager2d,
226                                    const Handle(Graphic2d_GraphicObject)& aGraphicObject, 
227                                    const Standard_Integer anInteger)
228 {
229 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)");
230  PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
231 }
232
233 void AIS_Chamf3dDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
234 {
235 // Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
236   PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
237 }
238
239 //=======================================================================
240 //function : ComputeSelection
241 //purpose  : 
242 //=======================================================================
243
244 void AIS_Chamf3dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, 
245                                             const Standard_Integer)
246 {
247   Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
248   Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
249   aSelection->Add(seg);
250
251   // Text
252   Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
253   Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
254                                                                    myPosition.X(),
255                                                                    myPosition.Y(),
256                                                                    myPosition.Z(),
257                                                                    myPosition.X() + size,
258                                                                    myPosition.Y() + size,
259                                                                    myPosition.Z() + size);    
260   aSelection->Add(box);
261 }
262