aba7ac663506d8b39d3eb4923f2da64aec9c6cbb
[occt.git] / src / TopOpeBRep / TopOpeBRep_FacesFiller.cxx
1 // Created on: 1994-10-10
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <TopOpeBRep_FacesFiller.ixx>
23
24 #include <Standard_ProgramError.hxx>
25 //#include <BRepAdaptor_Curve2d.hxx>
26 #include <TopOpeBRep_FFTransitionTool.hxx>
27 #include <TopOpeBRep.hxx>
28 #include <Precision.hxx>
29 #include <TopoDS.hxx>
30 #include <BRep_Tool.hxx>
31 #include <Geom_Surface.hxx>
32 #include <GeomProjLib.hxx>
33 #include <Geom_Circle.hxx>
34 #include <Geom_Line.hxx>
35 #include <gp_Pnt.hxx>
36 #include <gp_Pnt2d.hxx>
37 #include <TopOpeBRepTool_EXPORT.hxx>
38 #include <TopOpeBRepTool_2d.hxx>
39 #include <TopOpeBRep_define.hxx>
40 #include <TopOpeBRepTool_defineG.hxx>
41 #include <TopOpeBRepTool_SC.hxx>
42
43 Standard_EXPORT Standard_Boolean FUN_projPonL(const gp_Pnt& P,const TopOpeBRep_LineInter L,const TopOpeBRep_FacesFiller& FF,
44                                  Standard_Real& paramL)
45 {
46   Standard_Boolean paramLdef = Standard_False;
47   Standard_Integer Esi = (L.ArcIsEdge(1)) ? 1:2;
48   const TopoDS_Edge& E = TopoDS::Edge(L.Arc());
49   Standard_Boolean hasC3D = FC2D_HasC3D(E);
50   Standard_Real dist;
51   if (hasC3D) {
52     BRepAdaptor_Curve BAC(E);
53     paramLdef = FUN_tool_projPonC(P,BAC,paramL,dist);
54   }
55   else {
56     BRepAdaptor_Curve2d BAC2D;
57     if      (Esi == 1)  BAC2D.Initialize(E,FF.Face(1));
58     else if (Esi == 2)  BAC2D.Initialize(E,FF.Face(2));
59     paramLdef = FUN_tool_projPonC2D(P,BAC2D,paramL,dist);
60   }
61   return paramLdef;
62 }
63
64 #ifdef DEB
65 extern Standard_Boolean TopOpeBRepDS_GettraceDSF(); 
66 extern Standard_Boolean TopOpeBRepDS_GettraceDSFK(); 
67 extern Standard_Boolean TopOpeBRepDS_GettraceDSNC(); 
68 void debffsamdom(void){}
69 #endif
70
71 static void FUN_MakeERL(TopOpeBRep_FacesIntersector& FI,TopTools_ListOfShape& ERL)
72 {
73   ERL.Clear();
74   const TopTools_IndexedMapOfShape& mer = FI.Restrictions();
75   for ( Standard_Integer ie = 1, ne = mer.Extent(); ie <= ne; ie++) {
76     const TopoDS_Edge& E = TopoDS::Edge(mer.FindKey(ie));
77     ERL.Append(E);
78   }
79 }
80
81 // Unused :
82 #ifdef DEB
83 static void FUN_MakeERL(const TopTools_MapOfShape& mapES,TopTools_ListOfShape& ERL)
84 {
85   ERL.Clear();
86   TopTools_MapIteratorOfMapOfShape itES;
87   for (itES.Initialize(mapES);itES.More();itES.Next()) {
88     const TopoDS_Shape& E = itES.Key();
89     ERL.Append(E);
90   }
91 }
92 #endif
93
94 //=======================================================================
95 //function : TopOpeBRep_FacesFiller
96 //purpose  : 
97 //=======================================================================
98 TopOpeBRep_FacesFiller::TopOpeBRep_FacesFiller() : myPShapeClassifier(NULL)
99
100   myexF1 = myexF2 = 0;
101 #ifdef DEB
102   myHFFD = new TopOpeBRep_FFDumper(this);
103 #endif
104 }
105
106 //=======================================================================
107 //function : PShapeClassifier
108 //purpose  : 
109 //=======================================================================
110 TopOpeBRepTool_PShapeClassifier TopOpeBRep_FacesFiller::PShapeClassifier() const
111 {
112   return myPShapeClassifier;
113 }
114
115 //=======================================================================
116 //function : SetPShapeClassifier
117 //purpose  : 
118 //=======================================================================
119 void TopOpeBRep_FacesFiller::SetPShapeClassifier(const TopOpeBRepTool_PShapeClassifier& PSC) 
120 {
121   myPShapeClassifier = PSC;
122 }
123
124 //=======================================================================
125 //function : Insert
126 //purpose  : 
127 //=======================================================================
128 void TopOpeBRep_FacesFiller::Insert(const TopoDS_Shape& S1,const TopoDS_Shape& S2,TopOpeBRep_FacesIntersector& FACINT,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
129 {
130   myF1 = TopoDS::Face(S1); myF1ori = S1.Orientation();
131   myF2 = TopoDS::Face(S2); myF2ori = S2.Orientation(); 
132   myFacesIntersector = &FACINT;
133   myHDS = HDS;
134   myDS = &(HDS->ChangeDS());
135   if (myPShapeClassifier == NULL) myPShapeClassifier = new TopOpeBRepTool_ShapeClassifier();
136
137 #ifdef DEB
138   Standard_Integer exF1,exF2; GetTraceIndex(exF1,exF2);
139   myFacesIntersector->InitLine();
140   for (; myFacesIntersector->MoreLine(); myFacesIntersector->NextLine()) myFacesIntersector->CurrentLine().SetTraceIndex(exF1,exF2);
141   myHFFD->Init(this);
142 #endif
143   
144   Standard_Boolean samdom = myFacesIntersector->SameDomain();
145   if ( samdom ) {
146     myDS->FillShapesSameDomain(S1,S2);
147     return;
148   }
149   
150   myFacesIntersector->InitLine();
151   for (; myFacesIntersector->MoreLine(); myFacesIntersector->NextLine()) {
152     TopOpeBRep_LineInter& L = myFacesIntersector->CurrentLine();
153     L.SetFaces(TopoDS::Face(S1),TopoDS::Face(S2));
154   }
155   
156   VP_Position(FACINT);
157
158   myFacesIntersector->InitLine();
159   for (; myFacesIntersector->MoreLine(); myFacesIntersector->NextLine()) {
160     TopOpeBRep_LineInter& L = myFacesIntersector->CurrentLine();
161     L.SetHasVPonR();
162     L.SetINL();
163     L.SetIsVClosed();
164   }
165
166   ProcessSectionEdges();
167   myFFfirstDSP = myDS->NbPoints() + 1;
168
169   FUN_MakeERL((*myFacesIntersector), myERL); // BUG
170
171   myFacesIntersector->InitLine();
172   for (; myFacesIntersector->MoreLine(); myFacesIntersector->NextLine()) {
173     TopOpeBRep_LineInter& L = myFacesIntersector->CurrentLine();
174     LoadLine(L);
175     ProcessLine();
176   }
177   
178 }
179
180 //=======================================================================
181 //function : ChangePointClassifier
182 //purpose  : 
183 //=======================================================================
184 TopOpeBRep_PointClassifier& TopOpeBRep_FacesFiller::ChangePointClassifier()
185 {  
186   return myPointClassifier;
187 }
188
189
190 //=======================================================================
191 //function : LoadLine
192 //purpose  : 
193 //=======================================================================
194 void TopOpeBRep_FacesFiller::LoadLine(TopOpeBRep_LineInter& L)
195 {
196   myLine = &L;
197   Standard_Boolean bchk = CheckLine(L);
198   Standard_Boolean binl = L.INL();
199   myLineINL = binl;
200   {
201     TopOpeBRep_TypeLineCurve t = L.TypeLineCurve();
202     if ( !bchk && binl && t == TopOpeBRep_LINE ) {
203       bchk = Standard_True;
204     }
205   }
206   L.SetOK(bchk);
207   myLineOK = bchk;
208   if (!myLineOK) return;
209   
210   L.ComputeFaceFaceTransition();
211 } // LoadLine
212
213 //=======================================================================
214 //function : CheckLine
215 //purpose  : private
216 //           returns False if L is WALKING line with a number of VPoints < 2
217 //           else returns True 
218 //=======================================================================
219 Standard_Boolean TopOpeBRep_FacesFiller::CheckLine(TopOpeBRep_LineInter& L) const
220 {
221   Standard_Real tol1,tol2;
222   myFacesIntersector->GetTolerances(tol1,tol2);
223   
224   Standard_Boolean check = Standard_True;
225   TopOpeBRep_TypeLineCurve t = L.TypeLineCurve();
226   Standard_Integer nbvp = L.NbVPoint();
227   
228 #ifdef DEB
229   Standard_Boolean TDSF = TopOpeBRepDS_GettraceDSF();
230   if (TDSF) { cout<<"CheckLine ";TopOpeBRep::Print(t,cout);cout<<" "<<nbvp<<" points"<<endl; }
231 #endif
232   
233   if ( t == TopOpeBRep_WALKING ) {
234     if ( nbvp < 2 ) {
235 #ifdef DEB
236       cout<<"\n=== Nb de IntPatch_Point sur WL incorrect : "<<nbvp<<" ===\n";
237 #endif
238       check = Standard_False;
239     }
240   }
241   else if (t == TopOpeBRep_LINE) {
242     Standard_Integer np = 0;
243     TopOpeBRep_VPointInterIterator VPI;
244     
245     for ( VPI.Init(L); VPI.More(); VPI.Next()) {
246       const TopOpeBRep_VPointInter& VP = VPI.CurrentVP();
247       if ( VP.Keep() ) np++;
248     }
249     if ( np != 2 ) {
250       return Standard_True;
251     }
252     
253     TopOpeBRep_VPointInter A,B;
254     np = 0;
255     for ( VPI.Init(L); VPI.More(); VPI.Next()) {
256       const TopOpeBRep_VPointInter& VP = VPI.CurrentVP();
257       if ( !VP.Keep() ) continue;
258       np++;
259       if ( np == 1 ) A = VP;
260       if ( np == 2 ) B = VP;
261     }
262     
263     Standard_Boolean isAV1 = A.IsVertexOnS1();
264     Standard_Boolean isAV2 = A.IsVertexOnS2();
265     TopoDS_Shape V1;
266     if (isAV1) V1 = A.VertexOnS1();
267     if (isAV2) V1 = A.VertexOnS2();
268     Standard_Boolean isBV1 = B.IsVertexOnS1();
269     Standard_Boolean isBV2 = B.IsVertexOnS2();
270     TopoDS_Shape V2;
271     if (isBV1) V2 = B.VertexOnS1();
272     if (isBV2) V2 = B.VertexOnS2();
273     
274 #ifdef DEB
275     if (TDSF) {
276       cout<<"CheckLine : isAV1 isAV2 isBV1 isBV2 ";
277       cout<<isAV1<<" "<<isAV2<<" "<<isBV1<<" "<<isBV2<<endl;
278     }
279 #endif
280     
281     if ( !V1.IsNull() && ( V1.IsSame(V2) ) ) {
282 #ifdef DEB
283       Standard_Real parA = A.ParameterOnLine();    
284       Standard_Real parB = B.ParameterOnLine();    
285       if (TDSF) {
286         cout<<"kpart : parA parB delta "<<parA<<" "<<parB<<" "<<parA-parB<<endl;
287         cout<<"kpart : rejet de ligne"<<endl;
288       }
289 #endif
290       return Standard_False;      
291     }
292   } // LINE
293   else {
294     Standard_Boolean notrnotw = (t != TopOpeBRep_RESTRICTION && t != TopOpeBRep_WALKING);
295     if (notrnotw) {
296       if (t == TopOpeBRep_CIRCLE) { 
297         // cto 012 D2, faces 6 et 1, line 3 incorrecte.
298         
299         Standard_Integer iINON1,iINONn,nINON;
300         myLine->VPBounds(iINON1,iINONn,nINON);
301         if ( nINON >= 2) {
302           
303           const TopOpeBRep_VPointInter& A = myLine->VPoint(iINON1);
304           const TopOpeBRep_VPointInter& B = myLine->VPoint(iINONn);
305           Standard_Real parA = A.ParameterOnLine();    
306           Standard_Real parB = B.ParameterOnLine();    
307           Standard_Boolean conf = (fabs(parA-parB) < tol1);
308           if (conf) {
309             //modified by NIZHNY-MZV  Wed Dec  1 09:53:08 1999
310             check = Msf;
311 //modified by NIZHNY-MZV  Wed Dec  1 09:53:18 1999          Standard_Boolean isp = L.IsPeriodic();
312 //modified by NIZHNY-MZV  Wed Dec  1 09:53:20 1999          if (isp) {
313 //modified by NIZHNY-MZV  Wed Dec  1 09:53:21 1999            Handle(Geom_Circle) C = Handle(Geom_Circle)::DownCast(L.Curve());
314 //modified by NIZHNY-MZV  Wed Dec  1 09:53:22 1999            Standard_Real per = C->Period();
315 //modified by NIZHNY-MZV  Wed Dec  1 09:53:23 1999            parB = parA + per;
316 //modified by NIZHNY-MZV  Wed Dec  1 09:53:25 1999          }
317           }
318           
319 //modified by NIZHNY-MZV  Wed Dec  1 09:53:32 1999        Standard_Real t = 0.2567899311;
320 //modified by NIZHNY-MZV  Wed Dec  1 09:53:33 1999        Standard_Real p = (1-t)*parA + t*parB;
321 //modified by NIZHNY-MZV  Wed Dec  1 09:53:34 1999        Handle(Geom_Curve) GC = myLine->Curve();
322 //modified by NIZHNY-MZV  Wed Dec  1 09:53:34 1999        const TopoDS_Face& F1 = TopoDS::Face(myF1);
323 //modified by NIZHNY-MZV  Wed Dec  1 09:53:35 1999        const TopoDS_Face& F2 = TopoDS::Face(myF2);
324 //modified by NIZHNY-MZV  Wed Dec  1 09:53:36 1999        Handle(Geom_Surface) GS1 = BRep_Tool::Surface(F1);
325 //modified by NIZHNY-MZV  Wed Dec  1 09:53:36 1999        Handle(Geom_Surface) GS2 = BRep_Tool::Surface(F2);
326 //modified by NIZHNY-MZV  Wed Dec  1 09:53:37 1999        Handle(Geom2d_Curve) C1 = GeomProjLib::Curve2d(GC,parA,parB,GS1);
327 //modified by NIZHNY-MZV  Wed Dec  1 09:53:38 1999        Handle(Geom2d_Curve) C2 = GeomProjLib::Curve2d(GC,parA,parB,GS2);       
328           
329 //modified by NIZHNY-MZV  Wed Dec  1 09:53:39 1999        gp_Pnt2d P1 = C1->Value(p);
330 //modified by NIZHNY-MZV  Wed Dec  1 09:53:44 1999        gp_Pnt2d P2 = C2->Value(p);
331 //modified by NIZHNY-MZV  Wed Dec  1 09:53:45 1999        TopOpeBRep_PointClassifier* pcl = (TopOpeBRep_PointClassifier*)((void*)&myPointClassifier);
332 //modified by NIZHNY-MZV  Wed Dec  1 09:53:46 1999        TopAbs_State staP1 = pcl->Classify(F1,P1,tol1);
333 //modified by NIZHNY-MZV  Wed Dec  1 09:53:47 1999        TopAbs_State staP2 = pcl->Classify(F2,P2,tol1);
334 //modified by NIZHNY-MZV  Wed Dec  1 09:53:48 1999Standard_Boolean ok1 = (staP1 == TopAbs_IN || staP1 == TopAbs_ON);
335 //modified by NIZHNY-MZV  Wed Dec  1 09:53:49 1999        Standard_Boolean ok2 = (staP2 == TopAbs_IN || staP2 == TopAbs_ON);
336 //modified by NIZHNY-MZV  Wed Dec  1 09:53:50 1999        check = (ok1 && ok2);
337           
338         }
339       } // CIRCLE
340       else if (t == TopOpeBRep_HYPERBOLA) {
341         Standard_Integer iINON1,iINONn,nINON;
342         myLine->VPBounds(iINON1,iINONn,nINON);
343         if ( nINON < 2 ) {
344           check = Standard_False;
345         }
346       }
347       else if (t == TopOpeBRep_ELLIPSE) {
348         Standard_Integer iINON1,iINONn,nINON;
349         myLine->VPBounds(iINON1,iINONn,nINON);
350         if ( nINON < 2 ) {
351           check = Standard_False;
352         }
353         else {
354           const TopOpeBRep_VPointInter& A = myLine->VPoint(iINON1);
355           const TopOpeBRep_VPointInter& B = myLine->VPoint(iINONn);
356           Standard_Real parA = A.ParameterOnLine();    
357           Standard_Real parB = B.ParameterOnLine();    
358           Standard_Boolean conf = (fabs(parA-parB) < tol1);
359           if (conf) {
360             check = Standard_False;
361           }
362         }
363       }
364     }
365   }
366   
367 #ifdef DEB
368   if (!check) { cout<<"# DEB CheckLine : rejet de ";TopOpeBRep::Print(t,cout);cout<<" a "<<nbvp<<" points"<<endl; }
369 #endif
370
371   return check;
372 }
373
374 //=======================================================================
375 //function : VP_Position
376 //purpose  : 
377 //=======================================================================
378 //void TopOpeBRep_FacesFiller::VP_Position(TopOpeBRep_FacesIntersector& FACINT)
379 void TopOpeBRep_FacesFiller::VP_Position(TopOpeBRep_FacesIntersector& )
380 {
381   for (myFacesIntersector->InitLine(); 
382        myFacesIntersector->MoreLine();
383        myFacesIntersector->NextLine()) {
384     TopOpeBRep_LineInter& L = myFacesIntersector->CurrentLine();
385     const TopOpeBRep_TypeLineCurve tl = L.TypeLineCurve();
386     Standard_Boolean ok = (tl == TopOpeBRep_RESTRICTION) ;
387     if ( ok ) VP_Position(L);
388   }
389   
390   for (myFacesIntersector->InitLine(); 
391        myFacesIntersector->MoreLine(); 
392        myFacesIntersector->NextLine()) {
393     TopOpeBRep_LineInter& L = myFacesIntersector->CurrentLine();
394     const TopOpeBRep_TypeLineCurve tl = L.TypeLineCurve();
395     Standard_Boolean ok = (tl != TopOpeBRep_RESTRICTION) ;
396     if ( ok ) VP_Position(L);
397   }
398 }
399
400 //=======================================================================
401 //function : VP_Position
402 //purpose  : 
403 //=======================================================================
404 void TopOpeBRep_FacesFiller::VP_Position(TopOpeBRep_LineInter& L)
405 {
406   myLine = &L;
407 #ifdef DEB
408   if (TopOpeBRepDS_GettraceDSFK()) {
409     cout<<endl<<"VP_Position on line "<<L.Index()<<" ";L.DumpType();cout<<endl;
410   }
411 #endif
412   Standard_Boolean isrest = (L.TypeLineCurve() == TopOpeBRep_RESTRICTION) ;
413   
414   if (!isrest) VP_PositionOnL(L);
415   else         VP_PositionOnR(L);
416   
417   L.SetVPBounds();
418   
419 #ifdef DEB
420   if (TopOpeBRepDS_GettraceDSFK()) {
421     Standard_Integer VPF,VPL,VPN; L.VPBounds(VPF,VPL,VPN);
422     cout<<"SetVPBounds : VPF,VPL,VPN = "<<VPF<<","<<VPL<<","<<VPN;
423     if (VPN != 0) cout<<" : VP(s) kept"<<endl;
424     else          cout<<" : NO VP kept"<<endl;
425   }
426 #endif
427 }
428
429 //=======================================================================
430 //function : VP_PositionOnL
431 //purpose  : 
432 //=======================================================================
433 void TopOpeBRep_FacesFiller::VP_PositionOnL(TopOpeBRep_LineInter& L)
434 {
435   TopOpeBRep_VPointInterIterator VPI(L);
436   Standard_Integer Lindex = L.Index();
437   TopOpeBRep_VPointInterClassifier VPC;
438   
439   for (; VPI.More(); VPI.Next()) {
440     TopOpeBRep_VPointInter& VP = VPI.ChangeCurrentVP();
441     Standard_Integer VPsi = VP.ShapeIndex();
442     const gp_Pnt& P3D = VP.Value();
443     
444     Standard_Boolean VPequalVPONRESTRICTION = Standard_False;
445     TopOpeBRep_FacesIntersector& FI = *((TopOpeBRep_FacesIntersector*)((void*)myFacesIntersector));
446     Standard_Integer iOL = 1,n = FI.NbLines(); 
447     for (iOL=1; iOL<=n; iOL++ ) { 
448       if (iOL == Lindex ) continue; 
449       TopOpeBRep_LineInter& OL = FI.ChangeLine(iOL);
450       VPequalVPONRESTRICTION = PequalVPonR(P3D,VPsi,VP,OL);
451       if ( VPequalVPONRESTRICTION ) break;
452     }
453     
454     if ( !VPequalVPONRESTRICTION ) {
455       VP_Position(VP,VPC);
456     }    
457   }
458 }
459
460 //=======================================================================
461 //function : VP_PositionOnR
462 //purpose  : 
463 //=======================================================================
464 void TopOpeBRep_FacesFiller::VP_PositionOnR(TopOpeBRep_LineInter& L)
465 {
466   TopOpeBRep_VPointInterClassifier VPC;
467   
468   TopOpeBRep_VPointInterIterator VPI(L);
469   Standard_Integer Esi   = (L.ArcIsEdge(1)) ? 1:2;
470   Standard_Integer OOEsi = (L.ArcIsEdge(1)) ? 2:1;
471   
472   Standard_Boolean isline = Standard_False;
473   const TopoDS_Edge& earc = TopoDS::Edge(L.Arc());
474   Standard_Boolean hasc3d = FC2D_HasC3D(earc);
475   if (hasc3d) isline = FUN_tool_line(earc);
476   else {
477     BRepAdaptor_Curve2d BAC2D;
478     if      (Esi == 1)  BAC2D.Initialize(earc,myF1);
479     else if (Esi == 2)  BAC2D.Initialize(earc,myF2);
480     GeomAbs_CurveType t = BAC2D.GetType();
481     isline = (t == GeomAbs_Line);
482   }
483   
484   for (; VPI.More(); VPI.Next()) {
485     TopOpeBRep_VPointInter& VP = VPI.ChangeCurrentVP();
486     
487     Standard_Boolean isvertex = VP.IsVertex(Esi);
488     if ( isvertex ) {
489       if (!isline) VP_Position(VP,VPC);
490       continue;
491     }
492     Standard_Boolean OOisvertex = VP.IsVertex(OOEsi);
493     if ( OOisvertex ) {
494       if (!isline) VP_Position(VP,VPC);
495       continue;
496     }
497     
498     const gp_Pnt& P = VP.Value();
499     Standard_Boolean arcisE = L.ArcIsEdge(Esi);
500     Standard_Boolean arcisOOE = L.ArcIsEdge(OOEsi);
501     
502     if (arcisE) {
503       Standard_Real paramC;Standard_Boolean paramCdef = FUN_projPonL(P,L,(*this),paramC);
504       if ( paramCdef ) {
505         const TopoDS_Edge& E = TopoDS::Edge(L.Arc());
506         VP.State(TopAbs_ON,Esi);
507         VP.EdgeON(E,paramC,Esi);
508       }
509       else {
510 //      Standard_ProgramError::Raise("VP_Position projection failed on E");
511         VP.ChangeKeep(Standard_False); // xpu051198
512       }
513     }
514     
515     if (arcisOOE) {
516       Standard_Real paramC;Standard_Boolean paramCdef = FUN_projPonL(P,L,(*this),paramC);
517       if ( paramCdef ) {
518         const TopoDS_Edge& OOE = TopoDS::Edge(L.Arc());
519         VP.State(TopAbs_ON,OOEsi);
520         VP.EdgeON(OOE,paramC,OOEsi);
521       }
522       else {
523 //      Standard_ProgramError::Raise("VP_Position projection failed on OOE");
524         VP.ChangeKeep(Standard_False); // xpu051198
525       }
526     }
527     
528 #ifdef DEB
529     if (TopOpeBRepDS_GettraceDSFK()) {
530       cout<<"VP "<<VP.Index()<<" on "<<Esi<<" : ";
531       TopAbs::Print(VP.State(Esi),cout);
532       cout<<"/"<<Esi<<" ";
533       if (VP.Keep()) { cout<<"kept"<<endl; }
534       else           { cout<<"NOT kept"<<endl; }
535     }
536 #endif
537   }
538 }
539
540 //=======================================================================
541 //function : VP_Position
542 //purpose  : 
543 //=======================================================================
544 void TopOpeBRep_FacesFiller::VP_Position(TopOpeBRep_VPointInter& VP,TopOpeBRep_VPointInterClassifier& VPC)
545 {
546   Standard_Integer si = VP.ShapeIndex();
547   Standard_Boolean c1=Standard_False,c2=Standard_False;
548
549   if      (si == 0) { c1 = Standard_True; c2 = Standard_True; }
550   else if (si == 1) { c1 = Standard_False; c2 = Standard_True; }
551   else if (si == 2) { c1 = Standard_True; c2 = Standard_False; }
552   else if (si == 3) { c1 = Standard_True; c2 = Standard_True; }
553   
554   Standard_Boolean AssumeINON = Standard_False;
555   if (myLine) AssumeINON = (myLine->TypeLineCurve() != TopOpeBRep_RESTRICTION);
556
557   // modified by NIZHNY-MKK  Fri Oct 27 14:50:28 2000.BEGIN
558   //   Standard_Real tol = Precision::Confusion();
559   Standard_Real tol1, tol2;
560   tol1 = tol2 = Precision::Confusion();
561   myFacesIntersector->GetTolerances(tol1, tol2);
562   Standard_Real tol = (tol1 > tol2) ? tol1 : tol2;
563   // modified by NIZHNY-MKK  Fri Oct 27 14:50:36 2000.END
564
565   if (c1) VPC.VPointPosition(myF1,VP,1,myPointClassifier,AssumeINON,tol);
566   if (c2) VPC.VPointPosition(myF2,VP,2,myPointClassifier,AssumeINON,tol);
567   
568 #ifdef DEB
569   if (TopOpeBRepDS_GettraceDSFK()) {
570     cout<<"VP "<<VP.Index()<<" on "<<si<<" : ";
571     if (c1) { TopAbs::Print(VP.State(1),cout);cout<<"/1 "; }
572     if (c2) { TopAbs::Print(VP.State(2),cout);cout<<"/2 "; }
573     if (VP.Keep()) { cout<<"kept"<<endl; }
574     else           { cout<<"NOT kept"<<endl; }
575   }
576 #endif
577 }
578
579 //=======================================================================
580 //function : PequalVPonR
581 //purpose  : 
582 //=======================================================================
583 Standard_Boolean TopOpeBRep_FacesFiller::PequalVPonR(const gp_Pnt& P3D,const Standard_Integer VPsi,TopOpeBRep_VPointInter& VP,TopOpeBRep_LineInter& Lrest) const 
584 {
585   const TopOpeBRep_TypeLineCurve tOL = Lrest.TypeLineCurve();
586   Standard_Boolean OLok = (tOL == TopOpeBRep_RESTRICTION) ;
587   if ( !OLok ) return Standard_False;
588   
589   Standard_Boolean VPequalVPONRESTRICTION = Standard_False;
590   const TopoDS_Edge& EOL = TopoDS::Edge(Lrest.Arc());
591   Standard_Integer EOLsi = (Lrest.ArcIsEdge(1)) ? 1:2;
592   
593   TopOpeBRep_VPointInterIterator VPIOL(Lrest);
594   for (; VPIOL.More(); VPIOL.Next()) {
595     TopOpeBRep_VPointInter& VPOL = VPIOL.ChangeCurrentVP();
596     Standard_Integer VPOLsi = VPOL.ShapeIndex();
597     
598     Standard_Boolean VPOLisvertex = Standard_False;
599     VPOLisvertex = VPOL.IsVertex(1);
600     if (VPOLisvertex) continue;
601     
602     Standard_Boolean diffsi = (VPOLsi != VPsi);
603     if ( diffsi ) continue;
604     
605     TopAbs_State stateEsi = VPOL.State(EOLsi);
606     if (stateEsi != TopAbs_ON) continue; 
607     
608     const gp_Pnt& P3DOL = VPOL.Value();
609     Standard_Real tolE = BRep_Tool::Tolerance(EOL);
610     VPequalVPONRESTRICTION = P3DOL.IsEqual(P3D,tolE);
611     
612     if ( VPequalVPONRESTRICTION ) {
613       Standard_Real paramCOL = VPOL.EdgeONParameter(EOLsi);
614       VP.State(TopAbs_ON,EOLsi);
615       VP.EdgeON(EOL,paramCOL,EOLsi);
616       break;
617     }
618   }
619   return VPequalVPONRESTRICTION;
620 }
621
622 //=======================================================================
623 //function : FacesIntersector
624 //purpose  : 
625 //=======================================================================
626 TopOpeBRep_FacesIntersector& TopOpeBRep_FacesFiller::ChangeFacesIntersector()
627 {
628   return (*myFacesIntersector);
629 }
630
631 //=======================================================================
632 //function : HDataStructure
633 //purpose  : 
634 //=======================================================================
635 Handle(TopOpeBRepDS_HDataStructure) TopOpeBRep_FacesFiller::HDataStructure()
636 {
637   return myHDS;
638 }
639
640 //=======================================================================
641 //function : DataStructure
642 //purpose  : 
643 //=======================================================================
644 TopOpeBRepDS_DataStructure& TopOpeBRep_FacesFiller::ChangeDataStructure()
645 {
646   return (*myDS);
647 }
648
649 //=======================================================================
650 //function : Face
651 //purpose  : 
652 //=======================================================================
653 const TopoDS_Face& TopOpeBRep_FacesFiller::Face(const Standard_Integer I) const
654 {
655   if      (I == 1) return myF1;
656   else if (I == 2) return myF2;
657   Standard_ProgramError::Raise("FacesFiller::Face");
658   return myF1;
659 }
660
661 //=======================================================================
662 //function : FaceFaceTransition
663 //purpose  : 
664 //=======================================================================
665 const TopOpeBRepDS_Transition& TopOpeBRep_FacesFiller::FaceFaceTransition(const TopOpeBRep_LineInter& L,const Standard_Integer I) const
666 {
667   const TopOpeBRepDS_Transition& T = L.FaceFaceTransition(I);
668   return T;
669 }
670
671 //=======================================================================
672 //function : FaceFaceTransition
673 //purpose  : 
674 //=======================================================================
675 const TopOpeBRepDS_Transition& TopOpeBRep_FacesFiller::FaceFaceTransition(const Standard_Integer I) const
676 {
677   const TopOpeBRepDS_Transition& T = myLine->FaceFaceTransition(I);
678   return T;
679 }
680
681 TopOpeBRep_PFacesIntersector TopOpeBRep_FacesFiller::PFacesIntersectorDummy() const 
682 {return myFacesIntersector;}
683 TopOpeBRepDS_PDataStructure TopOpeBRep_FacesFiller::PDataStructureDummy() const 
684 {return myDS;}
685 TopOpeBRep_PLineInter TopOpeBRep_FacesFiller::PLineInterDummy() const 
686 {return myLine;}
687
688 //=======================================================================
689 //function : SetTraceIndex
690 //purpose  : 
691 //=======================================================================
692 void TopOpeBRep_FacesFiller::SetTraceIndex(const Standard_Integer exF1,const Standard_Integer exF2)
693
694   myexF1 = exF1;
695   myexF2 = exF2;
696 }
697
698 //=======================================================================
699 //function : GetTraceIndex
700 //purpose  : 
701 //=======================================================================
702 void TopOpeBRep_FacesFiller::GetTraceIndex(Standard_Integer& exF1,Standard_Integer& exF2)const 
703
704   exF1 = myexF1;
705   exF2 = myexF2;
706 }