Salome HOME
updated copyright message
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeParameter_i.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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 {
56   SALOMEDS::Locker lock; 
57   Unexpect aCatch (AP_InvalidIdentifier);
58   return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->GetInt(theID);
59 }
60
61 //=======================================================================
62 /*!
63  * Function : SetReal
64  * Purpose  : Associates a double value with the ID
65  */
66 //=======================================================================
67 void SALOMEDS_AttributeParameter_i::SetReal(const char* theID, CORBA::Double theValue)
68 {
69   SALOMEDS::Locker lock; 
70   CheckLocked();
71   dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->SetReal(theID, theValue);
72 }
73
74 //=======================================================================
75 /*!
76  * Function : GetReal
77  * Purpose  : Returns a double value associated with the given ID
78  */
79 //=======================================================================
80 CORBA::Double SALOMEDS_AttributeParameter_i::GetReal(const char* theID)
81 {
82   SALOMEDS::Locker lock; 
83   Unexpect aCatch (AP_InvalidIdentifier);
84   return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->GetReal(theID);
85 }
86
87 //=======================================================================
88 /*!
89  * Function : SetString
90  * Purpose  : Associates a string with the ID
91  */
92 //=======================================================================
93 void SALOMEDS_AttributeParameter_i::SetString(const char* theID, const char* theValue)
94 {
95   SALOMEDS::Locker lock; 
96   CheckLocked();
97   SALOMEDSImpl_AttributeParameter* impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl);
98   impl->SetString(theID, theValue);
99 }
100
101 //=======================================================================
102 /*!
103  * Function : GetString
104  * Purpose  : Returns a string associated with the given ID
105  */
106 //=======================================================================
107 char* SALOMEDS_AttributeParameter_i::GetString(const char* theID)
108 {
109   SALOMEDS::Locker lock; 
110   Unexpect aCatch (AP_InvalidIdentifier);
111   SALOMEDSImpl_AttributeParameter* impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl);
112   CORBA::String_var c_s = CORBA::string_dup(impl->GetString(theID).c_str());
113   return c_s._retn();
114 }
115
116 //=======================================================================
117 /*!
118  * Function : SetBool
119  * Purpose  : Associates a bool value with the ID
120  */
121 //=======================================================================  
122 void SALOMEDS_AttributeParameter_i::SetBool(const char* theID, CORBA::Boolean theValue)
123 {
124   SALOMEDS::Locker lock; 
125   CheckLocked();
126   dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->SetBool(theID, theValue);
127 }
128
129 //=======================================================================
130 /*!
131  * Function : GetBool
132  * Purpose  : Returns a bool value associated with the ID
133  */
134 //=======================================================================
135 CORBA::Boolean SALOMEDS_AttributeParameter_i::GetBool(const char* theID)
136 {
137   SALOMEDS::Locker lock; 
138   Unexpect aCatch (AP_InvalidIdentifier);
139   return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->GetBool(theID);
140 }
141   
142 //=======================================================================
143 /*!
144  * Function : SetRealArray
145  * Purpose  : Associates an array of double values with the given ID
146  */
147 //=======================================================================
148 void SALOMEDS_AttributeParameter_i::SetRealArray(const char* theID, const SALOMEDS::DoubleSeq& theArray)
149 {
150   SALOMEDS::Locker lock; 
151   CheckLocked();
152   std::vector<double> v;
153   int length = theArray.length();
154   if(length) {
155     v.resize(length);
156     for(int i = 0; i<length; i++) v[i] = theArray[i];
157   }
158   dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->SetRealArray(theID, v);
159 }
160
161 //=======================================================================
162 /*!
163  * Function : GetRealArray
164  * Purpose  : Returns an array of double values associated with the ID
165  */
166 //=======================================================================
167 SALOMEDS::DoubleSeq* SALOMEDS_AttributeParameter_i::GetRealArray(const char* theID)
168 {
169   SALOMEDS::Locker lock; 
170   Unexpect aCatch (AP_InvalidIdentifier);
171   SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq;
172   std::vector<double> v = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->GetRealArray(theID);
173   int length = (int)v.size(); //!< TODO: conversion from size_t to int
174   if(length) {
175     aSeq->length(length);
176     for(int i = 0; i<length; i++) aSeq[i] = v[i];
177   }
178   return aSeq._retn();
179 }
180  
181 //=======================================================================
182 /*!
183  * Function : SetIntArray
184  * Purpose  : Associates an array of int values with the given ID
185  */
186 //=======================================================================
187 void SALOMEDS_AttributeParameter_i::SetIntArray(const char* theID, const SALOMEDS::LongSeq& theArray)
188 {
189   SALOMEDS::Locker lock; 
190   CheckLocked();
191   std::vector<int> v;
192   int length = theArray.length();
193   if(length) {
194     v.resize(length);
195     for(int i = 0; i<length; i++) v[i] = theArray[i];
196   }
197   dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->SetIntArray(theID, v);
198 }
199
200 //=======================================================================
201 /*!
202  * Function : GetIntArray
203  * Purpose  : Returns an array of int values associated with the ID
204  */
205 //=======================================================================
206 SALOMEDS::LongSeq* SALOMEDS_AttributeParameter_i::GetIntArray(const char* theID)
207 {
208   SALOMEDS::Locker lock; 
209   Unexpect aCatch (AP_InvalidIdentifier);
210   SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq;
211   std::vector<int> v = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->GetIntArray(theID);
212   int length = (int)v.size(); //!< TODO: conversion from size_t to int
213   if(length) {
214     aSeq->length(length);
215     for(int i = 0; i<length; i++) aSeq[i] = v[i];
216   }
217   return aSeq._retn();
218 }
219   
220 //=======================================================================
221 /*!
222  * Function : SetStrArray
223  * Purpose  : Associates an array of string values with the given ID
224  */
225 //=======================================================================
226 void SALOMEDS_AttributeParameter_i::SetStrArray(const char* theID, const SALOMEDS::StringSeq& theArray)
227 {
228   SALOMEDS::Locker lock; 
229   CheckLocked();
230   std::vector<std::string> v;
231   int length = theArray.length();
232   if(length) {
233     v.resize(length);
234     for(int i = 0; i<length; i++) v[i] = std::string(theArray[i].in());
235   }
236   dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->SetStrArray(theID, v);
237 }
238
239 //=======================================================================
240 /*!
241  * Function : GetStrArray
242  * Purpose  : Returns an array of string values associated with the ID
243  */
244 //=======================================================================
245 SALOMEDS::StringSeq* SALOMEDS_AttributeParameter_i::GetStrArray(const char* theID)
246 {
247   SALOMEDS::Locker lock; 
248   Unexpect aCatch (AP_InvalidIdentifier);
249   SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq;
250   std::vector<std::string> v = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->GetStrArray(theID);
251   int length = (int)v.size(); //!< TODO: conversion from size_t to int
252   if(length) {
253     aSeq->length(length);
254     for(int i = 0; i<length; i++) aSeq[i] = CORBA::string_dup(v[i].c_str());
255   }
256   return aSeq._retn();
257 }
258   
259  
260 //=======================================================================
261 /*!
262  * Function : IsSet
263  * Purpose  : Returns true if for the ID of given type was assigned \n
264  *            a value in the attribute
265  */
266 //=======================================================================
267 CORBA::Boolean SALOMEDS_AttributeParameter_i::IsSet(const char* theID, CORBA::Long theType)
268 {
269   SALOMEDS::Locker lock; 
270   return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->IsSet(theID, (Parameter_Types)theType);
271 }
272
273 //=======================================================================
274 /*!
275  * Function : RemoveID
276  * Purpose  : Removes a parameter with given ID
277  */
278 //=======================================================================  
279 CORBA::Boolean SALOMEDS_AttributeParameter_i::RemoveID(const char* theID, CORBA::Long theType)
280 {
281   SALOMEDS::Locker lock; 
282   CheckLocked();
283   return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->RemoveID(theID, (Parameter_Types)theType);
284 }
285
286 //=======================================================================
287 /*!
288  * Function : GetFather
289  * Purpose  : Returns a father attribute for this attribute
290  */
291 //=======================================================================
292 SALOMEDS::AttributeParameter_ptr SALOMEDS_AttributeParameter_i::GetFather()
293 {
294   SALOMEDS::Locker lock; 
295   SALOMEDSImpl_AttributeParameter* impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl);
296   SALOMEDS_AttributeParameter_i* attr = new SALOMEDS_AttributeParameter_i(impl, _orb);
297   return attr->AttributeParameter::_this();
298 }
299
300 //=======================================================================
301 /*!
302  * Function : HasFather
303  * Purpose  : Returns True if the attribute has a father attribute
304  */
305 //=======================================================================
306 CORBA::Boolean SALOMEDS_AttributeParameter_i::HasFather()
307 {
308   SALOMEDS::Locker lock; 
309   return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->HasFather();
310 }
311
312 //=======================================================================
313 /*!
314  * Function : IsRoot
315  * Purpose  : Returns True is the attribute is highest in an hierarchy
316  */
317 //=======================================================================
318 CORBA::Boolean SALOMEDS_AttributeParameter_i::IsRoot()
319 {
320   SALOMEDS::Locker lock; 
321   return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->IsRoot();
322 }
323
324 //=======================================================================
325 /*!
326  * Function : IsRoot
327  * Purpose  : Clears the content of the attribute
328  */
329 //=======================================================================
330 void SALOMEDS_AttributeParameter_i::Clear()
331 {
332   SALOMEDS::Locker lock; 
333   dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->Clear();
334 }
335
336
337 //=======================================================================
338 /*!
339  * Function : GetIDs
340  * Purpose  : Returns an array of all ID's of the given type
341  */
342 //=======================================================================
343 SALOMEDS::StringSeq* SALOMEDS_AttributeParameter_i::GetIDs(CORBA::Long theType)
344 {
345   SALOMEDS::Locker lock; 
346   SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
347   std::vector<std::string> A = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_impl)->GetIDs((Parameter_Types)theType);
348
349   if(A.size()) {
350     int length = (int)A.size(); //!< TODO: conversion from size_t to int
351     CorbaSeq->length(length);
352     for (int i = 0; i < length; i++) CorbaSeq[i] = CORBA::string_dup(A[i].c_str());;
353   }
354
355   return CorbaSeq._retn();
356 }