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>
20 #include <TopOpeBRepBuild_GTopo.hxx>
21 #include <TopOpeBRepDS.hxx>
23 //=======================================================================
24 //function : TopOpeBRepBuild_GTopo
26 //=======================================================================
27 TopOpeBRepBuild_GTopo::TopOpeBRepBuild_GTopo()
32 //=======================================================================
33 //function : TopOpeBRepBuild_GTopo
35 //=======================================================================
37 TopOpeBRepBuild_GTopo::TopOpeBRepBuild_GTopo
38 (const Standard_Boolean ii,const Standard_Boolean in,const Standard_Boolean io,
39 const Standard_Boolean ni,const Standard_Boolean nn,const Standard_Boolean no,
40 const Standard_Boolean oi,const Standard_Boolean on,const Standard_Boolean oo,
41 const TopAbs_ShapeEnum t1, const TopAbs_ShapeEnum t2,
42 const TopOpeBRepDS_Config C1, const TopOpeBRepDS_Config C2)
54 //=======================================================================
57 //=======================================================================
59 void TopOpeBRepBuild_GTopo::Reset()
61 myt1 = myt2 = TopAbs_SHAPE;
62 mycases[0][0] = mycases[0][1] = mycases[0][2] =
63 mycases[1][0] = mycases[1][1] = mycases[1][2] =
64 mycases[2][0] = mycases[2][1] = mycases[2][2] = Standard_False;
65 myConfig1 = myConfig2 = TopOpeBRepDS_UNSHGEOMETRY;
66 myReverseForce = myReverseValue = Standard_False;
69 //=======================================================================
72 //=======================================================================
74 void TopOpeBRepBuild_GTopo::Set
75 (const Standard_Boolean ii,const Standard_Boolean in,const Standard_Boolean io,
76 const Standard_Boolean ni,const Standard_Boolean nn,const Standard_Boolean no,
77 const Standard_Boolean oi,const Standard_Boolean on,const Standard_Boolean oo)
79 mycases[0][0] = ii; mycases[0][1] = in; mycases[0][2] = io;
80 mycases[1][0] = ni; mycases[1][1] = nn; mycases[1][2] = no;
81 mycases[2][0] = oi; mycases[2][1] = on; mycases[2][2] = oo;
84 //=======================================================================
87 //=======================================================================
89 void TopOpeBRepBuild_GTopo::Type(TopAbs_ShapeEnum& t1,
90 TopAbs_ShapeEnum& t2) const
96 //=======================================================================
97 //function : ChangeType
99 //=======================================================================
101 void TopOpeBRepBuild_GTopo::ChangeType(const TopAbs_ShapeEnum t1,
102 const TopAbs_ShapeEnum t2)
108 //=======================================================================
111 //=======================================================================
113 TopOpeBRepDS_Config TopOpeBRepBuild_GTopo::Config1() const
118 //=======================================================================
121 //=======================================================================
123 TopOpeBRepDS_Config TopOpeBRepBuild_GTopo::Config2() const
128 //=======================================================================
129 //function : ChangeConfig
131 //=======================================================================
133 void TopOpeBRepBuild_GTopo::ChangeConfig(const TopOpeBRepDS_Config C1,
134 const TopOpeBRepDS_Config C2)
140 //=======================================================================
143 //=======================================================================
145 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const Standard_Integer i1,
146 const Standard_Integer i2) const
148 Standard_Boolean b = mycases[i1][i2];
152 //=======================================================================
155 //=======================================================================
157 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const TopAbs_State s1,
158 const TopAbs_State s2) const
160 Standard_Integer i1 = GIndex(s1);
161 Standard_Integer i2 = GIndex(s2);
162 Standard_Boolean b = mycases[i1][i2];
166 //=======================================================================
169 //=======================================================================
171 Standard_Boolean TopOpeBRepBuild_GTopo::Value(const Standard_Integer II) const
173 Standard_Integer i1=0,i2=0;
175 Standard_Boolean b = Value(i1,i2);
179 //=======================================================================
180 //function : ChangeValue
182 //=======================================================================
184 void TopOpeBRepBuild_GTopo::ChangeValue(const Standard_Integer i1,
185 const Standard_Integer i2,
186 const Standard_Boolean b)
191 //=======================================================================
192 //function : ChangeValue
194 //=======================================================================
196 void TopOpeBRepBuild_GTopo::ChangeValue(const TopAbs_State s1,
197 const TopAbs_State s2,
198 const Standard_Boolean b)
200 Standard_Integer i1 = GIndex(s1);
201 Standard_Integer i2 = GIndex(s2);
205 //=======================================================================
208 //=======================================================================
210 Standard_Integer TopOpeBRepBuild_GTopo::GIndex(const TopAbs_State s) const
212 if (s == TopAbs_IN ) return 0;
213 else if (s == TopAbs_ON ) return 1;
214 else if (s == TopAbs_OUT) return 2;
215 else throw Standard_ProgramError("GIndex : bad input");
218 //=======================================================================
221 //=======================================================================
223 TopAbs_State TopOpeBRepBuild_GTopo::GState(const Standard_Integer i) const
225 if (i == 0) return TopAbs_IN;
226 else if (i == 1) return TopAbs_ON;
227 else if (i == 2) return TopAbs_OUT;
228 else throw Standard_ProgramError("GState : bad input");
231 //=======================================================================
234 //=======================================================================
236 void TopOpeBRepBuild_GTopo::Index(const Standard_Integer II,
237 Standard_Integer& i1,
238 Standard_Integer& i2) const
241 case 0 : i1 = 0; i2 = 0; break;
242 case 1 : i1 = 0; i2 = 1; break;
243 case 2 : i1 = 0; i2 = 2; break;
244 case 3 : i1 = 1; i2 = 0; break;
245 case 4 : i1 = 1; i2 = 1; break;
246 case 5 : i1 = 1; i2 = 2; break;
247 case 6 : i1 = 2; i2 = 0; break;
248 case 7 : i1 = 2; i2 = 1; break;
249 case 8 : i1 = 2; i2 = 2; break;
253 //=======================================================================
256 //=======================================================================
258 void TopOpeBRepBuild_GTopo::DumpVal(Standard_OStream& OS,
259 const TopAbs_State s1,
260 const TopAbs_State s2) const
265 //=======================================================================
266 //function : DumpType
268 //=======================================================================
270 void TopOpeBRepBuild_GTopo::DumpType(Standard_OStream& OS) const
272 TopAbs::Print(myt1,OS); OS<<"/"; TopAbs::Print(myt2,OS);
275 //=======================================================================
278 //=======================================================================
280 void TopOpeBRepBuild_GTopo::DumpSSB(Standard_OStream& OS,
281 const TopAbs_State s1,
282 const TopAbs_State s2,
283 const Standard_Boolean b)
285 TopAbs::Print(s1,OS); OS<<" "; TopAbs::Print(s2,OS); OS<<" : "<<b;
288 //=======================================================================
291 //=======================================================================
293 void TopOpeBRepBuild_GTopo::Dump(Standard_OStream& OS,
294 const Standard_Address a) const
299 OS<<" "; TopOpeBRepDS::Print(myConfig1,OS);
300 OS<<" "; TopOpeBRepDS::Print(myConfig2,OS);
303 if (myReverseForce) OS<<"reverse value : "<<myReverseValue<<std::endl;
311 DumpVal(OS,TopAbs_IN,TopAbs_IN); OS<<" ";
312 DumpVal(OS,TopAbs_IN,TopAbs_ON); OS<<" ";
313 DumpVal(OS,TopAbs_IN,TopAbs_OUT); OS<<std::endl;
317 DumpVal(OS,TopAbs_ON,TopAbs_IN); OS<<" ";
318 DumpVal(OS,TopAbs_ON,TopAbs_ON); OS<<" ";
319 DumpVal(OS,TopAbs_ON,TopAbs_OUT); OS<<std::endl;
323 DumpVal(OS,TopAbs_OUT,TopAbs_IN); OS<<" ";
324 DumpVal(OS,TopAbs_OUT,TopAbs_ON); OS<<" ";
325 DumpVal(OS,TopAbs_OUT,TopAbs_OUT); OS<<std::endl;
328 //=======================================================================
331 //=======================================================================
333 void TopOpeBRepBuild_GTopo::StatesON(TopAbs_State& s1,
334 TopAbs_State& s2) const
337 if ( Value(TopAbs_ON,TopAbs_IN) ) s1 = TopAbs_IN;
338 else if ( Value(TopAbs_ON,TopAbs_OUT)) s1 = TopAbs_OUT;
341 if ( Value(TopAbs_IN,TopAbs_ON) ) s2 = TopAbs_IN;
342 else if ( Value(TopAbs_OUT,TopAbs_ON)) s2 = TopAbs_OUT;
344 if ( s1 == TopAbs_UNKNOWN || s2 == TopAbs_UNKNOWN ) {
345 throw Standard_ProgramError("Gtopo : StatesON incorrect");
349 //=======================================================================
350 //function : IsToReverse1
352 //=======================================================================
354 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse1() const
356 if (myReverseForce) {
357 return myReverseValue;
360 TopAbs_State s1,s2;StatesON(s1,s2);
361 Standard_Boolean IsToRev;
362 if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
363 else IsToRev = (s1 == TopAbs_IN);
366 // throw Standard_ProgramError("GTopo::IsToReverse1");
367 // return Standard_False; // dummy
371 //=======================================================================
372 //function : IsToReverse2
374 //=======================================================================
376 Standard_Boolean TopOpeBRepBuild_GTopo::IsToReverse2() const
378 if (myReverseForce) {
379 return myReverseValue;
384 Standard_Boolean IsToRev;
385 if (s1 == TopAbs_IN && s2 == TopAbs_IN) IsToRev = Standard_False;
386 else IsToRev = (s2 == TopAbs_IN);
391 //=======================================================================
392 //function : SetReverse
394 //=======================================================================
396 void TopOpeBRepBuild_GTopo::SetReverse(const Standard_Boolean rev)
398 myReverseForce = Standard_True;
399 myReverseValue = rev;
402 //=======================================================================
405 //=======================================================================
407 Standard_Boolean TopOpeBRepBuild_GTopo::Reverse() const
409 if (myReverseForce) return myReverseValue;
410 throw Standard_ProgramError("GTopo::ReverseValue undefined");
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);