b311480e |
1 | // Created on: 1996-04-09 |
2 | // Created by: Yves FRICAUD |
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 | |
23 | #include <BRepBuilderAPI_Collect.ixx> |
24 | |
25 | #include <TopoDS.hxx> |
26 | #include <TopExp_Explorer.hxx> |
b311480e |
27 | |
7fd59977 |
28 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> |
29 | #include <TopTools_ListOfShape.hxx> |
30 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
31 | #include <TopTools_DataMapOfShapeShape.hxx> |
32 | #include <TopTools_MapOfShape.hxx> |
33 | |
34 | #ifdef DEB |
35 | #include <stdio.h> |
36 | Standard_Boolean Affich; |
37 | #endif |
38 | |
39 | #ifdef DRAW |
40 | #include <DBRep.hxx> |
41 | #endif |
42 | //======================================================================= |
43 | //function : BuilBack |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | static void BuildBack (const TopTools_DataMapOfShapeListOfShape& M1, |
48 | TopTools_DataMapOfShapeShape& BM1) |
49 | { |
50 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(M1); |
51 | for (; it.More(); it.Next()) { |
52 | const TopoDS_Shape& KS = it.Key(); |
53 | TopTools_ListIteratorOfListOfShape itl(it.Value()); |
54 | for ( ; itl.More(); itl.Next()) { |
55 | const TopoDS_Shape& VS = itl.Value(); |
56 | BM1.Bind(VS,KS); |
57 | } |
58 | } |
59 | } |
60 | |
61 | //======================================================================= |
62 | //function : Replace |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | static void Replace ( TopTools_ListOfShape& L, |
67 | const TopoDS_Shape Old, |
68 | const TopTools_ListOfShape& New) |
69 | { |
70 | //----------------------------------- |
71 | // Suppression de Old dans la liste. |
72 | //----------------------------------- |
73 | TopTools_ListIteratorOfListOfShape it(L); |
74 | while (it.More()) { |
75 | if (it.Value().IsSame(Old)) { |
76 | L.Remove(it); |
77 | break; |
78 | } |
79 | if (it.More()) it.Next(); |
80 | } |
81 | //--------------------------- |
82 | // Ajout de New a L. |
83 | //--------------------------- |
84 | TopTools_ListOfShape copNew; |
85 | copNew = New; |
86 | L.Append(copNew); |
87 | } |
88 | |
89 | |
90 | //======================================================================= |
91 | //function : StoreImage |
92 | //purpose : |
93 | //======================================================================= |
94 | |
95 | static void StoreImage ( TopTools_DataMapOfShapeListOfShape& MG, |
96 | const TopoDS_Shape& S, |
97 | const TopTools_DataMapOfShapeShape& MGBack, |
98 | const TopTools_ListOfShape& LI) |
99 | { |
100 | if (!LI.IsEmpty()) { |
101 | if (MGBack.IsBound(S)) { |
102 | |
103 | Replace (MG.ChangeFind(MGBack(S)),S,LI); |
104 | } |
105 | else { |
106 | if (!MG.IsBound(S)) { |
107 | TopTools_ListOfShape empty; |
108 | MG.Bind(S,empty); |
109 | } |
110 | // Dans tous les cas on copie la liste pour eviter les pb de |
111 | // const& dans BRepBuilderAPI. |
112 | TopTools_ListIteratorOfListOfShape it; |
113 | for (it.Initialize(LI); it.More(); it.Next()) { |
114 | const TopoDS_Shape& SS = it.Value(); |
115 | MG(S).Append(SS); |
116 | } |
117 | } |
118 | } |
119 | } |
120 | |
121 | //======================================================================= |
122 | //function : UpdateGen |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | static void Update ( TopTools_DataMapOfShapeListOfShape& Mod, |
127 | TopTools_DataMapOfShapeListOfShape& Gen, |
128 | const TopTools_DataMapOfShapeShape& ModBack, |
129 | const TopTools_DataMapOfShapeShape& GenBack, |
130 | const TopoDS_Shape& SI, |
131 | BRepBuilderAPI_MakeShape& MKS, |
132 | const TopAbs_ShapeEnum ShapeType) |
133 | { |
134 | |
135 | TopTools_MapOfShape DejaVu; |
136 | TopExp_Explorer exp; |
137 | |
138 | for (exp.Init(SI,ShapeType); exp.More(); exp.Next()) { |
139 | const TopoDS_Shape& S = exp.Current(); |
140 | if (!DejaVu.Add(S)) continue; |
141 | |
142 | //--------------------------------------- |
143 | // Recuperation de l image de S par MKS. |
144 | //--------------------------------------- |
145 | const TopTools_ListOfShape& LIM = MKS.Modified(S); |
146 | if (!LIM.IsEmpty()) { |
147 | if (GenBack.IsBound(S)) { |
148 | // Modif de generation => generation du shape initial |
149 | StoreImage (Gen,S,GenBack,LIM); |
150 | } |
151 | else { |
152 | StoreImage (Mod,S,ModBack,LIM); |
153 | } |
154 | } |
155 | const TopTools_ListOfShape& LIG = MKS.Generated(S); |
156 | if (!LIG.IsEmpty()) { |
157 | if (ModBack.IsBound(S)) { |
158 | // Generation de modif => generation du shape initial |
159 | TopoDS_Shape IS = ModBack(S); |
160 | StoreImage (Gen,IS,GenBack,LIG); |
161 | } |
162 | else { |
163 | StoreImage (Gen,S,GenBack,LIG); |
164 | } |
165 | } |
166 | } |
167 | } |
168 | #ifdef DEB |
169 | //======================================================================= |
170 | //function : DEBControl |
171 | //purpose : |
172 | //======================================================================= |
173 | |
174 | static void DEBControl (const TopTools_DataMapOfShapeListOfShape& MG) |
175 | { |
176 | char name[100]; |
177 | Standard_Integer IK = 0; |
178 | |
179 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(MG); |
180 | for (; it.More(); it.Next()) { |
181 | const TopoDS_Shape& OS = it.Key(); |
182 | sprintf(name, "SK_%d",++IK); |
183 | #ifdef DRAW |
184 | DBRep::Set(name,OS); |
185 | #endif |
186 | TopTools_ListIteratorOfListOfShape itl(MG(OS)); |
187 | Standard_Integer IV = 1; |
188 | for (; itl.More(); itl.Next()) { |
7fd59977 |
189 | sprintf(name, "SV_%d_%d",IK,IV++); |
190 | #ifdef DRAW |
191 | DBRep::Set(name,NS); |
192 | #endif |
193 | } |
194 | } |
195 | } |
196 | #endif |
197 | //======================================================================= |
198 | //function : BRepBuilderAPI_Collect |
199 | //purpose : |
200 | //======================================================================= |
201 | |
202 | BRepBuilderAPI_Collect::BRepBuilderAPI_Collect() |
203 | {} |
204 | |
205 | //======================================================================= |
206 | //function : Add |
207 | //purpose : |
208 | //======================================================================= |
209 | |
210 | void BRepBuilderAPI_Collect::Add (const TopoDS_Shape& SI, |
211 | BRepBuilderAPI_MakeShape& MKS) |
212 | |
213 | { |
214 | TopTools_DataMapOfShapeShape GenBack; |
215 | TopTools_DataMapOfShapeShape ModBack; |
216 | BuildBack (myGen, GenBack); // Vraiment pas optimum a Revoir |
217 | BuildBack (myMod, ModBack); |
218 | |
219 | Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_FACE); |
220 | Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_EDGE); |
221 | Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_VERTEX); |
222 | |
223 | #ifdef DEB |
224 | if (Affich) { |
225 | DEBControl (myGen); |
226 | DEBControl (myMod); |
227 | } |
228 | #endif |
229 | } |
230 | //======================================================================= |
231 | //function : Add |
232 | //purpose : |
233 | //======================================================================= |
234 | |
235 | void BRepBuilderAPI_Collect::AddGenerated (const TopoDS_Shape& S, |
236 | const TopoDS_Shape& NS) |
237 | { |
238 | TopTools_DataMapOfShapeShape GenBack; |
239 | TopTools_DataMapOfShapeShape ModBack; |
240 | BuildBack (myGen, GenBack); |
241 | BuildBack (myMod, ModBack); |
242 | |
243 | TopTools_ListOfShape LIG; |
244 | LIG.Append(NS); |
245 | if (ModBack.IsBound(S)) { |
246 | // Generation de modif => generation du shape initial |
247 | TopoDS_Shape IS = ModBack(S); |
248 | StoreImage (myGen,IS,GenBack,LIG); |
249 | } |
250 | else { |
251 | StoreImage (myGen,S,GenBack,LIG); |
252 | } |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : Add |
257 | //purpose : |
258 | //======================================================================= |
259 | |
260 | void BRepBuilderAPI_Collect::AddModif (const TopoDS_Shape& S, |
261 | const TopoDS_Shape& NS) |
262 | |
263 | { |
264 | TopTools_DataMapOfShapeShape GenBack; |
265 | TopTools_DataMapOfShapeShape ModBack; |
266 | BuildBack (myGen, GenBack); |
267 | BuildBack (myMod, ModBack); |
268 | |
269 | TopTools_ListOfShape LIG; |
270 | LIG.Append(NS); |
271 | if (GenBack.IsBound(S)) { |
272 | // Modif de generation => generation du shape initial |
273 | StoreImage (myGen,S,GenBack,LIG); |
274 | } |
275 | else { |
276 | StoreImage (myMod,S,ModBack,LIG); |
277 | } |
278 | } |
279 | |
280 | |
281 | //======================================================================= |
282 | //function : Filter |
283 | //purpose : |
284 | //======================================================================= |
285 | |
286 | static void FilterByShape(TopTools_DataMapOfShapeListOfShape& MG, |
287 | const TopoDS_Shape& SF) |
288 | { |
289 | TopTools_MapOfShape MSF; |
290 | TopExp_Explorer exp; |
291 | Standard_Boolean YaEdge = Standard_False; |
292 | Standard_Boolean YaVertex = Standard_False; |
293 | for (exp.Init(SF,TopAbs_FACE) ; exp.More(); exp.Next()) MSF.Add(exp.Current()); |
294 | |
295 | //------------------------------------------------------------- |
296 | // Suppression de toutes les images qui ne sont pas dans MSF. |
297 | //------------------------------------------------------------- |
298 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(MG); |
299 | for (; it.More(); it.Next()) { |
300 | const TopoDS_Shape& OS = it.Key(); |
301 | TopTools_ListOfShape& LNS = MG.ChangeFind(OS); |
302 | TopTools_ListIteratorOfListOfShape itl(LNS); |
303 | while (itl.More()) { |
304 | const TopoDS_Shape& NS = itl.Value(); |
305 | //------------------------------------------------------------------- |
306 | // Images contiennet des edges => ajout des edges resultat dans MSF. |
307 | //------------------------------------------------------------------- |
308 | if (!YaEdge && NS.ShapeType() == TopAbs_EDGE) { |
309 | for (exp.Init(SF,TopAbs_EDGE) ; exp.More(); exp.Next()) { |
310 | MSF.Add(exp.Current()); |
311 | } |
312 | YaEdge = Standard_True; |
313 | } |
314 | //------------------------------------------------------------------- |
315 | // Images contiennet des vertex => ajout des vertex resultat dans MSF. |
316 | //------------------------------------------------------------------- |
317 | if (!YaVertex && NS.ShapeType() == TopAbs_VERTEX) { |
318 | for (exp.Init(SF,TopAbs_VERTEX) ; exp.More(); exp.Next()) { |
319 | MSF.Add(exp.Current()); |
320 | } |
321 | YaVertex = Standard_True; |
322 | } |
323 | //--------------------------------------- |
324 | // Si pas dans MSF suprresion de l image. |
325 | //--------------------------------------- |
326 | if (!MSF.Contains(NS)) { |
327 | LNS.Remove(itl); |
328 | } |
329 | else if (itl.More()) itl.Next(); |
330 | } |
331 | } |
332 | #ifdef DEB |
333 | if (Affich) { |
334 | DEBControl (MG); |
335 | } |
336 | #endif |
337 | |
338 | } |
339 | |
340 | //======================================================================= |
341 | //function : Modification |
342 | //purpose : |
343 | //======================================================================= |
344 | |
345 | const TopTools_DataMapOfShapeListOfShape& BRepBuilderAPI_Collect::Modification() const |
346 | { |
347 | return myMod; |
348 | } |
349 | |
350 | //======================================================================= |
351 | //function : Generation |
352 | //purpose : |
353 | //======================================================================= |
354 | |
355 | const TopTools_DataMapOfShapeListOfShape& BRepBuilderAPI_Collect::Generated() const |
356 | { |
357 | return myGen; |
358 | } |
359 | |
360 | //======================================================================= |
361 | //function : Filter |
362 | //purpose : |
363 | //======================================================================= |
364 | |
365 | void BRepBuilderAPI_Collect::Filter(const TopoDS_Shape& SF) |
366 | { |
367 | FilterByShape (myGen,SF); |
368 | FilterByShape (myMod,SF); |
369 | } |
370 | |
371 | |
372 | |
373 | |
374 | |
375 | |