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