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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Standard_ProgramError.hxx>
19 #include <TCollection_AsciiString.hxx>
21 #include <TopOpeBRepBuild_GTopo.hxx>
22 #include <TopOpeBRepDS.hxx>
24 //=======================================================================
25 //function : TopOpeBRepBuild_GTopo
27 //=======================================================================
28 TopOpeBRepBuild_GTopo::TopOpeBRepBuild_GTopo()
33 //=======================================================================
34 //function : TopOpeBRepBuild_GTopo
36 //=======================================================================
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)
55 //=======================================================================
58 //=======================================================================
60 void TopOpeBRepBuild_GTopo::Reset()
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;
70 //=======================================================================
73 //=======================================================================
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)
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;
85 //=======================================================================
88 //=======================================================================
90 void TopOpeBRepBuild_GTopo::Type(TopAbs_ShapeEnum& t1,
91 TopAbs_ShapeEnum& t2) const
97 //=======================================================================
98 //function : ChangeType
100 //=======================================================================
102 void TopOpeBRepBuild_GTopo::ChangeType(const TopAbs_ShapeEnum t1,
103 const TopAbs_ShapeEnum t2)
109 //=======================================================================
112 //=======================================================================
114 TopOpeBRepDS_Config TopOpeBRepBuild_GTopo::Config1() const
119 //=======================================================================
122 //=======================================================================
124 TopOpeBRepDS_Config TopOpeBRepBuild_GTopo::Config2() const
129 //=======================================================================
130 //function : ChangeConfig
132 //=======================================================================
134 void TopOpeBRepBuild_GTopo::ChangeConfig(const TopOpeBRepDS_Config C1,
135 const TopOpeBRepDS_Config C2)
141 //=======================================================================
144 //=======================================================================
146 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const Standard_Integer i1,
147 const Standard_Integer i2) const
149 Standard_Boolean b = mycases[i1][i2];
153 //=======================================================================
156 //=======================================================================
158 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const TopAbs_State s1,
159 const TopAbs_State s2) const
161 Standard_Integer i1 = GIndex(s1);
162 Standard_Integer i2 = GIndex(s2);
163 Standard_Boolean b = mycases[i1][i2];
167 //=======================================================================
170 //=======================================================================
172 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const Standard_Integer II) const
174 Standard_Integer i1=0,i2=0;
176 Standard_Boolean b = Value(i1,i2);
180 //=======================================================================
181 //function : ChangeValue
183 //=======================================================================
185 void TopOpeBRepBuild_GTopo::ChangeValue(const Standard_Integer i1,
186 const Standard_Integer i2,
187 const Standard_Boolean b)
192 //=======================================================================
193 //function : ChangeValue
195 //=======================================================================
197 void TopOpeBRepBuild_GTopo::ChangeValue(const TopAbs_State s1,
198 const TopAbs_State s2,
199 const Standard_Boolean b)
201 Standard_Integer i1 = GIndex(s1);
202 Standard_Integer i2 = GIndex(s2);
206 //=======================================================================
209 //=======================================================================
211 Standard_Integer TopOpeBRepBuild_GTopo::GIndex(const TopAbs_State s) const
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");
220 //=======================================================================
223 //=======================================================================
225 TopAbs_State TopOpeBRepBuild_GTopo::GState(const Standard_Integer i) const
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;
234 //=======================================================================
237 //=======================================================================
239 void TopOpeBRepBuild_GTopo::Index(const Standard_Integer II,
240 Standard_Integer& i1,
241 Standard_Integer& i2) const
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;
256 //=======================================================================
259 //=======================================================================
261 void TopOpeBRepBuild_GTopo::DumpVal(Standard_OStream& OS,
262 const TopAbs_State s1,
263 const TopAbs_State s2) const
268 //=======================================================================
269 //function : DumpType
271 //=======================================================================
273 void TopOpeBRepBuild_GTopo::DumpType(Standard_OStream& OS) const
275 TopAbs::Print(myt1,OS); OS<<"/"; TopAbs::Print(myt2,OS);
278 //=======================================================================
281 //=======================================================================
283 void TopOpeBRepBuild_GTopo::DumpSSB(Standard_OStream& OS,
284 const TopAbs_State s1,
285 const TopAbs_State s2,
286 const Standard_Boolean b)
288 TopAbs::Print(s1,OS); OS<<" "; TopAbs::Print(s2,OS); OS<<" : "<<b;
291 //=======================================================================
294 //=======================================================================
296 void TopOpeBRepBuild_GTopo::Dump(Standard_OStream& OS,
297 const Standard_Address a) const
302 OS<<" "; TopOpeBRepDS::Print(myConfig1,OS);
303 OS<<" "; TopOpeBRepDS::Print(myConfig2,OS);
306 if (myReverseForce) OS<<"reverse value : "<<myReverseValue<<endl;
308 if(s) OS<<s; OS<<"\\ I N O";
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;
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;
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;
327 //=======================================================================
330 //=======================================================================
332 void TopOpeBRepBuild_GTopo::StatesON(TopAbs_State& s1,
333 TopAbs_State& s2) const
336 if ( Value(TopAbs_ON,TopAbs_IN) ) s1 = TopAbs_IN;
337 else if ( Value(TopAbs_ON,TopAbs_OUT)) s1 = TopAbs_OUT;
340 if ( Value(TopAbs_IN,TopAbs_ON) ) s2 = TopAbs_IN;
341 else if ( Value(TopAbs_OUT,TopAbs_ON)) s2 = TopAbs_OUT;
343 if ( s1 == TopAbs_UNKNOWN || s2 == TopAbs_UNKNOWN ) {
344 Standard_ProgramError::Raise("Gtopo : StatesON incorrect");
348 //=======================================================================
349 //function : IsToReverse1
351 //=======================================================================
353 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse1() const
355 if (myReverseForce) {
356 return myReverseValue;
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);
365 // Standard_ProgramError::Raise("GTopo::IsToReverse1");
366 // return Standard_False; // dummy
370 //=======================================================================
371 //function : IsToReverse2
373 //=======================================================================
375 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse2() const
377 if (myReverseForce) {
378 return myReverseValue;
383 Standard_Boolean IsToRev;
384 if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
385 else IsToRev = (s2 == TopAbs_IN);
390 //=======================================================================
391 //function : SetReverse
393 //=======================================================================
395 void TopOpeBRepBuild_GTopo::SetReverse(const Standard_Boolean rev)
397 myReverseForce = Standard_True;
398 myReverseValue = rev;
401 //=======================================================================
404 //=======================================================================
406 Standard_Boolean TopOpeBRepBuild_GTopo::Reverse() const
408 if (myReverseForce) return myReverseValue;
409 Standard_ProgramError::Raise("GTopo::ReverseValue undefined");
410 return Standard_False; // dummy
413 //=======================================================================
414 //function : CopyPermuted
416 //=======================================================================
418 TopOpeBRepBuild_GTopo TopOpeBRepBuild_GTopo::CopyPermuted() const
420 TopOpeBRepBuild_GTopo g;
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);