1 // Created on: 1997-01-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <TopOpeBRepBuild_Builder.ixx>
23 #include <TopOpeBRepBuild_define.hxx>
24 #include <TopOpeBRepDS_CurveExplorer.hxx>
25 #include <TopOpeBRepDS_TKI.hxx>
26 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
27 #include <TopOpeBRepBuild_GTool.hxx>
29 #include <GeomAPI_ProjectPointOnCurve.hxx>
30 #include <BRep_Tool.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom2d_TrimmedCurve.hxx>
35 #include <Standard_ProgramError.hxx>
36 #include <TopOpeBRepDS_EXPORT.hxx>
37 #include <TopOpeBRepDS_connex.hxx>
38 #include <TopOpeBRepDS_TKI.hxx>
39 #include <Geom2d_Curve.hxx>
40 #include <Geom_Curve.hxx>
41 #include <BRep_Tool.hxx>
42 #include <BRep_Builder.hxx>
43 #include <TopOpeBRepTool_CurveTool.hxx>
44 #include <TopOpeBRepTool_TOOL.hxx>
45 #include <TopOpeBRepTool_2d.hxx>
46 #include <TopOpeBRepTool_EXPORT.hxx>
48 #define MGhc3 Handle(Geom_Curve)
49 #define MGhc2 Handle(Geom2d_Curve)
52 Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceSPS();
53 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceDSNC();
54 Standard_EXPORT void debsplitse(const Standard_Integer) {}
55 Standard_EXPORT void debsplitsemess(const Standard_Integer i,const TCollection_AsciiString& s = "");
56 Standard_EXPORT void debsplitsemess(const Standard_Integer i,const TCollection_AsciiString& s){cout<<"+++ debsplitse "<<s<<" E"<<i<<endl;debsplitse(i);}
57 Standard_EXPORT void debspseou(const Standard_Integer i) {debsplitsemess(i,"OUT");}
58 Standard_EXPORT void debspsein(const Standard_Integer i) {debsplitsemess(i,"IN ");}
59 Standard_EXPORT void debspseon(const Standard_Integer i) {debsplitsemess(i,"ON ");}
60 Standard_IMPORT Standard_Boolean TopOpeBRepTool_GettraceC2D();
64 #include <TopOpeBRepTool_DRAW.hxx>
67 //Standard_IMPORT void FUN_tool_ttranslate(const gp_Vec2d& tvector, const TopoDS_Face& fF, TopoDS_Edge& fyE);
69 #include <TopOpeBRepTool_ShapeTool.hxx>
70 #include <GeomAdaptor_Surface.hxx>
71 #include <GeomAbs_SurfaceType.hxx>
72 //---------------------------------------------
73 static Standard_Boolean FUN_periodicS(const TopoDS_Shape& F)
74 //---------------------------------------------
76 if (F.IsNull()) return Standard_False;
77 if (F.ShapeType() != TopAbs_FACE) return Standard_False;
78 Handle(Geom_Surface) SSS = TopOpeBRepTool_ShapeTool::BASISSURFACE(TopoDS::Face(F));
79 GeomAdaptor_Surface GAS(SSS);
80 GeomAbs_SurfaceType styp = GAS.GetType();
81 Standard_Boolean periodic = Standard_False;
82 if (styp == GeomAbs_Cylinder) periodic = Standard_True;
83 if (styp == GeomAbs_Cone) periodic = Standard_True;
84 if (styp == GeomAbs_Sphere) periodic = Standard_True;
85 // NYI : for Torus,SurfaceOfRevolution..
89 static Standard_Boolean FUN_periodic(const TopoDS_Face& F,Standard_Boolean& uper,Standard_Boolean& vper)
91 const Handle(Geom_Surface)& su = BRep_Tool::Surface(F);
92 uper = su->IsUPeriodic();
93 vper = su->IsVPeriodic();
94 Standard_Boolean per = (uper || vper);
98 static Standard_Boolean FUN_onboundsper(const gp_Pnt2d& uv,const TopoDS_Face& F)
101 const Handle(Geom_Surface)& su = BRep_Tool::Surface(F);
102 Standard_Boolean uclo = su->IsUPeriodic();
103 Standard_Boolean vclo = su->IsVPeriodic();
104 if (!uclo && !vclo) return Standard_False;
106 Standard_Real u1,u2,v1,v2; su->Bounds(u1,u2,v1,v2);
107 Standard_Real toluv = 1.e-8*1.e-2; // nyinyitol
109 Standard_Real d1 = Abs(u1-uv.X()); Standard_Boolean on1 = (d1 < toluv);
110 Standard_Real d2 = Abs(u2-uv.X()); Standard_Boolean on2 = (d2 < toluv);
114 Standard_Real d1 = Abs(v1-uv.Y()); Standard_Boolean on1 = (d1 < toluv);
115 Standard_Real d2 = Abs(v2-uv.Y()); Standard_Boolean on2 = (d2 < toluv);
118 return Standard_False;
121 static Standard_Boolean FUN_onboundsper(const TopoDS_Edge& E,const TopoDS_Face& F, gp_Pnt2d& uv)
122 // uv is found by projection pnt(E,par)
125 Standard_Real f,l; FUN_tool_bounds(E,f,l); Standard_Real x=0.45678; Standard_Real par=f*x+(1-x)*l;
126 Standard_Real tolF = BRep_Tool::Tolerance(F)*1.e2; // nyitol
127 Standard_Boolean ok = FUN_tool_parF(E,par,F,uv,tolF);
128 if (!ok) return Standard_False;
130 Standard_Boolean onbp = ::FUN_onboundsper(uv,F);
136 //-----------------------------------------------------------------------
137 static Standard_Boolean FUN_PinC(const gp_Pnt& P,const Handle(Geom_Curve)& C,const Standard_Real pmin,const Standard_Real pmax,const Standard_Real tol)
138 //-----------------------------------------------------------------------
140 Standard_Boolean PinC = Standard_False;
141 GeomAPI_ProjectPointOnCurve mydm(P,C,pmin,pmax);
142 Standard_Boolean dmdone = ( mydm.Extrema().IsDone() );
144 if ( mydm.NbPoints() ) {
145 Standard_Real d = mydm.LowerDistance();
152 //-----------------------------------------------------------------------
153 static Standard_Boolean FUN_PinE(const gp_Pnt& P, const TopoDS_Edge& E)
154 //-----------------------------------------------------------------------
156 Standard_Boolean PinE = Standard_False;
157 Standard_Real f,l; Handle(Geom_Curve) CE = BRep_Tool::Curve(E,f,l);
158 Standard_Real tolE = BRep_Tool::Tolerance(E);
159 PinE = FUN_PinC(P,CE,f,l,tolE);
163 #include <BRep_Tool.hxx>
164 //-----------------------------------------------------------------------
165 static Standard_Boolean FUN_EstaEE(const TopoDS_Edge& E, const TopAbs_State sta, const TopoDS_Edge& EE)
166 //-----------------------------------------------------------------------
168 Standard_Boolean EinEE = Standard_False;
170 //modified by NIZNHY-PKV Wed Nov 3 11:40:14 1999 from
172 if (BRep_Tool::Degenerated(E)) {
173 if (sta == TopAbs_IN) return Standard_False;
174 else return Standard_True;
176 //modified by NIZNHY-PKV Wed Nov 3 11:40:19 1999 to
178 Handle(Geom_Curve) CE = BRep_Tool::Curve(E,f,l);
179 Standard_Real t = 0.417789; // Oi blya... ???
180 Standard_Real p = (1-t)*f + t*l;
181 gp_Pnt P = CE->Value(p);
182 EinEE = FUN_PinE(P,EE);
183 if (sta == TopAbs_IN) return EinEE;
184 else if (sta == TopAbs_OUT) return !EinEE;
185 else Standard_ProgramError::Raise("TopOpeBRepBuild FUN_EstaEE on invalid state");
189 //=======================================================================
190 //function : TopOpeBRepBuild_Builder::InitSection
192 //=======================================================================
193 void TopOpeBRepBuild_Builder::InitSection()
195 mySectionDone = Standard_False;
197 mySplitSectionEdgesDone = Standard_False;
201 //-----------------------------------------------------------------------
202 // LE : list of edges from where is extracted LEsta = edges located <sta> / edge E
203 // N.B. : LEsta is expanded and NOT reinitialized
204 static void FUN_selLEE(TopTools_ListOfShape& LE,const TopoDS_Edge& E,const TopAbs_State sta,TopTools_ListOfShape& LEsta)
206 TopTools_ListIteratorOfListOfShape it(LE);
208 const TopoDS_Edge& Ecur = TopoDS::Edge(it.Value());
209 Standard_Boolean ok = FUN_EstaEE(Ecur,sta,E);
218 //-----------------------------------------------------------------------
219 // search the existence of shape E in time as shape of a mesh cell
220 // (shape,listofshape) of the list loslos.
221 Standard_Boolean FUN_FindEinSLOS(const TopoDS_Shape& E,const TopOpeBRepBuild_ListOfShapeListOfShape& loslos)
223 Standard_Boolean f = Standard_False;
224 for (TopOpeBRepBuild_ListIteratorOfListOfShapeListOfShape it(loslos); it.More(); it.Next()) {
225 const TopoDS_Shape& S = it.Value().Shape();
226 Standard_Boolean issame = (S.IsSame(E));
235 //=======================================================================
236 //function : SplitSectionEdges
238 //=======================================================================
239 void TopOpeBRepBuild_Builder::SplitSectionEdges()
241 if (mySplitSectionEdgesDone) return;
243 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
244 Standard_Integer i,n = BDS.NbSectionEdges();
247 if (TopOpeBRepDS_GettraceDSNC() && !mySplitSectionEdgesDone)
248 cout<<"TopOpeBRepBuild_Builder::SSE : compute "<<n<<" section edges"<<endl;
251 for (i = 1; i <= n; i++) { // 1
252 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
253 if(E.IsNull()) continue;
257 TopOpeBRepBuild_DataMapOfShapeListOfShapeListOfShape MEIN;
258 TopTools_DataMapOfShapeListOfShape MEOUT;
260 for (i = 1; i <= n; i++) { // 2
261 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
262 if(E.IsNull()) continue;
263 Standard_Integer iE = myDataStructure->Shape(E);
264 Standard_Integer rE = BDS.AncestorRank(E);
267 Standard_Boolean tSPS = GtraceSPS(E,iE); if (tSPS) debsplitsemess(iE); Standard_Integer DEBiESD = 1;
270 Standard_Boolean isspliton = IsSplit(E,TopAbs_ON);
271 if (!isspliton) continue;
273 const TopTools_ListOfShape& LESD = BDS.ShapeSameDomain(E);
274 if ( LESD.IsEmpty() ) continue;
276 const TopTools_ListOfShape& LEspon = Splits(E,TopAbs_ON);
277 TopTools_ListOfShape LEoutLESD; GCopyList(LEspon,LEoutLESD);
278 Standard_Integer iRef = BDS.SameDomainRef(E);
280 // LEoutLESD = list of edges Split(E,ON) OUT of all
281 // edges of the list of edges same domain of E in 3d only
282 // edges LEoutLESD are attached in Split(ON) to E only.
284 for (TopTools_ListIteratorOfListOfShape itLESD(LESD); itLESD.More(); itLESD.Next()) { // 2.1
285 const TopoDS_Edge& ESD = TopoDS::Edge(itLESD.Value());
286 Standard_Integer iESD = myDataStructure->Shape(ESD);
287 const TopTools_ListOfShape& LESDspon = Splits(ESD,TopAbs_ON);
291 TCollection_AsciiString str("# edge ");str=str+iE+" sd3d edge "+iESD;
292 TCollection_AsciiString stru(str.Length(),'-');
293 cout<<endl;if(DEBiESD==1)cout<<stru<<endl;
294 DEBiESD++;cout<<str<<endl;debsplitsemess(iE);
298 // reduction of LEoutLESD = edges OUT all ESD
299 TopTools_ListOfShape dummylos;
300 FUN_selLEE(LEoutLESD,ESD,TopAbs_IN,dummylos);
302 const TopoDS_Edge *pE1 = NULL, *pE2 = NULL;
303 const TopTools_ListOfShape *plos1 = NULL, *plos2 = NULL;
304 Standard_Integer nLEspon = LEspon.Extent();
305 Standard_Integer nLESDspon = LESDspon.Extent();
307 if ( nLEspon != 0 && nLESDspon != 0 ) {
308 Standard_Boolean takeE = (rE == 1 && iESD != iRef || iE == iRef);
309 pE1 = takeE ? &E : &ESD;
310 pE2 = !takeE ? &E : &ESD;
311 plos1 = takeE ? &LEspon : &LESDspon;
312 plos2 = !takeE ? &LEspon : &LESDspon;
314 else if ( nLEspon != 0 ) {
320 else if ( nLESDspon != 0 ) {
327 if (pE1 == NULL || pE2 == NULL) continue;
328 if (plos1 == NULL || plos2 == NULL) continue;
330 const TopoDS_Edge& E1 = *pE1;
331 const TopoDS_Edge& E2 = *pE2;
332 const TopTools_ListOfShape& LE1 = *plos1;
334 // selection of edges IN E2 = LEinE2
335 TopTools_ListOfShape LE1loc;
336 GCopyList(LE1,LE1loc);
337 TopTools_ListOfShape LE1inE2;
338 FUN_selLEE(LE1loc,E2,TopAbs_IN,LE1inE2);
339 Standard_Integer nLE1inE2 = LE1inE2.Extent();
343 cout<<"# edges ON "<<iE<<" ";
344 TopAbs::Print(TopAbs_IN,cout); cout<<" / esd";
346 cout<<" : ("<<nLE1inE2<<")"<<endl;
347 TCollection_AsciiString str("ON");str=str+iE+"IN"+iESD;
348 FDRAW_DINLOE(" ",LE1inE2,str,"");
352 // edges E1 and E2 share LE1inE2
353 if (nLE1inE2 != 0) { // 2.2
355 Standard_Boolean E1b = MEIN.IsBound(E1);
356 TopOpeBRepBuild_ListOfShapeListOfShape thelist;
357 if (!E1b) MEIN.Bind(E1, thelist);
358 TopOpeBRepBuild_ListOfShapeListOfShape& LE1loslos = MEIN.ChangeFind(E1);
360 // Standard_Integer nLE1 = LE1loslos.Extent();
363 Standard_Boolean E2b = MEIN.IsBound(E2);
364 TopOpeBRepBuild_ListOfShapeListOfShape thelist2;
365 if (!E2b) MEIN.Bind(E2,thelist2);
366 TopOpeBRepBuild_ListOfShapeListOfShape& LE2loslos = MEIN.ChangeFind(E2);
368 // Standard_Integer nLE2 = LE2loslos.Extent();
371 Standard_Boolean E2elemofE1 = FUN_FindEinSLOS(E2,LE1loslos);
372 Standard_Boolean E1elemofE2 = FUN_FindEinSLOS(E1,LE2loslos);
374 Standard_Boolean condadd = (!E2elemofE1 && !E1elemofE2);
376 // regularization of edges of LE1inE2 -> LR
377 TopTools_ListOfShape LR;
378 for (TopTools_ListIteratorOfListOfShape ite(LE1inE2);ite.More();ite.Next()){
379 const TopoDS_Edge& e = TopoDS::Edge(ite.Value());
380 TopTools_ListOfShape newle; Standard_Boolean ok = TopOpeBRepTool_TOOL::SplitE(e,newle);
381 if (ok) LR.Append(newle);
385 TopOpeBRepBuild_ShapeListOfShape thelist3;
386 LE1loslos.Append(thelist3);
387 TopOpeBRepBuild_ShapeListOfShape& E1slos = LE1loslos.Last();
388 E1slos.ChangeShape() = E2;
389 GCopyList(LR,E1slos.ChangeList());
392 TopOpeBRepBuild_ShapeListOfShape thelist4;
393 LE2loslos.Append(thelist4);
394 TopOpeBRepBuild_ShapeListOfShape& E2slos = LE2loslos.Last();
395 E2slos.ChangeShape() = E1;
396 GCopyList(LR,E2slos.ChangeList());
404 cout<<endl<<"# edges ON "<<iE<<" ";
405 TopAbs::Print(TopAbs_OUT,cout);cout<<" / lesd";
406 for(TopTools_ListIteratorOfListOfShape it(LESD);it.More();it.Next())
407 cout<<" "<<myDataStructure->Shape(it.Value());
408 Standard_Integer n=LEoutLESD.Extent();cout<<" : ("<<n<<")"<<endl;
409 TCollection_AsciiString str("ON");str=str+iE+"OUT";
410 FDRAW_DINLOE(" ",LEoutLESD,str,"");
414 if (!MEOUT.IsBound(E)) {
415 TopTools_ListOfShape thelist5;
416 MEOUT.Bind(E, thelist5);
418 GCopyList(LEoutLESD,MEOUT.ChangeFind(E));
422 for (i = 1; i <= n; i++) { // 3
423 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
424 if(E.IsNull()) continue;
426 Standard_Integer iE = myDataStructure->Shape(E);
427 // Standard_Integer rE = GShapeRank(E);
428 Standard_Boolean tSPS = GtraceSPS(E,iE);
429 if (tSPS) debsplitsemess(iE);
432 Standard_Boolean isspliton = IsSplit(E,TopAbs_ON);;
433 if (!isspliton) continue;
435 const TopTools_ListOfShape& LESD = BDS.ShapeSameDomain(E);
436 if ( LESD.IsEmpty() ) continue;
438 Standard_Boolean isbMEOUT = MEOUT.IsBound(E);
439 Standard_Boolean isbMEIN = MEIN.IsBound(E);
440 if (!isbMEOUT && !isbMEIN) continue;
442 TopTools_ListOfShape& LEspon = ChangeSplit(E,TopAbs_ON);
446 const TopTools_ListOfShape& LEOUT = MEOUT.Find(E);
448 // Standard_Integer nOUT = LEOUT.Extent();
450 GCopyList(LEOUT,LEspon);
454 const TopOpeBRepBuild_ListOfShapeListOfShape& loslos = MEIN.Find(E);
456 // Standard_Integer nloslos = loslos.Extent();
458 for (TopOpeBRepBuild_ListIteratorOfListOfShapeListOfShape it(loslos); it.More(); it.Next()) {
459 const TopTools_ListOfShape& los = it.Value().List();
461 // Standard_Integer nlos = los.Extent();
463 GCopyList(los,LEspon);
469 for (i = 1; i <= n; i++) { // 4
470 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i)); if(E.IsNull()) continue;
472 Standard_Integer idebE; Standard_Boolean tSPS = GtraceSPS(E,idebE); if (tSPS) debsplitsemess(idebE);
474 const TopTools_ListOfShape& lesd = BDS.ShapeSameDomain(E);
475 if (lesd.IsEmpty()) continue;
477 Standard_Integer iE = BDS.Shape(E);
479 // Standard_Integer rE = BDS.AncestorRank(E);
481 Standard_Integer RE = BDS.SameDomainRef(E);
482 if (iE != RE) continue;
484 TopTools_ListOfShape lF; TopTools_ListIteratorOfListOfShape itlesd;
485 for(itlesd.Initialize(lesd);itlesd.More();itlesd.Next()) {
486 const TopoDS_Edge& esd = TopoDS::Edge(itlesd.Value());
488 // Standard_Integer iesd = BDS.Shape(esd);
490 const TopTools_ListOfShape& lf = FDSCNX_EdgeConnexitySameShape(esd,myDataStructure);
494 // Standard_Integer nlF = lF.Extent();
497 TopTools_ListOfShape& lon = ChangeSplit(E,TopAbs_ON);
498 Standard_Real tolE = BRep_Tool::Tolerance(E);
499 TopTools_ListIteratorOfListOfShape it(lF); for(;it.More();it.Next()) {
500 const TopoDS_Face& F = TopoDS::Face(it.Value());
501 Standard_Integer iF = BDS.Shape(F); Standard_Integer rF = BDS.AncestorRank(iF);
503 TopoDS_Edge esdF; Standard_Boolean besdF = Standard_False; // NYI pointer on esdF
504 for(itlesd.Initialize(lesd);itlesd.More();itlesd.Next()) {
505 const TopoDS_Edge& esd = TopoDS::Edge(itlesd.Value());
506 Standard_Integer iesd = BDS.Shape(esd); Standard_Integer resd = BDS.AncestorRank(iesd);
509 for (ex.Init(F,TopAbs_EDGE);ex.More();ex.Next()) {
510 // for (TopExp_Explorer ex(F,TopAbs_EDGE);ex.More();ex.Next()) {
511 const TopoDS_Shape& ee = ex.Current();
512 Standard_Boolean eq = (ee.IsEqual(esd));
513 if (eq) { esdF = esd; besdF = Standard_True; break; }
519 TopTools_ListIteratorOfListOfShape itlon(lon); for(;itlon.More();itlon.Next()) {
520 TopoDS_Edge& eon = TopoDS::Edge(itlon.Value());
521 Standard_Real f,l; Standard_Boolean hasPC = FC2D_HasCurveOnSurface(eon,F);
524 if (TopOpeBRepTool_GettraceC2D()) {
525 cout<<"\n#TopOpeBRepBuild_Builder::SSE : hasPC = 0 ES"<<i<<" E"<<idebE<<" sur F"<<iF<<endl;
526 cout<<"tsee s "<<iF<<" "<<idebE<<";"<<endl;
529 // Standard_Real tolpc; MGhc2 PC = FC2D_CurveOnSurface(eon,F,esdF,f,l,tolpc);
530 Standard_Real tolpc; MGhc2 PC = FC2D_CurveOnSurface(eon,F,esdF,f,l,tolpc,Standard_True);//xpu051198 :PRO15049
531 hasPC = (!PC.IsNull());
532 if (!hasPC) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::SSE null PC on F");
533 Standard_Real tol = Max(tolE,tolpc);
534 BB.UpdateEdge(eon,PC,F,tol);
539 Standard_Integer nsha = BDS.NbShapes();
540 for (i = 1; i <= nsha; i++) { // 5
541 const TopoDS_Shape& FOR = myDataStructure->Shape(i);
542 Standard_Boolean isface = (FOR.ShapeType() == TopAbs_FACE);
543 if (!isface) continue;
544 const TopoDS_Face& FF = TopoDS::Face(FOR);
546 // Standard_Integer iFF = BDS.Shape(FF);
548 const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(FF); Standard_Integer nLI = LI.Extent();
549 if (nLI == 0) continue;
550 for (TopOpeBRepDS_ListIteratorOfListOfInterference ILI(LI); ILI.More(); ILI.Next() ) {
551 const Handle(TopOpeBRepDS_ShapeShapeInterference)& SSI = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(ILI.Value());
552 if (SSI.IsNull()) continue;
553 TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(SSI,GT,GI,ST,SI);
554 if (ST != TopOpeBRepDS_FACE) continue;
555 const TopOpeBRepDS_Transition& TFE = SSI->Transition();
556 TopAbs_ShapeEnum shab = TFE.ShapeBefore(),shaa = TFE.ShapeAfter();
557 if (shaa != TopAbs_FACE || shab != TopAbs_FACE) continue;
558 const TopoDS_Face& FS = TopoDS::Face( myDataStructure->Shape(SI));
560 // Standard_Integer iFS = myDataStructure->Shape(FS);
562 Standard_Boolean FSisper = FUN_periodicS(FS);
563 if (!FSisper) continue;
565 const TopoDS_Edge& EG = TopoDS::Edge(myDataStructure->Shape(GI));
567 // Standard_Integer iEG = myDataStructure->Shape(EG);
569 Standard_Boolean isrest = myDataStructure->DS().IsSectionEdge(EG); if (!isrest) continue;
571 // Standard_Real tolE = BRep_Tool::Tolerance(EG);
573 Standard_Boolean haspc = FC2D_HasCurveOnSurface(EG,FS); if (haspc) continue;
574 Standard_Boolean hasc3d = FC2D_HasC3D(EG);
575 if (!hasc3d) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::SSE EG without C3D");
576 Standard_Real pf,pl,tolpc; Handle(Geom2d_Curve) PC;
577 Standard_Boolean trim3d = Standard_True; PC = FC2D_CurveOnSurface(EG,FS,pf,pl,tolpc,trim3d);
578 if (PC.IsNull()) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::SSE EG without PC on FS");
582 for (i = 1; i <= nsha; i++) { // 6
583 // xpu201198, for all periodic surfaces
584 const TopoDS_Shape& FOR = myDataStructure->Shape(i);
585 Standard_Boolean isface = (FOR.ShapeType() == TopAbs_FACE);
586 if (!isface) continue;
587 const TopoDS_Face& FF = TopoDS::Face(FOR);
589 // Standard_Integer iFF = BDS.Shape(FF);
591 Standard_Boolean FFuper,FFvper; Standard_Boolean FFisper = FUN_periodic(FF,FFuper,FFvper);
592 if (!FFisper) continue;
594 const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(FF); Standard_Integer nLI = LI.Extent();
595 if (nLI == 0) continue;
596 for (TopOpeBRepDS_ListIteratorOfListOfInterference ILI(LI); ILI.More(); ILI.Next() ) {
597 const Handle(TopOpeBRepDS_ShapeShapeInterference)& SSI = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(ILI.Value());
598 if (SSI.IsNull()) continue;
599 TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(SSI,GT,GI,ST,SI);
600 if (ST != TopOpeBRepDS_FACE) continue;
601 Standard_Boolean GB = SSI->GBound();
602 if (GB == 1) continue;
604 const TopoDS_Edge& EG = TopoDS::Edge(myDataStructure->Shape(GI));
606 // Standard_Integer iEG = myDataStructure->Shape(EG);
608 Standard_Boolean isrest = myDataStructure->DS().IsSectionEdge(EG); if (!isrest) continue;
610 // xpu191198 : cto016*
611 Standard_Real pf,pl,tolpc; Handle(Geom2d_Curve) PC;
612 Standard_Boolean trim3d = Standard_True; PC = FC2D_CurveOnSurface(EG,FF,pf,pl,tolpc,trim3d);
613 Standard_Boolean isoU,isoV; gp_Pnt2d o2d; gp_Dir2d d2d;
614 Standard_Boolean ISO = TopOpeBRepTool_TOOL::UVISO(PC,isoU,isoV,d2d,o2d);
616 TopTools_ListIteratorOfListOfShape itON(Splits(EG,TopAbs_ON));
617 TopTools_ListOfShape newlON;
618 for (; itON.More(); itON.Next()){
619 TopoDS_Edge eon = TopoDS::Edge(itON.Value());
621 Standard_Real pfon,plon,tolpcon; Handle(Geom2d_Curve) PCon;
622 PCon = FC2D_CurveOnSurface(eon,FF,pfon,plon,tolpcon,trim3d);
624 Standard_Boolean isouon,isovon; gp_Pnt2d o2don; gp_Dir2d d2don;
625 Standard_Boolean ISOon = TopOpeBRepTool_TOOL::UVISO(PCon,isouon,isovon,d2don,o2don);
626 Standard_Boolean PCko = !ISOon || ((isoU && !isouon) || (isoV && !isovon));
627 if (PCko) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::splitON");
629 Standard_Boolean test = (FFuper && isoU) || (FFvper && isoV);
630 if (!test) { newlON.Append(eon); continue;}
632 gp_Pnt2d uvok; Standard_Boolean isonclo = FUN_onboundsper(eon,FF,uvok); //3d
633 if (isonclo) { newlON.Append(eon); continue;}
635 Standard_Boolean isonclo2 = FUN_onboundsper(o2don,FF); //2d
638 if (isoU) {Standard_Real dtr = uvok.X() - o2don.X();tr = gp_Vec2d(dtr,0.);}
639 else {Standard_Real dtr = uvok.Y() - o2don.Y();tr = gp_Vec2d(0.,dtr);}
640 Standard_Real mag = tr.Magnitude();
641 Standard_Real toluv = 1.e-8*1.e2; // NYINYI
642 if (mag > toluv) TopOpeBRepTool_TOOL::TrslUVModifE(tr,FF,eon);
646 TopTools_ListOfShape& nlON = ChangeSplit(EG,TopAbs_ON);
647 nlON.Clear(); nlON.Append(newlON);
651 mySplitSectionEdgesDone = Standard_True;
652 } // SplitSectionEdges
654 //Standard_IMPORT extern TopoDS_Shape GLOBALDS_shape1;
655 Standard_EXPORTEXTERN TopoDS_Shape GLOBALDS_shape1;
656 //Standard_IMPORT extern TopoDS_Shape GLOBALDS_shape2;
657 Standard_EXPORTEXTERN TopoDS_Shape GLOBALDS_shape2;
661 static void FUN_removeonGB(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const TopoDS_Edge& E)
663 // xpu041198 : removing interferences attached to bounds
664 // or vertices sdm to bounds of edge<EIX>
666 TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
667 TopOpeBRepDS_ListOfInterference& LI = BDS.ChangeShapeInterferences(E);
668 TopOpeBRepDS_TKI tki; tki.FillOnGeometry(LI);
669 for (tki.Init(); tki.More(); tki.Next()) {
670 TopOpeBRepDS_Kind K; Standard_Integer G; tki.Value(K,G);
671 TopOpeBRepDS_ListOfInterference& loi = tki.ChangeValue(K,G);
672 if (K==TopOpeBRepDS_VERTEX) {
673 const TopoDS_Vertex& vG = TopoDS::Vertex(BDS.Shape(G));
674 Standard_Integer iv = FUN_tool_orientVinE(vG,E);
677 Standard_Boolean sdm = FUN_ds_getoov(vG,BDS,oovG);
678 iv = FUN_tool_orientVinE(TopoDS::Vertex(oovG),E);
680 Standard_Boolean isonboundE = (iv != 0);
681 if (isonboundE) loi.Clear();
685 for (tki.Init(); tki.More(); tki.Next()) {
686 TopOpeBRepDS_Kind K; Standard_Integer G; tki.Value(K,G);
687 TopOpeBRepDS_ListOfInterference& loi = tki.ChangeValue(K,G);
696 Standard_EXPORT Standard_Integer GLOBAL_issp = 0; //++
700 Standard_EXPORT Standard_Integer GLOBAL_hassd = 0; //++
702 //=======================================================================
703 //function : SplitSectionEdge
705 //=======================================================================
706 void TopOpeBRepBuild_Builder::SplitSectionEdge(const TopoDS_Shape& EA)
709 Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EA,iE);
710 if (tSPS) debsplitsemess(iE);
713 TopOpeBRepDS_DataStructure& BDS = myDataStructure->ChangeDS();
714 const TopoDS_Edge& EOR = TopoDS::Edge(EA);
715 TopoDS_Edge EF = EOR; EF.Orientation(TopAbs_FORWARD);
716 Standard_Integer rankEF = myDataStructure->DS().AncestorRank(EF); // GShapeRank <- GMapShapes, appele par Merge
718 // FUN_removeonGB(myDataStructure,EOR); //xpu041198
720 Standard_Boolean hg = myDataStructure->HasGeometry(EOR);
721 Standard_Boolean hsd3d = FDS_HasSameDomain3d(BDS,EOR);
722 Standard_Boolean hsd2d = FDS_HasSameDomain2d(BDS,EOR);
724 Standard_Boolean issplit = IsSplit(EOR,TopAbs_ON);
727 Standard_Boolean cond = (hg || hsd3d); //REST2 //( hg && (!hsd) );
729 GLOBAL_hassd = 0; // initializing
730 if(hsd3d) GLOBAL_hassd=3; //++
731 if(hsd2d) GLOBAL_hassd=2; //++
733 if (mySplitSectionEdgesDone) {
736 GdumpSHA(EF, (char *) "SplitSectionEdges done : ");
737 if (issplit) cout<<" "<<Splits(EOR,TopAbs_ON).Extent()<<" edges splitON"<<endl;
738 else cout<<" !IsSplit"<<endl;
745 if(tSPS)GdumpSHASTA(EF,TopAbs_ON,"--- SplitSectionEdges ");
746 if(tSPS)cout<<" (hg="<<hg<<"||hsd3d="<<hsd3d<<")="<<cond<<endl;
749 // xpu161198 BUC60382(e3on) SE EOR has all its interferences "on bounds"
750 Standard_Boolean allGb1=Standard_False;
751 TopoDS_Vertex vf,vl; TopExp::Vertices(TopoDS::Edge(EOR),vf,vl);
752 const TopOpeBRepDS_ListOfInterference& loi = BDS.ShapeInterferences(EOR);
753 TopOpeBRepDS_ListIteratorOfListOfInterference it(loi);
754 for (; it.More(); it.Next()){
755 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
756 TopOpeBRepDS_Kind GT,ST; Standard_Integer G,S; FDS_data(I,GT,G,ST,S);
757 if (GT == TopOpeBRepDS_POINT) {allGb1=Standard_False; break;}
758 Standard_Integer rkG = BDS.AncestorRank(G);
759 const TopoDS_Vertex& v = TopoDS::Vertex(BDS.Shape(G));
761 allGb1 = (v.IsSame(vf) || v.IsSame(vl));
764 TopoDS_Shape oov; Standard_Boolean hsdmv = FUN_ds_getoov(v,myDataStructure,oov);
765 if (!hsdmv) allGb1=Standard_False;
766 allGb1 = (oov.IsSame(vf) || oov.IsSame(vl));
772 Standard_Boolean mke = !cond;
773 mke = mke || !hg; //xpu271098 cto002J2(e9on)
774 mke = mke || allGb1; //xpu161198 BUC60382(e3on)
776 MarkSplit(EOR,TopAbs_ON);
777 TopTools_ListOfShape& LON = ChangeSplit(EOR,TopAbs_ON);
779 // Standard_Integer non = LON.Extent(); // DEB
783 FUN_ds_CopyEdge(EOR,newEOR);
784 Standard_Boolean hasnewEOR=Standard_False;
786 TopExp_Explorer exv(EOR, TopAbs_VERTEX);
787 for (; exv.More(); exv.Next()){
788 const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current());
789 Standard_Real parv = BRep_Tool::Parameter(v,EOR);
790 Standard_Integer iv = BDS.Shape(v);
791 Standard_Integer ivref = 0;
792 Standard_Boolean hsd = Standard_False;
794 hsd = myDataStructure->HasSameDomain(v);
796 ivref = myDataStructure->SameDomainReference(v);
797 Standard_Boolean setref = hsd && (iv != ivref);
798 TopoDS_Vertex vref = TopoDS::Vertex(BDS.Shape(ivref));
800 {BB.Add(newEOR,v); FUN_ds_Parameter(newEOR,v,parv); continue;}
801 hasnewEOR = Standard_True;
802 vref.Orientation(v.Orientation());
804 FUN_ds_Parameter(newEOR,vref,parv);
813 TopTools_ListOfShape LESD1,LESD2; GFindSamDom(EOR,LESD1,LESD2);
816 if(tSPS)GdumpSHASTA(EF,TopAbs_ON,"--- SplitSectionEdges ");
818 cout<<" (hg="<<hg<<"||hsd3d="<<hsd3d<<")="<<cond<<endl;
819 GdumpSHA(EOR, (char *) "SplitSectionEdge");
821 GdumpSAMDOM(LESD1, (char *) "LESD1 : ");
822 GdumpSAMDOM(LESD2, (char *) "LESD2 : ");
828 if (tSPS) debspseon(iE);
830 TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GComUnsh(TopAbs_FACE,TopAbs_FACE);
831 myEdgeReference = EF;
832 TopOpeBRepBuild_PaveSet PVS(EF);
834 GLOBAL_issp = TheON; //++
835 GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
836 GLOBAL_issp = 0; //++
838 // Create an edge builder EDBU
839 TopOpeBRepBuild_PaveClassifier VCL(EF);
840 Standard_Boolean equalpar = PVS.HasEqualParameters();
841 if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
842 TopOpeBRepBuild_EdgeBuilder EDBU;
843 EDBU.InitEdgeBuilder(PVS,VCL);
845 // Build the new edges LEM
846 TopTools_ListOfShape LEM;
847 GEDBUMakeEdges(EF,EDBU,LEM);
849 // xpu : 18-03-98 (cto 016 B2)
850 // splits edges of LEM with internal vertices
851 TopTools_ListOfShape newLEM; TopTools_ListIteratorOfListOfShape ite(LEM);
852 for (; ite.More(); ite.Next()){
853 const TopoDS_Edge& esp = TopoDS::Edge(ite.Value());
854 TopTools_ListOfShape lspe; Standard_Boolean ok = TopOpeBRepTool_TOOL::SplitE(esp,lspe);
855 Standard_Boolean nonwesp = (!ok) || (lspe.Extent() < 2);
856 if (nonwesp) newLEM.Append(esp);
857 else newLEM.Append(lspe);
859 LEM.Clear(); LEM.Append(newLEM);
861 // connect new edges LEM as split parts (ON,SOLID)
862 MarkSplit(EOR,TopAbs_ON);
863 TopTools_ListOfShape& LON = ChangeSplit(EOR,TopAbs_ON);
867 //modified by NIZHNY-MZV Mon Apr 17 16:25:51 2000 TopTools_ListOfShape losOO;
868 //modified by NIZHNY-MZV Mon Apr 17 16:25:52 2000 if (rankEF == 1) losOO.Append(GLOBALDS_shape2);
869 //modified by NIZHNY-MZV Mon Apr 17 16:25:53 2000 else if (rankEF == 2) losOO.Append(GLOBALDS_shape1);
873 if (tSPS) debspsein(iE);
875 TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GCutUnsh(TopAbs_FACE,TopAbs_FACE);
876 G = G.CopyPermuted(); // parts (IN,OUT) 3d are constructed
877 myEdgeReference = EF;
878 TopOpeBRepBuild_PaveSet PVS(EF);
880 GLOBAL_issp = TheIN; //++
881 GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
882 GLOBAL_issp = 0; //++
884 // Create an edge builder EDBU
885 TopOpeBRepBuild_PaveClassifier VCL(EF);
886 Standard_Boolean equalpar = PVS.HasEqualParameters();
887 if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
888 TopOpeBRepBuild_EdgeBuilder EDBU;
889 EDBU.InitEdgeBuilder(PVS,VCL);
891 // Build the new edges LEM
892 TopTools_ListOfShape LEMNC;
893 GEDBUMakeEdges(EF,EDBU,LEMNC);
895 //modified by NIZHNY-MZV Mon Apr 17 15:23:28 2000 TopTools_ListOfShape LEM;
896 //modified by NIZHNY-MZV Mon Apr 17 15:23:16 2000 GKeepShapes(EF,losOO,TopAbs_IN,LEMNC,LEM);
898 // connect new edges LEM as split parts (IN,SOLID)
899 MarkSplit(EOR,TopAbs_IN);
900 TopTools_ListOfShape& LINN = ChangeSplit(EOR,TopAbs_IN);
901 GCopyList(LEMNC,LINN);
906 if (tSPS) debspseou(iE);
908 TopOpeBRepBuild_GTopo G = TopOpeBRepBuild_GTool::GCutUnsh(TopAbs_FACE,TopAbs_FACE);
909 // parts (OUT,IN) 3d are constructed
910 myEdgeReference = EF;
911 TopOpeBRepBuild_PaveSet PVS(EF);
913 GLOBAL_issp = TheOUT; //++
914 GFillEdgePVS(EF,myEmptyShapeList,G,PVS);
915 GLOBAL_issp = 0; //++
917 // Create an edge builder EDBU
918 TopOpeBRepBuild_PaveClassifier VCL(EF);
919 Standard_Boolean equalpar = PVS.HasEqualParameters();
920 if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
921 TopOpeBRepBuild_EdgeBuilder EDBU;
922 EDBU.InitEdgeBuilder(PVS,VCL);
924 // Build the new edges LEM
925 TopTools_ListOfShape LEM;
926 GEDBUMakeEdges(EF,EDBU,LEM);
928 // connect new edges LEM as split parts (OUT,SOLID)
929 MarkSplit(EOR,TopAbs_OUT);
930 TopTools_ListOfShape& LINN = ChangeSplit(EOR,TopAbs_OUT);
937 //=======================================================================
940 //=======================================================================
941 const TopTools_ListOfShape& TopOpeBRepBuild_Builder::Section()
943 if (mySectionDone) return mySection;
944 mySectionDone = Standard_True;
945 SectionCurves(mySection);
946 SectionEdges(mySection);
950 //=======================================================================
953 //=======================================================================
954 void TopOpeBRepBuild_Builder::Section(TopTools_ListOfShape& L)
959 //=======================================================================
960 //function : SectionCurves
962 //=======================================================================
963 void TopOpeBRepBuild_Builder::SectionCurves(TopTools_ListOfShape& LSE)
965 TopOpeBRepDS_CurveExplorer cex(myDataStructure->DS());
966 for (; cex.More(); cex.Next()) {
967 Standard_Integer ic = cex.Index();
968 TopTools_ListIteratorOfListOfShape itloe(NewEdges(ic));
969 for(;itloe.More();itloe.Next()) {
970 LSE.Append(itloe.Value());
975 //=======================================================================
976 //function : SectionEdges
978 //=======================================================================
979 void TopOpeBRepBuild_Builder::SectionEdges(TopTools_ListOfShape& LSE)
981 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
982 Standard_Integer i,nes = BDS.NbSectionEdges();
984 Standard_Integer iskpart = IsKPart();
985 if ( iskpart == 1 ) { // iskole
986 for (i=1;i<=nes;i++ ) {
987 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
988 // modif fbi 16-09-97: case possible if RemoveSectionEdge was called
999 // common of edges of section
1001 TopTools_MapOfShape MOS;
1003 for (i=1;i<=nes;i++) {
1005 const TopoDS_Shape& es = BDS.SectionEdge(i);
1006 // modif fbi 16-09-97: case possible if RemoveSectionEdge was called
1010 Standard_Boolean issplitIN = IsSplit(es,TopAbs_IN);
1011 Standard_Boolean issplitON = IsSplit(es,TopAbs_ON);
1012 TopAbs_State staspl=(issplitON)?TopAbs_ON:(issplitIN)?TopAbs_IN:TopAbs_UNKNOWN;
1015 Standard_Integer iii; Standard_Boolean tSPS = GtraceSPS(es,iii);
1017 GdumpSHA(es, (char *) "--- Section ");
1018 cout<<" splitIN "<<issplitIN<<" "<<Splits(es,TopAbs_IN).Extent()<<endl;
1019 cout<<" splitON "<<issplitON<<" "<<Splits(es,TopAbs_ON).Extent()<<endl;
1023 if (staspl != TopAbs_UNKNOWN) {
1024 for(TopTools_ListIteratorOfListOfShape it(Splits(es,staspl));it.More();it.Next()) {
1025 const TopoDS_Shape& S = it.Value();
1026 if ( !MOS.Contains(S) ) {
1033 Standard_Boolean hasgeom = myDataStructure->HasGeometry(es);
1034 Standard_Boolean hassame = myDataStructure->HasSameDomain(es);
1035 Standard_Boolean take = !(hasgeom || hassame);
1037 if ( !MOS.Contains(es) ) {
1046 //=======================================================================
1047 //function : FillSecEdgeAncestorMap
1049 //=======================================================================
1051 void TopOpeBRepBuild_Builder::FillSecEdgeAncestorMap(const Standard_Integer aShapeRank,
1052 const TopTools_MapOfShape& aMapON,
1053 TopTools_DataMapOfShapeShape& anAncMap)
1056 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
1058 Standard_Integer i,nse = BDS.NbSectionEdges();
1059 for (i=1; i<=nse; i++) {
1060 const TopoDS_Shape& es = BDS.SectionEdge(i);
1061 if(es.IsNull() || ShapeRank(es) != aShapeRank)
1063 if (aMapON.Contains(es)) {
1064 anAncMap.Bind(es,es);
1067 TopAbs_State states[3] = {TopAbs_IN, TopAbs_ON, TopAbs_OUT};
1068 for (Standard_Integer j=0; j < 3; j++) {
1069 // Standard_Boolean isSplit = IsSplit(es,states[j]);
1070 if (IsSplit(es,states[j])) {
1071 TopTools_ListIteratorOfListOfShape it(Splits(es,states[j]));
1072 for(;it.More();it.Next()) {
1073 const TopoDS_Shape& aS = it.Value();
1074 if (aMapON.Contains(aS))
1075 anAncMap.Bind(aS,es);