Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeStudyProperties.cxx
1 //  File   : SALOMEDS_AttributeStudyProperties.cxx
2 //  Author : Sergey RUIN
3 //  Module : SALOME
4
5 #include "SALOMEDS_AttributeStudyProperties.hxx"
6
7 #include <string>
8 #include <TCollection_AsciiString.hxx>
9 #include <TCollection_ExtendedString.hxx>
10 #include <TColStd_HSequenceOfExtendedString.hxx>
11 #include <TColStd_HSequenceOfInteger.hxx>
12
13 SALOMEDS_AttributeStudyProperties::SALOMEDS_AttributeStudyProperties
14                                    (const Handle(SALOMEDSImpl_AttributeStudyProperties)& theAttr)
15 :SALOMEDS_GenericAttribute(theAttr)
16 {}
17
18 SALOMEDS_AttributeStudyProperties::SALOMEDS_AttributeStudyProperties
19                                    (SALOMEDS::AttributeStudyProperties_ptr theAttr)
20 :SALOMEDS_GenericAttribute(theAttr)
21 {}
22
23 SALOMEDS_AttributeStudyProperties::~SALOMEDS_AttributeStudyProperties()
24 {
25 }
26
27 void SALOMEDS_AttributeStudyProperties::SetUserName(const std::string& theName)
28 {
29   if (_isLocal) {
30     Handle(SALOMEDSImpl_AttributeStudyProperties) anImpl =
31       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl);
32     anImpl->ChangeCreatorName((char*)theName.c_str());
33   } else
34     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetUserName(theName.c_str());
35 }
36
37 std::string SALOMEDS_AttributeStudyProperties::GetUserName()
38 {
39   std::string aName;
40   if (_isLocal) {
41     TCollection_ExtendedString S =
42       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->GetCreatorName();
43     aName = TCollection_AsciiString(S).ToCString();
44   }
45 #ifndef WNT
46   else aName = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetUserName();
47 #else
48   else aName = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetUserNameA();
49 #endif
50   return aName;
51 }
52
53 void SALOMEDS_AttributeStudyProperties::SetCreationDate
54               (int theMinute, int theHour, int theDay, int theMonth, int theYear)
55 {
56   if (_isLocal) {
57     Handle(SALOMEDSImpl_AttributeStudyProperties) anImpl =
58       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl);
59     int aTmp;
60     if (anImpl->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
61     TCollection_ExtendedString S;
62     anImpl->SetModification(S, theMinute, theHour, theDay, theMonth, theYear);
63   } else {
64     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetCreationDate(theMinute,
65                                                                               theHour,
66                                                                               theDay,
67                                                                               theMonth,
68                                                                               theYear);
69   }
70 }
71
72 bool SALOMEDS_AttributeStudyProperties::GetCreationDate(int& theMinute,
73                                                         int& theHour,
74                                                         int& theDay,
75                                                         int& theMonth,
76                                                         int& theYear)
77 {
78   bool ret;
79   if (_isLocal) {
80     ret = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast
81       (_local_impl)->GetCreationDate(theMinute, theHour, theDay, theMonth, theYear);
82   } else {
83     CORBA::Long aMinute, anHour, aDay, aMonth, anYear;
84     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetCreationDate(aMinute,
85                                                                                     anHour,
86                                                                                     aDay,
87                                                                                     aMonth,
88                                                                                     anYear);
89     theMinute = (int)aMinute;
90     theHour = (int)anHour;
91     theDay = (int)aDay;
92     theMonth = (int)aMonth;
93     theYear = (int)anYear;
94   }
95   return ret;
96 }
97
98 void SALOMEDS_AttributeStudyProperties::SetCreationMode(const std::string& theMode)
99 {
100   if (_isLocal) {
101     if (theMode == "from scratch")
102       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetCreationMode(1);
103     else if (theMode == "copy from")
104       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetCreationMode(2);
105     else //Not defined
106       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetCreationMode(0);
107   }
108   else SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetCreationMode(theMode.c_str());
109 }
110
111 std::string SALOMEDS_AttributeStudyProperties::GetCreationMode()
112 {
113   std::string aMode;
114   if (_isLocal) {
115     int mode  = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->GetCreationMode();
116     if (mode == 1) aMode = "from scratch";
117     if (mode == 2) aMode = "copy from";
118   }
119   else
120     aMode = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetCreationMode();
121   return aMode;
122 }
123
124 void SALOMEDS_AttributeStudyProperties::SetModified(int theModified)
125 {
126   if (_isLocal)
127     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetModified(theModified);
128   else
129     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetModified(theModified);
130 }
131
132 bool SALOMEDS_AttributeStudyProperties::IsModified()
133 {
134   bool ret;
135   if (_isLocal)
136     ret = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->IsModified();
137   else
138     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->IsModified();
139   return ret;
140 }
141
142 int SALOMEDS_AttributeStudyProperties::GetModified()
143 {
144   int isModified;
145   if (_isLocal)
146     isModified = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->GetModified();
147   else
148     isModified = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetModified();
149   return isModified;
150 }
151
152 void SALOMEDS_AttributeStudyProperties::SetLocked(bool theLocked)
153 {
154   if (_isLocal)
155     Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->SetLocked(theLocked);
156   else
157     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetLocked(theLocked);
158 }
159
160 bool SALOMEDS_AttributeStudyProperties::IsLocked()
161 {
162   bool ret;
163   if (_isLocal)
164     ret = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl)->IsLocked();
165   else
166     ret = SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->IsLocked();
167   return ret;
168 }
169
170 void SALOMEDS_AttributeStudyProperties::SetModification(const std::string& theName,
171                                                         int theMinute,
172                                                         int theHour,
173                                                         int theDay,
174                                                         int theMonth,
175                                                         int theYear)
176 {
177   if (_isLocal) {
178     Handle(SALOMEDSImpl_AttributeStudyProperties) anImpl =
179       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl);
180     anImpl->SetModification((char*)theName.c_str(), theMinute, theHour, theDay, theMonth, theYear);
181   } else
182     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->SetModification(theName.c_str(),
183                                                                               theMinute,
184                                                                               theHour,
185                                                                               theDay,
186                                                                               theMonth,
187                                                                               theYear);
188 }
189
190 void SALOMEDS_AttributeStudyProperties::GetModificationsList(std::vector<std::string>& theNames,
191                                                              std::vector<int>& theMinutes,
192                                                              std::vector<int>& theHours,
193                                                              std::vector<int>& theDays,
194                                                              std::vector<int>& theMonths,
195                                                              std::vector<int>& theYears,
196                                                              bool theWithCreator)
197 {
198   int i, aLength;
199
200   if (_isLocal) {
201     Handle(TColStd_HSequenceOfExtendedString) aNames;
202     Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
203     Handle(SALOMEDSImpl_AttributeStudyProperties) anImpl =
204       Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(_local_impl);
205     anImpl->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
206     aLength = aNames->Length();
207     i = ((theWithCreator) ? 1 : 2);
208     for (; i <= aLength; i++) {
209       theNames.push_back(TCollection_AsciiString(aNames->Value(i)).ToCString());
210       theMinutes.push_back(aMinutes->Value(i));
211       theHours.push_back(aHours->Value(i));
212       theDays.push_back(aDays->Value(i));
213       theMonths.push_back(aMonths->Value(i));
214       theYears.push_back(aYears->Value(i));
215     }
216   } else {
217     SALOMEDS::StringSeq_var aNames;
218     SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears;
219     SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl)->GetModificationsList(aNames.out(),
220                                                                                    aMinutes.out(),
221                                                                                    aHours.out(),
222                                                                                    aDays.out(),
223                                                                                    aMonths.out(),
224                                                                                    aYears.out(),
225                                                                                    theWithCreator);
226     aLength = aNames->length();
227     for (i = 0; i<aLength; i++) {
228       theNames.push_back(aNames[i].in());
229       theMinutes.push_back(aMinutes[i]);
230       theHours.push_back(aHours[i]);
231       theDays.push_back(aDays[i]);
232       theMonths.push_back(aMonths[i]);
233       theYears.push_back(aYears[i]);
234     }
235   }
236 }