Salome HOME
merge from BR_KERNEL_REFACTORING
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeStudyProperties.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : SALOMEDS_AttributeStudyProperties.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26 //
27 #include "SALOMEDS_AttributeStudyProperties.hxx"
28 #include "SALOMEDS.hxx"
29
30 SALOMEDS_AttributeStudyProperties::SALOMEDS_AttributeStudyProperties
31                                    (SALOMEDSImpl_AttributeStudyProperties* theAttr)
32 :SALOMEDS_GenericAttribute(theAttr)
33 {}
34
35 SALOMEDS_AttributeStudyProperties::SALOMEDS_AttributeStudyProperties
36                                    (SALOMEDS::AttributeStudyProperties_ptr theAttr)
37 :SALOMEDS_GenericAttribute(theAttr)
38 {}
39
40 SALOMEDS_AttributeStudyProperties::~SALOMEDS_AttributeStudyProperties()
41 {
42 }
43
44 void SALOMEDS_AttributeStudyProperties::SetUserName(const std::string& theName)
45 {
46   if (_isLocal) {
47     CheckLocked();
48     SALOMEDS::Locker lock;
49     SALOMEDSImpl_AttributeStudyProperties* anImpl =
50       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
51     anImpl->ChangeCreatorName(theName);
52   } else
53     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetUserName(theName.c_str());
54 }
55
56 std::string SALOMEDS_AttributeStudyProperties::GetUserName()
57 {
58   std::string aName;
59   if (_isLocal) {
60     SALOMEDS::Locker lock;
61     aName = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetCreatorName();
62   }
63 #ifndef WIN32
64   else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserName();
65 #else
66   else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserNameA();
67 #endif
68   return aName;
69 }
70
71 void SALOMEDS_AttributeStudyProperties::SetCreationDate
72               (int theMinute, int theHour, int theDay, int theMonth, int theYear)
73 {
74   if (_isLocal) {
75     CheckLocked();
76     SALOMEDS::Locker lock;
77     SALOMEDSImpl_AttributeStudyProperties* anImpl =
78       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
79     int aTmp;
80     if (anImpl->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
81     std::string S;
82     anImpl->SetModification(S, theMinute, theHour, theDay, theMonth, theYear);
83   } else {
84     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetCreationDate(theMinute,
85                                                                               theHour,
86                                                                               theDay,
87                                                                               theMonth,
88                                                                               theYear);
89   }
90 }
91
92 bool SALOMEDS_AttributeStudyProperties::GetCreationDate(int& theMinute,
93                                                         int& theHour,
94                                                         int& theDay,
95                                                         int& theMonth,
96                                                         int& theYear)
97 {
98   bool ret;
99   if (_isLocal) {
100     SALOMEDS::Locker lock;
101     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>
102       (_local_impl)->GetCreationDate(theMinute, theHour, theDay, theMonth, theYear);
103   } else {
104     CORBA::Long aMinute, anHour, aDay, aMonth, anYear;
105     ret = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetCreationDate(aMinute,
106                                                                                     anHour,
107                                                                                     aDay,
108                                                                                     aMonth,
109                                                                                     anYear);
110     theMinute = (int)aMinute;
111     theHour = (int)anHour;
112     theDay = (int)aDay;
113     theMonth = (int)aMonth;
114     theYear = (int)anYear;
115   }
116   return ret;
117 }
118
119 void SALOMEDS_AttributeStudyProperties::SetCreationMode(const std::string& theMode)
120 {
121   if (_isLocal) {
122     CheckLocked();
123     SALOMEDS::Locker lock;
124     if (theMode == "from scratch")
125       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(1);
126     else if (theMode == "copy from")
127       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(2);
128     else //Not defined
129       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(0);
130   }
131   else ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetCreationMode(theMode.c_str());
132 }
133
134 std::string SALOMEDS_AttributeStudyProperties::GetCreationMode()
135 {
136   std::string aMode;
137   if (_isLocal) {
138     SALOMEDS::Locker lock;
139     int mode  = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetCreationMode();
140     if (mode == 1) aMode = "from scratch";
141     if (mode == 2) aMode = "copy from";
142   }
143   else
144     aMode = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetCreationMode();
145   return aMode;
146 }
147
148 void SALOMEDS_AttributeStudyProperties::SetModified(int theModified)
149 {
150   if (_isLocal) {
151     SALOMEDS::Locker lock;
152     dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetModified(theModified);
153   }
154   else
155     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetModified(theModified);
156 }
157
158 bool SALOMEDS_AttributeStudyProperties::IsModified()
159 {
160   bool ret;
161   if (_isLocal) {
162     SALOMEDS::Locker lock;
163     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->IsModified();
164   }
165   else
166     ret = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->IsModified();
167   return ret;
168 }
169
170 int SALOMEDS_AttributeStudyProperties::GetModified()
171 {
172   int isModified;
173   if (_isLocal) {
174     SALOMEDS::Locker lock;
175     isModified = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetModified();
176   }
177   else
178     isModified = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetModified();
179   return isModified;
180 }
181
182 void SALOMEDS_AttributeStudyProperties::SetLocked(bool theLocked)
183 {
184   if (_isLocal) {
185     SALOMEDS::Locker lock;
186     dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetLocked(theLocked);
187   }
188   else
189     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetLocked(theLocked);
190 }
191
192 bool SALOMEDS_AttributeStudyProperties::IsLocked()
193 {
194   bool ret;
195   if (_isLocal) {
196     SALOMEDS::Locker lock;
197     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->IsLocked();
198   }
199   else
200     ret = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->IsLocked();
201   return ret;
202 }
203
204 void SALOMEDS_AttributeStudyProperties::SetModification(const std::string& theName,
205                                                         int theMinute,
206                                                         int theHour,
207                                                         int theDay,
208                                                         int theMonth,
209                                                         int theYear)
210 {
211   if (_isLocal) {
212     CheckLocked();
213     SALOMEDS::Locker lock;
214     SALOMEDSImpl_AttributeStudyProperties* anImpl = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
215     anImpl->SetModification(theName, theMinute, theHour, theDay, theMonth, theYear);
216   } else
217     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetModification(theName.c_str(),
218                                                                               theMinute,
219                                                                               theHour,
220                                                                               theDay,
221                                                                               theMonth,
222                                                                               theYear);
223 }
224
225 void SALOMEDS_AttributeStudyProperties::GetModificationsList(std::vector<std::string>& theNames,
226                                                              std::vector<int>& theMinutes,
227                                                              std::vector<int>& theHours,
228                                                              std::vector<int>& theDays,
229                                                              std::vector<int>& theMonths,
230                                                              std::vector<int>& theYears,
231                                                              bool theWithCreator)
232 {
233   int i, aLength;
234
235   if (_isLocal) {
236     SALOMEDS::Locker lock;
237     std::vector<std::string> aNames;
238     std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
239     SALOMEDSImpl_AttributeStudyProperties* anImpl = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
240     anImpl->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
241     aLength = aNames.size();
242     i = ((theWithCreator) ? 1 : 2);
243     for (; i <= aLength; i++) {
244       theNames.push_back(aNames[i-1]);
245       theMinutes.push_back(aMinutes[i-1]);
246       theHours.push_back(aHours[i-1]);
247       theDays.push_back(aDays[i-1]);
248       theMonths.push_back(aMonths[i-1]);
249       theYears.push_back(aYears[i-1]);
250     }
251   } else {
252     SALOMEDS::StringSeq_var aNames;
253     SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears;
254     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetModificationsList(aNames.out(),
255                                                                                    aMinutes.out(),
256                                                                                    aHours.out(),
257                                                                                    aDays.out(),
258                                                                                    aMonths.out(),
259                                                                                    aYears.out(),
260                                                                                    theWithCreator);
261     aLength = aNames->length();
262     for (i = 0; i<aLength; i++) {
263       theNames.push_back(aNames[i].in());
264       theMinutes.push_back(aMinutes[i]);
265       theHours.push_back(aHours[i]);
266       theDays.push_back(aDays[i]);
267       theMonths.push_back(aMonths[i]);
268       theYears.push_back(aYears[i]);
269     }
270   }
271 }
272
273
274 void SALOMEDS_AttributeStudyProperties::SetComment(const std::string& theComment)
275 {
276   if (_isLocal) {
277     CheckLocked();
278     SALOMEDS::Locker lock;
279     SALOMEDSImpl_AttributeStudyProperties* anImpl =
280       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
281     anImpl->SetComment(theComment);
282   } else
283     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetComment(theComment.c_str());
284 }
285
286 std::string SALOMEDS_AttributeStudyProperties::GetComment()
287 {
288   std::string aComment;
289   if (_isLocal) {
290     SALOMEDS::Locker lock;
291     aComment = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetComment();
292   }
293   else 
294     aComment = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetComment();
295   return aComment;
296 }
297
298
299 void SALOMEDS_AttributeStudyProperties::SetUnits(const std::string& theUnits)
300 {
301   if (_isLocal) {
302     CheckLocked();
303     SALOMEDS::Locker lock;
304     SALOMEDSImpl_AttributeStudyProperties* anImpl =
305       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
306     anImpl->SetUnits(theUnits);
307   } else
308     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetUnits(theUnits.c_str());
309 }
310
311 std::string SALOMEDS_AttributeStudyProperties::GetUnits()
312 {
313   std::string anUnits;
314   if (_isLocal) {
315     SALOMEDS::Locker lock;
316     anUnits = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetUnits();
317   }
318   else 
319     anUnits = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUnits();
320   return anUnits;
321 }
322
323 std::vector<std::string> SALOMEDS_AttributeStudyProperties::GetStoredComponents()
324 {
325   std::vector<std::string> aComponents;
326   if (_isLocal) {
327     SALOMEDS::Locker lock;
328     aComponents = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetStoredComponents();
329   }
330   else {
331     SALOMEDS::StringSeq_var components = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetStoredComponents();
332     int length = components->length();
333     for (int i = 0; i < length; i++) {
334       aComponents.push_back(components[i].in());
335     }
336   }
337   return aComponents;
338 }
339
340 std::string SALOMEDS_AttributeStudyProperties::GetComponentVersion( const std::string& theComponent )
341 {
342   std::string aVersion;
343   if (_isLocal) {
344     SALOMEDS::Locker lock;
345     aVersion = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetComponentVersion(theComponent);
346   }
347   else 
348     aVersion = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetComponentVersion(theComponent.c_str());
349   return aVersion;
350 }
351
352 std::vector<std::string> SALOMEDS_AttributeStudyProperties::GetComponentVersions( const std::string& theComponent )
353 {
354   std::vector<std::string> aVersions;
355   if (_isLocal) {
356     SALOMEDS::Locker lock;
357     aVersions = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetComponentVersions(theComponent);
358   }
359   else {
360     SALOMEDS::StringSeq_var versions = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetComponentVersions(theComponent.c_str());
361     int length = versions->length();
362     for (int i = 0; i < length; i++) {
363       aVersions.push_back(versions[i].in());
364     }
365   }
366   return aVersions;
367 }