0024059: Eliminate compiler warning C4701 in MSVC++ with warning level 4
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_repvg.cxx
1 // Created on: 1998-02-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1998-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 <TopOpeBRepDS_repvg.hxx>
23 #include <TopoDS.hxx>
24 #include <BRep_Tool.hxx>
25 #include <TopExp.hxx>
26
27 #include <TopOpeBRepTool_EXPORT.hxx>
28 #include <TopOpeBRepTool_SC.hxx>
29 #include <TopOpeBRepTool_makeTransition.hxx>
30
31 #include <TopOpeBRepDS_EdgeInterferenceTool.hxx>
32 #include <TopOpeBRepDS_EdgeVertexInterference.hxx>
33 #include <TopOpeBRepDS_Interference.hxx>
34 #include <TopOpeBRepDS_TKI.hxx>
35 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
36 #include <TopOpeBRepDS_EXPORT.hxx>
37 #include <TopOpeBRepDS_define.hxx>
38 #include <Precision.hxx>
39
40 #include <TopOpeBRepDS_DataMapOfIntegerListOfInterference.hxx>
41 #include <TopOpeBRepDS_DataMapIteratorOfDataMapOfIntegerListOfInterference.hxx>
42 #define MDSdmoiloi TopOpeBRepDS_DataMapOfIntegerListOfInterference
43 #define MDSdmiodmoiloi TopOpeBRepDS_DataMapIteratorOfDataMapOfIntegerListOfInterference
44
45 #ifdef DEB
46 #include <TopOpeBRepDS_reDEB.hxx>
47 extern Standard_Boolean TopOpeBRepDS_GetcontextMKTONREG();
48 #endif
49   
50 //------------------------------------------------------
51 Standard_EXPORT void FDS_repvg2
52 (const TopOpeBRepDS_DataStructure& BDS,const Standard_Integer EIX,const TopOpeBRepDS_Kind GT,TopOpeBRepDS_ListOfInterference& LI,TopOpeBRepDS_ListOfInterference& RLI)
53 //------------------------------------------------------
54 {
55 #ifdef DEB
56   Standard_Boolean TRC=DSREDUEDGETRCE(EIX);
57   TRC = Standard_False; //xpu170898
58 #endif
59   const TopoDS_Edge& E = TopoDS::Edge(BDS.Shape(EIX));
60   Standard_Boolean isEd = BRep_Tool::Degenerated(E);
61   if (isEd) return;
62   
63 #ifdef DEB
64   if (TRC) cout<<endl<<"repvg1 E"<<EIX<<" <- "<<LI.Extent()<<endl;
65   if (TRC) debredpvg(EIX);
66 #endif
67
68   Standard_Boolean ispoint  = (GT == TopOpeBRepDS_POINT);
69   Standard_Boolean isvertex = (GT == TopOpeBRepDS_VERTEX);
70
71   Standard_Boolean nLI = LI.Extent();
72
73   TopOpeBRepDS_ListIteratorOfListOfInterference it1(LI);
74   while (it1.More()) {
75     const Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
76     TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; TopAbs_ShapeEnum tsb1,tsa1; Standard_Integer isb1,isa1; 
77     FDS_Idata(I1,tsb1,isb1,tsa1,isa1,GT1,G1,ST1,S1);
78     if (tsb1 != TopAbs_FACE) {it1.Next(); continue;}
79     if (tsa1 != TopAbs_FACE) {it1.Next(); continue;}
80     if (GT1 != GT) {it1.Next(); continue;}
81
82     // xpu121198 : raise in PRO16303, if G1 is a vertex same domain, make sure 
83     // rk(G1)= rk(E1)
84     Standard_Integer rkG1 = BDS.AncestorRank(G1);
85     Standard_Integer rkS1 = BDS.AncestorRank(S1);
86     if (isvertex && (rkG1 != rkS1)) {
87       TopoDS_Shape oovG; Standard_Boolean issd = FUN_ds_getoov(BDS.Shape(G1),BDS,oovG);
88       if (!issd) {it1.Next(); continue;} //!!NYIRAISE
89       G1 = BDS.Shape(oovG);
90     }
91
92     const TopoDS_Edge& E1 = TopoDS::Edge(BDS.Shape(S1));
93     const TopoDS_Face& F1 = TopoDS::Face(BDS.Shape(isb1));
94     TopOpeBRepDS_Point PDS; TopoDS_Shape VDS;
95     if      (ispoint)  PDS = BDS.Point(G1);
96     else if (isvertex) VDS = BDS.Shape(G1);
97     else Standard_Failure::Raise("TopOpeBRepDS FDS_repvg2 1");
98
99     Standard_Boolean isEd1 = BRep_Tool::Degenerated(E1); if (isEd1) {it1.Next(); continue;}
100     TopOpeBRepDS_ListIteratorOfListOfInterference it2(it1); if (it2.More()) it2.Next(); else {it1.Next(); continue; }
101
102     TopOpeBRepDS_EdgeInterferenceTool EITool;
103     Standard_Boolean memeS = Standard_False; TopOpeBRepDS_Transition TrmemeS; Standard_Boolean isComplex = Standard_False;
104
105     while ( it2.More() ) {
106       const Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
107       TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2; TopAbs_ShapeEnum tsb2,tsa2; Standard_Integer isb2,isa2; 
108       FDS_Idata(I2,tsb2,isb2,tsa2,isa2,GT2,G2,ST2,S2);
109       if (tsb2 != TopAbs_FACE) {it2.Next(); continue;}
110       if (tsa2 != TopAbs_FACE) {it2.Next(); continue;}
111
112       Standard_Boolean cond = (G1 == G2); if (!cond) { it2.Next(); continue; }
113   
114 #ifdef DEB
115       if (TRC && isvertex && DSREDUEDGETRCE(BDS.Shape(VDS))) debreducerEV(EIX,BDS.Shape(VDS));
116 #endif
117       
118       const TopoDS_Edge& E2 = TopoDS::Edge(BDS.Shape(S2));
119       Standard_Boolean isEd2 = BRep_Tool::Degenerated(E2);
120       if (isEd2) {it2.Next(); continue;}
121
122       memeS = (S1 == S2);
123       memeS = memeS && (nLI == 2);
124
125       if (!isComplex && memeS) {
126         Standard_Boolean mktone = Standard_False;
127 #ifdef DEB
128         // NYI XPU : corriger la sequence suivante (avec mkTonE) qui produit une
129         // NYI transition (ON,ON) dans le cas cto 009 B4 pour l'arete 6* / face *21
130         // NYI aux PDS 1 et 5, au lieu de (IN,IN).
131         mktone = TopOpeBRepDS_GetcontextMKTONREG();
132         if (mktone) {
133           const TopOpeBRepDS_ListOfInterference& LOI = BDS.ShapeInterferences(E);
134           Standard_Real pbef,paft; Standard_Boolean isonper; 
135           Standard_Real pE = FDS_Parameter(I1);
136           Standard_Boolean ok = FDS_LOIinfsup(BDS,E,pE,GT1,G1,LOI,pbef,paft,isonper); 
137           if (!ok) {it2.Next();continue;}
138           Standard_Real pE1;     ok = FUN_tool_parE(E,pE,E1,pE1);   if (!ok) {it2.Next();continue;}
139           gp_Pnt2d uv; ok = FUN_tool_paronEF(E,pE,F1,uv); if (!ok) {it2.Next();continue;}
140           Standard_Real factor = 0.789;
141           TopOpeBRepTool_makeTransition MKT; 
142           TopAbs_State stb = TopAbs_UNKNOWN,sta = TopAbs_UNKNOWN; 
143           ok = MKT.Initialize(E,pbef,paft,pE, F1,uv, factor);
144           if (ok) ok = MKT.SetRest(E1,pE1);
145           if (ok) ok = MKT.MkTonE(stb,sta);
146           if (!ok) {it2.Next();continue;}  
147           TrmemeS.Before(stb); TrmemeS.After(sta);
148         }
149 #endif
150         if (!mktone) {
151           Standard_Real pE = FDS_Parameter(I1);
152           Standard_Boolean ok = FDS_stateEwithF2d(BDS,E,pE,GT1,G1,F1,TrmemeS); if (!ok) {it2.Next();continue;}
153         }
154
155 #ifdef DEB
156         if(TRC){cout<<"memeS result ";TrmemeS.Dump(cout);cout<<endl;}
157 #endif
158         LI.Remove(it2);
159       } // !isComplex && memeS
160
161       if (!isComplex && !memeS) {
162         isComplex = Standard_True;
163         EITool.Init(E,I1);
164         if      (ispoint)  EITool.Add(E,PDS,I1);
165         else if (isvertex) EITool.Add(E1,VDS,I1);
166 #ifdef DEB
167         if (TRC){cout<<endl<<"complex T2d E"<<EIX<<endl;I1->Dump(cout);cout<<endl;}
168         if (TRC){cout<<"init ";Handle(TopOpeBRepDS_Interference) IBID = new TopOpeBRepDS_Interference();
169                  EITool.Transition(IBID);IBID->Transition().Dump(cout);cout<<endl;}
170 #endif
171       } // !isComplex && !memeS
172       
173       if (isComplex && !memeS) {
174 #ifdef DEB
175         if(TRC) I2->Dump(cout,"add ","\n");
176 #endif      
177         if      (ispoint)  EITool.Add(E,PDS,I2);      
178         else if (isvertex) EITool.Add(E2,VDS,I2); 
179         LI.Remove(it2);
180 #ifdef DEB
181         if(TRC){cout<<"result ";Handle(TopOpeBRepDS_Interference) IBID = new TopOpeBRepDS_Interference();
182                 EITool.Transition(IBID);IBID->Transition().Dump(cout);cout<<endl;}
183 #endif
184       } // (isComplex && !memeS)
185
186       if (isComplex && memeS) {
187         it2.Next();
188 #ifdef DEB
189 #endif      
190       } // (isComplex && memeS)
191
192     } // it2
193     
194     if      (!isComplex && memeS) {
195       const TopOpeBRepDS_Transition& T1 = I1->Transition();
196       TrmemeS.Index(T1.Index()); I1->ChangeTransition() = TrmemeS;
197       RLI.Append(I1); LI.Remove(it1);
198     }
199     else if (isComplex && !memeS)  {
200       EITool.Transition(I1);
201       RLI.Append(I1); LI.Remove(it1);
202     }
203     else {
204       it1.Next();
205     }
206
207   } // it1
208   
209 #ifdef DEB
210   if (TRC) cout<<"repvg2 E"<<EIX<<" -> reste "<<LI.Extent()<<" + reduit "<<RLI.Extent()<<endl<<endl;
211 #endif
212 }  // FDS_repvg2
213
214 //------------------------------------------------------
215 Standard_EXPORT void FDS_repvg
216 (const TopOpeBRepDS_DataStructure& BDS,const Standard_Integer EIX,const TopOpeBRepDS_Kind GT,TopOpeBRepDS_ListOfInterference& LOI,TopOpeBRepDS_ListOfInterference& RLOI)
217 //------------------------------------------------------
218 {
219   TopOpeBRepDS_TKI tki; tki.FillOnGeometry(LOI);
220 #ifdef DEB
221   Standard_Boolean TRC=DSREDUEDGETRCE(EIX);
222   TRC = Standard_False; //xpu170898
223   if (TRC) cout<<endl<<"repvg E"<<EIX<<" <- "<<LOI.Extent()<<endl;
224   if (TRC) tki.DumpTKIIterator("","\n");
225   if (TRC) debredpvg(EIX);
226 #endif
227
228   // xpu211098 : cto904F6 (e10,FTRA1=f14,FTRA2=f17)
229   MDSdmoiloi mapITRASHA;
230   TopOpeBRepDS_ListIteratorOfListOfInterference it(LOI);
231   while (it.More()) {
232     const Handle(TopOpeBRepDS_Interference)& I = it.Value();
233     Standard_Integer isa = I->Transition().Index();
234     Standard_Boolean bound = mapITRASHA.IsBound(isa);
235     if (!bound) {
236       TopOpeBRepDS_ListOfInterference loi; loi.Append(I);
237       mapITRASHA.Bind(isa,loi);
238     }
239     else mapITRASHA.ChangeFind(isa).Append(I);
240     it.Next();
241   }
242   
243   LOI.Clear();
244   MDSdmiodmoiloi itm(mapITRASHA);
245   for (; itm.More(); itm.Next()){
246     Standard_Integer isa = itm.Key();
247     TopOpeBRepDS_ListOfInterference& loi = mapITRASHA.ChangeFind(isa);
248     Standard_Integer nloi = loi.Extent();
249     if (nloi < 2) continue;
250     TopOpeBRepDS_ListOfInterference rloi; FDS_repvg2(BDS,EIX,GT,loi,rloi);
251     LOI.Append(loi); RLOI.Append(rloi);
252   }  
253
254   /*LOI.Clear();
255   for (tki.Init(); tki.More(); tki.Next()) {
256     TopOpeBRepDS_Kind K; Standard_Integer G; tki.Value(K,G);
257 #ifdef DEB
258     if (TRC) {tki.DumpTKI(K,G,"","\n");debredpvg(EIX);}
259 #endif
260     TopOpeBRepDS_ListOfInterference& loi = tki.ChangeValue(K,G); TopOpeBRepDS_ListOfInterference Rloi;
261     Standard_Integer nloi = loi.Extent();
262     if      (nloi == 0) continue;
263     else if (nloi == 1) LOI.Append(loi);
264     else {
265       FDS_repvg2(BDS,EIX,GT,loi,Rloi);  
266       LOI.Append(loi); RLOI.Append(Rloi);
267     }
268   }*/
269
270 #ifdef DEB
271   if (TRC) cout<<"repvg E"<<EIX<<" -> reste "<<LOI.Extent()<<" + reduit "<<RLOI.Extent()<<endl<<endl;
272 #endif
273 }
274