1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSImpl_AttributeStudyProperties.cxx
21 // Author : Sergey RUIN
24 #include <SALOMEDSImpl_AttributeStudyProperties.hxx>
25 #include <Standard_GUID.hxx>
26 #include <TCollection_ExtendedString.hxx>
30 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute )
31 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute )
33 const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::GetID()
35 static Standard_GUID SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
36 return SALOMEDSImpl_AttributeStudyPropertiesID;
39 Handle(SALOMEDSImpl_AttributeStudyProperties) SALOMEDSImpl_AttributeStudyProperties::Set(const TDF_Label& label)
41 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
42 if (!label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(),anAttr)) {
43 anAttr = new SALOMEDSImpl_AttributeStudyProperties();
44 label.AddAttribute(anAttr);
49 SALOMEDSImpl_AttributeStudyProperties::SALOMEDSImpl_AttributeStudyProperties()
50 :SALOMEDSImpl_GenericAttribute("AttributeStudyProperties")
52 myLocked = Standard_False;
53 myLockChanged = Standard_False;
57 void SALOMEDSImpl_AttributeStudyProperties::Init()
59 myUserName = new TColStd_HSequenceOfExtendedString();
60 myMinute = new TColStd_HSequenceOfInteger();
61 myHour = new TColStd_HSequenceOfInteger();
62 myDay = new TColStd_HSequenceOfInteger();
63 myMonth = new TColStd_HSequenceOfInteger();
64 myYear = new TColStd_HSequenceOfInteger();
69 void SALOMEDSImpl_AttributeStudyProperties::SetModification(const TCollection_ExtendedString& theUserName,
70 const Standard_Integer theMinute,
71 const Standard_Integer theHour,
72 const Standard_Integer theDay,
73 const Standard_Integer theMonth,
74 const Standard_Integer theYear)
76 if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 ||
77 theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
83 myUserName->Append(theUserName);
84 myMinute->Append(theMinute);
85 myHour->Append(theHour);
86 myDay->Append(theDay);
87 myMonth->Append(theMonth);
88 myYear->Append(theYear);
91 void SALOMEDSImpl_AttributeStudyProperties::GetModifications
92 (Handle(TColStd_HSequenceOfExtendedString)& theUserNames,
93 Handle(TColStd_HSequenceOfInteger)& theMinutes,
94 Handle(TColStd_HSequenceOfInteger)& theHours,
95 Handle(TColStd_HSequenceOfInteger)& theDays,
96 Handle(TColStd_HSequenceOfInteger)& theMonths,
97 Handle(TColStd_HSequenceOfInteger)& theYears) const
99 theUserNames = myUserName;
100 theMinutes = myMinute;
107 TCollection_ExtendedString SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
109 if (myUserName->Length() == 0)
110 return TCollection_ExtendedString("");
111 return myUserName->Value(1);
114 Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::GetCreationDate
115 (Standard_Integer& theMinute,
116 Standard_Integer& theHour,
117 Standard_Integer& theDay,
118 Standard_Integer& theMonth,
119 Standard_Integer& theYear) const
121 if (myMinute->Length() != 0) {
122 theMinute = myMinute->Value(1);
123 theHour = myHour->Value(1);
124 theDay = myDay->Value(1);
125 theMonth = myMonth->Value(1);
126 theYear = myYear->Value(1);
127 return Standard_True;
129 return Standard_False;
132 void SALOMEDSImpl_AttributeStudyProperties::ChangeCreatorName(const TCollection_ExtendedString& theName)
134 if (myUserName->Length() > 0) {
137 myUserName->SetValue(1, theName);
141 void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const Standard_Integer theMode)
148 Standard_Integer SALOMEDSImpl_AttributeStudyProperties::GetCreationMode() const
153 void SALOMEDSImpl_AttributeStudyProperties::SetModified(const Standard_Integer theModified)
155 myModified = theModified;
158 Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsModified() const
160 return (myModified != 0);
163 Standard_Integer SALOMEDSImpl_AttributeStudyProperties::GetModified() const
168 void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const Standard_Boolean theLocked)
171 if (myLocked != theLocked) {
172 myLockChanged = Standard_True;
173 myLocked = theLocked;
177 Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsLocked() const
182 Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsLockChanged(const Standard_Boolean theErase) {
183 if (!myLockChanged) return Standard_False;
184 if (theErase) myLockChanged = Standard_False;
185 return Standard_True;
188 const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::ID() const
193 void SALOMEDSImpl_AttributeStudyProperties::Restore(const Handle(TDF_Attribute)& with)
195 Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
196 Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(with);
199 Handle(TColStd_HSequenceOfExtendedString) aNames;
200 Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
201 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
202 for (i = aNames->Length(); i > 0; i--) {
203 myUserName->Prepend(aNames->Value(i));
204 myMinute->Prepend(aMinutes->Value(i));
205 myHour->Prepend(aHours->Value(i));
206 myDay->Prepend(aDays->Value(i));
207 myMonth->Prepend(aMonths->Value(i));
208 myYear->Prepend(aYears->Value(i));
210 myMode = aProp->GetCreationMode();
211 // myModified = aProp->GetModified();
212 // myLocked = aProp->IsLocked();
215 Handle(TDF_Attribute) SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const
217 return new SALOMEDSImpl_AttributeStudyProperties();
220 void SALOMEDSImpl_AttributeStudyProperties::Paste(const Handle(TDF_Attribute)& into,
221 const Handle(TDF_RelocationTable)&) const
223 Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
224 Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(into);
228 for(i = 1; i <= myUserName->Length(); i++) {
229 aProp->SetModification(myUserName->Value(i),
230 myMinute->Value(i), myHour->Value(i),
231 myDay->Value(i), myMonth->Value(i), myYear->Value(i));
234 aProp->SetCreationMode(myMode);
235 // aProp->SetModified(myModified);
236 // aProp->SetLocked(myLocked);
240 TCollection_AsciiString SALOMEDSImpl_AttributeStudyProperties::Save()
242 Handle(TColStd_HSequenceOfExtendedString) aNames;
243 Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
244 GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
246 int aLength, anIndex;
247 for (aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--)
248 aLength += aNames->Value(anIndex).Length() + 1;
250 char* aProperty = new char[3 + aLength + 12 * aNames->Length()];
252 char crMode = (char)GetCreationMode();
254 sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u');
256 aLength = aNames->Length();
258 for (anIndex = 1; anIndex <= aLength; anIndex++) {
259 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
260 (int)(aMinutes->Value(anIndex)),
261 (int)(aHours->Value(anIndex)),
262 (int)(aDays->Value(anIndex)),
263 (int)(aMonths->Value(anIndex)),
264 (int)(aYears->Value(anIndex)),
265 (char*)(TCollection_AsciiString(aNames->Value(anIndex)).ToCString()));
266 a = strlen(aProperty);
270 TCollection_AsciiString prop(aProperty);
276 void SALOMEDSImpl_AttributeStudyProperties::Load(const TCollection_AsciiString& value)
278 char* aCopy = value.ToCString();
280 int crMode = (int)aCopy[0];
281 SetCreationMode(crMode);
284 for (anIndex = 2; anIndex + 2 < value.Length() ;) {
286 Standard_Integer aMinute, aHour, aDay, aMonth, aYear;
287 str[0] = aCopy[anIndex++];
288 str[1] = aCopy[anIndex++];
291 str[0] = aCopy[anIndex++];
292 str[1] = aCopy[anIndex++];
294 str[0] = aCopy[anIndex++];
295 str[1] = aCopy[anIndex++];
297 str[0] = aCopy[anIndex++];
298 str[1] = aCopy[anIndex++];
300 str[0] = aCopy[anIndex++];
301 str[1] = aCopy[anIndex++];
302 str[2] = aCopy[anIndex++];
303 str[3] = aCopy[anIndex++];
308 for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
309 char *aName = new char[aNameSize+1];
310 strncpy(aName, &(aCopy[anIndex]), aNameSize);
311 aName[aNameSize] = 0;
312 SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
314 anIndex += aNameSize + 1;
316 if (aCopy[1] == 'l') {
317 SetLocked(Standard_True);