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