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