Salome HOME
CCAR: remove duplicate variables (OMNIORB_IDL and IDL, OMNIORB_IDLCXXFLAGS and IDLCXX...
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeStudyProperties.cxx
1 //  Copyright (C) 2007-2008  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 //  File   : SALOMEDS_AttributeStudyProperties.cxx
23 //  Author : Sergey RUIN
24 //  Module : SALOME
25 //
26 #include "SALOMEDS_AttributeStudyProperties.hxx"
27 #include "SALOMEDS.hxx"
28
29 using namespace std;
30
31 SALOMEDS_AttributeStudyProperties::SALOMEDS_AttributeStudyProperties
32                                    (SALOMEDSImpl_AttributeStudyProperties* theAttr)
33 :SALOMEDS_GenericAttribute(theAttr)
34 {}
35
36 SALOMEDS_AttributeStudyProperties::SALOMEDS_AttributeStudyProperties
37                                    (SALOMEDS::AttributeStudyProperties_ptr theAttr)
38 :SALOMEDS_GenericAttribute(theAttr)
39 {}
40
41 SALOMEDS_AttributeStudyProperties::~SALOMEDS_AttributeStudyProperties()
42 {
43 }
44
45 void SALOMEDS_AttributeStudyProperties::SetUserName(const std::string& theName)
46 {
47   if (_isLocal) {
48     CheckLocked();
49     SALOMEDS::Locker lock;
50     SALOMEDSImpl_AttributeStudyProperties* anImpl =
51       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
52     anImpl->ChangeCreatorName(theName);
53   } else
54     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetUserName(theName.c_str());
55 }
56
57 std::string SALOMEDS_AttributeStudyProperties::GetUserName()
58 {
59   std::string aName;
60   if (_isLocal) {
61     SALOMEDS::Locker lock;
62     aName = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetCreatorName();
63   }
64 #ifndef WIN32
65   else aName = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetUserName();
66 #else
67   else aName = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetUserNameA();
68 #endif
69   return aName;
70 }
71
72 void SALOMEDS_AttributeStudyProperties::SetCreationDate
73               (int theMinute, int theHour, int theDay, int theMonth, int theYear)
74 {
75   if (_isLocal) {
76     CheckLocked();
77     SALOMEDS::Locker lock;
78     SALOMEDSImpl_AttributeStudyProperties* anImpl =
79       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
80     int aTmp;
81     if (anImpl->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
82     string S;
83     anImpl->SetModification(S, theMinute, theHour, theDay, theMonth, theYear);
84   } else {
85     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetCreationDate(theMinute,
86                                                                               theHour,
87                                                                               theDay,
88                                                                               theMonth,
89                                                                               theYear);
90   }
91 }
92
93 bool SALOMEDS_AttributeStudyProperties::GetCreationDate(int& theMinute,
94                                                         int& theHour,
95                                                         int& theDay,
96                                                         int& theMonth,
97                                                         int& theYear)
98 {
99   bool ret;
100   if (_isLocal) {
101     SALOMEDS::Locker lock;
102     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>
103       (_local_impl)->GetCreationDate(theMinute, theHour, theDay, theMonth, theYear);
104   } else {
105     CORBA::Long aMinute, anHour, aDay, aMonth, anYear;
106     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetCreationDate(aMinute,
107                                                                                     anHour,
108                                                                                     aDay,
109                                                                                     aMonth,
110                                                                                     anYear);
111     theMinute = (int)aMinute;
112     theHour = (int)anHour;
113     theDay = (int)aDay;
114     theMonth = (int)aMonth;
115     theYear = (int)anYear;
116   }
117   return ret;
118 }
119
120 void SALOMEDS_AttributeStudyProperties::SetCreationMode(const std::string& theMode)
121 {
122   if (_isLocal) {
123     CheckLocked();
124     SALOMEDS::Locker lock;
125     if (theMode == "from scratch")
126       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(1);
127     else if (theMode == "copy from")
128       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(2);
129     else //Not defined
130       dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetCreationMode(0);
131   }
132   else SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetCreationMode(theMode.c_str());
133 }
134
135 std::string SALOMEDS_AttributeStudyProperties::GetCreationMode()
136 {
137   std::string aMode;
138   if (_isLocal) {
139     SALOMEDS::Locker lock;
140     int mode  = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetCreationMode();
141     if (mode == 1) aMode = "from scratch";
142     if (mode == 2) aMode = "copy from";
143   }
144   else
145     aMode = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetCreationMode();
146   return aMode;
147 }
148
149 void SALOMEDS_AttributeStudyProperties::SetModified(int theModified)
150 {
151   if (_isLocal) {
152     SALOMEDS::Locker lock;
153     dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetModified(theModified);
154   }
155   else
156     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetModified(theModified);
157 }
158
159 bool SALOMEDS_AttributeStudyProperties::IsModified()
160 {
161   bool ret;
162   if (_isLocal) {
163     SALOMEDS::Locker lock;
164     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->IsModified();
165   }
166   else
167     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->IsModified();
168   return ret;
169 }
170
171 int SALOMEDS_AttributeStudyProperties::GetModified()
172 {
173   int isModified;
174   if (_isLocal) {
175     SALOMEDS::Locker lock;
176     isModified = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->GetModified();
177   }
178   else
179     isModified = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetModified();
180   return isModified;
181 }
182
183 void SALOMEDS_AttributeStudyProperties::SetLocked(bool theLocked)
184 {
185   if (_isLocal) {
186     SALOMEDS::Locker lock;
187     dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->SetLocked(theLocked);
188   }
189   else
190     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetLocked(theLocked);
191 }
192
193 bool SALOMEDS_AttributeStudyProperties::IsLocked()
194 {
195   bool ret;
196   if (_isLocal) {
197     SALOMEDS::Locker lock;
198     ret = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl)->IsLocked();
199   }
200   else
201     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->IsLocked();
202   return ret;
203 }
204
205 void SALOMEDS_AttributeStudyProperties::SetModification(const std::string& theName,
206                                                         int theMinute,
207                                                         int theHour,
208                                                         int theDay,
209                                                         int theMonth,
210                                                         int theYear)
211 {
212   if (_isLocal) {
213     CheckLocked();
214     SALOMEDS::Locker lock;
215     SALOMEDSImpl_AttributeStudyProperties* anImpl = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
216     anImpl->SetModification(theName, theMinute, theHour, theDay, theMonth, theYear);
217   } else
218     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetModification(theName.c_str(),
219                                                                               theMinute,
220                                                                               theHour,
221                                                                               theDay,
222                                                                               theMonth,
223                                                                               theYear);
224 }
225
226 void SALOMEDS_AttributeStudyProperties::GetModificationsList(std::vector<std::string>& theNames,
227                                                              std::vector<int>& theMinutes,
228                                                              std::vector<int>& theHours,
229                                                              std::vector<int>& theDays,
230                                                              std::vector<int>& theMonths,
231                                                              std::vector<int>& theYears,
232                                                              bool theWithCreator)
233 {
234   int i, aLength;
235
236   if (_isLocal) {
237     SALOMEDS::Locker lock;
238     vector<string> aNames;
239     vector<int> aMinutes, aHours, aDays, aMonths, aYears;
240     SALOMEDSImpl_AttributeStudyProperties* anImpl = dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(_local_impl);
241     anImpl->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
242     aLength = aNames.size();
243     i = ((theWithCreator) ? 1 : 2);
244     for (; i <= aLength; i++) {
245       theNames.push_back(aNames[i-1]);
246       theMinutes.push_back(aMinutes[i-1]);
247       theHours.push_back(aHours[i-1]);
248       theDays.push_back(aDays[i-1]);
249       theMonths.push_back(aMonths[i-1]);
250       theYears.push_back(aYears[i-1]);
251     }
252   } else {
253     SALOMEDS::StringSeq_var aNames;
254     SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears;
255     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetModificationsList(aNames.out(),
256                                                                                    aMinutes.out(),
257                                                                                    aHours.out(),
258                                                                                    aDays.out(),
259                                                                                    aMonths.out(),
260                                                                                    aYears.out(),
261                                                                                    theWithCreator);
262     aLength = aNames->length();
263     for (i = 0; i<aLength; i++) {
264       theNames.push_back(aNames[i].in());
265       theMinutes.push_back(aMinutes[i]);
266       theHours.push_back(aHours[i]);
267       theDays.push_back(aDays[i]);
268       theMonths.push_back(aMonths[i]);
269       theYears.push_back(aYears[i]);
270     }
271   }
272 }