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