]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.cxx
Salome HOME
Merge from branch CCRT_Port_V220.
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeStudyProperties_i.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SALOMEDS_AttributeStudyProperties_i.cxx
8 //  Author : Yves FRICAUD
9 //  Module : SALOME
10 //  $Header$
11
12 #include <TColStd_HSequenceOfExtendedString.hxx>
13 #include <TColStd_HSequenceOfInteger.hxx>
14 #include <TCollection_ExtendedString.hxx>
15 #include <TCollection_AsciiString.hxx>
16
17 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
18 #include "SALOMEDS.hxx"
19
20 #define CREATION_MODE_NOTDEFINED 0
21 #define CREATION_MODE_SCRATCH 1
22 #define CREATION_MODE_COPY 2
23
24 using namespace std;
25
26 void SALOMEDS_AttributeStudyProperties_i::SetUserName(const char* theName) {
27   SALOMEDS::Locker lock;
28
29   CheckLocked();
30   Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
31   aProp->SetFirstName(const_cast<char*>(theName));
32 }
33
34 char* SALOMEDS_AttributeStudyProperties_i::GetUserName() {
35   SALOMEDS::Locker lock;
36
37   TCollection_ExtendedString S = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreatorName();
38   CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(S).ToCString());
39   return c_s._retn();
40 }
41
42 void SALOMEDS_AttributeStudyProperties_i::SetCreationDate(CORBA::Long theMinute,
43                                                           CORBA::Long theHour,
44                                                           CORBA::Long theDay,
45                                                           CORBA::Long theMonth,
46                                                           CORBA::Long theYear) {
47   SALOMEDS::Locker lock;
48
49   CheckLocked();
50   Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
51   int aTmp;
52   if (aProp->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
53   aProp->SetModificationDate(theMinute, theHour, theDay, theMonth, theYear);
54 }
55
56 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::GetCreationDate(CORBA::Long& theMinute,
57                                                                     CORBA::Long& theHour,
58                                                                     CORBA::Long& theDay,
59                                                                     CORBA::Long& theMonth,
60                                                                     CORBA::Long& theYear) {
61   SALOMEDS::Locker lock;
62
63   Standard_Integer aMinute;
64   Standard_Integer aHour;
65   Standard_Integer aDay;
66   Standard_Integer aMonth;
67   Standard_Integer aYear;
68   if (Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreationDate(aMinute, aHour, aDay,
69                                                                                     aMonth, aYear)) {
70     theMinute = aMinute;
71     theHour = aHour;
72     theDay = aDay;
73     theMonth = aMonth;
74     theYear = aYear;
75     return Standard_True;
76   }
77   return Standard_False;
78 }
79
80 void SALOMEDS_AttributeStudyProperties_i::SetCreationMode(const char* theMode) {
81   SALOMEDS::Locker lock;
82
83   CheckLocked();
84   Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
85   if (strcmp(theMode,"from scratch")==0) aProp->SetCreationMode(CREATION_MODE_SCRATCH);
86   else if (strcmp(theMode,"copy from")==0) aProp->SetCreationMode(CREATION_MODE_COPY);
87   else aProp->SetCreationMode(CREATION_MODE_NOTDEFINED);
88 }
89
90 char* SALOMEDS_AttributeStudyProperties_i::GetCreationMode() {
91   SALOMEDS::Locker lock;
92
93   CORBA::String_var c_s;
94   switch (Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreationMode()) {
95   case CREATION_MODE_SCRATCH: c_s = "from scratch"; break;
96   case CREATION_MODE_COPY: c_s = "copy from"; break;
97   default: c_s = "";
98   }
99   return c_s._retn();
100 }
101
102 void SALOMEDS_AttributeStudyProperties_i::SetModified(CORBA::Long theModified) {
103   SALOMEDS::Locker lock;
104
105   Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetModified(theModified);
106 }
107
108 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsModified() {
109   SALOMEDS::Locker lock;
110
111   return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsModified();
112 }
113
114 CORBA::Long SALOMEDS_AttributeStudyProperties_i::GetModified() {
115   SALOMEDS::Locker lock;
116
117   return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetModified();
118 }
119
120 void SALOMEDS_AttributeStudyProperties_i::SetLocked(CORBA::Boolean theLocked) {
121   SALOMEDS::Locker lock;
122
123   Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetLocked(theLocked);
124 }
125
126 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsLocked() {
127   SALOMEDS::Locker lock;
128
129   return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsLocked();
130 }
131
132 void SALOMEDS_AttributeStudyProperties_i::SetModification(const char* theName,
133                                                           CORBA::Long theMinute,
134                                                           CORBA::Long theHour,
135                                                           CORBA::Long theDay,
136                                                           CORBA::Long theMonth,
137                                                           CORBA::Long theYear) {
138   SALOMEDS::Locker lock;
139
140   CheckLocked();
141   Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
142   aProp->SetUserName(const_cast<char*>(theName));
143   aProp->SetModificationDate((int)theMinute, (int)theHour, (int)theDay, (int)theMonth, (int)theYear);
144 }
145 void SALOMEDS_AttributeStudyProperties_i::GetModificationsList(SALOMEDS::StringSeq_out theNames,
146                                                                SALOMEDS::LongSeq_out theMinutes,
147                                                                SALOMEDS::LongSeq_out theHours,
148                                                                SALOMEDS::LongSeq_out theDays,
149                                                                SALOMEDS::LongSeq_out theMonths,
150                                                                SALOMEDS::LongSeq_out theYears,
151                                                                CORBA::Boolean theWithCreator) {
152   SALOMEDS::Locker lock;
153
154   Handle(TColStd_HSequenceOfExtendedString) aNames;
155   Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
156   Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
157   aNames = aProp->GetUserNames();
158   aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
159   int aLength = aNames->Length()-((theWithCreator)?0:1);
160   theNames = new SALOMEDS::StringSeq;
161 //   SALOMEDS::LongSeq *maminute = new SALOMEDS::LongSeq;
162 //   maminute->length(5);
163   theMinutes = new SALOMEDS::LongSeq;
164   theHours = new SALOMEDS::LongSeq;
165   theDays = new SALOMEDS::LongSeq;
166   theMonths = new SALOMEDS::LongSeq;
167   theYears = new SALOMEDS::LongSeq;
168   theNames->length(aLength);
169   theMinutes->length(aLength);
170   theHours->length(aLength);
171   theDays->length(aLength);
172   theMonths->length(aLength);
173   theYears->length(aLength);
174   int a;
175   for(a = 0; a < aLength; a++) 
176     {
177       (*theNames)[a] = CORBA::string_dup(TCollection_AsciiString(aNames->Value(a + 1 + ((theWithCreator)?0:1))).ToCString());
178       (*theMinutes)[a] = aMinutes->Value(a + 1 + ((theWithCreator)?0:1));
179       (*theHours)[a] = aHours->Value(a + 1 + ((theWithCreator)?0:1));
180       (*theDays)[a] = aDays->Value(a + 1 + ((theWithCreator)?0:1));
181       (*theMonths)[a] = aMonths->Value(a + 1 + ((theWithCreator)?0:1));
182       (*theYears)[a] = aYears->Value(a + 1 + ((theWithCreator)?0:1));
183     }
184 }
185
186 char* SALOMEDS_AttributeStudyProperties_i::Store() {
187   SALOMEDS::Locker lock;
188
189   Handle(TColStd_HSequenceOfExtendedString) aNames;
190   Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
191   Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
192   aNames = aProp->GetUserNames();
193   aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
194
195   int aLength, anIndex;
196   for(aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--) aLength += aNames->Value(anIndex).Length() + 1;
197
198   char* aProperty = new char[3 + aLength + 12 * aNames->Length()];
199
200   sprintf(aProperty,"%c%c", strlen(GetCreationMode())?GetCreationMode()[0]:'0', IsLocked()?'l':'u');
201
202   aLength = aNames->Length();
203   int a = 2;
204   for(anIndex = 1; anIndex  <= aLength; anIndex++) {
205     sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
206             (int)(aMinutes->Value(anIndex)),
207             (int)(aHours->Value(anIndex)),
208             (int)(aDays->Value(anIndex)),
209             (int)(aMonths->Value(anIndex)),
210             (int)(aYears->Value(anIndex)),
211             (char*)(TCollection_AsciiString(aNames->Value(anIndex)).ToCString()));
212     a = strlen(aProperty);
213     aProperty[a++] = 1;
214   }
215   aProperty[a] = 0;
216   return aProperty;
217 }
218
219 void SALOMEDS_AttributeStudyProperties_i::Restore(const char* value) {
220   SALOMEDS::Locker lock;
221
222   char* aCopy = strdup(value);
223   if (aCopy[0] == 'f') SetCreationMode("from scratch");
224   else if (aCopy[0] == 'c') SetCreationMode("copy from");
225   else SetCreationMode("none");
226
227   int anIndex;
228   for(anIndex = 2; anIndex + 2 < strlen(value) ;) {
229     char str[10];
230     Standard_Integer aMinute, aHour, aDay, aMonth, aYear;
231     str[0] = aCopy[anIndex++];
232     str[1] = aCopy[anIndex++];
233     str[2] = 0;
234     aMinute = atoi(str);
235     str[0] = aCopy[anIndex++];
236     str[1] = aCopy[anIndex++];
237     aHour =  atoi(str);
238     str[0] = aCopy[anIndex++];
239     str[1] = aCopy[anIndex++];
240     aDay =  atoi(str);
241     str[0] = aCopy[anIndex++];
242     str[1] = aCopy[anIndex++];
243     aMonth =  atoi(str);
244     str[0] = aCopy[anIndex++];
245     str[1] = aCopy[anIndex++];
246     str[2] = aCopy[anIndex++];
247     str[3] = aCopy[anIndex++];
248     str[4] = 0;
249     aYear = atoi(str);
250     
251     int aNameSize;
252     for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
253     char *aName = new char[aNameSize+1];
254     strncpy(aName, &(aCopy[anIndex]), aNameSize);
255     aName[aNameSize] = 0;
256     SetModification(aName, aMinute,aHour,aDay,aMonth,aYear);
257     delete(aName);
258     anIndex += aNameSize + 1;
259   }
260   if (aCopy[1] == 'l') {
261     SetLocked(Standard_True);
262   }
263   SetModified(0);
264   free(aCopy);
265 }