0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[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;
307   OS<<"\\ I N O";
308   OS<<endl;
309
310   if(s) OS<<s;
311   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;
317   OS<<"N ";
318   DumpVal(OS,TopAbs_ON,TopAbs_IN); OS<<" ";
319   DumpVal(OS,TopAbs_ON,TopAbs_ON); OS<<" ";
320   DumpVal(OS,TopAbs_ON,TopAbs_OUT); OS<<endl;
321
322   if(s) OS<<s;
323   OS<<"O ";
324   DumpVal(OS,TopAbs_OUT,TopAbs_IN); OS<<" ";
325   DumpVal(OS,TopAbs_OUT,TopAbs_ON); OS<<" ";
326   DumpVal(OS,TopAbs_OUT,TopAbs_OUT); OS<<endl;
327 }
328
329 //=======================================================================
330 //function : States
331 //purpose  : 
332 //=======================================================================
333
334 void TopOpeBRepBuild_GTopo::StatesON(TopAbs_State& s1,
335                                      TopAbs_State& s2) const  
336 {
337   s1 = TopAbs_UNKNOWN;
338   if      ( Value(TopAbs_ON,TopAbs_IN) ) s1 = TopAbs_IN;
339   else if ( Value(TopAbs_ON,TopAbs_OUT)) s1 = TopAbs_OUT;
340
341   s2 = TopAbs_UNKNOWN;
342   if      ( Value(TopAbs_IN,TopAbs_ON) ) s2 = TopAbs_IN;
343   else if ( Value(TopAbs_OUT,TopAbs_ON)) s2 = TopAbs_OUT;
344
345   if ( s1 == TopAbs_UNKNOWN || s2 == TopAbs_UNKNOWN ) {
346     throw Standard_ProgramError("Gtopo : StatesON incorrect");
347   }
348 }
349
350 //=======================================================================
351 //function : IsToReverse1
352 //purpose  : 
353 //=======================================================================
354
355 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse1() const 
356 {
357   if (myReverseForce) {
358     return myReverseValue;
359   }
360   else {
361     TopAbs_State s1,s2;StatesON(s1,s2);
362     Standard_Boolean IsToRev;
363     if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
364     else IsToRev = (s1 == TopAbs_IN);
365     return IsToRev;
366   }
367 //  throw Standard_ProgramError("GTopo::IsToReverse1");
368 //  return Standard_False; // dummy
369 }
370
371
372 //=======================================================================
373 //function : IsToReverse2
374 //purpose  : 
375 //=======================================================================
376
377 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse2() const 
378 {
379   if (myReverseForce) {
380     return myReverseValue;
381   }
382   else {
383     TopAbs_State s1,s2;
384     StatesON(s1,s2);
385     Standard_Boolean IsToRev;
386     if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
387     else IsToRev = (s2 == TopAbs_IN);
388     return IsToRev;
389   }
390 }
391
392 //=======================================================================
393 //function : SetReverse
394 //purpose  : 
395 //=======================================================================
396
397 void TopOpeBRepBuild_GTopo::SetReverse(const Standard_Boolean rev)
398 {
399   myReverseForce = Standard_True;
400   myReverseValue = rev;
401 }
402
403 //=======================================================================
404 //function : Reverse
405 //purpose  : 
406 //=======================================================================
407
408 Standard_Boolean TopOpeBRepBuild_GTopo::Reverse() const 
409 {
410   if (myReverseForce) return myReverseValue;
411   throw Standard_ProgramError("GTopo::ReverseValue undefined");
412 }
413
414 //=======================================================================
415 //function : CopyPermuted
416 //purpose  : 
417 //=======================================================================
418
419 TopOpeBRepBuild_GTopo TopOpeBRepBuild_GTopo::CopyPermuted() const 
420 {
421   TopOpeBRepBuild_GTopo g;
422
423   g.ChangeType(myt2,myt1);
424   g.ChangeConfig(myConfig2,myConfig1);
425   Standard_Integer i,j;
426   for (i=0; i<3; i++) for (j=0; j<3; j++) g.ChangeValue(j,i,Value(i,j));
427   if (myReverseForce) g.SetReverse(myReverseValue);
428
429   return g;
430 }