b311480e |
1 | // Created on: 1996-09-04 |
2 | // Created by: Olga PILLOT |
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 | |
7fd59977 |
21 | |
22 | #include <LocOpe_Revol.ixx> |
23 | |
24 | |
25 | #include <BRepSweep_Revol.hxx> |
26 | |
27 | #include <TopExp_Explorer.hxx> |
28 | #include <LocOpe_BuildShape.hxx> |
29 | #include <gp_Ax1.hxx> |
30 | #include <gp_Trsf.hxx> |
31 | #include <gp_Circ.hxx> |
32 | #include <gp_Vec.hxx> |
33 | |
34 | #include <BRepTools_TrsfModification.hxx> |
35 | #include <BRepTools_Modifier.hxx> |
36 | #include <Geom_Curve.hxx> |
37 | #include <Geom_Circle.hxx> |
38 | |
39 | |
40 | #include <BRepLib_MakeVertex.hxx> |
41 | #include <TopoDS_Edge.hxx> |
42 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
43 | #include <TColgp_SequenceOfPnt.hxx> |
44 | |
45 | #include <LocOpe.hxx> |
46 | #include <TopoDS.hxx> |
47 | #include <TopExp.hxx> |
48 | #include <Precision.hxx> |
49 | |
50 | |
51 | static Standard_Boolean FindCircle(const gp_Ax1&, |
52 | const gp_Pnt&, |
53 | gp_Circ&); |
54 | |
55 | |
56 | //======================================================================= |
57 | //function : LocOpe_Revol |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | LocOpe_Revol::LocOpe_Revol() : myDone(Standard_False) |
62 | |
63 | {} |
64 | |
65 | |
66 | //======================================================================= |
67 | //function : Perform |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | void LocOpe_Revol::Perform(const TopoDS_Shape& Base, |
72 | const gp_Ax1& Axis, |
73 | const Standard_Real Angle) |
74 | { |
75 | myMap.Clear(); |
76 | myFirstShape.Nullify(); |
77 | myLastShape.Nullify(); |
78 | myBase.Nullify(); |
79 | myRes.Nullify(); |
80 | myBase = Base; |
81 | myAngle = Angle; |
82 | myAxis = Axis; |
83 | myAngTra = 0.; |
84 | myIsTrans = Standard_False; |
85 | IntPerf(); |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : Perform |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | void LocOpe_Revol::Perform(const TopoDS_Shape& Base, |
94 | const gp_Ax1& Axis, |
95 | const Standard_Real Angle, |
96 | const Standard_Real angledec) |
97 | { |
98 | myMap.Clear(); |
99 | myFirstShape.Nullify(); |
100 | myLastShape.Nullify(); |
101 | myBase.Nullify(); |
102 | myRes.Nullify(); |
103 | myBase = Base; |
104 | myAngle = Angle; |
105 | myAxis = Axis; |
106 | myAngTra = angledec; |
107 | myIsTrans = Standard_True; |
108 | IntPerf(); |
109 | } |
110 | |
111 | |
112 | //======================================================================= |
113 | //function : IntPerf |
114 | //purpose : |
115 | //======================================================================= |
116 | |
117 | void LocOpe_Revol::IntPerf() |
118 | { |
119 | TopoDS_Shape theBase = myBase; |
120 | BRepTools_Modifier Modif; |
121 | if (myIsTrans) { |
122 | gp_Trsf T; |
123 | T.SetRotation(myAxis,myAngTra); |
124 | Handle(BRepTools_TrsfModification) modbase = |
125 | new BRepTools_TrsfModification(T); |
126 | Modif.Init(theBase); |
127 | Modif.Perform(modbase); |
128 | theBase = Modif.ModifiedShape(theBase); |
129 | } |
130 | |
131 | BRepSweep_Revol theRevol(theBase,myAxis,myAngle); |
132 | |
133 | myFirstShape = theRevol.FirstShape(); |
134 | myLastShape = theRevol.LastShape(); |
135 | |
136 | TopExp_Explorer exp; |
137 | if (theBase.ShapeType() == TopAbs_FACE) { |
138 | for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) { |
139 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
140 | if (!myMap.IsBound(edg)) { |
141 | TopTools_ListOfShape thelist; |
142 | myMap.Bind(edg, thelist); |
143 | TopoDS_Shape desc = theRevol.Shape(edg); |
144 | if (!desc.IsNull()) { |
145 | myMap(edg).Append(desc); |
146 | } |
147 | } |
148 | } |
149 | myRes = theRevol.Shape(); |
150 | } |
151 | |
152 | else { |
153 | // Cas base != FACE |
154 | TopTools_IndexedDataMapOfShapeListOfShape theEFMap; |
155 | TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap); |
156 | TopTools_ListOfShape lfaces; |
157 | Standard_Boolean toremove = Standard_False; |
158 | for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) { |
159 | const TopoDS_Shape& edg = theEFMap.FindKey(i); |
160 | TopTools_ListOfShape thelist1; |
161 | myMap.Bind(edg, thelist1); |
162 | TopoDS_Shape desc = theRevol.Shape(edg); |
163 | if (!desc.IsNull()) { |
164 | if (theEFMap(i).Extent() >= 2) { |
165 | toremove = Standard_True; |
166 | } |
167 | else { |
168 | myMap(edg).Append(desc); |
169 | lfaces.Append(desc); |
170 | } |
171 | } |
172 | } |
173 | if(toremove) { |
174 | // Rajouter les faces de FirstShape et LastShape |
175 | for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) { |
176 | lfaces.Append(exp.Current()); |
177 | } |
178 | for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) { |
179 | lfaces.Append(exp.Current()); |
180 | } |
181 | |
182 | LocOpe_BuildShape BS(lfaces); |
183 | myRes = BS.Shape(); |
184 | } |
185 | else { |
186 | for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) { |
187 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
188 | if (!myMap.IsBound(edg)) { |
189 | TopTools_ListOfShape thelist2; |
190 | myMap.Bind(edg, thelist2); |
191 | TopoDS_Shape desc = theRevol.Shape(edg); |
192 | if (!desc.IsNull()) { |
193 | myMap(edg).Append(desc); |
194 | } |
195 | } |
196 | } |
197 | myRes = theRevol.Shape(); |
198 | } |
199 | } |
200 | |
201 | if (myIsTrans) { |
202 | // m-a-j des descendants |
203 | TopExp_Explorer exp; |
204 | for (exp.Init(myBase,TopAbs_EDGE);exp.More();exp.Next()) { |
205 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
206 | const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg)); |
207 | if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) { |
208 | myMap.Bind(edg,myMap(edgbis)); |
209 | myMap.UnBind(edgbis); |
210 | } |
211 | } |
212 | } |
213 | myDone = Standard_True; |
214 | } |
215 | |
216 | //======================================================================= |
217 | //function : Shape |
218 | //purpose : |
219 | //======================================================================= |
220 | |
221 | const TopoDS_Shape& LocOpe_Revol::Shape () const |
222 | { |
223 | if (!myDone) { |
224 | StdFail_NotDone::Raise(); |
225 | } |
226 | return myRes; |
227 | } |
228 | |
229 | |
230 | //======================================================================= |
231 | //function : FirstShape |
232 | //purpose : |
233 | //======================================================================= |
234 | |
235 | const TopoDS_Shape& LocOpe_Revol::FirstShape () const |
236 | { |
237 | return myFirstShape; |
238 | } |
239 | |
240 | //======================================================================= |
241 | //function : LastShape |
242 | //purpose : |
243 | //======================================================================= |
244 | |
245 | const TopoDS_Shape& LocOpe_Revol::LastShape () const |
246 | { |
247 | return myLastShape; |
248 | } |
249 | |
250 | |
251 | //======================================================================= |
252 | //function : Shapes |
253 | //purpose : |
254 | //======================================================================= |
255 | |
256 | const TopTools_ListOfShape& LocOpe_Revol::Shapes (const TopoDS_Shape& S) const |
257 | { |
258 | return myMap(S); |
259 | } |
260 | |
261 | |
262 | //======================================================================= |
263 | //function : Curves |
264 | //purpose : |
265 | //======================================================================= |
266 | |
267 | void LocOpe_Revol::Curves(TColGeom_SequenceOfCurve& Scurves) const |
268 | { |
269 | Scurves.Clear(); |
270 | TColgp_SequenceOfPnt spt; |
271 | LocOpe::SampleEdges(myFirstShape,spt); |
272 | for (Standard_Integer jj=1;jj<=spt.Length(); jj++) { |
273 | const gp_Pnt& pvt = spt(jj); |
274 | gp_Circ CAX; |
275 | if (FindCircle(myAxis,pvt,CAX)) { |
276 | gp_Ax2 A2 = CAX.Position(); |
277 | Standard_Real r = CAX.Radius(); |
278 | Handle(Geom_Circle) Ci = new Geom_Circle(A2, r); |
279 | Scurves.Append(Ci); |
280 | } |
281 | } |
282 | } |
283 | |
284 | //======================================================================= |
285 | //function : BarycCurve |
286 | //purpose : |
287 | //======================================================================= |
288 | |
289 | Handle(Geom_Curve) LocOpe_Revol::BarycCurve() const |
290 | { |
291 | gp_Pnt bar(0., 0., 0.); |
292 | TColgp_SequenceOfPnt spt; |
293 | LocOpe::SampleEdges(myFirstShape,spt); |
294 | for (Standard_Integer jj=1;jj<=spt.Length(); jj++) { |
295 | const gp_Pnt& pvt = spt(jj); |
296 | bar.ChangeCoord() += pvt.XYZ(); |
297 | } |
298 | bar.ChangeCoord().Divide(spt.Length()); |
299 | gp_Circ CAX; |
300 | Handle(Geom_Circle) theCi; |
301 | if (FindCircle(myAxis,bar,CAX)) { |
302 | gp_Ax2 A2 = CAX.Position(); |
303 | Standard_Real r = CAX.Radius(); |
304 | theCi = new Geom_Circle(A2, r); |
305 | } |
306 | return theCi; |
307 | } |
308 | |
309 | |
310 | |
311 | //======================================================================= |
312 | //function : FincCircle |
313 | //purpose : |
314 | //======================================================================= |
315 | |
316 | static Standard_Boolean FindCircle(const gp_Ax1& Ax, |
317 | const gp_Pnt& Pt, |
318 | gp_Circ& Ci) |
319 | { |
320 | |
321 | const gp_Dir& Dax = Ax.Direction(); |
322 | gp_Vec OP(Ax.Location(),Pt); |
323 | |
324 | Standard_Real prm = OP.Dot(Dax); |
325 | |
326 | gp_Pnt prj(Ax.Location().XYZ().Added(prm*Dax.XYZ())); |
327 | gp_Vec axx(prj,Pt); |
328 | Standard_Real Radius = axx.Magnitude(); |
329 | if (Radius < Precision::Confusion()) { |
330 | return Standard_False; |
331 | } |
332 | Ci.SetRadius(Radius); |
333 | Ci.SetPosition(gp_Ax2(prj,Dax,axx)); |
334 | return Standard_True; |
335 | } |