1 // Created on: 1997-01-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <Geom2d_Curve.hxx>
21 #include <Geom2d_TrimmedCurve.hxx>
22 #include <Geom_Curve.hxx>
23 #include <GeomAPI_ProjectPointOnCurve.hxx>
25 #include <Standard_NoSuchObject.hxx>
26 #include <Standard_ProgramError.hxx>
27 #include <TCollection_AsciiString.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <TopOpeBRepBuild_Builder.hxx>
35 #include <TopOpeBRepBuild_define.hxx>
36 #include <TopOpeBRepBuild_EdgeBuilder.hxx>
37 #include <TopOpeBRepBuild_FaceBuilder.hxx>
38 #include <TopOpeBRepBuild_GTool.hxx>
39 #include <TopOpeBRepBuild_GTopo.hxx>
40 #include <TopOpeBRepBuild_HBuilder.hxx>
41 #include <TopOpeBRepBuild_PaveSet.hxx>
42 #include <TopOpeBRepBuild_ShapeSet.hxx>
43 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
44 #include <TopOpeBRepBuild_SolidBuilder.hxx>
45 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
46 #include <TopOpeBRepDS_BuildTool.hxx>
47 #include <TopOpeBRepDS_connex.hxx>
48 #include <TopOpeBRepDS_CurveExplorer.hxx>
49 #include <TopOpeBRepDS_CurveIterator.hxx>
50 #include <TopOpeBRepDS_EXPORT.hxx>
51 #include <TopOpeBRepDS_HDataStructure.hxx>
52 #include <TopOpeBRepDS_PointIterator.hxx>
53 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
54 #include <TopOpeBRepDS_SurfaceIterator.hxx>
55 #include <TopOpeBRepDS_TKI.hxx>
56 #include <TopOpeBRepTool_2d.hxx>
57 #include <TopOpeBRepTool_CurveTool.hxx>
58 #include <TopOpeBRepTool_EXPORT.hxx>
59 #include <TopOpeBRepTool_ShapeExplorer.hxx>
60 #include <TopOpeBRepTool_TOOL.hxx>
62 #define MGhc3 Handle(Geom_Curve)
63 #define MGhc2 Handle(Geom2d_Curve)
66 extern Standard_Boolean TopOpeBRepBuild_GettraceSPS();
67 Standard_EXPORT void debsplitse(const Standard_Integer) {}
68 Standard_EXPORT void debsplitsemess(const Standard_Integer i,const TCollection_AsciiString& s = "");
69 Standard_EXPORT void debsplitsemess(const Standard_Integer i,const TCollection_AsciiString& s){cout<<"+++ debsplitse "<<s<<" E"<<i<<endl;debsplitse(i);}
70 Standard_EXPORT void debspseou(const Standard_Integer i) {debsplitsemess(i,"OUT");}
71 Standard_EXPORT void debspsein(const Standard_Integer i) {debsplitsemess(i,"IN ");}
72 Standard_EXPORT void debspseon(const Standard_Integer i) {debsplitsemess(i,"ON ");}
73 extern Standard_Boolean TopOpeBRepTool_GettraceC2D();
77 #include <TopOpeBRepTool_DRAW.hxx>
80 //Standard_IMPORT void FUN_tool_ttranslate(const gp_Vec2d& tvector, const TopoDS_Face& fF, TopoDS_Edge& fyE);
82 #include <TopOpeBRepTool_ShapeTool.hxx>
83 #include <GeomAdaptor_Surface.hxx>
84 #include <GeomAbs_SurfaceType.hxx>
85 //---------------------------------------------
86 static Standard_Boolean FUN_periodicS(const TopoDS_Shape& F)
87 //---------------------------------------------
89 if (F.IsNull()) return Standard_False;
90 if (F.ShapeType() != TopAbs_FACE) return Standard_False;
91 Handle(Geom_Surface) SSS = TopOpeBRepTool_ShapeTool::BASISSURFACE(TopoDS::Face(F));
92 GeomAdaptor_Surface GAS(SSS);
93 GeomAbs_SurfaceType styp = GAS.GetType();
94 Standard_Boolean periodic = Standard_False;
95 if (styp == GeomAbs_Cylinder) periodic = Standard_True;
96 if (styp == GeomAbs_Cone) periodic = Standard_True;
97 if (styp == GeomAbs_Sphere) periodic = Standard_True;
98 // NYI : for Torus,SurfaceOfRevolution..
102 static Standard_Boolean FUN_periodic(const TopoDS_Face& F,Standard_Boolean& uper,Standard_Boolean& vper)
104 const Handle(Geom_Surface)& su = BRep_Tool::Surface(F);
105 uper = su->IsUPeriodic();
106 vper = su->IsVPeriodic();
107 Standard_Boolean per = (uper || vper);
111 static Standard_Boolean FUN_onboundsper(const gp_Pnt2d& uv,const TopoDS_Face& F)
114 const Handle(Geom_Surface)& su = BRep_Tool::Surface(F);
115 Standard_Boolean uclo = su->IsUPeriodic();
116 Standard_Boolean vclo = su->IsVPeriodic();
117 if (!uclo && !vclo) return Standard_False;
119 Standard_Real u1,u2,v1,v2; su->Bounds(u1,u2,v1,v2);
120 Standard_Real toluv = 1.e-8*1.e-2; // nyinyitol
122 Standard_Real d1 = Abs(u1-uv.X()); Standard_Boolean on1 = (d1 < toluv);
123 Standard_Real d2 = Abs(u2-uv.X()); Standard_Boolean on2 = (d2 < toluv);
127 Standard_Real d1 = Abs(v1-uv.Y()); Standard_Boolean on1 = (d1 < toluv);
128 Standard_Real d2 = Abs(v2-uv.Y()); Standard_Boolean on2 = (d2 < toluv);
131 return Standard_False;
134 static Standard_Boolean FUN_onboundsper(const TopoDS_Edge& E,const TopoDS_Face& F, gp_Pnt2d& uv)
135 // uv is found by projection pnt(E,par)
138 Standard_Real f,l; FUN_tool_bounds(E,f,l); Standard_Real x=0.45678; Standard_Real par=f*x+(1-x)*l;
139 Standard_Real tolF = BRep_Tool::Tolerance(F)*1.e2; // nyitol
140 Standard_Boolean ok = FUN_tool_parF(E,par,F,uv,tolF);
141 if (!ok) return Standard_False;
143 Standard_Boolean onbp = ::FUN_onboundsper(uv,F);
149 //-----------------------------------------------------------------------
150 static Standard_Boolean FUN_PinC(const gp_Pnt& P,const Handle(Geom_Curve)& C,const Standard_Real pmin,const Standard_Real pmax,const Standard_Real tol)
151 //-----------------------------------------------------------------------
153 Standard_Boolean PinC = Standard_False;
154 GeomAPI_ProjectPointOnCurve mydm(P,C,pmin,pmax);
155 Standard_Boolean dmdone = ( mydm.Extrema().IsDone() );
157 if ( mydm.NbPoints() ) {
158 Standard_Real d = mydm.LowerDistance();
165 //-----------------------------------------------------------------------
166 static Standard_Boolean FUN_PinE(const gp_Pnt& P, const TopoDS_Edge& E)
167 //-----------------------------------------------------------------------
169 Standard_Boolean PinE = Standard_False;
170 Standard_Real f,l; Handle(Geom_Curve) CE = BRep_Tool::Curve(E,f,l);
171 Standard_Real tolE = BRep_Tool::Tolerance(E);
172 PinE = FUN_PinC(P,CE,f,l,tolE);
176 #include <BRep_Tool.hxx>
177 #include <TopOpeBRepDS_ShapeShapeInterference.hxx>
178 //-----------------------------------------------------------------------
179 static Standard_Boolean FUN_EstaEE(const TopoDS_Edge& E, const TopAbs_State sta, const TopoDS_Edge& EE)
180 //-----------------------------------------------------------------------
182 Standard_Boolean EinEE = Standard_False;
184 //modified by NIZNHY-PKV Wed Nov 3 11:40:14 1999 from
186 if (BRep_Tool::Degenerated(E)) {
187 if (sta == TopAbs_IN) return Standard_False;
188 else return Standard_True;
190 //modified by NIZNHY-PKV Wed Nov 3 11:40:19 1999 to
192 Handle(Geom_Curve) CE = BRep_Tool::Curve(E,f,l);
193 Standard_Real t = 0.417789; // Oi blya... ???
194 Standard_Real p = (1-t)*f + t*l;
195 gp_Pnt P = CE->Value(p);
196 EinEE = FUN_PinE(P,EE);
197 if (sta == TopAbs_IN) return EinEE;
198 else if (sta == TopAbs_OUT) return !EinEE;
199 else throw Standard_ProgramError("TopOpeBRepBuild FUN_EstaEE on invalid state");
202 //=======================================================================
203 //function : TopOpeBRepBuild_Builder::InitSection
205 //=======================================================================
206 void TopOpeBRepBuild_Builder::InitSection()
208 mySectionDone = Standard_False;
210 mySplitSectionEdgesDone = Standard_False;
214 //-----------------------------------------------------------------------
215 // LE : list of edges from where is extracted LEsta = edges located <sta> / edge E
216 // N.B. : LEsta is expanded and NOT reinitialized
217 static void FUN_selLEE(TopTools_ListOfShape& LE,const TopoDS_Edge& E,const TopAbs_State sta,TopTools_ListOfShape& LEsta)
219 TopTools_ListIteratorOfListOfShape it(LE);
221 const TopoDS_Edge& Ecur = TopoDS::Edge(it.Value());
222 Standard_Boolean ok = FUN_EstaEE(Ecur,sta,E);
231 //-----------------------------------------------------------------------
232 // search the existence of shape E in time as shape of a mesh cell
233 // (shape,listofshape) of the list loslos.
234 Standard_Boolean FUN_FindEinSLOS(const TopoDS_Shape& E,const TopOpeBRepBuild_ListOfShapeListOfShape& loslos)
236 Standard_Boolean f = Standard_False;
237 for (TopOpeBRepBuild_ListIteratorOfListOfShapeListOfShape it(loslos); it.More(); it.Next()) {
238 const TopoDS_Shape& S = it.Value().Shape();
239 Standard_Boolean issame = (S.IsSame(E));
248 //=======================================================================
249 //function : SplitSectionEdges
251 //=======================================================================
252 void TopOpeBRepBuild_Builder::SplitSectionEdges()
254 if (mySplitSectionEdgesDone) return;
256 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
257 Standard_Integer i,n = BDS.NbSectionEdges();
259 for (i = 1; i <= n; i++) { // 1
260 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
261 if(E.IsNull()) continue;
265 TopOpeBRepBuild_DataMapOfShapeListOfShapeListOfShape MEIN;
266 TopTools_DataMapOfShapeListOfShape MEOUT;
268 for (i = 1; i <= n; i++) { // 2
269 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
270 if(E.IsNull()) continue;
271 Standard_Integer iE = myDataStructure->Shape(E);
272 Standard_Integer rE = BDS.AncestorRank(E);
275 Standard_Boolean tSPS = GtraceSPS(E,iE); if (tSPS) debsplitsemess(iE); Standard_Integer DEBiESD = 1;
278 Standard_Boolean isspliton = IsSplit(E,TopAbs_ON);
279 if (!isspliton) continue;
281 const TopTools_ListOfShape& LESD = BDS.ShapeSameDomain(E);
282 if ( LESD.IsEmpty() ) continue;
284 const TopTools_ListOfShape& LEspon = Splits(E,TopAbs_ON);
285 TopTools_ListOfShape LEoutLESD; GCopyList(LEspon,LEoutLESD);
286 Standard_Integer iRef = BDS.SameDomainRef(E);
288 // LEoutLESD = list of edges Split(E,ON) OUT of all
289 // edges of the list of edges same domain of E in 3d only
290 // edges LEoutLESD are attached in Split(ON) to E only.
292 for (TopTools_ListIteratorOfListOfShape itLESD(LESD); itLESD.More(); itLESD.Next()) { // 2.1
293 const TopoDS_Edge& ESD = TopoDS::Edge(itLESD.Value());
294 Standard_Integer iESD = myDataStructure->Shape(ESD);
295 const TopTools_ListOfShape& LESDspon = Splits(ESD,TopAbs_ON);
299 TCollection_AsciiString str("# edge ");str=str+iE+" sd3d edge "+iESD;
300 TCollection_AsciiString stru(str.Length(),'-');
301 cout<<endl;if(DEBiESD==1)cout<<stru<<endl;
302 DEBiESD++;cout<<str<<endl;debsplitsemess(iE);
306 // reduction of LEoutLESD = edges OUT all ESD
307 TopTools_ListOfShape dummylos;
308 FUN_selLEE(LEoutLESD,ESD,TopAbs_IN,dummylos);
310 const TopoDS_Edge *pE1 = NULL, *pE2 = NULL;
311 const TopTools_ListOfShape *plos1 = NULL, *plos2 = NULL;
312 Standard_Integer nLEspon = LEspon.Extent();
313 Standard_Integer nLESDspon = LESDspon.Extent();
315 if ( nLEspon != 0 && nLESDspon != 0 ) {
316 Standard_Boolean takeE = ((rE == 1 && iESD != iRef) || iE == iRef);
317 pE1 = takeE ? &E : &ESD;
318 pE2 = !takeE ? &E : &ESD;
319 plos1 = takeE ? &LEspon : &LESDspon;
320 plos2 = !takeE ? &LEspon : &LESDspon;
322 else if ( nLEspon != 0 ) {
328 else if ( nLESDspon != 0 ) {
335 if (pE1 == NULL || pE2 == NULL) continue;
336 if (plos1 == NULL || plos2 == NULL) continue;
338 const TopoDS_Edge& E1 = *pE1;
339 const TopoDS_Edge& E2 = *pE2;
340 const TopTools_ListOfShape& LE1 = *plos1;
342 // selection of edges IN E2 = LEinE2
343 TopTools_ListOfShape LE1loc;
344 GCopyList(LE1,LE1loc);
345 TopTools_ListOfShape LE1inE2;
346 FUN_selLEE(LE1loc,E2,TopAbs_IN,LE1inE2);
347 Standard_Integer nLE1inE2 = LE1inE2.Extent();
351 cout<<"# edges ON "<<iE<<" ";
352 TopAbs::Print(TopAbs_IN,cout); cout<<" / esd";
354 cout<<" : ("<<nLE1inE2<<")"<<endl;
355 TCollection_AsciiString str("ON");str=str+iE+"IN"+iESD;
356 FDRAW_DINLOE(" ",LE1inE2,str,"");
360 // edges E1 and E2 share LE1inE2
361 if (nLE1inE2 != 0) { // 2.2
363 Standard_Boolean E1b = MEIN.IsBound(E1);
364 TopOpeBRepBuild_ListOfShapeListOfShape thelist;
365 if (!E1b) MEIN.Bind(E1, thelist);
366 TopOpeBRepBuild_ListOfShapeListOfShape& LE1loslos = MEIN.ChangeFind(E1);
368 // Standard_Integer nLE1 = LE1loslos.Extent();
371 Standard_Boolean E2b = MEIN.IsBound(E2);
372 TopOpeBRepBuild_ListOfShapeListOfShape thelist2;
373 if (!E2b) MEIN.Bind(E2,thelist2);
374 TopOpeBRepBuild_ListOfShapeListOfShape& LE2loslos = MEIN.ChangeFind(E2);
376 // Standard_Integer nLE2 = LE2loslos.Extent();
379 Standard_Boolean E2elemofE1 = FUN_FindEinSLOS(E2,LE1loslos);
380 Standard_Boolean E1elemofE2 = FUN_FindEinSLOS(E1,LE2loslos);
382 Standard_Boolean condadd = (!E2elemofE1 && !E1elemofE2);
384 // regularization of edges of LE1inE2 -> LR
385 TopTools_ListOfShape LR;
386 for (TopTools_ListIteratorOfListOfShape ite(LE1inE2);ite.More();ite.Next()){
387 const TopoDS_Edge& e = TopoDS::Edge(ite.Value());
388 TopTools_ListOfShape newle; Standard_Boolean ok = TopOpeBRepTool_TOOL::SplitE(e,newle);
389 if (ok) LR.Append(newle);
393 TopOpeBRepBuild_ShapeListOfShape thelist3;
394 LE1loslos.Append(thelist3);
395 TopOpeBRepBuild_ShapeListOfShape& E1slos = LE1loslos.Last();
396 E1slos.ChangeShape() = E2;
397 GCopyList(LR,E1slos.ChangeList());
400 TopOpeBRepBuild_ShapeListOfShape thelist4;
401 LE2loslos.Append(thelist4);
402 TopOpeBRepBuild_ShapeListOfShape& E2slos = LE2loslos.Last();
403 E2slos.ChangeShape() = E1;
404 GCopyList(LR,E2slos.ChangeList());
412 cout<<endl<<"# edges ON "<<iE<<" ";
413 TopAbs::Print(TopAbs_OUT,cout);cout<<" / lesd";
414 for(TopTools_ListIteratorOfListOfShape it(LESD);it.More();it.Next())
415 cout<<" "<<myDataStructure->Shape(it.Value());
416 Standard_Integer n=LEoutLESD.Extent();cout<<" : ("<<n<<")"<<endl;
417 TCollection_AsciiString str("ON");str=str+iE+"OUT";
418 FDRAW_DINLOE(" ",LEoutLESD,str,"");
422 if (!MEOUT.IsBound(E)) {
423 TopTools_ListOfShape thelist5;
424 MEOUT.Bind(E, thelist5);
426 GCopyList(LEoutLESD,MEOUT.ChangeFind(E));
430 for (i = 1; i <= n; i++) { // 3
431 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
432 if(E.IsNull()) continue;
434 Standard_Integer iE = myDataStructure->Shape(E);
435 // Standard_Integer rE = GShapeRank(E);
436 Standard_Boolean tSPS = GtraceSPS(E,iE);
437 if (tSPS) debsplitsemess(iE);
440 Standard_Boolean isspliton = IsSplit(E,TopAbs_ON);;
441 if (!isspliton) continue;
443 const TopTools_ListOfShape& LESD = BDS.ShapeSameDomain(E);
444 if ( LESD.IsEmpty() ) continue;
446 Standard_Boolean isbMEOUT = MEOUT.IsBound(E);
447 Standard_Boolean isbMEIN = MEIN.IsBound(E);
448 if (!isbMEOUT && !isbMEIN) continue;
450 TopTools_ListOfShape& LEspon = ChangeSplit(E,TopAbs_ON);
454 const TopTools_ListOfShape& LEOUT = MEOUT.Find(E);
456 // Standard_Integer nOUT = LEOUT.Extent();
458 GCopyList(LEOUT,LEspon);
462 const TopOpeBRepBuild_ListOfShapeListOfShape& loslos = MEIN.Find(E);
464 // Standard_Integer nloslos = loslos.Extent();
466 for (TopOpeBRepBuild_ListIteratorOfListOfShapeListOfShape it(loslos); it.More(); it.Next()) {
467 const TopTools_ListOfShape& los = it.Value().List();
469 // Standard_Integer nlos = los.Extent();
471 GCopyList(los,LEspon);
477 for (i = 1; i <= n; i++) { // 4
478 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i)); if(E.IsNull()) continue;
480 Standard_Integer idebE; Standard_Boolean tSPS = GtraceSPS(E,idebE); if (tSPS) debsplitsemess(idebE);
482 const TopTools_ListOfShape& lesd = BDS.ShapeSameDomain(E);
483 if (lesd.IsEmpty()) continue;
485 Standard_Integer iE = BDS.Shape(E);
487 // Standard_Integer rE = BDS.AncestorRank(E);
489 Standard_Integer RE = BDS.SameDomainRef(E);
490 if (iE != RE) continue;
492 TopTools_ListOfShape lF; TopTools_ListIteratorOfListOfShape itlesd;
493 for(itlesd.Initialize(lesd);itlesd.More();itlesd.Next()) {
494 const TopoDS_Edge& esd = TopoDS::Edge(itlesd.Value());
496 // Standard_Integer iesd = BDS.Shape(esd);
498 const TopTools_ListOfShape& lf = FDSCNX_EdgeConnexitySameShape(esd,myDataStructure);
502 // Standard_Integer nlF = lF.Extent();
505 TopTools_ListOfShape& lon = ChangeSplit(E,TopAbs_ON);
506 Standard_Real tolE = BRep_Tool::Tolerance(E);
507 TopTools_ListIteratorOfListOfShape it(lF); for(;it.More();it.Next()) {
508 const TopoDS_Face& F = TopoDS::Face(it.Value());
509 Standard_Integer iF = BDS.Shape(F); Standard_Integer rF = BDS.AncestorRank(iF);
511 TopoDS_Edge esdF; Standard_Boolean besdF = Standard_False; // NYI pointer on esdF
512 for(itlesd.Initialize(lesd);itlesd.More();itlesd.Next()) {
513 const TopoDS_Edge& esd = TopoDS::Edge(itlesd.Value());
514 Standard_Integer iesd = BDS.Shape(esd); Standard_Integer resd = BDS.AncestorRank(iesd);
517 for (ex.Init(F,TopAbs_EDGE);ex.More();ex.Next()) {
518 // for (TopExp_Explorer ex(F,TopAbs_EDGE);ex.More();ex.Next()) {
519 const TopoDS_Shape& ee = ex.Current();
520 Standard_Boolean eq = (ee.IsEqual(esd));
521 if (eq) { esdF = esd; besdF = Standard_True; break; }
527 TopTools_ListIteratorOfListOfShape itlon(lon); for(;itlon.More();itlon.Next()) {
528 TopoDS_Edge& eon = TopoDS::Edge(itlon.Value());
529 Standard_Real f,l; Standard_Boolean hasPC = FC2D_HasCurveOnSurface(eon,F);
532 if (TopOpeBRepTool_GettraceC2D()) {
533 cout<<"\n#TopOpeBRepBuild_Builder::SSE : hasPC = 0 ES"<<i<<" E"<<idebE<<" sur F"<<iF<<endl;
534 cout<<"tsee s "<<iF<<" "<<idebE<<";"<<endl;
537 // Standard_Real tolpc; MGhc2 PC = FC2D_CurveOnSurface(eon,F,esdF,f,l,tolpc);
538 Standard_Real tolpc; MGhc2 PC = FC2D_CurveOnSurface(eon,F,esdF,f,l,tolpc,Standard_True);//xpu051198 :PRO15049
539 hasPC = (!PC.IsNull());
540 if (!hasPC) throw Standard_ProgramError("TopOpeBRepBuild_Builder::SSE null PC on F");
541 Standard_Real tol = Max(tolE,tolpc);
542 BB.UpdateEdge(eon,PC,F,tol);
547 Standard_Integer nsha = BDS.NbShapes();
548 for (i = 1; i <= nsha; i++) { // 5
549 const TopoDS_Shape& FOR = myDataStructure->Shape(i);
550 Standard_Boolean isface = (FOR.ShapeType() == TopAbs_FACE);
551 if (!isface) continue;
552 const TopoDS_Face& FF = TopoDS::Face(FOR);
554 // Standard_Integer iFF = BDS.Shape(FF);
556 const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(FF); Standard_Integer nLI = LI.Extent();
557 if (nLI == 0) continue;
558 for (TopOpeBRepDS_ListIteratorOfListOfInterference ILI(LI); ILI.More(); ILI.Next() ) {
559 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI (Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(ILI.Value()));
560 if (SSI.IsNull()) continue;
561 TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(SSI,GT,GI,ST,SI);
562 if (ST != TopOpeBRepDS_FACE) continue;
563 const TopOpeBRepDS_Transition& TFE = SSI->Transition();
564 TopAbs_ShapeEnum shab = TFE.ShapeBefore(),shaa = TFE.ShapeAfter();
565 if (shaa != TopAbs_FACE || shab != TopAbs_FACE) continue;
566 const TopoDS_Face& FS = TopoDS::Face( myDataStructure->Shape(SI));
568 // Standard_Integer iFS = myDataStructure->Shape(FS);
570 Standard_Boolean FSisper = FUN_periodicS(FS);
571 if (!FSisper) continue;
573 const TopoDS_Edge& EG = TopoDS::Edge(myDataStructure->Shape(GI));
575 // Standard_Integer iEG = myDataStructure->Shape(EG);
577 Standard_Boolean isrest = myDataStructure->DS().IsSectionEdge(EG); if (!isrest) continue;
579 // Standard_Real tolE = BRep_Tool::Tolerance(EG);
581 Standard_Boolean haspc = FC2D_HasCurveOnSurface(EG,FS); if (haspc) continue;
582 Standard_Boolean hasc3d = FC2D_HasC3D(EG);
583 if (!hasc3d) throw Standard_ProgramError("TopOpeBRepBuild_Builder::SSE EG without C3D");
584 Standard_Real pf,pl,tolpc; Handle(Geom2d_Curve) PC;
585 Standard_Boolean trim3d = Standard_True; PC = FC2D_CurveOnSurface(EG,FS,pf,pl,tolpc,trim3d);
586 if (PC.IsNull()) throw Standard_ProgramError("TopOpeBRepBuild_Builder::SSE EG without PC on FS");
590 for (i = 1; i <= nsha; i++) { // 6
591 // xpu201198, for all periodic surfaces
592 const TopoDS_Shape& FOR = myDataStructure->Shape(i);
593 Standard_Boolean isface = (FOR.ShapeType() == TopAbs_FACE);
594 if (!isface) continue;
595 const TopoDS_Face& FF = TopoDS::Face(FOR);
597 // Standard_Integer iFF = BDS.Shape(FF);
599 Standard_Boolean FFuper,FFvper; Standard_Boolean FFisper = FUN_periodic(FF,FFuper,FFvper);
600 if (!FFisper) continue;
602 const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(FF); Standard_Integer nLI = LI.Extent();
603 if (nLI == 0) continue;
604 for (TopOpeBRepDS_ListIteratorOfListOfInterference ILI(LI); ILI.More(); ILI.Next() ) {
605 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI (Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(ILI.Value()));
606 if (SSI.IsNull()) continue;
607 TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(SSI,GT,GI,ST,SI);
608 if (ST != TopOpeBRepDS_FACE) continue;
609 Standard_Boolean GB = SSI->GBound();
610 if (GB == 1) continue;
612 const TopoDS_Edge& EG = TopoDS::Edge(myDataStructure->Shape(GI));
614 // Standard_Integer iEG = myDataStructure->Shape(EG);
616 Standard_Boolean isrest = myDataStructure->DS().IsSectionEdge(EG); if (!isrest) continue;
618 // xpu191198 : cto016*
619 Standard_Real pf,pl,tolpc; Handle(Geom2d_Curve) PC;
620 Standard_Boolean trim3d = Standard_True; PC = FC2D_CurveOnSurface(EG,FF,pf,pl,tolpc,trim3d);
621 Standard_Boolean isoU,isoV; gp_Pnt2d o2d; gp_Dir2d d2d;
622 Standard_Boolean ISO = TopOpeBRepTool_TOOL::UVISO(PC,isoU,isoV,d2d,o2d);
624 TopTools_ListIteratorOfListOfShape itON(Splits(EG,TopAbs_ON));
625 TopTools_ListOfShape newlON;
626 for (; itON.More(); itON.Next()){
627 TopoDS_Edge eon = TopoDS::Edge(itON.Value());
629 Standard_Real pfon,plon,tolpcon; Handle(Geom2d_Curve) PCon;
630 PCon = FC2D_CurveOnSurface(eon,FF,pfon,plon,tolpcon,trim3d);
632 Standard_Boolean isouon,isovon; gp_Pnt2d o2don; gp_Dir2d d2don;
633 Standard_Boolean ISOon = TopOpeBRepTool_TOOL::UVISO(PCon,isouon,isovon,d2don,o2don);
634 Standard_Boolean PCko = !ISOon || ((isoU && !isouon) || (isoV && !isovon));
635 if (PCko) throw Standard_ProgramError("TopOpeBRepBuild_Builder::splitON");
637 Standard_Boolean test = (FFuper && isoU) || (FFvper && isoV);
638 if (!test) { newlON.Append(eon); continue;}
640 gp_Pnt2d uvok; Standard_Boolean isonclo = FUN_onboundsper(eon,FF,uvok); //3d
641 if (isonclo) { newlON.Append(eon); continue;}
643 Standard_Boolean isonclo2 = FUN_onboundsper(o2don,FF); //2d
646 if (isoU) {Standard_Real dtr = uvok.X() - o2don.X();tr = gp_Vec2d(dtr,0.);}
647 else {Standard_Real dtr = uvok.Y() - o2don.Y();tr = gp_Vec2d(0.,dtr);}
648 Standard_Real mag = tr.Magnitude();
649 Standard_Real toluv = 1.e-8*1.e2; // NYINYI
650 if (mag > toluv) TopOpeBRepTool_TOOL::TrslUVModifE(tr,FF,eon);
654 TopTools_ListOfShape& nlON = ChangeSplit(EG,TopAbs_ON);
655 nlON.Clear(); nlON.Append(newlON);
659 mySplitSectionEdgesDone = Standard_True;
660 } // SplitSectionEdges
665 Standard_Integer GLOBAL_issp = 0; //++
669 Standard_EXPORT Standard_Integer GLOBAL_hassd = 0; //++
671 //=======================================================================
672 //function : SplitSectionEdge
674 //=======================================================================
675 void TopOpeBRepBuild_Builder::SplitSectionEdge(const TopoDS_Shape& EA)
678 Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EA,iE);
679 if (tSPS) debsplitsemess(iE);
682 TopOpeBRepDS_DataStructure& BDS = myDataStructure->ChangeDS();
683 const TopoDS_Edge& EOR = TopoDS::Edge(EA);
684 TopoDS_Edge EF = EOR; EF.Orientation(TopAbs_FORWARD);
685 Standard_Integer rankEF = myDataStructure->DS().AncestorRank(EF); // GShapeRank <- GMapShapes, appele par Merge
687 // FUN_removeonGB(myDataStructure,EOR); //xpu041198
689 Standard_Boolean hg = myDataStructure->HasGeometry(EOR);
690 Standard_Boolean hsd3d = FDS_HasSameDomain3d(BDS,EOR);
691 Standard_Boolean hsd2d = FDS_HasSameDomain2d(BDS,EOR);
693 Standard_Boolean issplit = IsSplit(EOR,TopAbs_ON);
696 Standard_Boolean cond = (hg || hsd3d); //REST2 //( hg && (!hsd) );
698 GLOBAL_hassd = 0; // initializing
699 if(hsd3d) GLOBAL_hassd=3; //++
700 if(hsd2d) GLOBAL_hassd=2; //++
702 if (mySplitSectionEdgesDone) {
705 GdumpSHA(EF, (char *) "SplitSectionEdges done : ");
706 if (issplit) cout<<" "<<Splits(EOR,TopAbs_ON).Extent()<<" edges splitON"<<endl;
707 else cout<<" !IsSplit"<<endl;
714 if(tSPS)GdumpSHASTA(EF,TopAbs_ON,"--- SplitSectionEdges ");
715 if(tSPS)cout<<" (hg="<<hg<<"||hsd3d="<<hsd3d<<")="<<cond<<endl;
718 // xpu161198 BUC60382(e3on) SE EOR has all its interferences "on bounds"
719 Standard_Boolean allGb1=Standard_False;
720 TopoDS_Vertex vf,vl; TopExp::Vertices(TopoDS::Edge(EOR),vf,vl);
721 const TopOpeBRepDS_ListOfInterference& loi = BDS.ShapeInterferences(EOR);
722 TopOpeBRepDS_ListIteratorOfListOfInterference it(loi);
723 for (; it.More(); it.Next()){
724 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
725 TopOpeBRepDS_Kind GT,ST; Standard_Integer G,S; FDS_data(I,GT,G,ST,S);
726 if (GT == TopOpeBRepDS_POINT) {allGb1=Standard_False; break;}
727 Standard_Integer rkG = BDS.AncestorRank(G);
728 const TopoDS_Vertex& v = TopoDS::Vertex(BDS.Shape(G));
730 allGb1 = (v.IsSame(vf) || v.IsSame(vl));
733 TopoDS_Shape oov; Standard_Boolean hsdmv = FUN_ds_getoov(v,myDataStructure,oov);
734 if (!hsdmv) allGb1=Standard_False;
735 allGb1 = (oov.IsSame(vf) || oov.IsSame(vl));
741 Standard_Boolean mke = !cond;
742 mke = mke || !hg; //xpu271098 cto002J2(e9on)
743 mke = mke || allGb1; //xpu161198 BUC60382(e3on)
745 MarkSplit(EOR,TopAbs_ON);
746 TopTools_ListOfShape& LON = ChangeSplit(EOR,TopAbs_ON);
748 // Standard_Integer non = LON.Extent(); // DEB
752 FUN_ds_CopyEdge(EOR,newEOR);
753 Standard_Boolean hasnewEOR=Standard_False;
755 TopExp_Explorer exv(EOR, TopAbs_VERTEX);
756 for (; exv.More(); exv.Next()){
757 const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current());
758 Standard_Real parv = BRep_Tool::Parameter(v,EOR);
759 Standard_Integer iv = BDS.Shape(v);
760 Standard_Integer ivref = 0;
761 Standard_Boolean hsd = Standard_False;
763 hsd = myDataStructure->HasSameDomain(v);
765 ivref = myDataStructure->SameDomainReference(v);
766 Standard_Boolean setref = hsd && (iv != ivref);
767 TopoDS_Vertex vref = TopoDS::Vertex(BDS.Shape(ivref));
769 {BB.Add(newEOR,v); FUN_ds_Parameter(newEOR,v,parv); continue;}
770 hasnewEOR = Standard_True;
771 vref.Orientation(v.Orientation());
773 FUN_ds_Parameter(newEOR,vref,parv);
782 TopTools_ListOfShape LESD1,LESD2; GFindSamDom(EOR,LESD1,LESD2);
785 if(tSPS)GdumpSHASTA(EF,TopAbs_ON,"--- SplitSectionEdges ");
787 cout<<" (hg="<<hg<<"||hsd3d="<<hsd3d<<")="<<cond<<endl;
788 GdumpSHA(EOR, (char *) "SplitSectionEdge");
790 GdumpSAMDOM(LESD1, (char *) "LESD1 : ");
791 GdumpSAMDOM(LESD2, (char *) "LESD2 : ");
797 if (tSPS) debspseon(iE);
799 TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GComUnsh(TopAbs_FACE,TopAbs_FACE);
800 myEdgeReference = EF;
801 TopOpeBRepBuild_PaveSet PVS(EF);
803 GLOBAL_issp = TheON; //++
804 GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
805 GLOBAL_issp = 0; //++
807 // Create an edge builder EDBU
808 TopOpeBRepBuild_PaveClassifier VCL(EF);
809 Standard_Boolean equalpar = PVS.HasEqualParameters();
810 if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
811 TopOpeBRepBuild_EdgeBuilder EDBU;
812 EDBU.InitEdgeBuilder(PVS,VCL);
814 // Build the new edges LEM
815 TopTools_ListOfShape LEM;
816 GEDBUMakeEdges(EF,EDBU,LEM);
818 // xpu : 18-03-98 (cto 016 B2)
819 // splits edges of LEM with internal vertices
820 TopTools_ListOfShape newLEM; TopTools_ListIteratorOfListOfShape ite(LEM);
821 for (; ite.More(); ite.Next()){
822 const TopoDS_Edge& esp = TopoDS::Edge(ite.Value());
823 TopTools_ListOfShape lspe; Standard_Boolean ok = TopOpeBRepTool_TOOL::SplitE(esp,lspe);
824 Standard_Boolean nonwesp = (!ok) || (lspe.Extent() < 2);
825 if (nonwesp) newLEM.Append(esp);
826 else newLEM.Append(lspe);
828 LEM.Clear(); LEM.Append(newLEM);
830 // connect new edges LEM as split parts (ON,SOLID)
831 MarkSplit(EOR,TopAbs_ON);
832 TopTools_ListOfShape& LON = ChangeSplit(EOR,TopAbs_ON);
836 //modified by NIZHNY-MZV Mon Apr 17 16:25:51 2000 TopTools_ListOfShape losOO;
837 //modified by NIZHNY-MZV Mon Apr 17 16:25:52 2000 if (rankEF == 1) losOO.Append(GLOBALDS_shape2);
838 //modified by NIZHNY-MZV Mon Apr 17 16:25:53 2000 else if (rankEF == 2) losOO.Append(GLOBALDS_shape1);
842 if (tSPS) debspsein(iE);
844 TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GCutUnsh(TopAbs_FACE,TopAbs_FACE);
845 G = G.CopyPermuted(); // parts (IN,OUT) 3d are constructed
846 myEdgeReference = EF;
847 TopOpeBRepBuild_PaveSet PVS(EF);
849 GLOBAL_issp = TheIN; //++
850 GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
851 GLOBAL_issp = 0; //++
853 // Create an edge builder EDBU
854 TopOpeBRepBuild_PaveClassifier VCL(EF);
855 Standard_Boolean equalpar = PVS.HasEqualParameters();
856 if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
857 TopOpeBRepBuild_EdgeBuilder EDBU;
858 EDBU.InitEdgeBuilder(PVS,VCL);
860 // Build the new edges LEM
861 TopTools_ListOfShape LEMNC;
862 GEDBUMakeEdges(EF,EDBU,LEMNC);
864 //modified by NIZHNY-MZV Mon Apr 17 15:23:28 2000 TopTools_ListOfShape LEM;
865 //modified by NIZHNY-MZV Mon Apr 17 15:23:16 2000 GKeepShapes(EF,losOO,TopAbs_IN,LEMNC,LEM);
867 // connect new edges LEM as split parts (IN,SOLID)
868 MarkSplit(EOR,TopAbs_IN);
869 TopTools_ListOfShape& LINN = ChangeSplit(EOR,TopAbs_IN);
870 GCopyList(LEMNC,LINN);
875 if (tSPS) debspseou(iE);
877 TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GCutUnsh(TopAbs_FACE,TopAbs_FACE);
878 // parts (OUT,IN) 3d are constructed
879 myEdgeReference = EF;
880 TopOpeBRepBuild_PaveSet PVS(EF);
882 GLOBAL_issp = TheOUT; //++
883 GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
884 GLOBAL_issp = 0; //++
886 // Create an edge builder EDBU
887 TopOpeBRepBuild_PaveClassifier VCL(EF);
888 Standard_Boolean equalpar = PVS.HasEqualParameters();
889 if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
890 TopOpeBRepBuild_EdgeBuilder EDBU;
891 EDBU.InitEdgeBuilder(PVS,VCL);
893 // Build the new edges LEM
894 TopTools_ListOfShape LEM;
895 GEDBUMakeEdges(EF,EDBU,LEM);
897 // connect new edges LEM as split parts (OUT,SOLID)
898 MarkSplit(EOR,TopAbs_OUT);
899 TopTools_ListOfShape& LINN = ChangeSplit(EOR,TopAbs_OUT);
906 //=======================================================================
909 //=======================================================================
910 const TopTools_ListOfShape& TopOpeBRepBuild_Builder::Section()
912 if (mySectionDone) return mySection;
913 mySectionDone = Standard_True;
914 SectionCurves(mySection);
915 SectionEdges(mySection);
919 //=======================================================================
922 //=======================================================================
923 void TopOpeBRepBuild_Builder::Section(TopTools_ListOfShape& L)
928 //=======================================================================
929 //function : SectionCurves
931 //=======================================================================
932 void TopOpeBRepBuild_Builder::SectionCurves(TopTools_ListOfShape& LSE)
934 TopOpeBRepDS_CurveExplorer cex(myDataStructure->DS());
935 for (; cex.More(); cex.Next()) {
936 Standard_Integer ic = cex.Index();
937 TopTools_ListIteratorOfListOfShape itloe(NewEdges(ic));
938 for(;itloe.More();itloe.Next()) {
939 LSE.Append(itloe.Value());
944 //=======================================================================
945 //function : SectionEdges
947 //=======================================================================
948 void TopOpeBRepBuild_Builder::SectionEdges(TopTools_ListOfShape& LSE)
950 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
951 Standard_Integer i,nes = BDS.NbSectionEdges();
953 Standard_Integer iskpart = IsKPart();
954 if ( iskpart == 1 ) { // iskole
955 for (i=1;i<=nes;i++ ) {
956 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
957 // modif fbi 16-09-97: case possible if RemoveSectionEdge was called
968 // common of edges of section
970 TopTools_MapOfShape MOS;
972 for (i=1;i<=nes;i++) {
974 const TopoDS_Shape& es = BDS.SectionEdge(i);
975 // modif fbi 16-09-97: case possible if RemoveSectionEdge was called
979 Standard_Boolean issplitIN = IsSplit(es,TopAbs_IN);
980 Standard_Boolean issplitON = IsSplit(es,TopAbs_ON);
981 TopAbs_State staspl=(issplitON)?TopAbs_ON:(issplitIN)?TopAbs_IN:TopAbs_UNKNOWN;
984 Standard_Integer iii; Standard_Boolean tSPS = GtraceSPS(es,iii);
986 GdumpSHA(es, (char *) "--- Section ");
987 cout<<" splitIN "<<issplitIN<<" "<<Splits(es,TopAbs_IN).Extent()<<endl;
988 cout<<" splitON "<<issplitON<<" "<<Splits(es,TopAbs_ON).Extent()<<endl;
992 if (staspl != TopAbs_UNKNOWN) {
993 for(TopTools_ListIteratorOfListOfShape it(Splits(es,staspl));it.More();it.Next()) {
994 const TopoDS_Shape& S = it.Value();
995 if ( !MOS.Contains(S) ) {
1002 Standard_Boolean hasgeom = myDataStructure->HasGeometry(es);
1003 Standard_Boolean hassame = myDataStructure->HasSameDomain(es);
1004 Standard_Boolean take = !(hasgeom || hassame);
1006 if ( !MOS.Contains(es) ) {
1015 //=======================================================================
1016 //function : FillSecEdgeAncestorMap
1018 //=======================================================================
1020 void TopOpeBRepBuild_Builder::FillSecEdgeAncestorMap(const Standard_Integer aShapeRank,
1021 const TopTools_MapOfShape& aMapON,
1022 TopTools_DataMapOfShapeShape& anAncMap)
1025 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
1027 Standard_Integer i,nse = BDS.NbSectionEdges();
1028 for (i=1; i<=nse; i++) {
1029 const TopoDS_Shape& es = BDS.SectionEdge(i);
1030 if(es.IsNull() || ShapeRank(es) != aShapeRank)
1032 if (aMapON.Contains(es)) {
1033 anAncMap.Bind(es,es);
1036 TopAbs_State states[3] = {TopAbs_IN, TopAbs_ON, TopAbs_OUT};
1037 for (Standard_Integer j=0; j < 3; j++) {
1038 // Standard_Boolean isSplit = IsSplit(es,states[j]);
1039 if (IsSplit(es,states[j])) {
1040 TopTools_ListIteratorOfListOfShape it(Splits(es,states[j]));
1041 for(;it.More();it.Next()) {
1042 const TopoDS_Shape& aS = it.Value();
1043 if (aMapON.Contains(aS))
1044 anAncMap.Bind(aS,es);