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