1 // Created on: 1996-04-09
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRepBuilderAPI_Collect.ixx>
20 #include <TopExp_Explorer.hxx>
22 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
23 #include <TopTools_ListOfShape.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
25 #include <TopTools_DataMapOfShapeShape.hxx>
26 #include <TopTools_MapOfShape.hxx>
30 Standard_Boolean Affich;
36 //=======================================================================
39 //=======================================================================
41 static void BuildBack (const TopTools_DataMapOfShapeListOfShape& M1,
42 TopTools_DataMapOfShapeShape& BM1)
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();
55 //=======================================================================
58 //=======================================================================
60 static void Replace ( TopTools_ListOfShape& L,
61 const TopoDS_Shape Old,
62 const TopTools_ListOfShape& New)
64 //-----------------------------------
65 // Suppression de Old dans la liste.
66 //-----------------------------------
67 TopTools_ListIteratorOfListOfShape it(L);
69 if (it.Value().IsSame(Old)) {
73 if (it.More()) it.Next();
75 //---------------------------
77 //---------------------------
78 TopTools_ListOfShape copNew;
84 //=======================================================================
85 //function : StoreImage
87 //=======================================================================
89 static void StoreImage ( TopTools_DataMapOfShapeListOfShape& MG,
90 const TopoDS_Shape& S,
91 const TopTools_DataMapOfShapeShape& MGBack,
92 const TopTools_ListOfShape& LI)
95 if (MGBack.IsBound(S)) {
97 Replace (MG.ChangeFind(MGBack(S)),S,LI);
100 if (!MG.IsBound(S)) {
101 TopTools_ListOfShape empty;
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();
115 //=======================================================================
116 //function : UpdateGen
118 //=======================================================================
120 static 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)
129 TopTools_MapOfShape DejaVu;
132 for (exp.Init(SI,ShapeType); exp.More(); exp.Next()) {
133 const TopoDS_Shape& S = exp.Current();
134 if (!DejaVu.Add(S)) continue;
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);
146 StoreImage (Mod,S,ModBack,LIM);
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);
157 StoreImage (Gen,S,GenBack,LIG);
163 //=======================================================================
164 //function : DEBControl
166 //=======================================================================
168 static void DEBControl (const TopTools_DataMapOfShapeListOfShape& MG)
171 Standard_Integer IK = 0;
173 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(MG);
174 for (; it.More(); it.Next()) {
175 const TopoDS_Shape& OS = it.Key();
176 sprintf(name, "SK_%d",++IK);
180 TopTools_ListIteratorOfListOfShape itl(MG(OS));
181 Standard_Integer IV = 1;
182 for (; itl.More(); itl.Next()) {
183 sprintf(name, "SV_%d_%d",IK,IV++);
191 //=======================================================================
192 //function : BRepBuilderAPI_Collect
194 //=======================================================================
196 BRepBuilderAPI_Collect::BRepBuilderAPI_Collect()
199 //=======================================================================
202 //=======================================================================
204 void BRepBuilderAPI_Collect::Add (const TopoDS_Shape& SI,
205 BRepBuilderAPI_MakeShape& MKS)
208 TopTools_DataMapOfShapeShape GenBack;
209 TopTools_DataMapOfShapeShape ModBack;
210 BuildBack (myGen, GenBack); // Vraiment pas optimum a Revoir
211 BuildBack (myMod, ModBack);
213 Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_FACE);
214 Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_EDGE);
215 Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_VERTEX);
224 //=======================================================================
227 //=======================================================================
229 void BRepBuilderAPI_Collect::AddGenerated (const TopoDS_Shape& S,
230 const TopoDS_Shape& NS)
232 TopTools_DataMapOfShapeShape GenBack;
233 TopTools_DataMapOfShapeShape ModBack;
234 BuildBack (myGen, GenBack);
235 BuildBack (myMod, ModBack);
237 TopTools_ListOfShape LIG;
239 if (ModBack.IsBound(S)) {
240 // Generation de modif => generation du shape initial
241 TopoDS_Shape IS = ModBack(S);
242 StoreImage (myGen,IS,GenBack,LIG);
245 StoreImage (myGen,S,GenBack,LIG);
249 //=======================================================================
252 //=======================================================================
254 void BRepBuilderAPI_Collect::AddModif (const TopoDS_Shape& S,
255 const TopoDS_Shape& NS)
258 TopTools_DataMapOfShapeShape GenBack;
259 TopTools_DataMapOfShapeShape ModBack;
260 BuildBack (myGen, GenBack);
261 BuildBack (myMod, ModBack);
263 TopTools_ListOfShape LIG;
265 if (GenBack.IsBound(S)) {
266 // Modif de generation => generation du shape initial
267 StoreImage (myGen,S,GenBack,LIG);
270 StoreImage (myMod,S,ModBack,LIG);
275 //=======================================================================
278 //=======================================================================
280 static void FilterByShape(TopTools_DataMapOfShapeListOfShape& MG,
281 const TopoDS_Shape& SF)
283 TopTools_MapOfShape MSF;
285 Standard_Boolean YaEdge = Standard_False;
286 Standard_Boolean YaVertex = Standard_False;
287 for (exp.Init(SF,TopAbs_FACE) ; exp.More(); exp.Next()) MSF.Add(exp.Current());
289 //-------------------------------------------------------------
290 // Suppression de toutes les images qui ne sont pas dans MSF.
291 //-------------------------------------------------------------
292 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(MG);
293 for (; it.More(); it.Next()) {
294 const TopoDS_Shape& OS = it.Key();
295 TopTools_ListOfShape& LNS = MG.ChangeFind(OS);
296 TopTools_ListIteratorOfListOfShape itl(LNS);
298 const TopoDS_Shape& NS = itl.Value();
299 //-------------------------------------------------------------------
300 // Images contiennet des edges => ajout des edges resultat dans MSF.
301 //-------------------------------------------------------------------
302 if (!YaEdge && NS.ShapeType() == TopAbs_EDGE) {
303 for (exp.Init(SF,TopAbs_EDGE) ; exp.More(); exp.Next()) {
304 MSF.Add(exp.Current());
306 YaEdge = Standard_True;
308 //-------------------------------------------------------------------
309 // Images contiennet des vertex => ajout des vertex resultat dans MSF.
310 //-------------------------------------------------------------------
311 if (!YaVertex && NS.ShapeType() == TopAbs_VERTEX) {
312 for (exp.Init(SF,TopAbs_VERTEX) ; exp.More(); exp.Next()) {
313 MSF.Add(exp.Current());
315 YaVertex = Standard_True;
317 //---------------------------------------
318 // Si pas dans MSF suprresion de l image.
319 //---------------------------------------
320 if (!MSF.Contains(NS)) {
323 else if (itl.More()) itl.Next();
334 //=======================================================================
335 //function : Modification
337 //=======================================================================
339 const TopTools_DataMapOfShapeListOfShape& BRepBuilderAPI_Collect::Modification() const
344 //=======================================================================
345 //function : Generation
347 //=======================================================================
349 const TopTools_DataMapOfShapeListOfShape& BRepBuilderAPI_Collect::Generated() const
354 //=======================================================================
357 //=======================================================================
359 void BRepBuilderAPI_Collect::Filter(const TopoDS_Shape& SF)
361 FilterByShape (myGen,SF);
362 FilterByShape (myMod,SF);