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