bff2a268b4fe05ced147b65c00ffc403b516c169
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_BuilderON2d.cxx
1 // Created on: 1998-05-07
2 // Created by: Xuan PHAM PHU
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRep_Tool.hxx>
19 #include <Precision.hxx>
20 #include <TopExp.hxx>
21 #include <TopoDS.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopOpeBRepBuild_BuilderON.hxx>
24 #include <TopOpeBRepBuild_define.hxx>
25 #include <TopOpeBRepDS.hxx>
26 #include <TopOpeBRepDS_connex.hxx>
27 #include <TopOpeBRepDS_EXPORT.hxx>
28 #include <TopOpeBRepDS_Interference.hxx>
29 #include <TopOpeBRepDS_InterferenceTool.hxx>
30 #include <TopOpeBRepDS_ShapeShapeInterference.hxx>
31 #include <TopOpeBRepTool_EXPORT.hxx>
32 #include <TopOpeBRepTool_SC.hxx>
33
34 #define M_OUT(st) (st == TopAbs_OUT)
35 #define M_IN( st) (st == TopAbs_IN)
36 #define M_FORWARD(st) (st == TopAbs_FORWARD)
37 #define M_REVERSED(st) (st == TopAbs_REVERSED)
38
39 #ifdef OCCT_DEBUG
40 Standard_EXPORT Standard_Boolean TopOpeBRepBuild_GetcontextEINTERNAL();
41 Standard_EXPORT Standard_Boolean TopOpeBRepBuild_GetcontextEEXTERNAL();
42 Standard_EXPORT void debfillonf(const Standard_Integer iF);
43 Standard_EXPORT void debON2d(const Standard_Integer iF)
44 {cout<<"++ debON2d "<<iF<<" "<<endl;}
45 #endif
46
47 Standard_EXPORT TopAbs_State FUN_build_TB(const TopOpeBRepBuild_PBuilder& PB,const Standard_Integer rank); // xpu290698
48 Standard_EXPORT Standard_Boolean FUN_keepEON(const TopOpeBRepBuild_Builder& B,
49                                 const TopoDS_Shape& sEG,const TopoDS_Shape& sFOR,const TopoDS_Shape& sFS,
50                                 const Standard_Boolean EGBoundFOR,
51                                 const TopOpeBRepDS_Transition& TFE,const TopAbs_State TB1,const TopAbs_State TB2);
52 Standard_EXPORT void FUN_coutmess(const TCollection_AsciiString& m);
53
54 Standard_EXPORTEXTERN  TopOpeBRepDS_PDataStructure GLOBAL_DS2d;
55
56 //=======================================================================
57 //function : Perform2d
58 //purpose  : 
59 //=======================================================================
60 void TopOpeBRepBuild_BuilderON::Perform2d
61 (const TopOpeBRepBuild_PBuilder& PB,
62  const TopoDS_Shape& FOR,const TopOpeBRepBuild_PGTopo& PG,
63  const TopOpeBRepTool_Plos& PLSclass, const TopOpeBRepBuild_PWireEdgeSet& PWES)
64 {
65   myPB = PB;
66   myFace = FOR;
67   myPG = PG;
68   myPLSclass = PLSclass;
69   myPWES = PWES;
70
71   const TopOpeBRepDS_DataStructure& BDS=myPB->DataStructure()->DS();
72   if (GLOBAL_DS2d == NULL) GLOBAL_DS2d = (TopOpeBRepDS_PDataStructure)new TopOpeBRepDS_DataStructure();
73   const TopOpeBRepDS_ListOfInterference& lFEI = GLOBAL_DS2d->ShapeInterferences(FOR);
74
75 #ifdef OCCT_DEBUG
76   Standard_Integer iFOR;Standard_Boolean tFOR=myPB->GtraceSPS(FOR,iFOR);
77   if (tFOR) debfillonf(iFOR);
78   if (tFOR) {cout<<endl<<"LI on F"<<iFOR<<":"<<endl;
79              for (TopOpeBRepDS_ListIteratorOfListOfInterference iit(lFEI); iit.More(); iit.Next())
80                {iit.Value()->Dump(cout);cout<<endl;}}
81 #endif
82
83   for (TopOpeBRepDS_ListIteratorOfListOfInterference itI(lFEI); itI.More(); itI.Next()){
84     const Handle(TopOpeBRepDS_Interference)& I = itI.Value();
85     TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(I,GT,GI,ST,SI);
86
87     const TopoDS_Edge& EG=TopoDS::Edge(BDS.Shape(GI));
88 #ifdef OCCT_DEBUG
89 //    Standard_Integer iEG=BDS.Shape(EG);
90 #endif
91     const TopTools_ListOfShape& lEspON=myPB->Splits(EG,TopAbs_ON);
92 #ifdef OCCT_DEBUG
93 //    Standard_Integer nEspON=lEspON.Extent();
94 #endif
95     for(TopTools_ListIteratorOfListOfShape it(lEspON);it.More();it.Next()) {
96       const TopoDS_Shape& EspON=it.Value();
97       GFillONParts2dWES2(I,EspON);
98     }
99   }
100 }
101
102 //=======================================================================
103 //function : GFillONPartsWES2
104 //purpose  : 
105 //=======================================================================
106 void TopOpeBRepBuild_BuilderON::GFillONParts2dWES2(const Handle(TopOpeBRepDS_Interference)& I,const TopoDS_Shape& EspON)
107 {
108   const Handle(TopOpeBRepDS_HDataStructure)& HDS=myPB->DataStructure();
109   const TopOpeBRepDS_DataStructure& BDS= HDS->DS();
110   Handle(TopOpeBRepDS_ShapeShapeInterference) SSI (Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I));
111   TopAbs_State TB1,TB2;myPG->StatesON(TB1,TB2);
112   TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(SSI,GT,GI,ST,SI);
113 //  const TopOpeBRepDS_Transition& TFE=SSI->Transition(); 
114   Standard_Boolean EGBoundFOR=SSI->GBound();
115   const TopoDS_Face& FOR=TopoDS::Face(myFace); Standard_Integer iFOR=BDS.Shape(FOR);
116   const TopoDS_Edge& EG=TopoDS::Edge(BDS.Shape(GI));
117 #ifdef OCCT_DEBUG
118 //  Standard_Integer iEG=BDS.Shape(EG);
119 #endif
120   const TopoDS_Face& FS=TopoDS::Face(BDS.Shape(SI)); 
121 #ifdef OCCT_DEBUG
122 //  Standard_Integer iFS=BDS.Shape(FS);
123 //  Standard_Boolean isclosedFF=BRep_Tool::IsClosed(EG,FOR);
124 //  Standard_Boolean isclosedFS=BRep_Tool::IsClosed(EG,FS);
125 //  Standard_Boolean isclosed=(isclosedFF || isclosedFS);
126 //  Standard_Boolean isrest=BDS.IsSectionEdge(EG);
127 //  Standard_Boolean issplit=myPB->IsSplit(EG,TopAbs_ON);
128 //  Standard_Integer rankFS=myPB->GShapeRank(FS);
129 #endif  
130   Standard_Integer rankEG=myPB->GShapeRank(EG);
131 #ifdef OCCT_DEBUG
132 //  Standard_Integer rankFOR=myPB->GShapeRank(FOR);
133 #endif
134               
135 //  TopAbs_State TBEG = (rankEG == 1) ? TB1 : TB2;
136   TopAbs_State TBEG = FUN_build_TB(myPB,rankEG);
137 #ifdef OCCT_DEBUG
138 //  TopAbs_State TFEbef = TFE.Before();
139 //  TopAbs_State TFEaft = TFE.After();
140 //  Standard_Boolean EGboundFOR =
141 //                   Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I)->GBound();
142 #endif
143   Standard_Boolean eghassd   = HDS->HasSameDomain(EG);
144
145 #ifdef OCCT_DEBUG
146   Standard_Boolean tFOR=myPB->GtraceSPS(iFOR);
147 //  Standard_Boolean tE=myPB->GtraceSPS(GI);
148 //  Standard_Boolean tEFOR = (tE && tFOR);
149   if (tFOR) {debON2d(iFOR);}
150   if (tFOR) {I->Dump(cout);cout<<endl;}
151 #endif    
152   
153   Standard_Integer iFCX=SI;
154   Standard_Boolean FFinSDSO = Standard_True;
155 #ifdef OCCT_DEBUG
156 //  Standard_Boolean FFinSDDO = Standard_False;
157 #endif
158   Standard_Boolean FFinSD= Standard_True;
159   TopoDS_Face FCX = FS;
160   
161 #ifdef OCCT_DEBUG
162 //  TopAbs_Orientation oFOR = BDS.Shape(iFOR).Orientation();
163 //  TopAbs_Orientation oFS  = BDS.Shape(iFS).Orientation();
164 //  TopAbs_Orientation oFCX = BDS.Shape(iFCX).Orientation();
165 //  Standard_Integer irefFOR = BDS.SameDomainRef(FOR);
166 //  Standard_Integer irefFCX = BDS.SameDomainRef(FCX);
167 //  Standard_Boolean FORisref = (irefFOR == iFOR);
168 //  Standard_Boolean FCXisref = (irefFCX == iFCX);
169 #endif
170   
171   TopAbs_Orientation oegFCXF;Standard_Boolean EGBoundFCX = FUN_tool_orientEinFFORWARD(EG,FCX,oegFCXF);
172   TopAbs_Orientation oegFCX ;
173 #ifdef OCCT_DEBUG
174 //  Standard_Boolean ok2 =
175 #endif
176             FUN_tool_orientEinF(EG,FCX,oegFCX);
177
178   Standard_Boolean opeFus = myPB->Opefus(); 
179   Standard_Boolean opeCut = myPB->Opec12() || myPB->Opec21();
180   Standard_Boolean opeCom = myPB->Opecom();
181   
182     
183   Standard_Boolean yap6 = Standard_True;
184   yap6 = yap6 && FFinSD; 
185 //  yap6 = yap6 && (!EGBoundFOR);
186 //  yap6 = yap6 && EGBoundFCX;
187   yap6 =  yap6 && (EGBoundFOR || EGBoundFCX);
188   yap6 = yap6 && eghassd;
189    
190   //=========================================
191   if ( yap6) {
192 #ifdef OCCT_DEBUG
193     if (tFOR) cout<<"* yap6 = 1"<<endl;
194 #endif
195     TopAbs_Orientation neworiE = TopAbs_FORWARD;
196     // FF est samedomain avec FCX
197     // on evalue la transition de FOR par rapport a la matiere 2d de la face FCX
198     // au lieu de la transition par rapport a la matiere 3d de la face FS
199     // EG est une arete de FCX, oegFCXF=O.T. de EG dans FCX orientee FORWARD
200     
201     Standard_Boolean b = Standard_False;
202
203     Standard_Boolean SO = FFinSDSO;//(FFinSDSO && (oFOR == oFCX)) || (FFinSDDO && (oFOR != oFCX));
204 #ifdef OCCT_DEBUG
205 //    Standard_Integer rkToFill = BDS.AncestorRank(myFace); //DEB
206 #endif
207     Standard_Boolean rk1 = (rankEG == 1);
208     if (!rk1) return;
209
210     TopAbs_Orientation oegFOR;
211     Standard_Boolean shareG = Standard_False;
212     Standard_Boolean ok = Standard_False;
213     if      (EGBoundFCX) 
214       ok = FUN_ds_shareG(myPB->DataStructure(),iFOR,iFCX,GI,TopoDS::Edge(EspON),shareG);
215     else if (EGBoundFOR)
216       ok = FUN_ds_shareG(myPB->DataStructure(),iFCX,iFOR,GI,TopoDS::Edge(EspON),shareG);
217     if (!ok) return; // nyiFUNRAISE
218 #ifdef OCCT_DEBUG
219     if (tFOR) cout<<" shareG="<<shareG<<endl;
220 #endif
221
222     if (SO) {
223       // FOR and FCX share geometric domain.
224       if      (opeFus) b = shareG;
225       else if (opeCut) b = (!shareG) && M_OUT(TBEG);
226       else if (opeCom) b = shareG;
227     }
228     if (!b) return;    
229
230     if      (!EGBoundFOR) {      
231       TopAbs_Orientation oegFCXF1; FUN_tool_orientEinFFORWARD(EG,FCX,oegFCXF1);
232       neworiE = oegFCXF;
233     }
234     else if (EGBoundFOR) {
235       FUN_tool_orientEinFFORWARD(EG,TopoDS::Face(FOR),oegFOR);
236       neworiE = oegFOR;
237     }
238
239 //    Standard_Real f,l; FUN_tool_bounds(EG,f,l); Standard_Real parON = (f+l)*.4352;
240     Standard_Real f,l; FUN_tool_bounds(TopoDS::Edge(EspON),f,l); Standard_Real parON = (f+l)*.4352; // xpu120698
241     Standard_Boolean ESO; ok = FUN_tool_curvesSO(TopoDS::Edge(EspON),parON,EG,ESO);
242     if (!ok) return; // xpu120698
243     if (!ESO) neworiE = TopAbs::Complement(neworiE);
244
245     TopAbs_Orientation oFOR = BDS.Shape(iFOR).Orientation();
246     TopAbs_Orientation oFCX = BDS.Shape(iFCX).Orientation();
247     if (oFOR != oFCX) neworiE = TopAbs::Complement(neworiE);    
248
249     TopoDS_Shape newE = EspON;
250     newE.Orientation(neworiE);  
251     myPWES->AddStartElement(newE);
252 #ifdef OCCT_DEBUG
253     if (tFOR) cout<<"  add spON e"<<GI<<endl;
254 #endif
255     return;
256   } // yap6
257
258 } // GFillONPartsWES2