0026937: Eliminate NO_CXX_EXCEPTION macro support
[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_Boolean ii,const Standard_Boolean in,const Standard_Boolean io,
40  const Standard_Boolean ni,const Standard_Boolean nn,const Standard_Boolean no,
41  const Standard_Boolean oi,const Standard_Boolean on,const Standard_Boolean oo,
42  const TopAbs_ShapeEnum t1, const TopAbs_ShapeEnum t2,
43  const TopOpeBRepDS_Config C1, const TopOpeBRepDS_Config C2)
44 {
45   Reset();
46   Set (ii, in, io,
47        ni, nn, no,
48        oi, on, 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 throw Standard_ProgramError("GIndex : bad input");
217 }
218
219 //=======================================================================
220 //function : GState
221 //purpose  : 
222 //=======================================================================
223
224 TopAbs_State TopOpeBRepBuild_GTopo::GState(const Standard_Integer i) const
225 {
226   if      (i == 0) return TopAbs_IN;
227   else if (i == 1) return TopAbs_ON; 
228   else if (i == 2) return TopAbs_OUT;
229   else throw Standard_ProgramError("GState : bad input");
230 }
231
232 //=======================================================================
233 //function : Index
234 //purpose  : 
235 //=======================================================================
236
237 void TopOpeBRepBuild_GTopo::Index(const Standard_Integer II,
238                                   Standard_Integer& i1, 
239                                   Standard_Integer& i2) const 
240 {
241   switch (II) {
242   case 0 : i1 = 0; i2 = 0; break;
243   case 1 : i1 = 0; i2 = 1; break;
244   case 2 : i1 = 0; i2 = 2; break;
245   case 3 : i1 = 1; i2 = 0; break;
246   case 4 : i1 = 1; i2 = 1; break;
247   case 5 : i1 = 1; i2 = 2; break;
248   case 6 : i1 = 2; i2 = 0; break;
249   case 7 : i1 = 2; i2 = 1; break;
250   case 8 : i1 = 2; i2 = 2; break;
251   }
252 }
253
254 //=======================================================================
255 //function : DumpVal
256 //purpose  : 
257 //=======================================================================
258
259 void TopOpeBRepBuild_GTopo::DumpVal(Standard_OStream& OS,
260                                     const TopAbs_State s1,
261                                     const TopAbs_State s2) const 
262 {
263   OS<<Value(s1,s2);
264 }
265
266 //=======================================================================
267 //function : DumpType
268 //purpose  : 
269 //=======================================================================
270
271 void TopOpeBRepBuild_GTopo::DumpType(Standard_OStream& OS) const 
272 {
273   TopAbs::Print(myt1,OS); OS<<"/"; TopAbs::Print(myt2,OS);
274 }
275
276 //=======================================================================
277 //function : DumpSSB
278 //purpose  : 
279 //=======================================================================
280
281 void TopOpeBRepBuild_GTopo::DumpSSB(Standard_OStream& OS,
282                                     const TopAbs_State s1,
283                                     const TopAbs_State s2,
284                                     const Standard_Boolean b)
285 {
286   TopAbs::Print(s1,OS); OS<<" "; TopAbs::Print(s2,OS); OS<<" : "<<b;
287 }
288
289 //=======================================================================
290 //function : Dump
291 //purpose  : 
292 //=======================================================================
293
294 void TopOpeBRepBuild_GTopo::Dump(Standard_OStream& OS,
295                                  const Standard_Address a) const 
296 {
297   char* s = (char*)a;
298
299   DumpType(OS);
300   OS<<" "; TopOpeBRepDS::Print(myConfig1,OS);
301   OS<<" "; TopOpeBRepDS::Print(myConfig2,OS);
302   OS<<endl;
303
304   if (myReverseForce) OS<<"reverse value : "<<myReverseValue<<endl;
305
306   if(s) OS<<s; OS<<"\\ I N O"; 
307   OS<<endl;
308
309   if(s) OS<<s; OS<<"I ";
310   DumpVal(OS,TopAbs_IN,TopAbs_IN); OS<<" "; 
311   DumpVal(OS,TopAbs_IN,TopAbs_ON); OS<<" "; 
312   DumpVal(OS,TopAbs_IN,TopAbs_OUT); OS<<endl;
313
314   if(s) OS<<s; OS<<"N ";
315   DumpVal(OS,TopAbs_ON,TopAbs_IN); OS<<" "; 
316   DumpVal(OS,TopAbs_ON,TopAbs_ON); OS<<" "; 
317   DumpVal(OS,TopAbs_ON,TopAbs_OUT); OS<<endl;
318
319   if(s) OS<<s; OS<<"O ";
320   DumpVal(OS,TopAbs_OUT,TopAbs_IN); OS<<" "; 
321   DumpVal(OS,TopAbs_OUT,TopAbs_ON); OS<<" "; 
322   DumpVal(OS,TopAbs_OUT,TopAbs_OUT); OS<<endl;
323 }
324
325 //=======================================================================
326 //function : States
327 //purpose  : 
328 //=======================================================================
329
330 void TopOpeBRepBuild_GTopo::StatesON(TopAbs_State& s1,
331                                      TopAbs_State& s2) const  
332 {
333   s1 = TopAbs_UNKNOWN;
334   if      ( Value(TopAbs_ON,TopAbs_IN) ) s1 = TopAbs_IN;
335   else if ( Value(TopAbs_ON,TopAbs_OUT)) s1 = TopAbs_OUT;
336
337   s2 = TopAbs_UNKNOWN;
338   if      ( Value(TopAbs_IN,TopAbs_ON) ) s2 = TopAbs_IN;
339   else if ( Value(TopAbs_OUT,TopAbs_ON)) s2 = TopAbs_OUT;
340
341   if ( s1 == TopAbs_UNKNOWN || s2 == TopAbs_UNKNOWN ) {
342     throw Standard_ProgramError("Gtopo : StatesON incorrect");
343   }
344 }
345
346 //=======================================================================
347 //function : IsToReverse1
348 //purpose  : 
349 //=======================================================================
350
351 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse1() const 
352 {
353   if (myReverseForce) {
354     return myReverseValue;
355   }
356   else {
357     TopAbs_State s1,s2;StatesON(s1,s2);
358     Standard_Boolean IsToRev;
359     if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
360     else IsToRev = (s1 == TopAbs_IN);
361     return IsToRev;
362   }
363 //  throw Standard_ProgramError("GTopo::IsToReverse1");
364 //  return Standard_False; // dummy
365 }
366
367
368 //=======================================================================
369 //function : IsToReverse2
370 //purpose  : 
371 //=======================================================================
372
373 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse2() const 
374 {
375   if (myReverseForce) {
376     return myReverseValue;
377   }
378   else {
379     TopAbs_State s1,s2;
380     StatesON(s1,s2);
381     Standard_Boolean IsToRev;
382     if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
383     else IsToRev = (s2 == TopAbs_IN);
384     return IsToRev;
385   }
386 }
387
388 //=======================================================================
389 //function : SetReverse
390 //purpose  : 
391 //=======================================================================
392
393 void TopOpeBRepBuild_GTopo::SetReverse(const Standard_Boolean rev)
394 {
395   myReverseForce = Standard_True;
396   myReverseValue = rev;
397 }
398
399 //=======================================================================
400 //function : Reverse
401 //purpose  : 
402 //=======================================================================
403
404 Standard_Boolean TopOpeBRepBuild_GTopo::Reverse() const 
405 {
406   if (myReverseForce) return myReverseValue;
407   throw Standard_ProgramError("GTopo::ReverseValue undefined");
408 }
409
410 //=======================================================================
411 //function : CopyPermuted
412 //purpose  : 
413 //=======================================================================
414
415 TopOpeBRepBuild_GTopo TopOpeBRepBuild_GTopo::CopyPermuted() const 
416 {
417   TopOpeBRepBuild_GTopo g;
418
419   g.ChangeType(myt2,myt1);
420   g.ChangeConfig(myConfig2,myConfig1);
421   Standard_Integer i,j;
422   for (i=0; i<3; i++) for (j=0; j<3; j++) g.ChangeValue(j,i,Value(i,j));
423   if (myReverseForce) g.SetReverse(myReverseValue);
424
425   return g;
426 }