0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_redu.cxx
1 // Created on: 1998-11-25
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 #include <TopOpeBRepTool_EXPORT.hxx>
18 #include <TopOpeBRepTool_makeTransition.hxx>
19
20 #include <TopOpeBRepDS_define.hxx>
21 #include <TopOpeBRepDS_EXPORT.hxx>
22 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
23
24 #include <TopoDS.hxx>
25 #include <Precision.hxx>
26 #include <BRep_Tool.hxx>
27
28 #define M_FORWARD(st)  (st == TopAbs_FORWARD)
29 #define M_UNKNOWN(st)  (st == TopAbs_UNKNOWN)
30 #define M_REVERSED(st) (st == TopAbs_REVERSED)
31 #define M_INTERNAL(st) (st == TopAbs_INTERNAL)
32 #define M_EXTERNAL(st) (st == TopAbs_EXTERNAL)
33
34 Standard_EXPORT void FUN_scanloi(const TopOpeBRepDS_ListOfInterference& lI, 
35                                  TopOpeBRepDS_ListOfInterference& lFOR, Standard_Integer& FOR,
36                                  TopOpeBRepDS_ListOfInterference& lREV, Standard_Integer& REV,
37                                  TopOpeBRepDS_ListOfInterference& lINT, Standard_Integer& INT,
38                                  TopOpeBRepDS_ListOfInterference& lEXT, Standard_Integer& EXT)
39 {
40   lFOR.Clear(); lREV.Clear(); lINT.Clear(); lEXT.Clear();
41   FDS_assign(lI,lEXT);
42   FOR=FUN_selectTRAORIinterference(lEXT,TopAbs_FORWARD,lFOR);
43   REV=FUN_selectTRAORIinterference(lEXT,TopAbs_REVERSED,lREV);
44   INT=FUN_selectTRAORIinterference(lEXT,TopAbs_INTERNAL,lINT);
45   EXT = lEXT.Extent();
46 }
47
48 Standard_EXPORT Standard_Boolean FUN_ds_redu2d1d(const TopOpeBRepDS_DataStructure& BDS, const Standard_Integer ISE,
49                                     const Handle(TopOpeBRepDS_Interference)& I2d, const TopOpeBRepDS_ListOfInterference& l1d, TopOpeBRepDS_Transition& newT2d)
50 // attached to edge(ISE) : l1d = {I1d=(Tr1d(Esd),vG,Esd)}, I2d=(Tr2d(F),vG,E)
51 //                         - vG is not vertex of SE -
52 // purpose : I2d -> (newT2d(F),vG,E), with Esd is edge of F
53 //           returns true if set newT2d, false elsewhere.
54 // NYIxpu251198 treating interferences IB1 !=IA1, IB2 != IA2
55 {  
56   TopAbs_ShapeEnum SB2,SA2; Standard_Integer IB2,IA2; TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2; FDS_Idata(I2d,SB2,IB2,SA2,IA2,GT2,G2,ST2,S2);
57   const TopOpeBRepDS_Transition T2d = I2d->Transition();
58   TopAbs_Orientation O2 = T2d.Orientation(TopAbs_IN); newT2d.Index(IB2); newT2d.Set(O2);
59   Standard_Boolean ok2 = (IB2 == IA2)&&(SB2 == TopAbs_FACE)&&(GT2 == TopOpeBRepDS_VERTEX);
60   if (!ok2) return Standard_False;
61
62   const TopoDS_Edge& SE = TopoDS::Edge(BDS.Shape(ISE));
63   const TopoDS_Face& F  = TopoDS::Face(BDS.Shape(IB2)); Standard_Real tolF = BRep_Tool::Tolerance(F)*1.e2;//nyitol
64   const TopoDS_Edge& E  = TopoDS::Edge(BDS.Shape(S2)); Standard_Real tolE = BRep_Tool::Tolerance(E)*1.e2;//nyitol
65   Standard_Boolean EclosingF = FUN_tool_IsClosingE(E,F,F);
66   if (EclosingF) { 
67     TopAbs_State stb = T2d.Before(), sta = T2d.After();
68     if (stb != sta) { // costs 1 projPonE
69       Standard_Real pbef=0,paft=0,factor=1.e-4;
70       Standard_Real parSE = FDS_Parameter(I2d);
71       Standard_Real parE; Standard_Boolean ok = FUN_tool_parE(SE,parSE,E,parE,tolE);
72       if (!ok) return Standard_False;
73       gp_Pnt2d uv; ok = FUN_tool_paronEF(E,parE,F,uv,tolF);
74       if (!ok) return Standard_False;
75       
76       TopOpeBRepTool_makeTransition MKT;
77       TopAbs_State stb1 = TopAbs_UNKNOWN,sta1 = TopAbs_UNKNOWN; 
78       ok = MKT.Initialize(SE,pbef,paft,parSE, F,uv, factor);
79       if (ok) ok = MKT.SetRest(E,parE);
80       if (ok) ok = MKT.MkTonE(stb1,sta1); 
81       if (ok) {
82         newT2d.Before(stb1);
83         newT2d.After(sta1);
84       }
85       return ok;
86     }
87     return Standard_False;
88   }
89
90   TopOpeBRepDS_ListIteratorOfListOfInterference it1(l1d); 
91   Standard_Boolean beforeIN1d=Standard_False, afterIN1d=Standard_False;
92   // ------------------------------
93   for (; it1.More(); it1.Next()){
94     const Handle(TopOpeBRepDS_Interference)& I1d = it1.Value();
95     TopAbs_ShapeEnum SB1,SA1; Standard_Integer IB1,IA1; TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; FDS_Idata(I1d,SB1,IB1,SA1,IA1,GT1,G1,ST1,S1);
96     if (IB1 != IA1) continue;
97     TopAbs_Orientation O1 = I1d->Transition().Orientation(TopAbs_IN);
98     
99     const TopoDS_Edge& Esd  = TopoDS::Edge(BDS.Shape(IB1));
100     Standard_Boolean isedgeF = FUN_tool_inS(Esd,F);
101     if (!isedgeF) continue;
102
103     Standard_Boolean bIN = M_INTERNAL(O1) || M_REVERSED(O1);
104     Standard_Boolean aIN = M_INTERNAL(O1) || M_FORWARD(O1);
105     if (bIN && aIN) return Standard_False; //NYIRAISE I1d INTERNAL -> NO I2d!!
106     if (bIN) beforeIN1d = Standard_True;
107     if (aIN) afterIN1d = Standard_True;
108   }//it1
109   
110   if (beforeIN1d) newT2d.Before(TopAbs_IN);
111   if (afterIN1d)  newT2d.After(TopAbs_IN);
112   return Standard_True;
113 } // redu2d1d
114
115
116 Standard_EXPORT Standard_Boolean FUN_ds_GetTr(
117 //                                 const TopOpeBRepDS_DataStructure& BDS,
118                                  const TopOpeBRepDS_DataStructure& ,
119                                  const Standard_Integer ISE,
120 //                               const Standard_Integer G,
121                                  const Standard_Integer ,
122                                  const TopOpeBRepDS_ListOfInterference& LIG,
123                                  TopAbs_State& stb, Standard_Integer& isb, Standard_Integer& bdim,
124                                  TopAbs_State& sta, Standard_Integer& isa, Standard_Integer& adim)
125 // LIG = {I=(Tr,G,S)} attached to edge<ISE>
126 // purpose : returns newT(stb(isb,seb),sta(isa,sea)), 
127 // we assume IN1d > I2d > I3d
128 //           OUT3d > OUT2d > OUT1d
129
130   TopOpeBRepDS_ListOfInterference LIGcopy; FDS_copy(LIG,LIGcopy); 
131   TopOpeBRepDS_ListOfInterference l3d; FDS_assign(LIG,LIGcopy);
132   FUN_selectSKinterference(LIGcopy,TopOpeBRepDS_FACE,l3d);
133   TopOpeBRepDS_ListOfInterference l2d; FDS_assign(LIG,LIGcopy);
134   FUN_ds_hasI2d(ISE,LIGcopy,l2d);
135   TopOpeBRepDS_ListOfInterference l1d; FDS_assign(LIG,LIGcopy);
136   FUN_selectTRASHAinterference(LIGcopy,TopAbs_EDGE,l1d);
137   
138   TopOpeBRepDS_ListOfInterference l1dFOR,l1dREV,l1dINT,l1dEXT; Standard_Integer FOR1d,REV1d,INT1d,EXT1d;
139   ::FUN_scanloi(l1d, l1dFOR,FOR1d, l1dREV,REV1d, l1dINT,INT1d, l1dEXT,EXT1d);
140   Standard_Boolean beforeIN1d = (REV1d + INT1d > 0); Standard_Boolean beforeOU1d = (FOR1d + EXT1d) != 0;
141   Standard_Boolean afterIN1d  = (FOR1d + INT1d > 0); Standard_Boolean afterOU1d  = (REV1d + EXT1d) != 0;
142   
143   TopOpeBRepDS_ListOfInterference l2dFOR,l2dREV,l2dINT,l2dEXT; Standard_Integer FOR2d,REV2d,INT2d,EXT2d;
144   ::FUN_scanloi(l2d, l2dFOR,FOR2d, l2dREV,REV2d, l2dINT,INT2d, l2dEXT,EXT2d);
145   Standard_Boolean beforeIN2d = (REV2d + INT2d > 0); Standard_Boolean beforeOU2d = (FOR2d + EXT2d) != 0;
146   Standard_Boolean afterIN2d  = (FOR2d + INT2d > 0); Standard_Boolean afterOU2d  = (REV2d + EXT2d) != 0;
147
148   TopOpeBRepDS_ListOfInterference l3dFOR,l3dREV,l3dINT,l3dEXT; Standard_Integer FOR3d,REV3d,INT3d,EXT3d;
149   ::FUN_scanloi(l3d, l3dFOR,FOR3d, l3dREV,REV3d, l3dINT,INT3d, l3dEXT,EXT3d);
150   Standard_Boolean beforeIN3d = (REV3d + INT3d > 0); Standard_Boolean beforeOU3d = (FOR3d + EXT3d) != 0;
151   Standard_Boolean afterIN3d  = (FOR3d + INT3d > 0); Standard_Boolean afterOU3d  = (REV3d + EXT3d) != 0;
152
153   // state before
154   stb = TopAbs_UNKNOWN; isb=0; bdim=0;
155   if      (beforeIN1d) {    
156     stb = TopAbs_IN; bdim = 1;
157     TopOpeBRepDS_ListOfInterference l1INb; FDS_copy(l1dREV,l1INb); FDS_copy(l1dINT,l1INb);
158     isb = l1INb.First()->Transition().IndexBefore();
159   }
160   else if (beforeIN2d) {  
161     stb = TopAbs_IN;  bdim = 2;
162     TopOpeBRepDS_ListOfInterference l2INb; FDS_copy(l2dREV,l2INb); FDS_copy(l2dINT,l2INb);
163     isb = l2INb.First()->Transition().IndexBefore();
164   }
165   else if (beforeIN3d) {  
166     stb = TopAbs_IN; bdim = 3;
167     TopOpeBRepDS_ListOfInterference l3INb; FDS_copy(l3dREV,l3INb); FDS_copy(l3dINT,l3INb);
168     isb = l3INb.First()->Transition().IndexBefore();   
169   }
170   else if (beforeOU3d) { 
171     stb = TopAbs_OUT; bdim = 3;
172     TopOpeBRepDS_ListOfInterference l3OUb; FDS_copy(l3dFOR,l3OUb); FDS_copy(l3dEXT,l3OUb);
173     isb = l3OUb.First()->Transition().IndexBefore();  
174   }
175   else if (beforeOU2d) {
176     stb = TopAbs_OUT; bdim = 2;
177     TopOpeBRepDS_ListOfInterference l2OUb; FDS_copy(l2dFOR,l2OUb); FDS_copy(l2dEXT,l2OUb);
178     isb = l2OUb.First()->Transition().IndexBefore();  
179   }
180   else if (beforeOU1d) {
181     stb = TopAbs_OUT; bdim = 1;
182     TopOpeBRepDS_ListOfInterference l1OUb; FDS_copy(l1dFOR,l1OUb); FDS_copy(l1dEXT,l1OUb);
183     isb = l1OUb.First()->Transition().IndexBefore();  
184   }
185
186   // state after
187   sta = TopAbs_UNKNOWN; isa=0; adim=0;
188   if      (afterIN1d) { 
189     sta = TopAbs_IN; adim = 1;
190     TopOpeBRepDS_ListOfInterference l1INb; FDS_copy(l1dFOR,l1INb); FDS_copy(l1dINT,l1INb);
191     isa = l1INb.First()->Transition().IndexAfter();
192   }
193   else if (afterIN2d) { 
194     sta = TopAbs_IN; adim = 2;
195     TopOpeBRepDS_ListOfInterference l2INb; FDS_copy(l2dFOR,l2INb); FDS_copy(l2dINT,l2INb);
196     isa = l2INb.First()->Transition().IndexAfter();
197   }
198   else if (afterIN3d) { 
199     sta = TopAbs_IN; adim = 3;
200     TopOpeBRepDS_ListOfInterference l3INb; FDS_copy(l3dFOR,l3INb); FDS_copy(l3dINT,l3INb);
201     isa = l3INb.First()->Transition().IndexAfter();   
202   }
203   else if (afterOU3d) {
204     sta = TopAbs_OUT; adim = 3;
205     TopOpeBRepDS_ListOfInterference l3OUb; FDS_copy(l3dREV,l3OUb); FDS_copy(l3dEXT,l3OUb);
206     isa = l3OUb.First()->Transition().IndexAfter();  
207   }
208   else if (afterOU2d) {
209     sta = TopAbs_OUT; adim = 2; 
210     TopOpeBRepDS_ListOfInterference l2OUb; FDS_copy(l2dREV,l2OUb); FDS_copy(l2dEXT,l2OUb); 
211     isa = l2OUb.First()->Transition().IndexAfter();  
212   }
213   else if (afterOU1d) {
214     sta = TopAbs_OUT; adim = 1; 
215     TopOpeBRepDS_ListOfInterference l1OUb; FDS_copy(l1dREV,l1OUb); FDS_copy(l1dEXT,l1OUb); 
216     isa = l1OUb.First()->Transition().IndexAfter();  
217   }
218   return Standard_True;
219 }