c17b884d07bc16920dafac4414d01ea6329371c7
[occt.git] / src / TopOpeBRep / TopOpeBRep_DSFiller.cxx
1 // Created on: 1993-06-24
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-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 <Precision.hxx>
19 #include <TopExp.hxx>
20 #include <TopExp_Explorer.hxx>
21 #include <TopoDS.hxx>
22 #include <TopoDS_Face.hxx>
23 #include <TopoDS_Iterator.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopOpeBRep_define.hxx>
26 #include <TopOpeBRep_DSFiller.hxx>
27 #include <TopOpeBRep_EdgesFiller.hxx>
28 #include <TopOpeBRep_FaceEdgeFiller.hxx>
29 #include <TopOpeBRep_FacesFiller.hxx>
30 #include <TopOpeBRep_ShapeIntersector.hxx>
31 #include <TopOpeBRep_ShapeIntersector2d.hxx>
32 #include <TopOpeBRepDS_connex.hxx>
33 #include <TopOpeBRepDS_EXPORT.hxx>
34 #include <TopOpeBRepDS_Filter.hxx>
35 #include <TopOpeBRepDS_GapFiller.hxx>
36 #include <TopOpeBRepDS_HDataStructure.hxx>
37 #include <TopOpeBRepDS_IndexedDataMapOfShapeWithState.hxx>
38 #include <TopOpeBRepDS_Reducer.hxx>
39 #include <TopOpeBRepDS_samdom.hxx>
40 #include <TopOpeBRepDS_ShapeWithState.hxx>
41 #include <TopOpeBRepTool_2d.hxx>
42 #include <TopOpeBRepTool_box.hxx>
43 #include <TopOpeBRepTool_EXPORT.hxx>
44 #include <TopOpeBRepTool_SC.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46
47 extern void BREP_sortonparameter(const Handle(TopOpeBRepDS_HDataStructure)& HDS);
48 extern void BREP_mergePDS(const Handle(TopOpeBRepDS_HDataStructure)& HDS);
49
50
51 #ifdef OCCT_DEBUG
52 Standard_EXPORT void debcomplete(){};
53 Standard_EXPORT void debcompleteds(){};
54 static int Vdebfillerds=0;void debfillerds(void){Vdebfillerds++;}
55 static int Vdebfillerff=0;void debfillerff(void){Vdebfillerff++;}
56 static int Vdebfillerffsd=0;void debfillerffsd(void){Vdebfillerffsd++;}
57 static int Vdebfilleree=0;void debfilleree(void){Vdebfilleree++;}
58 static int Vdebfillereesd=0;void debfillereesd(void){Vdebfillereesd++;}
59 static int Vdebfilleref=0;void debfilleref(void){Vdebfilleref++;}
60 static int Vdebfillerfe=0;void debfillerfe(void){Vdebfillerfe++;}
61 void debfillerreset(void){Vdebfillerds=Vdebfillerff=Vdebfilleree=Vdebfilleref=Vdebfillerfe=0;}
62 void debfillerss(const Standard_Integer i1,const Standard_Integer i2){cout<<"+ + + + debfillerss "<<i1<<" "<<i2<<endl;}
63
64 #include <TopOpeBRepTool_KRO.hxx>
65 Standard_EXPORT TOPKRO KRO_DSFILLER_TOTAL("dsfiller");
66 extern TOPKRO KRO_DSFILLER_INTFF;
67 extern TOPKRO KRO_DSFILLER_INTEE;
68 extern TOPKRO KRO_DSFILLER_INTFE;
69 static void FUN_RESET_KRO_DSFILLER()
70 {
71   KRO_DSFILLER_TOTAL.Reset();
72   KRO_DSFILLER_INTFF.Reset();
73   KRO_DSFILLER_INTEE.Reset();
74   KRO_DSFILLER_INTFE.Reset();
75 }
76
77 #include <TopOpeBRep_traceSIFF.hxx>
78 #include <BRepTools.hxx>
79 #include <TopOpeBRepDS_ShapeShapeInterference.hxx>
80 #include <TopOpeBRepDS_CurvePointInterference.hxx>
81
82 extern TopOpeBRep_traceSIFF SIFF;
83
84 extern Standard_Boolean TopOpeBRepTool_GettraceKRO();
85 extern Standard_Boolean TopOpeBRep_GettraceSIFF();
86 extern Standard_Boolean TopOpeBRepTool_GettraceEND();
87 extern Standard_Boolean TopOpeBRep_GettraceSHA(const Standard_Integer);
88 extern Standard_Boolean TopOpeBRep_GetcontextNONOG();
89 #endif
90
91 //=======================================================================
92 //function : TopOpeBRep_DSFiller
93 //purpose  : 
94 //=======================================================================
95 TopOpeBRep_DSFiller::TopOpeBRep_DSFiller() 
96 :
97   myPShapeClassifier(NULL)
98 {
99 }
100
101 //modified by NIZNHY-PKV Mon Dec 16 11:12:38 2002 f
102 //=======================================================================
103 //function : Destroy
104 //purpose  : alias ~TopOpeBRep_DSFiller
105 //=======================================================================
106 void TopOpeBRep_DSFiller::Destroy() 
107 {
108   if (myPShapeClassifier) {
109     delete myPShapeClassifier;
110   }
111 }
112 //modified by NIZNHY-PKV Mon Dec 16 11:12:41 2002 t
113
114 //=======================================================================
115 //function : PShapeClassifier
116 //purpose  : 
117 //=======================================================================
118 TopOpeBRepTool_PShapeClassifier TopOpeBRep_DSFiller::PShapeClassifier() const
119 {
120   return myPShapeClassifier;
121 }
122
123 //modified by NIZNHY-PKV Mon Dec 16 11:30:43 2002 f
124 /*
125 //=======================================================================
126 //function : SetPShapeClassifier
127 //purpose  : 
128 //=======================================================================
129 void TopOpeBRep_DSFiller::SetPShapeClassifier(const TopOpeBRepTool_PShapeClassifier& PSC) 
130 {
131   myPShapeClassifier = PSC;
132 }
133 */
134 //modified by NIZNHY-PKV Mon Dec 16 11:30:52 2002 t
135
136 //=======================================================================
137 //function : BREP_correctgbound
138 //purpose  : 
139 //=======================================================================
140 void BREP_correctgbound(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
141 {
142   TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
143   Standard_Integer i=1,n=BDS.NbShapes();
144   for (;i<=n;i++) {
145     Standard_Boolean ehassiv = Standard_False;
146     const TopoDS_Shape& s = BDS.Shape(i);
147     TopAbs_ShapeEnum t = s.ShapeType();
148     if ( t != TopAbs_EDGE ) continue;
149     TopOpeBRepDS_ListIteratorOfListOfInterference it;
150     it.Initialize(BDS.ChangeShapeInterferences(s));
151     if ( !it.More() ) continue;    
152     for (; it.More(); it.Next()) {
153       const Handle(TopOpeBRepDS_Interference)& I = it.Value();
154       Handle(TopOpeBRepDS_ShapeShapeInterference) SSI = 
155         Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I);
156       if ( SSI.IsNull() ) continue;
157       TopOpeBRepDS_Kind GK = SSI->GeometryType();
158       if ( GK != TopOpeBRepDS_VERTEX ) continue;
159       
160       ehassiv = Standard_True;
161       break;
162     } // it.More
163     
164     if (! ehassiv ) continue;
165     
166     // l'arete s a au moins une shapeshapeinterference de geometrie VERTEX.
167     // on verifie l'information GBound de toutes ses shapeshapeinterferences.    
168     TopTools_IndexedMapOfShape imev;
169     TopExp::MapShapes(s,TopAbs_VERTEX,imev);
170     
171     it.Initialize(BDS.ChangeShapeInterferences(s));
172     for (; it.More(); it.Next()) {
173       const Handle(TopOpeBRepDS_Interference)& I = it.Value();
174       Handle(TopOpeBRepDS_ShapeShapeInterference) SSI = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I);
175       if ( SSI.IsNull() ) continue;
176       Standard_Integer GI = SSI->Geometry();
177       TopOpeBRepDS_Kind GK = SSI->GeometryType();
178       if ( GK != TopOpeBRepDS_VERTEX ) continue;
179       
180       const TopoDS_Shape& v = BDS.Shape(GI);
181       Standard_Boolean vofe = imev.Contains(v);
182       SSI->SetGBound(vofe);
183     } // it.More()   
184     
185     // l'arete s a au moins une shapeshapeinterference de geometrie VERTEX.
186     it.Initialize(BDS.ChangeShapeInterferences(s));
187     for (; it.More(); it.Next()) {
188       const Handle(TopOpeBRepDS_Interference)& I = it.Value();
189       Handle(TopOpeBRepDS_ShapeShapeInterference) SSI = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I);
190       if ( SSI.IsNull() ) continue;
191       Standard_Integer GI = SSI->Geometry();
192       TopOpeBRepDS_Kind GK = SSI->GeometryType();
193       if ( GK != TopOpeBRepDS_VERTEX ) continue;
194       const TopoDS_Shape& v = BDS.Shape(GI);      
195       Standard_Boolean vhassd = HDS->HasSameDomain(v);
196       if (! vhassd ) continue;
197       Standard_Integer ivref = BDS.SameDomainRef(v);
198       if ( ivref == GI ) continue;
199       
200       const TopoDS_Shape& vref = BDS.Shape(ivref);
201       Standard_Boolean vrefofe = imev.Contains(vref);
202       I->SetGeometry(ivref);
203       SSI->SetGBound(vrefofe);    
204     } // it.More
205   } // i
206   return;
207 } // correctGBound
208 //=======================================================================
209 //function : BREP_UnfillSameDomain
210 //purpose  : 
211 //=======================================================================
212 Standard_Boolean BREP_UnfillSameDomain(const TopoDS_Shape& F1,
213                                        const TopoDS_Shape& F2,
214                                        const Handle(TopOpeBRepDS_HDataStructure)& HDS,
215                                        TopOpeBRepTool_ShapeClassifier& SC)
216 {
217   Standard_Boolean unfill = Standard_True;
218   TopAbs_State st1=TopAbs_UNKNOWN,st2=TopAbs_UNKNOWN;
219   Standard_Integer samdom = 1;
220   st1 = SC.StateShapeShape(F1,F2,samdom);
221   st2 = SC.StateShapeShape(F2,F1,samdom);
222   if (((st1==TopAbs_OUT) && (st2==TopAbs_OUT)) || 
223       ((st1==TopAbs_UNKNOWN) && (st2==TopAbs_UNKNOWN)) ) {
224     unfill = Standard_True; // NYI IN IN aussi
225   }
226   else {
227     unfill = Standard_False;
228   }
229   if (unfill) {
230     TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
231     BDS.UnfillShapesSameDomain(F1,F2);
232   }
233   return unfill;
234 }
235 //=======================================================================
236 //function : FUN_shareNOG
237 //purpose  : 
238 //=======================================================================
239 static 
240   Standard_Boolean FUN_shareNOG(const Handle(TopOpeBRepDS_HDataStructure)& HDS, 
241                                 const TopoDS_Shape& lFF1, 
242                                 const TopoDS_Shape& lFF2)
243 {
244   const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
245   const TopoDS_Face& F1 = TopoDS::Face(lFF1);
246   const TopoDS_Face& F2 = TopoDS::Face(lFF2);  
247   TopTools_IndexedMapOfShape map1; TopExp::MapShapes(F1,TopAbs_EDGE,map1);
248   TopTools_IndexedMapOfShape map2; TopExp::MapShapes(F2,TopAbs_EDGE,map2);
249   Standard_Real tola = Precision::Angular();
250
251   const TopOpeBRepDS_ListOfInterference& lIF1 = BDS.ShapeInterferences(F1);
252   TopOpeBRepDS_ListIteratorOfListOfInterference it1(lIF1);
253   for (; it1.More(); it1.Next()){
254     const Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
255     Standard_Integer G = I1->Geometry(); TopOpeBRepDS_Kind GT = I1->GeometryType(); 
256     if (GT != TopOpeBRepDS_EDGE) continue;
257     const TopoDS_Shape& EG = BDS.Shape(G);
258     if (map2.Contains(EG)) return Standard_False;
259   }
260   const TopOpeBRepDS_ListOfInterference& lIF2 = BDS.ShapeInterferences(F2);
261   TopOpeBRepDS_ListIteratorOfListOfInterference it2(lIF2);
262   for (; it2.More(); it2.Next()){
263     const Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
264     Standard_Integer G = I2->Geometry(); TopOpeBRepDS_Kind GT = I2->GeometryType(); 
265     if (GT != TopOpeBRepDS_EDGE) continue;
266     const TopoDS_Shape& EG = BDS.Shape(G);
267     if (map1.Contains(EG)) return Standard_False;
268   }
269
270
271   TopExp_Explorer ex1(F1, TopAbs_EDGE);
272   for (; ex1.More(); ex1.Next()){
273     const TopoDS_Edge& e1 = TopoDS::Edge(ex1.Current());
274     Standard_Boolean hsd1 = HDS->HasSameDomain(e1);
275     if (hsd1) {
276       TopTools_ListIteratorOfListOfShape itsd1(HDS->SameDomain(e1));
277       for (; itsd1.More(); itsd1.Next()){
278         const TopoDS_Shape& e2 = itsd1.Value();
279         if (map2.Contains(e2)) return Standard_False;
280       }
281     }
282
283     const TopOpeBRepDS_ListOfInterference& lie1 = BDS.ShapeInterferences(e1);
284     TopOpeBRepDS_ListIteratorOfListOfInterference iter1(lie1);
285     for (; iter1.More(); iter1.Next()){
286       const Handle(TopOpeBRepDS_Interference)& I1 = iter1.Value();
287       Standard_Integer S1 = I1->Support(); TopOpeBRepDS_Kind ST1 = I1->SupportType();
288       if (ST1 != TopOpeBRepDS_EDGE) continue;
289       const TopoDS_Edge& e2 = TopoDS::Edge(BDS.Shape(S1));
290       if (!map2.Contains(e2)) continue;
291
292   TopOpeBRepDS_Kind GT1 = I1->GeometryType();
293       if (GT1 == TopOpeBRepDS_POINT) {
294         Handle(TopOpeBRepDS_CurvePointInterference) CPI1 = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(I1); 
295         Standard_Real par1 = CPI1->Parameter();
296         Standard_Real par2; Standard_Boolean ok = FUN_tool_parE(e1,par1,e2,par2);
297         if (!ok) {
298 #ifdef OCCT_DEBUG
299           cout<<"**********TopOpeBRep FUN_shareNOG**********"<<endl;
300 #endif
301           return Standard_False;
302         }
303         gp_Vec tge1 = FUN_tool_tggeomE(par1,e1);
304         gp_Vec tge2 = FUN_tool_tggeomE(par2,e2);
305         Standard_Real dot = gp_Dir(tge1).Dot(gp_Dir(tge2));
306         Standard_Real x = Abs(1-Abs(dot));
307         if (x > tola) return Standard_False; // e1,e2 not tangent
308
309         gp_Vec xxF1 = FUN_tool_getgeomxx(F1,e1,par1);
310         gp_Vec xxF2 = FUN_tool_getgeomxx(F2,e2,par2);
311         dot = gp_Dir(xxF1).Dot(gp_Dir(xxF2));
312         if (dot > 0) return Standard_False; // F1,F2 share geometric domain near G1
313       }
314     }// it1.More()
315   }// ex1(F1,EDGE)    
316   return Standard_True;
317
318 } // FUN_shareNOG
319
320 //=======================================================================
321 //function : Insert
322 //purpose  : 
323 //=======================================================================
324 void TopOpeBRep_DSFiller::Insert(const TopoDS_Shape& aS1,
325                                  const TopoDS_Shape& aS2,
326                                  const Handle(TopOpeBRepDS_HDataStructure)& HDS,
327                                  const Standard_Boolean orientFORWARD)
328 {
329   InsertIntersection(aS1,aS2,HDS,orientFORWARD);
330   Complete(HDS);
331 #ifdef OCCT_DEBUG
332   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::Insert"<<endl;
333 #endif
334 } // Insert
335
336 //=======================================================================
337 //function : InsertIntersection
338 //purpose  : 
339 //=======================================================================
340 void TopOpeBRep_DSFiller::InsertIntersection(const TopoDS_Shape& aS1,
341                                              const TopoDS_Shape& aS2,
342                                              const Handle(TopOpeBRepDS_HDataStructure)& HDS,
343                                              const Standard_Boolean orientFORWARD)
344 {
345   FBOX_Prepare();
346   FC2D_Prepare(aS1,aS2);
347
348   if (myPShapeClassifier == NULL) myPShapeClassifier = new TopOpeBRepTool_ShapeClassifier();
349   myFacesFiller.SetPShapeClassifier(myPShapeClassifier);
350   
351 #ifdef OCCT_DEBUG
352   Standard_Boolean tsiff = TopOpeBRep_GettraceSIFF();
353   Standard_Boolean tkro = TopOpeBRepTool_GettraceKRO();
354   if (tsiff) SIFF.Start("DSFiller debut tsif ",cout);
355   if (tkro) { FUN_RESET_KRO_DSFILLER(); KRO_DSFILLER_TOTAL.Start(); }
356 #endif
357   
358   if ( ! CheckInsert(aS1,aS2) ) {
359     HDS->AddAncestors(aS1); // xpu100798 cto902B4 (f24 as face ancestor of e19)
360     HDS->AddAncestors(aS2); // xpu100798 
361     FDSCNX_Prepare(aS1,aS2,HDS);
362     return;
363   }
364   
365   TopoDS_Shape S1 = aS1; 
366   TopoDS_Shape S2 = aS2; 
367   if ( orientFORWARD ) {
368     if ( S1.Orientation() == TopAbs_REVERSED ) {
369       S1.Orientation(TopAbs_FORWARD);
370     }
371     if ( S2.Orientation() == TopAbs_REVERSED ) {
372       S2.Orientation(TopAbs_FORWARD);
373     }
374   }
375
376   TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
377   BDS.AddShape(S1,1);
378   BDS.AddShape(S2,2);
379   TopExp_Explorer ex1,ex2;
380   for (ex1.Init(S1,TopAbs_SOLID); ex1.More(); ex1.Next()) {
381     const TopoDS_Shape& so1 = ex1.Current();
382     for (ex2.Init(S2,TopAbs_SOLID); ex2.More(); ex2.Next()) {
383       const TopoDS_Shape& so2 = ex2.Current();
384       BDS.FillShapesSameDomain(so1,so2);
385     }
386   }
387   
388 #ifdef OCCT_DEBUG
389   debfillerreset(); // debug
390 #endif
391
392   Standard_Boolean FFsamdom = Standard_True; // xpu060598
393   Standard_Boolean islFFsamdom = Standard_False;
394   Standard_Boolean isFF = Standard_False;
395   Standard_Boolean isFFsamdom = Standard_False;
396   Standard_Boolean isEE = Standard_False;
397   Standard_Boolean unfill = Standard_False;
398   TopoDS_Shape lFF1, lFF2;
399   //
400   // Find all Rejected Faces on the Object and on the Tool
401   /////////////// Rejected Faces' Block
402   TopOpeBRepDS_DataStructure& aDataStructure=HDS->ChangeDS();
403   
404   TopTools_IndexedMapOfShape& aMapOfRejectedShapesObj=
405     aDataStructure.ChangeMapOfRejectedShapesObj();
406   TopTools_IndexedMapOfShape& aMapOfRejectedShapesTool=
407     aDataStructure.ChangeMapOfRejectedShapesTool();
408   aMapOfRejectedShapesObj.Clear();
409   aMapOfRejectedShapesTool.Clear();
410
411   // 1.Find all Rejected Faces on the Object and on the Tool
412   TopTools_ListOfShape aListObj, aListTool;
413
414   //modified by NIZHNY-MKK  Fri Apr 14 09:35:26 2000.BEGIN
415   TopTools_IndexedMapOfShape aMapOfSolids;
416
417   TopExp::MapShapes(S2, TopAbs_SOLID, aMapOfSolids);
418   if(!aMapOfSolids.IsEmpty())
419     myShapeIntersector.RejectedFaces (S1, S2, aListObj);
420
421   aMapOfSolids.Clear();
422   TopExp::MapShapes(S1, TopAbs_SOLID, aMapOfSolids);
423   if(!aMapOfSolids.IsEmpty())
424     myShapeIntersector.RejectedFaces (S2, S1, aListTool);
425   //modified by NIZHNY-MKK  Fri Apr 14 09:37:32 2000.END
426  
427   // 2.Insert all rejected faces, wires, edges of Object in DS:
428   TopTools_ListIteratorOfListOfShape anIt(aListObj);
429   
430   for (; anIt.More(); anIt.Next()) {
431     const TopoDS_Shape& aS=anIt.Value();
432     aMapOfRejectedShapesObj.Add(aS);
433   }
434
435   TopTools_ListIteratorOfListOfShape anIt1(aListTool);
436   for (; anIt1.More(); anIt1.Next()) {
437     const TopoDS_Shape& aS=anIt1.Value();
438     aMapOfRejectedShapesTool.Add(aS);
439   }
440  
441   //
442   myShapeIntersector.InitIntersection(S1,S2);
443   while (myShapeIntersector.MoreIntersection()) {
444     
445 #ifdef OCCT_DEBUG
446     Standard_Integer i1deb = myShapeIntersector.Index(1);
447     Standard_Integer i2deb = myShapeIntersector.Index(2);
448     Standard_Boolean b1deb = TopOpeBRep_GettraceSHA(i1deb);
449     Standard_Boolean b2deb = TopOpeBRep_GettraceSHA(i2deb);
450     if (b1deb && b2deb) debfillerss(i1deb,i2deb);
451     debfillerds(); // debug
452 #endif
453     
454     // The two intersecting GeomShapes gs1,gs2 and their types t1,t2
455     const TopoDS_Shape& gs1 = myShapeIntersector.CurrentGeomShape(1);
456     const TopoDS_Shape& gs2 = myShapeIntersector.CurrentGeomShape(2);
457     TopAbs_ShapeEnum t1 = gs1.ShapeType();
458     TopAbs_ShapeEnum t2 = gs2.ShapeType();
459     
460     // si le couple courant apres un couple facefacesamedomain n'est
461     // pas un couple edgeedge ==> facefacesamedomain est deconnecte 
462     isFF = ((t1==TopAbs_FACE) && (t2==TopAbs_FACE));
463     isFFsamdom = Standard_False;
464     isEE = ((t1==TopAbs_EDGE) && (t2==TopAbs_EDGE));
465     unfill = (!isEE && islFFsamdom);
466     
467     if (unfill) {
468       if (myPShapeClassifier==NULL) myPShapeClassifier = new TopOpeBRepTool_ShapeClassifier();
469       unfill = BREP_UnfillSameDomain(lFF1,lFF2,HDS,*myPShapeClassifier);
470     }
471     
472     if      (isFF) {
473 #ifdef OCCT_DEBUG
474       if (tsiff) SIFF.Add(i1deb,i2deb); debfillerff();
475 #endif
476       TopOpeBRep_FacesIntersector& FF=myShapeIntersector.ChangeFacesIntersector();
477       isFFsamdom = FF.SameDomain();
478       FFsamdom = FFsamdom && isFFsamdom; //xpu060598
479       if (isFFsamdom) {
480         lFF1 = FF.Face(1);
481         lFF2 = FF.Face(2);
482       }
483       
484 #ifdef OCCT_DEBUG
485       if (isFFsamdom) debfillerffsd(); // debug
486       Standard_Integer exf1 = myShapeIntersector.Index(1);
487       Standard_Integer exf2 = myShapeIntersector.Index(2);
488       myFacesFiller.SetTraceIndex(exf1,exf2);
489 #endif
490       myFacesFiller.Insert(gs1,gs2,FF,HDS);
491     }
492     
493     else if ((t1 == TopAbs_EDGE) && (t2 == TopAbs_EDGE)) {
494 #ifdef OCCT_DEBUG
495       debfilleree(); // debug
496 #endif
497       TopOpeBRep_EdgesIntersector& EE = 
498         myShapeIntersector.ChangeEdgesIntersector();
499       EE.Dimension(2);
500 #ifdef OCCT_DEBUG
501       Standard_Boolean EEsamedomain =
502 #endif
503                          EE.SameDomain();
504 #ifdef OCCT_DEBUG
505       if (EEsamedomain) debfillereesd(); // debug
506 #endif
507       if ( islFFsamdom ) {
508         myEdgesFiller.Face(1,lFF1);
509         myEdgesFiller.Face(2,lFF2);
510       }
511       myEdgesFiller.Insert(gs1,gs2,EE,HDS);
512     }
513     
514     else if ((t1 == TopAbs_FACE) && (t2 == TopAbs_EDGE)) {
515 #ifdef OCCT_DEBUG
516       debfillerfe(); // debug
517 #endif
518       TopOpeBRep_FaceEdgeIntersector& FE = 
519         myShapeIntersector.ChangeFaceEdgeIntersector();
520       myFaceEdgeFiller.Insert(gs1,gs2,FE,HDS);
521     }
522     
523     else if ((t1 == TopAbs_EDGE) && (t2 == TopAbs_FACE)) {
524 #ifdef OCCT_DEBUG
525       debfilleref(); // debug
526 #endif
527       TopOpeBRep_FaceEdgeIntersector& FE = 
528         myShapeIntersector.ChangeFaceEdgeIntersector();
529       myFaceEdgeFiller.Insert(gs2,gs1,FE,HDS);
530     }
531     
532     islFFsamdom = isFFsamdom;
533     myShapeIntersector.NextIntersection();
534     
535   } // while (MoreIntersection())
536
537   // FFsamdom = true : rien que des faces tangentes
538   // codage des aretes de section des aretes samedomain
539   if (FFsamdom) FUN_ds_FillSDMFaces(HDS);// xpu060598
540   // xpu280199 : On stocke les edges sdm comme edges de section aussi ! - CTS21801 -
541   else          FUN_ds_addSEsdm1d(HDS);
542
543   if (FFsamdom) HDS->ChangeDS().Isfafa(Standard_True);// xpu120598
544   
545   if (islFFsamdom && !isEE) {
546     if (myPShapeClassifier==NULL) myPShapeClassifier = new TopOpeBRepTool_ShapeClassifier();
547     unfill = BREP_UnfillSameDomain(lFF1,lFF2,HDS,*myPShapeClassifier);
548   }
549   
550   BREP_sortonparameter(HDS);
551   BREP_correctgbound(HDS);
552   BREP_mergePDS(HDS);
553
554   HDS->AddAncestors(S1); // xpu100798 cto902B4 (f24 as face ancestor of e19)
555   HDS->AddAncestors(S2); // xpu100798 
556   FDSCNX_Prepare(aS1,aS2,HDS);
557   FDSSDM_prepare(HDS);
558   
559 #ifdef OCCT_DEBUG
560   if (tkro) KRO_DSFILLER_TOTAL.Stop();if (tsiff) SIFF.End("DSFiller fin tsif ",cout);
561 #endif
562 #ifdef OCCT_DEBUG
563   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::InsertIntersection"<<endl;
564 #endif
565   
566 } // InsertIntersection
567
568 //=======================================================================
569 //function : Complete
570 //purpose  : 
571 //=======================================================================
572 void TopOpeBRep_DSFiller::Complete(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
573 {
574 #ifdef OCCT_DEBUG
575   debcomplete();
576 #endif
577   GapFiller(HDS);
578   CompleteDS(HDS);
579   Filter(HDS);
580   Reducer(HDS);
581   RemoveUnsharedGeometry(HDS);
582   Checker(HDS);
583 #ifdef OCCT_DEBUG
584   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::Complete"<<endl;
585 #endif
586 } // Complete
587
588 //=======================================================================
589 //function : GapFiller
590 //purpose  : 
591 //=======================================================================
592 void TopOpeBRep_DSFiller::GapFiller(const Handle(TopOpeBRepDS_HDataStructure)& HDS) const
593 {
594   TopOpeBRepDS_GapFiller GF(HDS); GF.Perform();
595 #ifdef OCCT_DEBUG
596   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::GapFiller"<<endl;
597 #endif
598 }
599
600 //=======================================================================
601 //function : CompleteDS
602 //purpose  : 
603 //=======================================================================
604 void TopOpeBRep_DSFiller::CompleteDS(const Handle(TopOpeBRepDS_HDataStructure)& HDS) const
605 {
606 #ifdef OCCT_DEBUG
607   debcompleteds();
608 #endif
609   const TopoDS_Shape& S1 = myShapeIntersector.Shape(1);
610   const TopoDS_Shape& S2 = myShapeIntersector.Shape(2);
611   if(S1.IsNull() || S2.IsNull()) return;
612 //  HDS->AddAncestors(S1); -xpu100798 (is done before FDSCNX_Prepare)
613 //  HDS->AddAncestors(S2); -xpu100798
614
615 //  FUN_ds_unkeepEVIonGb1(HDS,TopAbs_IN); //xpu290698
616   
617   FUN_ds_PointToVertex(HDS);  // xpu090698, NYI TopOpeBRepDS_Filler
618   FUN_ds_redusamsha(HDS);     // xpu201098
619   FUN_ds_PURGEforE9(HDS);     // xpu040998,
620   FUN_ds_completeforSE8(HDS); // xpu020998,
621   FUN_ds_completeforSE1(HDS); // xpu160398,
622   FUN_ds_completeforSE2(HDS); // xpu250398,
623   FUN_ds_completeforSE3(HDS); // xpu170498,
624   FUN_ds_completeforSE4(HDS); // xpu160698,
625   FUN_ds_completeforSE5(HDS); // xpu190698,
626   FUN_ds_completeforSE6(HDS); // xpu280798,
627 //  FUN_ds_completeforSE7(HDS); // xpu100898,
628   FUN_ds_completeforE7(HDS); // xpu130898,
629   FUN_ds_completeforSE9(HDS); // xpu011098
630   FUN_ds_complete1dForSESDM(HDS); // MSV 25.03.2002 : OCC251
631 #ifdef OCCT_DEBUG
632   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::CompleteDS"<<endl;
633 #endif
634 } // CompleteDS
635
636 //=======================================================================
637 //function : Filter
638 //purpose  : 
639 //=======================================================================
640 void TopOpeBRep_DSFiller::Filter(const Handle(TopOpeBRepDS_HDataStructure)& HDS) const
641 {
642   TopOpeBRepDS_Filter F(HDS);
643   F.ProcessEdgeInterferences();
644   F.ProcessCurveInterferences();
645 #ifdef OCCT_DEBUG
646   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::Filter"<<endl;
647 #endif
648 } // Filter
649
650 //=======================================================================
651 //function : Reducer
652 //purpose  : 
653 //=======================================================================
654 void TopOpeBRep_DSFiller::Reducer(const Handle(TopOpeBRepDS_HDataStructure)& HDS) const
655 {
656   TopOpeBRepDS_Reducer R(HDS);
657   R.ProcessEdgeInterferences();
658 #ifdef OCCT_DEBUG
659   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::Reducer"<<endl;
660 #endif
661 } // Reducer
662
663 //=======================================================================
664 //function : RemoveUnsharedGeometry
665 //purpose  : 
666 //=======================================================================
667 void TopOpeBRep_DSFiller::RemoveUnsharedGeometry(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
668 {
669   Standard_Boolean processNOG = Standard_True;
670 #ifdef OCCT_DEBUG
671   if (TopOpeBRep_GetcontextNONOG()) processNOG = Standard_False;
672 #endif
673   if (!processNOG) return;
674   
675   // xpu290998 : PRO15369 (f5,f20 only share geometric point (vertex))
676   // end processing for all information on shapes is given.
677   const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
678   Standard_Integer nbs = BDS.NbShapes();
679   for (Standard_Integer i = 1; i <= nbs; i++) {
680     TopoDS_Shape S = BDS.Shape(i);
681     if (S.ShapeType() != TopAbs_FACE) continue;
682     Standard_Boolean hsd = HDS->HasSameDomain(S);
683     if (!hsd) continue;
684     Standard_Integer rkS = BDS.AncestorRank(S);
685     if (rkS != 1) continue;
686     const TopTools_ListOfShape& lSsd = BDS.ShapeSameDomain(S);
687     TopTools_ListIteratorOfListOfShape itsd(lSsd);
688     for (; itsd.More(); itsd.Next()){
689       TopoDS_Shape Ssd = itsd.Value(); //xpuxpu
690       Standard_Integer rkSsd = BDS.AncestorRank(Ssd);
691       if (rkSsd == 1) continue;
692       
693       Standard_Boolean unfill = ::FUN_shareNOG(HDS,S,Ssd);
694       unfill = unfill && FUN_ds_sdm(BDS,S,Ssd) && FUN_ds_sdm(BDS,Ssd,S);
695       if (unfill) {
696         if (myPShapeClassifier==NULL) myPShapeClassifier = new TopOpeBRepTool_ShapeClassifier();
697         unfill = BREP_UnfillSameDomain(S,Ssd,HDS,*myPShapeClassifier);
698       }
699     }
700   }
701 #ifdef OCCT_DEBUG
702   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::RemoveUnsharedGeometry"<<endl;
703 #endif
704 } // RemoveUnsharedGeometry
705
706 //=======================================================================
707 //function : Checker
708 //purpose  : 
709 //=======================================================================
710 void TopOpeBRep_DSFiller::Checker(const Handle(TopOpeBRepDS_HDataStructure)& /*HDS*/) const
711 {
712   // TopOpeBRepDS_Checker C(HDS); // NYI
713   //#ifdef OCCT_DEBUG
714   //  if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::Checker"<<endl;
715   //#endif
716 }
717
718 //=======================================================================
719 //function : Insert2d
720 //purpose  : 
721 //=======================================================================
722
723 void TopOpeBRep_DSFiller::Insert2d
724 (const TopoDS_Shape& aS1,const TopoDS_Shape& aS2,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
725 {
726   InsertIntersection2d(aS1,aS2,HDS);
727   CompleteDS2d(HDS);
728 #ifdef OCCT_DEBUG
729   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::Insert2d"<<endl;
730 #endif
731 } // Insert
732
733 //=======================================================================
734 //function : InsertIntersection2d
735 //purpose  : 
736 //=======================================================================
737
738 void TopOpeBRep_DSFiller::InsertIntersection2d
739 (const TopoDS_Shape& aS1,const TopoDS_Shape& aS2,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
740 {
741   if (myPShapeClassifier == NULL) {
742     myPShapeClassifier = new TopOpeBRepTool_ShapeClassifier();
743   }
744   myFacesFiller.SetPShapeClassifier(myPShapeClassifier);
745   
746   if ( ! ClearShapeSameDomain(aS1, aS2, HDS) ) return;
747   
748   TopoDS_Shape S1 = aS1; 
749   TopoDS_Shape S2 = aS2; 
750   TopOpeBRepDS_DataStructure& BDS1 = HDS->ChangeDS();
751   BDS1.AddShape(S1,1);
752   BDS1.AddShape(S2,2);
753   
754   TopoDS_Shape lFF1, lFF2;
755   Standard_Boolean isFFsamdom = Standard_False;
756   
757   myShapeIntersector2d.InitIntersection(S1,S2);
758   while (myShapeIntersector2d.MoreIntersection()) {
759     
760     // The two intersecting GeomShapes gs1,gs2 and their types t1,t2
761     const TopoDS_Shape& gs1 = myShapeIntersector2d.CurrentGeomShape(1);
762     const TopoDS_Shape& gs2 = myShapeIntersector2d.CurrentGeomShape(2);
763     TopAbs_ShapeEnum t1 = gs1.ShapeType();
764     TopAbs_ShapeEnum t2 = gs2.ShapeType();
765     
766     // si le couple courant apres un couple facefacesamedomain n'est
767     // pas un couple edgeedge ==> facefacesamedomain est deconnecte 
768     Standard_Boolean isFF = ((t1==TopAbs_FACE) && (t2==TopAbs_FACE));
769     Standard_Boolean isEE = ((t1==TopAbs_EDGE) && (t2==TopAbs_EDGE));
770     Standard_Boolean unfill = (!isEE && isFFsamdom);
771     if (unfill) {
772       if (myPShapeClassifier==NULL) 
773         myPShapeClassifier = new TopOpeBRepTool_ShapeClassifier();
774       // NYI : mettre en champs un ShapeClassifier commun a tous 
775       // NYI : les fillers
776       TopAbs_State st1=TopAbs_UNKNOWN,st2=TopAbs_UNKNOWN;
777       Standard_Integer samdom = 1;
778       st1 = myPShapeClassifier->StateShapeShape(lFF1,lFF2,samdom);
779       st2 = myPShapeClassifier->StateShapeShape(lFF2,lFF1,samdom);
780       if ( ((st1 == TopAbs_OUT) && (st2 == TopAbs_OUT)) ||
781           ((st1 == TopAbs_UNKNOWN) && (st2 == TopAbs_UNKNOWN)) ) {
782         unfill = Standard_True; // NYI IN IN aussi
783       }
784       else {
785         unfill = Standard_False;
786       }
787       if (unfill) {
788         TopOpeBRepDS_DataStructure& BDS2 = HDS->ChangeDS();
789         if(!lFF1.IsNull() && !lFF2.IsNull())
790           BDS2.UnfillShapesSameDomain(lFF1,lFF2);
791       }
792     }
793     
794     if      (isFF) {
795       isFFsamdom = Standard_True;
796       myShapeIntersector2d.ChangeEdgesIntersector().SetFaces(gs1,gs2);
797       lFF1 = gs1; lFF2 = gs2;
798       BDS1.FillShapesSameDomain(gs1,gs2);
799     }
800     else if ((t1 == TopAbs_EDGE) && (t2 == TopAbs_EDGE)) {
801       TopOpeBRep_EdgesIntersector& EE = myShapeIntersector2d.ChangeEdgesIntersector();
802       EE.Dimension(2);
803       myEdgesFiller.Face(1,lFF1);
804       myEdgesFiller.Face(2,lFF2);
805       myEdgesFiller.Insert(gs1,gs2,EE,HDS);
806     }
807     myShapeIntersector2d.NextIntersection();
808   } // while (MoreIntersection())
809   
810   BREP_sortonparameter(HDS);
811   BREP_correctgbound(HDS);
812   BREP_mergePDS(HDS);
813
814 #ifdef OCCT_DEBUG
815   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::InsertIntersection2d"<<endl;
816 #endif
817
818 } // InsertIntersection2d
819
820
821 //=======================================================================
822 //function : CompleteDS2d
823 //purpose  : 
824 //=======================================================================
825
826 void TopOpeBRep_DSFiller::CompleteDS2d(const Handle(TopOpeBRepDS_HDataStructure)& HDS) const
827 {
828   const TopoDS_Shape& S1 = myShapeIntersector2d.Shape(1);
829   const TopoDS_Shape& S2 = myShapeIntersector2d.Shape(2);
830   if(S1.IsNull() || S2.IsNull()) return;
831   HDS->AddAncestors(S1);
832   HDS->AddAncestors(S2);
833   
834   TopOpeBRepDS_Filter F(HDS);
835   F.ProcessEdgeInterferences();
836   F.ProcessCurveInterferences();
837   TopOpeBRepDS_Reducer R(HDS);
838   R.ProcessEdgeInterferences();
839   // TopOpeBRepDS_Checker C(HDS); // NYI
840 #ifdef OCCT_DEBUG
841   if (TopOpeBRepTool_GettraceEND()) cout<<"DSFiller::CompleteDS2d"<<endl;
842 #endif
843 } // CompleteDS2d
844
845 //=======================================================================
846 //function : IsMadeOf1d
847 //purpose  : 
848 //=======================================================================
849
850 Standard_Boolean TopOpeBRep_DSFiller::IsMadeOf1d(const TopoDS_Shape& aS) const 
851 {
852   // vrai si il existe > 1 WIRE et/ou > 1 EDGE sans ascendance de face
853   Standard_Boolean res = Standard_False;
854   TopAbs_ShapeEnum t = aS.ShapeType();
855   if      ( t == TopAbs_WIRE ) {
856     res = Standard_True;
857   }
858   else if ( t == TopAbs_EDGE ) {
859     res = Standard_True;
860   }
861   else if ( t == TopAbs_COMPOUND ) {
862     TopoDS_Iterator it(aS);
863     if ( ! it.More() ) {
864       res = Standard_False;
865     }
866     else {
867       res = Standard_True;
868       for (; it.More(); it.Next()) {
869         const TopoDS_Shape& S = it.Value();
870         Standard_Boolean is1d = IsMadeOf1d(S);
871         if ( !is1d ) {
872           res = Standard_False;
873           break;
874         }
875       }
876     }
877   }
878   else { // != COMPOUND,WIRE,EDGE 
879     res = Standard_False;
880   }
881   
882   return res;
883 }
884
885 //=======================================================================
886 //function : IsContext1d
887 //purpose  : 
888 //=======================================================================
889
890 Standard_Boolean TopOpeBRep_DSFiller::IsContext1d(const TopoDS_Shape& aS) const 
891 {
892   Standard_Boolean is1d = IsMadeOf1d(aS);
893 #ifdef OCCT_DEBUG
894   if ( is1d ) cout<<"TopOpeBRep_DSFiller : 1d"<<endl;
895 #endif
896   if ( !is1d ) return Standard_False;
897   return Standard_True;
898 }
899
900 //=======================================================================
901 //function : Insert1d
902 //purpose  : 
903 //=======================================================================
904
905 void TopOpeBRep_DSFiller::Insert1d
906 (const TopoDS_Shape& aS1,const TopoDS_Shape& aS2,const TopoDS_Face& aF1,const TopoDS_Face& aF2,
907  const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Boolean orientFORWARD)
908 {
909   if ( ! CheckInsert(aS1,aS2) ) return;
910   
911   TopoDS_Shape S1 = aS1; 
912   TopoDS_Shape S2 = aS2; 
913   if ( orientFORWARD ) {
914     if ( S1.Orientation() == TopAbs_REVERSED ) S1.Orientation(TopAbs_FORWARD);
915     if ( S2.Orientation() == TopAbs_REVERSED ) S2.Orientation(TopAbs_FORWARD);
916   }
917   TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
918   
919   BDS.AddShape(S1,1);
920   BDS.AddShape(S2,2);
921   
922   myShapeIntersector.InitIntersection(S1,S2,aF1,aF2);
923   for (;myShapeIntersector.MoreIntersection(); myShapeIntersector.NextIntersection()) {
924     
925     // The two intersecting GeomShapes gs1,gs2 and their types t1,t2
926     const TopoDS_Shape& gs1 = myShapeIntersector.CurrentGeomShape(1);
927     const TopoDS_Shape& gs2 = myShapeIntersector.CurrentGeomShape(2);
928     TopAbs_ShapeEnum t1 = gs1.ShapeType(), t2 = gs2.ShapeType();
929     
930     if ((t1 == TopAbs_EDGE) && (t2 == TopAbs_EDGE)) {
931       TopOpeBRep_EdgesIntersector& EE = 
932         myShapeIntersector.ChangeEdgesIntersector();
933       EE.Dimension(1);
934       myEdgesFiller.Insert(gs1,gs2,EE,HDS);
935     }
936   }
937   // update wires
938   CompleteDS(HDS);
939   
940 } // Insert
941
942
943 //=======================================================================
944 //function : CheckInsert
945 //purpose  : 
946 //=======================================================================
947
948 Standard_Boolean TopOpeBRep_DSFiller::CheckInsert(const TopoDS_Shape& aS1,const TopoDS_Shape& aS2) const 
949 {
950   if (aS1.IsEqual(aS2)) {
951 #ifdef OCCT_DEBUG
952     cout<<"TopOpeBRep_DSFiller : CheckInsert : S1 == S2"<<endl;
953 #endif
954     return Standard_False;
955   }
956   return Standard_True;
957 }
958
959 //=======================================================================
960 //function : ClearShapeSameDomain
961 //purpose  : 
962 //=======================================================================
963
964 Standard_Boolean TopOpeBRep_DSFiller::ClearShapeSameDomain
965 (const TopoDS_Shape& aS1,const TopoDS_Shape& aS2,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
966 {
967   TopOpeBRepDS_DataStructure& DS = HDS->ChangeDS();
968   const Standard_Boolean b = Standard_False;
969   if(!CheckInsert(aS1,aS2))
970     return b;
971   TopExp_Explorer exp1(aS1, TopAbs_FACE), exp2(aS2, TopAbs_FACE);
972   for(; exp1.More(); exp1.Next()) {
973     const TopoDS_Shape& Shape1 = exp1.Current();
974     if(!HDS->HasShape(Shape1))
975       if(HDS->HasSameDomain(Shape1)) {
976         TopTools_ListOfShape& los =
977           DS.ChangeShapeSameDomain(Shape1); 
978         los.Clear();
979       }
980   }
981   for(; exp2.More(); exp2.Next()) {
982     const TopoDS_Shape& Shape2 = exp2.Current();
983     if(HDS->HasShape(Shape2))
984       if(HDS->HasSameDomain(Shape2)) {
985         TopTools_ListOfShape& los =
986           DS.ChangeShapeSameDomain(Shape2); 
987         los.Clear();
988       }
989   }
990   return Standard_True;
991 }
992
993
994 //=======================================================================
995 //function : ChangeShapeIntersector
996 //purpose  : 
997 //=======================================================================
998
999 TopOpeBRep_ShapeIntersector& TopOpeBRep_DSFiller::ChangeShapeIntersector()
1000 {  return myShapeIntersector; }
1001
1002 //=======================================================================
1003 //function : ChangeShapeIntersector2d
1004 //purpose  : 
1005 //=======================================================================
1006
1007 TopOpeBRep_ShapeIntersector2d& TopOpeBRep_DSFiller::ChangeShapeIntersector2d()
1008 {  return myShapeIntersector2d; }
1009
1010
1011 //=======================================================================
1012 //function : ChangeFacesFiller
1013 //purpose  : 
1014 //=======================================================================
1015
1016 TopOpeBRep_FacesFiller& TopOpeBRep_DSFiller::ChangeFacesFiller()
1017 { return myFacesFiller; }
1018
1019
1020 //=======================================================================
1021 //function : ChangeEdgesFiller
1022 //purpose  : 
1023 //=======================================================================
1024
1025 TopOpeBRep_EdgesFiller& TopOpeBRep_DSFiller::ChangeEdgesFiller()
1026 { return myEdgesFiller; }
1027
1028
1029 //=======================================================================
1030 //function : ChangeFaceEdgeFiller
1031 //purpose  : 
1032 //=======================================================================
1033
1034 TopOpeBRep_FaceEdgeFiller& TopOpeBRep_DSFiller::ChangeFaceEdgeFiller()
1035 { return myFaceEdgeFiller; }