Salome HOME
Copyrights update
[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/
19 //
20 //  File   : SALOMEDS_AttributeStudyProperties.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDS_AttributeStudyProperties.hxx"
25
26 #include <string>
27 #include <TCollection_AsciiString.hxx>
28 #include <TCollection_ExtendedString.hxx>
29 #include <TColStd_HSequenceOfExtendedString.hxx>
30 #include <TColStd_HSequenceOfInteger.hxx>
31
32 SALOMEDS_AttributeStudyProperties::SALOMEDS_AttributeStudyProperties
33                                    (const Handle(SALOMEDSImpl_AttributeStudyProperties)& theAttr)
34 :SALOMEDS_GenericAttribute(theAttr)
35 {}
36
37 SALOMEDS_AttributeStudyProperties::SALOMEDS_AttributeStudyProperties
38                                    (SALOMEDS::AttributeStudyProperties_ptr theAttr)
39 :SALOMEDS_GenericAttribute(theAttr)
40 {}
41
42 SALOMEDS_AttributeStudyProperties::~SALOMEDS_AttributeStudyProperties()
43 {
44 }
45
46 void SALOMEDS_AttributeStudyProperties::SetUserName(const std::string& theName)
47 {
48   if (_isLocal) {
49     Handle(SALOMEDSImpl_AttributeStudyProperties) anImpl =
50       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl);
51     anImpl->ChangeCreatorName((char*)theName.c_str());
52   } else
53     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     TCollection_ExtendedString S =
61       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->GetCreatorName();
62     aName = TCollection_AsciiString(S).ToCString();
63   }
64 #ifndef WNT
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     Handle(SALOMEDSImpl_AttributeStudyProperties) anImpl =
77       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl);
78     int aTmp;
79     if (anImpl->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
80     TCollection_ExtendedString 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     ret = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast
100       (_local_impl)->GetCreationDate(theMinute, theHour, theDay, theMonth, theYear);
101   } else {
102     CORBA::Long aMinute, anHour, aDay, aMonth, anYear;
103     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetCreationDate(aMinute,
104                                                                                     anHour,
105                                                                                     aDay,
106                                                                                     aMonth,
107                                                                                     anYear);
108     theMinute = (int)aMinute;
109     theHour = (int)anHour;
110     theDay = (int)aDay;
111     theMonth = (int)aMonth;
112     theYear = (int)anYear;
113   }
114   return ret;
115 }
116
117 void SALOMEDS_AttributeStudyProperties::SetCreationMode(const std::string& theMode)
118 {
119   if (_isLocal) {
120     if (theMode == "from scratch")
121       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetCreationMode(1);
122     else if (theMode == "copy from")
123       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetCreationMode(2);
124     else //Not defined
125       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetCreationMode(0);
126   }
127   else SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetCreationMode(theMode.c_str());
128 }
129
130 std::string SALOMEDS_AttributeStudyProperties::GetCreationMode()
131 {
132   std::string aMode;
133   if (_isLocal) {
134     int mode  = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->GetCreationMode();
135     if (mode == 1) aMode = "from scratch";
136     if (mode == 2) aMode = "copy from";
137   }
138   else
139     aMode = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetCreationMode();
140   return aMode;
141 }
142
143 void SALOMEDS_AttributeStudyProperties::SetModified(int theModified)
144 {
145   if (_isLocal)
146     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetModified(theModified);
147   else
148     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetModified(theModified);
149 }
150
151 bool SALOMEDS_AttributeStudyProperties::IsModified()
152 {
153   bool ret;
154   if (_isLocal)
155     ret = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->IsModified();
156   else
157     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->IsModified();
158   return ret;
159 }
160
161 int SALOMEDS_AttributeStudyProperties::GetModified()
162 {
163   int isModified;
164   if (_isLocal)
165     isModified = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->GetModified();
166   else
167     isModified = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetModified();
168   return isModified;
169 }
170
171 void SALOMEDS_AttributeStudyProperties::SetLocked(bool theLocked)
172 {
173   if (_isLocal)
174     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetLocked(theLocked);
175   else
176     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetLocked(theLocked);
177 }
178
179 bool SALOMEDS_AttributeStudyProperties::IsLocked()
180 {
181   bool ret;
182   if (_isLocal)
183     ret = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->IsLocked();
184   else
185     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->IsLocked();
186   return ret;
187 }
188
189 void SALOMEDS_AttributeStudyProperties::SetModification(const std::string& theName,
190                                                         int theMinute,
191                                                         int theHour,
192                                                         int theDay,
193                                                         int theMonth,
194                                                         int theYear)
195 {
196   if (_isLocal) {
197     Handle(SALOMEDSImpl_AttributeStudyProperties) anImpl =
198       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl);
199     anImpl->SetModification((char*)theName.c_str(), theMinute, theHour, theDay, theMonth, theYear);
200   } else
201     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetModification(theName.c_str(),
202                                                                               theMinute,
203                                                                               theHour,
204                                                                               theDay,
205                                                                               theMonth,
206                                                                               theYear);
207 }
208
209 void SALOMEDS_AttributeStudyProperties::GetModificationsList(std::vector<std::string>& theNames,
210                                                              std::vector<int>& theMinutes,
211                                                              std::vector<int>& theHours,
212                                                              std::vector<int>& theDays,
213                                                              std::vector<int>& theMonths,
214                                                              std::vector<int>& theYears,
215                                                              bool theWithCreator)
216 {
217   int i, aLength;
218
219   if (_isLocal) {
220     Handle(TColStd_HSequenceOfExtendedString) aNames;
221     Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
222     Handle(SALOMEDSImpl_AttributeStudyProperties) anImpl =
223       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl);
224     anImpl->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
225     aLength = aNames->Length();
226     i = ((theWithCreator) ? 1 : 2);
227     for (; i <= aLength; i++) {
228       theNames.push_back(TCollection_AsciiString(aNames->Value(i)).ToCString());
229       theMinutes.push_back(aMinutes->Value(i));
230       theHours.push_back(aHours->Value(i));
231       theDays.push_back(aDays->Value(i));
232       theMonths.push_back(aMonths->Value(i));
233       theYears.push_back(aYears->Value(i));
234     }
235   } else {
236     SALOMEDS::StringSeq_var aNames;
237     SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears;
238     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetModificationsList(aNames.out(),
239                                                                                    aMinutes.out(),
240                                                                                    aHours.out(),
241                                                                                    aDays.out(),
242                                                                                    aMonths.out(),
243                                                                                    aYears.out(),
244                                                                                    theWithCreator);
245     aLength = aNames->length();
246     for (i = 0; i<aLength; i++) {
247       theNames.push_back(aNames[i].in());
248       theMinutes.push_back(aMinutes[i]);
249       theHours.push_back(aHours[i]);
250       theDays.push_back(aDays[i]);
251       theMonths.push_back(aMonths[i]);
252       theYears.push_back(aYears[i]);
253     }
254   }
255 }