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