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
13 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
14 #include "SALOMEDS_SObject_i.hxx"
15 #include <TColStd_HSequenceOfExtendedString.hxx>
16 #include <TColStd_HSequenceOfInteger.hxx>
18 #define CREATION_MODE_NOTDEFINED 0
19 #define CREATION_MODE_SCRATCH 1
20 #define CREATION_MODE_COPY 2
22 void SALOMEDS_AttributeStudyProperties_i::SetUserName(const char* theName) {
24 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
25 aProp->SetFirstName(TCollection_ExtendedString(strdup(theName)));
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());
34 void SALOMEDS_AttributeStudyProperties_i::SetCreationDate(CORBA::Long theMinute,
38 CORBA::Long theYear) {
40 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
42 if (aProp->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
43 aProp->SetModificationDate(theMinute, theHour, theDay, theMonth, theYear);
46 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::GetCreationDate(CORBA::Long& theMinute,
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,
65 return Standard_False;
68 void SALOMEDS_AttributeStudyProperties_i::SetCreationMode(const char* theMode) {
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);
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;
86 void SALOMEDS_AttributeStudyProperties_i::SetModified(CORBA::Long theModified) {
87 Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetModified(theModified);
90 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsModified() {
91 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsModified();
94 CORBA::Long SALOMEDS_AttributeStudyProperties_i::GetModified() {
95 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetModified();
98 void SALOMEDS_AttributeStudyProperties_i::SetLocked(CORBA::Boolean theLocked) {
99 Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetLocked(theLocked);
102 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsLocked() {
103 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsLocked();
106 void SALOMEDS_AttributeStudyProperties_i::SetModification(const char* theName,
107 CORBA::Long theMinute,
110 CORBA::Long theMonth,
111 CORBA::Long theYear) {
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);
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);
145 for(a = 0; a < aLength; a++)
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));
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);
163 int aLength, anIndex;
164 for(aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--) aLength += aNames->Value(anIndex).Length() + 1;
166 char* aProperty = new char[3 + aLength + 12 * aNames->Length()];
168 sprintf(aProperty,"%c%c", strlen(GetCreationMode())?GetCreationMode()[0]:'0', IsLocked()?'l':'u');
170 aLength = aNames->Length();
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);
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");
194 for(anIndex = 2; anIndex + 2 < strlen(value) ;) {
196 Standard_Integer aMinute, aHour, aDay, aMonth, aYear;
197 str[0] = aCopy[anIndex++];
198 str[1] = aCopy[anIndex++];
201 str[0] = aCopy[anIndex++];
202 str[1] = aCopy[anIndex++];
204 str[0] = aCopy[anIndex++];
205 str[1] = aCopy[anIndex++];
207 str[0] = aCopy[anIndex++];
208 str[1] = aCopy[anIndex++];
210 str[0] = aCopy[anIndex++];
211 str[1] = aCopy[anIndex++];
212 str[2] = aCopy[anIndex++];
213 str[3] = aCopy[anIndex++];
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);
224 anIndex += aNameSize + 1;
226 if (aCopy[1] == 'l') {
227 SetLocked(Standard_True);