1 // Created on: 1996-03-07
2 // Created by: Jean Yves LEBEY
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
9 // under the terms of the GNU Lesser General Public 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 <TopOpeBRepBuild_Builder.ixx>
19 #include <TopOpeBRepBuild_WireToFace.hxx>
20 #include <TopOpeBRepTool.hxx>
21 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Wire.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <BRep_Builder.hxx>
27 #include <BRep_Tool.hxx>
28 #include <Standard_ProgramError.hxx>
29 #include <TopOpeBRepDS_define.hxx>
32 extern Standard_Boolean TopOpeBRepBuild_GetcontextNOREGUFA();
33 extern Standard_Boolean TopOpeBRepBuild_GetcontextREGUXPU();
34 extern Standard_Boolean TopOpeBRepBuild_GettraceSAVFREGU();
35 void debregufa(const Standard_Integer /*iF*/) {}
42 #define M_FORWARD(O) (O == TopAbs_FORWARD)
43 #define M_REVERSED(O) (O == TopAbs_REVERSED)
45 //=======================================================================
46 //function : RegularizeFaces
48 //=======================================================================
49 void TopOpeBRepBuild_Builder::RegularizeFaces
50 (const TopoDS_Shape& FF,const TopTools_ListOfShape& lnewFace,TopTools_ListOfShape& LOF)
55 TopTools_ListIteratorOfListOfShape itl(lnewFace);
56 for (;itl.More();itl.Next()) {
57 const TopoDS_Shape& newFace = itl.Value();
58 TopTools_ListOfShape newFaceLOF;
59 RegularizeFace(FF,newFace,newFaceLOF);
61 // Standard_Integer nnewFaceLOF = newFaceLOF.Extent(); // DEB
63 LOF.Append(newFaceLOF);
66 // Standard_Integer nLOF = LOF.Extent(); // DEB
69 Standard_Integer nr = myMemoSplit.Extent();
72 // lfsdFF = faces SameDomain de FF
73 TopTools_ListOfShape lfsdFF,lfsdFF1,lfsdFF2;
74 GFindSamDom(FF,lfsdFF1,lfsdFF2);
75 lfsdFF.Append(lfsdFF1);
76 lfsdFF.Append(lfsdFF2);
78 TopTools_ListIteratorOfListOfShape itlfsdFF(lfsdFF);
79 for (; itlfsdFF.More(); itlfsdFF.Next()) {
80 const TopoDS_Shape& fsdFF = itlfsdFF.Value();
81 // au moins une arete de FF dont le Split() est lui meme Split()
83 for (x.Init(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
84 // for (TopExp_Explorer x(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
85 const TopoDS_Shape& e = x.Current();
87 // Standard_Integer ie = myDataStructure->Shape(e); //DEB
88 // Standard_Boolean issect = myDataStructure->DS().IsSectionEdge(TopoDS::Edge(e));
91 Standard_Integer ranke = GShapeRank(e);
92 TopAbs_State staeope = (ranke==1) ? myState1 : myState2;
94 for (Standard_Integer iiista = 1; iiista <= 2; iiista++ ) {
96 TopAbs_State stae = staeope;
97 if (iiista == 2) stae = TopAbs_ON;
99 Standard_Boolean issplite = IsSplit(e,stae);
100 if (!issplite) continue;
102 TopTools_ListOfShape& lspe = ChangeSplit(e,stae);
104 // Standard_Integer nlspe = lspe.Extent(); // DEB
106 TopTools_ListOfShape newlspe;
107 for (TopTools_ListIteratorOfListOfShape itl1(lspe);itl1.More();itl1.Next()) {
108 const TopoDS_Shape& esp = itl1.Value();
109 Standard_Boolean espmemo = myMemoSplit.Contains(esp);
110 if (!espmemo) newlspe.Append(esp);
112 const TopTools_ListOfShape& lspesp = Splits(esp,stae);
113 GCopyList(lspesp,newlspe);
117 GCopyList(newlspe,lspe);
120 } // explorer (fsdFF,TopAbs_EDGE)
124 /*static void FUN_setInternal(TopoDS_Face& F)
126 TopExp_Explorer ex(F,TopAbs_EDGE);
127 TopTools_MapOfShape meF,meR,meI;
128 for (; ex.More(); ex.Next()){
129 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
130 TopAbs_Orientation oE = E.Orientation();
131 Standard_Boolean isclo = BRep_Tool::IsClosed(E,F); // E has 2d rep on F
133 Standard_Boolean isb = Standard_False; // the edge is FOR + REV in F
134 if (M_FORWARD(oE)) {meF.Add(E); isb = meR.Contains(E);}
135 else if (M_REVERSED(oE)) {meR.Add(E); isb = meF.Contains(E);}
136 if (isb) meI.Add(E.Oriented(TopAbs_INTERNAL));
140 TopTools_MapIteratorOfMapOfShape it(meI);
141 for (; it.More(); it.Next()){
142 const TopoDS_Edge& E = TopoDS::Edge(it.Key());
143 BB.Remove(F,E.Oriented(TopAbs_FORWARD));
144 BB.Remove(F,E.Oriented(TopAbs_REVERSED));
149 //=======================================================================
150 //function : RegularizeFace
152 //=======================================================================
153 void TopOpeBRepBuild_Builder::RegularizeFace
154 (const TopoDS_Shape& FF,const TopoDS_Shape& anewFace,TopTools_ListOfShape& LOF)
157 const TopoDS_Face& newFace = TopoDS::Face(anewFace);
158 Standard_Boolean toregu = Standard_True;
159 Standard_Boolean usewtof = Standard_True;
162 Standard_Integer iF;Standard_Boolean tSPSFF=GtraceSPS(FF,iF);
163 // Standard_Boolean savfregu = TopOpeBRepBuild_GettraceSAVFREGU();
164 if (TopOpeBRepBuild_GetcontextNOREGUFA()) toregu = Standard_False;
165 if (TopOpeBRepBuild_GetcontextREGUXPU()) usewtof = Standard_False;
166 if (tSPSFF) debregufa(iF);
169 // If the same edge appears FOR+REV in the resulting face and
170 // whereas it's not a closing edge, set it as INTERNAL instead.
171 // FRA60275(iF=4) + PRO16297
172 // FUN_setInternal(newFace);
179 TopTools_DataMapOfShapeListOfShape ownw; // OldWires --> NewWires;
180 Standard_Boolean rw = Standard_False;
181 Standard_Boolean rf = Standard_False;
184 rw = TopOpeBRepTool::RegularizeWires(newFace,ownw,myESplits);
191 TopTools_ListOfShape newfaces;
193 TopOpeBRepBuild_WireToFace wtof;
194 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itownw(ownw);
195 for (; itownw.More(); itownw.Next()) {
196 const TopTools_ListOfShape& lw = itownw.Value();
198 // xpu200798 : cto902D4 f14ou
199 // recall ownw = {(ow = old wire, lnw = {list of new wires descendant of old wire}}
200 // if lnw is empty, then ow is kept unchanged.
201 Standard_Boolean kept = lw.IsEmpty();
203 const TopoDS_Wire& ow = TopoDS::Wire(itownw.Key());
206 for(TopTools_ListIteratorOfListOfShape iw(lw);iw.More();iw.Next()) {
207 const TopoDS_Wire& w = TopoDS::Wire(iw.Value());
211 wtof.MakeFaces(newFace,newfaces);
213 // Standard_Integer nnewfaces = newfaces.Extent(); // DEB
215 rf = (newfaces.Extent() != 0);
218 rf = TopOpeBRepTool::RegularizeFace(newFace,ownw,newfaces);
227 if (tSPSFF) { cout<<"RegularizeFace "<<iF<<endl; debregufa(iF); }
230 // LOF = nouvelles faces regularisees de newFace
231 TopTools_ListIteratorOfListOfShape itlnf(newfaces);
232 for (; itlnf.More(); itlnf.Next())
233 LOF.Append(TopoDS::Face(itlnf.Value()));
235 // mise a jour des aretes decoupees
236 // Edge(FF) = {E}, E-->Split(E) = {E'}, E'-->myESplits(E') = {E''}
238 TopTools_MapOfShape menf; // menf = aretes de newFace
240 for (x.Init(newFace,TopAbs_EDGE);x.More();x.Next()) {
241 const TopoDS_Shape& E = x.Current();
245 // lfsdFF = faces SameDomain de FF
246 TopTools_ListOfShape lfsdFF,lfsdFF1,lfsdFF2;
247 GFindSamDom(FF,lfsdFF1,lfsdFF2);
248 lfsdFF.Append(lfsdFF1);
249 lfsdFF.Append(lfsdFF2);
251 TopTools_ListIteratorOfListOfShape itlfsdFF(lfsdFF);
252 for (; itlfsdFF.More(); itlfsdFF.Next()) {
253 const TopoDS_Shape& fsdFF = itlfsdFF.Value();
256 Standard_Integer ifsdFF=0;Standard_Boolean tSPSfsdFF=GtraceSPS(fsdFF,ifsdFF);
257 if (tSPSfsdFF) debregufa(ifsdFF);
260 Standard_Integer rankfsdFF = GShapeRank(fsdFF);
261 TopAbs_State stafsdFF = (rankfsdFF == 1) ? myState1 : myState2;
263 // Standard_Boolean issplitfsdFF = IsSplit(fsdFF,stafsdFF);
267 const TopTools_ListOfShape& lspfsdFF = Splits(fsdFF,stafsdFF);
268 Standard_Integer nlspfsdFF = lspfsdFF.Extent();
271 // iteration sur les aretes de fsdFF
272 for (x.Init(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
274 //fsdFFe : 1 edge de fsdFF = 1 face SameDomain de FF
275 const TopoDS_Shape& fsdFFe = x.Current();
278 Standard_Integer ifsdFFe = 0;Standard_Boolean tSPSfsdFFe=GtraceSPS(fsdFFe,ifsdFFe);
279 if (tSPSfsdFFe) debregufa(ifsdFFe);
282 // a priori, on ne peut avoir plus de deux etats splites
283 // sur l'arete , soit (IN + ON) , soit (OUT + ON)
284 for (Standard_Integer iiista = 1; iiista <= 2; iiista++ ) {
285 TopAbs_State stafsdFFe = stafsdFF;
286 if (iiista == 2) stafsdFFe = TopAbs_ON;
288 TopTools_ListOfShape& lspfsdFFe = ChangeSplit(fsdFFe,stafsdFFe);
290 // Standard_Boolean issplitfsdFFe = IsSplit(fsdFFe,stafsdFFe);
291 // Standard_Integer nlspfsdFFe = lspfsdFFe.Extent();
294 for (TopTools_ListIteratorOfListOfShape it(lspfsdFFe);it.More();it.Next()) {
296 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
298 const TopoDS_Shape& espfsdFFe = it.Value();
299 Standard_Boolean inmenf = menf.Contains(espfsdFFe);
300 if (!inmenf) continue;
302 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
303 // espfsdFFe est une arete de Split(fsdFFe) ET figure dans newFace (Cf supra E')
305 Standard_Boolean resplitloc = myESplits.IsBound(espfsdFFe);
308 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
309 // espfsdFFe est une arete de Split(fsdFFe) ET figure dans newFace (Cf supra E')
310 // espfsdFFe de newFace a ete redecoupee par RegularizeWires
312 // son decoupage lresplit est stocke dans la DS du Builder
313 const TopTools_ListOfShape& lresplit = myESplits.Find(espfsdFFe); //Cf supra E''
315 // on memorise que espfsdFFe est redecoupee ...
316 myMemoSplit.Add(espfsdFFe);
318 // on stocke le nouveau decoupage de espfsdFFe dans la DS du builder ...
319 TopTools_ListOfShape& lsp = ChangeSplit(espfsdFFe,stafsdFFe);
320 GCopyList(lresplit,lsp);
324 } // explore(fsdFF,TopAbs_EDGE)
328 if (tSPSFF) debregufa(iF);
329 if (tSPSFF && savfregu) {
330 TCollection_AsciiString str("fregu"); str = str + iF;
331 DBRep::Set(str.ToCString(),newFace);
332 cout<<"newFace "<<str<<" built on face "<<iF<<" saved"<<endl;