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 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 <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
21 #include <Standard_NoSuchObject.hxx>
22 #include <Standard_ProgramError.hxx>
23 #include <TCollection_AsciiString.hxx>
25 #include <TopExp_Explorer.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Face.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <TopOpeBRepBuild_Builder.hxx>
33 #include <TopOpeBRepBuild_EdgeBuilder.hxx>
34 #include <TopOpeBRepBuild_FaceBuilder.hxx>
35 #include <TopOpeBRepBuild_GTopo.hxx>
36 #include <TopOpeBRepBuild_HBuilder.hxx>
37 #include <TopOpeBRepBuild_PaveSet.hxx>
38 #include <TopOpeBRepBuild_ShapeSet.hxx>
39 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
40 #include <TopOpeBRepBuild_SolidBuilder.hxx>
41 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
42 #include <TopOpeBRepBuild_WireToFace.hxx>
43 #include <TopOpeBRepDS_BuildTool.hxx>
44 #include <TopOpeBRepDS_CurveIterator.hxx>
45 #include <TopOpeBRepDS_define.hxx>
46 #include <TopOpeBRepDS_HDataStructure.hxx>
47 #include <TopOpeBRepDS_PointIterator.hxx>
48 #include <TopOpeBRepDS_SurfaceIterator.hxx>
49 #include <TopOpeBRepTool.hxx>
50 #include <TopOpeBRepTool_ShapeExplorer.hxx>
53 extern Standard_Boolean TopOpeBRepBuild_GetcontextNOREGUFA();
54 extern Standard_Boolean TopOpeBRepBuild_GetcontextREGUXPU();
55 extern Standard_Boolean TopOpeBRepBuild_GettraceSAVFREGU();
56 void debregufa(const Standard_Integer /*iF*/) {}
63 #define M_FORWARD(O) (O == TopAbs_FORWARD)
64 #define M_REVERSED(O) (O == TopAbs_REVERSED)
66 //=======================================================================
67 //function : RegularizeFaces
69 //=======================================================================
70 void TopOpeBRepBuild_Builder::RegularizeFaces
71 (const TopoDS_Shape& FF,const TopTools_ListOfShape& lnewFace,TopTools_ListOfShape& LOF)
76 TopTools_ListIteratorOfListOfShape itl(lnewFace);
77 for (;itl.More();itl.Next()) {
78 const TopoDS_Shape& newFace = itl.Value();
79 TopTools_ListOfShape newFaceLOF;
80 RegularizeFace(FF,newFace,newFaceLOF);
82 // Standard_Integer nnewFaceLOF = newFaceLOF.Extent(); // DEB
84 LOF.Append(newFaceLOF);
87 // Standard_Integer nLOF = LOF.Extent(); // DEB
90 Standard_Integer nr = myMemoSplit.Extent();
93 // lfsdFF = faces SameDomain de FF
94 TopTools_ListOfShape lfsdFF,lfsdFF1,lfsdFF2;
95 GFindSamDom(FF,lfsdFF1,lfsdFF2);
96 lfsdFF.Append(lfsdFF1);
97 lfsdFF.Append(lfsdFF2);
99 TopTools_ListIteratorOfListOfShape itlfsdFF(lfsdFF);
100 for (; itlfsdFF.More(); itlfsdFF.Next()) {
101 const TopoDS_Shape& fsdFF = itlfsdFF.Value();
102 // au moins une arete de FF dont le Split() est lui meme Split()
104 for (x.Init(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
105 // for (TopExp_Explorer x(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
106 const TopoDS_Shape& e = x.Current();
108 // Standard_Integer ie = myDataStructure->Shape(e); //DEB
109 // Standard_Boolean issect = myDataStructure->DS().IsSectionEdge(TopoDS::Edge(e));
112 Standard_Integer ranke = GShapeRank(e);
113 TopAbs_State staeope = (ranke==1) ? myState1 : myState2;
115 for (Standard_Integer iiista = 1; iiista <= 2; iiista++ ) {
117 TopAbs_State stae = staeope;
118 if (iiista == 2) stae = TopAbs_ON;
120 Standard_Boolean issplite = IsSplit(e,stae);
121 if (!issplite) continue;
123 TopTools_ListOfShape& lspe = ChangeSplit(e,stae);
125 // Standard_Integer nlspe = lspe.Extent(); // DEB
127 TopTools_ListOfShape newlspe;
128 for (TopTools_ListIteratorOfListOfShape itl1(lspe);itl1.More();itl1.Next()) {
129 const TopoDS_Shape& esp = itl1.Value();
130 Standard_Boolean espmemo = myMemoSplit.Contains(esp);
131 if (!espmemo) newlspe.Append(esp);
133 const TopTools_ListOfShape& lspesp = Splits(esp,stae);
134 GCopyList(lspesp,newlspe);
138 GCopyList(newlspe,lspe);
141 } // explorer (fsdFF,TopAbs_EDGE)
145 /*static void FUN_setInternal(TopoDS_Face& F)
147 TopExp_Explorer ex(F,TopAbs_EDGE);
148 TopTools_MapOfShape meF,meR,meI;
149 for (; ex.More(); ex.Next()){
150 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
151 TopAbs_Orientation oE = E.Orientation();
152 Standard_Boolean isclo = BRep_Tool::IsClosed(E,F); // E has 2d rep on F
154 Standard_Boolean isb = Standard_False; // the edge is FOR + REV in F
155 if (M_FORWARD(oE)) {meF.Add(E); isb = meR.Contains(E);}
156 else if (M_REVERSED(oE)) {meR.Add(E); isb = meF.Contains(E);}
157 if (isb) meI.Add(E.Oriented(TopAbs_INTERNAL));
161 TopTools_MapIteratorOfMapOfShape it(meI);
162 for (; it.More(); it.Next()){
163 const TopoDS_Edge& E = TopoDS::Edge(it.Key());
164 BB.Remove(F,E.Oriented(TopAbs_FORWARD));
165 BB.Remove(F,E.Oriented(TopAbs_REVERSED));
170 //=======================================================================
171 //function : RegularizeFace
173 //=======================================================================
174 void TopOpeBRepBuild_Builder::RegularizeFace
175 (const TopoDS_Shape& FF,const TopoDS_Shape& anewFace,TopTools_ListOfShape& LOF)
178 const TopoDS_Face& newFace = TopoDS::Face(anewFace);
179 Standard_Boolean toregu = Standard_True;
180 Standard_Boolean usewtof = Standard_True;
183 Standard_Integer iF;Standard_Boolean tSPSFF=GtraceSPS(FF,iF);
184 // Standard_Boolean savfregu = TopOpeBRepBuild_GettraceSAVFREGU();
185 if (TopOpeBRepBuild_GetcontextNOREGUFA()) toregu = Standard_False;
186 if (TopOpeBRepBuild_GetcontextREGUXPU()) usewtof = Standard_False;
187 if (tSPSFF) debregufa(iF);
190 // If the same edge appears FOR+REV in the resulting face and
191 // whereas it's not a closing edge, set it as INTERNAL instead.
192 // FRA60275(iF=4) + PRO16297
193 // FUN_setInternal(newFace);
200 TopTools_DataMapOfShapeListOfShape ownw; // OldWires --> NewWires;
201 Standard_Boolean rw = Standard_False;
202 Standard_Boolean rf = Standard_False;
205 rw = TopOpeBRepTool::RegularizeWires(newFace,ownw,myESplits);
212 TopTools_ListOfShape newfaces;
214 TopOpeBRepBuild_WireToFace wtof;
215 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itownw(ownw);
216 for (; itownw.More(); itownw.Next()) {
217 const TopTools_ListOfShape& lw = itownw.Value();
219 // xpu200798 : cto902D4 f14ou
220 // recall ownw = {(ow = old wire, lnw = {list of new wires descendant of old wire}}
221 // if lnw is empty, then ow is kept unchanged.
222 Standard_Boolean kept = lw.IsEmpty();
224 const TopoDS_Wire& ow = TopoDS::Wire(itownw.Key());
227 for(TopTools_ListIteratorOfListOfShape iw(lw);iw.More();iw.Next()) {
228 const TopoDS_Wire& w = TopoDS::Wire(iw.Value());
232 wtof.MakeFaces(newFace,newfaces);
234 // Standard_Integer nnewfaces = newfaces.Extent(); // DEB
236 rf = (newfaces.Extent() != 0);
239 rf = TopOpeBRepTool::RegularizeFace(newFace,ownw,newfaces);
248 if (tSPSFF) { cout<<"RegularizeFace "<<iF<<endl; debregufa(iF); }
251 // LOF = nouvelles faces regularisees de newFace
252 TopTools_ListIteratorOfListOfShape itlnf(newfaces);
253 for (; itlnf.More(); itlnf.Next())
254 LOF.Append(TopoDS::Face(itlnf.Value()));
256 // mise a jour des aretes decoupees
257 // Edge(FF) = {E}, E-->Split(E) = {E'}, E'-->myESplits(E') = {E''}
259 TopTools_MapOfShape menf; // menf = aretes de newFace
261 for (x.Init(newFace,TopAbs_EDGE);x.More();x.Next()) {
262 const TopoDS_Shape& E = x.Current();
266 // lfsdFF = faces SameDomain de FF
267 TopTools_ListOfShape lfsdFF,lfsdFF1,lfsdFF2;
268 GFindSamDom(FF,lfsdFF1,lfsdFF2);
269 lfsdFF.Append(lfsdFF1);
270 lfsdFF.Append(lfsdFF2);
272 TopTools_ListIteratorOfListOfShape itlfsdFF(lfsdFF);
273 for (; itlfsdFF.More(); itlfsdFF.Next()) {
274 const TopoDS_Shape& fsdFF = itlfsdFF.Value();
277 Standard_Integer ifsdFF=0;Standard_Boolean tSPSfsdFF=GtraceSPS(fsdFF,ifsdFF);
278 if (tSPSfsdFF) debregufa(ifsdFF);
281 Standard_Integer rankfsdFF = GShapeRank(fsdFF);
282 TopAbs_State stafsdFF = (rankfsdFF == 1) ? myState1 : myState2;
284 // Standard_Boolean issplitfsdFF = IsSplit(fsdFF,stafsdFF);
288 const TopTools_ListOfShape& lspfsdFF = Splits(fsdFF,stafsdFF);
289 Standard_Integer nlspfsdFF = lspfsdFF.Extent();
292 // iteration sur les aretes de fsdFF
293 for (x.Init(fsdFF,TopAbs_EDGE);x.More();x.Next()) {
295 //fsdFFe : 1 edge de fsdFF = 1 face SameDomain de FF
296 const TopoDS_Shape& fsdFFe = x.Current();
299 Standard_Integer ifsdFFe = 0;Standard_Boolean tSPSfsdFFe=GtraceSPS(fsdFFe,ifsdFFe);
300 if (tSPSfsdFFe) debregufa(ifsdFFe);
303 // a priori, on ne peut avoir plus de deux etats splites
304 // sur l'arete , soit (IN + ON) , soit (OUT + ON)
305 for (Standard_Integer iiista = 1; iiista <= 2; iiista++ ) {
306 TopAbs_State stafsdFFe = stafsdFF;
307 if (iiista == 2) stafsdFFe = TopAbs_ON;
309 TopTools_ListOfShape& lspfsdFFe = ChangeSplit(fsdFFe,stafsdFFe);
311 // Standard_Boolean issplitfsdFFe = IsSplit(fsdFFe,stafsdFFe);
312 // Standard_Integer nlspfsdFFe = lspfsdFFe.Extent();
315 for (TopTools_ListIteratorOfListOfShape it(lspfsdFFe);it.More();it.Next()) {
317 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
319 const TopoDS_Shape& espfsdFFe = it.Value();
320 Standard_Boolean inmenf = menf.Contains(espfsdFFe);
321 if (!inmenf) continue;
323 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
324 // espfsdFFe est une arete de Split(fsdFFe) ET figure dans newFace (Cf supra E')
326 Standard_Boolean resplitloc = myESplits.IsBound(espfsdFFe);
329 // fsdFFe (Cf supra E) a ete splittee, espfdsFFe = arete splittee de fsdFFe
330 // espfsdFFe est une arete de Split(fsdFFe) ET figure dans newFace (Cf supra E')
331 // espfsdFFe de newFace a ete redecoupee par RegularizeWires
333 // son decoupage lresplit est stocke dans la DS du Builder
334 const TopTools_ListOfShape& lresplit = myESplits.Find(espfsdFFe); //Cf supra E''
336 // on memorise que espfsdFFe est redecoupee ...
337 myMemoSplit.Add(espfsdFFe);
339 // on stocke le nouveau decoupage de espfsdFFe dans la DS du builder ...
340 TopTools_ListOfShape& lsp = ChangeSplit(espfsdFFe,stafsdFFe);
341 GCopyList(lresplit,lsp);
345 } // explore(fsdFF,TopAbs_EDGE)
349 if (tSPSFF) debregufa(iF);
350 if (tSPSFF && savfregu) {
351 TCollection_AsciiString str("fregu"); str = str + iF;
352 DBRep::Set(str.ToCString(),newFace);
353 cout<<"newFace "<<str<<" built on face "<<iF<<" saved"<<endl;