Salome HOME
PR: merge from branch BR_auto_V310 tag mergefrom_OCC_development_for_3_2_0a2_10mar06
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeParameter_i.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 //  File   : SALOMEDS_AttributeParameter_i.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24
25 #include "SALOMEDS_AttributeParameter_i.hxx"
26 #include "SALOMEDS.hxx"
27 #include <TCollection_AsciiString.hxx>
28
29 #include <vector>
30
31 using namespace std;
32
33 //=======================================================================
34 /*!
35  * Function : SetInt
36  * Purpose  : Associates a integer value with the ID
37  */
38 //=======================================================================
39 void SALOMEDS_AttributeParameter_i::SetInt(const char* theID, CORBA::Long theValue)
40 {
41   SALOMEDS::Locker lock; 
42   CheckLocked();
43   Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->SetInt(theID, theValue);
44 }
45
46 //=======================================================================
47 /*!
48  * Function : GetInt
49  * Purpose  : Returns a int value associated with the given ID
50  */
51 //=======================================================================
52 CORBA::Long SALOMEDS_AttributeParameter_i::GetInt(const char* theID)
53 {
54   SALOMEDS::Locker lock; 
55   return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->GetInt(theID);
56 }
57
58 //=======================================================================
59 /*!
60  * Function : SetReal
61  * Purpose  : Associates a double value with the ID
62  */
63 //=======================================================================
64 void SALOMEDS_AttributeParameter_i::SetReal(const char* theID, const CORBA::Double theValue)
65 {
66   SALOMEDS::Locker lock; 
67   CheckLocked();
68   Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->SetReal(theID, theValue);
69 }
70
71 //=======================================================================
72 /*!
73  * Function : GetReal
74  * Purpose  : Returns a double value associated with the given ID
75  */
76 //=======================================================================
77 CORBA::Double SALOMEDS_AttributeParameter_i::GetReal(const char* theID)
78 {
79   SALOMEDS::Locker lock; 
80   return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->GetReal(theID);
81 }
82
83 //=======================================================================
84 /*!
85  * Function : SetString
86  * Purpose  : Associates a string with the ID
87  */
88 //=======================================================================
89 void SALOMEDS_AttributeParameter_i::SetString(const char* theID, const char* theValue)
90 {
91   SALOMEDS::Locker lock; 
92   CheckLocked();
93   Handle(SALOMEDSImpl_AttributeParameter) impl = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl);
94   impl->SetString(theID, theValue);
95 }
96
97 //=======================================================================
98 /*!
99  * Function : GetString
100  * Purpose  : Returns a string associated with the given ID
101  */
102 //=======================================================================
103 char* SALOMEDS_AttributeParameter_i::GetString(const char* theID)
104 {
105   SALOMEDS::Locker lock; 
106   Handle(SALOMEDSImpl_AttributeParameter) impl = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl);
107   CORBA::String_var c_s = CORBA::string_dup(impl->GetString(theID).c_str());
108   return c_s._retn();
109 }
110
111 //=======================================================================
112 /*!
113  * Function : SetBool
114  * Purpose  : Associates a bool value with the ID
115  */
116 //=======================================================================  
117 void SALOMEDS_AttributeParameter_i::SetBool(const char* theID, CORBA::Boolean theValue)
118 {
119   SALOMEDS::Locker lock; 
120   CheckLocked();
121   Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->SetBool(theID, theValue);
122 }
123
124 //=======================================================================
125 /*!
126  * Function : GetBool
127  * Purpose  : Returns a bool value associated with the ID
128  */
129 //=======================================================================
130 CORBA::Boolean SALOMEDS_AttributeParameter_i::GetBool(const char* theID)
131 {
132   SALOMEDS::Locker lock; 
133   return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->GetBool(theID);
134 }
135   
136 //=======================================================================
137 /*!
138  * Function : SetRealArray
139  * Purpose  : Associates an array of double values with the given ID
140  */
141 //=======================================================================
142 void SALOMEDS_AttributeParameter_i::SetRealArray(const char* theID, const SALOMEDS::DoubleSeq& theArray)
143 {
144   SALOMEDS::Locker lock; 
145   CheckLocked();
146   vector<double> v;
147   int length = theArray.length();
148   if(length) {
149     v.resize(length);
150     for(int i = 0; i<length; i++) v[i] = theArray[i];
151   }
152   Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->SetRealArray(theID, v);
153 }
154
155 //=======================================================================
156 /*!
157  * Function : GetRealArray
158  * Purpose  : Returns an array of double values associated with the ID
159  */
160 //=======================================================================
161 SALOMEDS::DoubleSeq* SALOMEDS_AttributeParameter_i::GetRealArray(const char* theID)
162 {
163   SALOMEDS::Locker lock; 
164   SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq;
165   vector<double> v = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->GetRealArray(theID);
166   int length = v.size();
167   if(length) {
168     aSeq->length(length);
169     for(int i = 0; i<length; i++) aSeq[i] = v[i];
170   }
171   return aSeq._retn();
172 }
173  
174 //=======================================================================
175 /*!
176  * Function : SetIntArray
177  * Purpose  : Associates an array of int values with the given ID
178  */
179 //=======================================================================
180 void SALOMEDS_AttributeParameter_i::SetIntArray(const char* theID, const SALOMEDS::LongSeq& theArray)
181 {
182   SALOMEDS::Locker lock; 
183   CheckLocked();
184   vector<int> v;
185   int length = theArray.length();
186   if(length) {
187     v.resize(length);
188     for(int i = 0; i<length; i++) v[i] = theArray[i];
189   }
190   Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->SetIntArray(theID, v);
191 }
192
193 //=======================================================================
194 /*!
195  * Function : GetIntArray
196  * Purpose  : Returns an array of int values associated with the ID
197  */
198 //=======================================================================
199 SALOMEDS::LongSeq* SALOMEDS_AttributeParameter_i::GetIntArray(const char* theID)
200 {
201   SALOMEDS::Locker lock; 
202   SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq;
203   vector<int> v = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->GetIntArray(theID);
204   int length = v.size();
205   if(length) {
206     aSeq->length(length);
207     for(int i = 0; i<length; i++) aSeq[i] = v[i];
208   }
209   return aSeq._retn();
210 }
211   
212 //=======================================================================
213 /*!
214  * Function : SetStrArray
215  * Purpose  : Associates an array of string values with the given ID
216  */
217 //=======================================================================
218 void SALOMEDS_AttributeParameter_i::SetStrArray(const char* theID, const SALOMEDS::StringSeq& theArray)
219 {
220   SALOMEDS::Locker lock; 
221   CheckLocked();
222   vector<string> v;
223   int length = theArray.length();
224   if(length) {
225     v.resize(length);
226     for(int i = 0; i<length; i++) v[i] = string(theArray[i].in());
227   }
228   Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->SetStrArray(theID, v);
229 }
230
231 //=======================================================================
232 /*!
233  * Function : GetStrArray
234  * Purpose  : Returns an array of string values associated with the ID
235  */
236 //=======================================================================
237 SALOMEDS::StringSeq* SALOMEDS_AttributeParameter_i::GetStrArray(const char* theID)
238 {
239   SALOMEDS::Locker lock; 
240   SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq;
241   vector<string> v = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->GetStrArray(theID);
242   int length = v.size();
243   if(length) {
244     aSeq->length(length);
245     for(int i = 0; i<length; i++) aSeq[i] = CORBA::string_dup(v[i].c_str());
246   }
247   return aSeq._retn();
248 }
249   
250  
251 //=======================================================================
252 /*!
253  * Function : IsSet
254  * Purpose  : Returns true if for the ID of given type was assigned \n
255  *            a value in the attribute
256  */
257 //=======================================================================
258 CORBA::Boolean SALOMEDS_AttributeParameter_i::IsSet(const char* theID, CORBA::Long theType)
259 {
260   SALOMEDS::Locker lock; 
261   return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->IsSet(theID, (Parameter_Types)theType);
262 }
263
264 //=======================================================================
265 /*!
266  * Function : RemoveID
267  * Purpose  : Removes a parameter with given ID
268  */
269 //=======================================================================  
270 CORBA::Boolean SALOMEDS_AttributeParameter_i::RemoveID(const char* theID, CORBA::Long theType)
271 {
272   SALOMEDS::Locker lock; 
273   CheckLocked();
274   return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->RemoveID(theID, (Parameter_Types)theType);
275 }
276
277 //=======================================================================
278 /*!
279  * Function : GetFather
280  * Purpose  : Returns a father attribute for this attribute
281  */
282 //=======================================================================
283 SALOMEDS::AttributeParameter_ptr SALOMEDS_AttributeParameter_i::GetFather()
284 {
285   SALOMEDS::Locker lock; 
286   Handle(SALOMEDSImpl_AttributeParameter) impl = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl);
287   SALOMEDS_AttributeParameter_i* attr = new SALOMEDS_AttributeParameter_i(impl, _orb);
288   return attr->AttributeParameter::_this();
289 }
290
291 //=======================================================================
292 /*!
293  * Function : HasFather
294  * Purpose  : Returns True if the attribute has a father attribute
295  */
296 //=======================================================================
297 CORBA::Boolean SALOMEDS_AttributeParameter_i::HasFather()
298 {
299   SALOMEDS::Locker lock; 
300   return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->HasFather();
301 }
302
303 //=======================================================================
304 /*!
305  * Function : IsRoot
306  * Purpose  : Returns True is the attribute is highest in an hierachy
307  */
308 //=======================================================================
309 CORBA::Boolean SALOMEDS_AttributeParameter_i::IsRoot()
310 {
311   SALOMEDS::Locker lock; 
312   return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->IsRoot();
313 }
314
315 //=======================================================================
316 /*!
317  * Function : IsRoot
318  * Purpose  : Clears the content of the attribute
319  */
320 //=======================================================================
321 void SALOMEDS_AttributeParameter_i::Clear()
322 {
323   SALOMEDS::Locker lock; 
324   Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->Clear();
325 }
326
327
328 //=======================================================================
329 /*!
330  * Function : GetIDs
331  * Purpose  : Returns an array of all ID's of the given type
332  */
333 //=======================================================================
334 SALOMEDS::StringSeq* SALOMEDS_AttributeParameter_i::GetIDs(CORBA::Long theType)
335 {
336   SALOMEDS::Locker lock; 
337   SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
338   vector<string> A = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_impl)->GetIDs((Parameter_Types)theType);
339
340   if(A.size()) {
341     int length = A.size();
342     CorbaSeq->length(length);
343     for (int i = 0; i < length; i++) CorbaSeq[i] = CORBA::string_dup(A[i].c_str());;
344   }
345
346   return CorbaSeq._retn();
347 }