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