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"
19 #define CREATION_MODE_NOTDEFINED 0
20 #define CREATION_MODE_SCRATCH 1
21 #define CREATION_MODE_COPY 2
25 void SALOMEDS_AttributeStudyProperties_i::SetUserName(const char* theName) {
27 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
28 aProp->SetFirstName(const_cast<char*>(theName));
31 char* SALOMEDS_AttributeStudyProperties_i::GetUserName() {
32 TCollection_ExtendedString S = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreatorName();
33 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(S).ToCString());
37 void SALOMEDS_AttributeStudyProperties_i::SetCreationDate(CORBA::Long theMinute,
41 CORBA::Long theYear) {
43 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
45 if (aProp->GetCreationDate(aTmp, aTmp, aTmp, aTmp, aTmp)) return;
46 aProp->SetModificationDate(theMinute, theHour, theDay, theMonth, theYear);
49 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::GetCreationDate(CORBA::Long& theMinute,
52 CORBA::Long& theMonth,
53 CORBA::Long& theYear) {
54 Standard_Integer aMinute;
55 Standard_Integer aHour;
56 Standard_Integer aDay;
57 Standard_Integer aMonth;
58 Standard_Integer aYear;
59 if (Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreationDate(aMinute, aHour, aDay,
68 return Standard_False;
71 void SALOMEDS_AttributeStudyProperties_i::SetCreationMode(const char* theMode) {
73 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
74 if (strcmp(theMode,"from scratch")==0) aProp->SetCreationMode(CREATION_MODE_SCRATCH);
75 else if (strcmp(theMode,"copy from")==0) aProp->SetCreationMode(CREATION_MODE_COPY);
76 else aProp->SetCreationMode(CREATION_MODE_NOTDEFINED);
79 char* SALOMEDS_AttributeStudyProperties_i::GetCreationMode() {
80 CORBA::String_var c_s;
81 switch (Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetCreationMode()) {
82 case CREATION_MODE_SCRATCH: c_s = "from scratch"; break;
83 case CREATION_MODE_COPY: c_s = "copy from"; break;
89 void SALOMEDS_AttributeStudyProperties_i::SetModified(CORBA::Long theModified) {
90 Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetModified(theModified);
93 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsModified() {
94 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsModified();
97 CORBA::Long SALOMEDS_AttributeStudyProperties_i::GetModified() {
98 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->GetModified();
101 void SALOMEDS_AttributeStudyProperties_i::SetLocked(CORBA::Boolean theLocked) {
102 Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->SetLocked(theLocked);
105 CORBA::Boolean SALOMEDS_AttributeStudyProperties_i::IsLocked() {
106 return Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr)->IsLocked();
109 void SALOMEDS_AttributeStudyProperties_i::SetModification(const char* theName,
110 CORBA::Long theMinute,
113 CORBA::Long theMonth,
114 CORBA::Long theYear) {
116 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
117 aProp->SetUserName(const_cast<char*>(theName));
118 aProp->SetModificationDate((int)theMinute, (int)theHour, (int)theDay, (int)theMonth, (int)theYear);
120 void SALOMEDS_AttributeStudyProperties_i::GetModificationsList(SALOMEDS::StringSeq_out theNames,
121 SALOMEDS::LongSeq_out theMinutes,
122 SALOMEDS::LongSeq_out theHours,
123 SALOMEDS::LongSeq_out theDays,
124 SALOMEDS::LongSeq_out theMonths,
125 SALOMEDS::LongSeq_out theYears,
126 CORBA::Boolean theWithCreator) {
127 Handle(TColStd_HSequenceOfExtendedString) aNames;
128 Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
129 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
130 aNames = aProp->GetUserNames();
131 aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
132 int aLength = aNames->Length()-((theWithCreator)?0:1);
133 theNames = new SALOMEDS::StringSeq;
134 // SALOMEDS::LongSeq *maminute = new SALOMEDS::LongSeq;
135 // maminute->length(5);
136 theMinutes = new SALOMEDS::LongSeq;
137 theHours = new SALOMEDS::LongSeq;
138 theDays = new SALOMEDS::LongSeq;
139 theMonths = new SALOMEDS::LongSeq;
140 theYears = new SALOMEDS::LongSeq;
141 theNames->length(aLength);
142 theMinutes->length(aLength);
143 theHours->length(aLength);
144 theDays->length(aLength);
145 theMonths->length(aLength);
146 theYears->length(aLength);
148 for(a = 0; a < aLength; a++)
150 (*theNames)[a] = CORBA::string_dup(TCollection_AsciiString(aNames->Value(a + 1 + ((theWithCreator)?0:1))).ToCString());
151 (*theMinutes)[a] = aMinutes->Value(a + 1 + ((theWithCreator)?0:1));
152 (*theHours)[a] = aHours->Value(a + 1 + ((theWithCreator)?0:1));
153 (*theDays)[a] = aDays->Value(a + 1 + ((theWithCreator)?0:1));
154 (*theMonths)[a] = aMonths->Value(a + 1 + ((theWithCreator)?0:1));
155 (*theYears)[a] = aYears->Value(a + 1 + ((theWithCreator)?0:1));
159 char* SALOMEDS_AttributeStudyProperties_i::Store() {
160 Handle(TColStd_HSequenceOfExtendedString) aNames;
161 Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
162 Handle(SALOMEDS_StudyPropertiesAttribute) aProp = Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(_myAttr);
163 aNames = aProp->GetUserNames();
164 aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
166 int aLength, anIndex;
167 for(aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--) aLength += aNames->Value(anIndex).Length() + 1;
169 char* aProperty = new char[3 + aLength + 12 * aNames->Length()];
171 sprintf(aProperty,"%c%c", strlen(GetCreationMode())?GetCreationMode()[0]:'0', IsLocked()?'l':'u');
173 aLength = aNames->Length();
175 for(anIndex = 1; anIndex <= aLength; anIndex++) {
176 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
177 (int)(aMinutes->Value(anIndex)),
178 (int)(aHours->Value(anIndex)),
179 (int)(aDays->Value(anIndex)),
180 (int)(aMonths->Value(anIndex)),
181 (int)(aYears->Value(anIndex)),
182 (char*)(TCollection_AsciiString(aNames->Value(anIndex)).ToCString()));
183 a = strlen(aProperty);
190 void SALOMEDS_AttributeStudyProperties_i::Restore(const char* value) {
191 char* aCopy = strdup(value);
192 if (aCopy[0] == 'f') SetCreationMode("from scratch");
193 else if (aCopy[0] == 'c') SetCreationMode("copy from");
194 else SetCreationMode("none");
197 for(anIndex = 2; anIndex + 2 < strlen(value) ;) {
199 Standard_Integer aMinute, aHour, aDay, aMonth, aYear;
200 str[0] = aCopy[anIndex++];
201 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++];
213 str[0] = aCopy[anIndex++];
214 str[1] = aCopy[anIndex++];
215 str[2] = aCopy[anIndex++];
216 str[3] = aCopy[anIndex++];
221 for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
222 char *aName = new char[aNameSize+1];
223 strncpy(aName, &(aCopy[anIndex]), aNameSize);
224 aName[aNameSize] = 0;
225 SetModification(aName, aMinute,aHour,aDay,aMonth,aYear);
227 anIndex += aNameSize + 1;
229 if (aCopy[1] == 'l') {
230 SetLocked(Standard_True);