1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOMEDS_AttributeStudyProperties_i.cxx
8 // Author : Yves FRICAUD
12 #include <TColStd_HSequenceOfExtendedString.hxx>
13 #include <TColStd_HSequenceOfInteger.hxx>
14 #include <TCollection_ExtendedString.hxx>
15 #include <TCollection_AsciiString.hxx>
17 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
18 #include "SALOMEDS.hxx"
20 #define CREATION_MODE_NOTDEFINED 0
21 #define CREATION_MODE_SCRATCH 1
22 #define CREATION_MODE_COPY 2
26 void SALOMEDS_AttributeStudyProperties_i::SetUserName(const char* theName) {
27 SALOMEDS::Locker lock;
30 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
31 aProp->SetFirstName(const_cast<char*>(theName));
34 char* SALOMEDS_AttributeStudyProperties_i::GetUserName() {
35 SALOMEDS::Locker lock;
37 TCollection_ExtendedString S = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreatorName();
38 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(S).ToCString());
42 void SALOMEDS_AttributeStudyProperties_i::SetCreationDate(CORBA::Long theMinute,
46 CORBA::Long theYear) {
47 SALOMEDS::Locker lock;
50 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
52 if (aProp->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
53 aProp->SetModificationDate(theMinute, theHour, theDay, theMonth, theYear);
56 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::GetCreationDate(CORBA::Long& theMinute,
59 CORBA::Long& theMonth,
60 CORBA::Long& theYear) {
61 SALOMEDS::Locker lock;
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,
77 return Standard_False;
80 void SALOMEDS_AttributeStudyProperties_i::SetCreationMode(const char* theMode) {
81 SALOMEDS::Locker lock;
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);
90 char* SALOMEDS_AttributeStudyProperties_i::GetCreationMode() {
91 SALOMEDS::Locker lock;
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;
102 void SALOMEDS_AttributeStudyProperties_i::SetModified(CORBA::Long theModified) {
103 SALOMEDS::Locker lock;
105 Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetModified(theModified);
108 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsModified() {
109 SALOMEDS::Locker lock;
111 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsModified();
114 CORBA::Long SALOMEDS_AttributeStudyProperties_i::GetModified() {
115 SALOMEDS::Locker lock;
117 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetModified();
120 void SALOMEDS_AttributeStudyProperties_i::SetLocked(CORBA::Boolean theLocked) {
121 SALOMEDS::Locker lock;
123 Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetLocked(theLocked);
126 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsLocked() {
127 SALOMEDS::Locker lock;
129 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsLocked();
132 void SALOMEDS_AttributeStudyProperties_i::SetModification(const char* theName,
133 CORBA::Long theMinute,
136 CORBA::Long theMonth,
137 CORBA::Long theYear) {
138 SALOMEDS::Locker lock;
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);
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;
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);
175 for(a = 0; a < aLength; a++)
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));
186 char* SALOMEDS_AttributeStudyProperties_i::Store() {
187 SALOMEDS::Locker lock;
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);
195 int aLength, anIndex;
196 for(aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--) aLength += aNames->Value(anIndex).Length() + 1;
198 char* aProperty = new char[3 + aLength + 12 * aNames->Length()];
200 sprintf(aProperty,"%c%c", strlen(GetCreationMode())?GetCreationMode()[0]:'0', IsLocked()?'l':'u');
202 aLength = aNames->Length();
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);
219 void SALOMEDS_AttributeStudyProperties_i::Restore(const char* value) {
220 SALOMEDS::Locker lock;
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");
228 for(anIndex = 2; anIndex + 2 < strlen(value) ;) {
230 Standard_Integer aMinute, aHour, aDay, aMonth, aYear;
231 str[0] = aCopy[anIndex++];
232 str[1] = aCopy[anIndex++];
235 str[0] = aCopy[anIndex++];
236 str[1] = aCopy[anIndex++];
238 str[0] = aCopy[anIndex++];
239 str[1] = aCopy[anIndex++];
241 str[0] = aCopy[anIndex++];
242 str[1] = aCopy[anIndex++];
244 str[0] = aCopy[anIndex++];
245 str[1] = aCopy[anIndex++];
246 str[2] = aCopy[anIndex++];
247 str[3] = aCopy[anIndex++];
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);
258 anIndex += aNameSize + 1;
260 if (aCopy[1] == 'l') {
261 SetLocked(Standard_True);