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