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 throw Standard_ProgramError("GIndex : bad input");
219 //=======================================================================
222 //=======================================================================
224 TopAbs_State TopOpeBRepBuild_GTopo::GState(const Standard_Integer i) const
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");
232 //=======================================================================
235 //=======================================================================
237 void TopOpeBRepBuild_GTopo::Index(const Standard_Integer II,
238 Standard_Integer& i1,
239 Standard_Integer& i2) const
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;
254 //=======================================================================
257 //=======================================================================
259 void TopOpeBRepBuild_GTopo::DumpVal(Standard_OStream& OS,
260 const TopAbs_State s1,
261 const TopAbs_State s2) const
266 //=======================================================================
267 //function : DumpType
269 //=======================================================================
271 void TopOpeBRepBuild_GTopo::DumpType(Standard_OStream& OS) const
273 TopAbs::Print(myt1,OS); OS<<"/"; TopAbs::Print(myt2,OS);
276 //=======================================================================
279 //=======================================================================
281 void TopOpeBRepBuild_GTopo::DumpSSB(Standard_OStream& OS,
282 const TopAbs_State s1,
283 const TopAbs_State s2,
284 const Standard_Boolean b)
286 TopAbs::Print(s1,OS); OS<<" "; TopAbs::Print(s2,OS); OS<<" : "<<b;
289 //=======================================================================
292 //=======================================================================
294 void TopOpeBRepBuild_GTopo::Dump(Standard_OStream& OS,
295 const Standard_Address a) const
300 OS<<" "; TopOpeBRepDS::Print(myConfig1,OS);
301 OS<<" "; TopOpeBRepDS::Print(myConfig2,OS);
304 if (myReverseForce) OS<<"reverse value : "<<myReverseValue<<endl;
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;
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;
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;
329 //=======================================================================
332 //=======================================================================
334 void TopOpeBRepBuild_GTopo::StatesON(TopAbs_State& s1,
335 TopAbs_State& s2) const
338 if ( Value(TopAbs_ON,TopAbs_IN) ) s1 = TopAbs_IN;
339 else if ( Value(TopAbs_ON,TopAbs_OUT)) s1 = TopAbs_OUT;
342 if ( Value(TopAbs_IN,TopAbs_ON) ) s2 = TopAbs_IN;
343 else if ( Value(TopAbs_OUT,TopAbs_ON)) s2 = TopAbs_OUT;
345 if ( s1 == TopAbs_UNKNOWN || s2 == TopAbs_UNKNOWN ) {
346 throw Standard_ProgramError("Gtopo : StatesON incorrect");
350 //=======================================================================
351 //function : IsToReverse1
353 //=======================================================================
355 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse1() const
357 if (myReverseForce) {
358 return myReverseValue;
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);
367 // throw Standard_ProgramError("GTopo::IsToReverse1");
368 // return Standard_False; // dummy
372 //=======================================================================
373 //function : IsToReverse2
375 //=======================================================================
377 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse2() const
379 if (myReverseForce) {
380 return myReverseValue;
385 Standard_Boolean IsToRev;
386 if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
387 else IsToRev = (s2 == TopAbs_IN);
392 //=======================================================================
393 //function : SetReverse
395 //=======================================================================
397 void TopOpeBRepBuild_GTopo::SetReverse(const Standard_Boolean rev)
399 myReverseForce = Standard_True;
400 myReverseValue = rev;
403 //=======================================================================
406 //=======================================================================
408 Standard_Boolean TopOpeBRepBuild_GTopo::Reverse() const
410 if (myReverseForce) return myReverseValue;
411 throw Standard_ProgramError("GTopo::ReverseValue undefined");
414 //=======================================================================
415 //function : CopyPermuted
417 //=======================================================================
419 TopOpeBRepBuild_GTopo TopOpeBRepBuild_GTopo::CopyPermuted() const
421 TopOpeBRepBuild_GTopo g;
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);