Salome HOME
updated copyright message
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeParameter.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.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26 //
27 #include "SALOMEDS_AttributeParameter.hxx"
28 #include "SALOMEDS.hxx"
29
30 #include <string>
31
32 //=======================================================================
33 /*!
34  * Function : Constructor
35  * Purpose  : Creates a new instance of SALOMEDS_AttributeParameter
36  */
37 //=======================================================================
38 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDSImpl_AttributeParameter* theAttr)
39 :SALOMEDS_GenericAttribute(theAttr)
40 {}
41
42 //=======================================================================
43 /*!
44  * Function : Constructor
45  * Purpose  : Creates a new instance of SALOMEDS_AttributeParameter
46  */
47 //=======================================================================
48 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDS::AttributeParameter_ptr theAttr)
49 :SALOMEDS_GenericAttribute(theAttr)
50 {}
51
52 //=======================================================================
53 /*!
54  * Function : Destructor
55  * Purpose  : Destroys the instance of SALOMEDS_AttributeParameter
56  */
57 //=======================================================================
58 SALOMEDS_AttributeParameter::~SALOMEDS_AttributeParameter()
59 {}
60
61 //=======================================================================
62 /*!
63  * Function : SetInt
64  * Purpose  : Associates a integer value with the ID
65  */
66 //=======================================================================
67 void SALOMEDS_AttributeParameter::SetInt(const std::string& theID, const int theValue) 
68 {
69   CheckLocked();
70
71   if(_isLocal) {
72     SALOMEDS::Locker lock; 
73     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetInt(theID, theValue);
74   }
75   else
76     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetInt(theID.c_str(), theValue);
77 }
78
79 //=======================================================================
80 /*!
81  * Function : GetInt
82  * Purpose  : Returns a int value associated with the given ID
83  */
84 //=======================================================================
85 int SALOMEDS_AttributeParameter::GetInt(const std::string& theID) 
86 {
87   int aValue;
88   if(_isLocal) {
89     SALOMEDS::Locker lock; 
90     aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetInt(theID);
91   }
92   else
93     aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetInt(theID.c_str());
94   return aValue;
95 }
96
97 //=======================================================================
98 /*!
99  * Function : SetReal
100  * Purpose  : Associates a double value with the ID
101  */
102 //=======================================================================
103 void SALOMEDS_AttributeParameter::SetReal(const std::string& theID, const double& theValue) 
104 {
105   CheckLocked();
106
107   if(_isLocal) {
108     SALOMEDS::Locker lock; 
109     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetReal(theID, theValue);
110   }
111   else
112     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetReal(theID.c_str(), theValue);
113 }
114  
115 //=======================================================================
116 /*!
117  * Function : GetReal
118  * Purpose  : Returns a double value associated with the given ID
119  */
120 //=======================================================================
121 double SALOMEDS_AttributeParameter::GetReal(const std::string& theID) 
122 {
123   double aValue;
124   if(_isLocal) {
125     SALOMEDS::Locker lock; 
126     aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetReal(theID);
127   }
128   else
129     aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetReal(theID.c_str());
130   return aValue;
131 }
132
133 //=======================================================================
134 /*!
135  * Function : SetString
136  * Purpose  : Associates a string with the ID
137  */
138 //=======================================================================
139 void SALOMEDS_AttributeParameter::SetString(const std::string& theID, const std::string& theValue) 
140 {
141   CheckLocked();
142
143   if(_isLocal) {
144     SALOMEDS::Locker lock; 
145     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetString(theID, theValue);
146   }
147   else
148     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetString(theID.c_str(), theValue.c_str());
149 }
150  
151 //=======================================================================
152 /*!
153  * Function : GetString
154  * Purpose  : Returns a string associated with the given ID
155  */
156 //=======================================================================
157 std::string SALOMEDS_AttributeParameter::GetString(const std::string& theID) 
158 {
159   std::string aValue;
160   if(_isLocal) {
161     SALOMEDS::Locker lock; 
162     aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetString(theID);
163   }
164   else
165     aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetString(theID.c_str());
166   return aValue;
167 }
168   
169 //=======================================================================
170 /*!
171  * Function : SetBool
172  * Purpose  : Associates a bool value with the ID
173  */
174 //=======================================================================
175 void SALOMEDS_AttributeParameter::SetBool(const std::string& theID, const bool& theValue) 
176 {
177   CheckLocked();
178
179   if(_isLocal) {
180     SALOMEDS::Locker lock; 
181     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetBool(theID, theValue);
182   }
183   else
184     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetBool(theID.c_str(), theValue);
185 }
186
187 //=======================================================================
188 /*!
189  * Function : GetBool
190  * Purpose  : Returns a bool value associated with the ID
191  */
192 //=======================================================================
193 bool SALOMEDS_AttributeParameter::GetBool(const std::string& theID) 
194 {
195   if(_isLocal) {
196     SALOMEDS::Locker lock; 
197     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetBool(theID);
198   }
199   else
200     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetBool(theID.c_str());
201 }
202   
203 //=======================================================================
204 /*!
205  * Function : SetRealArray
206  * Purpose  : Associates an array of double values with the given ID
207  */
208 //=======================================================================
209 void SALOMEDS_AttributeParameter::SetRealArray(const std::string& theID, const std::vector<double>& theArray) 
210 {
211   CheckLocked();
212
213   if(_isLocal) {
214     SALOMEDS::Locker lock; 
215     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetRealArray(theID, theArray);
216   }
217   else {
218     SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq;
219     int length = (int)theArray.size(); //!< TODO: conversion from size_t to int
220     if(length) {
221       aSeq->length(length);
222       for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
223     }
224     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetRealArray(theID.c_str(), aSeq);
225   }
226 }
227  
228 //=======================================================================
229 /*!
230  * Function : GetRealArray
231  * Purpose  : Returns an array of double values associated with the ID
232  */
233 //=======================================================================
234 std::vector<double> SALOMEDS_AttributeParameter::GetRealArray(const std::string& theID) 
235 {
236   std::vector<double> v;
237   if(_isLocal) {
238     SALOMEDS::Locker lock; 
239     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetRealArray(theID);
240   }
241   else {
242     SALOMEDS::DoubleSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetRealArray(theID.c_str());    
243     int length = aSeq->length();
244     if(length) {
245       v.resize(length);
246       for(int i = 0; i < length; i++) v[i] = aSeq[i];
247     }
248   }
249   return v;
250 }
251
252 //=======================================================================
253 /*!
254  * Function : SetIntArray
255  * Purpose  : Associates an array of int values with the given ID
256  */
257 //=======================================================================
258 void SALOMEDS_AttributeParameter::SetIntArray(const std::string& theID, const std::vector<int>& theArray) 
259 {
260   CheckLocked();
261
262   if(_isLocal) {
263     SALOMEDS::Locker lock; 
264     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetIntArray(theID, theArray);
265   }
266   else {
267     SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq;
268     int length = (int)theArray.size(); //!< TODO: conversion from size_t to int
269     if(length) {
270       aSeq->length(length);
271       for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
272     }
273     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetIntArray(theID.c_str(), aSeq);
274   }
275 }
276  
277 //=======================================================================
278 /*!
279  * Function : GetIntArray
280  * Purpose  : Returns an array of int values associated with the ID
281  */
282 //=======================================================================
283 std::vector<int> SALOMEDS_AttributeParameter::GetIntArray(const std::string& theID) 
284 {
285   std::vector<int> v;
286   if(_isLocal) {
287     SALOMEDS::Locker lock; 
288     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetIntArray(theID);
289   }
290   else {
291     SALOMEDS::LongSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetIntArray(theID.c_str());    
292     int length = aSeq->length();
293     if(length) {
294       v.resize(length);
295       for(int i = 0; i < length; i++) v[i] = aSeq[i];
296     }
297   }
298   return v;
299 }
300
301 //=======================================================================
302 /*!
303  * Function : SetStrArray
304  * Purpose  : Associates an array of string values with the given ID
305  */
306 //=======================================================================
307 void SALOMEDS_AttributeParameter::SetStrArray(const std::string& theID, const std::vector<std::string>& theArray) 
308 {
309   CheckLocked();
310
311   if(_isLocal) {
312     SALOMEDS::Locker lock; 
313     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetStrArray(theID, theArray);
314   }
315   else {
316     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq;
317     int length = (int)theArray.size(); //!< TODO: conversion from size_t to int
318     if(length) {
319       aSeq->length(length);
320       for(int i = 0; i<length; i++) aSeq[i] = CORBA::string_dup(theArray[i].c_str());
321     }
322     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetStrArray(theID.c_str(), aSeq);
323   }
324 }
325  
326 //=======================================================================
327 /*!
328  * Function : GetStrArray
329  * Purpose  : Returns an array of string values associated with the ID
330  */
331 //=======================================================================
332 std::vector<std::string> SALOMEDS_AttributeParameter::GetStrArray(const std::string& theID) 
333 {
334   std::vector<std::string> v;
335   if(_isLocal) {
336     SALOMEDS::Locker lock; 
337     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetStrArray(theID);
338   }
339   else {
340     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetStrArray(theID.c_str());    
341     int length = aSeq->length();
342     if(length) {
343       v.resize(length);
344       for(int i = 0; i < length; i++) v[i] = std::string(aSeq[i].in());
345     }
346   }
347   return v;
348 }
349
350
351 //=======================================================================
352 /*!
353  * Function : IsSet
354  * Purpose  : Returns true if for the ID of given type was assigned \n
355  *            a value in the attribute
356  */
357 //======================================================================= 
358 bool SALOMEDS_AttributeParameter::IsSet(const std::string& theID, const int theType) 
359 {
360   if(_isLocal) {
361     SALOMEDS::Locker lock; 
362     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsSet(theID, (Parameter_Types)theType);
363   }
364   else 
365     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsSet(theID.c_str(), theType);
366 }
367
368 //=======================================================================
369 /*!
370  * Function : RemoveID
371  * Purpose  : Removes a parameter with given ID
372  */
373 //======================================================================= 
374 bool SALOMEDS_AttributeParameter::RemoveID(const std::string& theID, const int theType) 
375 {
376   CheckLocked();
377
378   if(_isLocal) {
379     SALOMEDS::Locker lock; 
380     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->RemoveID(theID, (Parameter_Types)theType);
381   }
382   else
383     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->RemoveID(theID.c_str(), theType);
384 }
385
386 //=======================================================================
387 /*!
388  * Function : GetFather
389  * Purpose  : Returns a father attribute for this attribute
390  */
391 //=======================================================================
392 _PTR(AttributeParameter) SALOMEDS_AttributeParameter::GetFather() 
393 {
394   SALOMEDSClient_AttributeParameter* AP = NULL;
395   if(_isLocal) {
396     SALOMEDS::Locker lock; 
397     SALOMEDSImpl_AttributeParameter* AP_impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetFather();
398     if(!AP_impl) return _PTR(AttributeParameter)(AP);
399     AP = new SALOMEDS_AttributeParameter(AP_impl);
400   }
401   else {
402     SALOMEDS::AttributeParameter_var AP_impl = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetFather();
403     if(CORBA::is_nil(AP_impl)) return _PTR(AttributeParameter)(AP);
404     AP = new SALOMEDS_AttributeParameter(AP_impl);
405   }
406   
407   return _PTR(AttributeParameter)(AP);
408 }
409
410 //=======================================================================
411 /*!
412  * Function : HasFather
413  * Purpose  : Returns True if the attribute has a father attribute
414  */
415 //======================================================================= 
416 bool SALOMEDS_AttributeParameter::HasFather() 
417 {
418   if(_isLocal) {
419     SALOMEDS::Locker lock; 
420     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->HasFather();
421   }
422   else 
423     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->HasFather();
424 }
425
426 //=======================================================================
427 /*!
428  * Function : IsRoot
429  * Purpose  : Returns True is the attribute is highest in an hierarchy
430  */
431 //=======================================================================
432 bool SALOMEDS_AttributeParameter::IsRoot()
433 {
434   if(_isLocal) {
435     SALOMEDS::Locker lock; 
436     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsRoot();
437   }
438   else 
439     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsRoot();
440 }
441
442 //=======================================================================
443 /*!
444  * Function : Clear
445  * Purpose  : Clears the content of the attribute
446  */
447 //======================================================================= 
448 void SALOMEDS_AttributeParameter::Clear() 
449 {
450   if(_isLocal) {
451     SALOMEDS::Locker lock; 
452     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->Clear();
453   }
454   else 
455     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->Clear();
456 }
457
458 //=======================================================================
459 /*!
460  * Function : GetIDs
461  * Purpose  : Returns an array of all ID's of the given type
462  */
463 //=======================================================================
464 std::vector<std::string> SALOMEDS_AttributeParameter::GetIDs(const int theType)
465 {
466   std::vector<std::string> v;
467   if(_isLocal) {
468     SALOMEDS::Locker lock; 
469     SALOMEDSImpl_AttributeParameter* AP_impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl);
470     return AP_impl->GetIDs((Parameter_Types)theType);
471   }
472   else {
473     SALOMEDS::AttributeParameter_var AP_impl = SALOMEDS::AttributeParameter::_narrow(_corba_impl);
474     SALOMEDS::StringSeq_var CorbaSeq = AP_impl->GetIDs(theType);
475     int length = CorbaSeq->length();
476     if(length) {
477       v.resize(length);
478       for(int i = 0; i <length; i++) v[i] = std::string(CorbaSeq[i].in());
479     }
480   }
481
482   return v;
483 }