0031662: Modeling Algorithms - Incomplete result of section operation
[occt.git] / src / StepData / StepData_SelectType.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <Interface_Macros.hxx>
16#include <Standard_Transient.hxx>
7fd59977 17#include <Standard_TypeMismatch.hxx>
42cf5bc1 18#include <StepData_PDescr.hxx>
19#include <StepData_SelectInt.hxx>
20#include <StepData_SelectMember.hxx>
7fd59977 21#include <StepData_SelectNamed.hxx>
22#include <StepData_SelectReal.hxx>
42cf5bc1 23#include <StepData_SelectType.hxx>
f9c58d7c 24#include <StepData_UndefinedEntity.hxx>
25
7fd59977 26
b311480e 27Standard_Boolean StepData_SelectType::Matches
7fd59977 28 (const Handle(Standard_Transient)& ent) const
29{
30 if (CaseNum(ent) > 0) return Standard_True;
31 DeclareAndCast(StepData_SelectMember,sm,ent);
32 if (sm.IsNull()) return Standard_False;
33 if (CaseMem(sm) > 0) return Standard_True;
34 return Standard_False;
35}
36
37 void StepData_SelectType::SetValue (const Handle(Standard_Transient)& ent)
38{
39 if (ent.IsNull()) thevalue.Nullify();
f9c58d7c 40 else if (ent->IsKind(STANDARD_TYPE(StepData_UndefinedEntity)))
41 thevalue = ent;
7fd59977 42 else if (!Matches(ent))
9775fa61 43 throw Standard_TypeMismatch("StepData : SelectType, SetValue");
7fd59977 44 else thevalue = ent;
45}
46
47 void StepData_SelectType::Nullify ()
48 { thevalue.Nullify(); }
49
50 const Handle(Standard_Transient)& StepData_SelectType::Value () const
51 { return thevalue; }
52
53 Standard_Boolean StepData_SelectType::IsNull () const
54 { return thevalue.IsNull(); }
55
56 Handle(Standard_Type) StepData_SelectType::Type () const
57{
58 if (thevalue.IsNull()) return STANDARD_TYPE(Standard_Transient);
59 return thevalue->DynamicType();
60}
61
62 Standard_Integer StepData_SelectType::CaseNumber () const
63 { if (thevalue.IsNull()) return 0; return CaseNum(thevalue); }
64
65
66// ********** Types Immediats ***********
67
68 Handle(StepData_PDescr) StepData_SelectType::Description () const
69 { Handle(StepData_PDescr) nuldescr; return nuldescr; }
70
71 Handle(StepData_SelectMember) StepData_SelectType::NewMember () const
72 { Handle(StepData_SelectMember) nulmem; return nulmem; }
73
35e08fe8 74 Standard_Integer StepData_SelectType::CaseMem (const Handle(StepData_SelectMember)& /*ent*/) const
7fd59977 75 { return 0; }
76
77 Standard_Integer StepData_SelectType::CaseMember () const
78{
79 DeclareAndCast(StepData_SelectMember,sm,thevalue);
80 if (sm.IsNull()) return 0;
81 return CaseMem (sm);
82}
83
84 Handle(StepData_SelectMember) StepData_SelectType::Member () const
85 { return GetCasted(StepData_SelectMember,thevalue); }
86
87 Standard_CString StepData_SelectType::SelectName () const
88{
89 DeclareAndCast(StepData_SelectMember,sm,thevalue);
90 if (sm.IsNull()) return "";
91 return sm->Name();
92}
93
94 Standard_Integer StepData_SelectType::Int () const
95{
96 DeclareAndCast(StepData_SelectMember,sm,thevalue);
97 if (sm.IsNull()) return 0;
98 return sm->Int();
99}
100
101 void StepData_SelectType::SetInt (const Standard_Integer val)
102{
103 DeclareAndCast(StepData_SelectMember,sm,thevalue);
9775fa61 104 if (sm.IsNull()) throw Standard_TypeMismatch("StepData : SelectType, SetInt");
7fd59977 105 sm->SetInt (val);
106}
107
108// ********** Types Immediats : Differents Cas ***********
109
110static Handle(StepData_SelectMember) SelectVal
111 (const Handle(Standard_Transient)& thevalue, const Standard_CString name,
112 const int mode)
113{
114 DeclareAndCast(StepData_SelectMember,sm,thevalue);
115 if (!sm.IsNull()) {
116 if (name && name[0] != '\0')
9775fa61 117 if (!sm->SetName(name)) throw Standard_TypeMismatch("StepData : SelectType, SetInteger");
7fd59977 118 }
119 else if (name && name[0] != '\0') {
120 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
121 sn->SetName (name);
122 sm = sn;
123 } else {
124 if (mode == 0) sm = new StepData_SelectInt;
125 if (mode == 1) sm = new StepData_SelectReal;
126 }
127 return sm;
128}
129
130
131 Standard_Integer StepData_SelectType::Integer () const
132{
133 DeclareAndCast(StepData_SelectMember,sm,thevalue);
134 if (sm.IsNull()) return 0;
135 return sm->Integer();
136}
137
138 void StepData_SelectType::SetInteger
139 (const Standard_Integer val, const Standard_CString name)
140{
141 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
142 sm->SetInteger (val);
9775fa61 143 if (CaseMem (sm) == 0) throw Standard_TypeMismatch("StepData : SelectType, SetInteger");
7fd59977 144 thevalue = sm;
145}
146
147 Standard_Boolean StepData_SelectType::Boolean () const
148{
149 DeclareAndCast(StepData_SelectMember,sm,thevalue);
150 if (sm.IsNull()) return Standard_False;
151 return sm->Boolean();
152}
153
154 void StepData_SelectType::SetBoolean
155 (const Standard_Boolean val, const Standard_CString name)
156{
157 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
158 sm->SetBoolean (val);
9775fa61 159 if (CaseMem (sm) == 0) throw Standard_TypeMismatch("StepData : SelectType, SetBoolean");
7fd59977 160 thevalue = sm;
161}
162
163 StepData_Logical StepData_SelectType::Logical () const
164{
165 DeclareAndCast(StepData_SelectMember,sm,thevalue);
166 if (sm.IsNull()) return StepData_LUnknown;
167 return sm->Logical();
168}
169
170 void StepData_SelectType::SetLogical
171 (const StepData_Logical val, const Standard_CString name)
172{
173 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
174 sm->SetLogical (val);
9775fa61 175 if (CaseMem (sm) == 0) throw Standard_TypeMismatch("StepData : SelectType, SetLogical");
7fd59977 176 thevalue = sm;
177}
178
179Standard_Real StepData_SelectType::Real () const
180{
181 DeclareAndCast(StepData_SelectMember,sm,thevalue);
182 if (sm.IsNull()) return 0.0;
183 return sm->Real();
184}
185
186 void StepData_SelectType::SetReal
187 (const Standard_Real val, const Standard_CString name)
188{
189 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,1);
190 sm->SetReal (val);
9775fa61 191 if (CaseMem (sm) == 0) throw Standard_TypeMismatch("StepData : SelectType, SetReal");
7fd59977 192 thevalue = sm;
193}
194
e6f550da 195StepData_SelectType::~StepData_SelectType()
196{}