1 // Copyright (C) 2007-2023 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, or (at your option) any later version.
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
23 // File : SALOMEDS_AttributeParameter.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDS_AttributeParameter.hxx"
28 #include "SALOMEDS.hxx"
32 //=======================================================================
34 * Function : Constructor
35 * Purpose : Creates a new instance of SALOMEDS_AttributeParameter
37 //=======================================================================
38 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDSImpl_AttributeParameter* theAttr)
39 :SALOMEDS_GenericAttribute(theAttr)
42 //=======================================================================
44 * Function : Constructor
45 * Purpose : Creates a new instance of SALOMEDS_AttributeParameter
47 //=======================================================================
48 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDS::AttributeParameter_ptr theAttr)
49 :SALOMEDS_GenericAttribute(theAttr)
52 //=======================================================================
54 * Function : Destructor
55 * Purpose : Destroys the instance of SALOMEDS_AttributeParameter
57 //=======================================================================
58 SALOMEDS_AttributeParameter::~SALOMEDS_AttributeParameter()
61 //=======================================================================
64 * Purpose : Associates a integer value with the ID
66 //=======================================================================
67 void SALOMEDS_AttributeParameter::SetInt(const std::string& theID, const int theValue)
72 SALOMEDS::Locker lock;
73 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetInt(theID, theValue);
76 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetInt(theID.c_str(), theValue);
79 //=======================================================================
82 * Purpose : Returns a int value associated with the given ID
84 //=======================================================================
85 int SALOMEDS_AttributeParameter::GetInt(const std::string& theID)
89 SALOMEDS::Locker lock;
90 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetInt(theID);
93 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetInt(theID.c_str());
97 //=======================================================================
100 * Purpose : Associates a double value with the ID
102 //=======================================================================
103 void SALOMEDS_AttributeParameter::SetReal(const std::string& theID, const double& theValue)
108 SALOMEDS::Locker lock;
109 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetReal(theID, theValue);
112 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetReal(theID.c_str(), theValue);
115 //=======================================================================
118 * Purpose : Returns a double value associated with the given ID
120 //=======================================================================
121 double SALOMEDS_AttributeParameter::GetReal(const std::string& theID)
125 SALOMEDS::Locker lock;
126 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetReal(theID);
129 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetReal(theID.c_str());
133 //=======================================================================
135 * Function : SetString
136 * Purpose : Associates a string with the ID
138 //=======================================================================
139 void SALOMEDS_AttributeParameter::SetString(const std::string& theID, const std::string& theValue)
144 SALOMEDS::Locker lock;
145 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetString(theID, theValue);
148 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetString(theID.c_str(), theValue.c_str());
151 //=======================================================================
153 * Function : GetString
154 * Purpose : Returns a string associated with the given ID
156 //=======================================================================
157 std::string SALOMEDS_AttributeParameter::GetString(const std::string& theID)
161 SALOMEDS::Locker lock;
162 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetString(theID);
165 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetString(theID.c_str());
169 //=======================================================================
172 * Purpose : Associates a bool value with the ID
174 //=======================================================================
175 void SALOMEDS_AttributeParameter::SetBool(const std::string& theID, const bool& theValue)
180 SALOMEDS::Locker lock;
181 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetBool(theID, theValue);
184 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetBool(theID.c_str(), theValue);
187 //=======================================================================
190 * Purpose : Returns a bool value associated with the ID
192 //=======================================================================
193 bool SALOMEDS_AttributeParameter::GetBool(const std::string& theID)
196 SALOMEDS::Locker lock;
197 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetBool(theID);
200 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetBool(theID.c_str());
203 //=======================================================================
205 * Function : SetRealArray
206 * Purpose : Associates an array of double values with the given ID
208 //=======================================================================
209 void SALOMEDS_AttributeParameter::SetRealArray(const std::string& theID, const std::vector<double>& theArray)
214 SALOMEDS::Locker lock;
215 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetRealArray(theID, theArray);
218 SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq;
219 int length = (int)theArray.size(); //!< TODO: conversion from size_t to int
221 aSeq->length(length);
222 for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
224 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetRealArray(theID.c_str(), aSeq);
228 //=======================================================================
230 * Function : GetRealArray
231 * Purpose : Returns an array of double values associated with the ID
233 //=======================================================================
234 std::vector<double> SALOMEDS_AttributeParameter::GetRealArray(const std::string& theID)
236 std::vector<double> v;
238 SALOMEDS::Locker lock;
239 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetRealArray(theID);
242 SALOMEDS::DoubleSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetRealArray(theID.c_str());
243 int length = aSeq->length();
246 for(int i = 0; i < length; i++) v[i] = aSeq[i];
252 //=======================================================================
254 * Function : SetIntArray
255 * Purpose : Associates an array of int values with the given ID
257 //=======================================================================
258 void SALOMEDS_AttributeParameter::SetIntArray(const std::string& theID, const std::vector<int>& theArray)
263 SALOMEDS::Locker lock;
264 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetIntArray(theID, theArray);
267 SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq;
268 int length = (int)theArray.size(); //!< TODO: conversion from size_t to int
270 aSeq->length(length);
271 for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
273 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetIntArray(theID.c_str(), aSeq);
277 //=======================================================================
279 * Function : GetIntArray
280 * Purpose : Returns an array of int values associated with the ID
282 //=======================================================================
283 std::vector<int> SALOMEDS_AttributeParameter::GetIntArray(const std::string& theID)
287 SALOMEDS::Locker lock;
288 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetIntArray(theID);
291 SALOMEDS::LongSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetIntArray(theID.c_str());
292 int length = aSeq->length();
295 for(int i = 0; i < length; i++) v[i] = aSeq[i];
301 //=======================================================================
303 * Function : SetStrArray
304 * Purpose : Associates an array of string values with the given ID
306 //=======================================================================
307 void SALOMEDS_AttributeParameter::SetStrArray(const std::string& theID, const std::vector<std::string>& theArray)
312 SALOMEDS::Locker lock;
313 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetStrArray(theID, theArray);
316 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq;
317 int length = (int)theArray.size(); //!< TODO: conversion from size_t to int
319 aSeq->length(length);
320 for(int i = 0; i<length; i++) aSeq[i] = CORBA::string_dup(theArray[i].c_str());
322 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetStrArray(theID.c_str(), aSeq);
326 //=======================================================================
328 * Function : GetStrArray
329 * Purpose : Returns an array of string values associated with the ID
331 //=======================================================================
332 std::vector<std::string> SALOMEDS_AttributeParameter::GetStrArray(const std::string& theID)
334 std::vector<std::string> v;
336 SALOMEDS::Locker lock;
337 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetStrArray(theID);
340 SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetStrArray(theID.c_str());
341 int length = aSeq->length();
344 for(int i = 0; i < length; i++) v[i] = std::string(aSeq[i].in());
351 //=======================================================================
354 * Purpose : Returns true if for the ID of given type was assigned \n
355 * a value in the attribute
357 //=======================================================================
358 bool SALOMEDS_AttributeParameter::IsSet(const std::string& theID, const int theType)
361 SALOMEDS::Locker lock;
362 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsSet(theID, (Parameter_Types)theType);
365 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsSet(theID.c_str(), theType);
368 //=======================================================================
370 * Function : RemoveID
371 * Purpose : Removes a parameter with given ID
373 //=======================================================================
374 bool SALOMEDS_AttributeParameter::RemoveID(const std::string& theID, const int theType)
379 SALOMEDS::Locker lock;
380 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->RemoveID(theID, (Parameter_Types)theType);
383 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->RemoveID(theID.c_str(), theType);
386 //=======================================================================
388 * Function : GetFather
389 * Purpose : Returns a father attribute for this attribute
391 //=======================================================================
392 _PTR(AttributeParameter) SALOMEDS_AttributeParameter::GetFather()
394 SALOMEDSClient_AttributeParameter* AP = NULL;
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);
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);
407 return _PTR(AttributeParameter)(AP);
410 //=======================================================================
412 * Function : HasFather
413 * Purpose : Returns True if the attribute has a father attribute
415 //=======================================================================
416 bool SALOMEDS_AttributeParameter::HasFather()
419 SALOMEDS::Locker lock;
420 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->HasFather();
423 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->HasFather();
426 //=======================================================================
429 * Purpose : Returns True is the attribute is highest in an hierarchy
431 //=======================================================================
432 bool SALOMEDS_AttributeParameter::IsRoot()
435 SALOMEDS::Locker lock;
436 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsRoot();
439 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsRoot();
442 //=======================================================================
445 * Purpose : Clears the content of the attribute
447 //=======================================================================
448 void SALOMEDS_AttributeParameter::Clear()
451 SALOMEDS::Locker lock;
452 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->Clear();
455 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->Clear();
458 //=======================================================================
461 * Purpose : Returns an array of all ID's of the given type
463 //=======================================================================
464 std::vector<std::string> SALOMEDS_AttributeParameter::GetIDs(const int theType)
466 std::vector<std::string> v;
468 SALOMEDS::Locker lock;
469 SALOMEDSImpl_AttributeParameter* AP_impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl);
470 return AP_impl->GetIDs((Parameter_Types)theType);
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();
478 for(int i = 0; i <length; i++) v[i] = std::string(CorbaSeq[i].in());