Salome HOME
Copyright update 2022
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeStudyProperties.cxx
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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 #ifdef UNICODE
67   else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserNameW();
68 #else
69   else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserNameA();
70 #endif
71 #endif
72   return aName;
73 }
74
75 void SALOMEDS_AttributeStudyProperties::SetCreationDate
76               (int theMinute, int theHour, int theDay, int theMonth, int theYear)
77 {
78   if (_isLocal) {
79     CheckLocked();
80     SALOMEDS::Locker lock;
81     SALOMEDSImpl_AttributeStudyProperties* anImpl =
82       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
83     int aTmp;
84     if (anImpl->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
85     std::string S;
86     anImpl->SetModification(S, theMinute, theHour, theDay, theMonth, theYear);
87   } else {
88     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetCreationDate(theMinute,
89                                                                               theHour,
90                                                                               theDay,
91                                                                               theMonth,
92                                                                               theYear);
93   }
94 }
95
96 bool SALOMEDS_AttributeStudyProperties::GetCreationDate(int& theMinute,
97                                                         int& theHour,
98                                                         int& theDay,
99                                                         int& theMonth,
100                                                         int& theYear)
101 {
102   bool ret;
103   if (_isLocal) {
104     SALOMEDS::Locker lock;
105     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>
106       (_local_impl)->GetCreationDate(theMinute, theHour, theDay, theMonth, theYear);
107   } else {
108     CORBA::Long aMinute, anHour, aDay, aMonth, anYear;
109     ret = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetCreationDate(aMinute,
110                                                                                     anHour,
111                                                                                     aDay,
112                                                                                     aMonth,
113                                                                                     anYear);
114     theMinute = (int)aMinute;
115     theHour = (int)anHour;
116     theDay = (int)aDay;
117     theMonth = (int)aMonth;
118     theYear = (int)anYear;
119   }
120   return ret;
121 }
122
123 void SALOMEDS_AttributeStudyProperties::SetCreationMode(const std::string& theMode)
124 {
125   if (_isLocal) {
126     CheckLocked();
127     SALOMEDS::Locker lock;
128     if (theMode == "from scratch")
129       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(1);
130     else if (theMode == "copy from")
131       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(2);
132     else //Not defined
133       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(0);
134   }
135   else ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetCreationMode(theMode.c_str());
136 }
137
138 std::string SALOMEDS_AttributeStudyProperties::GetCreationMode()
139 {
140   std::string aMode;
141   if (_isLocal) {
142     SALOMEDS::Locker lock;
143     int mode  = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetCreationMode();
144     if (mode == 1) aMode = "from scratch";
145     if (mode == 2) aMode = "copy from";
146   }
147   else
148     aMode = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetCreationMode();
149   return aMode;
150 }
151
152 void SALOMEDS_AttributeStudyProperties::SetModified(int theModified)
153 {
154   if (_isLocal) {
155     SALOMEDS::Locker lock;
156     dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetModified(theModified);
157   }
158   else
159     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetModified(theModified);
160 }
161
162 bool SALOMEDS_AttributeStudyProperties::IsModified()
163 {
164   bool ret;
165   if (_isLocal) {
166     SALOMEDS::Locker lock;
167     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->IsModified();
168   }
169   else
170     ret = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->IsModified();
171   return ret;
172 }
173
174 int SALOMEDS_AttributeStudyProperties::GetModified()
175 {
176   int isModified;
177   if (_isLocal) {
178     SALOMEDS::Locker lock;
179     isModified = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetModified();
180   }
181   else
182     isModified = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetModified();
183   return isModified;
184 }
185
186 void SALOMEDS_AttributeStudyProperties::SetLocked(bool theLocked)
187 {
188   if (_isLocal) {
189     SALOMEDS::Locker lock;
190     dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetLocked(theLocked);
191   }
192   else
193     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetLocked(theLocked);
194 }
195
196 bool SALOMEDS_AttributeStudyProperties::IsLocked()
197 {
198   bool ret;
199   if (_isLocal) {
200     SALOMEDS::Locker lock;
201     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->IsLocked();
202   }
203   else
204     ret = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->IsLocked();
205   return ret;
206 }
207
208 void SALOMEDS_AttributeStudyProperties::SetModification(const std::string& theName,
209                                                         int theMinute,
210                                                         int theHour,
211                                                         int theDay,
212                                                         int theMonth,
213                                                         int theYear)
214 {
215   if (_isLocal) {
216     CheckLocked();
217     SALOMEDS::Locker lock;
218     SALOMEDSImpl_AttributeStudyProperties* anImpl = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
219     anImpl->SetModification(theName, theMinute, theHour, theDay, theMonth, theYear);
220   } else
221     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetModification(theName.c_str(),
222                                                                               theMinute,
223                                                                               theHour,
224                                                                               theDay,
225                                                                               theMonth,
226                                                                               theYear);
227 }
228
229 void SALOMEDS_AttributeStudyProperties::GetModificationsList(std::vector<std::string>& theNames,
230                                                              std::vector<int>& theMinutes,
231                                                              std::vector<int>& theHours,
232                                                              std::vector<int>& theDays,
233                                                              std::vector<int>& theMonths,
234                                                              std::vector<int>& theYears,
235                                                              bool theWithCreator)
236 {
237   int i, aLength;
238
239   if (_isLocal) {
240     SALOMEDS::Locker lock;
241     std::vector<std::string> aNames;
242     std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
243     SALOMEDSImpl_AttributeStudyProperties* anImpl = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
244     anImpl->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
245     aLength = (int)aNames.size(); //!< TODO: conversion from size_t to int
246     i = ((theWithCreator) ? 1 : 2);
247     for (; i <= aLength; i++) {
248       theNames.push_back(aNames[i-1]);
249       theMinutes.push_back(aMinutes[i-1]);
250       theHours.push_back(aHours[i-1]);
251       theDays.push_back(aDays[i-1]);
252       theMonths.push_back(aMonths[i-1]);
253       theYears.push_back(aYears[i-1]);
254     }
255   } else {
256     SALOMEDS::StringSeq_var aNames;
257     SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears;
258     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetModificationsList(aNames.out(),
259                                                                                    aMinutes.out(),
260                                                                                    aHours.out(),
261                                                                                    aDays.out(),
262                                                                                    aMonths.out(),
263                                                                                    aYears.out(),
264                                                                                    theWithCreator);
265     aLength = aNames->length();
266     for (i = 0; i<aLength; i++) {
267       theNames.push_back(aNames[i].in());
268       theMinutes.push_back(aMinutes[i]);
269       theHours.push_back(aHours[i]);
270       theDays.push_back(aDays[i]);
271       theMonths.push_back(aMonths[i]);
272       theYears.push_back(aYears[i]);
273     }
274   }
275 }
276
277
278 void SALOMEDS_AttributeStudyProperties::SetComment(const std::string& theComment)
279 {
280   if (_isLocal) {
281     CheckLocked();
282     SALOMEDS::Locker lock;
283     SALOMEDSImpl_AttributeStudyProperties* anImpl =
284       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
285     anImpl->SetComment(theComment);
286   } else
287     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetComment(theComment.c_str());
288 }
289
290 std::string SALOMEDS_AttributeStudyProperties::GetComment()
291 {
292   std::string aComment;
293   if (_isLocal) {
294     SALOMEDS::Locker lock;
295     aComment = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetComment();
296   }
297   else 
298     aComment = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetComment();
299   return aComment;
300 }
301
302
303 void SALOMEDS_AttributeStudyProperties::SetUnits(const std::string& theUnits)
304 {
305   if (_isLocal) {
306     CheckLocked();
307     SALOMEDS::Locker lock;
308     SALOMEDSImpl_AttributeStudyProperties* anImpl =
309       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
310     anImpl->SetUnits(theUnits);
311   } else
312     ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetUnits(theUnits.c_str());
313 }
314
315 std::string SALOMEDS_AttributeStudyProperties::GetUnits()
316 {
317   std::string anUnits;
318   if (_isLocal) {
319     SALOMEDS::Locker lock;
320     anUnits = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetUnits();
321   }
322   else 
323     anUnits = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUnits();
324   return anUnits;
325 }
326
327 std::vector<std::string> SALOMEDS_AttributeStudyProperties::GetStoredComponents()
328 {
329   std::vector<std::string> aComponents;
330   if (_isLocal) {
331     SALOMEDS::Locker lock;
332     aComponents = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetStoredComponents();
333   }
334   else {
335     SALOMEDS::StringSeq_var components = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetStoredComponents();
336     int length = components->length();
337     for (int i = 0; i < length; i++) {
338       aComponents.push_back(components[i].in());
339     }
340   }
341   return aComponents;
342 }
343
344 std::string SALOMEDS_AttributeStudyProperties::GetComponentVersion( const std::string& theComponent )
345 {
346   std::string aVersion;
347   if (_isLocal) {
348     SALOMEDS::Locker lock;
349     aVersion = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetComponentVersion(theComponent);
350   }
351   else 
352     aVersion = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetComponentVersion(theComponent.c_str());
353   return aVersion;
354 }
355
356 std::vector<std::string> SALOMEDS_AttributeStudyProperties::GetComponentVersions( const std::string& theComponent )
357 {
358   std::vector<std::string> aVersions;
359   if (_isLocal) {
360     SALOMEDS::Locker lock;
361     aVersions = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetComponentVersions(theComponent);
362   }
363   else {
364     SALOMEDS::StringSeq_var versions = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetComponentVersions(theComponent.c_str());
365     int length = versions->length();
366     for (int i = 0; i < length; i++) {
367       aVersions.push_back(versions[i].in());
368     }
369   }
370   return aVersions;
371 }