0024510: Remove unused local variables
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_makefaces.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TopOpeBRepBuild_Builder.ixx>
18
19 #include <BRep_Builder.hxx>
20 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
21 #include <TopTools_IndexedMapOfOrientedShape.hxx>
22 #include <TopExp.hxx>
23 #include <TopoDS.hxx>
24 #include <TopoDS_Wire.hxx>
25 #include <TopoDS_Compound.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRepTools.hxx>
28 #include <GeomAdaptor_Surface.hxx>
29 #include <GeomAbs_SurfaceType.hxx>
30 #include <Geom_Surface.hxx>
31 #include <Geom_RectangularTrimmedSurface.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <Standard_ProgramError.hxx>
34 #include <TopOpeBRepDS.hxx>
35 #include <TopOpeBRepDS_EXPORT.hxx>
36 #include <TopOpeBRepTool.hxx>
37 #include <TopOpeBRepTool_EXPORT.hxx>
38 #include <TopOpeBRepBuild_define.hxx>
39 #include <TopOpeBRepTool_2d.hxx>
40
41
42 #ifdef DEB
43 extern Standard_Boolean TopOpeBRepBuild_GetcontextNOPURGE();
44 extern Standard_Boolean TopOpeBRepBuild_GetcontextNOCORRISO();
45 extern Standard_Boolean TopOpeBRepBuild_GettraceCHK();
46 extern Standard_Boolean TopOpeBRepDS_GettraceSTRANGE();
47 #define DEBSHASET(sarg,meth,shaset,str) \
48 TCollection_AsciiString sarg((meth));(sarg)=(sarg)+(shaset).DEBNumber()+(str);
49 Standard_EXPORT void debgfabu(const Standard_Integer i) {cout<<"++ debgfabu "<<i<<endl;}
50 Standard_EXPORT void debwesmf(const Standard_Integer i) {cout<<"++ debwesmf "<<i<<endl;}
51 Standard_EXPORT Standard_Boolean DEBpurclo = Standard_False;
52 void debpurclo() {}
53 void debpurclomess(Standard_Integer i){cout<<"++ debpurclo "<<i<<endl;debpurclo();}
54 Standard_EXPORT void debcorriso(const Standard_Integer i) {cout<<"++ debcorriso "<<i<<endl;}
55 extern void* GFABUMAKEFACEPWES_DEB;
56 #endif
57
58 #ifdef DRAW
59 #include <DBRep.hxx>
60 #include <TopOpeBRepTool_DRAW.hxx>
61 #endif
62
63 Standard_EXPORT Standard_Boolean FUN_tool_ClosedW(const TopoDS_Wire& W);
64 // Unused :
65 /*#ifdef DEB
66 static void FUN_Raise(){cout<<"--------- ERROR in GWESMakeFaces ---------"<<endl;}
67 #endif*/
68
69 //=======================================================================
70 //function : GWESMakeFaces
71 //purpose  : 
72 //=======================================================================
73 void TopOpeBRepBuild_Builder::GWESMakeFaces
74 (const TopoDS_Shape& FF,TopOpeBRepBuild_WireEdgeSet& WES,TopTools_ListOfShape& LOF)  
75 {
76 #ifdef DEB  
77   Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(FF,iF);
78   DEBSHASET(s,"#--- GWESMakeFaces ",WES," ");
79   if(tSPS){ GdumpSHA(FF,(Standard_Address)s.ToCString());cout<<endl; WES.DumpSS();}
80   if(tSPS){debwesmf(iF);}
81   GFABUMAKEFACEPWES_DEB = (void*)&WES;
82 #endif
83   
84   const Standard_Boolean ForceClass = Standard_True;
85   TopOpeBRepBuild_FaceBuilder FABU;
86   FABU.InitFaceBuilder(WES,FF,ForceClass);
87   
88   // Wire checking,the aim is to rebuild faces having
89   // edges unconnected to the others (in the face UV representation)
90   // This can occur when the face has a closing edge. To avoid this,
91   // we delete the lonesome closing edge from the wire.
92   Standard_Boolean topurge = Standard_True;
93 #ifdef DEB
94   if (TopOpeBRepBuild_GetcontextNOPURGE()) topurge = Standard_False;
95 #endif
96
97 #ifdef DRAW
98   Standard_Boolean traceF = Standard_False;
99   if (traceF) {
100     TopTools_IndexedMapOfShape mapW;
101     for (FABU.InitFace(); FABU.MoreFace(); FABU.NextFace()) {
102       for (FABU.InitWire(); FABU.MoreWire(); FABU.NextWire()) {      
103         TopoDS_Shape W;
104         Standard_Boolean isold = FABU.IsOldWire();
105         if (isold) W = FABU.OldWire();
106         else {
107           BRep_Builder BB;
108           TopoDS_Compound cmp; BB.MakeCompound(cmp);
109           FABU.InitEdge();
110           for (; FABU.MoreEdge(); FABU.NextEdge()) FABU.AddEdgeWire(FABU.Edge(),cmp);
111           W = cmp;
112         }
113         if (W.IsNull()) continue;
114         Standard_Integer iiwi = mapW.Add(W);    TCollection_AsciiString aa("wii_");FUN_tool_draw(aa,W,iiwi);
115       }
116     }
117   }
118 #endif
119   
120   if (topurge) {
121     TopOpeBRepDS_DataStructure& BDS = myDataStructure->ChangeDS();
122     
123     TopTools_IndexedMapOfShape mapPIE; // pseudo internal edges
124     FABU.DetectPseudoInternalEdge(mapPIE);
125
126     TopTools_IndexedDataMapOfShapeShape mapVVsameG,mapVon1Edge,mapVVref; 
127     FABU.DetectUnclosedWire(mapVVsameG,mapVon1Edge);
128     
129     Standard_Integer nVV = mapVVsameG.Extent();
130     if (nVV > 0) {
131       // Updating the DS with same domain vertices,
132       // filling up map <mapVVref>
133       for (Standard_Integer i = 1; i <= nVV; i++) {
134         const TopoDS_Shape& V = mapVVsameG.FindKey(i);
135         Standard_Boolean hsdm = myDataStructure->HasSameDomain(V);
136         if (!hsdm) {
137           Standard_Integer rankV = BDS.AncestorRank(V);
138           
139           const TopoDS_Shape& VsameG = mapVVsameG.FindFromIndex(i);
140
141           // MSV Oct 4, 2001: prefer old vertex as SameDomainReference
142           Standard_Integer rankVsameG = BDS.AncestorRank(VsameG);
143           Standard_Boolean otherRef = (rankVsameG != 0 && rankV != 1);
144
145           if (otherRef)
146             BDS.FillShapesSameDomain(VsameG,V);
147           else
148             BDS.FillShapesSameDomain(V,VsameG);
149
150           hsdm = myDataStructure->HasSameDomain(V);  
151         }
152         if (hsdm) {
153           Standard_Integer Iref = myDataStructure->SameDomainReference(V);
154           const TopoDS_Shape& Vref = myDataStructure->Shape(Iref);
155           mapVVref.Add(V,Vref);
156         }
157       }
158       FABU.CorrectGclosedWire(mapVVref,mapVon1Edge);
159       FABU.DetectUnclosedWire(mapVVsameG,mapVon1Edge);
160     }    
161   }
162     
163   TopTools_DataMapOfShapeInteger MWisOld;
164   TopTools_IndexedMapOfOrientedShape MshNOK;
165   GFABUMakeFaces(FF,FABU,LOF,MWisOld);
166   
167   // 2.  on periodic face F :
168   //   finds up faulty shapes MshNOK to avoid when building up shapes
169   //   (edge no longer closing that appears twice in the new face)
170
171   if (topurge) {
172
173 #ifdef DRAW
174     if (tSPS) {
175       cout<<endl<<"#<< AVANT PurgeClosingEdges "<<endl; 
176       GdumpFABU(FABU);
177       TopTools_ListOfShape dLOF;TopTools_DataMapOfShapeInteger dMWisOld;
178       GFABUMakeFaces(FF,FABU,dLOF,dMWisOld);
179       TopTools_ListIteratorOfListOfShape X(dLOF); for (Standard_Integer i=1;X.More();X.Next(),i++) {
180         TCollection_AsciiString ss("purclo");ss=ss+i;DBRep::Set(ss.ToCString(),X.Value());
181         cout<<"... face "<<ss<<endl;
182       }
183       debpurclomess(iF);
184       DEBpurclo = Standard_True;
185     }
186 #endif
187     
188     const TopoDS_Face& FA = TopoDS::Face(FF);
189     Standard_Boolean puok = TopOpeBRepTool::PurgeClosingEdges(FA,LOF,MWisOld,MshNOK);
190     if (!puok) Standard_Failure::Raise("TopOpeBRepBuild::GWESMakeFaces");
191     topurge = !MshNOK.IsEmpty();
192
193 #ifdef DEB
194     if (tSPS) DEBpurclo = Standard_False;
195 #endif
196   } // topurge
197
198   if (topurge) {
199     TopTools_ListOfShape LOFF;
200     Standard_Boolean puok = TopOpeBRepTool::MakeFaces(TopoDS::Face(FF),LOF,MshNOK,LOFF);
201     if (!puok) Standard_Failure::Raise("TopOpeBRepBuild::GWESMakeFaces");
202     LOF.Clear(); LOF.Assign(LOFF);
203   }
204
205   //1.  on periodic face F :
206   //  translates edge's pcurve to have it in F's UVbounds  
207   //  translates edge's pcurve to have it connexed to others in UV space 
208   Standard_Boolean corronISO = Standard_True;
209 #ifdef DEB
210   if (TopOpeBRepBuild_GetcontextNOCORRISO()) corronISO = Standard_False;
211   if (tSPS) debcorriso(iF);
212 #endif
213   Standard_Boolean ffcloseds = FUN_tool_closedS(FF);
214   corronISO = corronISO && ffcloseds;
215   if (corronISO) {
216     TopTools_ListIteratorOfListOfShape itFF(LOF);
217     TopTools_ListOfShape newLOF;
218     const TopoDS_Face& FFa = TopoDS::Face(FF);
219     for (; itFF.More(); itFF.Next()){
220       TopoDS_Face Fa = TopoDS::Face(itFF.Value());
221       TopOpeBRepTool::CorrectONUVISO(FFa,Fa);
222       newLOF.Append(Fa);
223     }
224     LOF.Clear(); LOF.Assign(newLOF);
225   }
226
227   // xpu280898 : regularisation after GFABUMakeFaces,purge processings
228   TopTools_ListOfShape newLOF; RegularizeFaces(FF,LOF,newLOF);
229   LOF.Clear(); LOF.Assign(newLOF);
230
231 } // GWESMakeFaces
232
233 //------------------------------------------------------
234 // retourne vrai si newFace contient une seule arete non orientee
235 //------------------------------------------------------
236 static Standard_Boolean FUN_purgeFon1nonoriE(const TopoDS_Shape& newFace)
237 {
238   TopExp_Explorer ex(newFace,TopAbs_EDGE);
239   Standard_Integer nE = 0;
240   for (; ex.More(); ex.Next()) nE++;
241   if (nE == 1) {
242     ex.Init(newFace,TopAbs_EDGE);
243     const TopoDS_Shape& ed = ex.Current();
244     TopAbs_Orientation ori = ed.Orientation();
245     Standard_Boolean hasori = (ori == TopAbs_FORWARD) || (ori == TopAbs_REVERSED);
246     if (!hasori) return Standard_True;
247     //// modified by jgv, 6.06.02 for OCC424 ////
248     TopoDS_Edge theEdge = TopoDS::Edge( ed );
249     if (BRep_Tool::Degenerated( theEdge ))
250       return Standard_True;
251     /////////////////////////////////////////////
252   }
253   return Standard_False;
254 }
255
256 //-- ofv --------------------------------------------------------------------
257 // function : FUN_ReOrientIntExtEdge
258 // purpose  : change orientation of INTERNAL (EXTERNAL) edge, if necessary 
259 //            FRE  - tool (edge with FORWARD or REVERSED orientation),
260 //            OFRE - orientation of tool (FORWARD or REVERSED),
261 //            INE  - object (edge with INTERNAL (EXTERNAL) orientation)
262 //---------------------------------------------------------------------------
263 static TopAbs_Orientation FUN_ReOrientIntExtEdge(const TopoDS_Edge& FRE,
264                                                  TopAbs_Orientation OFRE,
265                                                  const TopoDS_Edge& INE)
266 {
267   TopAbs_Orientation result = INE.Orientation();
268   TopoDS_Vertex Vf1,Vl1,Vf2,Vl2;
269
270   TopExp::Vertices(FRE, Vf1, Vl1, Standard_False);
271   TopExp::Vertices(INE, Vf2, Vl2, Standard_False);
272
273   if(OFRE == TopAbs_FORWARD)
274     {
275       if(Vl1.IsSame(Vf2)) result = TopAbs_FORWARD;
276       if(Vl1.IsSame(Vl2)) result = TopAbs_REVERSED;
277       if(Vf1.IsSame(Vf2)) result = TopAbs_REVERSED;
278       if(Vf1.IsSame(Vl2)) result = TopAbs_FORWARD;
279     }
280   if(OFRE == TopAbs_REVERSED)
281     {
282       if(Vl1.IsSame(Vf2)) result = TopAbs_REVERSED;
283       if(Vl1.IsSame(Vl2)) result = TopAbs_FORWARD;
284       if(Vf1.IsSame(Vf2)) result = TopAbs_FORWARD;
285       if(Vf1.IsSame(Vl2)) result = TopAbs_REVERSED;
286     }
287   return result;
288 }
289 //----------------------------------------------------------------------------
290
291 //-- ofv --------------------------------------------------------------------
292 // function : FUN_CheckORI
293 // purpose  :
294 //----------------------------------------------------------------------------
295 static Standard_Integer FUN_CheckORI(TopAbs_Orientation O1,
296                                      TopAbs_Orientation O2)
297 {
298   Standard_Integer result;
299   if((O1 == TopAbs_INTERNAL || O1 == TopAbs_EXTERNAL) && (O2 == TopAbs_INTERNAL || O2 == TopAbs_EXTERNAL)) result = 0;
300   else if((O1 == TopAbs_INTERNAL || O1 == TopAbs_EXTERNAL) && (O2 == TopAbs_FORWARD || O2 == TopAbs_REVERSED)) result = 1;
301   else if((O1 == TopAbs_FORWARD || O1 == TopAbs_REVERSED) && (O2 == TopAbs_INTERNAL || O2 == TopAbs_EXTERNAL)) result = 2;
302   else result = 4;
303   return result;
304 }
305 //----------------------------------------------------------------------------
306 //=======================================================================
307 //function : GFABUMakeFaces
308 //purpose  : 
309 //=======================================================================
310
311 void TopOpeBRepBuild_Builder::GFABUMakeFaces(const TopoDS_Shape& FF,TopOpeBRepBuild_FaceBuilder& FABU,
312                           TopTools_ListOfShape& LOF,TopTools_DataMapOfShapeInteger& MWisOld)
313 {
314 #ifdef DEB
315   Standard_Integer iF;Standard_Boolean tSPS=GtraceSPS(FF,iF);
316   if(tSPS) {
317     cout<<endl;GdumpSHA(FF,(char *) "#--- GFABUMakeFaces ");cout<<endl;
318     GdumpFABU(FABU);debgfabu(iF);
319   }
320   Standard_Boolean strange = TopOpeBRepDS_GettraceSTRANGE();
321 #endif
322   
323   TopTools_ListOfShape lnewFace;
324   TopoDS_Face newFace;
325   TopoDS_Wire newWire;
326   
327   TopLoc_Location Loc;
328   Handle(Geom_Surface) Surf = BRep_Tool::Surface(TopoDS::Face(FF),Loc);
329 // JYL : mise en // des 5 lignes suivantes pour reprendre la correction de DPF
330 //       du 29/07/1998
331 //  GeomAdaptor_Surface GAS1(Surf);
332 //  GeomAbs_SurfaceType tt1 = GAS1.GetType();
333 //  Handle(Standard_Type) T = Surf->DynamicType();
334 //  Standard_Boolean istrim = ( T == STANDARD_TYPE(Geom_RectangularTrimmedSurface) );
335 //  if ( istrim && tt1 == GeomAbs_Plane) Surf = Handle(Geom_RectangularTrimmedSurface)::DownCast(Surf)->BasisSurface();
336   Standard_Real tolFF = BRep_Tool::Tolerance(TopoDS::Face(FF));
337   BRep_Builder BB;
338
339
340   //--ofv:
341   //       Unfortunately, the function GFillONPartsWES2() from file TopOpeBRepBuild_BuilderON.cxx sets orientation of
342   //       some section edges as INTERNAL or EXTERNAL, but they should be FORWARD or REVERSED. It probably makes faces
343   //       without closed boundary, for example. So, we must check carefuly edges with orientation INTERNAL(EXTERNAL).
344   //       Bugs: 60936, 60937, 60938 (cut, fuse, common shapes)
345   TopoDS_Compound CmpOfEdges;
346   BRep_Builder BldCmpOfEdges;
347   TopTools_IndexedDataMapOfShapeListOfShape mapVOE;
348   TopoDS_Face tdF = TopoDS::Face(FF);
349   //--ofv.
350
351   FABU.InitFace();
352   for (; FABU.MoreFace(); FABU.NextFace())
353     {
354       Standard_Integer nbnewWwithe = 0;
355       Standard_Integer nboldW = 0;
356     
357       BB.MakeFace(newFace,Surf,Loc,tolFF);
358 //    myBuildTool.CopyFace(FF,newFace);
359
360       Standard_Integer nbw = FABU.InitWire();
361       for (; FABU.MoreWire(); FABU.NextWire())
362         {
363           Standard_Integer ne = 0;
364           Standard_Integer neFORWARD  = 0;
365           Standard_Integer neREVERSED = 0;
366           Standard_Integer neINTERNAL = 0;
367           Standard_Integer neEXTERNAL = 0;
368
369           Standard_Boolean isold = FABU.IsOldWire();
370           if(isold)
371             {
372               nboldW++;
373               newWire = TopoDS::Wire(FABU.OldWire());
374             }
375           else
376             {
377               BldCmpOfEdges.MakeCompound(CmpOfEdges);//new compound
378               myBuildTool.MakeWire(newWire);
379               FABU.InitEdge();
380               for(; FABU.MoreEdge(); FABU.NextEdge())
381                 {
382                   TopoDS_Edge newEdge = TopoDS::Edge(FABU.Edge());
383 //                if (mEtouched.Contains(newEdge)) continue;// xpu290498
384 //                mEtouched.Add(newEdge);// xpu290498
385
386                   //--ofv:
387                   Standard_Integer nadde = FABU.AddEdgeWire(newEdge,CmpOfEdges);
388                   ne += nadde;
389                   //Standard_Integer nadde = FABU.AddEdgeWire(newEdge,newWire);
390                   //ne += nadde;
391                   //--ofv.
392
393                   TopAbs_Orientation oE = newEdge.Orientation();
394                   if      (oE == TopAbs_INTERNAL) neINTERNAL++;
395                   else if (oE == TopAbs_EXTERNAL) neEXTERNAL++;
396                   else if (oE == TopAbs_FORWARD)  neFORWARD++;
397                   else if (oE == TopAbs_REVERSED) neREVERSED++;
398           
399                   Standard_Boolean hasPC = FC2D_HasCurveOnSurface(newEdge,newFace);                                     // jyl980402+
400                   if (!hasPC)                                                                                           // jyl980402+
401                     {                                                                                                   // jyl980402+
402                       Standard_Real tolE = BRep_Tool::Tolerance(newEdge);                                               // jyl980402+
403                       Standard_Real f2,l2,tolpc; Handle(Geom2d_Curve) C2D;                                              // jyl980402+
404                       //C2D = FC2D_CurveOnSurface(newEdge,newFace,f2,l2,tolpc);                                         // jyl980402+
405                       C2D = FC2D_CurveOnSurface(newEdge,newFace,f2,l2,tolpc, Standard_True);                            // xpu051198 (CTS21701)
406                       if(C2D.IsNull()) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::GFABUMakeFaces null PC"); // jyl980402+
407                       Standard_Real tol = Max(tolE,tolpc);                                                              // jyl980402+
408                       BRep_Builder BB_PC; BB_PC.UpdateEdge(newEdge,C2D,newFace,tol);                                    // jyl980402+
409                     }                                                                                                   // jyl980402+
410                 } // FABU.MoreEdge()
411
412               //--ofv:
413               if((neINTERNAL == 0 && neEXTERNAL == 0) || (ne == neINTERNAL || ne == neEXTERNAL))
414                 {
415                   TopExp_Explorer EdgeEx;
416                   if(nbw == 1 && ne == 2)
417                     {
418                       EdgeEx.Init(CmpOfEdges,TopAbs_EDGE);
419                       TopoDS_Edge nEdge1 = TopoDS::Edge(EdgeEx.Current());
420                       EdgeEx.Next();
421                       TopoDS_Edge nEdge2 = TopoDS::Edge(EdgeEx.Current());
422                       if( nEdge1.IsSame(nEdge2) )
423                         return;
424                     }
425                   for(EdgeEx.Init(CmpOfEdges,TopAbs_EDGE); EdgeEx.More(); EdgeEx.Next())
426                     {
427                       TopoDS_Edge newEdge = TopoDS::Edge(EdgeEx.Current());
428                       FABU.AddEdgeWire(newEdge,newWire);
429                     }
430                 }
431               else
432                 {
433                   //TopTools_IndexedDataMapOfShapeListOfShape mapVOE;
434                   mapVOE.Clear();
435                   TopExp::MapShapesAndAncestors(CmpOfEdges,TopAbs_VERTEX,TopAbs_EDGE,mapVOE);
436                   // checking: wire is closed and regular. If wire is not close or not regular: vertex has only the one edge
437                   // or vetrex has more then two shared edges, we don't modify it. 
438                   Standard_Boolean WisClsd = Standard_True;
439                   for(Standard_Integer MapStep = 1; MapStep <= mapVOE.Extent(); MapStep++)
440                     {
441                       const TopTools_ListOfShape& LofE = mapVOE.FindFromIndex(MapStep);
442                       if(LofE.Extent() != 2) { WisClsd = Standard_False; break; }
443                     }
444                   if(!WisClsd)
445                     {
446                       //wire is not regular:
447                       TopExp_Explorer EdgeEx;
448                       for(EdgeEx.Init(CmpOfEdges,TopAbs_EDGE); EdgeEx.More(); EdgeEx.Next())
449                         {
450                           TopoDS_Edge newEdge = TopoDS::Edge(EdgeEx.Current());
451                           FABU.AddEdgeWire(newEdge,newWire);
452                         }
453                     }
454                   else
455                     {
456                       //wire seems to be regular:
457                       TopTools_ListOfShape LofAddE;  // list of edges has already been added in wire
458                       Standard_Integer naddsame = 0; 
459                       while( ne > (LofAddE.Extent() + naddsame) )
460                         {
461                           for(Standard_Integer StepMap = 1; StepMap <= mapVOE.Extent(); StepMap++)
462                             {
463                               const TopTools_ListOfShape& LofE = mapVOE.FindFromIndex(StepMap);
464                               TopTools_ListIteratorOfListOfShape itLofE(LofE);
465                               TopoDS_Edge E1 = TopoDS::Edge(itLofE.Value());
466                               itLofE.Next();
467                               TopoDS_Edge E2 = TopoDS::Edge(itLofE.Value());
468                               TopAbs_Orientation O1 = E1.Orientation();
469                               TopAbs_Orientation O2 = E2.Orientation();
470                               Standard_Boolean IsSameE1 = BRep_Tool::IsClosed(E1,tdF);
471                               Standard_Boolean IsSameE2 = BRep_Tool::IsClosed(E2,tdF);
472                               Standard_Boolean AddE1 = Standard_True;
473                               Standard_Boolean AddE2 = Standard_True;
474
475                               //checking current edges in the list of added edges
476                               TopTools_ListIteratorOfListOfShape itLofAddE(LofAddE);
477                               for(; itLofAddE.More(); itLofAddE.Next() )
478                                 {
479                                   const TopoDS_Shape& LE = itLofAddE.Value();
480                                   TopAbs_Orientation OLE = LE.Orientation();
481                                   if(E1.IsSame(LE) && !IsSameE1) { AddE1 = Standard_False; E1.Orientation(OLE); O1 = OLE; }
482                                   if(E2.IsSame(LE) && !IsSameE2) { AddE2 = Standard_False; E2.Orientation(OLE); O2 = OLE; }
483                                 }
484                               Standard_Integer chkORI = FUN_CheckORI(O1,O2);
485                               if(chkORI == 0){ AddE1 = Standard_False; AddE2 = Standard_False; }
486                               if(chkORI == 1)
487                                 {
488                                   TopAbs_Orientation ori = FUN_ReOrientIntExtEdge(E2,O2,E1);
489                                   if(ori == TopAbs_FORWARD) { E1.Orientation(TopAbs_FORWARD); neFORWARD++; }
490                                   if(ori == TopAbs_REVERSED){ E1.Orientation(TopAbs_REVERSED); neREVERSED++; }
491                                   if(ori == TopAbs_REVERSED || ori == TopAbs_FORWARD)
492                                     {
493                                       if(O1 == TopAbs_INTERNAL) neINTERNAL--;
494                                       else neEXTERNAL--;
495                                     }
496                                 }
497                               if(chkORI == 2)
498                                 {
499                                   TopAbs_Orientation ori = FUN_ReOrientIntExtEdge(E1,O1,E2);
500                                   if(ori == TopAbs_FORWARD) { E2.Orientation(TopAbs_FORWARD); neFORWARD++; }
501                                   if(ori == TopAbs_REVERSED){ E2.Orientation(TopAbs_REVERSED); neREVERSED++; }
502                                   if(ori == TopAbs_REVERSED || ori == TopAbs_FORWARD)
503                                     {
504                                       if(O2 == TopAbs_INTERNAL) neINTERNAL--;
505                                       else neEXTERNAL--;
506                                     }
507                                 }
508
509
510
511                               if(AddE1)
512                                 {
513                                   FABU.AddEdgeWire(E1,newWire);
514                                   if(!IsSameE1) LofAddE.Append(E1);
515                                   else naddsame++;
516                                 }
517                               if(AddE2)
518                                 {
519                                   FABU.AddEdgeWire(E2,newWire);
520                                   if(!IsSameE2) LofAddE.Append(E2);
521                                   else naddsame++;
522                                 }
523                             }//for StepMap
524                         } // while ne >
525                     } // not regular
526                 } // neINTERNAL(neEXTERNAL) != 0
527             } // !isold
528           //--ofv.
529
530 #ifdef DEB
531       if ( tSPS ) cout<<"#--- GFABUMakeFaces "<<iF<<" : "<<ne<<" edges"<<endl; 
532 #endif    
533
534       // xpu : 13-11-97
535       if (ne != 0) {
536         Standard_Integer iow = isold? 1: 0;
537         MWisOld.Bind(newWire,iow);
538       }
539       
540       // <newWire> is empty :
541       if ( !isold ) {
542         if (ne == 0) continue;
543         else if (nbw == 1 && (ne == neINTERNAL+neEXTERNAL)) continue;
544         else nbnewWwithe++;
545       }
546
547       // caractere Closed() du nouveau wire newWire
548       if ( !isold ) {
549         Standard_Boolean closed = FUN_tool_ClosedW(newWire);
550         myBuildTool.Closed(newWire,closed); 
551       } // !isold
552       
553       myBuildTool.AddFaceWire(newFace,newWire);
554       
555     } // FABU.MoreWire()
556     
557     if ( nbnewWwithe == 0 && nboldW == 0 ) {
558       continue;
559     }
560
561     Standard_Boolean topurge = FUN_purgeFon1nonoriE(newFace);
562     if (topurge) {
563 #ifdef DEB      
564       if (strange) cout<<"Builder::GFABUMakeFaces -> purgeFon1nonoriE\n";
565 #endif
566       continue;
567     }
568     
569 // Le changement de surface de trim a basis causait la perte des regularites de l'edge
570 // j'ai change par un recadrage du trim en attendant mieux. DPF le 29/07/1998.
571 // Le danger est de modifier une donnee d'entree.
572     Handle(Standard_Type) T = Surf->DynamicType();
573     Standard_Boolean istrim = ( T == STANDARD_TYPE(Geom_RectangularTrimmedSurface) );
574     if (istrim) {
575       Handle(Geom_RectangularTrimmedSurface) 
576         hrts=*((Handle(Geom_RectangularTrimmedSurface)*)&Surf);
577       Standard_Real oumin,oumax,ovmin,ovmax;
578       hrts->Bounds(oumin,oumax,ovmin,ovmax);
579       Standard_Real umin,umax,vmin,vmax;
580       BRepTools::UVBounds(newFace, umin, umax, vmin, vmax);
581       if (umin < oumin) oumin=umin;
582       if (umax > oumax) oumax=umax;
583       if (vmin < ovmin) ovmin=vmin;
584       if (vmax > ovmax) ovmax=vmax;
585       hrts->SetTrim(oumin, oumax, ovmin, ovmax, Standard_True, Standard_True);
586     }
587     lnewFace.Append(newFace);
588
589   } // FABU.MoreFace()
590
591 #ifdef DEB
592   if(tSPS) {
593     cout<<endl;GdumpSHA(FF, (char *) "#--- GFABUMakeFaces avant regularize");cout<<endl;
594     GdumpFABU(FABU);debgfabu(iF);
595   }
596 #endif
597
598   // xpu281098 : regularisation after purge processings (cto009L2,f4ou)
599 //  RegularizeFaces(FF,lnewFace,LOF);
600 //  Standard_Integer nLOF = LOF.Extent(); // DEB
601   LOF.Append(lnewFace);
602
603 } // GFABUMakeFaces