1e93f7d47351e77564590930084124767c753e27
[occt.git] / src / TopOpeBRepTool / TopOpeBRepTool_CORRISO.cxx
1 // Created on: 1998-11-25
2 // Created by: Prestataire Xuan PHAM PHU
3 // Copyright (c) 1998-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 <TopOpeBRepTool.hxx>
23 #include <TopOpeBRepTool_TOOL.hxx>
24 #include <TopOpeBRepTool_CORRISO.ixx>
25 #include <TopOpeBRepTool_define.hxx>
26 #include <TopOpeBRepTool_EXPORT.hxx>
27 #include <TopOpeBRepTool_PURGE.hxx>
28 #include <TopOpeBRepTool_2d.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRep_Builder.hxx>
31 #include <TopExp_Explorer.hxx>
32 #include <TopTools_Array1OfShape.hxx>
33 #include <Geom2dAdaptor_Curve.hxx>
34 #include <Geom2d_TrimmedCurve.hxx>
35 #include <GeomAdaptor_Surface.hxx>
36 #include <BndLib_Add2dCurve.hxx>
37 #include <TopoDS.hxx>
38
39 #include <BRep_TEdge.hxx>
40 #include <BRep_ListOfCurveRepresentation.hxx>
41 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
42 #include <BRep_GCurve.hxx>
43
44 #ifdef DEB
45 Standard_IMPORT Standard_Boolean TopOpeBRepTool_GettraceCORRISO();
46 Standard_EXPORT TopTools_IndexedMapOfShape STATIC_PURGE_mapv;
47 Standard_EXPORT TopTools_IndexedMapOfOrientedShape STATIC_PURGE_mapeds;
48 #endif
49
50 static void FUN_RaiseError()
51 {
52 #ifdef DEB
53   Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
54   FUN_REINIT(); 
55 //  if (trc) cout <<"*********failure in CORRISO***********\n";
56 #endif
57 }
58 static void FUN_Raise()
59 {
60 #ifdef DEB
61 //  cout <<"*********failure in CORRISO***********\n";
62 #endif
63 }
64
65 #ifdef DRAW
66 #include <TopOpeBRepTool_DRAW.hxx>
67 #endif
68
69 #define M_FORWARD(sta)  (sta == TopAbs_FORWARD)
70 #define M_REVERSED(sta) (sta == TopAbs_REVERSED)
71 #define M_INTERNAL(sta) (sta == TopAbs_INTERNAL)
72 #define M_EXTERNAL(sta) (sta == TopAbs_EXTERNAL)
73
74 //=======================================================================
75 //function : TopOpeBRepTool_CORRISO
76 //purpose  : 
77 //=======================================================================
78
79 TopOpeBRepTool_CORRISO::TopOpeBRepTool_CORRISO()
80 {
81 }
82
83 //=======================================================================
84 //function : TopOpeBRepTool_CORRISO
85 //purpose  : 
86 //=======================================================================
87
88 TopOpeBRepTool_CORRISO::TopOpeBRepTool_CORRISO(const TopoDS_Face& Fref)
89 {
90   myFref = Fref;
91
92   FUN_tool_closedS(myFref,myUclosed,myUper,myVclosed,myVper);
93
94   const Handle(Geom_Surface)& SU = BRep_Tool::Surface(myFref);
95   myGAS = GeomAdaptor_Surface(SU);
96 }
97
98 //=======================================================================
99 //function : Fref
100 //purpose  : 
101 //=======================================================================
102
103 const TopoDS_Face& TopOpeBRepTool_CORRISO::Fref() const
104 {
105   return myFref;
106 }
107
108 //=======================================================================
109 //function : GASref
110 //purpose  : 
111 //=======================================================================
112
113 const GeomAdaptor_Surface& TopOpeBRepTool_CORRISO::GASref() const 
114 {
115   return myGAS;
116 }
117
118
119 //=======================================================================
120 //function : Refclosed
121 //purpose  : 
122 //=======================================================================
123
124 Standard_Boolean TopOpeBRepTool_CORRISO::Refclosed(const Standard_Integer x, Standard_Real& xperiod) const
125 {
126   if (x==1) {xperiod = myUper; return myUclosed;}
127   if (x==2) {xperiod = myVper; return myVclosed;}
128   return Standard_False;
129 }
130
131
132
133 //=======================================================================
134 //function : Init
135 //purpose  : 
136 //=======================================================================
137
138 Standard_Boolean TopOpeBRepTool_CORRISO::Init(const TopoDS_Shape& S)
139 {
140 #ifdef DRAW  
141   Standard_Integer ie = 0;
142   Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
143   Standard_Boolean INIT = Standard_True;
144   if (INIT) FUN_REINIT();
145 #endif
146
147   myERep2d.Clear();
148   myEds.Clear();
149   myVEds.Clear();
150
151   if (S.IsNull()) return Standard_False;
152   myS = S;
153
154   TopExp_Explorer ex(S, TopAbs_EDGE);
155   for (; ex.More(); ex.Next()){
156     const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
157 #ifdef DEB
158     Standard_Integer iE = STATIC_PURGE_mapeds.Add(E);
159 #ifdef DRAW
160     if (trc) {TCollection_AsciiString aa = TCollection_AsciiString("e"); FUN_tool_draw(aa,E,iE);}
161 #endif
162 #endif
163     // myEds :
164     myEds.Append(E);
165
166     // myERep2d :
167 //    Standard_Real f,l,tol; Handle(Geom2d_Curve) PC = FC2D_CurveOnSurface(E,myFref,f,l,tol);
168     Handle(Geom2d_Curve) PC; Standard_Real f,l,tol;
169     Standard_Boolean hasold = FC2D_HasOldCurveOnSurface(E,myFref,PC);
170     PC = FC2D_EditableCurveOnSurface(E,myFref,f,l,tol);
171     if (!hasold) FC2D_AddNewCurveOnSurface(PC,E,myFref,f,l,tol);
172     if (PC.IsNull()) return Standard_False;
173     TopOpeBRepTool_C2DF C2DF(PC,f,l,tol,myFref);
174     myERep2d.Bind(E,C2DF);
175         
176     // myVEds :
177     TopExp_Explorer exv(E, TopAbs_VERTEX);
178     for (; exv.More(); exv.Next()){
179       const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current());   
180 #ifdef DEB
181       Standard_Integer iv = STATIC_PURGE_mapv.Add(v);
182 #ifdef DRAW
183       if (trc) {TCollection_AsciiString bb = TCollection_AsciiString("v"); FUN_tool_draw(bb,v,iv);}
184 #endif      
185 #endif
186       Standard_Boolean isb = myVEds.IsBound(v);
187       if (isb) myVEds.ChangeFind(v).Append(E);
188       else     {TopTools_ListOfShape loe; loe.Append(E); myVEds.Bind(v,loe);}
189     }//exv
190   }
191   return Standard_True;
192 }
193
194 //=======================================================================
195 //function : S
196 //purpose  : 
197 //=======================================================================
198
199 const TopoDS_Shape& TopOpeBRepTool_CORRISO::S() const 
200 {
201   return myS;
202 }
203
204 //=======================================================================
205 //function : Eds
206 //purpose  : 
207 //=======================================================================
208
209 const TopTools_ListOfShape& TopOpeBRepTool_CORRISO::Eds() const 
210 {
211   return myEds;
212 }
213
214 //=======================================================================
215 //function : UVRep
216 //purpose  : 
217 //=======================================================================
218
219 Standard_Boolean TopOpeBRepTool_CORRISO::UVRep(const TopoDS_Edge& E, TopOpeBRepTool_C2DF& C2DF) const
220 {
221   Standard_Boolean isb = myERep2d.IsBound(E);
222   if (!isb) return Standard_False;
223   
224   C2DF = myERep2d.Find(E);
225   return Standard_True;
226 }
227
228 //=======================================================================
229 //function : SetUVRep
230 //purpose  : 
231 //=======================================================================
232
233 Standard_Boolean TopOpeBRepTool_CORRISO::SetUVRep(const TopoDS_Edge& E, const TopOpeBRepTool_C2DF& C2DF)
234 {
235   Standard_Boolean isb = myERep2d.IsBound(E);
236   if (!isb) return Standard_False;
237   
238   myERep2d.ChangeFind(E) = C2DF;
239   return Standard_True;  
240 }
241
242 //=======================================================================
243 //function : Connexity
244 //purpose  : 
245 //=======================================================================
246
247 Standard_Boolean TopOpeBRepTool_CORRISO::Connexity(const TopoDS_Vertex& V, TopTools_ListOfShape& Eds) const
248 {
249   Standard_Boolean isb = myVEds.IsBound(V);
250   if (!isb) return Standard_False;
251   
252   Eds = myVEds.Find(V);
253   return Standard_True;
254 }
255
256 //=======================================================================
257 //function : SetConnexity
258 //purpose  : 
259 //=======================================================================
260
261 Standard_Boolean TopOpeBRepTool_CORRISO::SetConnexity(const TopoDS_Vertex& V, const TopTools_ListOfShape& Eds) 
262 {
263   Standard_Boolean isb = myVEds.IsBound(V);
264   if (!isb) return Standard_False;
265   
266   myVEds.ChangeFind(V) = Eds;
267   return Standard_True;
268 }
269
270 //=======================================================================
271 //function : UVClosed
272 //purpose  : 
273 //=======================================================================
274
275 Standard_Boolean TopOpeBRepTool_CORRISO::UVClosed() const
276 {  
277 #ifdef DEB
278   Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
279   if (trc) cout<<"** UVClosed"<<endl;
280 #endif
281   TopTools_DataMapOfOrientedShapeInteger lfyE; Standard_Integer nfybounds=3; Standard_Boolean stopatfirst = Standard_True;
282   Standard_Boolean foundfaulty = EdgesWithFaultyUV(myEds,nfybounds,lfyE,stopatfirst);
283   return !foundfaulty;
284 }
285
286 //=======================================================================
287 //function : Tol
288 //purpose  : 
289 //=======================================================================
290
291 Standard_Real TopOpeBRepTool_CORRISO::Tol(const Standard_Integer I, const Standard_Real tol3d) const
292 {
293   Standard_Real tol = (I==1) ? myGAS.UResolution(tol3d) : myGAS.VResolution(tol3d);
294   return tol;
295 }
296
297 //static Standard_Real FUN_getx(const TopoDS_Edge& E,
298 static Standard_Real FUN_getx(const TopoDS_Edge& ,
299                               const TopOpeBRepTool_C2DF& c2df,
300                               const Standard_Boolean uiso,
301                               const Standard_Real par)
302 { // prequesitory : E is uviso
303   gp_Pnt2d uv = TopOpeBRepTool_TOOL::UVF(par,c2df);
304   Standard_Real x = (uiso) ? uv.Y() : uv.X();
305   return x;
306 }
307
308 /*static void FUN_getinfsupx(const TopoDS_Edge& E, const TopOpeBRepTool_C2DF& c2df,
309                            const Standard_Boolean uiso,
310                            Standard_Real& xf, Standard_Real& xl)
311 { // prequesitory : E is uviso
312   // 2drep(E) describes [xf,xl]*[yf,yl];
313   // if (uiso) x = upar
314   // if (viso) x = vpar
315   Standard_Real f,l; FUN_tool_bounds(E, f,l);
316   Standard_Real parf = FUN_getx(E,c2df,uiso, f);
317   Standard_Real parl = FUN_getx(E,c2df,uiso, l);
318   if (parf < parl) {xf = parf; xl = parl;}
319   else             {xf = parl; xl = parf;}
320 }*/
321
322 #ifdef DEB
323 static Standard_Boolean FUN_isonOcE(const TopOpeBRepTool_CORRISO CO, const TopoDS_Edge& cE)
324 {
325   TopTools_Array1OfShape vcE(1,2); TopOpeBRepTool_TOOL::Vertices(cE,vcE); 
326   TopAbs_Orientation ocE = cE.Orientation(); 
327   
328   Standard_Real tttolcE = BRep_Tool::Tolerance(cE);
329   Standard_Real tttuvcE = Max(CO.Tol(1,tttolcE),CO.Tol(2,tttolcE));
330   TopOpeBRepTool_C2DF cE2d; Standard_Boolean isb = CO.UVRep(cE,cE2d);
331   if (!isb) return Standard_False; // NYIRAISE
332   
333   // isonOcE2d :
334   Standard_Boolean isonOcE2d = Standard_False;
335   {
336     // OcE (closing edge with complemented orientation):
337     TopAbs_Orientation oOcE = TopAbs::Complement(ocE);
338     TopoDS_Shape aLocalShape = cE.Oriented(oOcE);
339     TopoDS_Edge OcE = TopoDS::Edge(aLocalShape);
340 //    TopoDS_Edge OcE = TopoDS::Edge(cE.Oriented(oOcE));
341     TopTools_Array1OfShape vOcE(1,2); TopOpeBRepTool_TOOL::Vertices(OcE,vOcE); 
342     Standard_Real tttolOcE = BRep_Tool::Tolerance(OcE);
343     Standard_Real tttuvOcE = Max(CO.Tol(1,tttolOcE),CO.Tol(2,tttolOcE));
344     TopOpeBRepTool_C2DF OcE2d; Standard_Boolean isOb = CO.UVRep(OcE,OcE2d);
345     if (!isOb) return Standard_False; // NYIRAISE
346     
347 #ifdef DEB
348     const TopoDS_Vertex& vce1 =
349 #endif
350                       TopoDS::Vertex(vcE(1)); 
351     Standard_Real parvce1 = TopOpeBRepTool_TOOL::ParE(1,cE);   gp_Pnt2d UVvce1 = TopOpeBRepTool_TOOL::UVF(parvce1,cE2d);
352 #ifdef DEB
353     const TopoDS_Vertex& vOce2 =
354 #endif
355                        TopoDS::Vertex(vOcE(2)); 
356     Standard_Real parvOcE2 = TopOpeBRepTool_TOOL::ParE(2,OcE); gp_Pnt2d UVvOcE2 = TopOpeBRepTool_TOOL::UVF(parvOcE2,OcE2d);
357     Standard_Real tol = Max(tttuvcE,tttuvOcE);
358     isonOcE2d = (UVvce1.Distance(UVvOcE2) < tol);
359   }
360   return isonOcE2d;
361 }
362 #endif
363
364 //=======================================================================
365 //function : PurgeFyClosingE
366 //purpose  : 
367 //=======================================================================
368
369 Standard_Boolean TopOpeBRepTool_CORRISO::PurgeFyClosingE(const TopTools_ListOfShape& ClEds, TopTools_ListOfShape& fyClEds) const
370 {
371   fyClEds.Clear();
372 #ifdef DEB
373   Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
374   if (trc) cout<<"* PurgeFyClosingE"<<endl;
375 #endif
376 //  Standard_Real xperiod = myUclosed ? myUper : myVper; 
377   Standard_Real tttol = 1.e-8;
378   Standard_Real tttolS = BRep_Tool::Tolerance(myFref);
379   Standard_Real tolu = Tol(1,tttolS), tolv = Tol(2,tttolS);
380   Standard_Real tttuvF = Max(tolu,tolv);
381
382   TopTools_IndexedMapOfOrientedShape mapcl;
383   TopTools_ListIteratorOfListOfShape itce(ClEds);
384   for (; itce.More(); itce.Next()) mapcl.Add(itce.Value());
385
386   //* one closing edge should be removed     
387   itce.Initialize(ClEds);
388   TopTools_DataMapOfOrientedShapeInteger fyceds; Standard_Boolean found = EdgesWithFaultyUV(ClEds,3,fyceds);
389   if (!found) return Standard_False;  
390
391   if      (fyceds.Extent() == 1) {// ivf == 3 : cto016G*
392     TopTools_DataMapOfOrientedShapeInteger fyeds;
393
394     EdgesWithFaultyUV(myEds,3,fyeds);
395     Standard_Integer nfy = fyeds.Extent();
396
397     TopTools_DataMapIteratorOfDataMapOfOrientedShapeInteger itm(fyceds);
398     const TopoDS_Edge& cE = TopoDS::Edge(itm.Key());
399
400     TopAbs_Orientation OocE = TopAbs::Complement(cE.Orientation());
401     Standard_Boolean isoncE = mapcl.Contains(cE.Oriented(OocE));
402     if (isoncE) {
403       TopTools_Array1OfShape vcE(1,2); TopOpeBRepTool_TOOL::Vertices(cE,vcE); 
404       TopAbs_Orientation ocE = cE.Orientation();       
405       Standard_Real tttolcE = BRep_Tool::Tolerance(cE);
406       Standard_Real tttuvcE = Max(Tol(1,tttolcE),Tol(2,tttolcE));
407       TopOpeBRepTool_C2DF cE2d; Standard_Boolean isb = UVRep(cE,cE2d);
408       if (!isb) return Standard_False; // NYIRAISE
409   
410       // isonOcE2d :
411       // OcE (closing edge with complemented orientation):
412       TopAbs_Orientation oOcE = TopAbs::Complement(ocE);
413       TopoDS_Shape alocalShape = cE.Oriented(oOcE);     
414       TopoDS_Edge OcE = TopoDS::Edge(alocalShape);
415 //      TopoDS_Edge OcE = TopoDS::Edge(cE.Oriented(oOcE));
416       TopTools_Array1OfShape vOcE(1,2); TopOpeBRepTool_TOOL::Vertices(OcE,vOcE); 
417       Standard_Real tttolOcE = BRep_Tool::Tolerance(OcE);
418       Standard_Real tttuvOcE = Max(Tol(1,tttolOcE),Tol(2,tttolOcE));
419       TopOpeBRepTool_C2DF OcE2d; Standard_Boolean isOb = UVRep(OcE,OcE2d);
420       if (!isOb) return Standard_False; // NYIRAISE
421       
422 #ifdef DEB
423       const TopoDS_Vertex& vce1 =
424 #endif
425                          TopoDS::Vertex(vcE(1)); 
426       Standard_Real parvce1 = TopOpeBRepTool_TOOL::ParE(1,cE);   gp_Pnt2d UVvce1 = TopOpeBRepTool_TOOL::UVF(parvce1,cE2d);
427 #ifdef DEB
428       const TopoDS_Vertex& vOce2 =
429 #endif
430                          TopoDS::Vertex(vOcE(2)); 
431       Standard_Real parvOcE2 = TopOpeBRepTool_TOOL::ParE(2,OcE); gp_Pnt2d UVvOcE2 = TopOpeBRepTool_TOOL::UVF(parvOcE2,OcE2d);
432       Standard_Real tol = Max(tttuvcE,tttuvOcE);
433       isoncE = (UVvce1.Distance(UVvOcE2) < tol);
434       if (isoncE && (nfy != 1)) {// cto009L2
435         return Standard_False; 
436       }
437     }
438
439     Standard_Integer ivf = itm.Value();
440     if (ivf == 3) {
441       fyClEds.Append(cE); 
442       return Standard_True;
443     }
444   }
445   else if (fyceds.Extent() > 1) {// ivf == 1,2 : cto016E*
446     // if {edges of fyceds} describe a closing edge with its first and last 
447     // uvbounds non connexed -> we do remove these edges
448     Standard_Boolean hasinit=Standard_False; Standard_Boolean isou=Standard_False,isov=Standard_False;
449     gp_Pnt2d o2d; gp_Dir2d d2d; 
450     Standard_Real xinf=1.e7,  xsup=-1.e7; // faulty inf and sup bounds
451     Standard_Boolean infdef=Standard_False, supdef=Standard_False;
452     TopTools_DataMapIteratorOfDataMapOfOrientedShapeInteger itm(fyceds);
453     for (; itm.More(); itm.Next()){
454       const TopoDS_Edge& cE = TopoDS::Edge(itm.Key());
455       TopOpeBRepTool_C2DF c2df; Standard_Boolean isb = UVRep(cE,c2df);
456       if (!isb) return Standard_False; // NYIRAISE
457
458       Standard_Integer ivf = itm.Value();
459       Standard_Boolean isoux,isovx; gp_Pnt2d o2dx; gp_Dir2d d2dx;
460       Standard_Boolean uvisox = TopOpeBRepTool_TOOL::UVISO(c2df,isoux,isovx, d2dx, o2dx);
461       if (!uvisox) return Standard_False;
462       
463       if (hasinit) {
464         Standard_Boolean onsamline = (isou && isoux) || (isov && isovx);
465         if (!onsamline) return Standard_False;
466       }
467       if (!hasinit) {
468         isou=isoux; isov=isovx; 
469         o2d=o2dx; d2d=d2dx;
470         hasinit = Standard_True;
471       }
472       else {
473         Standard_Boolean onsamline = Standard_False;
474         if (isou && isoux) {
475           Standard_Real du = o2d.X()-o2dx.X();
476           onsamline = (Abs(du) < tolu);
477         }
478         if (isov && isovx) {
479           Standard_Real dv = o2d.Y()-o2dx.Y();
480           onsamline = (Abs(dv) < tolv);
481         }
482         if (!onsamline) return Standard_False;
483       }        
484       for (Standard_Integer i = 1; i <=2; i++) {
485         Standard_Real pari = TopOpeBRepTool_TOOL::ParE(i,cE);
486         Standard_Real xi = FUN_getx(cE,c2df,isou,pari);
487         Standard_Boolean vifaulty = (ivf == i || ivf == 3);     
488         Standard_Boolean inff = (xi < xinf);
489         Standard_Boolean supl = (xi > xsup);
490 //      if (inff) xinf = (ivf == i || ivf == 3) ? xi : 1.e7;
491 //      if (supl) xsup = (ivf == i || ivf == 3) ? xi : -1.e7;
492         if (inff) {xinf = xi; infdef = vifaulty;}
493         if (supl) {xsup = xi; supdef = vifaulty;}
494       }      
495       fyClEds.Append(cE);
496     }//itm
497     Standard_Boolean toremove = infdef && supdef; // ie infx,supx are not "uv-connexed"
498     if (!toremove) fyClEds.Clear();
499   }
500   if (!fyClEds.IsEmpty()) return Standard_True; // keeping only one closing edge
501
502   //* the 2 closing edges have they 2drep "confunded"
503   itce.Initialize(ClEds);
504   for (; itce.More(); itce.Next()){
505     // cE : 
506     const TopoDS_Edge& cE = TopoDS::Edge(itce.Value());
507     TopTools_Array1OfShape vcE(1,2); TopOpeBRepTool_TOOL::Vertices(cE,vcE); 
508     TopAbs_Orientation ocE = cE.Orientation(); 
509
510     Standard_Real tttolcE = BRep_Tool::Tolerance(cE);
511     Standard_Real tttuvcE = Max(Tol(1,tttolcE),Tol(2,tttolcE));
512     TopOpeBRepTool_C2DF cE2d; Standard_Boolean isb = UVRep(cE,cE2d);
513     if (!isb) return Standard_False; // NYIRAISE
514 #ifdef DEB
515     Standard_Integer icE = STATIC_PURGE_mapeds.Add(cE);
516     if (trc) cout<<"? e"<<icE<<" :"<<endl;
517 #endif
518
519     // isonOcE2d :
520     Standard_Boolean isonOcE2d = Standard_False;
521     {
522       // OcE (closing edge with complemented orientation):
523       TopAbs_Orientation oOcE = TopAbs::Complement(ocE);
524       TopoDS_Shape aLocalShape = cE.Oriented(oOcE);
525       TopoDS_Edge OcE = TopoDS::Edge(aLocalShape);
526 //      TopoDS_Edge OcE = TopoDS::Edge(cE.Oriented(oOcE));
527       TopTools_Array1OfShape vOcE(1,2); TopOpeBRepTool_TOOL::Vertices(OcE,vOcE); 
528       Standard_Boolean hasOcE = mapcl.Contains(OcE);
529       if (!hasOcE) continue; // closing edge appears twice
530       Standard_Real tttolOcE = BRep_Tool::Tolerance(OcE);
531       Standard_Real tttuvOcE = Max(Tol(1,tttolOcE),Tol(2,tttolOcE));
532       TopOpeBRepTool_C2DF OcE2d; Standard_Boolean isOb = UVRep(OcE,OcE2d);
533       if (!isOb) return Standard_False; // NYIRAISE
534 #ifdef DEB 
535       const TopoDS_Vertex& vce1 = TopoDS::Vertex(vcE(1));
536 #endif 
537       Standard_Real parvce1 = TopOpeBRepTool_TOOL::ParE(1,cE);   gp_Pnt2d UVvce1 = TopOpeBRepTool_TOOL::UVF(parvce1,cE2d);
538 #ifdef DEB
539       const TopoDS_Vertex& vOce2 =
540 #endif
541                          TopoDS::Vertex(vOcE(2)); 
542       Standard_Real parvOcE2 = TopOpeBRepTool_TOOL::ParE(2,OcE); gp_Pnt2d UVvOcE2 = TopOpeBRepTool_TOOL::UVF(parvOcE2,OcE2d);
543       Standard_Real tol = Max(tttuvcE,tttuvOcE);
544       isonOcE2d = (UVvce1.Distance(UVvOcE2) < tol);
545     }
546     if (!isonOcE2d) {
547 #ifdef DEB
548       if (trc) cout<<"-> valid edge"<<endl;
549 #endif
550       continue;
551     }
552
553     Standard_Integer nvcEok = 0;   
554     for (Standard_Integer ivce = 1; ivce <=2; ivce++) {
555       // <vce> (boundary of <cE>):   
556       const TopoDS_Vertex& vce = TopoDS::Vertex(vcE(ivce)); 
557       TopTools_ListOfShape loe; isb = Connexity(vce,loe);
558
559       if (!isb) return Standard_False; // NYIRAISE
560
561       Standard_Real parvce = TopOpeBRepTool_TOOL::ParE(ivce,cE); gp_Pnt2d UVvce = TopOpeBRepTool_TOOL::UVF(parvce,cE2d);
562 #ifdef DEB
563       // recall in one wire, there are 2 vertices for one non-degenerated closing edge
564       Standard_Integer ivmapv = STATIC_PURGE_mapv.Add(vce);
565       if (trc) {cout<<" connexity for v("<<ivce<<")=v"<<ivmapv;FUN_tool_trace(UVvce);}
566 #ifdef DRAW     
567       if (trc) {TCollection_AsciiString bb("uv_");bb += TCollection_AsciiString(ivmapv);FUN_tool_draw(bb,UVvce);}
568 #endif
569 #endif        
570       Standard_Real tttolvce = BRep_Tool::Tolerance(vce); 
571       Standard_Real tttuvvce = Max(Tol(1,tttolvce),Tol(2,tttolvce));
572
573       Standard_Boolean vceok = Standard_False;
574       for (TopTools_ListIteratorOfListOfShape ite(loe); ite.More(); ite.Next()) {
575         const TopoDS_Edge& E = TopoDS::Edge(ite.Value());
576
577 #ifdef DEB
578         Standard_Integer iE = STATIC_PURGE_mapeds.Add(E);
579         if (trc) {cout<<"    : on e"<<iE<<endl;}
580 #endif
581 //      if (E.IsSame(cE)) continue;
582         if (mapcl.Contains(E)) continue; // do NOT check connexity on closing edges 
583                                           // xpu090399 cto016E1
584
585         TopOpeBRepTool_C2DF E2d; Standard_Boolean isb = UVRep(E,E2d);
586         if (!isb) return Standard_False; // NYIRAISE
587         
588         Standard_Real tttolE = BRep_Tool::Tolerance(E);
589         Standard_Real tttuvE = Max(Tol(1,tttolE),Tol(2,tttolE));
590         
591         TopTools_Array1OfShape vE(1,2); TopOpeBRepTool_TOOL::Vertices(E,vE);
592         for (Standard_Integer ive = 1; ive <=2; ive++) {         
593
594           const TopoDS_Vertex& ve = TopoDS::Vertex(vE(ive));              
595           Standard_Boolean samev = ve.IsSame(vce);
596           if (!samev) continue; 
597           Standard_Real parve = TopOpeBRepTool_TOOL::ParE(ive,E); gp_Pnt2d UVve = TopOpeBRepTool_TOOL::UVF(parve,E2d);
598 #ifdef DEB
599           if (trc) {cout<<"    ve("<<ive<<")";FUN_tool_trace(UVve);}
600 #endif 
601           if (ive == ivce) continue; // vertex FORWARD connexed to REVERSED one
602           Standard_Real tttolve = BRep_Tool::Tolerance(ve);
603           Standard_Real tttuvve = Max(Tol(1,tttolve),Tol(2,tttolve));
604           
605           tttol = Max(tttol,Max(tttuvF,Max(tttuvE,Max(tttuvcE,Max(tttuvve,tttuvvce)))));
606 //        Standard_Real dd = myUclosed ? (UVve.X()-UVvce.X()) : (UVve.Y()-UVvce.Y());
607 //        Standard_Boolean xok = (Abs(dd)<tttol) || (Abs(Abs(dd)-xperiod)<tttol);
608 //        if (xok) {
609           Standard_Real dd = UVve.Distance(UVvce);
610           Standard_Boolean sameuv = (dd < tttol);
611           if (myUclosed) {          
612             Standard_Real xperiod = myUper;
613             dd = (UVve.X()-UVvce.X());
614             sameuv = sameuv || (Abs(Abs(dd)-xperiod)<tttol);
615           }
616           if (myVclosed) {          
617             Standard_Real xperiod = myVper;
618             dd = (UVve.Y()-UVvce.Y());
619             sameuv = sameuv || (Abs(Abs(dd)-xperiod)<tttol);
620           }
621           if (sameuv) {
622             vceok = Standard_True;
623 #ifdef DEB
624             if (trc){cout<<" connexity->ok"<<endl;}
625 #endif  
626           }
627           break;
628         } // ive=1..2
629         if (vceok) break;       
630       } //ite(loe)     
631  
632 #ifdef DEB
633       if (trc && !vceok) {cout<<" connexity->KO"<<endl;}        
634 #endif     
635       if (vceok) nvcEok++;
636     }// ivce=1..2
637
638     Standard_Boolean isfycE = (nvcEok == 0); // each bound is not connexed to any non-closed edge
639
640 #ifdef DEB 
641     if (trc) 
642       {if (isfycE) cout<<"-> faulty edge"<<endl; 
643        else        cout<<"-> valid edge"<<endl;}
644 #endif 
645     if (isfycE) fyClEds.Append(cE);
646   }//itce
647   return (!fyClEds.IsEmpty());
648 }
649
650 #define SPLITEDGE (0)
651 #define INCREASE  (1)
652 #define DECREASE (-1)
653
654 static Standard_Integer FUN_tool_recadre(const Standard_Real minx,const Standard_Real maxx,
655                             const Standard_Real xfirst,const Standard_Real xlast,const Standard_Real tolx,
656                             Standard_Boolean& maxsup)
657 {
658   Standard_Integer recadre = 10; // INIT  
659   Standard_Boolean maxinf = (maxx < xfirst+tolx);    // permissive
660   Standard_Boolean mininf   = (minx   < xfirst-tolx);// 
661   maxsup = (maxx > xlast+tolx);     // 
662   Standard_Boolean minsup   = (minx   > xlast-tolx); // permissive
663   Standard_Boolean maxok  = (xfirst-tolx < maxx) && (maxx < xlast+tolx);// permissive
664   Standard_Boolean minok    = (xfirst-tolx < minx) && (minx < xlast+tolx);    // permissive
665   
666   if      (maxinf)          recadre = INCREASE;
667   else if (minsup)          recadre = DECREASE;
668   else if (mininf && maxok) recadre = SPLITEDGE;
669   else if (minok && maxsup) recadre = SPLITEDGE;
670   return recadre;
671 }
672
673 //=======================================================================
674 //function : EdgeOUTofBoundsUV
675 //purpose  : 
676 //=======================================================================
677
678 Standard_Integer TopOpeBRepTool_CORRISO::EdgeOUTofBoundsUV(const TopoDS_Edge& E, const Standard_Boolean onU, const Standard_Real tolx, 
679                                               Standard_Real& parspE) const 
680 {
681   Standard_Integer recadre = 10; parspE = -1.e7; // INIT
682   Standard_Integer isb = myERep2d.IsBound(E);
683   if (!isb) return Standard_False;
684   
685   const TopOpeBRepTool_C2DF& C2DF = myERep2d.Find(E);
686   Standard_Real f,l,tol; const Handle(Geom2d_Curve)& PC = C2DF.PC(f,l,tol);
687  
688   Standard_Real xfirst  = onU ? myGAS.FirstUParameter() : myGAS.FirstVParameter();
689   Standard_Real xlast   = onU ? myGAS.LastUParameter() : myGAS.LastVParameter(); // xlast=xfirst+xperiod
690   Standard_Real xperiod = onU ? myUper : myVper;
691
692   Standard_Boolean isou,isov; gp_Pnt2d o2d; gp_Dir2d d2d; 
693   Standard_Boolean iso = TopOpeBRepTool_TOOL::UVISO(PC,isou,isov,d2d,o2d);
694
695   if (iso) { // 2drep(E,myFref) is an ISO
696              // -------------------------
697     Standard_Boolean inX = (onU && isou) || ((!onU) && isov);
698     if (inX) {
699       // faulty u-iso : upar out of ubound
700       Standard_Real xpar = onU ? o2d.X() : o2d.Y(); 
701       Standard_Boolean toosmall = (xpar < xfirst-tolx); 
702       Standard_Boolean tobig = (xpar > xfirst+xperiod+tolx);
703       
704       if (toosmall) recadre = INCREASE;
705       if (tobig)    recadre = DECREASE;
706       return recadre;
707     } // inX
708     Standard_Boolean inY = (onU && isov) || ((!onU) && isou); // inY = !inX
709     if (inY) {
710       // faulty u-iso : vpar describes (minv,maxv) out of vbounds
711       // PC describes [minx,maxx] in x-space 
712       // recadre = INCREASE : maxx < 0.
713       //           DECREASE : minx > 2PI
714       //           SPLITEDGE : minx<0.<maxx || minx<2PI<maxx
715       Standard_Real d2ddir = onU? d2d.Y(): d2d.X();
716       Standard_Boolean reverse = (d2ddir < 0.); Standard_Real xfactor = reverse? -1.: 1.;
717       Standard_Real max = reverse? f: l;
718       Standard_Real min   = reverse? l: f;
719       gp_Pnt2d maxuv = PC->Value(max); 
720       gp_Pnt2d minuv = PC->Value(min); 
721
722       Standard_Real maxx = onU? maxuv.X(): maxuv.Y();
723       Standard_Real minx = onU? minuv.X(): minuv.Y();
724
725       Standard_Boolean maxsup;
726       recadre = FUN_tool_recadre(minx,maxx,xfirst,xlast,tolx,
727                                  maxsup);      
728       if (recadre == SPLITEDGE) {
729         Standard_Real xbound = maxsup? xperiod: 0.;
730         parspE = max - xfactor*(maxx-xbound);
731       }      
732       return recadre;
733     } // inY
734   } // iso
735   else { // 2drep(E, myFref) is NOT an iso
736          // ------------------------------
737     Bnd_Box2d Bn2d;
738     Geom2dAdaptor_Curve GC2d(PC,f,l);
739     Standard_Real tolE = BRep_Tool::Tolerance(E);
740     Standard_Real toladd = Max(tolE,tol);
741     BndLib_Add2dCurve::Add(GC2d,toladd,Bn2d);
742     Standard_Real umin,vmin,umax,vmax; Bn2d.Get(umin,vmin,umax,vmax);
743     Standard_Real xmin = onU ? umin : vmin;
744     Standard_Real xmax = onU ? umax : vmax;
745     Standard_Boolean maxsup;
746     recadre = FUN_tool_recadre(xmin,xmax,xfirst,xlast,tolx,
747                                maxsup);  
748     if (recadre == SPLITEDGE) {
749       // ================================================================
750       //NYIxpu271198 : intersection PC avec xiso (x= maxsup? xperiod: 0.)
751       // ================================================================
752       return 10;
753     }  
754     return recadre;
755   }  
756   return recadre;
757 }
758
759 //=======================================================================
760 //function : EdgesOUTofBoundsUV
761 //purpose  : 
762 //=======================================================================
763
764 Standard_Boolean TopOpeBRepTool_CORRISO::EdgesOUTofBoundsUV(const TopTools_ListOfShape& EdsToCheck, const Standard_Boolean onU, const Standard_Real tolx, 
765                                                TopTools_DataMapOfOrientedShapeInteger & FyEds) const 
766 {
767   FyEds.Clear();
768   TopTools_ListIteratorOfListOfShape it(EdsToCheck);
769   for (; it.More(); it.Next()){
770     const TopoDS_Edge& E = TopoDS::Edge(it.Value());
771     Standard_Real sspar = -1.e7;
772     Standard_Integer recadre = EdgeOUTofBoundsUV(E,onU,tolx,sspar);
773     if (recadre == SPLITEDGE) FUN_Raise();
774     if (recadre == INCREASE)  FyEds.Bind(E,1);
775     if (recadre == DECREASE)  FyEds.Bind(E,-1);
776   }
777   return (!FyEds.IsEmpty());
778 }
779
780
781 //=======================================================================
782 //function : EdgeWithFaultyUV
783 //purpose  : 
784 //=======================================================================
785
786 Standard_Boolean TopOpeBRepTool_CORRISO::EdgeWithFaultyUV(const TopoDS_Edge& E, Standard_Integer& Ivfaulty) const 
787 {
788 #ifdef DEB
789   Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
790   Standard_Integer iE = STATIC_PURGE_mapeds.Add(E);
791   if (trc) cout<<"? e"<<iE<<" :"<<endl;
792 #endif
793   Ivfaulty = 0;
794   Standard_Real tttol = 1.e-8;
795   Standard_Real tttolF = BRep_Tool::Tolerance(TopoDS::Face(myFref));
796   Standard_Real tttuvF = Max(Tol(1,tttolF),Tol(2,tttolF));
797   Standard_Real tttolE = BRep_Tool::Tolerance(E);
798   Standard_Real tttuvE = Max(Tol(1,tttolE),Tol(2,tttolE));
799
800   TopAbs_Orientation oE = E.Orientation();
801   if (M_INTERNAL(oE) || M_EXTERNAL(oE)) return Standard_False;
802     
803   TopTools_Array1OfShape vEs(1,2); TopOpeBRepTool_TOOL::Vertices(E, vEs);
804   Standard_Boolean closed = vEs(1).IsSame(vEs(2));
805   if (closed) {
806 #ifdef DEB 
807     if (trc) {cout<<"closed -> valid edge"<<endl;}
808 #endif     
809     return Standard_False; // closed edge is assumed valid
810   }
811   
812   Standard_Integer nfyv = 0;
813   for (Standard_Integer ivE = 1; ivE <=2; ivE++) {
814     
815     // <vE> (boundary of <E>):      
816     const TopoDS_Vertex& vE = TopoDS::Vertex(vEs(ivE)); 
817     Standard_Real parvE = TopOpeBRepTool_TOOL::ParE(ivE,E);
818     TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = UVRep(E,C2DF);
819     if (!isb) return Standard_False; //NYIRAISE
820     gp_Pnt2d UVvE = TopOpeBRepTool_TOOL::UVF(parvE,C2DF);
821 #ifdef DEB
822       // recall in one wire, there are 2 vertices for one non-degenerated closing edge
823     Standard_Integer ivmapv = STATIC_PURGE_mapv.Add(vE);
824     if (trc) {cout<<" connexity for v("<<ivE<<")=v"<<ivmapv;FUN_tool_trace(UVvE);}
825 #ifdef DRAW     
826     if (trc) {TCollection_AsciiString bb("uv_");bb += TCollection_AsciiString(ivmapv);FUN_tool_draw(bb,UVvE);}
827 #endif
828 #endif  
829     
830     Standard_Real tttolvE = BRep_Tool::Tolerance(vE);
831     Standard_Real tttuvvE = Max(Tol(1,tttolvE),Tol(2,tttolvE));
832     
833     Standard_Boolean isbound = myVEds.IsBound(vE);
834     if (!isbound) {FUN_RaiseError(); return Standard_False;}
835     
836     // <vEok> :
837     Standard_Boolean vEok = Standard_False;
838     const TopTools_ListOfShape& loe = myVEds.Find(vE);
839
840     for (TopTools_ListIteratorOfListOfShape ite(loe); ite.More(); ite.Next()) {
841       const TopoDS_Edge& e = TopoDS::Edge(ite.Value());
842       TopAbs_Orientation oe = e.Orientation();
843 #ifdef DEB
844       Standard_Integer ie = STATIC_PURGE_mapeds.Add(e);
845       if (trc) {cout<<"    : on e"<<ie<<endl;}
846 #endif
847       if (e.IsSame(E)) continue;      
848       if (M_INTERNAL(oe) || M_EXTERNAL(oe)) continue;
849
850 #ifdef DEB
851       Standard_Real tttole =
852 #endif
853                    BRep_Tool::Tolerance(e);
854       
855       Standard_Boolean isb = myERep2d.IsBound(e);
856       if (!isb) {FUN_RaiseError(); return Standard_False;}
857       const TopOpeBRepTool_C2DF& C2DF = myERep2d.Find(e);
858       
859       TopTools_Array1OfShape ves(1,2); TopOpeBRepTool_TOOL::Vertices(e,ves);    
860       for (Standard_Integer ive = 1; ive <=2; ive++) {    
861         const TopoDS_Vertex& ve = TopoDS::Vertex(ves(ive));       
862         Standard_Boolean samev = ve.IsSame(vE);
863         if (!samev) continue;
864           
865         Standard_Real pare = TopOpeBRepTool_TOOL::ParE(ive,e); gp_Pnt2d UVve = TopOpeBRepTool_TOOL::UVF(pare,C2DF);
866 #ifdef DEB
867         if (trc) {cout<<"    ve("<<ive<<")";FUN_tool_trace(UVve);}
868 #endif 
869         if (ive == ivE) continue;       
870         
871         Standard_Real tttolve = BRep_Tool::Tolerance(ve);
872         Standard_Real tttuvve = Max(Tol(1,tttolve),Tol(2, tttolve));
873         
874         tttol = Max(tttol,Max(tttuvF,Max(tttuvE,Max(tttuvE,Max(tttuvve,tttuvvE)))));
875         Standard_Boolean isequal = UVvE.IsEqual(UVve,tttol);
876         if (isequal) {
877           vEok = Standard_True;
878 #ifdef DEB
879           if (trc){cout<<" connexity->ok"<<endl;}
880 #endif  
881           break;
882         }
883       } // ive  
884       if (vEok) break;
885     } // ite(loe)
886       
887     if (!vEok) {nfyv++; Ivfaulty = ivE;}      
888 #ifdef DEB
889     if (trc && !vEok) {cout<<" connexity->KO"<<endl;}   
890 #endif      
891
892   } // ivE = 1..2          
893   if (nfyv == 2) Ivfaulty = 3;
894 #ifdef DEB 
895   if (trc) {if (Ivfaulty == 0) cout<<"-> valid edge"<<endl; else cout<<"-> faulty edge"<<endl;}
896 #endif   
897   return (Ivfaulty != 0);
898 }
899
900 //=======================================================================
901 //function : EdgesWithFaultyUV
902 //purpose  : 
903 //=======================================================================
904
905 Standard_Boolean TopOpeBRepTool_CORRISO::EdgesWithFaultyUV(const TopTools_ListOfShape& EdsToCheck, const Standard_Integer nfybounds,
906                                               TopTools_DataMapOfOrientedShapeInteger& FyEds, const Standard_Boolean stopatfirst) const 
907 {
908   FyEds.Clear();
909 #ifdef DEB
910   Standard_Integer ifault = 0;
911   Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO(); 
912   if (trc) cout<<endl<<"* EdgesWithFaultyUV"<<endl;
913 #endif
914
915   // fF's checking :
916   // -----------------
917   // An edge is valid if the first and last vertices are valid:
918   // vertex <vEchk> is valid if there is an edge with bound <ve> such that :
919   //   <vEchk> and <ve> share same UV geometry
920   //   <vEchk> and <ve> are of opposite orientation.   
921   TopTools_ListIteratorOfListOfShape itchk(EdsToCheck);
922   for (; itchk.More(); itchk.Next()) {
923
924     const TopoDS_Edge& Echk = TopoDS::Edge(itchk.Value());    
925     Standard_Integer Ivfaulty=0; Standard_Boolean faulty = EdgeWithFaultyUV(Echk,Ivfaulty);
926     if (!faulty) continue;
927     Standard_Integer nfyv = (Ivfaulty == 3)? 2 : 1;
928
929 #ifdef DEB
930     ifault++; 
931     if (trc) cout<<"e"<<STATIC_PURGE_mapeds.FindIndex(Echk)<<" has ifyv="<<Ivfaulty<<endl;
932 #ifdef DRAW
933     if (trc) {TCollection_AsciiString aa("fault"); FUN_tool_draw(aa,Echk,ifault);}
934 #endif
935 #endif
936
937     Standard_Boolean found = Standard_False;
938     if      (nfybounds == 1) found = (nfyv == nfybounds);
939     else if (nfybounds == 2) found = (nfyv == nfybounds);
940     else if (nfybounds == 3) found = (nfyv > 0);
941
942     if (found) { 
943       FyEds.Bind(Echk,Ivfaulty);
944       if (stopatfirst) return Standard_True;
945     }
946   } // itchk
947   Standard_Integer n = FyEds.Extent(); // DEB
948   return (n != 0);   
949 }
950
951 //=======================================================================
952 //function : EdgeWithFaultyUV
953 //purpose  : 
954 //=======================================================================
955
956 Standard_Boolean TopOpeBRepTool_CORRISO::EdgeWithFaultyUV(const TopTools_ListOfShape& EdsToCheck, const Standard_Integer nfybounds,
957                                              TopoDS_Shape& fyE, Standard_Integer& Ifaulty) const 
958 {
959   TopTools_DataMapOfOrientedShapeInteger FyEds;
960   Standard_Boolean found = EdgesWithFaultyUV(EdsToCheck,nfybounds,FyEds,Standard_True);
961   if (!found) return Standard_False;
962
963   TopTools_DataMapIteratorOfDataMapOfOrientedShapeInteger itm(FyEds);
964   fyE = itm.Key();
965   Ifaulty = itm.Value();
966   return Standard_True;
967 }
968
969 //=======================================================================
970 //function : TrslUV
971 //purpose  : 
972 //=======================================================================
973
974 Standard_Boolean TopOpeBRepTool_CORRISO::TrslUV(const Standard_Boolean onU, const TopTools_DataMapOfOrientedShapeInteger& FyEds)
975 {
976   gp_Vec2d tt2d; 
977   if (onU) {Standard_Real uper;
978                      Refclosed(1,uper);
979             if (!uper) return Standard_False;
980             tt2d = gp_Vec2d(uper,0.);}
981   else     {Standard_Real vper;
982                      Refclosed(2,vper);
983             if (!vper) return Standard_False;
984             tt2d = gp_Vec2d(0.,vper);}
985   TopTools_DataMapIteratorOfDataMapOfOrientedShapeInteger itm(FyEds);
986   for (; itm.More(); itm.Next()){
987     const TopoDS_Edge& E = TopoDS::Edge(itm.Key());
988     TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = UVRep(E,C2DF);
989     if (!isb) return Standard_False;
990
991     Standard_Integer itt = itm.Value();
992     if      (itt == SPLITEDGE) return Standard_False;
993     else if (itt == INCREASE) TopOpeBRepTool_TOOL::TrslUV(tt2d,C2DF);
994     else if (itt == DECREASE) TopOpeBRepTool_TOOL::TrslUV(tt2d.Multiplied(-1.),C2DF);
995     else return Standard_False;
996     SetUVRep(E,C2DF);
997   }
998   return Standard_True;
999 }
1000
1001 // modif in BRep_Builder031298
1002 /*static void FUN_tool_correctdgE(const TopoDS_Edge& E)
1003 {
1004   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1005   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1006   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1007   while (itcr.More()) {
1008     Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1009     if (!GC.IsNull()) {
1010       if (GC->IsCurve3D()) lcr.Remove(itcr);
1011       else itcr.Next();
1012     }
1013   }
1014 }*/
1015
1016 //=======================================================================
1017 //function : GetnewS
1018 //purpose  : 
1019 //=======================================================================
1020
1021 Standard_Boolean TopOpeBRepTool_CORRISO::GetnewS(TopoDS_Face& newS) const 
1022 {
1023   newS.Nullify();
1024   if (myS.ShapeType() != TopAbs_FACE) return Standard_False;
1025
1026   newS = TopoDS::Face(myS);
1027   BRep_Builder BB;
1028
1029   TopTools_ListIteratorOfListOfShape it(myEds);
1030   for (; it.More(); it.Next()){
1031     TopoDS_Edge E = TopoDS::Edge(it.Value());   
1032     TopAbs_Orientation oriE = E.Orientation();
1033     TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = UVRep(E,C2DF);
1034     if (!isb) return Standard_False;
1035
1036     Standard_Real f,l,tol;const Handle(Geom2d_Curve)& PC = C2DF.PC(f,l,tol);
1037     Handle(Geom2d_TrimmedCurve) cu = new Geom2d_TrimmedCurve(PC,f,l);
1038     
1039     TopoDS_Shape aLocalShape = E.Oriented(TopAbs::Complement(oriE));
1040     TopoDS_Edge Err = TopoDS::Edge(aLocalShape);
1041 //    TopoDS_Edge Err = TopoDS::Edge(E.Oriented(TopAbs::Complement(oriE)));
1042     TopOpeBRepTool_C2DF C2DFrr; Standard_Boolean isclo = UVRep(Err,C2DFrr);
1043     
1044 //    Standard_Boolean isdgE = BRep_Tool::Degenerated(E);
1045     // !BUC60380 : degenerated edge has a 3d curve !!, remove it
1046 //    if (isdgE) {FUN_tool_correctdgE(E);}     
1047                 
1048     if (isclo) {
1049       Standard_Real frr,lrr,tolrr;const Handle(Geom2d_Curve)& PCrr = C2DFrr.PC(frr,lrr,tolrr);
1050       Handle(Geom2d_TrimmedCurve) curr = new Geom2d_TrimmedCurve(PCrr,frr,lrr);
1051       if (M_FORWARD(oriE)) BB.UpdateEdge(E,cu,curr,newS,tol);
1052     }
1053     else BB.UpdateEdge(E,cu,newS,tol);
1054   }
1055   return Standard_True;
1056 }
1057
1058 //=======================================================================
1059 //function : AddNewConnexity
1060 //purpose  : 
1061 //=======================================================================
1062
1063 //Standard_Boolean TopOpeBRepTool_CORRISO::AddNewConnexity(const TopoDS_Vertex& V,
1064 Standard_Boolean TopOpeBRepTool_CORRISO::AddNewConnexity(const TopoDS_Vertex& ,
1065                                                          const TopoDS_Edge& E)
1066 {
1067   // <myERep2d> : 
1068   Standard_Boolean isb = myERep2d.IsBound(E);
1069   if (!isb) {
1070     Handle(Geom2d_Curve) PC; Standard_Real f,l,tol;
1071     Standard_Boolean hasold = FC2D_HasOldCurveOnSurface(E,myFref,PC);
1072     PC = FC2D_EditableCurveOnSurface(E,myFref,f,l,tol);
1073     if (!hasold) FC2D_AddNewCurveOnSurface(PC,E,myFref,f,l,tol);
1074     if (PC.IsNull()) return Standard_False;
1075     TopOpeBRepTool_C2DF C2DF(PC,f,l,tol,myFref);
1076     myERep2d.Bind(E,C2DF);  
1077   }
1078
1079   // <myEds> : 
1080   if (!isb) myEds.Append(E);
1081
1082   // <myVEds> :
1083   TopExp_Explorer exv(E, TopAbs_VERTEX);
1084   for (; exv.More(); exv.Next()){
1085     const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current()); 
1086     Standard_Boolean isbb = myVEds.IsBound(v);
1087     if (isbb) myVEds.ChangeFind(v).Append(E);
1088     else      {TopTools_ListOfShape loe; loe.Append(E); myVEds.Bind(v,loe);}
1089   }//exv
1090   return Standard_True;
1091   
1092 }
1093
1094 //=======================================================================
1095 //function : RemoveOldConnexity
1096 //purpose  : 
1097 //=======================================================================
1098
1099 //Standard_Boolean TopOpeBRepTool_CORRISO::RemoveOldConnexity(const TopoDS_Vertex& V,
1100 Standard_Boolean TopOpeBRepTool_CORRISO::RemoveOldConnexity(const TopoDS_Vertex& ,
1101                                                             const TopoDS_Edge& E)
1102 {
1103   // <myERep2d> :
1104   Standard_Boolean isb = myERep2d.IsBound(E);
1105   if (isb) myERep2d.UnBind(E);
1106
1107   // <myEds> : 
1108   if (isb) {
1109     TopTools_ListIteratorOfListOfShape it(myEds);
1110     while (it.More()) {
1111       if (it.Value().IsEqual(E)) {myEds.Remove(it);break;}
1112       else                       it.Next();
1113     }
1114   }
1115
1116   // <myVEds> :
1117   Standard_Boolean done = Standard_False;
1118   TopExp_Explorer exv(E, TopAbs_VERTEX);
1119   for (; exv.More(); exv.Next()){
1120     const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current()); 
1121     Standard_Boolean isb = myVEds.IsBound(v); 
1122     if (!isb) return Standard_False;
1123     TopTools_ListOfShape& loe = myVEds.ChangeFind(v);
1124     TopTools_ListIteratorOfListOfShape ite(loe);
1125     while (ite.More()) {
1126       if (ite.Value().IsEqual(E)) {done = Standard_True; loe.Remove(ite);break;}
1127       else                         ite.Next();
1128     }
1129   }//exv
1130   return done;
1131 }
1132