1 // Created on: 1996-03-07
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 
18 #include <BRep_Tool.hxx>
19 #include <gp_Pnt.hxx>
20 #include <Standard_NoSuchObject.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <TopExp.hxx>
23 #include <TopoDS.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopoDS_Vertex.hxx>
28 #include <TopOpeBRepBuild_Builder.hxx>
29 #include <TopOpeBRepBuild_define.hxx>
30 #include <TopOpeBRepBuild_EdgeBuilder.hxx>
31 #include <TopOpeBRepBuild_FaceBuilder.hxx>
32 #include <TopOpeBRepBuild_GTopo.hxx>
33 #include <TopOpeBRepBuild_HBuilder.hxx>
34 #include <TopOpeBRepBuild_PaveSet.hxx>
35 #include <TopOpeBRepBuild_ShapeSet.hxx>
36 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
37 #include <TopOpeBRepBuild_SolidBuilder.hxx>
38 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
39 #include <TopOpeBRepDS.hxx>
40 #include <TopOpeBRepDS_BuildTool.hxx>
41 #include <TopOpeBRepDS_CurveIterator.hxx>
42 #include <TopOpeBRepDS_EXPORT.hxx>
43 #include <TopOpeBRepDS_HDataStructure.hxx>
44 #include <TopOpeBRepDS_InterferenceTool.hxx>
45 #include <TopOpeBRepDS_PointIterator.hxx>
46 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
47 #include <TopOpeBRepDS_SurfaceIterator.hxx>
48 #include <TopOpeBRepTool_2d.hxx>
49 #include <TopOpeBRepTool_EXPORT.hxx>
50 #include <TopOpeBRepTool_ShapeExplorer.hxx>
51 #include <TopOpeBRepTool_ShapeTool.hxx>
52 #include <TopOpeBRepTool_TOOL.hxx>
53 
54 #ifdef DRAW
55 Standard_IMPORT void FUN_draw(const TopoDS_Shape& s);
56 Standard_IMPORT void FUN_draw2de (const TopoDS_Shape& ed,const TopoDS_Shape& fa);
57 #endif
58 
59 #ifdef OCCT_DEBUG
60 extern void* GFABUMAKEFACEPWES_DEB;
61 #define DEBSHASET(sarg,meth,shaset,str) TCollection_AsciiString sarg((meth));(sarg)=(sarg)+(shaset).DEBNumber()+(str);
62 Standard_Integer GLOBAL_iexE = 0;
debfillw(const Standard_Integer)63 Standard_EXPORT void debfillw(const Standard_Integer /*i*/) {}
debfille(const Standard_Integer)64 Standard_EXPORT void debfille(const Standard_Integer /*i*/) {}
debffwesON(const Standard_Integer i)65 Standard_EXPORT void debffwesON(const Standard_Integer i) {std::cout<<"++ debffwesON "<<i<<std::endl;}
debffwesmf(const Standard_Integer i)66 Standard_EXPORT void debffwesmf(const Standard_Integer i) {std::cout<<"++ debffwesmf "<<i<<std::endl;}
debfillf(const Standard_Integer i)67 Standard_EXPORT void debfillf(const Standard_Integer i) {std::cout<<"++ debfillf "<<i<<std::endl;}
debsplite(const Standard_Integer i)68 Standard_EXPORT void debsplite(const Standard_Integer i) {std::cout<<"++ debsplite "<<i<<std::endl;}
debmergef(const Standard_Integer i)69 Standard_EXPORT void debmergef(const Standard_Integer i) {std::cout<<"++ debmergef "<<i<<std::endl;}
70 Standard_IMPORT void debfctwesmess(const Standard_Integer i,
71 				   const TCollection_AsciiString& s = "");
72 extern void debaddpwes(const Standard_Integer iFOR, const TopAbs_State TB1, const Standard_Integer iEG,
73                        const TopAbs_Orientation neworiE, const TopOpeBRepBuild_PBuilder& PB,
74                        const TopOpeBRepBuild_PWireEdgeSet& PWES, const TCollection_AsciiString& str1,
75                        const TCollection_AsciiString& str2);
76 #endif
77 
78 Standard_Boolean GLOBAL_faces2d = Standard_False;
79 Standard_EXPORT Standard_Boolean GLOBAL_classifysplitedge = Standard_False;
80 
81 #define M_IN(st )      (st == TopAbs_IN)
82 #define M_OUT(st)      (st == TopAbs_OUT)
83 #define M_FORWARD(st ) (st == TopAbs_FORWARD)
84 #define M_REVERSED(st) (st == TopAbs_REVERSED)
85 #define M_INTERNAL(st) (st == TopAbs_INTERNAL)
86 #define M_EXTERNAL(st) (st == TopAbs_EXTERNAL)
87 
88 Standard_IMPORT Standard_Boolean FUN_HDS_FACESINTERFER(const TopoDS_Shape& F1,
89 						       const TopoDS_Shape& F2,
90 						       const Handle(TopOpeBRepDS_HDataStructure)& HDS);
91 
92 static
93   TopAbs_State ClassifyEdgeToSolidByOnePoint(const TopoDS_Edge& E,
94 					     const TopoDS_Shape& Ref);
95 static
96   Standard_Boolean FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder& BU,
97 					 const TopoDS_Face& F,
98 					 const TopoDS_Edge& E,
99 					 TopOpeBRepDS_PDataStructure& pDS2d);
100 static
101   Standard_Boolean FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder& BU,
102 					 const TopoDS_Face& F,
103 					 TopOpeBRepDS_PDataStructure& pDS2d);
104 
105 //-------------------------------------------------------------
106 // Unused :
107 /*#ifdef OCCT_DEBUG
108 //=======================================================================
109 //function :FUN_BUI_FACESINTERFER
110 //purpose  :
111 //=======================================================================
112 static Standard_Boolean FUN_BUI_FACESINTERFER(const TopoDS_Shape& F1,
113 					      const TopoDS_Shape& F2,
114 					      const TopOpeBRepBuild_Builder& B)
115 {
116   Standard_Boolean yainterf = Standard_False;
117   Handle(TopOpeBRepDS_HDataStructure) HDS = B.DataStructure();
118 
119 
120 
121   Standard_Boolean ya1 = FUN_HDS_FACESINTERFER(F1,F2,HDS);
122   Standard_Boolean ya2 = FUN_HDS_FACESINTERFER(F2,F1,HDS);
123   yainterf = (ya1 && ya2);
124   return yainterf;
125 }
126 #endif*/
127 
128 //=======================================================================
129 //function :TopOpeBRepBuild_FUN_aresamegeom
130 //purpose  :
131 //=======================================================================
TopOpeBRepBuild_FUN_aresamegeom(const TopoDS_Shape & S1,const TopoDS_Shape & S2)132 Standard_Boolean TopOpeBRepBuild_FUN_aresamegeom (const TopoDS_Shape& S1,
133                                                   const TopoDS_Shape& S2)
134 {
135   TopoDS_Shape SF1 = S1;
136   SF1.Orientation(TopAbs_FORWARD);
137   TopoDS_Shape SF2 = S2;
138   SF2.Orientation(TopAbs_FORWARD);
139   Standard_Boolean same = TopOpeBRepTool_ShapeTool::ShapesSameOriented(SF1,SF2);
140   return same;
141 }
142 
143 //=======================================================================
144 //function :FUN_computeLIFfaces2d
145 //purpose  :
146 //=======================================================================
FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder & BU,const TopoDS_Face & F,const TopoDS_Edge & E,TopOpeBRepDS_PDataStructure & pDS2d)147 Standard_Boolean FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder& BU,
148 				       const TopoDS_Face& F,
149 				       const TopoDS_Edge& E,
150 				       TopOpeBRepDS_PDataStructure& pDS2d)
151 // purpose : compute new face/face interferences F FTRA,
152 //  {I = (T(F),ES,FTRA)} / Fsdm F and ES interfers with E which has splits ON
153 //  E is edge of F
154 {
155   const TopOpeBRepDS_DataStructure& BDS = BU.DataStructure()->DS();
156   const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(E);
157   Standard_Integer IE = BDS.Shape(E);
158   Standard_Integer IF = BDS.Shape(F);
159   Standard_Integer rkF = BDS.AncestorRank(F);
160   Standard_Boolean hasspE = BU.IsSplit(E,TopAbs_ON);
161   if (hasspE) hasspE = (BU.Splits(E,TopAbs_ON).Extent() > 0);
162   TopTools_MapOfShape Ffound;
163 
164   TopTools_ListOfShape Fsdm; TopTools_ListIteratorOfListOfShape itf(BDS.ShapeSameDomain(F));
165   for (; itf.More(); itf.Next()){
166     const TopoDS_Shape& f = itf.Value();
167     Standard_Integer rkf = BDS.AncestorRank(f);
168     if (rkf == rkF) continue;
169     Fsdm.Append(f);
170   }
171 
172   for (TopOpeBRepDS_ListIteratorOfListOfInterference itI(LI); itI.More(); itI.Next()){
173     const Handle(TopOpeBRepDS_Interference)& I = itI.Value();
174 //    const TopOpeBRepDS_Transition& T = I->Transition();
175     TopAbs_ShapeEnum SB,SA;Standard_Integer IB,IA;TopOpeBRepDS_Kind GT,ST;Standard_Integer G,S;
176     FDS_Idata(I,SB,IB,SA,IA,GT,G,ST,S);
177     if (ST != TopOpeBRepDS_EDGE) return Standard_False;
178 
179     TopoDS_Face FTRA; Standard_Integer ITRA = IB;
180     if      (SB == TopAbs_FACE) FTRA = TopoDS::Face(BDS.Shape(IB));
181     else if (SB == TopAbs_EDGE) {
182       Standard_Boolean ok = FUN_tool_findAncestor(Fsdm,TopoDS::Edge(BDS.Shape(S)),FTRA);
183       ITRA = BDS.Shape(FTRA);
184       if (!ok) return Standard_False;
185     }
186     Standard_Boolean found = Ffound.Contains(FTRA);
187 
188     // prequesitory : F and FTRA are SDSO
189     // -------------
190 
191     // attached to E : I = (T(FTRA),G,ES),
192     // ES : support edge
193     // GP : geometric point
194     // recall : rankE  = rankF
195     //          rankTRA = rankS != rankE
196     Standard_Real parE = FDS_Parameter(I);
197     const TopoDS_Edge& ES = TopoDS::Edge(BDS.Shape(S));
198     Standard_Boolean hasspES = BU.IsSplit(ES,TopAbs_ON);
199     if (hasspES) hasspE = (BU.Splits(ES,TopAbs_ON).Extent() > 0);
200 
201     Standard_Boolean sdm = FUN_ds_sdm(BDS,E,ES);
202     Standard_Boolean mkTonEsdm = sdm && hasspE && !found;
203     Standard_Boolean hasfeiF_E_FTRA = FUN_ds_hasFEI(pDS2d,F,IE,ITRA);  //xpu120698
204     mkTonEsdm = mkTonEsdm && !hasfeiF_E_FTRA; //xpu120698
205     if (mkTonEsdm) {
206       Ffound.Add(FTRA);
207       TopoDS_Edge dummy; TopOpeBRepDS_Transition newT;
208       Standard_Boolean ok = FUN_ds_mkTonFsdm(BU.DataStructure(),IF,ITRA,S,IE,parE,dummy,Standard_True,newT);
209 
210       if (ok) {
211 	newT.Index(ITRA); TopOpeBRepDS_Config C = TopOpeBRepDS_SAMEORIENTED;
212 	Handle(TopOpeBRepDS_Interference) newI = TopOpeBRepDS_InterferenceTool::MakeFaceEdgeInterference(newT,ITRA,IE,Standard_True,C);
213 	pDS2d->AddShapeInterference(F,newI);
214       }
215     }
216     Standard_Boolean mkTonESsdm = sdm && hasspES;
217     Standard_Boolean hasfeiFRA_E_F = FUN_ds_hasFEI(pDS2d,FTRA,IE,IF);  //xpu120698
218     mkTonESsdm = mkTonESsdm && !hasfeiFRA_E_F;  //xpu120698
219     if (mkTonESsdm) { // ff1, IE=3 has interferences, S=8 has none
220       TopoDS_Edge dummy; TopOpeBRepDS_Transition newT;
221 
222       Standard_Real parES; Standard_Boolean ok = FUN_tool_parE(E,parE,ES,parES);
223       if (!ok) continue;
224       ok = FUN_ds_mkTonFsdm(BU.DataStructure(),ITRA,IF,IE,S,parES,dummy,Standard_True,newT);
225       if (ok) {
226 	newT.Index(IF); TopOpeBRepDS_Config C = TopOpeBRepDS_SAMEORIENTED;
227 	Handle(TopOpeBRepDS_Interference) newI = TopOpeBRepDS_InterferenceTool::MakeFaceEdgeInterference(newT,IF,IE,Standard_False,C);
228 	pDS2d->AddShapeInterference(FTRA,newI);
229       }
230 
231       ok = FUN_ds_mkTonFsdm(BU.DataStructure(),ITRA,IF,IE,IE,parE,dummy,Standard_True,newT);
232       if (ok) {
233 	newT.Index(IF); TopOpeBRepDS_Config C = TopOpeBRepDS_SAMEORIENTED;
234 	Handle(TopOpeBRepDS_Interference) newI = TopOpeBRepDS_InterferenceTool::MakeFaceEdgeInterference(newT,IF,S,Standard_True,C);
235 	pDS2d->AddShapeInterference(FTRA,newI);
236       }
237 
238     }
239 
240     Standard_Boolean mkTonES = hasspES;
241     Standard_Boolean hasfeiF_S_FTRA = FUN_ds_hasFEI(pDS2d,F,S,ITRA);  //xpu120698
242     mkTonES = mkTonES && !hasfeiF_S_FTRA;
243     if (mkTonES) {
244       Standard_Real parES; Standard_Boolean ok = FUN_tool_parE(E,parE,ES,parES);
245       if (!ok) continue;
246 
247       TopoDS_Edge dummy; TopOpeBRepDS_Transition newT;
248       ok = FUN_ds_mkTonFsdm(BU.DataStructure(),IF,ITRA,S,S,parES,dummy,Standard_True,newT);
249 
250       if (ok) {
251 	newT.Index(ITRA); TopOpeBRepDS_Config C = TopOpeBRepDS_SAMEORIENTED;
252 	Handle(TopOpeBRepDS_Interference) newI = TopOpeBRepDS_InterferenceTool::MakeFaceEdgeInterference(newT,ITRA,S,Standard_False,C);
253 	pDS2d->AddShapeInterference(F,newI);
254       }
255     }
256   } // itI(LI)
257 
258   return Standard_True;
259 }
260 //=======================================================================
261 //function :FUN_computeLIFfaces2d
262 //purpose  :
263 //=======================================================================
FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder & BU,const TopoDS_Face & F,TopOpeBRepDS_PDataStructure & pDS2d)264 Standard_Boolean FUN_computeLIFfaces2d(const TopOpeBRepBuild_Builder& BU,
265 				       const TopoDS_Face& F,
266 				       TopOpeBRepDS_PDataStructure& pDS2d)
267 {
268   TopExp_Explorer ex(F, TopAbs_EDGE);
269   for (; ex.More(); ex.Next()){
270     const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
271     Standard_Boolean ok = FUN_computeLIFfaces2d(BU,F,E,pDS2d);
272     if (!ok) return Standard_False;
273   }
274   return Standard_True;
275 }
276 //=======================================================================
277 //variable : Standard_EXPORT TopOpeBRepDS_PDataStructure GLOBAL_DS2d
278 //purpose  :
279 //=======================================================================
280 Standard_EXPORT TopOpeBRepDS_PDataStructure GLOBAL_DS2d = NULL;
281 
282 //=======================================================================
283 //function : GMergeFaces
284 //purpose  :
285 //=======================================================================
GMergeFaces(const TopTools_ListOfShape & LF1,const TopTools_ListOfShape & LF2,const TopOpeBRepBuild_GTopo & G1)286   void TopOpeBRepBuild_Builder::GMergeFaces(const TopTools_ListOfShape& LF1,
287 					    const TopTools_ListOfShape& LF2,
288 					    const TopOpeBRepBuild_GTopo& G1)
289 {
290   if ( LF1.IsEmpty() ) return;
291   if (GLOBAL_DS2d == NULL) GLOBAL_DS2d = (TopOpeBRepDS_PDataStructure)new TopOpeBRepDS_DataStructure();
292   GLOBAL_DS2d->Init();
293 
294   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
295 
296   const TopoDS_Shape& F1 = LF1.First();
297 #ifdef OCCT_DEBUG
298   Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(F1,iF);
299   if(tSPS){
300     std::cout<<std::endl<<"--- GMergeFaces "<<std::endl;
301     GdumpSAMDOM(LF1, (char *) "1 : ");
302     GdumpSAMDOM(LF2, (char *) "2 : ");
303     debmergef(iF);
304   }
305 #endif
306 
307   // xpu070598 : filling up DS2
308 //  for (TopTools_ListIteratorOfListOfShape itF1(LF1); itF1.More(); itF1.Next()) GLOBAL_DS2d->AddShape(itF1.Value(),1);
309    TopTools_ListIteratorOfListOfShape itF1(LF1) ;
310   for ( ; itF1.More(); itF1.Next()) GLOBAL_DS2d->AddShape(itF1.Value(),1);
311 //  for (TopTools_ListIteratorOfListOfShape itF2(LF2); itF2.More(); itF2.Next()) GLOBAL_DS2d->AddShape(itF2.Value(),2);
312   TopTools_ListIteratorOfListOfShape itF2(LF2) ;
313   for ( ; itF2.More(); itF2.Next()) GLOBAL_DS2d->AddShape(itF2.Value(),2);
314 
315 //  for (itF1.Initialize(LF1); itF1.More(); itF1.Next()){
316   itF1.Initialize(LF1) ;
317   for ( ; itF1.More(); itF1.Next()){
318     const TopoDS_Face& FF1 = TopoDS::Face(itF1.Value());
319     FUN_computeLIFfaces2d((*this),TopoDS::Face(FF1),GLOBAL_DS2d);
320   }
321 //  for (itF2.Initialize(LF2); itF2.More(); itF2.Next()){
322   itF2.Initialize(LF2) ;
323   for ( ; itF2.More(); itF2.Next()){
324     const TopoDS_Face& FF2 = TopoDS::Face(itF2.Value());
325     FUN_computeLIFfaces2d((*this),TopoDS::Face(FF2),GLOBAL_DS2d);
326   }
327   // xpu070598
328 
329   {
330     for (Standard_Integer ii=1; ii<=GLOBAL_DS2d->NbShapes(); ii++) {
331       TopOpeBRepDS_ListOfInterference& LI = GLOBAL_DS2d->ChangeShapeInterferences(ii);
332       FUN_reducedoublons(LI,(*GLOBAL_DS2d),ii);
333     }
334   }
335 
336   myFaceReference = TopoDS::Face(F1);
337   TopOpeBRepBuild_WireEdgeSet WES(F1,this);
338 
339   GLOBAL_faces2d = Standard_True;
340   Standard_Integer K1=1; GFillFacesWESK(LF1,LF2,G1,WES,K1);
341   Standard_Integer K3=3; GFillFacesWESK(LF1,LF2,G1,WES,K3); // xpu060598
342   GLOBAL_faces2d = Standard_False;
343 
344   // Create a face builder FABU
345   TopoDS_Shape F1F = LF1.First(); F1F.Orientation(TopAbs_FORWARD);
346   Standard_Boolean ForceClass = Standard_True;
347   TopOpeBRepBuild_FaceBuilder FABU;
348   FABU.InitFaceBuilder(WES,F1F,ForceClass);
349 
350   // Build new faces LFM
351   TopTools_ListOfShape LFM;
352 
353 #ifdef OCCT_DEBUG
354   GFABUMAKEFACEPWES_DEB = (void*)&WES;
355 #endif
356 
357   TopTools_DataMapOfShapeInteger MWisOld;
358   GFABUMakeFaces(F1F,FABU,LFM,MWisOld);
359 
360   // xpu281098 : regularisation after GFABUMakeFaces
361   TopTools_ListOfShape newLFM; RegularizeFaces(F1F,LFM,newLFM);
362   LFM.Clear(); LFM.Assign(newLFM);
363 
364   // connect new faces as faces built TB1 on LF1 faces
365   TopTools_ListIteratorOfListOfShape it1;
366   for (it1.Initialize(LF1); it1.More(); it1.Next()) {
367     const TopoDS_Shape& F1x = it1.Value();
368     Standard_Boolean tomerge = !IsMerged(F1x,TB1);
369     if (tomerge) {
370       ChangeMerged(F1x, TB1) = LFM;
371     }
372   }
373 
374   // connect new faces as faces built TB2 on LF2 faces
375   TopTools_ListIteratorOfListOfShape it2;
376   for (it2.Initialize(LF2); it2.More(); it2.Next()) {
377     const TopoDS_Shape& F2 = it2.Value();
378     Standard_Boolean tomerge = !IsMerged(F2,TB2);
379     if (tomerge) ChangeMerged(F2,TB2) = LFM;
380   }
381 
382 } // GMergeFaces
383 
384 //=======================================================================
385 //function : GFillFacesWES
386 //purpose  :
387 //=======================================================================
GFillFacesWES(const TopTools_ListOfShape &,const TopTools_ListOfShape &,const TopOpeBRepBuild_GTopo &,TopOpeBRepBuild_WireEdgeSet &)388   void TopOpeBRepBuild_Builder::GFillFacesWES(const TopTools_ListOfShape& ,
389 					      const TopTools_ListOfShape& ,
390 					      const TopOpeBRepBuild_GTopo& ,
391 					      TopOpeBRepBuild_WireEdgeSet& )
392 {
393 } // GFillFacesWES
394 
FUN_validF1edge(const TopoDS_Shape & F)395 static Standard_Boolean FUN_validF1edge(const TopoDS_Shape& F)
396 {
397   Standard_Integer nE = 0;
398   TopTools_IndexedMapOfShape mEt;
399   TopExp_Explorer exE(F, TopAbs_EDGE);
400 //  for ( exE ; exE.More(); exE.Next()) {
401   for (  ; exE.More(); exE.Next()) {
402     const TopoDS_Shape& e = exE.Current();
403     if (mEt.Contains(e)) continue;
404     mEt.Add(e);
405     nE++;
406     if (nE > 2) break;
407   }
408   if (nE > 1) return Standard_True;
409   if (nE == 1) {
410     exE.Init(F, TopAbs_EDGE);
411     const TopoDS_Edge& e = TopoDS::Edge(exE.Current());
412     TopoDS_Vertex dummy; Standard_Boolean closed = TopOpeBRepTool_TOOL::ClosedE(e,dummy);
413     return closed;
414   }
415   return Standard_False;
416 }
417 
418 //=======================================================================
419 //function : GFillFacesWESMakeFaces
420 //purpose  :
421 //=======================================================================
GFillFacesWESMakeFaces(const TopTools_ListOfShape & LLF1,const TopTools_ListOfShape & LF2,const TopTools_ListOfShape &,const TopOpeBRepBuild_GTopo & GM)422   void TopOpeBRepBuild_Builder::GFillFacesWESMakeFaces(const TopTools_ListOfShape& LLF1,
423 						       const TopTools_ListOfShape& LF2,
424 						       const TopTools_ListOfShape& ,//LSO,
425 						       const TopOpeBRepBuild_GTopo& GM)
426 {
427   TopAbs_State TB1,TB2; GM.StatesON(TB1,TB2);
428   if (LLF1.IsEmpty()) return;
429 
430   // xpu270898 : cto905E2 split(fref6,f33,f16) must be built on fref6
431   TopTools_ListOfShape LF1;
432   TopTools_ListIteratorOfListOfShape itf(LLF1);
433   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
434   Standard_Integer iref = 0;
435   for (; itf.More(); itf.Next()){
436     const TopoDS_Shape& fcur = itf.Value();
437     Standard_Integer icur = BDS.Shape(fcur);
438     iref = BDS.SameDomainRef(fcur);
439     if (icur == iref) LF1.Prepend(fcur);
440     else              LF1.Append(fcur);
441   }
442   // xpu270898 : cto905I1 split(f6,f30,fref14) must be built on fref6, f6 is in LFDO1
443 //  Standard_Boolean FFinDO1 = (iFF == iref);
444 //  const TopoDS_Shape& FF = BDS.Shape(iref);
445   const TopoDS_Shape& FF = LF1.First().Oriented(TopAbs_FORWARD);
446   Standard_Integer iFF = BDS.Shape(FF);
447 
448   TopOpeBRepBuild_WireEdgeSet WES(FF,this);
449 
450 #ifdef OCCT_DEBUG
451   Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(FF,iF);
452   if(tSPS) GdumpSHASTA(iF,TB1,WES,"\n--- GFillFacesWESMakeFaces");
453   if(tSPS) debfillf(iF);
454   if(tSPS) debffwesmf(iF);
455 #endif
456 
457   Standard_Integer n1 = 0;
458   GLOBAL_faces2d = Standard_True;
459   Standard_Integer K1=1; GFillFacesWESK(LF1,LF2,GM,WES,K1);
460   GLOBAL_faces2d = Standard_False;
461   n1 = WES.StartElements().Extent();
462 
463   Standard_Integer K2=2; GFillFacesWESK(LF1,LF2,GM,WES,K2);
464   n1 = WES.StartElements().Extent();
465 
466   Standard_Integer K3=3; GFillFacesWESK(LF1,LF2,GM,WES,K3);
467   n1 = WES.StartElements().Extent();
468 
469   Standard_Integer n2 = WES.StartElements().Extent();
470   myEdgeAvoid.Clear(); // Start edges dues a GFillCurveTopologyWES
471   GCopyList(WES.StartElements(),(n1+1),n2,myEdgeAvoid);
472   TopTools_ListOfShape LOF; // LOF : toutes les faces construites sur WES
473   GWESMakeFaces(FF,WES,LOF);
474 
475   // xpu290498
476   //cto 001 F2 : spIN(f18)
477   TopTools_ListIteratorOfListOfShape itF(LOF);
478   while (itF.More()){
479     const TopoDS_Shape& F = itF.Value();
480     Standard_Boolean valid = ::FUN_validF1edge(F);
481     if (!valid) LOF.Remove(itF);
482     else itF.Next();
483   }
484   // xpu290498
485 
486   TopTools_ListOfShape LOFS; // LOFS : LOF faces situees TB1/LSO2
487   GKeepShapes(FF,myEmptyShapeList,TB1,LOF,LOFS);
488 
489   // les faces construites (LOFS) prennent l'orientation originale de FF
490   TopAbs_Orientation odsFF = myDataStructure->Shape(iFF).Orientation();
491   for(TopTools_ListIteratorOfListOfShape itt(LOFS);itt.More();itt.Next()) itt.Value().Orientation(odsFF);
492 
493   TopTools_ListIteratorOfListOfShape it1;
494   for (it1.Initialize(LF1); it1.More(); it1.Next()) {
495     const TopoDS_Shape& S = it1.Value();
496 #ifdef OCCT_DEBUG
497     Standard_Integer iS; GtraceSPS(S,iS);
498 #endif
499     MarkSplit(S,TB1);
500     TopTools_ListOfShape& LS1 = ChangeSplit(S,TB1);
501     GCopyList(LOFS,LS1);
502   }
503 
504   TopTools_ListIteratorOfListOfShape it2;
505   for (it2.Initialize(LF2); it2.More(); it2.Next()) {
506     const TopoDS_Shape& S = it2.Value();
507 #ifdef OCCT_DEBUG
508     Standard_Integer iS; GtraceSPS(S,iS);
509 #endif
510     MarkSplit(S,TB2);
511     TopTools_ListOfShape& LS2 = ChangeSplit(S,TB2);
512     GCopyList(LOFS,LS2);
513   }
514 } // GFillFacesWESMakeFaces
515 
516 //=======================================================================
517 //function : GFillFaceWES
518 //purpose  :
519 //=======================================================================
GFillFaceWES(const TopoDS_Shape & FOR1,const TopTools_ListOfShape & LFclass,const TopOpeBRepBuild_GTopo & G1,TopOpeBRepBuild_WireEdgeSet & WES)520   void TopOpeBRepBuild_Builder::GFillFaceWES(const TopoDS_Shape& FOR1,
521 					     const TopTools_ListOfShape& LFclass,
522 					     const TopOpeBRepBuild_GTopo& G1,
523 					     TopOpeBRepBuild_WireEdgeSet& WES)
524 {
525   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
526   Standard_Boolean RevOri1 = G1.IsToReverse1();
527 
528 #ifdef OCCT_DEBUG
529   Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(FOR1,iF);
530   if(tSPS) GdumpSHASTA(iF,TB1,WES,"--- GFillFaceWES","START");
531   if(tSPS) debfillf(iF);
532 #endif
533 
534   // xpu200598 bcl1;bcl2; tsp(f9)
535   Standard_Boolean opeCut = Opec12() || Opec21(); //xpu200598
536   Standard_Boolean ComOfCut = opeCut && (TB1 == TB2) && (TB1 == TopAbs_IN); //xpu200598
537   Standard_Boolean hsdm = myDataStructure->HasSameDomain(FOR1);//xpu200598
538   if (hsdm && ComOfCut) return; //xpu200598
539 
540   // work on a FORWARD face FF
541   TopoDS_Shape FF = FOR1; FF.Orientation(TopAbs_FORWARD);
542   myFaceToFill = TopoDS::Face(FF);
543 
544   TopOpeBRepTool_ShapeExplorer exWire(FF,TopAbs_WIRE);
545   for (; exWire.More(); exWire.Next()) {
546     TopoDS_Shape W = exWire.Current();
547     Standard_Boolean hasshape = myDataStructure->HasShape(W);
548 
549     if ( ! hasshape ) {
550       // wire W is not in DS : classify it with LFclass faces
551       TopAbs_State pos;
552       Standard_Boolean keep = GKeepShape1(W,LFclass,TB1,pos);
553       if (keep) {
554 	TopAbs_Orientation oriW = W.Orientation();
555 	TopAbs_Orientation neworiW = Orient(oriW,RevOri1);
556 	W.Orientation(neworiW);
557 	WES.AddShape(W);
558       }
559       else if (myProcessON && pos == TopAbs_ON)
560         myONElemMap.Add(W);
561     }
562     else { // wire W has edges(s) with geometry : split W edges
563       GFillWireWES(W,LFclass,G1,WES);
564     }
565   }
566 
567 #ifdef OCCT_DEBUG
568   if(tSPS) GdumpSHASTA(iF,TB1,WES,"--- GFillFaceWES","END");
569 #endif
570 
571   return;
572 } // GFillFaceWES
573 
574 //=======================================================================
575 //function : GFillWireWES
576 //purpose  :
577 //=======================================================================
GFillWireWES(const TopoDS_Shape & W,const TopTools_ListOfShape & LSclass,const TopOpeBRepBuild_GTopo & G1,TopOpeBRepBuild_WireEdgeSet & WES)578   void TopOpeBRepBuild_Builder::GFillWireWES(const TopoDS_Shape& W,
579 					     const TopTools_ListOfShape& LSclass,
580 					     const TopOpeBRepBuild_GTopo& G1,
581 					     TopOpeBRepBuild_WireEdgeSet& WES)
582 {
583   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
584 
585 #ifdef OCCT_DEBUG
586   Standard_Integer iW; Standard_Boolean tSPS = GtraceSPS(W,iW);
587   if(tSPS){
588     std::cout<<std::endl;DEBSHASET(s,"--- GFillWireWES ",WES," ");
589     GdumpSHA(W,(Standard_Address)s.ToCString()); std::cout<<std::endl;
590     Standard_Integer nbe = 0;
591     TopOpeBRepTool_ShapeExplorer exE(W,TopAbs_EDGE);for (;exE.More(); exE.Next()) nbe++;
592     std::cout<<"--- GFillWireWES on W "<<iW<<" with "<<nbe<<" edges "<<std::endl;
593     debfillw(iW);
594   }
595   GLOBAL_iexE = 0;
596 #endif
597 
598   TopOpeBRepTool_ShapeExplorer exEdge(W,TopAbs_EDGE);
599   for (; exEdge.More(); exEdge.Next()) {
600     const TopoDS_Shape& EOR = exEdge.Current();
601 
602 #ifdef OCCT_DEBUG
603     GLOBAL_iexE++;
604     if (tSPS) {
605 //      const TopoDS_Edge& ed = TopoDS::Edge(EOR);
606 //      Standard_Boolean isdegen = BRep_Tool::Degenerated(ed);
607 //      TopLoc_Location L;
608 //      Handle(Geom_Surface) S = BRep_Tool::Surface(myFaceToFill,L);
609 //      Standard_Boolean isclosed = BRep_Tool::IsClosed(ed,S,L);
610 //      TopAbs_Orientation oried = ed.Orientation();
611 //      Standard_Boolean trc = Standard_False;
612 #ifdef DRAW
613 //      if (trc) {FUN_draw(ed); FUN_draw2de(ed,myFaceReference);}
614 #endif
615     }
616 #endif
617 
618     GFillEdgeWES(EOR,LSclass,G1,WES);
619   }
620 } // GFillWireWES
621 
622 
623 //=======================================================================
624 //function : GFillEdgeWES
625 //purpose  :
626 //=======================================================================
GFillEdgeWES(const TopoDS_Shape & EOR,const TopTools_ListOfShape & LSclass,const TopOpeBRepBuild_GTopo & G1,TopOpeBRepBuild_WireEdgeSet & WES)627   void TopOpeBRepBuild_Builder::GFillEdgeWES(const TopoDS_Shape& EOR,
628 					     const TopTools_ListOfShape& LSclass,
629 					     const TopOpeBRepBuild_GTopo& G1,
630 					     TopOpeBRepBuild_WireEdgeSet& WES)
631 {
632   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
633 
634 #ifdef OCCT_DEBUG
635   Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EOR,iE);
636   if(tSPS)std::cout<<std::endl;
637 #endif
638 
639 #ifdef OCCT_DEBUG
640   Standard_Boolean tosplit =
641 #endif
642                 GToSplit(EOR,TB1);
643 #ifdef OCCT_DEBUG
644   Standard_Boolean tomerge =
645 #endif
646                 GToMerge(EOR);
647 
648 #ifdef OCCT_DEBUG
649   if(tSPS) GdumpSHASTA(iE,TB1,WES,"--- GFillEdgeWES ");
650   if(tSPS) std::cout<<" tosplit "<<tosplit<<" tomerge "<<tomerge<<std::endl;
651   if(tSPS) debfille(iE);
652 #endif
653 
654   TopOpeBRepBuild_GTopo GME = G1;
655   GMergeEdgeWES(EOR,GME,WES);
656 
657   TopOpeBRepBuild_GTopo GSE = G1;
658   GSE.ChangeConfig(TopOpeBRepDS_UNSHGEOMETRY,TopOpeBRepDS_UNSHGEOMETRY);
659   GSplitEdgeWES(EOR,LSclass,GSE,WES);
660 
661 } // GFillEdgeWES
662 
FUN_samgeomori(const TopOpeBRepDS_DataStructure & BDS,const Standard_Integer iref,const Standard_Integer ifil,Standard_Boolean & samgeomori)663 static void FUN_samgeomori(const TopOpeBRepDS_DataStructure& BDS, const Standard_Integer iref, const Standard_Integer ifil,
664 			   Standard_Boolean& samgeomori)
665 {
666   TopOpeBRepDS_Config cfill = BDS.SameDomainOri(ifil);
667   TopAbs_Orientation oref=BDS.Shape(iref).Orientation(), ofil=BDS.Shape(ifil).Orientation();
668   samgeomori = (cfill == TopOpeBRepDS_SAMEORIENTED);
669   if (oref == TopAbs::Complement(ofil)) samgeomori = !samgeomori;
670 }
671 
672 #define UNKNOWN   (0)
673 #define ONSAMESHA (1)
674 #define CLOSESAME (11)
675 #define ONOPPOSHA (2)
676 #define CLOSEOPPO (22)
677 #define FORREVOPPO (222)
678 
679 //=======================================================================
680 //function : GSplitEdgeWES
681 //purpose  :
682 //=======================================================================
GSplitEdgeWES(const TopoDS_Shape & EOR,const TopTools_ListOfShape & LSclass,const TopOpeBRepBuild_GTopo & G1,TopOpeBRepBuild_WireEdgeSet & WES)683   void TopOpeBRepBuild_Builder::GSplitEdgeWES(const TopoDS_Shape& EOR,
684 					      const TopTools_ListOfShape& LSclass,
685 					      const TopOpeBRepBuild_GTopo& G1,
686 					      TopOpeBRepBuild_WireEdgeSet& WES)
687 {
688   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
689   Standard_Boolean RevOri1 = G1.IsToReverse1();
690   TopAbs_Orientation oriE = EOR.Orientation();
691   TopAbs_Orientation neworiE = Orient(oriE,RevOri1);
692   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
693 
694   TopAbs_Orientation oEinF;
695   Standard_Integer Oinref = 0;
696   Standard_Boolean hsdm = myDataStructure->HasSameDomain(myFaceToFill);
697   Standard_Boolean hsdmE = myDataStructure->HasSameDomain(EOR);
698   Standard_Integer ifil = myDataStructure->Shape(myFaceToFill);
699   Standard_Integer iref = myDataStructure->Shape(myFaceReference);
700   if (hsdm) {
701     Oinref = FUN_ds_oriEinF(BDS,TopoDS::Edge(EOR),myFaceReference,oEinF); //xpu060598
702 
703     // xpu150998 : cto900P6 : e35ou added to fref34,f53, oEinF=REVERSED, oEinfill=FORWARD
704     TopAbs_Orientation oEinfill;
705     Standard_Integer Oinfill = FUN_ds_oriEinF(BDS,TopoDS::Edge(EOR),myFaceToFill,oEinfill);
706     if (Oinref == Oinfill) {
707 
708       Standard_Boolean reverse = Standard_False;
709       if (iref != ifil) {
710 	// xpu230299 : FRA60275 (e6,fref4,ffill7) + PRO16297
711 	TopAbs_Orientation oref = myFaceReference.Orientation();
712 	Standard_Boolean samegeomori; FUN_samgeomori(BDS,iref,ifil,samegeomori);
713 	reverse = (!samegeomori);
714 	if (oref == TopAbs_REVERSED) reverse = !reverse;
715       }
716 //      TopAbs_Orientation oref=myFaceReference.Orientation(), ofill=myFaceToFill.Orientation();
717 //      Standard_Boolean reverse = (oref != ofill);
718 
719       TopAbs_Orientation oEinfillTOref = reverse ? TopAbs::Complement(oEinfill) : oEinfill;
720       Standard_Boolean same = (oEinF == oEinfillTOref);
721       if (!same && (oEinF!=TopAbs_INTERNAL) && (oEinF!=TopAbs_EXTERNAL)) oEinF = oEinfillTOref;
722     }
723   }
724   else      Oinref = FUN_ds_oriEinF(BDS,TopoDS::Edge(EOR),myFaceToFill,oEinF); //xpu060598
725   Standard_Boolean newO = (Oinref == ONSAMESHA) || (Oinref == ONOPPOSHA); //xpu060598
726 
727   Standard_Boolean isfafa = (myIsKPart == 3);
728   if (isfafa) newO = Standard_False;// xpu110598
729 
730   // if (fus) : faces are SDSO : we keep original edge's orientation
731   // if (com) : faces are SDSO : we keep original edge's orientation
732   // if (cut && TBToFill==OUT)  : myFaceToFill is the reference face,
733   //                              we keep original edge's orientation
734 
735 #ifdef OCCT_DEBUG
736   Standard_Integer iEOR; Standard_Boolean tSPS = GtraceSPS(EOR,iEOR);
737   Standard_Integer iWESF; /*Standard_Boolean tSPSW = */GtraceSPS(WES.Face(),iWESF);
738   if(tSPS) GdumpSHASTA(iEOR,TB1,WES,"\n--- GSplitEdgeWES","START");
739   if(tSPS) std::cout<<" RevOri1 : "<<RevOri1<<std::endl;
740   if(tSPS) debsplite(iEOR);
741 #endif
742 
743   Standard_Boolean tosplit = GToSplit(EOR,TB1);
744   if (tosplit) {
745     GSplitEdge(EOR,G1,LSclass);
746     //modified by NIZNHY-PKV Mon Mar 19 16:53:40 2001 f
747     if (myIsKPart==4) {
748       // Only solids are available here
749       TopAbs_State aState;
750       Standard_Integer aRank1;
751       TopTools_ListOfShape anAuxList;
752 
753       aRank1=ShapeRank(EOR);
754       const TopoDS_Shape& aSolid=(aRank1==1) ? myShape2 : myShape1;
755 
756       TopTools_ListOfShape& aSplitList = ChangeSplit (EOR, TB1);
757       TopTools_ListIteratorOfListOfShape anIt(aSplitList);
758       for (; anIt.More(); anIt.Next()) {
759 	const TopoDS_Edge& aSplitEdge=TopoDS::Edge (anIt.Value());
760 	aState=ClassifyEdgeToSolidByOnePoint (aSplitEdge, aSolid);
761 	if (aState==TB1) {
762 	  anAuxList.Append (aSplitEdge);
763 	}
764       }
765 
766       aSplitList.Clear();
767 
768       anIt.Initialize(anAuxList);
769       for (; anIt.More(); anIt.Next()) {
770 	const TopoDS_Shape& aShape=anIt.Value();
771 	aSplitList.Append(aShape);
772       }
773     }
774     //modified by NIZNHY-PKV Mon Mar 19 16:53:44 2001 t
775   }
776 
777   //xpu200598 : never add spIN in fusion
778   Standard_Boolean opeFus = Opefus(); //xpu200598
779   if (opeFus) //xpu200598
780     if (TB1 == TopAbs_IN) return;  //xpu200598
781 
782   Standard_Boolean issplit = IsSplit(EOR,TB1);
783   if ( issplit ) {
784     const TopTools_ListOfShape& LSE = Splits(EOR,TB1);
785 
786 #ifdef OCCT_DEBUG
787     if(tSPS) {
788       GdumpSHASTA(iEOR,TB1,WES,"--- GSplitEdgeWES","WES+ Split");
789       std::cout<<" ";TopAbs::Print(TB1,std::cout)<<" : "<<LSE.Extent()<<" edge(s) ";
790       TopAbs::Print(neworiE,std::cout); std::cout<<std::endl;
791     }
792 #endif
793 
794     for (TopTools_ListIteratorOfListOfShape it(LSE);
795 	 it.More(); it.Next()) {
796       TopoDS_Edge newE = TopoDS::Edge(it.Value());
797       if (newO) {// xpu060598
798 	// PRO13075 tspIN(f18), tspIN(e17)
799 	// we add sp(EOR) to myFaceToFill with its orientation
800 	newE.Orientation(oEinF);
801 	Standard_Boolean dgE = BRep_Tool::Degenerated(TopoDS::Edge(EOR));
802 	if (!dgE && hsdmE) {
803           Standard_Real f,l; FUN_tool_bounds(newE,f,l);
804           Standard_Real x = 0.45678; Standard_Real par = (1-x)*f + x*l;
805           Standard_Boolean so = Standard_True;
806 	  Standard_Boolean ok = FUN_tool_curvesSO(newE,par,TopoDS::Edge(EOR),so);
807 	  if (!ok) {
808 #ifdef OCCT_DEBUG
809             std::cout<<"GSplitEdgeWES: cannot orient SDM split of an edge"<<std::endl;
810 #endif
811 	    //return; // nyiFUNRAISE
812 	  }
813 	  if (!so) {
814             newE.Reverse();
815 	  }
816 	} //!dgE && hsdmE
817       }// xpu060598
818       else newE.Orientation(neworiE);
819 
820 #ifdef OCCT_DEBUG
821       if (tSPS) debaddpwes(iWESF,TB1,iEOR,neworiE,(TopOpeBRepBuild_Builder* const)this,&WES,"GSplitEdgeWES " ,"WES+ Eisspl ");
822 #endif
823 
824       WES.AddStartElement(newE);
825     }
826   } // issplit
827 
828   else {
829     // EOR sans devenir de Split par TB1 : on la garde si elle est situee TB1 / LSclass
830     Standard_Boolean se = BDS.IsSectionEdge(TopoDS::Edge(EOR));
831     Standard_Boolean hs = myDataStructure->HasShape(EOR);
832     Standard_Boolean hg = myDataStructure->HasGeometry(EOR);
833     Standard_Boolean add = Standard_False;
834     Standard_Boolean addON = Standard_False;
835 
836     Standard_Boolean isstart = Standard_False;
837     isstart = hs;
838 
839     if (se) {
840       Standard_Boolean ftg = !LSclass.IsEmpty();
841       TopAbs_ShapeEnum tclass = LSclass.First().ShapeType();
842       ftg = ftg && (tclass == TopAbs_FACE);
843       if (!ftg) {
844         TopAbs_State pos;
845         Standard_Boolean keepse = GKeepShape1(EOR,LSclass,TB1,pos);
846         if (keepse)
847           add = Standard_True;
848         else if (myProcessON && pos == TopAbs_ON)
849           addON = Standard_True;
850       }
851 
852 #ifdef OCCT_DEBUG
853       std::cout<<"o-o GridFF ffil F"<<ifil<<" se E"<<iEOR<<" / "<<iWESF<<" ";
854       TopAbs::Print(TB1,std::cout);std::cout.flush();
855       if (!ftg) {std::cout<<" : !ftg --> "; GKeepShape(EOR,LSclass,TB1);std::cout.flush();}
856       else      {std::cout<<" : ftg --> non gardee"<<std::endl;std::cout.flush();}
857 #endif
858 
859     }
860     else {
861       add = Standard_True;
862       Standard_Boolean testkeep = Standard_True;
863       testkeep = hs && (!hg);
864       if (testkeep) {
865 #ifdef OCCT_DEBUG
866 	if(tSPS){std::cout<<"--- GSplitEdgeWES ";}
867 #endif
868         TopAbs_State pos;
869 	Standard_Boolean keep = GKeepShape1(EOR,LSclass,TB1,pos);
870 	if ( !keep ) {
871 	  Standard_Boolean testON = (!LSclass.IsEmpty());
872 	  if (testON) testON = (LSclass.First().ShapeType() == TopAbs_SOLID);
873 	  if (testON) keep = (pos == TopAbs_ON);
874           addON = myProcessON && keep;
875 	}
876 	add = keep;
877       }
878     } // !se
879 
880     if (add) {
881       TopoDS_Shape newE = EOR;
882 
883       if      (newO)                 newE.Orientation(oEinF);// xpu060598
884       else if (Oinref == FORREVOPPO) newE.Orientation(TopAbs_INTERNAL);// xpu120898 (PRO14785 : e36 shared by f34 & f39,
885                                                                        // faces sdm with f16)
886       else                           newE.Orientation(neworiE);
887 #ifdef OCCT_DEBUG
888       if(tSPS){
889 	DEBSHASET(ss,"--- GSplitEdgeWES ",WES," WES+ edge ");
890 	GdumpSHA(newE,(Standard_Address)ss.ToCString());
891 	std::cout<<" ";TopAbs::Print(TB1,std::cout)<<" : 1 edge ";
892 	TopAbs::Print(neworiE,std::cout); std::cout<<std::endl;
893       }
894 #endif
895 
896       if (isstart) {
897 #ifdef OCCT_DEBUG
898 	if (tSPS) debaddpwes(iWESF,TB1,iEOR,neworiE,(TopOpeBRepBuild_Builder* const)this,&WES,"GSplitEdgeWES " ,"WES+ Enospl ");
899 #endif
900 	WES.AddStartElement(newE);
901       }
902       else {
903 	WES.AddElement(newE);
904       }
905     } // add
906 
907     if (addON) {
908       TopoDS_Shape newE = EOR;
909       newE.Orientation(neworiE);
910       myONElemMap.Add(newE);
911     }
912   } // !issplit
913 
914   if (myProcessON && IsSplit(EOR,TopAbs_ON)) {
915     const TopTools_ListOfShape& LSE = Splits(EOR,TopAbs_ON);
916     TopTools_ListIteratorOfListOfShape it(LSE);
917     for (; it.More(); it.Next()) {
918       TopoDS_Edge newE = TopoDS::Edge(it.Value());
919       if (newO) {
920 	newE.Orientation(oEinF);
921 	Standard_Boolean dgE = BRep_Tool::Degenerated(TopoDS::Edge(EOR));
922 	if (!dgE && hsdmE) {
923           Standard_Real f,l; FUN_tool_bounds(newE,f,l);
924           Standard_Real x = 0.45678; Standard_Real par = (1-x)*f + x*l;
925           Standard_Boolean so = Standard_True;
926 	  Standard_Boolean ok = FUN_tool_curvesSO(newE,par,TopoDS::Edge(EOR),so);
927 	  if (!ok) {
928 #ifdef OCCT_DEBUG
929             std::cout<<"GSplitEdgeWES: cannot orient SDM split of an edge"<<std::endl;
930 #endif
931           }
932 	  if (!so) newE.Reverse();
933 	}
934       }
935       else newE.Orientation(neworiE);
936       myONElemMap.Add(newE);
937     }
938   }
939 
940 #ifdef OCCT_DEBUG
941   if(tSPS) GdumpSHASTA(iEOR,TB1,WES,"--- GSplitEdgeWES","END");
942 #endif
943 
944   return;
945 } // GSplitEdgeWES
946 
947 Standard_IMPORT Standard_Boolean FUN_ismotheropedef();
948 Standard_IMPORT const TopOpeBRepBuild_GTopo& FUN_motherope();
949 Standard_EXPORT Standard_Boolean GLOBAL_IEtoMERGE = 0; // xpu240498
950 
951 #ifdef OCCT_DEBUG
debmergee(const Standard_Integer)952 void debmergee(const Standard_Integer /*i*/) {}
953 #endif
954 
955 //=======================================================================
956 //function : GMergeEdgeWES
957 //purpose  :
958 //=======================================================================
GMergeEdgeWES(const TopoDS_Shape & EOR,const TopOpeBRepBuild_GTopo & G1,TopOpeBRepBuild_WireEdgeSet & WES)959   void TopOpeBRepBuild_Builder::GMergeEdgeWES(const TopoDS_Shape& EOR,
960 					      const TopOpeBRepBuild_GTopo& G1,
961 					      TopOpeBRepBuild_WireEdgeSet& WES)
962 {
963 #ifdef OCCT_DEBUG
964   Standard_Integer iWESF; /*Standard_Boolean tSPSW = */GtraceSPS(WES.Face(),iWESF);
965   Standard_Integer iEOR; Standard_Boolean tSPS = GtraceSPS(EOR,iEOR);
966   if(tSPS){ debmergee(iEOR);
967     DEBSHASET(s,"\n--- GMergeEdgeWES ",WES," START ");
968     GdumpSHAORIGEO(EOR,(Standard_Address)s.ToCString()); std::cout<<std::endl;
969   }
970 #endif
971 
972   Standard_Boolean closing = BRep_Tool::IsClosed(TopoDS::Edge(EOR),myFaceToFill); // xpu050598
973   if (closing) return; // xpu050598
974 
975   if (Opefus()) return;
976 
977 //  const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
978   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
979   Standard_Boolean RevOri1 = G1.IsToReverse1();
980   TopAbs_Orientation oriE = EOR.Orientation();
981   TopAbs_Orientation neworiE = Orient(oriE,RevOri1);
982 
983   Standard_Boolean hassame = myDataStructure->HasSameDomain(EOR);
984   if (!hassame) return;
985 
986   Standard_Boolean Eisref = Standard_False;
987   if (hassame) {
988     Standard_Integer iEref = myDataStructure->SameDomainReference(EOR);
989     const TopoDS_Shape& Eref = myDataStructure->Shape(iEref);
990     Eisref = EOR.IsSame(Eref);
991   }
992 
993   TopAbs_State TBEOR = (Eisref) ? TB1 : TB2;
994   if (TBEOR == TopAbs_OUT) return; //xpu040598
995 
996   Standard_Boolean ismerged = IsMerged(EOR,TBEOR);
997   if (ismerged) {
998     if (!Eisref) return;
999 
1000     const TopTools_ListOfShape& ME = Merged(EOR,TBEOR);
1001     TopTools_ListIteratorOfListOfShape it(ME);
1002     for(; it.More(); it.Next()) {
1003       TopoDS_Shape newE = it.Value();
1004       newE.Orientation(neworiE);
1005 
1006 #ifdef OCCT_DEBUG
1007       if (tSPS) debaddpwes(iWESF,TB1,iEOR,neworiE,(TopOpeBRepBuild_Builder* const)this,&WES,"GMergeEdgeWES " ,"WES+ Emerge ");
1008 #endif
1009 
1010       WES.AddStartElement(newE);
1011     }
1012     return;
1013   }
1014 
1015   ChangeMerged(EOR,TBEOR) = myEmptyShapeList;
1016   TopAbs_State stspEOR;
1017 //  if (isfafa) stspEOR = TBEOR; // xpu110598
1018 //  else stspEOR = (TBEOR == TopAbs_IN) ? TopAbs_ON : TopAbs_OUT;
1019   stspEOR = TBEOR; // xpu120598
1020 
1021   Standard_Boolean issplit = IsSplit(EOR,stspEOR);
1022   if (!issplit) return;
1023 
1024   ChangeMerged(EOR,TBEOR) = Splits(EOR,stspEOR);
1025 
1026   const TopTools_ListOfShape& ME = Merged(EOR,TBEOR);
1027 #ifdef OCCT_DEBUG
1028   if(tSPS){
1029     DEBSHASET(s,"GMergeEdgeWES(1) ",WES," WES+ Merged ");
1030     GdumpSHA(EOR,(Standard_Address)s.ToCString());
1031     std::cout<<" ";TopAbs::Print(TBEOR,std::cout);
1032     std::cout<<" : "<<ME.Extent()<<" edge"<<std::endl;
1033   }
1034 #endif
1035   for(TopTools_ListIteratorOfListOfShape it(ME);it.More();it.Next()) {
1036     TopoDS_Shape newE = it.Value();
1037     newE.Orientation(neworiE);
1038     WES.AddStartElement(newE);
1039   }
1040 
1041 #ifdef OCCT_DEBUG
1042   if(tSPS){
1043     DEBSHASET(sss,"GMergeEdgeWES ",WES," END ");
1044     GdumpSHA(EOR,(Standard_Address)sss.ToCString());std::cout<<std::endl;
1045   }
1046 #endif
1047 
1048 } // GMergeEdgeWES
1049 
1050 //=======================================================================
1051 //function : GSplitEdge
1052 //purpose  :
1053 //=======================================================================
GSplitEdge(const TopoDS_Shape & EOR,const TopOpeBRepBuild_GTopo & G1,const TopTools_ListOfShape & LSclass)1054   void TopOpeBRepBuild_Builder::GSplitEdge(const TopoDS_Shape& EOR,
1055 					   const TopOpeBRepBuild_GTopo& G1,
1056 					   const TopTools_ListOfShape& LSclass)
1057 {
1058   TopAbs_ShapeEnum t1,t2;
1059   G1.Type(t1,t2);
1060   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
1061   // work on a FORWARD edge <EF>
1062   TopoDS_Shape EF = EOR; EF.Orientation(TopAbs_FORWARD);
1063 
1064 #ifdef OCCT_DEBUG
1065   Standard_Integer iE; Standard_Boolean tSPS = GtraceSPS(EOR,iE);
1066   if (tSPS) GdumpSHASTA(EOR,TB1,"--- GSplitEdge ","\n");
1067   if (tSPS) GdumpEDG(EF);
1068   if (tSPS) debsplite(iE);
1069 #endif
1070 
1071   const TopoDS_Edge& EEF = TopoDS::Edge(EF);
1072   Standard_Boolean isse = myDataStructure->DS().IsSectionEdge(EEF);
1073   Standard_Boolean issplitON = IsSplit(EEF,TopAbs_ON);
1074   Standard_Boolean takeON = (TB1 == TopAbs_IN) && (isse) && (issplitON);
1075   takeON = Standard_False;
1076 #ifdef OCCT_DEBUG
1077   if (tSPS) std::cout<<"---- takeON mis a 0"<<std::endl;
1078 #endif
1079 
1080   if ( takeON ) {
1081 
1082 #ifdef OCCT_DEBUG
1083     if (tSPS) GdumpSHASTA(EOR,TB1,"--- GSplitEdge takeON ","\n");
1084 #endif
1085 
1086     MarkSplit(EF,TB1);
1087     TopTools_ListOfShape& SSEL = ChangeSplit(EF,TB1);
1088     SSEL.Clear();
1089     SSEL = Splits(EEF,TopAbs_ON);
1090     return;
1091   }
1092 
1093   TopTools_ListOfShape LOE;
1094 
1095   // Make a PaveSet PVS on edge EF
1096   TopOpeBRepBuild_PaveSet PVS(EF);
1097 
1098   // Add the point topology found on edge EF in PVS
1099   myEdgeReference = TopoDS::Edge(EF);
1100   GFillPointTopologyPVS(EF,G1,PVS);
1101 
1102   // mark EF as split TB1
1103   MarkSplit(EF,TB1);
1104 
1105   // build the new edges LOE on EF from the Parametrized Vertex set PVS
1106   GPVSMakeEdges(EF,PVS,LOE);
1107 
1108   Standard_Boolean novertex = LOE.IsEmpty();
1109   if (novertex) return;
1110 
1111   TopTools_ListOfShape& SEL = ChangeSplit(EF,TB1);
1112   SEL.Clear();
1113   // NYI ne pas faire de classification des aretes reconstruites / liste de solides
1114   // NYI dans le cas ou l'appel a SplitEdge est utilise pour construire les parties
1115   // NYI (TopAbs_ON,SOLID) (i.e par la construction des parties (TopAbs_IN,FACE)).
1116   TopOpeBRepDS_Config c1 = G1.Config1(),c2 = G1.Config2();
1117   Standard_Boolean UUFACE = (c1==TopOpeBRepDS_UNSHGEOMETRY && c2==TopOpeBRepDS_UNSHGEOMETRY);
1118 
1119   Standard_Boolean ONSOLID = Standard_False;
1120   if ( ! LSclass.IsEmpty() ) {
1121     TopAbs_ShapeEnum t = LSclass.First().ShapeType();
1122     ONSOLID = (t == TopAbs_SOLID);
1123   }
1124 
1125   Standard_Boolean toclass = UUFACE;
1126   toclass = ! ONSOLID;
1127 
1128   TopTools_ListOfShape loos;
1129   const TopTools_ListOfShape* pls;
1130   if (GLOBAL_classifysplitedge) {
1131     Standard_Integer r=GShapeRank(EOR);
1132     TopoDS_Shape oos=myShape1;
1133     if (r==1) oos = myShape2;
1134     if (!oos.IsNull()) loos.Append(oos); // PMN 5/03/99 Nothing to append
1135     pls = &loos;
1136   }
1137   else if (toclass) {
1138     pls = &LSclass;
1139   }
1140   else {
1141     pls = &myEmptyShapeList;
1142   }
1143 
1144   TopTools_ListOfShape aLON;
1145   TopTools_ListIteratorOfListOfShape it(LOE);
1146   for(;it.More();it.Next()) {
1147     const TopoDS_Shape& aE = it.Value();
1148     TopAbs_State pos;
1149     if (GKeepShape1(aE,*pls,TB1,pos))
1150       SEL.Append(aE);
1151     else if (myProcessON && pos == TopAbs_ON)
1152       aLON.Append(aE);
1153   }
1154 
1155   if (!aLON.IsEmpty()) {
1156     MarkSplit(EF,TopAbs_ON);
1157     TopTools_ListOfShape& aSLON = ChangeSplit(EF,TopAbs_ON);
1158     aSLON.Clear();
1159     aSLON.Append(aLON);
1160   }
1161 
1162 } // GSplitEdge
1163 
1164 //modified by NIZNHY-PKV Mon Mar 19 16:50:33 2001 f
1165 #include <BRepClass3d_SolidClassifier.hxx>
1166 //=======================================================================
1167 //function : ClassifyEdgeToSolidByOnePoint
1168 //purpose  :
1169 //=======================================================================
ClassifyEdgeToSolidByOnePoint(const TopoDS_Edge & E,const TopoDS_Shape & Ref)1170 TopAbs_State ClassifyEdgeToSolidByOnePoint(const TopoDS_Edge& E,
1171 						  const TopoDS_Shape& Ref)
1172 {
1173   const Standard_Real PAR_T = 0.43213918;//10.*e^-PI
1174   Standard_Real f2 = 0., l2 = 0., par = 0.;
1175 
1176   Handle(Geom_Curve) C3D = BRep_Tool::Curve(E, f2, l2);
1177   gp_Pnt aP3d;
1178 
1179   if(C3D.IsNull()) {
1180     //it means that we are in degenerated edge
1181     const TopoDS_Vertex& fv = TopExp::FirstVertex(E);
1182     if(fv.IsNull())
1183       return TopAbs_UNKNOWN;
1184     aP3d = BRep_Tool::Pnt(fv);
1185   }
1186   else {//usual case
1187     par = f2*PAR_T + (1 - PAR_T)*l2;
1188     C3D -> D0(par, aP3d);
1189   }
1190 
1191   BRepClass3d_SolidClassifier SC(Ref);
1192   SC.Perform(aP3d, 1e-7);
1193 
1194   return SC.State();
1195 }
1196 //modified by NIZNHY-PKV Mon Mar 19 16:50:36 2001 t
1197