0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_Transition.cxx
CommitLineData
b311480e 1// Created on: 1994-05-26
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1994-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TopOpeBRepDS_Transition.ixx>
18
19#include <TopOpeBRepDS.hxx>
20#include <TopOpeBRepDS_define.hxx>
21
22//=======================================================================
23//function : TopOpeBRepDS_Transition
24//purpose :
25//=======================================================================
26TopOpeBRepDS_Transition::TopOpeBRepDS_Transition() :
27myStateBefore(TopAbs_UNKNOWN),myStateAfter(TopAbs_UNKNOWN),
28myShapeBefore(TopAbs_FACE),myShapeAfter(TopAbs_FACE),
29myIndexBefore(0),myIndexAfter(0)
30{
31}
32
33//=======================================================================
34//function : TopOpeBRepDS_Transition
35//purpose :
36//=======================================================================
37TopOpeBRepDS_Transition::TopOpeBRepDS_Transition(const TopAbs_State SB,const TopAbs_State SA,const TopAbs_ShapeEnum ONB,const TopAbs_ShapeEnum ONA) :
38myStateBefore(SB),myStateAfter(SA),
39myShapeBefore(ONB),myShapeAfter(ONA),
40myIndexBefore(0),myIndexAfter(0)
41{
42}
43
44//=======================================================================
45//function : TopOpeBRepDS_Transition
46//purpose :
47//=======================================================================
48TopOpeBRepDS_Transition::TopOpeBRepDS_Transition(const TopAbs_Orientation O) :
49myShapeBefore(TopAbs_FACE),myShapeAfter(TopAbs_FACE),
50myIndexBefore(0),myIndexAfter(0)
51{
52 Set(O);
53}
54
55//=======================================================================
56//function : Set
57//purpose :
58//=======================================================================
59void TopOpeBRepDS_Transition::Set(const TopAbs_State SB,const TopAbs_State SA,const TopAbs_ShapeEnum ONB,const TopAbs_ShapeEnum ONA)
60{
61 myStateBefore = SB;
62 myStateAfter = SA;
63 myShapeBefore = ONB;
64 myShapeAfter = ONA;
65}
66
67//=======================================================================
68//function : StateBefore
69//purpose :
70//=======================================================================
71void TopOpeBRepDS_Transition::StateBefore(const TopAbs_State S)
72{
73 myStateBefore = S;
74}
75
76//=======================================================================
77//function : StateAfter
78//purpose :
79//=======================================================================
80void TopOpeBRepDS_Transition::StateAfter(const TopAbs_State S)
81{
82 myStateAfter = S;
83}
84
85//=======================================================================
86//function : ShapeBefore
87//purpose :
88//=======================================================================
89void TopOpeBRepDS_Transition::ShapeBefore(const TopAbs_ShapeEnum SE)
90{
91 myShapeBefore = SE;
92}
93
94//=======================================================================
95//function : ShapeAfter
96//purpose :
97//=======================================================================
98void TopOpeBRepDS_Transition::ShapeAfter(const TopAbs_ShapeEnum SE)
99{
100 myShapeAfter = SE;
101}
102
103//=======================================================================
104//function : Before
105//purpose :
106//=======================================================================
107void TopOpeBRepDS_Transition::Before(const TopAbs_State S,const TopAbs_ShapeEnum ONB)
108{
109 myStateBefore = S;
110 myShapeBefore = ONB;
111}
112
113//=======================================================================
114//function : After
115//purpose :
116//=======================================================================
117void TopOpeBRepDS_Transition::After(const TopAbs_State S,const TopAbs_ShapeEnum ONA)
118{
119 myStateAfter = S;
120 myShapeAfter = ONA;
121}
122
123//=======================================================================
124//function : Index
125//purpose :
126//=======================================================================
127void TopOpeBRepDS_Transition::Index(const Standard_Integer I)
128{
129 myIndexBefore = myIndexAfter = I;
130}
131
132//=======================================================================
133//function : IndexBefore
134//purpose :
135//=======================================================================
136void TopOpeBRepDS_Transition::IndexBefore(const Standard_Integer I)
137{
138 myIndexBefore = I;
139}
140
141//=======================================================================
142//function : IndexAfter
143//purpose :
144//=======================================================================
145void TopOpeBRepDS_Transition::IndexAfter(const Standard_Integer I)
146{
147 myIndexAfter = I;
148}
149
150//=======================================================================
151//function : Before
152//purpose :
153//=======================================================================
154TopAbs_State TopOpeBRepDS_Transition::Before() const
155{
156 return myStateBefore;
157}
158
159//=======================================================================
160//function : ONBefore
161//purpose :
162//=======================================================================
163TopAbs_ShapeEnum TopOpeBRepDS_Transition::ONBefore() const
164{
165 return myShapeBefore;
166}
167
168//=======================================================================
169//function : After
170//purpose :
171//=======================================================================
172TopAbs_State TopOpeBRepDS_Transition::After() const
173{
174 return myStateAfter;
175}
176
177//=======================================================================
178//function : ONAfter
179//purpose :
180//=======================================================================
181TopAbs_ShapeEnum TopOpeBRepDS_Transition::ONAfter() const
182{
183 return myShapeAfter;
184}
185
186//=======================================================================
187//function : ShapeBefore
188//purpose :
189//=======================================================================
190TopAbs_ShapeEnum TopOpeBRepDS_Transition::ShapeBefore() const
191{
192 return myShapeBefore;
193}
194
195//=======================================================================
196//function : ShapeAfter
197//purpose :
198//=======================================================================
199TopAbs_ShapeEnum TopOpeBRepDS_Transition::ShapeAfter() const
200{
201 return myShapeAfter;
202}
203
204//=======================================================================
205//function : Index
206//purpose :
207//=======================================================================
208Standard_Integer TopOpeBRepDS_Transition::Index() const
209{
210 if ( myIndexAfter != myIndexBefore )
211 Standard_Failure::Raise("Transition::Index() on different shapes");
212 return myIndexBefore;
213}
214
215//=======================================================================
216//function : IndexBefore
217//purpose :
218//=======================================================================
219Standard_Integer TopOpeBRepDS_Transition::IndexBefore() const
220{
221 return myIndexBefore;
222}
223
224//=======================================================================
225//function : IndexAfter
226//purpose :
227//=======================================================================
228Standard_Integer TopOpeBRepDS_Transition::IndexAfter() const
229{
230 return myIndexAfter;
231}
232
233//=======================================================================
234//function : Set
235//purpose :
236//=======================================================================
237void TopOpeBRepDS_Transition::Set(const TopAbs_Orientation O)
238{
239 switch (O) {
240 case TopAbs_FORWARD :
241 myStateBefore = TopAbs_OUT; myStateAfter = TopAbs_IN; break;
242
243 case TopAbs_REVERSED :
244 myStateBefore = TopAbs_IN; myStateAfter = TopAbs_OUT; break;
245
246 case TopAbs_INTERNAL :
247 myStateBefore = TopAbs_IN; myStateAfter = TopAbs_IN; break;
248
249 case TopAbs_EXTERNAL :
250 myStateBefore = TopAbs_OUT; myStateAfter = TopAbs_OUT; break;
251 }
252}
253
254//=======================================================================
255//function : Orientation
256//purpose :
257//=======================================================================
258TopAbs_Orientation TopOpeBRepDS_Transition::Orientation(const TopAbs_State S,const TopAbs_ShapeEnum T) const
259{
260 if (myStateBefore == TopAbs_ON || myStateAfter == TopAbs_ON) {
261 return OrientationON(S,T);
262 }
263 else {
264 if (myStateBefore == S) {
265 if (myStateAfter == S) return TopAbs_INTERNAL;
266 else return TopAbs_REVERSED;
267 }
268 else {
269 if (myStateAfter == S) return TopAbs_FORWARD;
270 else return TopAbs_EXTERNAL;
271 }
272 }
273}
274
275//=======================================================================
276//function : OrientationON
277//purpose :
278//=======================================================================
279TopAbs_Orientation TopOpeBRepDS_Transition::OrientationON(const TopAbs_State S,const TopAbs_ShapeEnum ) const // T) const
280{
7fd59977 281 TopAbs_Orientation result=TopAbs_FORWARD;
7fd59977 282
283 if (myStateBefore == TopAbs_ON && myStateAfter == TopAbs_ON) {
284#if 0
285 if ( S == TopAbs_IN ) result = TopAbs_FORWARD;
286 else if ( S == TopAbs_OUT ) result = TopAbs_REVERSED;
287 else if ( S == TopAbs_ON ) result = TopAbs_INTERNAL;
288#endif
289 if ( S == TopAbs_IN ) result = TopAbs_INTERNAL;
290 else if ( S == TopAbs_OUT ) result = TopAbs_EXTERNAL;
291 else if ( S == TopAbs_ON ) result = TopAbs_INTERNAL;
292 }
293 else if (myStateBefore == TopAbs_ON) {
294 if (myStateAfter == S) return TopAbs_FORWARD;
295 else return TopAbs_REVERSED;
296 }
297 else if (myStateAfter == TopAbs_ON) {
298 if (myStateBefore == S) return TopAbs_REVERSED;
299 else return TopAbs_FORWARD;
300 }
301
302 return result;
303}
304
305//=======================================================================
306//function : Complement
307//purpose :
308//=======================================================================
309TopOpeBRepDS_Transition TopOpeBRepDS_Transition::Complement() const
310{
311 TopOpeBRepDS_Transition T;
312 T.myIndexBefore = myIndexBefore;
313 T.myIndexAfter = myIndexAfter;
314
315 // xpu : 14-01-98
316 if ( myStateBefore == TopAbs_UNKNOWN && myStateAfter == TopAbs_UNKNOWN ) {
317 T.Set(myStateAfter,myStateBefore,myShapeAfter,myShapeBefore);
318 return T;
319 }
320 // xpu : 14-01-98
321
322 if ( myStateBefore == TopAbs_ON || myStateAfter == TopAbs_ON) {
323 T.Set(myStateAfter,myStateBefore,myShapeAfter,myShapeBefore);
324 }
325 else {
326 TopAbs_Orientation o = Orientation(TopAbs_IN);
327 if ( o == TopAbs_FORWARD) // (OUT,IN) --> (IN,OUT)
328 T.Set(TopAbs_IN,TopAbs_OUT,myShapeBefore,myShapeAfter);
329 else if ( o == TopAbs_REVERSED) // (IN,OUT) --> (OUT,IN)
330 T.Set(TopAbs_OUT,TopAbs_IN,myShapeBefore,myShapeAfter);
331 else if ( o == TopAbs_EXTERNAL) // (OUT,OUT) --> (IN,IN)
332 T.Set(TopAbs_IN,TopAbs_IN,myShapeBefore,myShapeAfter);
333 else if ( o == TopAbs_INTERNAL) // (IN,IN) --> (OUT,OUT)
334 T.Set(TopAbs_OUT,TopAbs_OUT,myShapeBefore,myShapeAfter);
335 }
336
337 return T;
338}
339
340//=======================================================================
341//function : IsUnknown
342//purpose :
343//=======================================================================
344Standard_Boolean TopOpeBRepDS_Transition::IsUnknown() const
345{
346 return (myStateBefore == TopAbs_UNKNOWN) && (myStateAfter == TopAbs_UNKNOWN);
347}
348
349//=======================================================================
350//function : DumpB
351//purpose :
352//=======================================================================
353Standard_OStream& TopOpeBRepDS_Transition::DumpB(Standard_OStream& OS) const
354{
0797d9d3 355#ifdef OCCT_DEBUG
7fd59977 356 TopOpeBRepDS::Print(myStateBefore,OS);
357 TopOpeBRepDS::Print(TopOpeBRepDS::ShapeToKind(myShapeBefore),myIndexBefore,OS);
358#endif
359 return OS;
360}
361
362//=======================================================================
363//function : DumpA
364//purpose :
365//=======================================================================
366Standard_OStream& TopOpeBRepDS_Transition::DumpA(Standard_OStream& OS) const
367{
0797d9d3 368#ifdef OCCT_DEBUG
7fd59977 369 TopOpeBRepDS::Print(myStateAfter,OS);
370 TopOpeBRepDS::Print(TopOpeBRepDS::ShapeToKind(myShapeAfter),myIndexAfter,OS);
371#endif
372 return OS;
373}
374
375//=======================================================================
376//function : Dump
377//purpose :
378//=======================================================================
379Standard_OStream& TopOpeBRepDS_Transition::Dump(Standard_OStream& OS) const
380{
0797d9d3 381#ifdef OCCT_DEBUG
7fd59977 382 OS<<"("; DumpB(OS); OS<<","; DumpA(OS); OS<<")";
383#endif
384 return OS;
385}