7883f673ac2cb4ecbfa3e68101b835a86067833c
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_GridFF.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 <TopOpeBRepDS.hxx>
20 #include <TopOpeBRepDS_InterferenceTool.hxx>
21 #include <TopOpeBRepTool_TOOL.hxx>
22 #include <TopOpeBRepTool_ShapeExplorer.hxx>
23 #include <TopOpeBRepTool_ShapeTool.hxx>
24 #include <TopoDS.hxx>
25 #include <BRep_Tool.hxx>
26 #include <TopExp.hxx>
27
28 #include <TopOpeBRepTool_2d.hxx>
29 #include <TopOpeBRepTool_EXPORT.hxx>
30 #include <TopOpeBRepDS_EXPORT.hxx>
31 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
32 #include <TopOpeBRepBuild_define.hxx>
33
34 #ifdef DRAW
35 #include <TopOpeBRepDS_DSX.hxx>
36 Standard_IMPORT void FUN_draw(const TopoDS_Shape& s);
37 Standard_IMPORT void FUN_draw2de (const TopoDS_Shape& ed,const TopoDS_Shape& fa);
38 #endif
39
40 #ifdef DEB
41 extern void* GFABUMAKEFACEPWES_DEB;
42 #define DEBSHASET(sarg,meth,shaset,str) TCollection_AsciiString sarg((meth));(sarg)=(sarg)+(shaset).DEBNumber()+(str);
43 Standard_Integer GLOBAL_iexE = 0;
44 Standard_EXPORT void debfillw(const Standard_Integer /*i*/) {}
45 Standard_EXPORT void debfille(const Standard_Integer /*i*/) {}
46 Standard_EXPORT void debffwesON(const Standard_Integer i) {cout<<"++ debffwesON "<<i<<endl;}
47 Standard_EXPORT void debffwesmf(const Standard_Integer i) {cout<<"++ debffwesmf "<<i<<endl;}
48 Standard_EXPORT void debfillf(const Standard_Integer i) {cout<<"++ debfillf "<<i<<endl;}
49 Standard_EXPORT void debsplite(const Standard_Integer i) {cout<<"++ debsplite "<<i<<endl;}
50 Standard_EXPORT void debmergef(const Standard_Integer i) {cout<<"++ debmergef "<<i<<endl;}
51 Standard_IMPORT void debfctwesmess(const Standard_Integer i,
52                                    const TCollection_AsciiString& s = "");
53 extern void debaddpwes(const Standard_Integer iFOR, const TopAbs_State TB1, const Standard_Integer iEG,
54                        const TopAbs_Orientation neworiE, const TopOpeBRepBuild_PBuilder& PB,
55                        const TopOpeBRepBuild_PWireEdgeSet& PWES, const TCollection_AsciiString& str1, 
56                        const TCollection_AsciiString& str2);
57 #endif
58
59 Standard_Boolean GLOBAL_faces2d = Standard_False;
60 Standard_EXPORT Standard_Boolean GLOBAL_classifysplitedge = Standard_False;  
61
62 #define M_IN(st )      (st == TopAbs_IN)
63 #define M_OUT(st)      (st == TopAbs_OUT)
64 #define M_FORWARD(st ) (st == TopAbs_FORWARD)
65 #define M_REVERSED(st) (st == TopAbs_REVERSED)
66 #define M_INTERNAL(st) (st == TopAbs_INTERNAL)
67 #define M_EXTERNAL(st) (st == TopAbs_EXTERNAL)
68
69 Standard_IMPORT Standard_Boolean FUN_HDS_FACESINTERFER(const TopoDS_Shape& F1, 
70                                                        const TopoDS_Shape& F2,
71                                                        const Handle(TopOpeBRepDS_HDataStructure)& HDS);
72
73 static 
74   TopAbs_State ClassifyEdgeToSolidByOnePoint(const TopoDS_Edge& E,
75                                              const TopoDS_Shape& Ref);
76 static
77   Standard_Boolean FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder& BU, 
78                                          const TopoDS_Face& F, 
79                                          const TopoDS_Edge& E, 
80                                          TopOpeBRepDS_PDataStructure& pDS2d);
81 static 
82   Standard_Boolean FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder& BU, 
83                                          const TopoDS_Face& F, 
84                                          TopOpeBRepDS_PDataStructure& pDS2d);
85
86 //-------------------------------------------------------------
87 // Unused :
88 /*#ifdef DEB
89 //=======================================================================
90 //function :FUN_BUI_FACESINTERFER
91 //purpose  : 
92 //=======================================================================
93 static Standard_Boolean FUN_BUI_FACESINTERFER(const TopoDS_Shape& F1,
94                                               const TopoDS_Shape& F2,
95                                               const TopOpeBRepBuild_Builder& B)
96 {
97   Standard_Boolean yainterf = Standard_False;
98   Handle(TopOpeBRepDS_HDataStructure) HDS = B.DataStructure();
99   
100
101
102   Standard_Boolean ya1 = FUN_HDS_FACESINTERFER(F1,F2,HDS);
103   Standard_Boolean ya2 = FUN_HDS_FACESINTERFER(F2,F1,HDS);
104   yainterf = (ya1 && ya2);
105   return yainterf;
106 }
107 #endif*/
108
109 //=======================================================================
110 //function :TopOpeBRepBuild_FUN_aresamegeom
111 //purpose  : 
112 //=======================================================================
113 Standard_Boolean TopOpeBRepBuild_FUN_aresamegeom (const TopoDS_Shape& S1,
114                                                   const TopoDS_Shape& S2)
115 {
116   TopoDS_Shape SF1 = S1; 
117   SF1.Orientation(TopAbs_FORWARD);
118   TopoDS_Shape SF2 = S2; 
119   SF2.Orientation(TopAbs_FORWARD);
120   Standard_Boolean same = TopOpeBRepTool_ShapeTool::ShapesSameOriented(SF1,SF2);
121   return same;
122 }
123
124 //=======================================================================
125 //function :FUN_computeLIFfaces2d
126 //purpose  : 
127 //=======================================================================
128 Standard_Boolean FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder& BU, 
129                                        const TopoDS_Face& F, 
130                                        const TopoDS_Edge& E, 
131                                        TopOpeBRepDS_PDataStructure& pDS2d)
132 // purpose : compute new face/face interferences F FTRA,
133 //  {I = (T(F),ES,FTRA)} / Fsdm F and ES interfers with E which has splits ON
134 //  E is edge of F
135
136 #ifdef DEB
137   Standard_Integer iF;Standard_Boolean tF=BU.GtraceSPS(F,iF);
138 #endif
139   
140   const TopOpeBRepDS_DataStructure& BDS = BU.DataStructure()->DS(); 
141   const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(E);
142   Standard_Integer IE = BDS.Shape(E);
143   Standard_Integer IF = BDS.Shape(F);
144   Standard_Integer rkF = BDS.AncestorRank(F);
145   Standard_Boolean hasspE = BU.IsSplit(E,TopAbs_ON);
146   if (hasspE) hasspE = (BU.Splits(E,TopAbs_ON).Extent() > 0);
147   TopTools_MapOfShape Ffound;
148   
149   TopTools_ListOfShape Fsdm; TopTools_ListIteratorOfListOfShape itf(BDS.ShapeSameDomain(F));
150   for (; itf.More(); itf.Next()){
151     const TopoDS_Shape& f = itf.Value();
152     Standard_Integer rkf = BDS.AncestorRank(f);
153     if (rkf == rkF) continue;
154     Fsdm.Append(f);
155   }
156
157   for (TopOpeBRepDS_ListIteratorOfListOfInterference itI(LI); itI.More(); itI.Next()){
158     const Handle(TopOpeBRepDS_Interference)& I = itI.Value();
159 //    const TopOpeBRepDS_Transition& T = I->Transition();
160     TopAbs_ShapeEnum SB,SA;Standard_Integer IB,IA;TopOpeBRepDS_Kind GT,ST;Standard_Integer G,S;
161     FDS_Idata(I,SB,IB,SA,IA,GT,G,ST,S);
162     if (ST != TopOpeBRepDS_EDGE) return Standard_False;
163
164     TopoDS_Face FTRA; Standard_Integer ITRA = IB;
165     if      (SB == TopAbs_FACE) FTRA = TopoDS::Face(BDS.Shape(IB));
166     else if (SB == TopAbs_EDGE) {
167       Standard_Boolean ok = FUN_tool_findAncestor(Fsdm,TopoDS::Edge(BDS.Shape(S)),FTRA);
168       ITRA = BDS.Shape(FTRA);
169       if (!ok) return Standard_False;      
170     }
171     Standard_Boolean found = Ffound.Contains(FTRA);
172
173     // prequesitory : F and FTRA are SDSO
174     // -------------
175
176     // attached to E : I = (T(FTRA),G,ES),
177     // ES : support edge
178     // GP : geometric point  
179     // recall : rankE  = rankF
180     //          rankTRA = rankS != rankE
181     Standard_Real parE = FDS_Parameter(I);
182     const TopoDS_Edge& ES = TopoDS::Edge(BDS.Shape(S));
183     Standard_Boolean hasspES = BU.IsSplit(ES,TopAbs_ON);
184     if (hasspES) hasspE = (BU.Splits(ES,TopAbs_ON).Extent() > 0); 
185
186     Standard_Boolean sdm = FUN_ds_sdm(BDS,E,ES);
187     Standard_Boolean mkTonEsdm = sdm && hasspE && !found;
188     Standard_Boolean hasfeiF_E_FTRA = FUN_ds_hasFEI(pDS2d,F,IE,ITRA);  //xpu120698
189     mkTonEsdm = mkTonEsdm && !hasfeiF_E_FTRA; //xpu120698
190     if (mkTonEsdm) {
191       Ffound.Add(FTRA);
192       TopoDS_Edge dummy; TopOpeBRepDS_Transition newT;  
193       Standard_Boolean ok = FUN_ds_mkTonFsdm(BU.DataStructure(),IF,ITRA,S,IE,parE,dummy,Standard_True,newT);
194
195       if (ok) {
196         newT.Index(ITRA); TopOpeBRepDS_Config C = TopOpeBRepDS_SAMEORIENTED;
197         Handle(TopOpeBRepDS_Interference) newI = TopOpeBRepDS_InterferenceTool::MakeFaceEdgeInterference(newT,ITRA,IE,Standard_True,C);
198 #ifdef DEB
199         if (tF) {cout<<"f"<<IF<<" + ";newI->Dump(cout);cout<<endl;}
200 #endif
201         pDS2d->AddShapeInterference(F,newI);
202       }
203     }
204     Standard_Boolean mkTonESsdm = sdm && hasspES;
205     Standard_Boolean hasfeiFRA_E_F = FUN_ds_hasFEI(pDS2d,FTRA,IE,IF);  //xpu120698
206     mkTonESsdm = mkTonESsdm && !hasfeiFRA_E_F;  //xpu120698
207     if (mkTonESsdm) { // ff1, IE=3 has interferences, S=8 has none
208       TopoDS_Edge dummy; TopOpeBRepDS_Transition newT; 
209
210       Standard_Real parES; Standard_Boolean ok = FUN_tool_parE(E,parE,ES,parES);
211       if (!ok) continue; 
212       ok = FUN_ds_mkTonFsdm(BU.DataStructure(),ITRA,IF,IE,S,parES,dummy,Standard_True,newT);
213       if (ok) {
214         newT.Index(IF); TopOpeBRepDS_Config C = TopOpeBRepDS_SAMEORIENTED;
215         Handle(TopOpeBRepDS_Interference) newI = TopOpeBRepDS_InterferenceTool::MakeFaceEdgeInterference(newT,IF,IE,Standard_False,C);
216 #ifdef DEB
217         if (tF) {cout<<"f"<<ITRA<<" + ";newI->Dump(cout);cout<<endl;}
218 #endif
219         pDS2d->AddShapeInterference(FTRA,newI);
220       }
221
222       ok = FUN_ds_mkTonFsdm(BU.DataStructure(),ITRA,IF,IE,IE,parE,dummy,Standard_True,newT);      
223       if (ok) {
224         newT.Index(IF); TopOpeBRepDS_Config C = TopOpeBRepDS_SAMEORIENTED;
225         Handle(TopOpeBRepDS_Interference) newI = TopOpeBRepDS_InterferenceTool::MakeFaceEdgeInterference(newT,IF,S,Standard_True,C);
226 #ifdef DEB
227         if (tF) {cout<<endl<<"f"<<ITRA<<" + ";newI->Dump(cout);cout<<endl;}
228 #endif
229         pDS2d->AddShapeInterference(FTRA,newI);
230       }
231       
232     }
233
234     Standard_Boolean mkTonES = hasspES;
235     Standard_Boolean hasfeiF_S_FTRA = FUN_ds_hasFEI(pDS2d,F,S,ITRA);  //xpu120698
236     mkTonES = mkTonES && !hasfeiF_S_FTRA;
237     if (mkTonES) {
238       Standard_Real parES; Standard_Boolean ok = FUN_tool_parE(E,parE,ES,parES);
239       if (!ok) continue;
240       
241       TopoDS_Edge dummy; TopOpeBRepDS_Transition newT; 
242       ok = FUN_ds_mkTonFsdm(BU.DataStructure(),IF,ITRA,S,S,parES,dummy,Standard_True,newT);
243
244       if (ok) {
245         newT.Index(ITRA); TopOpeBRepDS_Config C = TopOpeBRepDS_SAMEORIENTED;
246         Handle(TopOpeBRepDS_Interference) newI = TopOpeBRepDS_InterferenceTool::MakeFaceEdgeInterference(newT,ITRA,S,Standard_False,C);
247 #ifdef DEB
248         if (tF) {cout<<"f"<<iF<<" + ";newI->Dump(cout);cout<<endl;}
249 #endif
250         pDS2d->AddShapeInterference(F,newI);
251       }
252     }
253   } // itI(LI)
254
255   return Standard_True;
256 }
257 //=======================================================================
258 //function :FUN_computeLIFfaces2d
259 //purpose  : 
260 //=======================================================================
261 Standard_Boolean FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder& BU, 
262                                        const TopoDS_Face& F,
263                                        TopOpeBRepDS_PDataStructure& pDS2d)
264 {
265   TopExp_Explorer ex(F, TopAbs_EDGE);   
266   for (; ex.More(); ex.Next()){
267     const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
268     Standard_Boolean ok = FUN_computeLIFfaces2d(BU,F,E,pDS2d);
269     if (!ok) return Standard_False;
270   }
271   return Standard_True;
272 }
273 //=======================================================================
274 //variable : Standard_EXPORT TopOpeBRepDS_PDataStructure GLOBAL_DS2d
275 //purpose  : 
276 //=======================================================================
277 Standard_EXPORT TopOpeBRepDS_PDataStructure GLOBAL_DS2d = NULL;
278
279 //=======================================================================
280 //function : GMergeFaces
281 //purpose  : 
282 //=======================================================================
283   void TopOpeBRepBuild_Builder::GMergeFaces(const TopTools_ListOfShape& LF1,
284                                             const TopTools_ListOfShape& LF2,
285                                             const TopOpeBRepBuild_GTopo& G1)
286 {
287   if ( LF1.IsEmpty() ) return;
288   if (GLOBAL_DS2d == NULL) GLOBAL_DS2d = (TopOpeBRepDS_PDataStructure)new TopOpeBRepDS_DataStructure();
289   GLOBAL_DS2d->Init();
290
291   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
292
293   const TopoDS_Shape& F1 = LF1.First();
294 #ifdef DEB
295   Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(F1,iF);
296   if(tSPS){
297     cout<<endl<<"--- GMergeFaces "<<endl;
298     GdumpSAMDOM(LF1, (char *) "1 : ");
299     GdumpSAMDOM(LF2, (char *) "2 : ");
300     debmergef(iF);
301   }
302 #endif
303
304   // xpu070598 : filling up DS2
305 //  for (TopTools_ListIteratorOfListOfShape itF1(LF1); itF1.More(); itF1.Next()) GLOBAL_DS2d->AddShape(itF1.Value(),1); 
306    TopTools_ListIteratorOfListOfShape itF1(LF1) ;
307   for ( ; itF1.More(); itF1.Next()) GLOBAL_DS2d->AddShape(itF1.Value(),1);  
308 //  for (TopTools_ListIteratorOfListOfShape itF2(LF2); itF2.More(); itF2.Next()) GLOBAL_DS2d->AddShape(itF2.Value(),2);
309   TopTools_ListIteratorOfListOfShape itF2(LF2) ;
310   for ( ; itF2.More(); itF2.Next()) GLOBAL_DS2d->AddShape(itF2.Value(),2);
311
312 //  for (itF1.Initialize(LF1); itF1.More(); itF1.Next()){
313   itF1.Initialize(LF1) ;
314   for ( ; itF1.More(); itF1.Next()){
315     const TopoDS_Face& FF1 = TopoDS::Face(itF1.Value());
316     FUN_computeLIFfaces2d((*this),TopoDS::Face(FF1),GLOBAL_DS2d);
317   }
318 //  for (itF2.Initialize(LF2); itF2.More(); itF2.Next()){
319   itF2.Initialize(LF2) ;
320   for ( ; itF2.More(); itF2.Next()){
321     const TopoDS_Face& FF2 = TopoDS::Face(itF2.Value());
322     FUN_computeLIFfaces2d((*this),TopoDS::Face(FF2),GLOBAL_DS2d);
323   }
324   // xpu070598
325
326   {
327     for (Standard_Integer ii=1; ii<=GLOBAL_DS2d->NbShapes(); ii++) {
328       TopOpeBRepDS_ListOfInterference& LI = GLOBAL_DS2d->ChangeShapeInterferences(ii);
329       FUN_reducedoublons(LI,(*GLOBAL_DS2d),ii);
330     }
331   }
332
333   myFaceReference = TopoDS::Face(F1);
334   TopOpeBRepBuild_WireEdgeSet WES(F1,this);
335
336   GLOBAL_faces2d = Standard_True;
337   Standard_Integer K1=1; GFillFacesWESK(LF1,LF2,G1,WES,K1);
338   Standard_Integer K3=3; GFillFacesWESK(LF1,LF2,G1,WES,K3); // xpu060598
339   GLOBAL_faces2d = Standard_False;
340
341   // Create a face builder FABU
342   TopoDS_Shape F1F = LF1.First(); F1F.Orientation(TopAbs_FORWARD);
343   Standard_Boolean ForceClass = Standard_True;
344   TopOpeBRepBuild_FaceBuilder FABU;
345   FABU.InitFaceBuilder(WES,F1F,ForceClass);
346   
347   // Build new faces LFM
348   TopTools_ListOfShape LFM;
349
350 #ifdef DEB
351   GFABUMAKEFACEPWES_DEB = (void*)&WES;
352 #endif
353
354   TopTools_DataMapOfShapeInteger MWisOld;
355   GFABUMakeFaces(F1F,FABU,LFM,MWisOld);
356   
357   // xpu281098 : regularisation after GFABUMakeFaces
358   TopTools_ListOfShape newLFM; RegularizeFaces(F1F,LFM,newLFM);
359   LFM.Clear(); LFM.Assign(newLFM);
360
361   // connect new faces as faces built TB1 on LF1 faces
362   TopTools_ListIteratorOfListOfShape it1;
363   for (it1.Initialize(LF1); it1.More(); it1.Next()) {
364     const TopoDS_Shape& F1x = it1.Value();
365     Standard_Boolean tomerge = !IsMerged(F1x,TB1);
366     if (tomerge) {
367       ChangeMerged(F1x, TB1) = LFM;
368     }
369   }
370   
371   // connect new faces as faces built TB2 on LF2 faces
372   TopTools_ListIteratorOfListOfShape it2;
373   for (it2.Initialize(LF2); it2.More(); it2.Next()) {
374     const TopoDS_Shape& F2 = it2.Value();
375     Standard_Boolean tomerge = !IsMerged(F2,TB2);
376     if (tomerge) ChangeMerged(F2,TB2) = LFM;
377   }
378   
379 } // GMergeFaces
380
381 //=======================================================================
382 //function : GFillFacesWES
383 //purpose  : 
384 //=======================================================================
385   void TopOpeBRepBuild_Builder::GFillFacesWES(const TopTools_ListOfShape& ,
386                                               const TopTools_ListOfShape& ,
387                                               const TopOpeBRepBuild_GTopo& ,
388                                               TopOpeBRepBuild_WireEdgeSet& )
389 {
390 } // GFillFacesWES
391
392 static Standard_Boolean FUN_validF1edge(const TopoDS_Shape& F)
393 {
394   Standard_Integer nE = 0; 
395   TopTools_IndexedMapOfShape mEt;
396   TopExp_Explorer exE(F, TopAbs_EDGE);
397 //  for ( exE ; exE.More(); exE.Next()) {
398   for (  ; exE.More(); exE.Next()) {
399     const TopoDS_Shape& e = exE.Current();
400     if (mEt.Contains(e)) continue;
401     mEt.Add(e);
402     nE++; 
403     if (nE > 2) break;
404   }
405   if (nE > 1) return Standard_True;
406   if (nE == 1) {
407     exE.Init(F, TopAbs_EDGE);
408     const TopoDS_Edge& e = TopoDS::Edge(exE.Current());
409     TopoDS_Vertex dummy; Standard_Boolean closed = TopOpeBRepTool_TOOL::ClosedE(e,dummy);
410     return closed;
411   }
412   return Standard_False;
413 }
414
415 //=======================================================================
416 //function : GFillFacesWESMakeFaces
417 //purpose  : 
418 //=======================================================================
419   void TopOpeBRepBuild_Builder::GFillFacesWESMakeFaces(const TopTools_ListOfShape& LLF1,
420                                                        const TopTools_ListOfShape& LF2,
421                                                        const TopTools_ListOfShape& ,//LSO,
422                                                        const TopOpeBRepBuild_GTopo& GM)
423 {
424   TopAbs_State TB1,TB2; GM.StatesON(TB1,TB2);
425   if (LLF1.IsEmpty()) return;
426   
427   // xpu270898 : cto905E2 split(fref6,f33,f16) must be built on fref6
428   TopTools_ListOfShape LF1;
429   TopTools_ListIteratorOfListOfShape itf(LLF1);
430   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
431   Standard_Integer iref = 0; 
432   for (; itf.More(); itf.Next()){
433     const TopoDS_Shape& fcur = itf.Value();
434     Standard_Integer icur = BDS.Shape(fcur);
435     iref = BDS.SameDomainRef(fcur);
436     if (icur == iref) LF1.Prepend(fcur);
437     else              LF1.Append(fcur);
438   }
439   // xpu270898 : cto905I1 split(f6,f30,fref14) must be built on fref6, f6 is in LFDO1
440 //  Standard_Boolean FFinDO1 = (iFF == iref);
441 //  const TopoDS_Shape& FF = BDS.Shape(iref);
442   const TopoDS_Shape& FF = LF1.First().Oriented(TopAbs_FORWARD);
443   Standard_Integer iFF = BDS.Shape(FF);
444
445   TopOpeBRepBuild_WireEdgeSet WES(FF,this);
446
447 #ifdef DEB
448   Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(FF,iF);
449   if(tSPS) GdumpSHASTA(iF,TB1,WES,"\n--- GFillFacesWESMakeFaces");
450   if(tSPS) debfillf(iF);
451   if(tSPS) debffwesmf(iF);
452 #endif
453
454   Standard_Integer n1 = 0;
455   GLOBAL_faces2d = Standard_True;
456   Standard_Integer K1=1; GFillFacesWESK(LF1,LF2,GM,WES,K1);
457   GLOBAL_faces2d = Standard_False;
458   n1 = WES.StartElements().Extent();
459   
460   Standard_Integer K2=2; GFillFacesWESK(LF1,LF2,GM,WES,K2);
461   n1 = WES.StartElements().Extent();
462   
463   Standard_Integer K3=3; GFillFacesWESK(LF1,LF2,GM,WES,K3);
464   n1 = WES.StartElements().Extent();
465
466   Standard_Integer n2 = WES.StartElements().Extent();
467   myEdgeAvoid.Clear(); // Start edges dues a GFillCurveTopologyWES
468   GCopyList(WES.StartElements(),(n1+1),n2,myEdgeAvoid);
469   TopTools_ListOfShape LOF; // LOF : toutes les faces construites sur WES
470   GWESMakeFaces(FF,WES,LOF);
471
472   // xpu290498
473   //cto 001 F2 : spIN(f18)
474   TopTools_ListIteratorOfListOfShape itF(LOF);
475   while (itF.More()){
476     const TopoDS_Shape& F = itF.Value();
477     Standard_Boolean valid = ::FUN_validF1edge(F);
478     if (!valid) LOF.Remove(itF);
479     else itF.Next();
480   }
481   // xpu290498
482
483   TopTools_ListOfShape LOFS; // LOFS : LOF faces situees TB1/LSO2
484   GKeepShapes(FF,myEmptyShapeList,TB1,LOF,LOFS);
485
486   // les faces construites (LOFS) prennent l'orientation originale de FF  
487   TopAbs_Orientation odsFF = myDataStructure->Shape(iFF).Orientation();
488   for(TopTools_ListIteratorOfListOfShape itt(LOFS);itt.More();itt.Next()) itt.Value().Orientation(odsFF);
489
490   TopTools_ListIteratorOfListOfShape it1;
491   for (it1.Initialize(LF1); it1.More(); it1.Next()) {
492     const TopoDS_Shape& S = it1.Value(); 
493 #ifdef DEB
494     Standard_Integer iS; GtraceSPS(S,iS);
495 #endif
496     MarkSplit(S,TB1);
497     TopTools_ListOfShape& LS1 = ChangeSplit(S,TB1);
498     GCopyList(LOFS,LS1);
499   }
500
501   TopTools_ListIteratorOfListOfShape it2;
502   for (it2.Initialize(LF2); it2.More(); it2.Next()) {
503     const TopoDS_Shape& S = it2.Value(); 
504 #ifdef DEB
505     Standard_Integer iS; GtraceSPS(S,iS);
506 #endif
507     MarkSplit(S,TB2);
508     TopTools_ListOfShape& LS2 = ChangeSplit(S,TB2);
509     GCopyList(LOFS,LS2);
510   }
511 } // GFillFacesWESMakeFaces
512
513 //=======================================================================
514 //function : GFillFaceWES
515 //purpose  : 
516 //=======================================================================
517   void TopOpeBRepBuild_Builder::GFillFaceWES(const TopoDS_Shape& FOR1,
518                                              const TopTools_ListOfShape& LFclass,
519                                              const TopOpeBRepBuild_GTopo& G1,
520                                              TopOpeBRepBuild_WireEdgeSet& WES)
521 {
522   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
523   Standard_Boolean RevOri1 = G1.IsToReverse1();
524   
525 #ifdef DEB
526   Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(FOR1,iF);
527   if(tSPS) GdumpSHASTA(iF,TB1,WES,"--- GFillFaceWES","START");
528   if(tSPS) debfillf(iF);
529 #endif
530   
531   // xpu200598 bcl1;bcl2; tsp(f9)
532   Standard_Boolean opeCut = Opec12() || Opec21(); //xpu200598
533   Standard_Boolean ComOfCut = opeCut && (TB1 == TB2) && (TB1 == TopAbs_IN); //xpu200598
534   Standard_Boolean hsdm = myDataStructure->HasSameDomain(FOR1);//xpu200598
535   if (hsdm && ComOfCut) return; //xpu200598
536   
537   // work on a FORWARD face FF
538   TopoDS_Shape FF = FOR1; FF.Orientation(TopAbs_FORWARD);
539   myFaceToFill = TopoDS::Face(FF);
540   
541   TopOpeBRepTool_ShapeExplorer exWire(FF,TopAbs_WIRE);
542   for (; exWire.More(); exWire.Next()) {
543     TopoDS_Shape W = exWire.Current();
544     Standard_Boolean hasshape = myDataStructure->HasShape(W);
545     
546     if ( ! hasshape ) {
547       // wire W is not in DS : classify it with LFclass faces
548       TopAbs_State pos;
549       Standard_Boolean keep = GKeepShape1(W,LFclass,TB1,pos);
550       if (keep) {
551         TopAbs_Orientation oriW = W.Orientation();
552         TopAbs_Orientation neworiW = Orient(oriW,RevOri1);
553         W.Orientation(neworiW);
554         WES.AddShape(W);
555       }
556       else if (myProcessON && pos == TopAbs_ON)
557         myONElemMap.Add(W);
558     }
559     else { // wire W has edges(s) with geometry : split W edges
560       GFillWireWES(W,LFclass,G1,WES);
561     }
562   }
563   
564 #ifdef DEB
565   if(tSPS) GdumpSHASTA(iF,TB1,WES,"--- GFillFaceWES","END");
566 #endif
567
568   return;
569 } // GFillFaceWES
570
571 //=======================================================================
572 //function : GFillWireWES
573 //purpose  : 
574 //=======================================================================
575   void TopOpeBRepBuild_Builder::GFillWireWES(const TopoDS_Shape& W,
576                                              const TopTools_ListOfShape& LSclass,
577                                              const TopOpeBRepBuild_GTopo& G1,
578                                              TopOpeBRepBuild_WireEdgeSet& WES)
579 {
580   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
581
582 #ifdef DEB
583   Standard_Integer iW; Standard_Boolean tSPS = GtraceSPS(W,iW);
584   if(tSPS){
585     cout<<endl;DEBSHASET(s,"--- GFillWireWES ",WES," ");
586     GdumpSHA(W,(Standard_Address)s.ToCString()); cout<<endl;
587     Standard_Integer nbe = 0;
588     TopOpeBRepTool_ShapeExplorer exE(W,TopAbs_EDGE);for (;exE.More(); exE.Next()) nbe++;
589     cout<<"--- GFillWireWES on W "<<iW<<" with "<<nbe<<" edges "<<endl;
590     debfillw(iW);
591   }
592   GLOBAL_iexE = 0;
593 #endif
594   
595   TopOpeBRepTool_ShapeExplorer exEdge(W,TopAbs_EDGE);
596   for (; exEdge.More(); exEdge.Next()) {
597     const TopoDS_Shape& EOR = exEdge.Current();
598     
599 #ifdef DEB
600     GLOBAL_iexE++;
601     if (tSPS) {
602 //      const TopoDS_Edge& ed = TopoDS::Edge(EOR);
603 //      Standard_Boolean isdegen = BRep_Tool::Degenerated(ed);
604 //      TopLoc_Location L;
605 //      Handle(Geom_Surface) S = BRep_Tool::Surface(myFaceToFill,L);
606 //      Standard_Boolean isclosed = BRep_Tool::IsClosed(ed,S,L);
607 //      TopAbs_Orientation oried = ed.Orientation();
608 //      Standard_Boolean trc = Standard_False;
609 #ifdef DRAW
610 //      if (trc) {FUN_draw(ed); FUN_draw2de(ed,myFaceReference);}
611 #endif
612     }
613 #endif
614     
615     GFillEdgeWES(EOR,LSclass,G1,WES);
616   }
617 } // GFillWireWES
618
619
620 //=======================================================================
621 //function : GFillEdgeWES
622 //purpose  : 
623 //=======================================================================
624   void TopOpeBRepBuild_Builder::GFillEdgeWES(const TopoDS_Shape& EOR,
625                                              const TopTools_ListOfShape& LSclass,
626                                              const TopOpeBRepBuild_GTopo& G1,
627                                              TopOpeBRepBuild_WireEdgeSet& WES)
628 {
629   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
630
631 #ifdef DEB
632   Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EOR,iE);
633   if(tSPS)cout<<endl;
634 #endif
635
636 #ifdef DEB
637   Standard_Boolean tosplit =
638 #endif
639                 GToSplit(EOR,TB1);
640 #ifdef DEB
641   Standard_Boolean tomerge =
642 #endif
643                 GToMerge(EOR);
644
645 #ifdef DEB
646   if(tSPS) GdumpSHASTA(iE,TB1,WES,"--- GFillEdgeWES ");
647   if(tSPS) cout<<" tosplit "<<tosplit<<" tomerge "<<tomerge<<endl;
648   if(tSPS) debfille(iE);
649 #endif
650   
651   TopOpeBRepBuild_GTopo GME = G1;
652   GMergeEdgeWES(EOR,GME,WES);
653   
654   TopOpeBRepBuild_GTopo GSE = G1;
655   GSE.ChangeConfig(TopOpeBRepDS_UNSHGEOMETRY,TopOpeBRepDS_UNSHGEOMETRY);
656   GSplitEdgeWES(EOR,LSclass,GSE,WES);
657
658 } // GFillEdgeWES
659
660 static void FUN_samgeomori(const TopOpeBRepDS_DataStructure& BDS, const Standard_Integer iref, const Standard_Integer ifil,
661                            Standard_Boolean& samgeomori)
662 {
663   TopOpeBRepDS_Config cfill = BDS.SameDomainOri(ifil);
664   TopAbs_Orientation oref=BDS.Shape(iref).Orientation(), ofil=BDS.Shape(ifil).Orientation();
665   samgeomori = (cfill == TopOpeBRepDS_SAMEORIENTED);
666   if (oref == TopAbs::Complement(ofil)) samgeomori = !samgeomori;
667 }
668
669 #define UNKNOWN   (0)
670 #define ONSAMESHA (1)
671 #define CLOSESAME (11)
672 #define ONOPPOSHA (2)
673 #define CLOSEOPPO (22)
674 #define FORREVOPPO (222)
675
676 //=======================================================================
677 //function : GSplitEdgeWES
678 //purpose  : 
679 //=======================================================================
680   void TopOpeBRepBuild_Builder::GSplitEdgeWES(const TopoDS_Shape& EOR,
681                                               const TopTools_ListOfShape& LSclass,
682                                               const TopOpeBRepBuild_GTopo& G1,
683                                               TopOpeBRepBuild_WireEdgeSet& WES)
684 {
685   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
686   Standard_Boolean RevOri1 = G1.IsToReverse1();
687   TopAbs_Orientation oriE = EOR.Orientation();
688   TopAbs_Orientation neworiE = Orient(oriE,RevOri1);
689   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
690   
691   TopAbs_Orientation oEinF; 
692   Standard_Integer Oinref = 0;
693   Standard_Boolean hsdm = myDataStructure->HasSameDomain(myFaceToFill);
694   Standard_Boolean hsdmE = myDataStructure->HasSameDomain(EOR);
695   Standard_Integer ifil = myDataStructure->Shape(myFaceToFill);
696   Standard_Integer iref = myDataStructure->Shape(myFaceReference);
697   if (hsdm) {
698     Oinref = FUN_ds_oriEinF(BDS,TopoDS::Edge(EOR),myFaceReference,oEinF); //xpu060598
699
700     // xpu150998 : cto900P6 : e35ou added to fref34,f53, oEinF=REVERSED, oEinfill=FORWARD
701     TopAbs_Orientation oEinfill; 
702     Standard_Integer Oinfill = FUN_ds_oriEinF(BDS,TopoDS::Edge(EOR),myFaceToFill,oEinfill);
703     if (Oinref == Oinfill) {
704
705       Standard_Boolean reverse = Standard_False; 
706       if (iref != ifil) {
707         // xpu230299 : FRA60275 (e6,fref4,ffill7) + PRO16297
708         TopAbs_Orientation oref = myFaceReference.Orientation();
709         Standard_Boolean samegeomori; FUN_samgeomori(BDS,iref,ifil,samegeomori);
710         reverse = (!samegeomori);
711         if (oref == TopAbs_REVERSED) reverse = !reverse;
712       }
713 //      TopAbs_Orientation oref=myFaceReference.Orientation(), ofill=myFaceToFill.Orientation();
714 //      Standard_Boolean reverse = (oref != ofill);
715
716       TopAbs_Orientation oEinfillTOref = reverse ? TopAbs::Complement(oEinfill) : oEinfill;
717       Standard_Boolean same = (oEinF == oEinfillTOref);
718       if (!same && (oEinF!=TopAbs_INTERNAL) && (oEinF!=TopAbs_EXTERNAL)) oEinF = oEinfillTOref;
719     }
720   }
721   else      Oinref = FUN_ds_oriEinF(BDS,TopoDS::Edge(EOR),myFaceToFill,oEinF); //xpu060598
722   Standard_Boolean newO = (Oinref == ONSAMESHA) || (Oinref == ONOPPOSHA); //xpu060598
723
724   Standard_Boolean isfafa = (myIsKPart == 3);
725   if (isfafa) newO = Standard_False;// xpu110598
726
727   // if (fus) : faces are SDSO : we keep original edge's orientation
728   // if (com) : faces are SDSO : we keep original edge's orientation
729   // if (cut && TBToFill==OUT)  : myFaceToFill is the reference face,
730   //                              we keep original edge's orientation
731
732 #ifdef DEB 
733   Standard_Integer iEOR; Standard_Boolean tSPS = GtraceSPS(EOR,iEOR);
734   Standard_Integer iWESF; /*Standard_Boolean tSPSW = */GtraceSPS(WES.Face(),iWESF);
735   if(tSPS) GdumpSHASTA(iEOR,TB1,WES,"\n--- GSplitEdgeWES","START");
736   if(tSPS) cout<<" RevOri1 : "<<RevOri1<<endl;
737   if(tSPS) debsplite(iEOR);
738 #endif  
739     
740   Standard_Boolean tosplit = GToSplit(EOR,TB1);
741   if (tosplit) {
742     GSplitEdge(EOR,G1,LSclass);
743     //modified by NIZNHY-PKV Mon Mar 19 16:53:40 2001 f
744     if (myIsKPart==4) {
745       // Only solids are available here
746       TopAbs_State aState;
747       Standard_Integer aRank1;
748       TopTools_ListOfShape anAuxList;
749
750       aRank1=ShapeRank(EOR);
751       const TopoDS_Shape& aSolid=(aRank1==1) ? myShape2 : myShape1;
752       
753       TopTools_ListOfShape& aSplitList = ChangeSplit (EOR, TB1);
754       TopTools_ListIteratorOfListOfShape anIt(aSplitList);
755       for (; anIt.More(); anIt.Next()) {
756         const TopoDS_Edge& aSplitEdge=TopoDS::Edge (anIt.Value());
757         aState=ClassifyEdgeToSolidByOnePoint (aSplitEdge, aSolid);
758         if (aState==TB1) {
759           anAuxList.Append (aSplitEdge);
760         }
761       }
762       
763       aSplitList.Clear();
764       
765       anIt.Initialize(anAuxList);
766       for (; anIt.More(); anIt.Next()) {
767         const TopoDS_Shape& aShape=anIt.Value();
768         aSplitList.Append(aShape);
769       }
770     }
771     //modified by NIZNHY-PKV Mon Mar 19 16:53:44 2001 t
772   }
773
774   //xpu200598 : never add spIN in fusion
775   Standard_Boolean opeFus = Opefus(); //xpu200598
776   if (opeFus) //xpu200598
777     if (TB1 == TopAbs_IN) return;  //xpu200598
778      
779   Standard_Boolean issplit = IsSplit(EOR,TB1);
780   if ( issplit ) {
781     const TopTools_ListOfShape& LSE = Splits(EOR,TB1);
782
783 #ifdef DEB
784     if(tSPS) {
785       GdumpSHASTA(iEOR,TB1,WES,"--- GSplitEdgeWES","WES+ Split");
786       cout<<" ";TopAbs::Print(TB1,cout)<<" : "<<LSE.Extent()<<" edge(s) ";
787       TopAbs::Print(neworiE,cout); cout<<endl;
788     }
789 #endif
790
791     for (TopTools_ListIteratorOfListOfShape it(LSE); 
792          it.More(); it.Next()) {
793       TopoDS_Edge newE = TopoDS::Edge(it.Value()); 
794       if (newO) {// xpu060598   
795         // PRO13075 tspIN(f18), tspIN(e17)
796         // we add sp(EOR) to myFaceToFill with its orientation
797         newE.Orientation(oEinF);
798         Standard_Boolean dgE = BRep_Tool::Degenerated(TopoDS::Edge(EOR)); 
799         if (!dgE && hsdmE) {
800           Standard_Real f,l; FUN_tool_bounds(newE,f,l); 
801           Standard_Real x = 0.45678; Standard_Real par = (1-x)*f + x*l; 
802           Standard_Boolean so = Standard_True;
803           Standard_Boolean ok = FUN_tool_curvesSO(newE,par,TopoDS::Edge(EOR),so);
804           if (!ok) {
805 #ifdef DEB
806             cout<<"GSplitEdgeWES: cannot orient SDM split of an edge"<<endl;
807 #endif
808             //return; // nyiFUNRAISE
809           }
810           if (!so) {
811             newE.Reverse();
812           }
813         } //!dgE && hsdmE
814       }// xpu060598     
815       else newE.Orientation(neworiE);
816       
817 #ifdef DEB
818       if (tSPS) debaddpwes(iWESF,TB1,iEOR,neworiE,(TopOpeBRepBuild_Builder* const)this,&WES,"GSplitEdgeWES " ,"WES+ Eisspl ");
819 #endif
820       
821       WES.AddStartElement(newE);
822     }
823   } // issplit
824
825   else {
826     // EOR sans devenir de Split par TB1 : on la garde si elle est situee TB1 / LSclass
827     Standard_Boolean se = BDS.IsSectionEdge(TopoDS::Edge(EOR));
828     Standard_Boolean hs = myDataStructure->HasShape(EOR);
829     Standard_Boolean hg = myDataStructure->HasGeometry(EOR);
830     Standard_Boolean add = Standard_False;
831     Standard_Boolean addON = Standard_False;
832
833     Standard_Boolean isstart = Standard_False;
834     isstart = hs;
835
836     if (se) {
837       Standard_Boolean ftg = !LSclass.IsEmpty();
838       TopAbs_ShapeEnum tclass = LSclass.First().ShapeType();
839       ftg = ftg && (tclass == TopAbs_FACE);
840       if (!ftg) {
841         TopAbs_State pos;
842         Standard_Boolean keepse = GKeepShape1(EOR,LSclass,TB1,pos);
843         if (keepse)
844           add = Standard_True;
845         else if (myProcessON && pos == TopAbs_ON)
846           addON = Standard_True;
847       }
848       
849 #ifdef DEBDEB
850       cout<<"o-o GridFF ffil F"<<ifil<<" se E"<<iEOR<<" / "<<iWESF<<" ";
851       TopAbs::Print(TB1,cout);cout.flush();
852       Standard_Boolean tse = TopOpeBRepDS_GettraceSPSX(iEOR);
853       TopOpeBRepDS_SettraceSPSX(iEOR,Standard_True);
854       if (!ftg) {cout<<" : !ftg --> "; GKeepShape(EOR,LSclass,TB1);cout.flush();}
855       else      {cout<<" : ftg --> non gardee"<<endl;cout.flush();}
856       TopOpeBRepDS_SettraceSPSX(iEOR,tse);
857 #endif
858
859     }
860     else {
861       add = Standard_True;
862       Standard_Boolean testkeep = Standard_True;
863       testkeep = hs && (!hg);
864       if (testkeep) {
865 #ifdef DEB
866         if(tSPS){cout<<"--- GSplitEdgeWES ";}
867 #endif
868         TopAbs_State pos;
869         Standard_Boolean keep = GKeepShape1(EOR,LSclass,TB1,pos);
870         if ( !keep ) {
871           Standard_Boolean testON = (!LSclass.IsEmpty());
872           if (testON) testON = (LSclass.First().ShapeType() == TopAbs_SOLID);
873           if (testON) keep = (pos == TopAbs_ON);
874           addON = myProcessON && keep;
875         }
876         add = keep;
877       }
878     } // !se
879
880     if (add) {
881       TopoDS_Shape newE = EOR;
882        
883       if      (newO)                 newE.Orientation(oEinF);// xpu060598  
884       else if (Oinref == FORREVOPPO) newE.Orientation(TopAbs_INTERNAL);// xpu120898 (PRO14785 : e36 shared by f34 & f39,
885                                                                        // faces sdm with f16)
886       else                           newE.Orientation(neworiE); 
887 #ifdef DEB
888       if(tSPS){
889         DEBSHASET(ss,"--- GSplitEdgeWES ",WES," WES+ edge ");  
890         GdumpSHA(newE,(Standard_Address)ss.ToCString());
891         cout<<" ";TopAbs::Print(TB1,cout)<<" : 1 edge ";
892         TopAbs::Print(neworiE,cout); cout<<endl;
893       }
894 #endif
895
896       if (isstart) {
897 #ifdef DEB
898         if (tSPS) debaddpwes(iWESF,TB1,iEOR,neworiE,(TopOpeBRepBuild_Builder* const)this,&WES,"GSplitEdgeWES " ,"WES+ Enospl ");
899 #endif
900         WES.AddStartElement(newE);
901       }
902       else {
903         WES.AddElement(newE);
904       }
905     } // add
906
907     if (addON) {
908       TopoDS_Shape newE = EOR;
909       newE.Orientation(neworiE);
910       myONElemMap.Add(newE);
911     }
912   } // !issplit
913
914   if (myProcessON && IsSplit(EOR,TopAbs_ON)) {
915     const TopTools_ListOfShape& LSE = Splits(EOR,TopAbs_ON);
916     TopTools_ListIteratorOfListOfShape it(LSE);
917     for (; it.More(); it.Next()) {
918       TopoDS_Edge newE = TopoDS::Edge(it.Value());
919       if (newO) {
920         newE.Orientation(oEinF);
921         Standard_Boolean dgE = BRep_Tool::Degenerated(TopoDS::Edge(EOR)); 
922         if (!dgE && hsdmE) {
923           Standard_Real f,l; FUN_tool_bounds(newE,f,l); 
924           Standard_Real x = 0.45678; Standard_Real par = (1-x)*f + x*l; 
925           Standard_Boolean so = Standard_True;
926           Standard_Boolean ok = FUN_tool_curvesSO(newE,par,TopoDS::Edge(EOR),so);
927           if (!ok) {
928 #ifdef DEB
929             cout<<"GSplitEdgeWES: cannot orient SDM split of an edge"<<endl;
930 #endif
931           }
932           if (!so) newE.Reverse();
933         }
934       }
935       else newE.Orientation(neworiE);
936       myONElemMap.Add(newE);
937     }
938   }
939
940 #ifdef DEB
941   if(tSPS) GdumpSHASTA(iEOR,TB1,WES,"--- GSplitEdgeWES","END");
942 #endif  
943   
944   return;
945 } // GSplitEdgeWES
946
947 Standard_IMPORT Standard_Boolean FUN_ismotheropedef();
948 Standard_IMPORT const TopOpeBRepBuild_GTopo& FUN_motherope();
949 Standard_EXPORT Standard_Boolean GLOBAL_IEtoMERGE = 0; // xpu240498
950
951 #ifdef DEB
952 void debmergee(const Standard_Integer /*i*/) {}
953 #endif
954
955 //=======================================================================
956 //function : GMergeEdgeWES
957 //purpose  : 
958 //=======================================================================
959   void TopOpeBRepBuild_Builder::GMergeEdgeWES(const TopoDS_Shape& EOR,
960                                               const TopOpeBRepBuild_GTopo& G1,
961                                               TopOpeBRepBuild_WireEdgeSet& WES)
962 {
963 #ifdef DEB
964   Standard_Integer iWESF; /*Standard_Boolean tSPSW = */GtraceSPS(WES.Face(),iWESF);
965   Standard_Integer iEOR; Standard_Boolean tSPS = GtraceSPS(EOR,iEOR);
966   if(tSPS){ debmergee(iEOR);
967     DEBSHASET(s,"\n--- GMergeEdgeWES ",WES," START ");  
968     GdumpSHAORIGEO(EOR,(Standard_Address)s.ToCString()); cout<<endl;
969   }
970 #endif
971
972   Standard_Boolean closing = BRep_Tool::IsClosed(TopoDS::Edge(EOR),myFaceToFill); // xpu050598
973   if (closing) return; // xpu050598
974
975   if (Opefus()) return;
976   
977 //  const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
978   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
979   Standard_Boolean RevOri1 = G1.IsToReverse1();
980   TopAbs_Orientation oriE = EOR.Orientation();
981   TopAbs_Orientation neworiE = Orient(oriE,RevOri1);
982   
983   Standard_Boolean hassame = myDataStructure->HasSameDomain(EOR);
984   if (!hassame) return;
985
986   Standard_Boolean Eisref = Standard_False;
987   if (hassame) {
988     Standard_Integer iEref = myDataStructure->SameDomainReference(EOR);
989     const TopoDS_Shape& Eref = myDataStructure->Shape(iEref);
990     Eisref = EOR.IsSame(Eref);
991   }
992
993   TopAbs_State TBEOR = (Eisref) ? TB1 : TB2; 
994   if (TBEOR == TopAbs_OUT) return; //xpu040598
995
996   Standard_Boolean ismerged = IsMerged(EOR,TBEOR);
997   if (ismerged) {
998     if (!Eisref) return;
999
1000     const TopTools_ListOfShape& ME = Merged(EOR,TBEOR);
1001     TopTools_ListIteratorOfListOfShape it(ME);
1002     for(; it.More(); it.Next()) {
1003       TopoDS_Shape newE = it.Value();
1004       newE.Orientation(neworiE);
1005
1006 #ifdef DEB
1007       if (tSPS) debaddpwes(iWESF,TB1,iEOR,neworiE,(TopOpeBRepBuild_Builder* const)this,&WES,"GMergeEdgeWES " ,"WES+ Emerge ");
1008 #endif
1009
1010       WES.AddStartElement(newE);
1011     }
1012     return;
1013   } 
1014
1015   ChangeMerged(EOR,TBEOR) = myEmptyShapeList; 
1016   TopAbs_State stspEOR;
1017 //  if (isfafa) stspEOR = TBEOR; // xpu110598
1018 //  else stspEOR = (TBEOR == TopAbs_IN) ? TopAbs_ON : TopAbs_OUT;
1019   stspEOR = TBEOR; // xpu120598
1020
1021   Standard_Boolean issplit = IsSplit(EOR,stspEOR);
1022   if (!issplit) return;
1023
1024   ChangeMerged(EOR,TBEOR) = Splits(EOR,stspEOR);
1025
1026   const TopTools_ListOfShape& ME = Merged(EOR,TBEOR);
1027 #ifdef DEB
1028   if(tSPS){
1029     DEBSHASET(s,"GMergeEdgeWES(1) ",WES," WES+ Merged ");  
1030     GdumpSHA(EOR,(Standard_Address)s.ToCString());
1031     cout<<" ";TopAbs::Print(TBEOR,cout);
1032     cout<<" : "<<ME.Extent()<<" edge"<<endl;
1033   }
1034 #endif
1035   for(TopTools_ListIteratorOfListOfShape it(ME);it.More();it.Next()) {
1036     TopoDS_Shape newE = it.Value();
1037     newE.Orientation(neworiE);
1038     WES.AddStartElement(newE);
1039   }
1040
1041 #ifdef DEB
1042   if(tSPS){
1043     DEBSHASET(sss,"GMergeEdgeWES ",WES," END ");
1044     GdumpSHA(EOR,(Standard_Address)sss.ToCString());cout<<endl;
1045   }
1046 #endif
1047   
1048 } // GMergeEdgeWES
1049
1050 //=======================================================================
1051 //function : GSplitEdge
1052 //purpose  : 
1053 //=======================================================================
1054   void TopOpeBRepBuild_Builder::GSplitEdge(const TopoDS_Shape& EOR,
1055                                            const TopOpeBRepBuild_GTopo& G1,
1056                                            const TopTools_ListOfShape& LSclass)
1057 {
1058   TopAbs_ShapeEnum t1,t2;
1059   G1.Type(t1,t2);
1060   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
1061   // work on a FORWARD edge <EF>
1062   TopoDS_Shape EF = EOR; EF.Orientation(TopAbs_FORWARD);
1063   
1064 #ifdef DEB
1065   Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EOR,iE);
1066   if (tSPS) GdumpSHASTA(EOR,TB1,"--- GSplitEdge ","\n");
1067   if (tSPS) GdumpEDG(EF);
1068   if (tSPS) debsplite(iE);
1069 #endif
1070
1071   const TopoDS_Edge& EEF = TopoDS::Edge(EF);
1072   Standard_Boolean isse = myDataStructure->DS().IsSectionEdge(EEF);
1073   Standard_Boolean issplitON = IsSplit(EEF,TopAbs_ON);
1074   Standard_Boolean takeON = (TB1 == TopAbs_IN) && (isse) && (issplitON);
1075   takeON = Standard_False;
1076 #ifdef DEB
1077   if (tSPS) cout<<"---- takeON mis a 0"<<endl;
1078 #endif
1079
1080   if ( takeON ) {
1081
1082 #ifdef DEB
1083     if (tSPS) GdumpSHASTA(EOR,TB1,"--- GSplitEdge takeON ","\n");
1084 #endif
1085
1086     MarkSplit(EF,TB1);
1087     TopTools_ListOfShape& SSEL = ChangeSplit(EF,TB1);
1088     SSEL.Clear();
1089     SSEL = Splits(EEF,TopAbs_ON);
1090     return;
1091   }
1092
1093   TopTools_ListOfShape LOE;
1094   
1095   // Make a PaveSet PVS on edge EF
1096   TopOpeBRepBuild_PaveSet PVS(EF);
1097   
1098   // Add the point topology found on edge EF in PVS
1099   myEdgeReference = TopoDS::Edge(EF);
1100   GFillPointTopologyPVS(EF,G1,PVS);
1101   
1102   // mark EF as split TB1
1103   MarkSplit(EF,TB1);
1104   
1105   // build the new edges LOE on EF from the Parametrized Vertex set PVS
1106   GPVSMakeEdges(EF,PVS,LOE);
1107   
1108   Standard_Boolean novertex = LOE.IsEmpty();
1109   if (novertex) return;
1110
1111   TopTools_ListOfShape& SEL = ChangeSplit(EF,TB1);
1112   SEL.Clear();
1113   // NYI ne pas faire de classification des aretes reconstruites / liste de solides
1114   // NYI dans le cas ou l'appel a SplitEdge est utilise pour construire les parties
1115   // NYI (TopAbs_ON,SOLID) (i.e par la construction des parties (TopAbs_IN,FACE)).
1116   TopOpeBRepDS_Config c1 = G1.Config1(),c2 = G1.Config2();
1117   Standard_Boolean UUFACE = (c1==TopOpeBRepDS_UNSHGEOMETRY && c2==TopOpeBRepDS_UNSHGEOMETRY);
1118
1119   Standard_Boolean ONSOLID = Standard_False;
1120   if ( ! LSclass.IsEmpty() ) {
1121     TopAbs_ShapeEnum t = LSclass.First().ShapeType();
1122     ONSOLID = (t == TopAbs_SOLID);
1123   }
1124
1125   Standard_Boolean toclass = UUFACE;
1126   toclass = ! ONSOLID; 
1127
1128   TopTools_ListOfShape loos;
1129   const TopTools_ListOfShape* pls;
1130   if (GLOBAL_classifysplitedge) {
1131     Standard_Integer r=GShapeRank(EOR);
1132     TopoDS_Shape oos=myShape1;
1133     if (r==1) oos = myShape2;
1134     if (!oos.IsNull()) loos.Append(oos); // PMN 5/03/99 Nothing to append
1135     pls = &loos;
1136   }
1137   else if (toclass) {
1138     pls = &LSclass;
1139   }
1140   else {
1141     pls = &myEmptyShapeList;
1142   }
1143
1144   TopTools_ListOfShape aLON;
1145   TopTools_ListIteratorOfListOfShape it(LOE);
1146   for(;it.More();it.Next()) {
1147     const TopoDS_Shape& aE = it.Value();
1148     TopAbs_State pos;
1149     if (GKeepShape1(aE,*pls,TB1,pos))
1150       SEL.Append(aE);
1151     else if (myProcessON && pos == TopAbs_ON)
1152       aLON.Append(aE);
1153   }
1154
1155   if (!aLON.IsEmpty()) {
1156     MarkSplit(EF,TopAbs_ON);
1157     TopTools_ListOfShape& aSLON = ChangeSplit(EF,TopAbs_ON);
1158     aSLON.Clear();
1159     aSLON.Append(aLON);
1160   }
1161
1162 } // GSplitEdge
1163
1164 //modified by NIZNHY-PKV Mon Mar 19 16:50:33 2001 f
1165 #include <BRepClass3d_SolidClassifier.hxx>
1166 //=======================================================================
1167 //function : ClassifyEdgeToSolidByOnePoint
1168 //purpose  : 
1169 //=======================================================================
1170 TopAbs_State ClassifyEdgeToSolidByOnePoint(const TopoDS_Edge& E,
1171                                                   const TopoDS_Shape& Ref)
1172 {
1173   const Standard_Real PAR_T = 0.43213918;//10.*e^-PI
1174   Standard_Real f2 = 0., l2 = 0., par = 0.;
1175
1176   Handle(Geom_Curve) C3D = BRep_Tool::Curve(E, f2, l2);
1177   gp_Pnt aP3d;
1178
1179   if(C3D.IsNull()) {
1180     //it means that we are in degenerated edge
1181     const TopoDS_Vertex& fv = TopExp::FirstVertex(E);
1182     if(fv.IsNull())
1183       return TopAbs_UNKNOWN;
1184     aP3d = BRep_Tool::Pnt(fv);
1185   }
1186   else {//usual case
1187     par = f2*PAR_T + (1 - PAR_T)*l2;
1188     C3D -> D0(par, aP3d);
1189   }
1190     
1191   BRepClass3d_SolidClassifier SC(Ref);
1192   SC.Perform(aP3d, 1e-7);
1193
1194   return SC.State();
1195 }
1196 //modified by NIZNHY-PKV Mon Mar 19 16:50:36 2001 t