0022627: Change OCCT memory management defaults
[occt.git] / src / TopOpeBRepTool / TopOpeBRepTool_PURGE.cxx
CommitLineData
7fd59977 1// File: TopOpeBRepTool_PURGE.cxx
2// Created: Thu Nov 13 13:45:48 1997
3// Author: Xuan PHAM PHU
4// <xpu@poulopox.paris1.matra-dtv.fr>
5
6#include <TopOpeBRepTool.hxx>
7#include <TopOpeBRepTool_TOOL.hxx>
8#include <TopOpeBRepTool_CORRISO.hxx>
9#include <TopOpeBRepTool_C2DF.hxx>
10#include <gp_Pnt2d.hxx>
11#include <gp_Vec2d.hxx>
12#include <GeomAdaptor_Surface.hxx>
13#include <Geom2d_Curve.hxx>
14#include <Geom2d_TrimmedCurve.hxx>
15#include <Geom2d_Line.hxx>
16#include <Geom_Surface.hxx>
17#include <TopoDS.hxx>
18#include <TopoDS_Wire.hxx>
19#include <TopTools_Array1OfShape.hxx>
20
21#include <BRep_Tool.hxx>
22#include <Precision.hxx>
23#include <TopExp.hxx>
24#include <TopExp_Explorer.hxx>
25#include <BRep_Builder.hxx>
26#include <BRepAdaptor_Surface.hxx>
27#include <TopOpeBRepTool_define.hxx>
28#include <TopOpeBRepTool_EXPORT.hxx>
29#include <TopOpeBRepTool_2d.hxx>
30#include <Standard_Failure.hxx>
31#include <TopOpeBRepTool_PURGE.hxx>
32
33#ifdef DEB
34//Standard_EXPORT Standard_Integer STATIC_PURGE_iwi = 0;
35//Standard_EXPORT TopTools_IndexedMapOfShape STATIC_PURGE_mapw, STATIC_PURGE_mapv;
36//Standard_EXPORT TopTools_IndexedMapOfOrientedShape STATIC_PURGE_mapeds, STATIC_CORR_mapeds;
37
38Standard_EXPORT void debcorrUV(){};
39Standard_EXPORT Standard_Boolean TopOpeBRepTool_GettracePURGE();
40Standard_EXPORT Standard_Boolean TopOpeBRepTool_GettraceCORRISO();
41#endif
42// DEB
43
44// Unused :
45#ifdef DEB
46static void FUN_RaiseError()
47{
48#ifdef DEB
49 Standard_Boolean trc = TopOpeBRepTool_GettracePURGE();
50 // Standard_Failure::Raise("TopOpeBRepTool::PurgeClosingEdges");
51 FUN_REINIT();
52 if (trc) cout <<"*********failure in TopOpeBRepTool::PurgeClosingEdges***********\n";
53#endif
54}
55static void FUN_Raise()
56{
57#ifdef DEB
58 // cout <<"*********failure in TopOpeBRepTool::CorrectONUVISO***********\n";
59 // Standard_Failure::Raise("TopOpeBRepTool::CorrectONUVISO");
60#endif
61}
62#endif
63
64#define SPLITEDGE (0)
65#define INCREASE (1)
66#define DECREASE (-1)
67
68#define M_FORWARD(sta) (sta == TopAbs_FORWARD)
69#define M_REVERSED(sta) (sta == TopAbs_REVERSED)
70#define M_INTERNAL(sta) (sta == TopAbs_INTERNAL)
71#define M_EXTERNAL(sta) (sta == TopAbs_EXTERNAL)
72
73static void FUN_addtomap(TopTools_DataMapOfShapeListOfShape& map, const TopoDS_Shape& key, const TopoDS_Shape& item)
74{
75 if (map.IsBound(key)) map.ChangeFind(key).Append(item);
76 else {TopTools_ListOfShape los; los.Append(item); map.Bind(key,los);}
77}
78
79static Standard_Boolean FUN_getv(const TopAbs_Orientation& orivine, const TopoDS_Shape& e, TopoDS_Shape& v)
80{
81 v.Nullify();
82 // gets <v> oriented <orivine> in <e>
83 TopAbs_Orientation oe = e.Orientation();
84 Standard_Boolean isnonO = M_INTERNAL(oe) || M_EXTERNAL(oe);
85 TopoDS_Shape eO;
86 if (isnonO) {
87 eO = e.Oriented(TopAbs_FORWARD);
88 }
89 else {
90 eO = e;
91 }
92 TopExp_Explorer exv(eO, TopAbs_VERTEX);
93 for (; exv.More(); exv.Next()) {
94 const TopoDS_Shape& vcur = exv.Current();
95 if (vcur.Orientation() == orivine) {v = vcur; return Standard_True;}
96 } // exv
97 return Standard_False;
98}
99
100Standard_EXPORT Standard_Boolean FUN_tool_ClosedW(const TopoDS_Wire& W)
101{
102 // !! an edge oriented INTERNAL/EXTERNAL has all its vertices
103 // oriented INTERNAL/EXTERNAL.
104
105 // <mapvedsO> = {(v,loe)} / e is oriented :
106 // <mapvedsO> = {(v,loe)} / e is not oriented (INTERNAL/EXTERNAL) :
107 TopTools_DataMapOfShapeListOfShape mapvFine,mapvRine, mapvIine;
108
109 TopExp_Explorer exe(W, TopAbs_EDGE);
110 for (; exe.More(); exe.Next()){
111 const TopoDS_Shape& e = exe.Current();
112 TopAbs_Orientation oe = e.Orientation();
113 Standard_Boolean isnonO = M_INTERNAL(oe) || M_EXTERNAL(oe);
114 TopoDS_Shape eO;
115 if (isnonO) {
116 eO = e.Oriented(TopAbs_FORWARD);
117 }
118 else {
119 eO = e;
120 }
121
122 TopExp_Explorer exv(eO, TopAbs_VERTEX);
123 for (; exv.More(); exv.Next()) {
124 const TopoDS_Shape& v = exv.Current();
125 TopAbs_Orientation oriv = v.Orientation();
126 if (M_FORWARD(oriv)) FUN_addtomap(mapvFine,v,e);
127 if (M_REVERSED(oriv)) FUN_addtomap(mapvRine,v,e);
128 if (M_INTERNAL(oriv)) FUN_addtomap(mapvIine,v,e);
129 }
130 }
131
132 if (mapvFine.Extent() == 0) return Standard_False; // empty wire
133
134 TopTools_MapOfShape mapvok;
135 // a vertex is found valid if is - an internal vertex
136 // - found FORWARD and REVERSED.
137 TopTools_MapOfShape mapvonlyFine; // {(v,e)} v F in e, v belongs to only one e
138 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itvFine(mapvFine);
139 for (; itvFine.More(); itvFine.Next()){
140 const TopoDS_Shape& vFine = itvFine.Key();
7fd59977 141 Standard_Boolean vIine = mapvIine.IsBound(vFine);
142 if (vIine) {mapvok.Add(vFine); continue;}
143 Standard_Boolean vRine = mapvRine.IsBound(vFine);
144 if (vRine) {mapvok.Add(vFine); continue;}
145 mapvonlyFine.Add(vFine);
146 }
147 // <mapvRinonee> = {(v,e)} v R in e, v belongs to only one e
148 TopTools_MapOfShape mapvonlyRine;
149 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itvRine(mapvRine);
150 for (; itvRine.More(); itvRine.Next()){
151 const TopoDS_Shape& vRine = itvRine.Key();
7fd59977 152 Standard_Boolean vok = mapvok.Contains(vRine);
153 if (vok) continue;
154 Standard_Boolean vIine = mapvIine.IsBound(vRine);
155 if (vIine) {mapvok.Add(vRine); continue;}
156 mapvonlyRine.Add(vRine);
157 }
158
159 // checking vertices <mapvonlyFine> and <mapvonlyRine>
160 TopTools_MapIteratorOfMapOfShape itvonlyFRine;
161 Standard_Integer nmap = 0;
162 while (nmap <= 2) {
163 nmap++;
164 Standard_Boolean vFine = (nmap == 1);
165 if (vFine) itvonlyFRine.Initialize(mapvonlyFine);
166 else itvonlyFRine.Initialize(mapvonlyRine);
167
168 for (; itvonlyFRine.More(); itvonlyFRine.Next()){
169 const TopoDS_Shape& vtocheck = itvonlyFRine.Key();
170 TopTools_ListOfShape edsvFRine;
171 if (vFine) edsvFRine = mapvFine.Find(vtocheck);
172 else edsvFRine = mapvRine.Find(vtocheck);
173
174 if (edsvFRine.Extent() > 1) return Standard_False; // faulty wire
175 const TopoDS_Shape& e = edsvFRine.First();
176
177 TopAbs_Orientation ovori = vFine? TopAbs_REVERSED: TopAbs_FORWARD;
178 TopoDS_Shape ov; Standard_Boolean ovfound = FUN_getv(ovori,e,ov);
179 if (!ovfound) return Standard_False; // faulty edge
180
181 // <vtocheck> is on only one edge <e>,
182 // <vtocheck> is FORWARD/REVERSED in <e>,
183 // <ovfound> is REVERSED/FORWARD in <e>.
184 // <vtocheck> is ok if : - <ovfound> is INTERNAL in another edge
185 // - <ovfound> is FORWARD and REVERSED in
186 // one or two other edges.
187 // and e is not oriented
188 TopAbs_Orientation oe = e.Orientation();
189 if (M_FORWARD(oe) || M_REVERSED(oe)) return Standard_False;
190 if (!mapvok.Contains(ov)) return Standard_False;
191
192 Standard_Boolean ovIine = mapvIine.IsBound(ov); if (ovIine) continue;
193 Standard_Boolean ovFine = mapvRine.IsBound(ov); if (!ovFine) return Standard_False;
194 Standard_Boolean ovRine = mapvRine.IsBound(ov); if (!ovRine) return Standard_False;
195
196 const TopTools_ListOfShape& edsovFine = mapvFine.Find(ov);
197 const TopTools_ListOfShape& edsovRine = mapvRine.Find(ov);
198 if (edsovFine.Extent() > 1) continue;
199 if (edsovRine.Extent() > 1) continue;
200 if (edsovFine.First().IsEqual(e)) return Standard_False;
201 if (edsovRine.First().IsEqual(e)) return Standard_False;
202 }
203 } // nmap
204 return Standard_True;
205}
206
207//=======================================================================
208//function : PurgeClosingEdges
209//purpose :
210//=======================================================================
211
212Standard_Boolean TopOpeBRepTool::PurgeClosingEdges(const TopoDS_Face& Fin, const TopoDS_Face& FF,
213// const TopTools_DataMapOfShapeInteger& MWisOld,
214 const TopTools_DataMapOfShapeInteger& ,
215 TopTools_IndexedMapOfOrientedShape& MshNOK)
216{
217 // Fin is the original face
218 // FF is the splitted face
219
220 // prequesitory : splitted edges, of edge ancestor a closing edge
221 // keep in memory the geometry of the ancestor edge,
222 // they answer True to BRep_Tool::IsClosed.
223 // elsewhere : we have to get this information using geometric
224 // criteriums (TopOpeBRepTool_TOOL::IsonCLO)
225
226#ifdef DEB
227 Standard_Boolean trc = TopOpeBRepTool_GettracePURGE();
228 if (trc) cout<<"\n* PurgeClosingEdges:\n\n";
229#endif
230 TopOpeBRepTool_CORRISO CORRISO(Fin);
231 Standard_Real tolF = BRep_Tool::Tolerance(Fin);
232 Standard_Real uperiod; Standard_Boolean uclosed = CORRISO.Refclosed(1,uperiod);
233 Standard_Real vperiod; Standard_Boolean vclosed = CORRISO.Refclosed(2,vperiod);
234 if (!uclosed && !vclosed) return Standard_False;
235 Standard_Boolean inU = uclosed ? Standard_True : Standard_False;
236 Standard_Real xmin = inU ? (CORRISO.GASref().FirstUParameter()) :
237 (CORRISO.GASref().FirstVParameter());
238 Standard_Real xper = inU ? uperiod : vperiod;
239 Standard_Real tolx = inU ? (CORRISO.Tol(1,tolF)) : (CORRISO.Tol(2,tolF));
240
241 TopExp_Explorer exw(FF, TopAbs_WIRE);
242 for (; exw.More(); exw.Next()){
243 const TopoDS_Shape& W = exw.Current();
244
245 CORRISO.Init(W);
246 Standard_Boolean ok = CORRISO.UVClosed();
247 if (ok) continue;
248
249 TopTools_ListOfShape cEds;
250 TopTools_ListIteratorOfListOfShape ite(CORRISO.Eds());
251 for (; ite.More(); ite.Next()){
252 const TopoDS_Edge& E = TopoDS::Edge(ite.Value());
253 Standard_Boolean closing = BRep_Tool::IsClosed(E,Fin);
254 if (!closing) {// xpu231198 : pcurve modified, the information is lost
255 TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = CORRISO.UVRep(E,C2DF);
256 if (!isb) return Standard_False;//NYIRAISE
257 Standard_Boolean onclo = TopOpeBRepTool_TOOL::IsonCLO(C2DF,inU,xmin,xper,tolx);
258 if (onclo) closing=Standard_True;
259 }
260 if (closing) cEds.Append(E);
261 }
262 Standard_Integer ncE = cEds.Extent();
263 Standard_Boolean nopurge = (ncE <= 1);
264 if (nopurge) return Standard_True;
265
266 // Checking <W>
267 TopTools_ListOfShape fyEds; Standard_Boolean topurge = CORRISO.PurgeFyClosingE(cEds,fyEds);
268 if (topurge) {
269 TopTools_ListIteratorOfListOfShape it(fyEds);
270 for (; it.More(); it.Next()) MshNOK.Add(it.Value());
271 MshNOK.Add(W);
272 MshNOK.Add(FF);
273 }
274
275#ifdef DEB
276 if (trc && topurge) cout<<"found FAULTY edge = ed"<<endl;
277#endif
278 } // exw
279 return Standard_True;
280}
281
282//=======================================================================
283//function : PurgeClosingEdges
284//purpose :
285//=======================================================================
286
287Standard_Boolean TopOpeBRepTool::PurgeClosingEdges(const TopoDS_Face& Fin, const TopTools_ListOfShape& LOF,
288 const TopTools_DataMapOfShapeInteger& MWisOld,
289 TopTools_IndexedMapOfOrientedShape& MshNOK)
290{
291 Standard_Boolean uvclosed = FUN_tool_closedS(Fin);
292 if (!uvclosed) return Standard_True;
293
294 TopTools_ListIteratorOfListOfShape it(LOF);
295 for (; it.More(); it.Next()){
296 const TopoDS_Face& FF = TopoDS::Face(it.Value());
297 Standard_Boolean ok = TopOpeBRepTool::PurgeClosingEdges(Fin,FF,MWisOld,MshNOK);
298 if (!ok) return Standard_False;
299 }
300 return Standard_True;
301}
302
303/*static Standard_Boolean FUN_correctClosingE(TopoDS_Edge& newfE, TopoDS_Face& Fsp)
304{
305 Standard_Real f,l,tol; Handle(Geom2d_Curve) PC = FUNTOOLC2D_CurveOnSurface(newfE,Fsp,f,l,tol);
306 gp_Dir2d d2d; gp_Pnt2d O2d; Standard_Boolean isuiso,isviso;
307 Standard_Boolean uviso = FUN_tool_IsUViso(PC,isuiso,isviso,d2d,O2d);
308 if (!uviso) return Standard_False;
309
c6541a0c 310 Standard_Real period = 2*M_PI;
7fd59977 311 Standard_Real piso = isuiso? O2d.X(): O2d.Y();
312 Standard_Real tol2d = 1.e-6;
313 Standard_Boolean is0 = Abs(piso) < tol2d;
314 Standard_Boolean is2PI = Abs(period-piso) < tol2d;
315 // --------------------------------------------------
316 // prequesitory : Closed Surfaces have period 2PI
317 if (!is0 && !is2PI) return Standard_False;
318 // --------------------------------------------------
319 Standard_Real factor = is0? period: -period;
320 gp_Vec2d transl(1.,0.); if (isviso) transl = gp_Vec2d(0.,1.);
321 transl.Multiply(factor);
322
323 Standard_Integer ok = FUN_tool_translate(transl,Fsp,newfE);
324 return Standard_True;
325}
326
327static Standard_Boolean FUN_correctDegeneratedE
328(const TopTools_IndexedDataMapOfShapeListOfShape& mve,TopoDS_Edge& Ein,TopoDS_Face& Fsp)
329{
330 TopoDS_Vertex v1,v2; TopExp::Vertices(Ein,v1,v2);
331 TopAbs_Orientation ov1 = v1.Orientation();
332 TopAbs_Orientation ov2 = v2.Orientation();
333 Standard_Boolean ok1 = mve.Contains(v1); if (!ok1) return Standard_False;
334 Standard_Boolean ok2 = mve.Contains(v2); if (!ok2) return Standard_False;
335
336 const TopTools_ListOfShape& le= mve.FindFromKey(v1);
337
338 TopoDS_Edge e1,e2; Standard_Boolean fe1 = Standard_False; Standard_Boolean fe2 = Standard_False;
339 TopoDS_Vertex vfe1,vfe2;
340 Standard_Boolean fEin = Standard_False;
341 for(TopTools_ListIteratorOfListOfShape itle(le);itle.More();itle.Next()) {
342 const TopoDS_Shape& ecx = TopoDS::Edge(itle.Value());
343 if (ecx.IsEqual(Ein)) {
344 fEin = Standard_True;
345 }
346 else {
347 TopExp_Explorer exv;
348 for (exv.Init(ecx,TopAbs_VERTEX);exv.More();exv.Next()) {
349// for (TopExp_Explorer exv(ecx,TopAbs_VERTEX);exv.More();exv.Next()) {
350 const TopoDS_Vertex& vecx = TopoDS::Vertex(exv.Current());
351 Standard_Boolean issam = vecx.IsSame(v1);
352 if (issam) {
353 Standard_Boolean iseq1 = vecx.IsEqual(v1);
354 Standard_Boolean iseq2 = vecx.IsEqual(v2);
355 if (!iseq1) {
356 e1 = TopoDS::Edge(ecx);
357 vfe1 = TopoDS::Vertex(vecx);
358 fe1 = Standard_True;
359 }
360 if (!iseq2) {
361 e2 = TopoDS::Edge(ecx);
362 vfe2 = TopoDS::Vertex(vecx);
363 fe2 = Standard_True;
364 }
365 }
366 if (fe1 && fe2) break;
367 }
368 if (fe1 && fe2) break;
369 }
370 if (fEin && fe1 && fe2) break;
371 } // itle.More()
372
373 Standard_Boolean ok = (fEin && fe1 && fe2);
374 if (!ok) return Standard_False;
375
376#ifdef DEB
377 debcorrUV(); // call Draw_Call("av2d;dy fyf;fit;ppcu fyf")
378#endif
379
380 Standard_Real f,l,tol; Handle(Geom2d_Curve) PC = FUNTOOLC2D_CurveOnSurface(Ein,Fsp,f,l,tol);
381 gp_Dir2d d2d; gp_Pnt2d O2d; Standard_Boolean isuiso = 0,isviso = 0;
382 Standard_Boolean uviso = FUN_tool_IsUViso(PC,isuiso,isviso,d2d,O2d);
383 if (!uviso) return Standard_False;
384
385 Standard_Real pfEin,plEin,tolEin; Handle(Geom2d_Curve) PCEin = FUNTOOLC2D_CurveOnSurface(Ein,Fsp,pfEin,plEin,tolEin);
386 if (PCEin.IsNull()) Standard_Failure::Raise(" FUN_correctDegeneratedE : no 2d curve Ein");
387 Standard_Real pf1,pl1,tol1; Handle(Geom2d_Curve) PC1 = FUNTOOLC2D_CurveOnSurface(e1,Fsp,pf1,pl1,tol1);
388 if (PC1.IsNull()) Standard_Failure::Raise(" FUN_correctDegeneratedE : no 2d curve e1");
389 Standard_Real pf2,pl2,tol2; Handle(Geom2d_Curve) PC2 = FUNTOOLC2D_CurveOnSurface(e2,Fsp,pf2,pl2,tol2);
390 if (PC2.IsNull()) Standard_Failure::Raise(" FUN_correctDegeneratedE : no 2d curve e2");
391
392 Standard_Real parv1 = BRep_Tool::Parameter(v1,Ein,Fsp);
393 Standard_Real parv2 = BRep_Tool::Parameter(v2,Ein,Fsp);
394 gp_Pnt2d pv1; PCEin->D0(parv1,pv1);
395 gp_Pnt2d pv2; PCEin->D0(parv2,pv2);
396
397 Standard_Real par1 = BRep_Tool::Parameter(vfe1,e1,Fsp);
398 Standard_Real par2 = BRep_Tool::Parameter(vfe2,e2,Fsp);
399 gp_Pnt2d p1; PC1->D0(par1,p1);
400 gp_Pnt2d p2; PC2->D0(par2,p2);
401
402 Standard_Real cv1 = (isuiso) ? pv1.Y() : pv1.X();
403 Standard_Real cv2 = (isuiso) ? pv2.Y() : pv2.X();
404 Standard_Real c1 = (isuiso) ? p1.Y() : p1.X();
405 Standard_Real c2 = (isuiso) ? p2.Y() : p2.X();
406
407 Standard_Real d1 = (c1 - cv1);
408 Standard_Real d2 = (c2 - cv2);
409 Standard_Real adc = Abs(c1 - c2);
410 Standard_Real adcv = Abs(cv1 - cv2);
411
412 Standard_Real tol2d = 1.e-6;
413 Standard_Boolean mmd = (Abs(adc-adcv) < tol2d);
414 if (mmd) { // correction de CTS20973
415 gp_Vec2d transl(0.,1.); if (isviso) transl = gp_Vec2d(1.,0.);
416 transl.Multiply(d1); // ou d2
417 ok = FUN_tool_translate(transl,Fsp,Ein);
418 }
419 else {
420 // redefinition des parametres de v1,v2 de Ein tels que des parametres de
421#ifdef DEB
422 if (TopOpeBRepTool_GettraceCORRISO()) {
423 cout<<"FUN_correctDegeneratedE : !mmd NYI"<<endl;
424 }
425#endif
426 ok = Standard_False;
427 }
428
429 return ok;
430} //FUN_correctDegeneratedE*/
431
432/*static Standard_Boolean FUN_tool_reguUV(const TopoDS_Face& FF, TopoDS_Face& fF)
433{
434
435 const TopoDS_Face& F = TopoDS::Face(FF);
436 Standard_Boolean uclosed,vclosed; Standard_Real uperiod,vperiod;
437 Standard_Boolean closed = FUN_tool_closedS(F,uclosed,uperiod,vclosed,vperiod);
438 if (!closed) return Standard_False;
439 Standard_Real tolu,tolv; FUN_tool_tolUV(TopoDS::Face(fF),tolu,tolv);
440
441 TopTools_ListOfShape leko;
442 // --------
443 TopTools_IndexedMapOfOrientedShape mape;
444 TopExp_Explorer ex(fF, TopAbs_EDGE);
445 for (; ex.More(); ex.Next()){
446 const TopoDS_Edge& ee = TopoDS::Edge(ex.Current());
447 TopAbs_Orientation oee = ee.Orientation();
448 TopAbs_Orientation oe = TopAbs::Complement(oee);
449 TopoDS_Edge e = TopoDS::Edge(ee.Oriented(oe));
450 Standard_Boolean hasoppo = mape.Contains(e); // e with complement ori was added to mape
451 if (hasoppo) {
452 // ee :
453 Standard_Real ff,ll; Handle(Geom2d_Curve) PCee = BRep_Tool::CurveOnSurface(ee,F,ff,ll);
454 Standard_Boolean uisoee,visoee; gp_Dir2d d2dee; gp_Pnt2d O2dee;
455 Standard_Boolean uvisoee = FUN_tool_IsUViso(PCee,uisoee,visoee,d2dee,O2dee);
456 // e :
457 Standard_Real f,l; Handle(Geom2d_Curve) PCe = BRep_Tool::CurveOnSurface(e,F,f,l);
458 Standard_Boolean uisoe,visoe; gp_Dir2d d2de; gp_Pnt2d O2de;
459 Standard_Boolean uvisoe = FUN_tool_IsUViso(PCe,uisoe,visoe,d2de,O2de);
460
461 // isfaulty :
462 Standard_Boolean isfaulty = Standard_False;
463 Standard_Real dd = O2dee.Distance(O2de);
464 if (uisoee && uisoe) isfaulty = (dd < tolu);
465 if (visoee && visoe) isfaulty = (dd < tolv);
466
467 if (isfaulty) leko.Append(ee);
468 }
469 else mape.Add(ee);
470 }
471
472 Standard_Integer nko = leko.Extent();
473 if (nko != 1) return Standard_False;
474
475 // eko = edge with faulty pcurve :
476 const TopoDS_Shape& eko = leko.First();
477 TopAbs_Orientation oeko = eko.Orientation();
478 TopTools_ListOfShape edges; ex.Init(fF, TopAbs_EDGE);
479 for (; ex.More(); ex.Next()){
480 const TopoDS_Shape& ee = ex.Current();
481 if (!ee.IsSame(eko)) edges.Append(ee);
482 }
483 // fe = edge with vfe = vertex(ivfe) not uv-connexed :
484 TopoDS_Shape fe; Standard_Integer ivfe=0;
485 Standard_Boolean det = ::FUN_DetectEdgewithfaultyUV(FF,fF,edges,Standard_False,fe,ivfe);
486 if (!det) return Standard_False;
487
488 TopTools_Array1OfShape Vfe(1,2); FUN_Vertices(TopoDS::Edge(fe),Vfe);
489 TopAbs_Orientation ofe = fe.Orientation();
490 const TopoDS_Vertex& vfe = TopoDS::Vertex(Vfe(ivfe));
491 Standard_Real parfe = BRep_Tool::Parameter(vfe,TopoDS::Edge(fe));
492 gp_Pnt2d uvfe; Standard_Boolean ok = FUN_tool_paronEF(TopoDS::Edge(fe),parfe,F,uvfe);
493 if (!ok) return Standard_False;
494 // ivconnex :
495 Standard_Integer ivconnex = (ivfe == 1) ? 2 : 1;
496// if (ofe == TopAbs_REVERSED) ivconnex = (ivconnex == 1) ? 2 : 1;
497
498 // vertex(ivconnex) of eko FORWARD
499 TopoDS_Edge ekoFOR = TopoDS::Edge(eko.Oriented(TopAbs_FORWARD));
500 TopTools_Array1OfShape Veko(1,2); FUN_Vertices(TopoDS::Edge(ekoFOR),Veko);
501 const TopoDS_Vertex& veko1 = TopoDS::Vertex(Veko(1));
502 const TopoDS_Vertex& veko2 = TopoDS::Vertex(Veko(2));
503 Standard_Integer iveko = 0;
504 if (veko1.IsSame(vfe)) iveko = 1;
505 if (veko2.IsSame(vfe)) iveko = 2;
506 if (iveko == 0) return Standard_False;
507
508 // ett : edge same eko with pcurve to translate
509 // isekoFOR=true : vfe should be connexed to vertex(ivconnex) of ekoFOR
510 Standard_Boolean isekoFOR = (iveko == ivconnex);
511 TopAbs_Orientation oett = isekoFOR ? TopAbs_FORWARD : TopAbs_REVERSED;
512 TopoDS_Edge ett = TopoDS::Edge(eko.Oriented(oett));
513 const TopoDS_Vertex& vtt = TopoDS::Vertex(Veko(iveko));
514
515 Standard_Real parett = BRep_Tool::Parameter(vtt,ett);
516 gp_Pnt2d uvtt; ok = FUN_tool_paronEF(ett,parett,F,uvtt);
517 if (!ok) return Standard_False;
518
519 Standard_Real du = uvfe.X()-uvtt.X();
520 Standard_Real dv = uvfe.Y()-uvtt.Y();
521 Standard_Boolean tru=Standard_False, trv=Standard_False;
522 if (uclosed) tru = (Abs(Abs(du)-uperiod) < tolu);
523 if (vclosed) trv = (Abs(Abs(dv)-vperiod) < tolv);
524 if (!tru && !trv) return Standard_False;
525
526 gp_Vec2d tt;
527 if (tru) tt = gp_Vec2d(du,0.);
528 if (trv) tt = gp_Vec2d(0.,dv);
529 Standard_Real f,l; Handle(Geom2d_Curve) PC1 = BRep_Tool::CurveOnSurface(ett,F,f,l);
530 Standard_Boolean uisoett,visoett; gp_Dir2d d2dett; gp_Pnt2d o2dett;
531 Standard_Boolean uvisoett = FUN_tool_IsUViso(PC1,uisoett,visoett,d2dett,o2dett);o2dett.Translate(tt);
532 Handle(Geom2d_Line) L2d = new Geom2d_Line(o2dett,d2dett);
533 Handle(Geom2d_TrimmedCurve) PC2 = new Geom2d_TrimmedCurve(L2d,f,l);
534
535 BRep_Builder BB;
536 Standard_Real toltt = BRep_Tool::Tolerance(ett);
537// BB.UpdateEdge(TopoDS::Edge(ett),PC2,PC1,fF,toltt);
538 // xpu220998 : cto cylcong A1
539 Handle(Geom2d_Curve) nullc2d;
540 BB.UpdateEdge(TopoDS::Edge(ekoFOR),nullc2d,nullc2d,fF,toltt); // clear
541 if (isekoFOR) BB.UpdateEdge(TopoDS::Edge(ekoFOR),PC2,PC1,fF,toltt);
542 else BB.UpdateEdge(TopoDS::Edge(ekoFOR),PC1,PC2,fF,toltt);
543
544 return Standard_True;
545}*/
546
547static Standard_Boolean FUN_connexX(const Standard_Boolean onU, TopOpeBRepTool_CORRISO& CORRISO,
548 const TopTools_ListOfShape& EdstoCheck, TopTools_DataMapOfOrientedShapeInteger& fyEds)
549// purpose : Fref is x-periodic,
550// <fyEds>={(fye,recadre)}, recadre = INCREASE,DECREASE
551// fye has its 2 bounds faulty
552{
553 fyEds.Clear();
554 Standard_Real tolF = BRep_Tool::Tolerance(CORRISO.Fref());
555 Standard_Integer Index = onU ? 1 : 2;
556 Standard_Real xperiod; Standard_Boolean xclosed = CORRISO.Refclosed(Index,xperiod);
557 if (!xclosed) return Standard_False;
558 Standard_Real xtol = CORRISO.Tol(Index,tolF);
559
560 // fy has its 2 uvbounds non-connexed
561 //nyixpu300998 : iterative (while ko) + map of "static" edges
562 TopoDS_Shape fy; Standard_Integer Ify=0; Standard_Boolean hasfy = CORRISO.EdgeWithFaultyUV(EdstoCheck,2,fy,Ify);
563 if (!hasfy) return Standard_False;
564 TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = CORRISO.UVRep(TopoDS::Edge(fy),C2DF);
565 if (!isb) return Standard_False; // NYIRAISE
566
567 TopTools_Array1OfShape vfy(1,2); TopOpeBRepTool_TOOL::Vertices(TopoDS::Edge(fy),vfy);
568 for (Standard_Integer ii = 1; ii <=2; ii++) {
569 // vff = vertex[ii] of fy
570 const TopoDS_Vertex& vff = TopoDS::Vertex(vfy(ii));
571 Standard_Real parvff = TopOpeBRepTool_TOOL::ParE(ii,TopoDS::Edge(fy));gp_Pnt2d uvff = TopOpeBRepTool_TOOL::UVF(parvff,C2DF);
572 // loe list of edges connexed to faultE
573 TopTools_ListOfShape loe; isb = CORRISO.Connexity(vff,loe);
574 if (!isb) return Standard_False; // FUNRAISE
575
576 TopTools_ListIteratorOfListOfShape ite(loe); // iteration on connex edges of vff
577 for (; ite.More(); ite.Next()){
578 const TopoDS_Edge& ee = TopoDS::Edge(ite.Value());
579 TopTools_Array1OfShape vee(1,2); TopOpeBRepTool_TOOL::Vertices(ee,vee);
580 for (Standard_Integer ive = 1; ive <=2; ive++) {
581 // ve = vertex[ive] of ee
582 const TopoDS_Vertex& ve = TopoDS::Vertex(vee(ive));
583 Standard_Boolean samev = ve.IsSame(vff);
584 if (!samev) continue;
585 if (ive == ii) continue;
586 TopOpeBRepTool_C2DF C2DFe; isb = CORRISO.UVRep(ee,C2DFe);
587 if (!isb) return Standard_False; // FUNRAISE
588 Standard_Real paree = TopOpeBRepTool_TOOL::ParE(ive,ee); gp_Pnt2d uve = TopOpeBRepTool_TOOL::UVF(paree,C2DFe);
589
590 // xxtrsl :
591 Standard_Real dxx = onU ? uve.X()-uvff.X() : uve.Y()-uvff.Y();
592 Standard_Boolean isper =( Abs(xperiod-Abs(dxx)) < xtol);
593 if (!isper) continue;
594
595 Standard_Integer recadre = (dxx > 0) ? INCREASE : DECREASE;
596 fyEds.Bind(fy,recadre);
597 } //ive=1..2
598 }//ite(loe)
599 }//ii=1..2
600 return !fyEds.IsEmpty();
601} // FUN_connexX
602
603//=======================================================================
604//function : CorrectONUVISO
605//purpose :
606//=======================================================================
607
608Standard_Boolean TopOpeBRepTool::CorrectONUVISO(const TopoDS_Face& Fin, TopoDS_Face& Fsp)
609// <Fref> is x-periodic
610{
611#ifdef DEB
612 Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
613 if (trc) cout<<"\n#### CorrectONUVISO ####\n\n";
614 debcorrUV();
615#endif
616
617 Standard_Real tolF = BRep_Tool::Tolerance(Fin);
618
619 TopOpeBRepTool_CORRISO CORRISO(Fin);
620 Standard_Real uperiod,vperiod;
621 Standard_Boolean uclosed = CORRISO.Refclosed(1,uperiod);
622 Standard_Boolean vclosed = CORRISO.Refclosed(2,vperiod);
623 if (!uclosed && !vclosed) return Standard_False;
624
625 CORRISO.Init(Fsp);
626 Standard_Boolean ok = CORRISO.UVClosed();
627 if (ok) return Standard_True; // Fsp is valid
628
629 // 1. We check connexity among all edges of <Fsp>
630 // if we find on edge with 2 faulty UVbounds, we try to UVconnect it.
631// for (Standard_Integer i=1; i<=2; i++) {
632 Standard_Integer i ;
633 for ( i=1; i<=2; i++) {
634 Standard_Boolean onU = (i==1) ? Standard_True : Standard_False;
635 const TopTools_ListOfShape& Tocheck = CORRISO.Eds();
636 TopTools_DataMapOfOrientedShapeInteger fyEds; ok =::FUN_connexX(onU,CORRISO,Tocheck,fyEds);
637 if (!ok) continue;
638 ok = CORRISO.TrslUV(onU,fyEds);
639 if (!ok) continue;
640 ok = CORRISO.UVClosed();
641 if (!ok) continue;
642 ok = CORRISO.GetnewS(Fsp);
643 if (!ok) return Standard_False; //NYIRAISE
644 return Standard_True;
645 }
646
647 // 2. x-2drep(edges) are in [xfirst,xfirst+xperiod]
648 for (i = 1; i <=2; i++) {
649 Standard_Boolean onU = (i==1);
650 Standard_Real xper=0.; Standard_Boolean xclosed = CORRISO.Refclosed(i,xper);
651 if (!xclosed) continue;
652 Standard_Real tolx = CORRISO.Tol(i,tolF);
653 tolx *= 1.e2; // BUC60380
654 TopTools_DataMapOfOrientedShapeInteger FyEds; Standard_Boolean hasfy = CORRISO.EdgesOUTofBoundsUV(CORRISO.Eds(),onU,tolx,FyEds);
655 if (!hasfy) continue;
656 ok = CORRISO.TrslUV(onU,FyEds);
657 if (!ok) return Standard_False;
658 ok = CORRISO.UVClosed();
659 if (!ok) continue;
660 ok = CORRISO.GetnewS(Fsp);
661 if (!ok) return Standard_False; //NYIRAISE
662 return Standard_True;
663 }
664 return Standard_False;
665
666 /*// xpu310898 : eC closing ff, ff sdm F(reference face), proj(eC,F) gives ee with
667 // !closing(ee,Fsp) -> 2drep(Fsp) is not closed.
668 // purpose : translate pceCFOR or pceCREV
669 // cto902B7 (ff=f7,eC=e9,F=f14)
670 ok = ::FUN_tool_reguUV(Fin,Fsp);*/
671
672 /*// JYL 980909 : reecriture complete
673 // 1/ traitement de TOUTES les aretes
674 // isou et isov fautives (et non la premiere trouvee);
675 // 2/ traitement des aretes degenerees fautives : CTS20973
676
677 TopTools_ListOfShape lisoe,ldege;
678 TopExp_Explorer exe(Fsp, TopAbs_EDGE);
679 for (; exe.More(); exe.Next()){
680 const TopoDS_Edge& E = TopoDS::Edge(exe.Current());
681 Standard_Boolean degen = BRep_Tool::Degenerated(E);
682 if ( degen ) {
683 ldege.Append(E);
684 }
685 else {
686 Standard_Real f,l; Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,Fin,f,l);
687 Standard_Boolean uiso,viso; gp_Dir2d d2d; gp_Pnt2d O2d;
688 Standard_Boolean uviso = FUN_tool_IsUViso(PC,uiso,viso,d2d,O2d);
689 Standard_Boolean onclosing = (uiso && uclosed) || (viso && vclosed);
690 if ( onclosing) {
691 lisoe.Append(E);
692 }
693 }
694 }
695
696 Standard_Integer nisoe = lisoe.Extent();
697 Standard_Integer ndege = ldege.Extent();
698 if (nisoe ==0 && ndege == 0) return Standard_False;
699
700 Standard_Integer tmpisoe;
701 Standard_Integer tmpdege;
702
703 TopTools_ListOfShape lfyisoe; Standard_Boolean tocorrectisoe = Standard_False;
704 tocorrectisoe = FUN_DetectEdgeswithfaultyUV(Fsp,Fsp,lisoe,Standard_True,lfyisoe,tmpisoe);
705
706 TopTools_ListOfShape lfydege; Standard_Boolean tocorrectdege = Standard_False;
707 tocorrectdege = FUN_DetectEdgeswithfaultyUV(Fsp,Fsp,ldege,Standard_True,lfydege,tmpdege);
708
709 tocorrect = (tocorrectisoe || tocorrectdege);
710 if (!tocorrect) {
711 return Standard_True;
712 }
713
714#ifdef DEB
715 if (trc) {
716 cout<<"CorrectONUVISO ";
717 cout<<"iso faulty "<<tocorrectisoe<<" deg faulty "<<tocorrectdege<<endl;;
718 }
719 debcorrUV();
720#endif
721
722 if (tocorrectisoe) {
723 for (TopTools_ListIteratorOfListOfShape itiso(lfyisoe);itiso.More();itiso.Next()) {
724 TopoDS_Edge& fyisoe = TopoDS::Edge(itiso.Value());
725
726 // !! if the faulty edge ON closing appears twice in <Eds>, NOTHING is done!
727 // -> see processing ::PurgeClosingEdges later called in WESMakeFaces
728 Standard_Integer nfoundisoe = 0;
729 for (exe.Init(Fsp, TopAbs_EDGE); exe.More(); exe.Next()) {
730 if (exe.Current().IsSame(fyisoe)) {
731 nfoundisoe++;
732 }
733 }
734 if (nfoundisoe > 1) {
735 continue;
736 }
737
738#ifdef DRAW
739 if (trc) {
740 cout<<"TopOpeBRepTool correctONUVISO : faulty iso edge"<<endl;
741 FUN_tool_draw("fyf",Fsp);FUN_tool_draw("fyisoe",fyisoe);
742 }
743#endif
744
745 Standard_Boolean ok = ::FUN_correctClosingE(fyisoe,Fsp);
746 if (!ok) {
747 FUN_Raise();
748 continue;
749 }
750 }
751
752 Standard_Integer tmpisoe;
753 TopTools_ListOfShape lffyisoe; tocorrectisoe = FUN_DetectEdgeswithfaultyUV(Fsp,Fsp,lfyisoe,Standard_False,lffyisoe,tmpisoe);
754 } // end lffyisoe process
755
756 if (tocorrectdege) {
757 TopTools_IndexedDataMapOfShapeListOfShape mve;
758 TopExp::MapShapesAndAncestors(Fsp,TopAbs_VERTEX,TopAbs_EDGE,mve);
759
760 for (TopTools_ListIteratorOfListOfShape itdeg(lfydege);itdeg.More();itdeg.Next()) {
761 TopoDS_Edge& fydege = TopoDS::Edge(itdeg.Value());
762
763#ifdef DRAW
764 if (trc) {
765 cout<<"TopOpeBRepTool correctONUVISO : faulty deg edge"<<endl;
766 FUN_tool_draw("fyf",Fsp);FUN_tool_draw("fydege",fydege);
767 }
768#endif
769
770 Standard_Boolean ok = ::FUN_correctDegeneratedE(mve,fydege,Fsp);
771 if (!ok) {
772 FUN_Raise();
773 continue;
774 }
775 } // itdeg
776
777 TopTools_ListOfShape lffydege; tocorrectdege = FUN_DetectEdgeswithfaultyUV(Fsp,Fsp,lfydege,Standard_False,lffydege,tmpdege);
778 } // end lfydege process
779
780 TopTools_ListOfShape eFsp; FUN_tool_shapes(Fsp,TopAbs_EDGE,eFsp);
781 TopTools_ListOfShape lffydege; tocorrect = FUN_DetectEdgeswithfaultyUV(Fsp,Fsp,eFsp,Standard_False,lffydege,tmpdege);
782 Standard_Boolean done = !tocorrect;
783 return done;*/
784
785} // correctONUVISO
786
787//=======================================================================
788//function : MakeFaces
789//purpose :
790//=======================================================================
791
792Standard_Boolean TopOpeBRepTool::MakeFaces(const TopoDS_Face& Fin, const TopTools_ListOfShape& LOF,
793 const TopTools_IndexedMapOfOrientedShape& MshNOK,
794 TopTools_ListOfShape& LOFF)
795{
796// TopOpeBRepDS_BuildTool BT;
797 BRep_Builder BB;
798 LOFF.Clear();
799 TopTools_ListIteratorOfListOfShape it(LOF);
800 for (; it.More(); it.Next()){
801 const TopoDS_Face& FF = TopoDS::Face(it.Value());
802 Standard_Boolean valid = !MshNOK.Contains(FF);
803 if (valid) {LOFF.Append(FF); continue;}
804
805 TopoDS_Shape aLocalShape = Fin.EmptyCopied();
806 TopoDS_Face newFace = TopoDS::Face(aLocalShape);// BT.CopyFace(Fin,newFace);
807// TopoDS_Face newFace = TopoDS::Face(Fin.EmptyCopied());// BT.CopyFace(Fin,newFace);
808 TopExp_Explorer exw(FF, TopAbs_WIRE);
809
810 for (; exw.More(); exw.Next()){
811 const TopoDS_Wire& W = TopoDS::Wire(exw.Current());
812 valid = !MshNOK.Contains(W);
813 // if (valid) {BT.AddFaceWire(newFace,W); continue;}
814 if (valid) {BB.Add(newFace,W); continue;}
815
816 TopoDS_Wire newWire; //BT.MakeWire(newWire);
817 BB.MakeWire(newWire);
818 TopExp_Explorer exe(W, TopAbs_EDGE);
819 Standard_Integer ne = 0;
820 for (; exe.More(); exe.Next()){
821 const TopoDS_Edge& E = TopoDS::Edge(exe.Current());
822 valid = !MshNOK.Contains(E);
823 if (!valid) continue;
824 // BT.AddWireEdge(newWire,E);
825 BB.Add(newWire,E);
826 ne++;
827 } // exe
828 if (ne == 0) continue;
829 Standard_Boolean closed = FUN_tool_ClosedW(newWire);
830 // BT.Closed(newWire,closed);
831 // BT.AddFaceWire(newFace,newWire);
832 newWire.Closed(closed);
833 BB.Add(newFace,newWire);
834 } // exw
835 LOFF.Append(newFace);
836 }
837 return Standard_True;
838}
839
840/*static Handle(Geom2d_TrimmedCurve) FUN_translate(const gp_Vec2d& tvector, const TopoDS_Face& fF, TopoDS_Edge& fyE)
841{
842 Standard_Real f,l,tol; Handle(Geom2d_Curve) PC = FUNTOOLC2D_CurveOnSurface(fyE,fF,f,l,tol);
843 Standard_Boolean isou,isov; gp_Pnt2d o2d; gp_Dir2d d2d;
844 Standard_Boolean isouv = FUN_tool_IsUViso(PC,isou,isov,d2d,o2d); o2d.Translate(tvector);
845 Handle(Geom2d_Line) L2d = new Geom2d_Line(o2d,d2d);
846 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(L2d,f,l);
847 return C2d;
848}
849Standard_EXPORT void FUN_tool_ttranslate(const gp_Vec2d& tvector, const TopoDS_Face& fF, TopoDS_Edge& fyE)
850{
851 Handle(Geom2d_TrimmedCurve) C2d = ::FUN_translate(tvector,fF,fyE);
852 Standard_Real tole = BRep_Tool::Tolerance(fyE);
853 BRep_Builder BB;
854// Handle(Geom2d_Curve) toclear; BB.UpdateEdge(fyE,toclear,fF,tole);
855 BB.UpdateEdge(fyE,C2d,fF,tole);
856}
857
858static Standard_Boolean FUN_tool_translate(const gp_Vec2d& tvector, TopoDS_Face& fF, TopoDS_Edge& fyE)
859 // prequesitory : <fF> is on periodic surface, translates edge
860 // <fyE>'s uorviso to have its uorvpar bounded in [0.,2PI].
861{
862 Handle(Geom2d_TrimmedCurve) C2d = ::FUN_translate(tvector,fF,fyE);
863 Standard_Real tole = BRep_Tool::Tolerance(fyE);
864
865 //xpu040598 : CTS20280 f37 modified when its split is modified!
866 TopoDS_Face newf; Standard_Boolean ok = FUN_tool_pcurveonF(fF,fyE,C2d,newf);
867 if (ok) fF = newf;
868 return ok;
869 //xpu040598
870}
871*/