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_LinearForm.ixx> |
23 | |
24 | |
25 | #include <BRepSweep_Prism.hxx> |
26 | |
27 | #include <TopExp.hxx> |
28 | #include <TopExp_Explorer.hxx> |
29 | |
30 | #include <TopoDS.hxx> |
31 | #include <TopoDS_Face.hxx> |
32 | #include <TopoDS_Edge.hxx> |
33 | #include <TopoDS_Compound.hxx> |
34 | |
35 | #include <BRep_Builder.hxx> |
36 | |
37 | #include <LocOpe_BuildShape.hxx> |
38 | #include <LocOpe.hxx> |
39 | |
40 | #include <gp_Ax1.hxx> |
41 | #include <gp_Trsf.hxx> |
42 | |
43 | #include <BRepTools_TrsfModification.hxx> |
44 | #include <BRepTools_Modifier.hxx> |
45 | |
46 | #include <BRep_Tool.hxx> |
47 | |
48 | #include <BRepLib_MakeEdge.hxx> |
49 | |
50 | #include <Geom_Line.hxx> |
51 | #include <Geom_Curve.hxx> |
52 | #include <Geom_TrimmedCurve.hxx> |
53 | |
54 | #include <BRepLib_MakeVertex.hxx> |
55 | |
56 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
57 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
58 | |
59 | #include <TColgp_SequenceOfPnt.hxx> |
60 | |
61 | |
62 | |
63 | |
64 | //======================================================================= |
65 | //function : Perform |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | void LocOpe_LinearForm::Perform(const TopoDS_Shape& Base, |
70 | const gp_Vec& V, |
71 | const gp_Pnt& Pnt1, |
72 | const gp_Pnt& Pnt2) |
73 | |
74 | { |
75 | myIsTrans = Standard_False; |
76 | myMap.Clear(); |
77 | myFirstShape.Nullify(); |
78 | myLastShape.Nullify(); |
79 | myBase.Nullify(); |
80 | myRes.Nullify(); |
81 | |
82 | myBase = Base; |
83 | myVec = V; |
84 | |
85 | //myEdge = E; |
86 | myPnt1 = Pnt1; |
87 | myPnt2 = Pnt2; |
88 | |
89 | IntPerf(); |
90 | } |
91 | |
92 | |
93 | //======================================================================= |
94 | //function : Perform |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | void LocOpe_LinearForm::Perform(const TopoDS_Shape& Base, |
99 | const gp_Vec& V, |
100 | const gp_Vec& Vectra, |
101 | const gp_Pnt& Pnt1, |
102 | const gp_Pnt& Pnt2) |
103 | |
104 | { |
105 | myIsTrans = Standard_True; |
106 | myTra = Vectra; |
107 | myMap.Clear(); |
108 | myFirstShape.Nullify(); |
109 | myLastShape.Nullify(); |
110 | myBase.Nullify(); |
111 | myRes.Nullify(); |
112 | |
113 | myBase = Base; |
114 | myVec = V; |
115 | |
116 | //myEdge = E; |
117 | myPnt1 = Pnt1; |
118 | myPnt2 = Pnt2; |
119 | |
120 | |
121 | IntPerf(); |
122 | } |
123 | |
124 | //======================================================================= |
125 | //function : IntPerf |
126 | //purpose : |
127 | //======================================================================= |
128 | |
129 | void LocOpe_LinearForm::IntPerf() |
130 | { |
131 | TopoDS_Shape theBase = myBase; |
132 | BRepTools_Modifier Modif; |
133 | |
134 | if (myIsTrans) { |
135 | gp_Trsf T; |
136 | T.SetTranslation(myTra); |
137 | Handle(BRepTools_TrsfModification) modbase = |
138 | new BRepTools_TrsfModification(T); |
139 | Modif.Init(theBase); |
140 | Modif.Perform(modbase); |
141 | theBase = Modif.ModifiedShape(theBase); |
142 | } |
143 | |
144 | BRepSweep_Prism myPrism(theBase, myVec); |
145 | |
146 | myFirstShape = myPrism.FirstShape(); |
147 | myLastShape = myPrism.LastShape(); |
148 | |
149 | TopExp_Explorer exp; |
150 | if (theBase.ShapeType() == TopAbs_FACE) { |
151 | for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) { |
152 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
153 | if (!myMap.IsBound(edg)) { |
154 | TopTools_ListOfShape thelist; |
155 | myMap.Bind(edg, thelist); |
156 | TopoDS_Shape desc = myPrism.Shape(edg); |
157 | if (!desc.IsNull()) { |
158 | myMap(edg).Append(desc); |
159 | } |
160 | } |
161 | } |
162 | myRes = myPrism.Shape(); |
163 | } |
164 | |
165 | else { |
166 | // Cas base != FACE |
167 | TopTools_IndexedDataMapOfShapeListOfShape theEFMap; |
168 | TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap); |
169 | TopTools_ListOfShape lfaces; |
170 | Standard_Boolean toremove = Standard_False; |
171 | for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) { |
172 | const TopoDS_Shape& edg = theEFMap.FindKey(i); |
173 | TopTools_ListOfShape thelist1; |
174 | myMap.Bind(edg, thelist1); |
175 | TopoDS_Shape desc = myPrism.Shape(edg); |
176 | if (!desc.IsNull()) { |
177 | if (theEFMap(i).Extent() >= 2) { |
178 | toremove = Standard_True; |
179 | } |
180 | else { |
181 | myMap(edg).Append(desc); |
182 | lfaces.Append(desc); |
183 | } |
184 | } |
185 | } |
186 | if(toremove) { |
187 | // Rajouter les faces de FirstShape et LastShape |
188 | for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) { |
189 | lfaces.Append(exp.Current()); |
190 | } |
191 | for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) { |
192 | lfaces.Append(exp.Current()); |
193 | } |
194 | |
195 | LocOpe_BuildShape BS(lfaces); |
196 | myRes = BS.Shape(); |
197 | } |
198 | else { |
199 | for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) { |
200 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
201 | if (!myMap.IsBound(edg)) { |
202 | TopTools_ListOfShape thelist2; |
203 | myMap.Bind(edg, thelist2); |
204 | TopoDS_Shape desc = myPrism.Shape(edg); |
205 | if (!desc.IsNull()) { |
206 | myMap(edg).Append(desc); |
207 | } |
208 | } |
209 | } |
210 | myRes = myPrism.Shape(); |
211 | } |
212 | } |
213 | |
214 | if (myIsTrans) { |
215 | // m-a-j des descendants |
216 | TopExp_Explorer exp; |
217 | for (exp.Init(myBase,TopAbs_EDGE);exp.More();exp.Next()) { |
218 | const TopoDS_Edge& edg = TopoDS::Edge(exp.Current()); |
219 | const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg)); |
220 | if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) { |
221 | myMap.Bind(edg,myMap(edgbis)); |
222 | myMap.UnBind(edgbis); |
223 | } |
224 | } |
225 | } |
226 | |
227 | myDone = Standard_True; |
228 | } |
229 | |
230 | //======================================================================= |
231 | //function : Shape |
232 | //purpose : |
233 | //======================================================================= |
234 | |
235 | const TopoDS_Shape& LocOpe_LinearForm::Shape () const |
236 | { |
237 | if (!myDone) { |
238 | StdFail_NotDone::Raise(); |
239 | } |
240 | return myRes; |
241 | } |
242 | |
243 | |
244 | //======================================================================= |
245 | //function : FirstShape |
246 | //purpose : |
247 | //======================================================================= |
248 | |
249 | const TopoDS_Shape& LocOpe_LinearForm::FirstShape () const |
250 | { |
251 | return myFirstShape; |
252 | } |
253 | |
254 | //======================================================================= |
255 | //function : LastShape |
256 | //purpose : |
257 | //======================================================================= |
258 | |
259 | const TopoDS_Shape& LocOpe_LinearForm::LastShape () const |
260 | { |
261 | return myLastShape; |
262 | } |
263 | |
264 | |
265 | //======================================================================= |
266 | //function : Shapes |
267 | //purpose : |
268 | //======================================================================= |
269 | |
270 | const TopTools_ListOfShape& LocOpe_LinearForm::Shapes (const TopoDS_Shape& S) const |
271 | { |
272 | return myMap(S); |
273 | } |
274 | |
275 | |
276 | |
277 | |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | |
290 | |
291 | |
292 | |
293 | |
294 | |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | |
307 | |
308 | |
309 | |
310 | |
311 | |
312 | |
313 | |
314 | |
315 | |
316 | |
317 | |
318 | |
319 | |