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