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.
18 #include <BRepBuilderAPI_Collect.hxx>
19 #include <BRepBuilderAPI_MakeShape.hxx>
20 #include <TopExp_Explorer.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
24 #include <TopTools_DataMapOfShapeShape.hxx>
25 #include <TopTools_ListIteratorOfListOfShape.hxx>
26 #include <TopTools_ListOfShape.hxx>
27 #include <TopTools_MapOfShape.hxx>
31 Standard_Boolean Affich;
37 //=======================================================================
40 //=======================================================================
42 static void BuildBack (const TopTools_DataMapOfShapeListOfShape& M1,
43 TopTools_DataMapOfShapeShape& BM1)
45 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(M1);
46 for (; it.More(); it.Next()) {
47 const TopoDS_Shape& KS = it.Key();
48 TopTools_ListIteratorOfListOfShape itl(it.Value());
49 for ( ; itl.More(); itl.Next()) {
50 const TopoDS_Shape& VS = itl.Value();
56 //=======================================================================
59 //=======================================================================
61 static void Replace ( TopTools_ListOfShape& L,
62 const TopoDS_Shape Old,
63 const TopTools_ListOfShape& New)
65 //-----------------------------------
66 // Suppression de Old dans la liste.
67 //-----------------------------------
68 TopTools_ListIteratorOfListOfShape it(L);
70 if (it.Value().IsSame(Old)) {
74 if (it.More()) it.Next();
76 //---------------------------
78 //---------------------------
79 TopTools_ListOfShape copNew;
85 //=======================================================================
86 //function : StoreImage
88 //=======================================================================
90 static void StoreImage ( TopTools_DataMapOfShapeListOfShape& MG,
91 const TopoDS_Shape& S,
92 const TopTools_DataMapOfShapeShape& MGBack,
93 const TopTools_ListOfShape& LI)
96 if (MGBack.IsBound(S)) {
98 Replace (MG.ChangeFind(MGBack(S)),S,LI);
101 if (!MG.IsBound(S)) {
102 TopTools_ListOfShape empty;
105 // Dans tous les cas on copie la liste pour eviter les pb de
106 // const& dans BRepBuilderAPI.
107 TopTools_ListIteratorOfListOfShape it;
108 for (it.Initialize(LI); it.More(); it.Next()) {
109 const TopoDS_Shape& SS = it.Value();
116 //=======================================================================
117 //function : UpdateGen
119 //=======================================================================
121 static void Update ( TopTools_DataMapOfShapeListOfShape& Mod,
122 TopTools_DataMapOfShapeListOfShape& Gen,
123 const TopTools_DataMapOfShapeShape& ModBack,
124 const TopTools_DataMapOfShapeShape& GenBack,
125 const TopoDS_Shape& SI,
126 BRepBuilderAPI_MakeShape& MKS,
127 const TopAbs_ShapeEnum ShapeType)
130 TopTools_MapOfShape DejaVu;
133 for (exp.Init(SI,ShapeType); exp.More(); exp.Next()) {
134 const TopoDS_Shape& S = exp.Current();
135 if (!DejaVu.Add(S)) continue;
137 //---------------------------------------
138 // Recuperation de l image de S par MKS.
139 //---------------------------------------
140 const TopTools_ListOfShape& LIM = MKS.Modified(S);
141 if (!LIM.IsEmpty()) {
142 if (GenBack.IsBound(S)) {
143 // Modif de generation => generation du shape initial
144 StoreImage (Gen,S,GenBack,LIM);
147 StoreImage (Mod,S,ModBack,LIM);
150 const TopTools_ListOfShape& LIG = MKS.Generated(S);
151 if (!LIG.IsEmpty()) {
152 if (ModBack.IsBound(S)) {
153 // Generation de modif => generation du shape initial
154 TopoDS_Shape IS = ModBack(S);
155 StoreImage (Gen,IS,GenBack,LIG);
158 StoreImage (Gen,S,GenBack,LIG);
164 //=======================================================================
165 //function : DEBControl
167 //=======================================================================
169 static void DEBControl (const TopTools_DataMapOfShapeListOfShape& MG)
172 Standard_Integer IK = 0;
174 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(MG);
175 for (; it.More(); it.Next()) {
176 const TopoDS_Shape& OS = it.Key();
177 sprintf(name, "SK_%d",++IK);
181 TopTools_ListIteratorOfListOfShape itl(MG(OS));
182 Standard_Integer IV = 1;
183 for (; itl.More(); itl.Next()) {
184 sprintf(name, "SV_%d_%d",IK,IV++);
192 //=======================================================================
193 //function : BRepBuilderAPI_Collect
195 //=======================================================================
197 BRepBuilderAPI_Collect::BRepBuilderAPI_Collect()
200 //=======================================================================
203 //=======================================================================
205 void BRepBuilderAPI_Collect::Add (const TopoDS_Shape& SI,
206 BRepBuilderAPI_MakeShape& MKS)
209 TopTools_DataMapOfShapeShape GenBack;
210 TopTools_DataMapOfShapeShape ModBack;
211 BuildBack (myGen, GenBack); // Vraiment pas optimum a Revoir
212 BuildBack (myMod, ModBack);
214 Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_FACE);
215 Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_EDGE);
216 Update (myMod,myGen,ModBack,GenBack,SI,MKS,TopAbs_VERTEX);
225 //=======================================================================
228 //=======================================================================
230 void BRepBuilderAPI_Collect::AddGenerated (const TopoDS_Shape& S,
231 const TopoDS_Shape& NS)
233 TopTools_DataMapOfShapeShape GenBack;
234 TopTools_DataMapOfShapeShape ModBack;
235 BuildBack (myGen, GenBack);
236 BuildBack (myMod, ModBack);
238 TopTools_ListOfShape LIG;
240 if (ModBack.IsBound(S)) {
241 // Generation de modif => generation du shape initial
242 TopoDS_Shape IS = ModBack(S);
243 StoreImage (myGen,IS,GenBack,LIG);
246 StoreImage (myGen,S,GenBack,LIG);
250 //=======================================================================
253 //=======================================================================
255 void BRepBuilderAPI_Collect::AddModif (const TopoDS_Shape& S,
256 const TopoDS_Shape& NS)
259 TopTools_DataMapOfShapeShape GenBack;
260 TopTools_DataMapOfShapeShape ModBack;
261 BuildBack (myGen, GenBack);
262 BuildBack (myMod, ModBack);
264 TopTools_ListOfShape LIG;
266 if (GenBack.IsBound(S)) {
267 // Modif de generation => generation du shape initial
268 StoreImage (myGen,S,GenBack,LIG);
271 StoreImage (myMod,S,ModBack,LIG);
276 //=======================================================================
279 //=======================================================================
281 static void FilterByShape(TopTools_DataMapOfShapeListOfShape& MG,
282 const TopoDS_Shape& SF)
284 TopTools_MapOfShape MSF;
286 Standard_Boolean YaEdge = Standard_False;
287 Standard_Boolean YaVertex = Standard_False;
288 for (exp.Init(SF,TopAbs_FACE) ; exp.More(); exp.Next()) MSF.Add(exp.Current());
290 //-------------------------------------------------------------
291 // Suppression de toutes les images qui ne sont pas dans MSF.
292 //-------------------------------------------------------------
293 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(MG);
294 for (; it.More(); it.Next()) {
295 const TopoDS_Shape& OS = it.Key();
296 TopTools_ListOfShape& LNS = MG.ChangeFind(OS);
297 TopTools_ListIteratorOfListOfShape itl(LNS);
299 const TopoDS_Shape& NS = itl.Value();
300 //-------------------------------------------------------------------
301 // Images contiennet des edges => ajout des edges resultat dans MSF.
302 //-------------------------------------------------------------------
303 if (!YaEdge && NS.ShapeType() == TopAbs_EDGE) {
304 for (exp.Init(SF,TopAbs_EDGE) ; exp.More(); exp.Next()) {
305 MSF.Add(exp.Current());
307 YaEdge = Standard_True;
309 //-------------------------------------------------------------------
310 // Images contiennet des vertex => ajout des vertex resultat dans MSF.
311 //-------------------------------------------------------------------
312 if (!YaVertex && NS.ShapeType() == TopAbs_VERTEX) {
313 for (exp.Init(SF,TopAbs_VERTEX) ; exp.More(); exp.Next()) {
314 MSF.Add(exp.Current());
316 YaVertex = Standard_True;
318 //---------------------------------------
319 // Si pas dans MSF suprresion de l image.
320 //---------------------------------------
321 if (!MSF.Contains(NS)) {
324 else if (itl.More()) itl.Next();
335 //=======================================================================
336 //function : Modification
338 //=======================================================================
340 const TopTools_DataMapOfShapeListOfShape& BRepBuilderAPI_Collect::Modification() const
345 //=======================================================================
346 //function : Generation
348 //=======================================================================
350 const TopTools_DataMapOfShapeListOfShape& BRepBuilderAPI_Collect::Generated() const
355 //=======================================================================
358 //=======================================================================
360 void BRepBuilderAPI_Collect::Filter(const TopoDS_Shape& SF)
362 FilterByShape (myGen,SF);
363 FilterByShape (myMod,SF);