Test for 0022778: Bug in BRepMesh
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_Section.cxx
1 // Created on: 1997-01-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
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.
10 //
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.
13 //
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.
20
21
22 #include <TopOpeBRepBuild_Builder.ixx>
23 #include <TopOpeBRepBuild_define.hxx>
24 #include <TopOpeBRepDS_CurveExplorer.hxx>
25 #include <TopOpeBRepDS_TKI.hxx>
26 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
27 #include <TopOpeBRepBuild_GTool.hxx>
28 #include <TopoDS.hxx>
29 #include <GeomAPI_ProjectPointOnCurve.hxx>
30 #include <BRep_Tool.hxx>
31 #include <gp_Pnt.hxx>
32 #include <TopExp.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom2d_TrimmedCurve.hxx>
35 #include <Standard_ProgramError.hxx>
36 #include <TopOpeBRepDS_EXPORT.hxx>
37 #include <TopOpeBRepDS_connex.hxx>
38 #include <TopOpeBRepDS_TKI.hxx>
39 #include <Geom2d_Curve.hxx>
40 #include <Geom_Curve.hxx>
41 #include <BRep_Tool.hxx>
42 #include <BRep_Builder.hxx>
43 #include <TopOpeBRepTool_CurveTool.hxx>
44 #include <TopOpeBRepTool_TOOL.hxx>
45 #include <TopOpeBRepTool_2d.hxx>
46 #include <TopOpeBRepTool_EXPORT.hxx>
47
48 #define MGhc3 Handle(Geom_Curve)
49 #define MGhc2 Handle(Geom2d_Curve)
50
51 #ifdef DEB
52 Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceSPS();
53 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceDSNC();
54 Standard_EXPORT void debsplitse(const Standard_Integer) {}
55 Standard_EXPORT void debsplitsemess(const Standard_Integer i,const TCollection_AsciiString& s = "");
56 Standard_EXPORT void debsplitsemess(const Standard_Integer i,const TCollection_AsciiString& s){cout<<"+++ debsplitse "<<s<<" E"<<i<<endl;debsplitse(i);}
57 Standard_EXPORT void debspseou(const Standard_Integer i) {debsplitsemess(i,"OUT");}
58 Standard_EXPORT void debspsein(const Standard_Integer i) {debsplitsemess(i,"IN ");}
59 Standard_EXPORT void debspseon(const Standard_Integer i) {debsplitsemess(i,"ON ");}
60 Standard_IMPORT Standard_Boolean TopOpeBRepTool_GettraceC2D();
61 #endif
62
63 #ifdef DRAW
64 #include <TopOpeBRepTool_DRAW.hxx>
65 #endif
66
67 //Standard_IMPORT void FUN_tool_ttranslate(const gp_Vec2d& tvector, const TopoDS_Face& fF, TopoDS_Edge& fyE);
68
69 #include <TopOpeBRepTool_ShapeTool.hxx>
70 #include <GeomAdaptor_Surface.hxx>
71 #include <GeomAbs_SurfaceType.hxx>
72 //---------------------------------------------
73 static Standard_Boolean FUN_periodicS(const TopoDS_Shape& F)
74 //---------------------------------------------
75 {
76   if (F.IsNull()) return Standard_False;
77   if (F.ShapeType() != TopAbs_FACE) return Standard_False;
78   Handle(Geom_Surface) SSS = TopOpeBRepTool_ShapeTool::BASISSURFACE(TopoDS::Face(F));
79   GeomAdaptor_Surface GAS(SSS);  
80   GeomAbs_SurfaceType styp = GAS.GetType();
81   Standard_Boolean periodic = Standard_False;
82   if (styp == GeomAbs_Cylinder) periodic = Standard_True;
83   if (styp == GeomAbs_Cone) periodic = Standard_True;
84   if (styp == GeomAbs_Sphere) periodic = Standard_True;
85   // NYI : for Torus,SurfaceOfRevolution.. 
86   return periodic;
87 }
88
89 static Standard_Boolean FUN_periodic(const TopoDS_Face& F,Standard_Boolean& uper,Standard_Boolean& vper)
90 {
91   const Handle(Geom_Surface)& su = BRep_Tool::Surface(F);
92   uper = su->IsUPeriodic(); 
93   vper = su->IsVPeriodic();
94   Standard_Boolean per = (uper || vper);
95   return per;  
96 }
97
98 static Standard_Boolean FUN_onboundsper(const gp_Pnt2d& uv,const TopoDS_Face& F)
99 {  
100   // 2d : 
101   const Handle(Geom_Surface)& su = BRep_Tool::Surface(F);
102   Standard_Boolean uclo = su->IsUPeriodic();  
103   Standard_Boolean vclo = su->IsVPeriodic();
104   if (!uclo && !vclo) return Standard_False;
105
106   Standard_Real u1,u2,v1,v2; su->Bounds(u1,u2,v1,v2);
107   Standard_Real toluv = 1.e-8*1.e-2; // nyinyitol
108   if (uclo) {
109     Standard_Real d1 = Abs(u1-uv.X()); Standard_Boolean on1 = (d1 < toluv);
110     Standard_Real d2 = Abs(u2-uv.X()); Standard_Boolean on2 = (d2 < toluv);
111     return (on1 || on2);
112   }
113   if (vclo) {
114     Standard_Real d1 = Abs(v1-uv.Y()); Standard_Boolean on1 = (d1 < toluv);
115     Standard_Real d2 = Abs(v2-uv.Y()); Standard_Boolean on2 = (d2 < toluv);
116     return (on1 || on2);
117   }
118   return Standard_False;  
119 }
120                            
121 static Standard_Boolean FUN_onboundsper(const TopoDS_Edge& E,const TopoDS_Face& F, gp_Pnt2d& uv)
122 // uv is found by projection pnt(E,par)
123 {  
124   // 3d : 
125   Standard_Real f,l; FUN_tool_bounds(E,f,l); Standard_Real x=0.45678; Standard_Real par=f*x+(1-x)*l;
126   Standard_Real tolF = BRep_Tool::Tolerance(F)*1.e2; // nyitol
127   Standard_Boolean ok = FUN_tool_parF(E,par,F,uv,tolF);
128   if (!ok) return Standard_False;
129   
130   Standard_Boolean onbp = ::FUN_onboundsper(uv,F);
131   return onbp;
132 }
133
134
135
136 //-----------------------------------------------------------------------
137 static Standard_Boolean FUN_PinC(const gp_Pnt& P,const Handle(Geom_Curve)& C,const Standard_Real pmin,const Standard_Real pmax,const Standard_Real tol)
138 //-----------------------------------------------------------------------
139 {
140   Standard_Boolean PinC = Standard_False;
141   GeomAPI_ProjectPointOnCurve mydm(P,C,pmin,pmax);
142   Standard_Boolean dmdone = ( mydm.Extrema().IsDone() );
143   if ( dmdone ) {
144     if ( mydm.NbPoints() ) {
145       Standard_Real d = mydm.LowerDistance();
146       PinC = (d <= tol);
147     }
148   }
149   return PinC;
150 }
151
152 //-----------------------------------------------------------------------
153 static Standard_Boolean FUN_PinE(const gp_Pnt& P, const TopoDS_Edge& E)
154 //-----------------------------------------------------------------------
155 {
156   Standard_Boolean PinE = Standard_False; 
157   Standard_Real f,l; Handle(Geom_Curve) CE = BRep_Tool::Curve(E,f,l);
158   Standard_Real tolE = BRep_Tool::Tolerance(E);
159   PinE = FUN_PinC(P,CE,f,l,tolE);
160   return PinE;
161 }
162
163 #include <BRep_Tool.hxx>
164 //-----------------------------------------------------------------------
165 static Standard_Boolean FUN_EstaEE(const TopoDS_Edge& E, const TopAbs_State sta, const TopoDS_Edge& EE)
166 //-----------------------------------------------------------------------
167 {
168   Standard_Boolean EinEE = Standard_False; 
169   Standard_Real f,l; 
170   //modified by NIZNHY-PKV Wed Nov  3 11:40:14 1999 from
171
172   if (BRep_Tool::Degenerated(E)) {
173     if      (sta == TopAbs_IN)  return Standard_False;
174     else  return  Standard_True;
175   }
176   //modified by NIZNHY-PKV Wed Nov  3 11:40:19 1999 to
177
178   Handle(Geom_Curve) CE = BRep_Tool::Curve(E,f,l);
179   Standard_Real t = 0.417789; // Oi blya... ???
180   Standard_Real p = (1-t)*f + t*l; 
181   gp_Pnt P = CE->Value(p);
182   EinEE = FUN_PinE(P,EE);
183   if      (sta == TopAbs_IN)  return EinEE;
184   else if (sta == TopAbs_OUT) return !EinEE;
185   else Standard_ProgramError::Raise("TopOpeBRepBuild FUN_EstaEE on invalid state");
186   return EinEE;
187 }
188
189 //=======================================================================
190 //function : TopOpeBRepBuild_Builder::InitSection
191 //purpose  : 
192 //=======================================================================
193 void TopOpeBRepBuild_Builder::InitSection()
194 {
195   mySectionDone = Standard_False;
196   mySection.Clear();
197   mySplitSectionEdgesDone = Standard_False;
198   mySplitON.Clear();
199 }
200
201 //-----------------------------------------------------------------------
202 // LE : list of edges from where is extracted LEsta = edges located <sta> / edge E
203 // N.B. : LEsta is expanded and NOT reinitialized
204 static void FUN_selLEE(TopTools_ListOfShape& LE,const TopoDS_Edge& E,const TopAbs_State sta,TopTools_ListOfShape& LEsta)
205 {
206   TopTools_ListIteratorOfListOfShape it(LE);
207   while (it.More()) {
208     const TopoDS_Edge& Ecur = TopoDS::Edge(it.Value());
209     Standard_Boolean ok = FUN_EstaEE(Ecur,sta,E);
210     if (ok) {
211       LEsta.Append(Ecur);
212       LE.Remove(it);
213     }
214     else it.Next();
215   }
216 }
217
218 //-----------------------------------------------------------------------
219 // search the existence of shape E in time as shape of a mesh cell
220 // (shape,listofshape) of the list loslos.
221 Standard_Boolean FUN_FindEinSLOS(const TopoDS_Shape& E,const TopOpeBRepBuild_ListOfShapeListOfShape& loslos)
222 {
223   Standard_Boolean f = Standard_False;
224   for (TopOpeBRepBuild_ListIteratorOfListOfShapeListOfShape it(loslos); it.More(); it.Next()) {
225     const TopoDS_Shape& S = it.Value().Shape();
226     Standard_Boolean issame = (S.IsSame(E));
227     if (issame) {
228       f = Standard_True;
229       break;
230     }
231   }
232   return f;
233 }
234
235 //=======================================================================
236 //function : SplitSectionEdges
237 //purpose  : 
238 //=======================================================================
239 void TopOpeBRepBuild_Builder::SplitSectionEdges()
240 {
241   if (mySplitSectionEdgesDone) return;
242
243   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
244   Standard_Integer i,n = BDS.NbSectionEdges();
245   
246 #ifdef DEB
247   if (TopOpeBRepDS_GettraceDSNC() && !mySplitSectionEdgesDone) 
248     cout<<"TopOpeBRepBuild_Builder::SSE : compute "<<n<<" section edges"<<endl;
249 #endif
250   
251   for (i = 1; i <= n; i++) { // 1
252     const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
253     if(E.IsNull()) continue;
254     SplitSectionEdge(E);  
255   } // 1
256
257   TopOpeBRepBuild_DataMapOfShapeListOfShapeListOfShape MEIN;
258   TopTools_DataMapOfShapeListOfShape MEOUT;
259   
260   for (i = 1; i <= n; i++) { // 2
261     const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
262     if(E.IsNull()) continue;
263     Standard_Integer iE = myDataStructure->Shape(E); 
264     Standard_Integer rE = BDS.AncestorRank(E);
265
266 #ifdef DEB
267     Standard_Boolean tSPS = GtraceSPS(E,iE); if (tSPS) debsplitsemess(iE); Standard_Integer DEBiESD = 1;
268 #endif
269
270     Standard_Boolean isspliton = IsSplit(E,TopAbs_ON);
271     if (!isspliton) continue;
272
273     const TopTools_ListOfShape& LESD = BDS.ShapeSameDomain(E);
274     if ( LESD.IsEmpty() ) continue;
275
276     const TopTools_ListOfShape& LEspon = Splits(E,TopAbs_ON);
277     TopTools_ListOfShape LEoutLESD; GCopyList(LEspon,LEoutLESD);
278     Standard_Integer iRef = BDS.SameDomainRef(E);
279
280     // LEoutLESD = list of edges Split(E,ON) OUT of all 
281     // edges of the list of edges same domain of E in 3d only
282     // edges LEoutLESD are attached in Split(ON) to E only.
283  
284     for (TopTools_ListIteratorOfListOfShape itLESD(LESD); itLESD.More(); itLESD.Next()) { // 2.1
285       const TopoDS_Edge& ESD = TopoDS::Edge(itLESD.Value()); 
286       Standard_Integer iESD = myDataStructure->Shape(ESD);
287       const TopTools_ListOfShape& LESDspon = Splits(ESD,TopAbs_ON);
288
289 #ifdef DEB
290       if (tSPS) {
291         TCollection_AsciiString str("# edge ");str=str+iE+" sd3d edge "+iESD;
292         TCollection_AsciiString stru(str.Length(),'-');
293         cout<<endl;if(DEBiESD==1)cout<<stru<<endl;
294         DEBiESD++;cout<<str<<endl;debsplitsemess(iE);
295       }
296 #endif
297
298       // reduction of LEoutLESD = edges OUT all ESD
299       TopTools_ListOfShape dummylos;
300       FUN_selLEE(LEoutLESD,ESD,TopAbs_IN,dummylos);
301
302       const TopoDS_Edge    *pE1 = NULL,   *pE2 = NULL;
303       const TopTools_ListOfShape *plos1 = NULL, *plos2 = NULL;
304       Standard_Integer nLEspon   = LEspon.Extent();
305       Standard_Integer nLESDspon = LESDspon.Extent();
306
307       if ( nLEspon != 0 && nLESDspon != 0 ) {
308         Standard_Boolean takeE = (rE == 1 && iESD != iRef || iE == iRef);
309         pE1 =  takeE ? &E : &ESD;
310         pE2 = !takeE ? &E : &ESD;
311         plos1 =  takeE ? &LEspon : &LESDspon;
312         plos2 = !takeE ? &LEspon : &LESDspon;
313       }
314       else if ( nLEspon != 0 ) {
315         pE1 = &E;
316         pE2 = &ESD;
317         plos1 = &LEspon;
318         plos2 = &LESDspon;
319       }
320       else if ( nLESDspon != 0 ) {
321         pE1 = &ESD;
322         pE2 = &E;
323         plos1 = &LESDspon;
324         plos2 = &LEspon;
325       }
326       
327       if (pE1 == NULL || pE2 == NULL) continue;
328       if (plos1 == NULL || plos2 == NULL) continue;
329
330       const TopoDS_Edge& E1 = *pE1;
331       const TopoDS_Edge& E2 = *pE2;
332       const TopTools_ListOfShape& LE1 = *plos1;
333
334       // selection of edges IN E2 = LEinE2
335       TopTools_ListOfShape LE1loc; 
336       GCopyList(LE1,LE1loc);
337       TopTools_ListOfShape LE1inE2;
338       FUN_selLEE(LE1loc,E2,TopAbs_IN,LE1inE2);
339       Standard_Integer nLE1inE2 = LE1inE2.Extent();
340
341 #ifdef DRAW
342       if (tSPS) {
343         cout<<"# edges ON "<<iE<<" ";
344         TopAbs::Print(TopAbs_IN,cout); cout<<" / esd";
345         cout<<" "<<iESD;
346         cout<<" : ("<<nLE1inE2<<")"<<endl;
347         TCollection_AsciiString str("ON");str=str+iE+"IN"+iESD;
348         FDRAW_DINLOE("   ",LE1inE2,str,"");
349       }
350 #endif
351       
352       // edges E1 and E2 share LE1inE2
353       if (nLE1inE2 != 0) { // 2.2
354
355         Standard_Boolean E1b = MEIN.IsBound(E1);
356         TopOpeBRepBuild_ListOfShapeListOfShape thelist;
357         if (!E1b) MEIN.Bind(E1, thelist);
358         TopOpeBRepBuild_ListOfShapeListOfShape& LE1loslos = MEIN.ChangeFind(E1);
359 #ifdef DEB
360 //      Standard_Integer nLE1 = LE1loslos.Extent();
361 #endif
362         
363         Standard_Boolean E2b = MEIN.IsBound(E2);
364         TopOpeBRepBuild_ListOfShapeListOfShape thelist2;
365         if (!E2b) MEIN.Bind(E2,thelist2);
366         TopOpeBRepBuild_ListOfShapeListOfShape& LE2loslos = MEIN.ChangeFind(E2);
367 #ifdef DEB
368 //      Standard_Integer nLE2 = LE2loslos.Extent();
369 #endif
370         
371         Standard_Boolean E2elemofE1 = FUN_FindEinSLOS(E2,LE1loslos);     
372         Standard_Boolean E1elemofE2 = FUN_FindEinSLOS(E1,LE2loslos);
373         
374         Standard_Boolean condadd = (!E2elemofE1 && !E1elemofE2);
375         if (condadd) {
376           // regularization of edges of LE1inE2 -> LR
377           TopTools_ListOfShape LR;
378           for (TopTools_ListIteratorOfListOfShape ite(LE1inE2);ite.More();ite.Next()){
379             const TopoDS_Edge& e = TopoDS::Edge(ite.Value());
380             TopTools_ListOfShape newle; Standard_Boolean ok = TopOpeBRepTool_TOOL::SplitE(e,newle);
381             if (ok) LR.Append(newle);
382             else    LR.Append(e);
383           }
384           {
385             TopOpeBRepBuild_ShapeListOfShape thelist3;
386             LE1loslos.Append(thelist3);
387             TopOpeBRepBuild_ShapeListOfShape& E1slos = LE1loslos.Last();
388             E1slos.ChangeShape() = E2;
389             GCopyList(LR,E1slos.ChangeList());
390           }
391           {
392             TopOpeBRepBuild_ShapeListOfShape thelist4;
393             LE2loslos.Append(thelist4);
394             TopOpeBRepBuild_ShapeListOfShape& E2slos = LE2loslos.Last();
395             E2slos.ChangeShape() = E1;
396             GCopyList(LR,E2slos.ChangeList());
397           }
398         }
399       } // 2.2
400     } 
401
402 #ifdef DRAW
403     if (tSPS) {
404       cout<<endl<<"# edges ON "<<iE<<" ";
405       TopAbs::Print(TopAbs_OUT,cout);cout<<" / lesd";
406       for(TopTools_ListIteratorOfListOfShape it(LESD);it.More();it.Next())
407         cout<<" "<<myDataStructure->Shape(it.Value());
408       Standard_Integer n=LEoutLESD.Extent();cout<<" : ("<<n<<")"<<endl;
409       TCollection_AsciiString str("ON");str=str+iE+"OUT";
410       FDRAW_DINLOE("   ",LEoutLESD,str,"");
411     }
412 #endif
413     
414     if (!MEOUT.IsBound(E)) {
415       TopTools_ListOfShape thelist5;
416       MEOUT.Bind(E, thelist5);
417     }
418     GCopyList(LEoutLESD,MEOUT.ChangeFind(E));
419
420   } // 2
421
422   for (i = 1; i <= n; i++) { // 3
423     const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
424     if(E.IsNull()) continue;
425 #ifdef DEB
426     Standard_Integer iE = myDataStructure->Shape(E);
427 //    Standard_Integer rE = GShapeRank(E);
428     Standard_Boolean tSPS = GtraceSPS(E,iE); 
429     if (tSPS) debsplitsemess(iE);
430 #endif
431
432     Standard_Boolean isspliton = IsSplit(E,TopAbs_ON);;
433     if (!isspliton) continue;
434
435     const TopTools_ListOfShape& LESD = BDS.ShapeSameDomain(E);
436     if ( LESD.IsEmpty() ) continue;
437
438     Standard_Boolean isbMEOUT = MEOUT.IsBound(E);
439     Standard_Boolean isbMEIN = MEIN.IsBound(E);
440     if (!isbMEOUT && !isbMEIN) continue;
441
442     TopTools_ListOfShape& LEspon = ChangeSplit(E,TopAbs_ON);
443     LEspon.Clear();
444     
445     if (isbMEOUT) {
446       const TopTools_ListOfShape& LEOUT = MEOUT.Find(E);
447 #ifdef DEB
448 //      Standard_Integer nOUT = LEOUT.Extent();
449 #endif
450       GCopyList(LEOUT,LEspon);
451     }
452
453     if (isbMEIN) {
454       const TopOpeBRepBuild_ListOfShapeListOfShape& loslos = MEIN.Find(E);
455 #ifdef DEB
456 //      Standard_Integer nloslos = loslos.Extent();
457 #endif
458       for (TopOpeBRepBuild_ListIteratorOfListOfShapeListOfShape it(loslos); it.More(); it.Next()) {
459         const TopTools_ListOfShape& los = it.Value().List();
460 #ifdef DEB
461 //      Standard_Integer nlos = los.Extent();
462 #endif
463         GCopyList(los,LEspon);
464       }
465     }
466   } // 3
467
468   BRep_Builder BB;
469   for (i = 1; i <= n; i++) { // 4
470     const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i)); if(E.IsNull()) continue;
471 #ifdef DEB
472     Standard_Integer idebE; Standard_Boolean tSPS = GtraceSPS(E,idebE); if (tSPS) debsplitsemess(idebE);
473 #endif
474     const TopTools_ListOfShape& lesd = BDS.ShapeSameDomain(E);
475     if (lesd.IsEmpty()) continue;
476     
477     Standard_Integer iE = BDS.Shape(E);
478 #ifdef DEB
479 //    Standard_Integer rE = BDS.AncestorRank(E); 
480 #endif
481     Standard_Integer RE = BDS.SameDomainRef(E);
482     if (iE != RE) continue;
483     
484     TopTools_ListOfShape lF; TopTools_ListIteratorOfListOfShape itlesd;
485     for(itlesd.Initialize(lesd);itlesd.More();itlesd.Next()) {
486       const TopoDS_Edge& esd = TopoDS::Edge(itlesd.Value());
487 #ifdef DEB
488 //      Standard_Integer iesd = BDS.Shape(esd);
489 #endif
490       const TopTools_ListOfShape& lf = FDSCNX_EdgeConnexitySameShape(esd,myDataStructure);
491       GCopyList(lf,lF);
492     }
493 #ifdef DEB
494 //    Standard_Integer nlF = lF.Extent();
495 #endif
496     
497     TopTools_ListOfShape& lon = ChangeSplit(E,TopAbs_ON);
498     Standard_Real tolE = BRep_Tool::Tolerance(E); 
499     TopTools_ListIteratorOfListOfShape it(lF); for(;it.More();it.Next()) {
500       const TopoDS_Face& F = TopoDS::Face(it.Value());
501       Standard_Integer iF = BDS.Shape(F); Standard_Integer rF = BDS.AncestorRank(iF);
502
503       TopoDS_Edge esdF; Standard_Boolean besdF = Standard_False; // NYI pointer on esdF
504       for(itlesd.Initialize(lesd);itlesd.More();itlesd.Next()) {
505         const TopoDS_Edge& esd = TopoDS::Edge(itlesd.Value()); 
506         Standard_Integer iesd = BDS.Shape(esd); Standard_Integer resd = BDS.AncestorRank(iesd);
507         if (resd == rF) { 
508           TopExp_Explorer ex;
509           for (ex.Init(F,TopAbs_EDGE);ex.More();ex.Next()) {
510 //        for (TopExp_Explorer ex(F,TopAbs_EDGE);ex.More();ex.Next()) {
511             const TopoDS_Shape& ee = ex.Current();
512             Standard_Boolean eq = (ee.IsEqual(esd));
513             if (eq) { esdF = esd; besdF = Standard_True; break; }
514           }
515         }
516         if (besdF) break;
517       }
518       
519       TopTools_ListIteratorOfListOfShape itlon(lon); for(;itlon.More();itlon.Next()) {
520         TopoDS_Edge& eon = TopoDS::Edge(itlon.Value());
521         Standard_Real f,l; Standard_Boolean hasPC = FC2D_HasCurveOnSurface(eon,F);
522         if (hasPC) continue;
523 #ifdef DEB
524         if (TopOpeBRepTool_GettraceC2D()) {
525           cout<<"\n#TopOpeBRepBuild_Builder::SSE : hasPC = 0 ES"<<i<<" E"<<idebE<<" sur F"<<iF<<endl;
526           cout<<"tsee s "<<iF<<" "<<idebE<<";"<<endl;
527         }
528 #endif
529 //      Standard_Real tolpc; MGhc2 PC = FC2D_CurveOnSurface(eon,F,esdF,f,l,tolpc);
530         Standard_Real tolpc; MGhc2 PC = FC2D_CurveOnSurface(eon,F,esdF,f,l,tolpc,Standard_True);//xpu051198 :PRO15049
531         hasPC = (!PC.IsNull());
532         if (!hasPC) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::SSE null PC on F");
533         Standard_Real tol = Max(tolE,tolpc);
534         BB.UpdateEdge(eon,PC,F,tol);
535       }
536     }
537   } // 4
538   
539   Standard_Integer nsha = BDS.NbShapes();
540   for (i = 1; i <= nsha; i++) { // 5
541     const TopoDS_Shape& FOR = myDataStructure->Shape(i);
542     Standard_Boolean isface = (FOR.ShapeType() == TopAbs_FACE); 
543     if (!isface) continue;
544     const TopoDS_Face& FF = TopoDS::Face(FOR);
545 #ifdef DEB
546 //    Standard_Integer iFF = BDS.Shape(FF);
547 #endif
548     const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(FF); Standard_Integer nLI = LI.Extent(); 
549     if (nLI == 0) continue;
550     for (TopOpeBRepDS_ListIteratorOfListOfInterference ILI(LI); ILI.More(); ILI.Next() ) {
551       const Handle(TopOpeBRepDS_ShapeShapeInterference)& SSI = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(ILI.Value()); 
552       if (SSI.IsNull()) continue;      
553       TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(SSI,GT,GI,ST,SI); 
554       if (ST != TopOpeBRepDS_FACE) continue;      
555       const TopOpeBRepDS_Transition& TFE = SSI->Transition(); 
556       TopAbs_ShapeEnum shab = TFE.ShapeBefore(),shaa = TFE.ShapeAfter();
557       if (shaa != TopAbs_FACE || shab != TopAbs_FACE) continue;
558       const TopoDS_Face& FS = TopoDS::Face( myDataStructure->Shape(SI)); 
559 #ifdef DEB
560 //      Standard_Integer iFS = myDataStructure->Shape(FS);       
561 #endif
562       Standard_Boolean FSisper = FUN_periodicS(FS);
563       if (!FSisper) continue;
564
565       const TopoDS_Edge& EG = TopoDS::Edge(myDataStructure->Shape(GI)); 
566 #ifdef DEB
567 //      Standard_Integer iEG = myDataStructure->Shape(EG);    
568 #endif
569       Standard_Boolean isrest = myDataStructure->DS().IsSectionEdge(EG); if (!isrest) continue;
570 #ifdef DEB
571 //      Standard_Real tolE = BRep_Tool::Tolerance(EG);
572 #endif
573       Standard_Boolean haspc = FC2D_HasCurveOnSurface(EG,FS); if (haspc) continue;
574       Standard_Boolean hasc3d = FC2D_HasC3D(EG);
575       if (!hasc3d) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::SSE EG without C3D");
576       Standard_Real pf,pl,tolpc; Handle(Geom2d_Curve) PC;
577       Standard_Boolean trim3d = Standard_True; PC = FC2D_CurveOnSurface(EG,FS,pf,pl,tolpc,trim3d);
578       if (PC.IsNull()) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::SSE EG without PC on FS");
579     } 
580   } //5
581   
582   for (i = 1; i <= nsha; i++) { // 6 
583     // xpu201198, for all periodic surfaces
584     const TopoDS_Shape& FOR = myDataStructure->Shape(i);
585     Standard_Boolean isface = (FOR.ShapeType() == TopAbs_FACE); 
586     if (!isface) continue;
587     const TopoDS_Face& FF = TopoDS::Face(FOR);
588 #ifdef DEB
589 //    Standard_Integer iFF = BDS.Shape(FF); 
590 #endif
591     Standard_Boolean FFuper,FFvper; Standard_Boolean FFisper = FUN_periodic(FF,FFuper,FFvper);
592     if (!FFisper) continue;
593
594     const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(FF); Standard_Integer nLI = LI.Extent(); 
595     if (nLI == 0) continue;
596     for (TopOpeBRepDS_ListIteratorOfListOfInterference ILI(LI); ILI.More(); ILI.Next() ) {
597       const Handle(TopOpeBRepDS_ShapeShapeInterference)& SSI = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(ILI.Value()); 
598       if (SSI.IsNull()) continue;      
599       TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(SSI,GT,GI,ST,SI); 
600       if (ST != TopOpeBRepDS_FACE) continue;      
601       Standard_Boolean GB = SSI->GBound();
602       if (GB == 1) continue;
603       
604       const TopoDS_Edge& EG = TopoDS::Edge(myDataStructure->Shape(GI)); 
605 #ifdef DEB
606 //      Standard_Integer iEG = myDataStructure->Shape(EG);    
607 #endif
608       Standard_Boolean isrest = myDataStructure->DS().IsSectionEdge(EG); if (!isrest) continue;
609       
610       // xpu191198 : cto016*
611       Standard_Real pf,pl,tolpc; Handle(Geom2d_Curve) PC;
612       Standard_Boolean trim3d = Standard_True; PC = FC2D_CurveOnSurface(EG,FF,pf,pl,tolpc,trim3d);
613       Standard_Boolean isoU,isoV; gp_Pnt2d o2d; gp_Dir2d d2d; 
614       Standard_Boolean ISO = TopOpeBRepTool_TOOL::UVISO(PC,isoU,isoV,d2d,o2d);
615       if (ISO) {
616         TopTools_ListIteratorOfListOfShape itON(Splits(EG,TopAbs_ON));
617         TopTools_ListOfShape newlON;
618         for (; itON.More(); itON.Next()){
619           TopoDS_Edge eon = TopoDS::Edge(itON.Value());
620
621           Standard_Real pfon,plon,tolpcon; Handle(Geom2d_Curve) PCon;
622           PCon = FC2D_CurveOnSurface(eon,FF,pfon,plon,tolpcon,trim3d);
623
624           Standard_Boolean isouon,isovon; gp_Pnt2d o2don; gp_Dir2d d2don; 
625           Standard_Boolean ISOon = TopOpeBRepTool_TOOL::UVISO(PCon,isouon,isovon,d2don,o2don);
626           Standard_Boolean PCko = !ISOon || ((isoU && !isouon) || (isoV && !isovon));
627           if (PCko) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::splitON");
628
629           Standard_Boolean test = (FFuper && isoU) || (FFvper && isoV);
630           if (!test) { newlON.Append(eon); continue;}
631
632           gp_Pnt2d uvok; Standard_Boolean isonclo = FUN_onboundsper(eon,FF,uvok); //3d
633           if (isonclo) { newlON.Append(eon); continue;}
634           
635           Standard_Boolean isonclo2 = FUN_onboundsper(o2don,FF); //2d
636           if (isonclo2) {           
637             gp_Vec2d tr;
638             if (isoU) {Standard_Real dtr = uvok.X() - o2don.X();tr = gp_Vec2d(dtr,0.);}
639             else      {Standard_Real dtr = uvok.Y() - o2don.Y();tr = gp_Vec2d(0.,dtr);}
640             Standard_Real mag = tr.Magnitude();
641             Standard_Real toluv = 1.e-8*1.e2; // NYINYI
642             if (mag > toluv) TopOpeBRepTool_TOOL::TrslUVModifE(tr,FF,eon);
643           }
644           newlON.Append(eon);    
645         } // itON
646         TopTools_ListOfShape& nlON = ChangeSplit(EG,TopAbs_ON);
647         nlON.Clear(); nlON.Append(newlON);      
648       } // ISO
649     } //ILI(LI)
650   } //6
651   mySplitSectionEdgesDone = Standard_True;  
652 } // SplitSectionEdges
653
654 //Standard_IMPORT extern TopoDS_Shape GLOBALDS_shape1;
655 Standard_EXPORTEXTERN TopoDS_Shape GLOBALDS_shape1;
656 //Standard_IMPORT extern TopoDS_Shape GLOBALDS_shape2;
657 Standard_EXPORTEXTERN TopoDS_Shape GLOBALDS_shape2;
658
659 //unused
660 /*#ifdef DEB
661 static void FUN_removeonGB(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const TopoDS_Edge& E) 
662 {
663   // xpu041198 : removing interferences attached to bounds
664   //             or vertices sdm to bounds of edge<EIX>
665   // (PRO16032, e3on)
666   TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
667   TopOpeBRepDS_ListOfInterference& LI = BDS.ChangeShapeInterferences(E);
668   TopOpeBRepDS_TKI tki; tki.FillOnGeometry(LI);
669   for (tki.Init(); tki.More(); tki.Next()) {
670     TopOpeBRepDS_Kind K; Standard_Integer G; tki.Value(K,G);
671     TopOpeBRepDS_ListOfInterference& loi = tki.ChangeValue(K,G);
672     if (K==TopOpeBRepDS_VERTEX) {
673       const TopoDS_Vertex& vG = TopoDS::Vertex(BDS.Shape(G));
674       Standard_Integer iv = FUN_tool_orientVinE(vG,E);
675       if (iv == 0) {
676         TopoDS_Shape oovG;
677         Standard_Boolean sdm = FUN_ds_getoov(vG,BDS,oovG);
678         iv = FUN_tool_orientVinE(TopoDS::Vertex(oovG),E);
679       }
680       Standard_Boolean isonboundE = (iv != 0);
681       if (isonboundE) loi.Clear();
682     }
683   }
684   LI.Clear();
685   for (tki.Init(); tki.More(); tki.Next()) {
686     TopOpeBRepDS_Kind K; Standard_Integer G; tki.Value(K,G);
687     TopOpeBRepDS_ListOfInterference& loi = tki.ChangeValue(K,G);
688     LI.Append(loi);
689   }  
690 } // FUN_removeonGB
691 #endif*/
692
693 #define TheIN (1)
694 #define TheON (2)
695 #define TheOUT (3)
696 Standard_EXPORT Standard_Integer GLOBAL_issp = 0; //++
697
698 #define HASSD2d (2)
699 #define HASSD3d (3)
700 Standard_EXPORT Standard_Integer GLOBAL_hassd = 0; //++
701
702 //=======================================================================
703 //function : SplitSectionEdge
704 //purpose  : 
705 //=======================================================================
706 void TopOpeBRepBuild_Builder::SplitSectionEdge(const TopoDS_Shape& EA)
707 {
708 #ifdef DEB
709   Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EA,iE);
710   if (tSPS) debsplitsemess(iE);
711 #endif
712
713   TopOpeBRepDS_DataStructure& BDS = myDataStructure->ChangeDS();
714   const TopoDS_Edge& EOR = TopoDS::Edge(EA);
715   TopoDS_Edge EF = EOR; EF.Orientation(TopAbs_FORWARD);
716   Standard_Integer rankEF = myDataStructure->DS().AncestorRank(EF); // GShapeRank <- GMapShapes, appele par Merge
717   
718 //  FUN_removeonGB(myDataStructure,EOR); //xpu041198
719
720   Standard_Boolean hg = myDataStructure->HasGeometry(EOR);
721   Standard_Boolean hsd3d = FDS_HasSameDomain3d(BDS,EOR);
722   Standard_Boolean hsd2d = FDS_HasSameDomain2d(BDS,EOR);
723 #ifdef DEB
724   Standard_Boolean issplit = IsSplit(EOR,TopAbs_ON);
725 #endif
726
727   Standard_Boolean cond = (hg || hsd3d); //REST2 //( hg && (!hsd) );  
728
729   GLOBAL_hassd = 0; // initializing
730   if(hsd3d) GLOBAL_hassd=3; //++
731   if(hsd2d) GLOBAL_hassd=2; //++
732
733   if (mySplitSectionEdgesDone) {
734 #ifdef DEB
735     if(tSPS) {
736       GdumpSHA(EF, (char *) "SplitSectionEdges done : ");
737       if (issplit) cout<<" "<<Splits(EOR,TopAbs_ON).Extent()<<" edges splitON"<<endl;
738       else cout<<" !IsSplit"<<endl;
739     }
740 #endif
741     return;
742   }
743   
744 #ifdef DEB
745   if(tSPS)GdumpSHASTA(EF,TopAbs_ON,"--- SplitSectionEdges ");
746   if(tSPS)cout<<" (hg="<<hg<<"||hsd3d="<<hsd3d<<")="<<cond<<endl;
747 #endif   
748
749   // xpu161198 BUC60382(e3on) SE EOR has all its interferences "on bounds"
750   Standard_Boolean allGb1=Standard_False;   
751   TopoDS_Vertex vf,vl; TopExp::Vertices(TopoDS::Edge(EOR),vf,vl);
752   const TopOpeBRepDS_ListOfInterference& loi = BDS.ShapeInterferences(EOR);
753   TopOpeBRepDS_ListIteratorOfListOfInterference it(loi);
754   for (; it.More(); it.Next()){
755     const Handle(TopOpeBRepDS_Interference)& I = it.Value();
756     TopOpeBRepDS_Kind GT,ST; Standard_Integer G,S; FDS_data(I,GT,G,ST,S);    
757     if (GT == TopOpeBRepDS_POINT) {allGb1=Standard_False; break;}
758     Standard_Integer rkG = BDS.AncestorRank(G);
759     const TopoDS_Vertex& v = TopoDS::Vertex(BDS.Shape(G));
760     if (rkG==rankEF) {
761       allGb1 = (v.IsSame(vf) || v.IsSame(vl));      
762     }
763     else {
764       TopoDS_Shape oov; Standard_Boolean hsdmv = FUN_ds_getoov(v,myDataStructure,oov);
765       if (!hsdmv) allGb1=Standard_False;
766       allGb1 = (oov.IsSame(vf) || oov.IsSame(vl)); 
767     }
768     if (!allGb1) break;
769   } // tki
770   
771
772   Standard_Boolean mke = !cond;
773   mke = mke || !hg; //xpu271098 cto002J2(e9on)
774   mke = mke || allGb1; //xpu161198 BUC60382(e3on)
775   if (mke) {
776     MarkSplit(EOR,TopAbs_ON);
777     TopTools_ListOfShape& LON = ChangeSplit(EOR,TopAbs_ON);
778 #ifdef DEB
779 //    Standard_Integer non = LON.Extent(); // DEB
780 #endif
781
782     TopoDS_Edge newEOR; 
783     FUN_ds_CopyEdge(EOR,newEOR); 
784     Standard_Boolean hasnewEOR=Standard_False;
785     BRep_Builder BB;
786     TopExp_Explorer exv(EOR, TopAbs_VERTEX);
787     for (; exv.More(); exv.Next()){
788       const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current());
789       Standard_Real parv = BRep_Tool::Parameter(v,EOR);
790       Standard_Integer iv = BDS.Shape(v); 
791       Standard_Integer ivref = 0;
792       Standard_Boolean hsd = Standard_False;
793       if (iv != 0) 
794         hsd = myDataStructure->HasSameDomain(v);      
795       if (hsd) 
796         ivref = myDataStructure->SameDomainReference(v);
797       Standard_Boolean setref = hsd && (iv != ivref);
798       TopoDS_Vertex vref = TopoDS::Vertex(BDS.Shape(ivref));
799       if (!setref) 
800         {BB.Add(newEOR,v); FUN_ds_Parameter(newEOR,v,parv); continue;}
801       hasnewEOR = Standard_True;
802       vref.Orientation(v.Orientation());
803       BB.Add(newEOR,vref); 
804       FUN_ds_Parameter(newEOR,vref,parv);
805     }
806     if (hasnewEOR) 
807       LON.Append(newEOR);
808     else           
809       LON.Append(EOR);
810     return;
811   } // mke
812
813   TopTools_ListOfShape LESD1,LESD2; GFindSamDom(EOR,LESD1,LESD2);
814  
815 #ifdef DEB
816   if(tSPS)GdumpSHASTA(EF,TopAbs_ON,"--- SplitSectionEdges ");
817   if(tSPS){ 
818     cout<<" (hg="<<hg<<"||hsd3d="<<hsd3d<<")="<<cond<<endl;
819     GdumpSHA(EOR, (char *) "SplitSectionEdge");
820     cout<<endl;
821     GdumpSAMDOM(LESD1, (char *) "LESD1 : ");
822     GdumpSAMDOM(LESD2, (char *) "LESD2 : ");
823   }
824 #endif
825
826   {
827 #ifdef DEB
828     if (tSPS) debspseon(iE);
829 #endif
830     TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GComUnsh(TopAbs_FACE,TopAbs_FACE);
831     myEdgeReference = EF;   
832     TopOpeBRepBuild_PaveSet PVS(EF);
833
834     GLOBAL_issp = TheON; //++
835     GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
836     GLOBAL_issp = 0; //++
837     
838     // Create an edge builder EDBU
839     TopOpeBRepBuild_PaveClassifier VCL(EF);
840     Standard_Boolean equalpar = PVS.HasEqualParameters();
841     if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
842     TopOpeBRepBuild_EdgeBuilder EDBU;
843     EDBU.InitEdgeBuilder(PVS,VCL);
844     
845     // Build the new edges LEM
846     TopTools_ListOfShape LEM;
847     GEDBUMakeEdges(EF,EDBU,LEM);
848
849     // xpu : 18-03-98 (cto 016 B2)
850     //       splits edges of LEM with internal vertices    
851     TopTools_ListOfShape newLEM; TopTools_ListIteratorOfListOfShape ite(LEM);
852     for (; ite.More(); ite.Next()){
853       const TopoDS_Edge& esp = TopoDS::Edge(ite.Value());
854       TopTools_ListOfShape lspe; Standard_Boolean ok = TopOpeBRepTool_TOOL::SplitE(esp,lspe);
855       Standard_Boolean nonwesp = (!ok) || (lspe.Extent() < 2);
856       if (nonwesp) newLEM.Append(esp); 
857       else         newLEM.Append(lspe);
858     }
859     LEM.Clear(); LEM.Append(newLEM);
860     
861     // connect new edges LEM as split parts (ON,SOLID)
862     MarkSplit(EOR,TopAbs_ON);
863     TopTools_ListOfShape& LON = ChangeSplit(EOR,TopAbs_ON);
864     GCopyList(LEM,LON);
865   }
866
867 //modified by NIZHNY-MZV  Mon Apr 17 16:25:51 2000  TopTools_ListOfShape losOO;
868 //modified by NIZHNY-MZV  Mon Apr 17 16:25:52 2000  if      (rankEF == 1) losOO.Append(GLOBALDS_shape2);
869 //modified by NIZHNY-MZV  Mon Apr 17 16:25:53 2000  else if (rankEF == 2) losOO.Append(GLOBALDS_shape1);
870
871   {
872 #ifdef DEB
873     if (tSPS) debspsein(iE);
874 #endif
875     TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GCutUnsh(TopAbs_FACE,TopAbs_FACE);
876     G = G.CopyPermuted(); // parts (IN,OUT) 3d are constructed
877     myEdgeReference = EF;   
878     TopOpeBRepBuild_PaveSet PVS(EF);
879   
880     GLOBAL_issp = TheIN; //++
881     GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
882     GLOBAL_issp = 0; //++
883
884     // Create an edge builder EDBU
885     TopOpeBRepBuild_PaveClassifier VCL(EF);
886     Standard_Boolean equalpar = PVS.HasEqualParameters();
887     if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
888     TopOpeBRepBuild_EdgeBuilder EDBU;
889     EDBU.InitEdgeBuilder(PVS,VCL);
890     
891     // Build the new edges LEM
892     TopTools_ListOfShape LEMNC;
893     GEDBUMakeEdges(EF,EDBU,LEMNC);
894
895 //modified by NIZHNY-MZV  Mon Apr 17 15:23:28 2000    TopTools_ListOfShape LEM;
896 //modified by NIZHNY-MZV  Mon Apr 17 15:23:16 2000    GKeepShapes(EF,losOO,TopAbs_IN,LEMNC,LEM);
897
898     // connect new edges LEM as split parts (IN,SOLID)
899     MarkSplit(EOR,TopAbs_IN);
900     TopTools_ListOfShape& LINN = ChangeSplit(EOR,TopAbs_IN);
901     GCopyList(LEMNC,LINN);
902   }
903
904   {
905 #ifdef DEB
906     if (tSPS) debspseou(iE);
907 #endif
908     TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GCutUnsh(TopAbs_FACE,TopAbs_FACE);
909     // parts (OUT,IN) 3d are constructed
910     myEdgeReference = EF;   
911     TopOpeBRepBuild_PaveSet PVS(EF);
912
913     GLOBAL_issp = TheOUT; //++    
914     GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
915     GLOBAL_issp = 0; //++    
916     
917     // Create an edge builder EDBU
918     TopOpeBRepBuild_PaveClassifier VCL(EF);
919     Standard_Boolean equalpar = PVS.HasEqualParameters();
920     if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
921     TopOpeBRepBuild_EdgeBuilder EDBU;
922     EDBU.InitEdgeBuilder(PVS,VCL);
923     
924     // Build the new edges LEM
925     TopTools_ListOfShape LEM;
926     GEDBUMakeEdges(EF,EDBU,LEM);
927
928     // connect new edges LEM as split parts (OUT,SOLID)
929     MarkSplit(EOR,TopAbs_OUT);
930     TopTools_ListOfShape& LINN = ChangeSplit(EOR,TopAbs_OUT);
931     GCopyList(LEM,LINN);
932   }
933
934   GLOBAL_hassd=0; //++
935 }
936
937 //=======================================================================
938 //function : Section
939 //purpose  : 
940 //=======================================================================
941 const TopTools_ListOfShape& TopOpeBRepBuild_Builder::Section()
942 {
943   if (mySectionDone) return mySection;
944   mySectionDone = Standard_True;
945   SectionCurves(mySection);
946   SectionEdges(mySection);
947   return mySection;
948 }
949
950 //=======================================================================
951 //function : Section
952 //purpose  : 
953 //=======================================================================
954 void TopOpeBRepBuild_Builder::Section(TopTools_ListOfShape& L)
955 {
956   L = Section();
957 }
958
959 //=======================================================================
960 //function : SectionCurves
961 //purpose  : 
962 //=======================================================================
963 void TopOpeBRepBuild_Builder::SectionCurves(TopTools_ListOfShape& LSE)
964 {
965   TopOpeBRepDS_CurveExplorer cex(myDataStructure->DS());
966   for (; cex.More(); cex.Next()) {
967     Standard_Integer ic = cex.Index();
968     TopTools_ListIteratorOfListOfShape itloe(NewEdges(ic));
969     for(;itloe.More();itloe.Next()) {
970       LSE.Append(itloe.Value());
971     }
972   }
973 }
974
975 //=======================================================================
976 //function : SectionEdges
977 //purpose  : 
978 //=======================================================================
979 void TopOpeBRepBuild_Builder::SectionEdges(TopTools_ListOfShape& LSE)
980 {
981   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
982   Standard_Integer i,nes = BDS.NbSectionEdges();
983   
984   Standard_Integer iskpart = IsKPart();
985   if ( iskpart == 1 ) { // iskole
986     for (i=1;i<=nes;i++ ) {
987       const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
988       // modif fbi 16-09-97: case possible if RemoveSectionEdge was called
989       if(E.IsNull()) 
990         continue;
991       // end modif fbi
992       LSE.Append(E);
993     }
994     return;
995   }
996   
997   SplitSectionEdges();
998   
999   // common of edges of section
1000
1001   TopTools_MapOfShape MOS;
1002
1003   for (i=1;i<=nes;i++) {
1004
1005     const TopoDS_Shape& es = BDS.SectionEdge(i);
1006     // modif fbi 16-09-97: case possible if RemoveSectionEdge was called
1007     if(es.IsNull()) 
1008       continue;
1009     // end modif fbi
1010     Standard_Boolean issplitIN = IsSplit(es,TopAbs_IN);
1011     Standard_Boolean issplitON = IsSplit(es,TopAbs_ON);
1012     TopAbs_State staspl=(issplitON)?TopAbs_ON:(issplitIN)?TopAbs_IN:TopAbs_UNKNOWN;
1013
1014 #ifdef DEB
1015     Standard_Integer iii; Standard_Boolean tSPS = GtraceSPS(es,iii);
1016     if (tSPS) {
1017       GdumpSHA(es, (char *) "--- Section ");
1018       cout<<" splitIN "<<issplitIN<<" "<<Splits(es,TopAbs_IN).Extent()<<endl;
1019       cout<<" splitON "<<issplitON<<" "<<Splits(es,TopAbs_ON).Extent()<<endl;
1020     }
1021 #endif
1022     
1023     if (staspl != TopAbs_UNKNOWN) {
1024       for(TopTools_ListIteratorOfListOfShape it(Splits(es,staspl));it.More();it.Next()) {
1025         const TopoDS_Shape& S = it.Value();
1026         if ( !MOS.Contains(S) ) {
1027           MOS.Add(S);
1028           LSE.Append(S);
1029         }
1030       }
1031     }
1032     else {
1033       Standard_Boolean hasgeom = myDataStructure->HasGeometry(es);
1034       Standard_Boolean hassame = myDataStructure->HasSameDomain(es);
1035       Standard_Boolean take = !(hasgeom || hassame);
1036       if (take) {
1037         if ( !MOS.Contains(es) ) {
1038           MOS.Add(es);
1039           LSE.Append(es);
1040         }
1041       }
1042     }
1043   } // for i [1..nes]
1044 } // SectionEdges
1045
1046 //=======================================================================
1047 //function : FillSecEdgeAncestorMap
1048 //purpose  : 
1049 //=======================================================================
1050
1051 void TopOpeBRepBuild_Builder::FillSecEdgeAncestorMap(const Standard_Integer aShapeRank,
1052                                                      const TopTools_MapOfShape& aMapON,
1053                                                      TopTools_DataMapOfShapeShape& anAncMap)
1054      const
1055 {
1056   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
1057
1058   Standard_Integer i,nse = BDS.NbSectionEdges();
1059   for (i=1; i<=nse; i++) {
1060     const TopoDS_Shape& es = BDS.SectionEdge(i);
1061     if(es.IsNull() || ShapeRank(es) != aShapeRank)
1062       continue;
1063     if (aMapON.Contains(es)) {
1064       anAncMap.Bind(es,es);
1065       continue;
1066     }
1067     TopAbs_State states[3] = {TopAbs_IN, TopAbs_ON, TopAbs_OUT};
1068     for (Standard_Integer j=0; j < 3; j++) {
1069 //      Standard_Boolean isSplit = IsSplit(es,states[j]);
1070       if (IsSplit(es,states[j])) {
1071         TopTools_ListIteratorOfListOfShape it(Splits(es,states[j]));
1072         for(;it.More();it.Next()) {
1073           const TopoDS_Shape& aS = it.Value();
1074           if (aMapON.Contains(aS))
1075             anAncMap.Bind(aS,es);
1076         }
1077       }
1078     }
1079   }
1080 }