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
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.
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.
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.
22 #include <TopOpeBRepBuild_Builder.ixx>
24 #include <TopOpeBRepBuild_WireToFace.hxx>
25 #include <TopOpeBRepTool.hxx>
26 #include <TopExp_Explorer.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>
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*/) {}
47 #define M_FORWARD(O) (O == TopAbs_FORWARD)
48 #define M_REVERSED(O) (O == TopAbs_REVERSED)
50 //=======================================================================
51 //function : RegularizeFaces
53 //=======================================================================
54 void TopOpeBRepBuild_Builder::RegularizeFaces
55 (const TopoDS_Shape& FF,const TopTools_ListOfShape& lnewFace,TopTools_ListOfShape& LOF)
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);
66 // Standard_Integer nnewFaceLOF = newFaceLOF.Extent(); // DEB
68 LOF.Append(newFaceLOF);
71 // Standard_Integer nLOF = LOF.Extent(); // DEB
74 Standard_Integer nr = myMemoSplit.Extent();
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);
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()
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();
92 // Standard_Integer ie = myDataStructure->Shape(e); //DEB
93 // Standard_Boolean issect = myDataStructure->DS().IsSectionEdge(TopoDS::Edge(e));
96 Standard_Integer ranke = GShapeRank(e);
97 TopAbs_State staeope = (ranke==1) ? myState1 : myState2;
99 for (Standard_Integer iiista = 1; iiista <= 2; iiista++ ) {
101 TopAbs_State stae = staeope;
102 if (iiista == 2) stae = TopAbs_ON;
104 Standard_Boolean issplite = IsSplit(e,stae);
105 if (!issplite) continue;
107 TopTools_ListOfShape& lspe = ChangeSplit(e,stae);
109 // Standard_Integer nlspe = lspe.Extent(); // DEB
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);
117 const TopTools_ListOfShape& lspesp = Splits(esp,stae);
118 GCopyList(lspesp,newlspe);
122 GCopyList(newlspe,lspe);
125 } // explorer (fsdFF,TopAbs_EDGE)
129 /*static void FUN_setInternal(TopoDS_Face& F)
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
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));
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));
154 //=======================================================================
155 //function : RegularizeFace
157 //=======================================================================
158 void TopOpeBRepBuild_Builder::RegularizeFace
159 (const TopoDS_Shape& FF,const TopoDS_Shape& anewFace,TopTools_ListOfShape& LOF)
162 const TopoDS_Face& newFace = TopoDS::Face(anewFace);
163 Standard_Boolean toregu = Standard_True;
164 Standard_Boolean usewtof = Standard_True;
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);
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);
184 TopTools_DataMapOfShapeListOfShape ownw; // OldWires --> NewWires;
185 Standard_Boolean rw = Standard_False;
186 Standard_Boolean rf = Standard_False;
189 rw = TopOpeBRepTool::RegularizeWires(newFace,ownw,myESplits);
196 TopTools_ListOfShape newfaces;
198 TopOpeBRepBuild_WireToFace wtof;
199 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itownw(ownw);
200 for (; itownw.More(); itownw.Next()) {
201 const TopTools_ListOfShape& lw = itownw.Value();
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();
208 const TopoDS_Wire& ow = TopoDS::Wire(itownw.Key());
211 for(TopTools_ListIteratorOfListOfShape iw(lw);iw.More();iw.Next()) {
212 const TopoDS_Wire& w = TopoDS::Wire(iw.Value());
216 wtof.MakeFaces(newFace,newfaces);
218 // Standard_Integer nnewfaces = newfaces.Extent(); // DEB
220 rf = (newfaces.Extent() != 0);
223 rf = TopOpeBRepTool::RegularizeFace(newFace,ownw,newfaces);
232 if (tSPSFF) { cout<<"RegularizeFace "<<iF<<endl; debregufa(iF); }
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()));
240 // mise a jour des aretes decoupees
241 // Edge(FF) = {E}, E-->Split(E) = {E'}, E'-->myESplits(E') = {E''}
243 TopTools_MapOfShape menf; // menf = aretes de newFace
245 for (x.Init(newFace,TopAbs_EDGE);x.More();x.Next()) {
246 const TopoDS_Shape& E = x.Current();
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);
256 TopTools_ListIteratorOfListOfShape itlfsdFF(lfsdFF);
257 for (; itlfsdFF.More(); itlfsdFF.Next()) {
258 const TopoDS_Shape& fsdFF = itlfsdFF.Value();
261 Standard_Integer ifsdFF=0;Standard_Boolean tSPSfsdFF=GtraceSPS(fsdFF,ifsdFF);
262 if (tSPSfsdFF) debregufa(ifsdFF);
265 Standard_Integer rankfsdFF = GShapeRank(fsdFF);
266 TopAbs_State stafsdFF = (rankfsdFF == 1) ? myState1 : myState2;
268 // Standard_Boolean issplitfsdFF = IsSplit(fsdFF,stafsdFF);
272 const TopTools_ListOfShape& lspfsdFF = Splits(fsdFF,stafsdFF);
273 Standard_Integer nlspfsdFF = lspfsdFF.Extent();
276 // iteration sur les aretes de fsdFF
277 for (x.Init(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
279 //fsdFFe : 1 edge de fsdFF = 1 face SameDomain de FF
280 const TopoDS_Shape& fsdFFe = x.Current();
283 Standard_Integer ifsdFFe = 0;Standard_Boolean tSPSfsdFFe=GtraceSPS(fsdFFe,ifsdFFe);
284 if (tSPSfsdFFe) debregufa(ifsdFFe);
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;
293 TopTools_ListOfShape& lspfsdFFe = ChangeSplit(fsdFFe,stafsdFFe);
295 // Standard_Boolean issplitfsdFFe = IsSplit(fsdFFe,stafsdFFe);
296 // Standard_Integer nlspfsdFFe = lspfsdFFe.Extent();
299 Standard_Integer nDEB2=0 ;
301 for (TopTools_ListIteratorOfListOfShape it(lspfsdFFe);it.More();it.Next()) {
303 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
305 const TopoDS_Shape& espfsdFFe = it.Value();
306 Standard_Boolean inmenf = menf.Contains(espfsdFFe);
307 if (!inmenf) continue;
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')
312 Standard_Boolean resplitloc = myESplits.IsBound(espfsdFFe);
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
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();
323 // on memorise que espfsdFFe est redecoupee ...
324 myMemoSplit.Add(espfsdFFe);
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();
333 } // explore(fsdFF,TopAbs_EDGE)
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;