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