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