1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOMEDS_AttributeParameter.cxx
23 // Author : Sergey RUIN
26 #include "SALOMEDS_AttributeParameter.hxx"
27 #include "SALOMEDS.hxx"
33 //=======================================================================
35 * Function : Constructor
36 * Purpose : Creates a new instance of SALOMEDS_AttributeParameter
38 //=======================================================================
39 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDSImpl_AttributeParameter* theAttr)
40 :SALOMEDS_GenericAttribute(theAttr)
43 //=======================================================================
45 * Function : Constructor
46 * Purpose : Creates a new instance of SALOMEDS_AttributeParameter
48 //=======================================================================
49 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDS::AttributeParameter_ptr theAttr)
50 :SALOMEDS_GenericAttribute(theAttr)
53 //=======================================================================
55 * Function : Destructor
56 * Purpose : Destroys the instance of SALOMEDS_AttributeParameter
58 //=======================================================================
59 SALOMEDS_AttributeParameter::~SALOMEDS_AttributeParameter()
62 //=======================================================================
65 * Purpose : Associates a integer value with the ID
67 //=======================================================================
68 void SALOMEDS_AttributeParameter::SetInt(const string& theID, const int theValue)
73 SALOMEDS::Locker lock;
74 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetInt(theID, theValue);
77 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetInt(theID.c_str(), theValue);
80 //=======================================================================
83 * Purpose : Returns a int value associated with the given ID
85 //=======================================================================
86 int SALOMEDS_AttributeParameter::GetInt(const string& theID)
90 SALOMEDS::Locker lock;
91 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetInt(theID);
94 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetInt(theID.c_str());
98 //=======================================================================
101 * Purpose : Associates a double value with the ID
103 //=======================================================================
104 void SALOMEDS_AttributeParameter::SetReal(const string& theID, const double& theValue)
109 SALOMEDS::Locker lock;
110 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetReal(theID, theValue);
113 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetReal(theID.c_str(), theValue);
116 //=======================================================================
119 * Purpose : Returns a double value associated with the given ID
121 //=======================================================================
122 double SALOMEDS_AttributeParameter::GetReal(const string& theID)
126 SALOMEDS::Locker lock;
127 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetReal(theID);
130 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetReal(theID.c_str());
134 //=======================================================================
136 * Function : SetString
137 * Purpose : Associates a string with the ID
139 //=======================================================================
140 void SALOMEDS_AttributeParameter::SetString(const string& theID, const string& theValue)
145 SALOMEDS::Locker lock;
146 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetString(theID, theValue);
149 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetString(theID.c_str(), theValue.c_str());
152 //=======================================================================
154 * Function : GetString
155 * Purpose : Returns a string associated with the given ID
157 //=======================================================================
158 string SALOMEDS_AttributeParameter::GetString(const string& theID)
162 SALOMEDS::Locker lock;
163 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetString(theID);
166 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetString(theID.c_str());
170 //=======================================================================
173 * Purpose : Associates a bool value with the ID
175 //=======================================================================
176 void SALOMEDS_AttributeParameter::SetBool(const string& theID, const bool& theValue)
181 SALOMEDS::Locker lock;
182 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetBool(theID, theValue);
185 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetBool(theID.c_str(), theValue);
188 //=======================================================================
191 * Purpose : Returns a bool value associated with the ID
193 //=======================================================================
194 bool SALOMEDS_AttributeParameter::GetBool(const string& theID)
197 SALOMEDS::Locker lock;
198 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetBool(theID);
201 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetBool(theID.c_str());
204 //=======================================================================
206 * Function : SetRealArray
207 * Purpose : Associates an array of double values with the given ID
209 //=======================================================================
210 void SALOMEDS_AttributeParameter::SetRealArray(const string& theID, const vector<double>& theArray)
215 SALOMEDS::Locker lock;
216 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetRealArray(theID, theArray);
219 SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq;
220 int length = theArray.size();
222 aSeq->length(length);
223 for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
225 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetRealArray(theID.c_str(), aSeq);
229 //=======================================================================
231 * Function : GetRealArray
232 * Purpose : Returns an array of double values associated with the ID
234 //=======================================================================
235 vector<double> SALOMEDS_AttributeParameter::GetRealArray(const string& theID)
239 SALOMEDS::Locker lock;
240 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetRealArray(theID);
243 SALOMEDS::DoubleSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetRealArray(theID.c_str());
244 int length = aSeq->length();
247 for(int i = 0; i < length; i++) v[i] = aSeq[i];
253 //=======================================================================
255 * Function : SetIntArray
256 * Purpose : Associates an array of int values with the given ID
258 //=======================================================================
259 void SALOMEDS_AttributeParameter::SetIntArray(const string& theID, const vector<int>& theArray)
264 SALOMEDS::Locker lock;
265 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetIntArray(theID, theArray);
268 SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq;
269 int length = theArray.size();
271 aSeq->length(length);
272 for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
274 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetIntArray(theID.c_str(), aSeq);
278 //=======================================================================
280 * Function : GetIntArray
281 * Purpose : Returns an array of int values associated with the ID
283 //=======================================================================
284 vector<int> SALOMEDS_AttributeParameter::GetIntArray(const string& theID)
288 SALOMEDS::Locker lock;
289 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetIntArray(theID);
292 SALOMEDS::LongSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetIntArray(theID.c_str());
293 int length = aSeq->length();
296 for(int i = 0; i < length; i++) v[i] = aSeq[i];
302 //=======================================================================
304 * Function : SetStrArray
305 * Purpose : Associates an array of string values with the given ID
307 //=======================================================================
308 void SALOMEDS_AttributeParameter::SetStrArray(const string& theID, const vector<string>& theArray)
313 SALOMEDS::Locker lock;
314 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetStrArray(theID, theArray);
317 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq;
318 int length = theArray.size();
320 aSeq->length(length);
321 for(int i = 0; i<length; i++) aSeq[i] = CORBA::string_dup(theArray[i].c_str());
323 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetStrArray(theID.c_str(), aSeq);
327 //=======================================================================
329 * Function : GetStrArray
330 * Purpose : Returns an array of string values associated with the ID
332 //=======================================================================
333 vector<string> SALOMEDS_AttributeParameter::GetStrArray(const string& theID)
337 SALOMEDS::Locker lock;
338 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetStrArray(theID);
341 SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetStrArray(theID.c_str());
342 int length = aSeq->length();
345 for(int i = 0; i < length; i++) v[i] = string(aSeq[i].in());
352 //=======================================================================
355 * Purpose : Returns true if for the ID of given type was assigned \n
356 * a value in the attribute
358 //=======================================================================
359 bool SALOMEDS_AttributeParameter::IsSet(const string& theID, const int theType)
362 SALOMEDS::Locker lock;
363 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsSet(theID, (Parameter_Types)theType);
366 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsSet(theID.c_str(), theType);
369 //=======================================================================
371 * Function : RemoveID
372 * Purpose : Removes a parameter with given ID
374 //=======================================================================
375 bool SALOMEDS_AttributeParameter::RemoveID(const string& theID, const int theType)
380 SALOMEDS::Locker lock;
381 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->RemoveID(theID, (Parameter_Types)theType);
384 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->RemoveID(theID.c_str(), theType);
387 //=======================================================================
389 * Function : GetFather
390 * Purpose : Returns a father attribute for this attribute
392 //=======================================================================
393 _PTR(AttributeParameter) SALOMEDS_AttributeParameter::GetFather()
395 SALOMEDSClient_AttributeParameter* AP = NULL;
397 SALOMEDS::Locker lock;
398 SALOMEDSImpl_AttributeParameter* AP_impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetFather();
399 if(!AP_impl) return _PTR(AttributeParameter)(AP);
400 AP = new SALOMEDS_AttributeParameter(AP_impl);
403 SALOMEDS::AttributeParameter_var AP_impl = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetFather();
404 if(CORBA::is_nil(AP_impl)) return _PTR(AttributeParameter)(AP);
405 AP = new SALOMEDS_AttributeParameter(AP_impl);
408 return _PTR(AttributeParameter)(AP);
411 //=======================================================================
413 * Function : HasFather
414 * Purpose : Returns True if the attribute has a father attribute
416 //=======================================================================
417 bool SALOMEDS_AttributeParameter::HasFather()
420 SALOMEDS::Locker lock;
421 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->HasFather();
424 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->HasFather();
427 //=======================================================================
430 * Purpose : Returns True is the attribute is highest in an hierachy
432 //=======================================================================
433 bool SALOMEDS_AttributeParameter::IsRoot()
436 SALOMEDS::Locker lock;
437 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsRoot();
440 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsRoot();
443 //=======================================================================
446 * Purpose : Clears the content of the attribute
448 //=======================================================================
449 void SALOMEDS_AttributeParameter::Clear()
452 SALOMEDS::Locker lock;
453 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->Clear();
456 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->Clear();
459 //=======================================================================
462 * Purpose : Returns an array of all ID's of the given type
464 //=======================================================================
465 vector<string> SALOMEDS_AttributeParameter::GetIDs(const int theType)
469 SALOMEDS::Locker lock;
470 SALOMEDSImpl_AttributeParameter* AP_impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl);
471 return AP_impl->GetIDs((Parameter_Types)theType);
474 SALOMEDS::AttributeParameter_var AP_impl = SALOMEDS::AttributeParameter::_narrow(_corba_impl);
475 SALOMEDS::StringSeq_var CorbaSeq = AP_impl->GetIDs(theType);
476 int length = CorbaSeq->length();
479 for(int i = 0; i <length; i++) v[i] = string(CorbaSeq[i].in());