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"
31 //=======================================================================
33 * Function : Constructor
34 * Purpose : Creates a new instance of SALOMEDS_AttributeParameter
36 //=======================================================================
37 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDSImpl_AttributeParameter* theAttr)
38 :SALOMEDS_GenericAttribute(theAttr)
41 //=======================================================================
43 * Function : Constructor
44 * Purpose : Creates a new instance of SALOMEDS_AttributeParameter
46 //=======================================================================
47 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDS::AttributeParameter_ptr theAttr)
48 :SALOMEDS_GenericAttribute(theAttr)
51 //=======================================================================
53 * Function : Destructor
54 * Purpose : Destroys the instance of SALOMEDS_AttributeParameter
56 //=======================================================================
57 SALOMEDS_AttributeParameter::~SALOMEDS_AttributeParameter()
60 //=======================================================================
63 * Purpose : Associates a integer value with the ID
65 //=======================================================================
66 void SALOMEDS_AttributeParameter::SetInt(const string& theID, const int theValue)
71 SALOMEDS::Locker lock;
72 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetInt(theID, theValue);
75 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetInt(theID.c_str(), theValue);
78 //=======================================================================
81 * Purpose : Returns a int value associated with the given ID
83 //=======================================================================
84 int SALOMEDS_AttributeParameter::GetInt(const string& theID)
88 SALOMEDS::Locker lock;
89 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetInt(theID);
92 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetInt(theID.c_str());
96 //=======================================================================
99 * Purpose : Associates a double value with the ID
101 //=======================================================================
102 void SALOMEDS_AttributeParameter::SetReal(const string& theID, const double& theValue)
107 SALOMEDS::Locker lock;
108 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetReal(theID, theValue);
111 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetReal(theID.c_str(), theValue);
114 //=======================================================================
117 * Purpose : Returns a double value associated with the given ID
119 //=======================================================================
120 double SALOMEDS_AttributeParameter::GetReal(const string& theID)
124 SALOMEDS::Locker lock;
125 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetReal(theID);
128 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetReal(theID.c_str());
132 //=======================================================================
134 * Function : SetString
135 * Purpose : Associates a string with the ID
137 //=======================================================================
138 void SALOMEDS_AttributeParameter::SetString(const string& theID, const string& theValue)
143 SALOMEDS::Locker lock;
144 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetString(theID, theValue);
147 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetString(theID.c_str(), theValue.c_str());
150 //=======================================================================
152 * Function : GetString
153 * Purpose : Returns a string associated with the given ID
155 //=======================================================================
156 string SALOMEDS_AttributeParameter::GetString(const string& theID)
160 SALOMEDS::Locker lock;
161 aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetString(theID);
164 aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetString(theID.c_str());
168 //=======================================================================
171 * Purpose : Associates a bool value with the ID
173 //=======================================================================
174 void SALOMEDS_AttributeParameter::SetBool(const string& theID, const bool& theValue)
179 SALOMEDS::Locker lock;
180 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetBool(theID, theValue);
183 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetBool(theID.c_str(), theValue);
186 //=======================================================================
189 * Purpose : Returns a bool value associated with the ID
191 //=======================================================================
192 bool SALOMEDS_AttributeParameter::GetBool(const string& theID)
195 SALOMEDS::Locker lock;
196 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetBool(theID);
199 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetBool(theID.c_str());
202 //=======================================================================
204 * Function : SetRealArray
205 * Purpose : Associates an array of double values with the given ID
207 //=======================================================================
208 void SALOMEDS_AttributeParameter::SetRealArray(const string& theID, const vector<double>& theArray)
213 SALOMEDS::Locker lock;
214 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetRealArray(theID, theArray);
217 SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq;
218 int length = theArray.size();
220 aSeq->length(length);
221 for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
223 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetRealArray(theID.c_str(), aSeq);
227 //=======================================================================
229 * Function : GetRealArray
230 * Purpose : Returns an array of double values associated with the ID
232 //=======================================================================
233 vector<double> SALOMEDS_AttributeParameter::GetRealArray(const string& theID)
237 SALOMEDS::Locker lock;
238 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetRealArray(theID);
241 SALOMEDS::DoubleSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetRealArray(theID.c_str());
242 int length = aSeq->length();
245 for(int i = 0; i < length; i++) v[i] = aSeq[i];
251 //=======================================================================
253 * Function : SetIntArray
254 * Purpose : Associates an array of int values with the given ID
256 //=======================================================================
257 void SALOMEDS_AttributeParameter::SetIntArray(const string& theID, const vector<int>& theArray)
262 SALOMEDS::Locker lock;
263 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetIntArray(theID, theArray);
266 SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq;
267 int length = theArray.size();
269 aSeq->length(length);
270 for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
272 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetIntArray(theID.c_str(), aSeq);
276 //=======================================================================
278 * Function : GetIntArray
279 * Purpose : Returns an array of int values associated with the ID
281 //=======================================================================
282 vector<int> SALOMEDS_AttributeParameter::GetIntArray(const string& theID)
286 SALOMEDS::Locker lock;
287 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetIntArray(theID);
290 SALOMEDS::LongSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetIntArray(theID.c_str());
291 int length = aSeq->length();
294 for(int i = 0; i < length; i++) v[i] = aSeq[i];
300 //=======================================================================
302 * Function : SetStrArray
303 * Purpose : Associates an array of string values with the given ID
305 //=======================================================================
306 void SALOMEDS_AttributeParameter::SetStrArray(const string& theID, const vector<string>& theArray)
311 SALOMEDS::Locker lock;
312 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetStrArray(theID, theArray);
315 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq;
316 int length = theArray.size();
318 aSeq->length(length);
319 for(int i = 0; i<length; i++) aSeq[i] = CORBA::string_dup(theArray[i].c_str());
321 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetStrArray(theID.c_str(), aSeq);
325 //=======================================================================
327 * Function : GetStrArray
328 * Purpose : Returns an array of string values associated with the ID
330 //=======================================================================
331 vector<string> SALOMEDS_AttributeParameter::GetStrArray(const string& theID)
335 SALOMEDS::Locker lock;
336 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetStrArray(theID);
339 SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetStrArray(theID.c_str());
340 int length = aSeq->length();
343 for(int i = 0; i < length; i++) v[i] = string(aSeq[i].in());
350 //=======================================================================
353 * Purpose : Returns true if for the ID of given type was assigned \n
354 * a value in the attribute
356 //=======================================================================
357 bool SALOMEDS_AttributeParameter::IsSet(const string& theID, const int theType)
360 SALOMEDS::Locker lock;
361 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsSet(theID, (Parameter_Types)theType);
364 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsSet(theID.c_str(), theType);
367 //=======================================================================
369 * Function : RemoveID
370 * Purpose : Removes a parameter with given ID
372 //=======================================================================
373 bool SALOMEDS_AttributeParameter::RemoveID(const string& theID, const int theType)
378 SALOMEDS::Locker lock;
379 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->RemoveID(theID, (Parameter_Types)theType);
382 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->RemoveID(theID.c_str(), theType);
385 //=======================================================================
387 * Function : GetFather
388 * Purpose : Returns a father attribute for this attribute
390 //=======================================================================
391 _PTR(AttributeParameter) SALOMEDS_AttributeParameter::GetFather()
393 SALOMEDSClient_AttributeParameter* AP = NULL;
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);
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);
406 return _PTR(AttributeParameter)(AP);
409 //=======================================================================
411 * Function : HasFather
412 * Purpose : Returns True if the attribute has a father attribute
414 //=======================================================================
415 bool SALOMEDS_AttributeParameter::HasFather()
418 SALOMEDS::Locker lock;
419 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->HasFather();
422 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->HasFather();
425 //=======================================================================
428 * Purpose : Returns True is the attribute is highest in an hierachy
430 //=======================================================================
431 bool SALOMEDS_AttributeParameter::IsRoot()
434 SALOMEDS::Locker lock;
435 return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsRoot();
438 return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsRoot();
441 //=======================================================================
444 * Purpose : Clears the content of the attribute
446 //=======================================================================
447 void SALOMEDS_AttributeParameter::Clear()
450 SALOMEDS::Locker lock;
451 dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->Clear();
454 SALOMEDS::AttributeParameter::_narrow(_corba_impl)->Clear();
457 //=======================================================================
460 * Purpose : Returns an array of all ID's of the given type
462 //=======================================================================
463 vector<string> SALOMEDS_AttributeParameter::GetIDs(const int theType)
467 SALOMEDS::Locker lock;
468 SALOMEDSImpl_AttributeParameter* AP_impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl);
469 return AP_impl->GetIDs((Parameter_Types)theType);
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();
477 for(int i = 0; i <length; i++) v[i] = string(CorbaSeq[i].in());