0027197: Configuration - fix compilation issues when using mingw
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_GTopo.cxx
1 // Created on: 1996-02-13
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-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 <Standard_ProgramError.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TopAbs.hxx>
21 #include <TopOpeBRepBuild_GTopo.hxx>
22 #include <TopOpeBRepDS.hxx>
23
24 //=======================================================================
25 //function : TopOpeBRepBuild_GTopo
26 //purpose  : 
27 //=======================================================================
28 TopOpeBRepBuild_GTopo::TopOpeBRepBuild_GTopo()
29 {
30   Reset();
31 }
32
33 //=======================================================================
34 //function : TopOpeBRepBuild_GTopo
35 //purpose  : 
36 //=======================================================================
37
38 TopOpeBRepBuild_GTopo::TopOpeBRepBuild_GTopo
39 (const Standard_Integer ii,const Standard_Integer in,const Standard_Integer io,
40  const Standard_Integer ni,const Standard_Integer nn,const Standard_Integer no,
41  const Standard_Integer oi,const Standard_Integer on,const Standard_Integer oo,
42  const TopAbs_ShapeEnum t1, const TopAbs_ShapeEnum t2,
43  const TopOpeBRepDS_Config C1, const TopOpeBRepDS_Config C2)
44 {
45   Reset();
46   Set((Standard_Boolean)ii,(Standard_Boolean)in,(Standard_Boolean)io,
47       (Standard_Boolean)ni,(Standard_Boolean)nn,(Standard_Boolean)no,  
48       (Standard_Boolean)oi,(Standard_Boolean)on,(Standard_Boolean)oo);
49   myt1 = t1; 
50   myt2 = t2;
51   myConfig1 = C1;
52   myConfig2 = C2;
53 }
54
55 //=======================================================================
56 //function : Reset
57 //purpose  : 
58 //=======================================================================
59
60 void TopOpeBRepBuild_GTopo::Reset()
61 {
62   myt1 = myt2 = TopAbs_SHAPE;
63   mycases[0][0] = mycases[0][1] = mycases[0][2] =   
64   mycases[1][0] = mycases[1][1] = mycases[1][2] = 
65   mycases[2][0] = mycases[2][1] = mycases[2][2] = Standard_False;
66   myConfig1 = myConfig2 = TopOpeBRepDS_UNSHGEOMETRY;
67   myReverseForce = myReverseValue = Standard_False;
68 }
69
70 //=======================================================================
71 //function : Set
72 //purpose  : 
73 //=======================================================================
74
75 void TopOpeBRepBuild_GTopo::Set
76 (const Standard_Boolean ii,const Standard_Boolean in,const Standard_Boolean io,
77  const Standard_Boolean ni,const Standard_Boolean nn,const Standard_Boolean no,
78  const Standard_Boolean oi,const Standard_Boolean on,const Standard_Boolean oo)
79 {
80   mycases[0][0] = ii; mycases[0][1] = in; mycases[0][2] = io;   
81   mycases[1][0] = ni; mycases[1][1] = nn; mycases[1][2] = no;
82   mycases[2][0] = oi; mycases[2][1] = on; mycases[2][2] = oo;
83 }
84
85 //=======================================================================
86 //function : Type
87 //purpose  : 
88 //=======================================================================
89
90 void TopOpeBRepBuild_GTopo::Type(TopAbs_ShapeEnum& t1, 
91                                  TopAbs_ShapeEnum& t2) const 
92 {
93   t1 = myt1;
94   t2 = myt2;
95 }
96
97 //=======================================================================
98 //function : ChangeType
99 //purpose  : 
100 //=======================================================================
101
102 void TopOpeBRepBuild_GTopo::ChangeType(const TopAbs_ShapeEnum t1, 
103                                        const TopAbs_ShapeEnum t2)
104 {
105   myt1 = t1;
106   myt2 = t2;
107 }
108
109 //=======================================================================
110 //function : Config1
111 //purpose  : 
112 //=======================================================================
113
114 TopOpeBRepDS_Config TopOpeBRepBuild_GTopo::Config1() const
115 {
116   return myConfig1;
117 }
118
119 //=======================================================================
120 //function : Config2
121 //purpose  : 
122 //=======================================================================
123
124 TopOpeBRepDS_Config TopOpeBRepBuild_GTopo::Config2() const
125 {
126   return myConfig2;
127 }
128
129 //=======================================================================
130 //function : ChangeConfig
131 //purpose  : 
132 //=======================================================================
133
134 void TopOpeBRepBuild_GTopo::ChangeConfig(const TopOpeBRepDS_Config C1,
135                                          const TopOpeBRepDS_Config C2)
136 {
137   myConfig1 = C1;
138   myConfig2 = C2;
139 }
140
141 //=======================================================================
142 //function : Value
143 //purpose  : 
144 //=======================================================================
145
146 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const Standard_Integer i1,
147                                               const Standard_Integer i2) const 
148 {
149   Standard_Boolean b = mycases[i1][i2];
150   return b;
151 }
152
153 //=======================================================================
154 //function : Value
155 //purpose  : 
156 //=======================================================================
157
158 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const TopAbs_State s1,
159                                               const TopAbs_State s2) const  
160 {
161   Standard_Integer i1 = GIndex(s1);
162   Standard_Integer i2 = GIndex(s2);
163   Standard_Boolean b = mycases[i1][i2];
164   return b;
165 }
166
167 //=======================================================================
168 //function : Value
169 //purpose  : 
170 //=======================================================================
171
172 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const Standard_Integer II) const
173 {
174   Standard_Integer i1=0,i2=0;
175   Index(II,i1,i2);
176   Standard_Boolean b = Value(i1,i2);
177   return b;
178 }
179
180 //=======================================================================
181 //function : ChangeValue
182 //purpose  : 
183 //=======================================================================
184
185 void TopOpeBRepBuild_GTopo::ChangeValue(const Standard_Integer i1,
186                                         const Standard_Integer i2,
187                                         const Standard_Boolean b)
188 {
189   mycases[i1][i2] = b;
190 }
191
192 //=======================================================================
193 //function : ChangeValue
194 //purpose  : 
195 //=======================================================================
196
197 void TopOpeBRepBuild_GTopo::ChangeValue(const TopAbs_State s1, 
198                                         const TopAbs_State s2,
199                                         const Standard_Boolean b)
200 {
201   Standard_Integer i1 = GIndex(s1);
202   Standard_Integer i2 = GIndex(s2);
203   mycases[i1][i2] = b;
204 }
205
206 //=======================================================================
207 //function : GIndex
208 //purpose  : 
209 //=======================================================================
210
211 Standard_Integer TopOpeBRepBuild_GTopo::GIndex(const TopAbs_State s) const
212 {
213   if      (s == TopAbs_IN ) return 0;
214   else if (s == TopAbs_ON ) return 1;
215   else if (s == TopAbs_OUT) return 2;
216   else Standard_ProgramError::Raise("GIndex : bad input");
217   return 0;
218 }
219
220 //=======================================================================
221 //function : GState
222 //purpose  : 
223 //=======================================================================
224
225 TopAbs_State TopOpeBRepBuild_GTopo::GState(const Standard_Integer i) const
226 {
227   if      (i == 0) return TopAbs_IN;
228   else if (i == 1) return TopAbs_ON; 
229   else if (i == 2) return TopAbs_OUT;
230   else Standard_ProgramError::Raise("GState : bad input");
231   return TopAbs_UNKNOWN;
232 }
233
234 //=======================================================================
235 //function : Index
236 //purpose  : 
237 //=======================================================================
238
239 void TopOpeBRepBuild_GTopo::Index(const Standard_Integer II,
240                                   Standard_Integer& i1, 
241                                   Standard_Integer& i2) const 
242 {
243   switch (II) {
244   case 0 : i1 = 0; i2 = 0; break;
245   case 1 : i1 = 0; i2 = 1; break;
246   case 2 : i1 = 0; i2 = 2; break;
247   case 3 : i1 = 1; i2 = 0; break;
248   case 4 : i1 = 1; i2 = 1; break;
249   case 5 : i1 = 1; i2 = 2; break;
250   case 6 : i1 = 2; i2 = 0; break;
251   case 7 : i1 = 2; i2 = 1; break;
252   case 8 : i1 = 2; i2 = 2; break;
253   }
254 }
255
256 //=======================================================================
257 //function : DumpVal
258 //purpose  : 
259 //=======================================================================
260
261 void TopOpeBRepBuild_GTopo::DumpVal(Standard_OStream& OS,
262                                     const TopAbs_State s1,
263                                     const TopAbs_State s2) const 
264 {
265   OS<<Value(s1,s2);
266 }
267
268 //=======================================================================
269 //function : DumpType
270 //purpose  : 
271 //=======================================================================
272
273 void TopOpeBRepBuild_GTopo::DumpType(Standard_OStream& OS) const 
274 {
275   TopAbs::Print(myt1,OS); OS<<"/"; TopAbs::Print(myt2,OS);
276 }
277
278 //=======================================================================
279 //function : DumpSSB
280 //purpose  : 
281 //=======================================================================
282
283 void TopOpeBRepBuild_GTopo::DumpSSB(Standard_OStream& OS,
284                                     const TopAbs_State s1,
285                                     const TopAbs_State s2,
286                                     const Standard_Boolean b)
287 {
288   TopAbs::Print(s1,OS); OS<<" "; TopAbs::Print(s2,OS); OS<<" : "<<b;
289 }
290
291 //=======================================================================
292 //function : Dump
293 //purpose  : 
294 //=======================================================================
295
296 void TopOpeBRepBuild_GTopo::Dump(Standard_OStream& OS,
297                                  const Standard_Address a) const 
298 {
299   char* s = (char*)a;
300
301   DumpType(OS);
302   OS<<" "; TopOpeBRepDS::Print(myConfig1,OS);
303   OS<<" "; TopOpeBRepDS::Print(myConfig2,OS);
304   OS<<endl;
305
306   if (myReverseForce) OS<<"reverse value : "<<myReverseValue<<endl;
307
308   if(s) OS<<s; OS<<"\\ I N O"; 
309   OS<<endl;
310
311   if(s) OS<<s; OS<<"I ";
312   DumpVal(OS,TopAbs_IN,TopAbs_IN); OS<<" "; 
313   DumpVal(OS,TopAbs_IN,TopAbs_ON); OS<<" "; 
314   DumpVal(OS,TopAbs_IN,TopAbs_OUT); OS<<endl;
315
316   if(s) OS<<s; OS<<"N ";
317   DumpVal(OS,TopAbs_ON,TopAbs_IN); OS<<" "; 
318   DumpVal(OS,TopAbs_ON,TopAbs_ON); OS<<" "; 
319   DumpVal(OS,TopAbs_ON,TopAbs_OUT); OS<<endl;
320
321   if(s) OS<<s; OS<<"O ";
322   DumpVal(OS,TopAbs_OUT,TopAbs_IN); OS<<" "; 
323   DumpVal(OS,TopAbs_OUT,TopAbs_ON); OS<<" "; 
324   DumpVal(OS,TopAbs_OUT,TopAbs_OUT); OS<<endl;
325 }
326
327 //=======================================================================
328 //function : States
329 //purpose  : 
330 //=======================================================================
331
332 void TopOpeBRepBuild_GTopo::StatesON(TopAbs_State& s1,
333                                      TopAbs_State& s2) const  
334 {
335   s1 = TopAbs_UNKNOWN;
336   if      ( Value(TopAbs_ON,TopAbs_IN) ) s1 = TopAbs_IN;
337   else if ( Value(TopAbs_ON,TopAbs_OUT)) s1 = TopAbs_OUT;
338
339   s2 = TopAbs_UNKNOWN;
340   if      ( Value(TopAbs_IN,TopAbs_ON) ) s2 = TopAbs_IN;
341   else if ( Value(TopAbs_OUT,TopAbs_ON)) s2 = TopAbs_OUT;
342
343   if ( s1 == TopAbs_UNKNOWN || s2 == TopAbs_UNKNOWN ) {
344     Standard_ProgramError::Raise("Gtopo : StatesON incorrect");
345   }
346 }
347
348 //=======================================================================
349 //function : IsToReverse1
350 //purpose  : 
351 //=======================================================================
352
353 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse1() const 
354 {
355   if (myReverseForce) {
356     return myReverseValue;
357   }
358   else {
359     TopAbs_State s1,s2;StatesON(s1,s2);
360     Standard_Boolean IsToRev;
361     if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
362     else IsToRev = (s1 == TopAbs_IN);
363     return IsToRev;
364   }
365 //  Standard_ProgramError::Raise("GTopo::IsToReverse1");
366 //  return Standard_False; // dummy
367 }
368
369
370 //=======================================================================
371 //function : IsToReverse2
372 //purpose  : 
373 //=======================================================================
374
375 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse2() const 
376 {
377   if (myReverseForce) {
378     return myReverseValue;
379   }
380   else {
381     TopAbs_State s1,s2;
382     StatesON(s1,s2);
383     Standard_Boolean IsToRev;
384     if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
385     else IsToRev = (s2 == TopAbs_IN);
386     return IsToRev;
387   }
388 }
389
390 //=======================================================================
391 //function : SetReverse
392 //purpose  : 
393 //=======================================================================
394
395 void TopOpeBRepBuild_GTopo::SetReverse(const Standard_Boolean rev)
396 {
397   myReverseForce = Standard_True;
398   myReverseValue = rev;
399 }
400
401 //=======================================================================
402 //function : Reverse
403 //purpose  : 
404 //=======================================================================
405
406 Standard_Boolean TopOpeBRepBuild_GTopo::Reverse() const 
407 {
408   if (myReverseForce) return myReverseValue;
409   Standard_ProgramError::Raise("GTopo::ReverseValue undefined");
410   return Standard_False; // dummy
411 }
412
413 //=======================================================================
414 //function : CopyPermuted
415 //purpose  : 
416 //=======================================================================
417
418 TopOpeBRepBuild_GTopo TopOpeBRepBuild_GTopo::CopyPermuted() const 
419 {
420   TopOpeBRepBuild_GTopo g;
421
422   g.ChangeType(myt2,myt1);
423   g.ChangeConfig(myConfig2,myConfig1);
424   Standard_Integer i,j;
425   for (i=0; i<3; i++) for (j=0; j<3; j++) g.ChangeValue(j,i,Value(i,j));
426   if (myReverseForce) g.SetReverse(myReverseValue);
427
428   return g;
429 }