1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDS_AttributeParameter.cxx
21 // Author : Sergey RUIN
24 #include "SALOMEDS_AttributeParameter.hxx"
25 #include "SALOMEDS.hxx"
28 #include <TCollection_AsciiString.hxx>
30 //=======================================================================
32 * Function : Constructor
33 * Purpose : Creates a new instance of SALOMEDS_AttributeParameter
35 //=======================================================================
36 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(const Handle(SALOMEDSImpl_AttributeParameter)& theAttr)
37 :SALOMEDS_GenericAttribute(theAttr)
40 //=======================================================================
42 * Function : Constructor
43 * Purpose : Creates a new instance of SALOMEDS_AttributeParameter
45 //=======================================================================
46 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDS::AttributeParameter_ptr theAttr)
47 :SALOMEDS_GenericAttribute(theAttr)
50 //=======================================================================
52 * Function : Destructor
53 * Purpose : Destroys the instance of SALOMEDS_AttributeParameter
55 //=======================================================================
56 SALOMEDS_AttributeParameter::~SALOMEDS_AttributeParameter()
59 //=======================================================================
62 * Purpose : Associates a integer value with the ID
64 //=======================================================================
65 void SALOMEDS_AttributeParameter::SetInt(const string& theID, const int theValue)
70 SALOMEDS::Locker lock;
71 Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->SetInt(theID, theValue);
74 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetInt(theID.c_str(), theValue);
77 //=======================================================================
80 * Purpose : Returns a int value associated with the given ID
82 //=======================================================================
83 int SALOMEDS_AttributeParameter::GetInt(const string& theID)
87 SALOMEDS::Locker lock;
88 aValue = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->GetInt(theID);
91 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetInt(theID.c_str());
95 //=======================================================================
98 * Purpose : Associates a double value with the ID
100 //=======================================================================
101 void SALOMEDS_AttributeParameter::SetReal(const string& theID, const double& theValue)
106 SALOMEDS::Locker lock;
107 Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->SetReal(theID, theValue);
110 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetReal(theID.c_str(), theValue);
113 //=======================================================================
116 * Purpose : Returns a double value associated with the given ID
118 //=======================================================================
119 double SALOMEDS_AttributeParameter::GetReal(const string& theID)
123 SALOMEDS::Locker lock;
124 aValue = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->GetReal(theID);
127 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetReal(theID.c_str());
131 //=======================================================================
133 * Function : SetString
134 * Purpose : Associates a string with the ID
136 //=======================================================================
137 void SALOMEDS_AttributeParameter::SetString(const string& theID, const string& theValue)
142 SALOMEDS::Locker lock;
143 Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->SetString(theID, theValue);
146 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetString(theID.c_str(), theValue.c_str());
149 //=======================================================================
151 * Function : GetString
152 * Purpose : Returns a string associated with the given ID
154 //=======================================================================
155 string SALOMEDS_AttributeParameter::GetString(const string& theID)
159 SALOMEDS::Locker lock;
160 aValue = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->GetString(theID);
163 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetString(theID.c_str());
167 //=======================================================================
170 * Purpose : Associates a bool value with the ID
172 //=======================================================================
173 void SALOMEDS_AttributeParameter::SetBool(const string& theID, const bool& theValue)
178 SALOMEDS::Locker lock;
179 Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->SetBool(theID, theValue);
182 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetBool(theID.c_str(), theValue);
185 //=======================================================================
188 * Purpose : Returns a bool value associated with the ID
190 //=======================================================================
191 bool SALOMEDS_AttributeParameter::GetBool(const string& theID)
194 SALOMEDS::Locker lock;
195 return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->GetBool(theID);
198 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetBool(theID.c_str());
201 //=======================================================================
203 * Function : SetRealArray
204 * Purpose : Associates an array of double values with the given ID
206 //=======================================================================
207 void SALOMEDS_AttributeParameter::SetRealArray(const string& theID, const vector<double>& theArray)
212 SALOMEDS::Locker lock;
213 Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->SetRealArray(theID, theArray);
216 SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq;
217 int length = theArray.size();
219 aSeq->length(length);
220 for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
222 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetRealArray(theID.c_str(), aSeq);
226 //=======================================================================
228 * Function : GetRealArray
229 * Purpose : Returns an array of double values associated with the ID
231 //=======================================================================
232 vector<double> SALOMEDS_AttributeParameter::GetRealArray(const string& theID)
236 SALOMEDS::Locker lock;
237 return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->GetRealArray(theID);
240 SALOMEDS::DoubleSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetRealArray(theID.c_str());
241 int length = aSeq->length();
244 for(int i = 0; i < length; i++) v[i] = aSeq[i];
250 //=======================================================================
252 * Function : SetIntArray
253 * Purpose : Associates an array of int values with the given ID
255 //=======================================================================
256 void SALOMEDS_AttributeParameter::SetIntArray(const string& theID, const vector<int>& theArray)
261 SALOMEDS::Locker lock;
262 Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->SetIntArray(theID, theArray);
265 SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq;
266 int length = theArray.size();
268 aSeq->length(length);
269 for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
271 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetIntArray(theID.c_str(), aSeq);
275 //=======================================================================
277 * Function : GetIntArray
278 * Purpose : Returns an array of int values associated with the ID
280 //=======================================================================
281 vector<int> SALOMEDS_AttributeParameter::GetIntArray(const string& theID)
285 SALOMEDS::Locker lock;
286 return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->GetIntArray(theID);
289 SALOMEDS::LongSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetIntArray(theID.c_str());
290 int length = aSeq->length();
293 for(int i = 0; i < length; i++) v[i] = aSeq[i];
299 //=======================================================================
301 * Function : SetStrArray
302 * Purpose : Associates an array of string values with the given ID
304 //=======================================================================
305 void SALOMEDS_AttributeParameter::SetStrArray(const string& theID, const vector<string>& theArray)
310 SALOMEDS::Locker lock;
311 Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->SetStrArray(theID, theArray);
314 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq;
315 int length = theArray.size();
317 aSeq->length(length);
318 for(int i = 0; i<length; i++) aSeq[i] = CORBA::string_dup(theArray[i].c_str());
320 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetStrArray(theID.c_str(), aSeq);
324 //=======================================================================
326 * Function : GetStrArray
327 * Purpose : Returns an array of string values associated with the ID
329 //=======================================================================
330 vector<string> SALOMEDS_AttributeParameter::GetStrArray(const string& theID)
334 SALOMEDS::Locker lock;
335 return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->GetStrArray(theID);
338 SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetStrArray(theID.c_str());
339 int length = aSeq->length();
342 for(int i = 0; i < length; i++) v[i] = string(aSeq[i].in());
349 //=======================================================================
352 * Purpose : Returns true if for the ID of given type was assigned \n
353 * a value in the attribute
355 //=======================================================================
356 bool SALOMEDS_AttributeParameter::IsSet(const string& theID, const int theType)
359 SALOMEDS::Locker lock;
360 return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->IsSet(theID, (Parameter_Types)theType);
363 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsSet(theID.c_str(), theType);
366 //=======================================================================
368 * Function : RemoveID
369 * Purpose : Removes a parameter with given ID
371 //=======================================================================
372 bool SALOMEDS_AttributeParameter::RemoveID(const string& theID, const int theType)
377 SALOMEDS::Locker lock;
378 return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->RemoveID(theID, (Parameter_Types)theType);
381 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->RemoveID(theID.c_str(), theType);
384 //=======================================================================
386 * Function : GetFather
387 * Purpose : Returns a father attribute for this attribute
389 //=======================================================================
390 _PTR(AttributeParameter) SALOMEDS_AttributeParameter::GetFather()
392 SALOMEDSClient_AttributeParameter* AP = NULL;
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);
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);
405 return _PTR(AttributeParameter)(AP);
408 //=======================================================================
410 * Function : HasFather
411 * Purpose : Returns True if the attribute has a father attribute
413 //=======================================================================
414 bool SALOMEDS_AttributeParameter::HasFather()
417 SALOMEDS::Locker lock;
418 return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->HasFather();
421 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->HasFather();
424 //=======================================================================
427 * Purpose : Returns True is the attribute is highest in an hierachy
429 //=======================================================================
430 bool SALOMEDS_AttributeParameter::IsRoot()
433 SALOMEDS::Locker lock;
434 return Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->IsRoot();
437 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsRoot();
440 //=======================================================================
443 * Purpose : Clears the content of the attribute
445 //=======================================================================
446 void SALOMEDS_AttributeParameter::Clear()
449 SALOMEDS::Locker lock;
450 Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl)->Clear();
453 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->Clear();
456 //=======================================================================
459 * Purpose : Returns an array of all ID's of the given type
461 //=======================================================================
462 vector<string> SALOMEDS_AttributeParameter::GetIDs(const int theType)
466 SALOMEDS::Locker lock;
467 Handle(SALOMEDSImpl_AttributeParameter) AP_impl = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(_local_impl);
468 return AP_impl->GetIDs((Parameter_Types)theType);
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();
476 for(int i = 0; i <length; i++) v[i] = string(CorbaSeq[i].in());