0022627: Change OCCT memory management defaults
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_FREGU.cxx
CommitLineData
7fd59977 1// file: TopOpeBRepBuild_Grid.cxx
2// Created: Thu Mar 7 10:49:33 1996
3// Author: Jean Yves LEBEY
4// <jyl@meteox>
5
6#include <TopOpeBRepBuild_Builder.ixx>
7
8#include <TopOpeBRepBuild_WireToFace.hxx>
9#include <TopOpeBRepTool.hxx>
10#include <TopExp_Explorer.hxx>
11#include <TopExp.hxx>
12#include <TopoDS.hxx>
13#include <TopoDS_Wire.hxx>
14#include <TopoDS_Face.hxx>
15#include <BRep_Builder.hxx>
16#include <BRep_Tool.hxx>
17#include <Standard_ProgramError.hxx>
18#include <TopOpeBRepDS_define.hxx>
19
20#ifdef DEB
21Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GetcontextNOREGUFA();
22Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GetcontextREGUXPU();
23Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceSAVFREGU();
24void debregufa(const Standard_Integer /*iF*/) {}
25#endif
26
27#ifdef DRAW
28#include <DBRep.hxx>
29#endif
30
31#define M_FORWARD(O) (O == TopAbs_FORWARD)
32#define M_REVERSED(O) (O == TopAbs_REVERSED)
33
34//=======================================================================
35//function : RegularizeFaces
36//purpose :
37//=======================================================================
38void TopOpeBRepBuild_Builder::RegularizeFaces
39(const TopoDS_Shape& FF,const TopTools_ListOfShape& lnewFace,TopTools_ListOfShape& LOF)
40{
41 LOF.Clear();
42 myMemoSplit.Clear();
43
44 TopTools_ListIteratorOfListOfShape itl(lnewFace);
45 for (;itl.More();itl.Next()) {
46 const TopoDS_Shape& newFace = itl.Value();
47 TopTools_ListOfShape newFaceLOF;
48 RegularizeFace(FF,newFace,newFaceLOF);
49#ifdef DEB
50// Standard_Integer nnewFaceLOF = newFaceLOF.Extent(); // DEB
51#endif
52 LOF.Append(newFaceLOF);
53 }
54#ifdef DEB
55// Standard_Integer nLOF = LOF.Extent(); // DEB
56#endif
57
58 Standard_Integer nr = myMemoSplit.Extent();
59 if (nr == 0 ) return;
60
61 // lfsdFF = faces SameDomain de FF
62 TopTools_ListOfShape lfsdFF,lfsdFF1,lfsdFF2;
63 GFindSamDom(FF,lfsdFF1,lfsdFF2);
64 lfsdFF.Append(lfsdFF1);
65 lfsdFF.Append(lfsdFF2);
66
67 TopTools_ListIteratorOfListOfShape itlfsdFF(lfsdFF);
68 for (; itlfsdFF.More(); itlfsdFF.Next()) {
69 const TopoDS_Shape& fsdFF = itlfsdFF.Value();
70 // au moins une arete de FF dont le Split() est lui meme Split()
71 TopExp_Explorer x;
72 for (x.Init(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
73// for (TopExp_Explorer x(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
74 const TopoDS_Shape& e = x.Current();
75#ifdef DEB
76// Standard_Integer ie = myDataStructure->Shape(e); //DEB
77// Standard_Boolean issect = myDataStructure->DS().IsSectionEdge(TopoDS::Edge(e));
78#endif
79
80 Standard_Integer ranke = GShapeRank(e);
81 TopAbs_State staeope = (ranke==1) ? myState1 : myState2;
82
83 for (Standard_Integer iiista = 1; iiista <= 2; iiista++ ) {
84
85 TopAbs_State stae = staeope;
86 if (iiista == 2) stae = TopAbs_ON;
87
88 Standard_Boolean issplite = IsSplit(e,stae);
89 if (!issplite) continue;
90
91 TopTools_ListOfShape& lspe = ChangeSplit(e,stae);
92#ifdef DEB
93// Standard_Integer nlspe = lspe.Extent(); // DEB
94#endif
95 TopTools_ListOfShape newlspe;
96 for (TopTools_ListIteratorOfListOfShape itl1(lspe);itl1.More();itl1.Next()) {
97 const TopoDS_Shape& esp = itl1.Value();
98 Standard_Boolean espmemo = myMemoSplit.Contains(esp);
99 if (!espmemo) newlspe.Append(esp);
100 else {
101 const TopTools_ListOfShape& lspesp = Splits(esp,stae);
102 GCopyList(lspesp,newlspe);
103 }
104 }
105 lspe.Clear();
106 GCopyList(newlspe,lspe);
107
108 } // iiista
109 } // explorer (fsdFF,TopAbs_EDGE)
110 } // itlfsdFF.More()
111} // RegularizeFaces
112
113/*static void FUN_setInternal(TopoDS_Face& F)
114{
115 TopExp_Explorer ex(F,TopAbs_EDGE);
116 TopTools_MapOfShape meF,meR,meI;
117 for (; ex.More(); ex.Next()){
118 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
119 TopAbs_Orientation oE = E.Orientation();
120 Standard_Boolean isclo = BRep_Tool::IsClosed(E,F); // E has 2d rep on F
121 if (isclo) continue;
122 Standard_Boolean isb = Standard_False; // the edge is FOR + REV in F
123 if (M_FORWARD(oE)) {meF.Add(E); isb = meR.Contains(E);}
124 else if (M_REVERSED(oE)) {meR.Add(E); isb = meF.Contains(E);}
125 if (isb) meI.Add(E.Oriented(TopAbs_INTERNAL));
126 }
127
128 BRep_Builder BB;
129 TopTools_MapIteratorOfMapOfShape it(meI);
130 for (; it.More(); it.Next()){
131 const TopoDS_Edge& E = TopoDS::Edge(it.Key());
132 BB.Remove(F,E.Oriented(TopAbs_FORWARD));
133 BB.Remove(F,E.Oriented(TopAbs_REVERSED));
134 BB.Add(F,E);
135 }
136}*/
137
138//=======================================================================
139//function : RegularizeFace
140//purpose :
141//=======================================================================
142void TopOpeBRepBuild_Builder::RegularizeFace
143(const TopoDS_Shape& FF,const TopoDS_Shape& anewFace,TopTools_ListOfShape& LOF)
144{
145 LOF.Clear();
146 const TopoDS_Face& newFace = TopoDS::Face(anewFace);
147 Standard_Boolean toregu = Standard_True;
148 Standard_Boolean usewtof = Standard_True;
149
150#ifdef DEB
151 Standard_Integer iF;Standard_Boolean tSPSFF=GtraceSPS(FF,iF);
152// Standard_Boolean savfregu = TopOpeBRepBuild_GettraceSAVFREGU();
153 if (TopOpeBRepBuild_GetcontextNOREGUFA()) toregu = Standard_False;
154 if (TopOpeBRepBuild_GetcontextREGUXPU()) usewtof = Standard_False;
155 if (tSPSFF) debregufa(iF);
156#endif
157
158 // If the same edge appears FOR+REV in the resulting face and
159 // whereas it's not a closing edge, set it as INTERNAL instead.
160 // FRA60275(iF=4) + PRO16297
161// FUN_setInternal(newFace);
162
163 if (!toregu) {
164 LOF.Append(newFace);
165 return;
166 }
167
168 TopTools_DataMapOfShapeListOfShape ownw; // OldWires --> NewWires;
169 Standard_Boolean rw = Standard_False;
170 Standard_Boolean rf = Standard_False;
171 myESplits.Clear();
172
173 rw = TopOpeBRepTool::RegularizeWires(newFace,ownw,myESplits);
174
175 if ( !rw ) {
176 LOF.Append(newFace);
177 return;
178 }
179
180 TopTools_ListOfShape newfaces;
181 if (usewtof) {
182 TopOpeBRepBuild_WireToFace wtof;
183 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itownw(ownw);
184 for (; itownw.More(); itownw.Next()) {
185 const TopTools_ListOfShape& lw = itownw.Value();
186
187 // xpu200798 : cto902D4 f14ou
188 // recall ownw = {(ow = old wire, lnw = {list of new wires descendant of old wire}}
189 // if lnw is empty, then ow is kept unchanged.
190 Standard_Boolean kept = lw.IsEmpty();
191 if (kept) {
192 const TopoDS_Wire& ow = TopoDS::Wire(itownw.Key());
193 wtof.AddWire(ow);
194 }
195 for(TopTools_ListIteratorOfListOfShape iw(lw);iw.More();iw.Next()) {
196 const TopoDS_Wire& w = TopoDS::Wire(iw.Value());
197 wtof.AddWire(w);
198 }
199 }
200 wtof.MakeFaces(newFace,newfaces);
201#ifdef DEB
202// Standard_Integer nnewfaces = newfaces.Extent(); // DEB
203#endif
204 rf = (newfaces.Extent() != 0);
205 }
206 else {
207 rf = TopOpeBRepTool::RegularizeFace(newFace,ownw,newfaces);
208 }
209
210 if (!rf) {
211 LOF.Append(newFace);
212 return;
213 }
214
215#ifdef DEB
216 if (tSPSFF) { cout<<"RegularizeFace "<<iF<<endl; debregufa(iF); }
217#endif
218
219 // LOF = nouvelles faces regularisees de newFace
220 TopTools_ListIteratorOfListOfShape itlnf(newfaces);
221 for (; itlnf.More(); itlnf.Next())
222 LOF.Append(TopoDS::Face(itlnf.Value()));
223
224 // mise a jour des aretes decoupees
225 // Edge(FF) = {E}, E-->Split(E) = {E'}, E'-->myESplits(E') = {E''}
226
227 TopTools_MapOfShape menf; // menf = aretes de newFace
228 TopExp_Explorer x;
229 for (x.Init(newFace,TopAbs_EDGE);x.More();x.Next()) {
230 const TopoDS_Shape& E = x.Current();
231 menf.Add(E);
232 }
233
234 // lfsdFF = faces SameDomain de FF
235 TopTools_ListOfShape lfsdFF,lfsdFF1,lfsdFF2;
236 GFindSamDom(FF,lfsdFF1,lfsdFF2);
237 lfsdFF.Append(lfsdFF1);
238 lfsdFF.Append(lfsdFF2);
239
240 TopTools_ListIteratorOfListOfShape itlfsdFF(lfsdFF);
241 for (; itlfsdFF.More(); itlfsdFF.Next()) {
242 const TopoDS_Shape& fsdFF = itlfsdFF.Value();
243
244#ifdef DEB
245 Standard_Integer ifsdFF=0;Standard_Boolean tSPSfsdFF=GtraceSPS(fsdFF,ifsdFF);
246 if (tSPSfsdFF) debregufa(ifsdFF);
247#endif
248
249 Standard_Integer rankfsdFF = GShapeRank(fsdFF);
250 TopAbs_State stafsdFF = (rankfsdFF == 1) ? myState1 : myState2;
251#ifdef DEB
252// Standard_Boolean issplitfsdFF = IsSplit(fsdFF,stafsdFF);
253#endif
254
255/*#ifdef DEB
256 const TopTools_ListOfShape& lspfsdFF = Splits(fsdFF,stafsdFF);
257 Standard_Integer nlspfsdFF = lspfsdFF.Extent();
258#endif*/
259
260 // iteration sur les aretes de fsdFF
261 for (x.Init(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
262
263 //fsdFFe : 1 edge de fsdFF = 1 face SameDomain de FF
264 const TopoDS_Shape& fsdFFe = x.Current();
265
266#ifdef DEB
267 Standard_Integer ifsdFFe = 0;Standard_Boolean tSPSfsdFFe=GtraceSPS(fsdFFe,ifsdFFe);
268 if (tSPSfsdFFe) debregufa(ifsdFFe);
269#endif
270
271 // a priori, on ne peut avoir plus de deux etats splites
272 // sur l'arete , soit (IN + ON) , soit (OUT + ON)
273 for (Standard_Integer iiista = 1; iiista <= 2; iiista++ ) {
274 TopAbs_State stafsdFFe = stafsdFF;
275 if (iiista == 2) stafsdFFe = TopAbs_ON;
276
277 TopTools_ListOfShape& lspfsdFFe = ChangeSplit(fsdFFe,stafsdFFe);
278#ifdef DEB
279// Standard_Boolean issplitfsdFFe = IsSplit(fsdFFe,stafsdFFe);
280// Standard_Integer nlspfsdFFe = lspfsdFFe.Extent();
281#endif
282
283 Standard_Integer nDEB2=0 ;
284
285 for (TopTools_ListIteratorOfListOfShape it(lspfsdFFe);it.More();it.Next()) {
286
287 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
288
289 const TopoDS_Shape& espfsdFFe = it.Value();
290 Standard_Boolean inmenf = menf.Contains(espfsdFFe);
291 if (!inmenf) continue;
292
293 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
294 // espfsdFFe est une arete de Split(fsdFFe) ET figure dans newFace (Cf supra E')
295
296 Standard_Boolean resplitloc = myESplits.IsBound(espfsdFFe);
297 if (resplitloc) {
298
299 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
300 // espfsdFFe est une arete de Split(fsdFFe) ET figure dans newFace (Cf supra E')
301 // espfsdFFe de newFace a ete redecoupee par RegularizeWires
302
303 // son decoupage lresplit est stocke dans la DS du Builder
304 const TopTools_ListOfShape& lresplit = myESplits.Find(espfsdFFe); //Cf supra E''
305 nDEB2 = lresplit.Extent();
306
307 // on memorise que espfsdFFe est redecoupee ...
308 myMemoSplit.Add(espfsdFFe);
309
310 // on stocke le nouveau decoupage de espfsdFFe dans la DS du builder ...
311 TopTools_ListOfShape& lsp = ChangeSplit(espfsdFFe,stafsdFFe);
312 GCopyList(lresplit,lsp);
313 nDEB2 = lsp.Extent();
314 }
315 } // it.More
316 } // iiista
317 } // explore(fsdFF,TopAbs_EDGE)
318 } // itlfsdFF.More()
319
320#ifdef DRAW
321 if (tSPSFF) debregufa(iF);
322 if (tSPSFF && savfregu) {
323 TCollection_AsciiString str("fregu"); str = str + iF;
324 DBRep::Set(str.ToCString(),newFace);
325 cout<<"newFace "<<str<<" built on face "<<iF<<" saved"<<endl;
326 }
327#endif
328
329} // RegularizeFace