Salome HOME
Fix some problems with Study Properties
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeStudyProperties.cxx
index 3d7cc3d575b407582e87ed21aede9f1e7bf27ff9..3093a7ae787d7e5584becbb6f05ddd34fdd51d73 100644 (file)
@@ -11,13 +11,13 @@ using namespace std;
 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute )
 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute )
 
-const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::GetID() 
+const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::GetID()
 {
   static Standard_GUID SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
   return SALOMEDSImpl_AttributeStudyPropertiesID;
 }
 
-Handle(SALOMEDSImpl_AttributeStudyProperties) SALOMEDSImpl_AttributeStudyProperties::Set(const TDF_Label& label) 
+Handle(SALOMEDSImpl_AttributeStudyProperties) SALOMEDSImpl_AttributeStudyProperties::Set(const TDF_Label& label)
 {
   Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
   if (!label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(),anAttr)) {
@@ -47,54 +47,57 @@ void SALOMEDSImpl_AttributeStudyProperties::Init()
   myMode = 0; // none
 }
 
-void SALOMEDSImpl_AttributeStudyProperties::SetUserName(const TCollection_ExtendedString& theName) 
+void SALOMEDSImpl_AttributeStudyProperties::SetModification(const TCollection_ExtendedString& theUserName,
+                                                            const Standard_Integer            theMinute,
+                                                            const Standard_Integer            theHour,
+                                                            const Standard_Integer            theDay,
+                                                            const Standard_Integer            theMonth,
+                                                            const Standard_Integer            theYear)
 {
-  CheckLocked();  
-  Backup();
-  myUserName->Append(theName);
-}
+  if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 ||
+      theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
+    return;
 
-void SALOMEDSImpl_AttributeStudyProperties::SetFirstName(const TCollection_ExtendedString& theName)
-{
-  CheckLocked();  
+  CheckLocked();
   Backup();
-  if (myUserName->Length() == 0) myUserName->Append(theName);
-  else myUserName->SetValue(1, theName);
-}
 
-TCollection_ExtendedString SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
-{
-  if (myUserName->Length() == 0) return TCollection_ExtendedString("");
-  return myUserName->Value(1);
+  myUserName->Append(theUserName);
+  myMinute->Append(theMinute);
+  myHour->Append(theHour);
+  myDay->Append(theDay);
+  myMonth->Append(theMonth);
+  myYear->Append(theYear);
 }
 
-Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeStudyProperties::GetUserNames() const
+void SALOMEDSImpl_AttributeStudyProperties::GetModifications
+                  (Handle(TColStd_HSequenceOfExtendedString)& theUserNames,
+                   Handle(TColStd_HSequenceOfInteger)&        theMinutes,
+                   Handle(TColStd_HSequenceOfInteger)&        theHours,
+                   Handle(TColStd_HSequenceOfInteger)&        theDays,
+                   Handle(TColStd_HSequenceOfInteger)&        theMonths,
+                   Handle(TColStd_HSequenceOfInteger)&        theYears) const
 {
-  return myUserName;
+  theUserNames = myUserName;
+  theMinutes = myMinute;
+  theHours = myHour;
+  theDays = myDay;
+  theMonths = myMonth;
+  theYears = myYear;
 }
 
-void SALOMEDSImpl_AttributeStudyProperties::SetModificationDate(const Standard_Integer theMinute,
-                                                       const Standard_Integer theHour,
-                                                       const Standard_Integer theDay,
-                                                       const Standard_Integer theMonth,
-                                                       const Standard_Integer theYear) 
+TCollection_ExtendedString SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
 {
-  CheckLocked();  
-  Backup();
-  if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 || theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
-    return;
-  myMinute->Append(theMinute);
-  myHour->Append(theHour);
-  myDay->Append(theDay);
-  myMonth->Append(theMonth);
-  myYear->Append(theYear);
+  if (myUserName->Length() == 0)
+    return TCollection_ExtendedString("");
+  return myUserName->Value(1);
 }
 
-Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::GetCreationDate(Standard_Integer& theMinute,
-                                                                   Standard_Integer& theHour,
-                                                                   Standard_Integer& theDay,
-                                                                   Standard_Integer& theMonth,
-                                                                   Standard_Integer& theYear) const
+Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::GetCreationDate
+                              (Standard_Integer&           theMinute,
+                               Standard_Integer&           theHour,
+                               Standard_Integer&           theDay,
+                               Standard_Integer&           theMonth,
+                               Standard_Integer&           theYear) const
 {
   if (myMinute->Length() != 0) {
     theMinute = myMinute->Value(1);
@@ -107,22 +110,18 @@ Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::GetCreationDate(Standard
   return Standard_False;
 }
 
-void SALOMEDSImpl_AttributeStudyProperties::GetModificationDates(Handle(TColStd_HSequenceOfInteger)& theMinutes,
-                                                            Handle(TColStd_HSequenceOfInteger)& theHours,
-                                                            Handle(TColStd_HSequenceOfInteger)& theDays,
-                                                            Handle(TColStd_HSequenceOfInteger)& theMonths,
-                                                            Handle(TColStd_HSequenceOfInteger)& theYears) const
+void SALOMEDSImpl_AttributeStudyProperties::ChangeCreatorName(const TCollection_ExtendedString& theName)
 {
-  theMinutes = myMinute;
-  theHours = myHour;
-  theDays = myDay;
-  theMonths = myMonth;
-  theYears = myYear;
+  if (myUserName->Length() > 0) {
+    CheckLocked();
+    Backup();
+    myUserName->SetValue(1, theName);
+  }
 }
 
-void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const Standard_Integer theMode) 
+void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const Standard_Integer theMode)
 {
-  CheckLocked();  
+  CheckLocked();
   Backup();
   myMode = theMode;
 }
@@ -132,7 +131,7 @@ Standard_Integer SALOMEDSImpl_AttributeStudyProperties::GetCreationMode() const
   return myMode;
 }
 
-void SALOMEDSImpl_AttributeStudyProperties::SetModified(const Standard_Integer theModified) 
+void SALOMEDSImpl_AttributeStudyProperties::SetModified(const Standard_Integer theModified)
 {
   myModified = theModified;
 }
@@ -147,7 +146,7 @@ Standard_Integer SALOMEDSImpl_AttributeStudyProperties::GetModified() const
   return myModified;
 }
 
-void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const Standard_Boolean theLocked) 
+void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const Standard_Boolean theLocked)
 {
 //  Backup();
   if (myLocked != theLocked) {
@@ -172,18 +171,17 @@ const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::ID() const
   return GetID();
 }
 
-void SALOMEDSImpl_AttributeStudyProperties::Restore(const Handle(TDF_Attribute)& with) 
+void SALOMEDSImpl_AttributeStudyProperties::Restore(const Handle(TDF_Attribute)& with)
 {
-  Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(with);
+  Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
+    Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(with);
   Init();
   Standard_Integer i;
-  Handle(TColStd_HSequenceOfExtendedString) aNames = aProp->GetUserNames();
-  for(i = aNames->Length(); i > 0; i--) {
-    myUserName->Prepend(aNames->Value(i));
-  }
+  Handle(TColStd_HSequenceOfExtendedString) aNames;
   Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
-  aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
-  for(i = aMinutes->Length(); i > 0; i--) {
+  aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
+  for (i = aNames->Length(); i > 0; i--) {
+    myUserName->Prepend(aNames->Value(i));
     myMinute->Prepend(aMinutes->Value(i));
     myHour->Prepend(aHours->Value(i));
     myDay->Prepend(aDays->Value(i));
@@ -201,17 +199,17 @@ Handle(TDF_Attribute) SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const
 }
 
 void SALOMEDSImpl_AttributeStudyProperties::Paste(const Handle(TDF_Attribute)& into,
-                                             const Handle(TDF_RelocationTable)&) const
+                                                  const Handle(TDF_RelocationTable)&) const
 {
-  Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(into);
+  Handle(SALOMEDSImpl_AttributeStudyProperties) aProp =
+    Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(into);
   aProp->Init();
 
   Standard_Integer i;
   for(i = 1; i <= myUserName->Length(); i++) {
-    aProp->SetUserName(myUserName->Value(i));
-  }
-  for(i = 1; i <= myMinute->Length(); i++) {
-    aProp->SetModificationDate(myMinute->Value(i), myHour->Value(i), myDay->Value(i), myMonth->Value(i), myYear->Value(i));
+    aProp->SetModification(myUserName->Value(i),
+                           myMinute->Value(i), myHour->Value(i),
+                           myDay->Value(i), myMonth->Value(i), myYear->Value(i));
   }
 
   aProp->SetCreationMode(myMode);
@@ -220,15 +218,15 @@ void SALOMEDSImpl_AttributeStudyProperties::Paste(const Handle(TDF_Attribute)& i
 }
 
 
-TCollection_AsciiString SALOMEDSImpl_AttributeStudyProperties::Save() 
+TCollection_AsciiString SALOMEDSImpl_AttributeStudyProperties::Save()
 {
   Handle(TColStd_HSequenceOfExtendedString) aNames;
   Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears;
-  aNames = GetUserNames();
-  GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears);
+  GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
 
   int aLength, anIndex;
-  for(aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--) aLength += aNames->Value(anIndex).Length() + 1;
+  for (aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--)
+    aLength += aNames->Value(anIndex).Length() + 1;
 
   char* aProperty = new char[3 + aLength + 12 * aNames->Length()];
 
@@ -238,7 +236,7 @@ TCollection_AsciiString SALOMEDSImpl_AttributeStudyProperties::Save()
 
   aLength = aNames->Length();
   int a = 2;
-  for(anIndex = 1; anIndex  <= aLength; anIndex++) {
+  for (anIndex = 1; anIndex  <= aLength; anIndex++) {
     sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
            (int)(aMinutes->Value(anIndex)),
            (int)(aHours->Value(anIndex)),
@@ -250,13 +248,13 @@ TCollection_AsciiString SALOMEDSImpl_AttributeStudyProperties::Save()
     aProperty[a++] = 1;
   }
   aProperty[a] = 0;
-  TCollection_AsciiString prop(aProperty); 
+  TCollection_AsciiString prop(aProperty);
   delete aProperty;
 
   return prop;
 }
 
-void SALOMEDSImpl_AttributeStudyProperties::Load(const TCollection_AsciiString& value) 
+void SALOMEDSImpl_AttributeStudyProperties::Load(const TCollection_AsciiString& value)
 {
   char* aCopy = value.ToCString();
 
@@ -264,7 +262,7 @@ void SALOMEDSImpl_AttributeStudyProperties::Load(const TCollection_AsciiString&
   SetCreationMode(crMode);
 
   int anIndex;
-  for(anIndex = 2; anIndex + 2 < value.Length() ;) {
+  for (anIndex = 2; anIndex + 2 < value.Length() ;) {
     char str[10];
     Standard_Integer aMinute, aHour, aDay, aMonth, aYear;
     str[0] = aCopy[anIndex++];
@@ -286,14 +284,13 @@ void SALOMEDSImpl_AttributeStudyProperties::Load(const TCollection_AsciiString&
     str[3] = aCopy[anIndex++];
     str[4] = 0;
     aYear = atoi(str);
-    
+
     int aNameSize;
     for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
     char *aName = new char[aNameSize+1];
     strncpy(aName, &(aCopy[anIndex]), aNameSize);
     aName[aNameSize] = 0;
-    SetUserName(aName);
-    SetModificationDate(aMinute,aHour,aDay,aMonth,aYear);  
+    SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
     delete(aName);
     anIndex += aNameSize + 1;
   }
@@ -302,4 +299,3 @@ void SALOMEDSImpl_AttributeStudyProperties::Load(const TCollection_AsciiString&
   }
   SetModified(0);
 }
-