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