0024624: Lost word in license statement in source files
[occt.git] / src / AIS / AIS_Chamf2dDimension.cxx
1 // Created on: 1996-12-05
2 // Created by: Flore Lantheaume/Odile Olivier
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #define BUC60915        //GG 05/06/01 Enable to compute the requested arrow size
18 //                      if any in all dimensions.
19
20 #include <Standard_NotImplemented.hxx>
21
22 #include <AIS_Chamf2dDimension.ixx>
23
24 #include <DsgPrs_Chamf2dPresentation.hxx>
25
26 #include <Prs3d_ArrowAspect.hxx>
27 #include <Prs3d_DimensionAspect.hxx>
28 #include <Prs3d_Drawer.hxx>
29
30 #include <SelectMgr_EntityOwner.hxx>
31 #include <Select3D_SensitiveSegment.hxx>
32
33 #include <TopoDS.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36
37 #include <TopAbs_Orientation.hxx>
38
39 #include <Bnd_Box.hxx>
40 #include <BRepBndLib.hxx>
41
42 #include <gp_Dir.hxx>
43 #include <gp_Pln.hxx>
44 #include <gp_Vec.hxx>
45
46 #include <Geom_Line.hxx>
47
48 #include <ElCLib.hxx>
49
50 #include <Precision.hxx>
51
52 #include <TCollection_AsciiString.hxx>
53 #include <TCollection_ExtendedString.hxx>
54
55 #include <BRepTools_WireExplorer.hxx>
56
57 #include <AIS.hxx>
58 #include <AIS_Drawer.hxx>
59
60 #include <BRepAdaptor_Surface.hxx>
61 #include <ProjLib.hxx>
62 #include <Select3D_SensitiveBox.hxx>
63
64 //=======================================================================
65 //function : Constructor
66 //purpose  : 
67 //=======================================================================
68 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape, 
69                                            const Handle(Geom_Plane)& aPlane, 
70                                            const Standard_Real aVal, 
71                                            const TCollection_ExtendedString& aText)
72 :AIS_Relation()
73 {
74   myFShape = aFShape;
75   myPlane = aPlane;
76   myVal = aVal;
77   myText = aText;
78   mySymbolPrs = DsgPrs_AS_LASTAR;
79   myAutomaticPosition = Standard_True;
80
81   myArrowSize = myVal / 100.;
82 }
83 //=======================================================================
84 //function : Constructor
85 //purpose  : 
86 //=======================================================================
87 AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape, 
88                                            const Handle(Geom_Plane)& aPlane, 
89                                            const Standard_Real aVal, 
90                                            const TCollection_ExtendedString& aText,
91                                            const gp_Pnt& aPosition, 
92                                            const DsgPrs_ArrowSide aSymbolPrs ,
93                                            const Standard_Real anArrowSize)
94 :AIS_Relation()
95 {
96   myFShape = aFShape;
97   myPlane = aPlane;
98   myVal = aVal;
99   myText = aText;
100   myPosition = aPosition;
101   mySymbolPrs = aSymbolPrs;
102 #ifdef BUC60915
103   SetArrowSize( anArrowSize );
104 #else
105   myArrowSize = anArrowSize;
106 #endif
107   myAutomaticPosition = Standard_False;
108 }
109
110
111 //=======================================================================
112 //function : Compute
113 //purpose  : 
114 //=======================================================================
115
116 void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& , 
117                                    const Handle(Prs3d_Presentation)& aPresentation, 
118                                    const Standard_Integer)
119 {
120     aPresentation->Clear();
121
122     Handle(Geom_Line) glin;
123     gp_Pnt pfirst,plast;
124     const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape);
125     if (!AIS::ComputeGeometry(thechamfedge, glin,pfirst,plast) ) 
126       return;
127
128
129     gp_Dir dir1 (glin->Position().Direction());
130     gp_Dir norm1 = myPlane->Pln().Axis().Direction();
131     myDir = norm1.Crossed(dir1);
132     
133
134     //-------------------------------------------------
135     // calcul d'une direction orthogonale a l'edge du
136     // chanfrein et dirigee vers l'ext. du contour
137     //-------------------------------------------------
138     
139
140     // recup. d'une edge adjacente a l'edge du chanfrein
141     /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape);
142
143     gp_Pnt pfirstnext,plastnext;
144     Handle(Geom_Line) glinnext;
145     if (!AIS::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) )
146       return;
147     
148     gp_Vec v1(pfirst,plast);
149     gp_Vec v2;
150     if (pfirst.IsEqual(plastnext, Precision::Confusion()))
151       v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ());
152     else
153       v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ());
154     gp_Vec crossvec = v1.Crossed(v2);
155     
156     myDir = dimserv.GetDirection().Crossed(glin->Position().Direction());
157     if (crossvec.Dot(dimserv.GetDirection()) > 0 )
158       myDir.Reverse();*/     //       myDir   => donne a la creation
159     
160     //--------------------------------------------
161     //Calcul du point de positionnement du texte
162     //--------------------------------------------
163     gp_Pnt curpos;
164     if (myAutomaticPosition) {
165       myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
166       gp_Vec transVec(myDir);
167       transVec*=myVal;
168       curpos = myPntAttach.Translated(transVec);
169
170       if (myIsSetBndBox)
171         curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
172
173       myPosition = curpos;
174     }
175     else {
176
177       myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
178       Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
179       Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
180       curpos = ElCLib::Value(parcurpos,dimLin->Lin());
181       //static Standard_Real minlength = 0.005;
182       //taille minimale de la dimension
183
184       if ( curpos.Distance(myPntAttach) < 5. ) {
185         gp_Vec transVec(myDir);
186         transVec*=5.;
187         curpos = myPntAttach.Translated(transVec);
188       }
189       myPosition = curpos;
190     }
191     
192     Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
193     Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
194     
195     //-------------------------------------------------
196     //Calcul de la boite englobante du component pour
197     //determiner la taille de la fleche
198     //-------------------------------------------------
199
200 #ifdef BUC60915
201     if( !myArrowSizeIsDefined ) {
202 #endif
203       Standard_Real arrsize = myArrowSize;
204       if ( (myVal/4) < arrsize)
205         arrsize = myVal/4;
206       if (arrsize > 30.) 
207         arrsize = 30.;
208       else if (arrsize < 8.)
209         arrsize = 8.;
210 #ifdef BUC60915
211       myArrowSize = arrsize;
212     }
213     arr->SetLength(myArrowSize);
214 #else
215     arr->SetLength(arrsize);
216 #endif
217     
218     //Calcul de la presentation
219     DsgPrs_Chamf2dPresentation::Add(aPresentation,
220                                     myDrawer,
221                                     myPntAttach,
222                                     curpos,
223                                     myText,
224                                     mySymbolPrs);
225   
226   }
227
228 //=======================================================================
229 //function : Compute
230 //purpose  : to avoid warning
231 //=======================================================================
232
233 void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
234                                    const Handle(Prs3d_Presentation)& aPresentation)
235 {
236 // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
237  PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
238 }
239
240 void AIS_Chamf2dDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
241 {
242 // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
243   PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
244 }
245
246 //=======================================================================
247 //function : ComputeSelection
248 //purpose  : 
249 //=======================================================================
250
251 void AIS_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, 
252                                             const Standard_Integer)
253 {
254   Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
255   Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
256   aSelection->Add(seg);
257
258   // Text
259   Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
260   Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
261                                                                    myPosition.X(),
262                                                                    myPosition.Y(),
263                                                                    myPosition.Z(),
264                                                                    myPosition.X() + size,
265                                                                    myPosition.Y() + size,
266                                                                    myPosition.Z() + size);    
267   aSelection->Add(box);
268 }
269