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