Back to index

salome-kernel  6.5.0
SALOMEDSImpl_AttributeStudyProperties.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : SALOMEDSImpl_AttributeStudyProperties.cxx
00024 //  Author : Sergey RUIN
00025 //  Module : SALOME
00026 //
00027 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
00028 #include <string.h>
00029 
00030 const std::string& SALOMEDSImpl_AttributeStudyProperties::GetID()
00031 {
00032   static std::string SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
00033   return SALOMEDSImpl_AttributeStudyPropertiesID;
00034 }
00035 
00036 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_AttributeStudyProperties::Set(const DF_Label& label)
00037 {
00038   SALOMEDSImpl_AttributeStudyProperties* A = NULL;
00039   if (!(A=(SALOMEDSImpl_AttributeStudyProperties*)label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID()))) {
00040     A = new SALOMEDSImpl_AttributeStudyProperties();
00041     label.AddAttribute(A);
00042   }
00043   return A;
00044 }
00045 
00046 SALOMEDSImpl_AttributeStudyProperties::SALOMEDSImpl_AttributeStudyProperties()
00047 :SALOMEDSImpl_GenericAttribute("AttributeStudyProperties")
00048 {
00049   myLocked = false;
00050   myLockChanged = false;
00051   Init();
00052 }
00053 
00054 void SALOMEDSImpl_AttributeStudyProperties::Init()
00055 {
00056   myUserName.clear();
00057   myMinute.clear();
00058   myHour.clear();
00059   myDay.clear();
00060   myMonth.clear();
00061   myYear.clear();
00062   myMode = 0; // none
00063 }
00064 
00065 void SALOMEDSImpl_AttributeStudyProperties::SetModification(const std::string& theUserName,
00066                                                             const int            theMinute,
00067                                                             const int            theHour,
00068                                                             const int            theDay,
00069                                                             const int            theMonth,
00070                                                             const int            theYear)
00071 {
00072   if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 ||
00073       theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
00074     return;
00075 
00076   CheckLocked();
00077   Backup();
00078 
00079   myUserName.push_back(theUserName);
00080   myMinute.push_back(theMinute);
00081   myHour.push_back(theHour);
00082   myDay.push_back(theDay);
00083   myMonth.push_back(theMonth);
00084   myYear.push_back(theYear);
00085 }
00086 
00087 void SALOMEDSImpl_AttributeStudyProperties::GetModifications
00088                   (std::vector<std::string>& theUserNames,
00089                    std::vector<int>&    theMinutes,
00090                    std::vector<int>&    theHours,
00091                    std::vector<int>&    theDays,
00092                    std::vector<int>&    theMonths,
00093                    std::vector<int>&    theYears) const
00094 {
00095   theUserNames = myUserName;
00096   theMinutes = myMinute;
00097   theHours = myHour;
00098   theDays = myDay;
00099   theMonths = myMonth;
00100   theYears = myYear;
00101 }
00102 
00103 std::string SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
00104 {
00105   if (myUserName.size() == 0)
00106     return std::string("");
00107   return myUserName[0];
00108 }
00109 
00110 bool SALOMEDSImpl_AttributeStudyProperties::GetCreationDate
00111                               (int&           theMinute,
00112                                int&           theHour,
00113                                int&           theDay,
00114                                int&           theMonth,
00115                                int&           theYear) const
00116 {
00117   if (myMinute.size() != 0) {
00118     theMinute = myMinute[0];
00119     theHour = myHour[0];
00120     theDay = myDay[0];
00121     theMonth = myMonth[0];
00122     theYear = myYear[0];
00123     return true;
00124   }
00125   return false;
00126 }
00127 
00128 void SALOMEDSImpl_AttributeStudyProperties::ChangeCreatorName(const std::string& theName)
00129 {
00130   if (myUserName.size() > 0) {
00131     CheckLocked();
00132     Backup();
00133     myUserName[0] = theName;
00134   }
00135 }
00136 
00137 void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const int theMode)
00138 {
00139   CheckLocked();
00140   Backup();
00141   myMode = theMode;
00142 }
00143 
00144 int SALOMEDSImpl_AttributeStudyProperties::GetCreationMode() const
00145 {
00146   return myMode;
00147 }
00148 
00149 void SALOMEDSImpl_AttributeStudyProperties::SetModified(const int theModified)
00150 {
00151   myModified = theModified;
00152 }
00153 
00154 bool SALOMEDSImpl_AttributeStudyProperties::IsModified() const
00155 {
00156   return (myModified != 0);
00157 }
00158 
00159 int SALOMEDSImpl_AttributeStudyProperties::GetModified() const
00160 {
00161   return myModified;
00162 }
00163 
00164 void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const bool theLocked)
00165 {
00166 //  Backup();
00167   if (myLocked != theLocked) {
00168     myLockChanged = true;
00169     myLocked = theLocked;
00170   }
00171 }
00172 
00173 bool SALOMEDSImpl_AttributeStudyProperties::IsLocked() const
00174 {
00175   return myLocked;
00176 }
00177 
00178 bool SALOMEDSImpl_AttributeStudyProperties::IsLockChanged(const bool theErase) {
00179   if (!myLockChanged) return false;
00180   if (theErase) myLockChanged = false;
00181   return true;
00182 }
00183 
00184 const std::string& SALOMEDSImpl_AttributeStudyProperties::ID() const
00185 {
00186   return GetID();
00187 }
00188 
00189 void SALOMEDSImpl_AttributeStudyProperties::Restore(DF_Attribute* with)
00190 {
00191   SALOMEDSImpl_AttributeStudyProperties* aProp =
00192     dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(with);
00193 
00194   Init();
00195   std::vector<std::string> aNames;
00196   std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
00197   aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
00198   for (int i = 0, len = aNames.size(); i < len; i++) {
00199     myUserName.push_back(aNames[i]);
00200     myMinute.push_back(aMinutes[i]);
00201     myHour.push_back(aHours[i]);
00202     myDay.push_back(aDays[i]);
00203     myMonth.push_back(aMonths[i]);
00204     myYear.push_back(aYears[i]);
00205   }
00206   myMode = aProp->GetCreationMode();
00207 //  myModified = aProp->GetModified();
00208 //  myLocked = aProp->IsLocked();
00209 }
00210 
00211 DF_Attribute* SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const
00212 {
00213   return new SALOMEDSImpl_AttributeStudyProperties();
00214 }
00215 
00216 void SALOMEDSImpl_AttributeStudyProperties::Paste(DF_Attribute* into)
00217 {
00218   SALOMEDSImpl_AttributeStudyProperties* aProp =
00219     dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(into);
00220   aProp->Init();
00221 
00222   int i;
00223   for(i = 0; i < myUserName.size(); i++) {
00224     aProp->SetModification(myUserName[i],
00225                            myMinute[i], myHour[i],
00226                            myDay[i], myMonth[i], myYear[i]);
00227   }
00228 
00229   aProp->SetCreationMode(myMode);
00230 //  aProp->SetModified(myModified);
00231 //  aProp->SetLocked(myLocked);
00232 }
00233 
00234 
00235 std::string SALOMEDSImpl_AttributeStudyProperties::Save()
00236 {
00237   std::vector<std::string> aNames;
00238   std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
00239   GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
00240 
00241   int aLength, anIndex, unitsSize = 0, commentSize = 0;;
00242   for (aLength = 0, anIndex = aNames.size()-1; anIndex >= 0; anIndex--)
00243     aLength += aNames[anIndex].size() + 1;
00244 
00245   std::string units = GetUnits();
00246   std::string comment = GetComment();
00247   
00248   unitsSize = units.size();
00249   commentSize = comment.size();
00250 
00251   char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize];
00252 
00253   char crMode = (char)GetCreationMode();
00254 
00255   sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u');
00256 
00257   aLength = aNames.size();
00258   int a = 2;
00259   for (anIndex = 0; anIndex  < aLength; anIndex++) {
00260     sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
00261             (int)(aMinutes[anIndex]),
00262             (int)(aHours[anIndex]),
00263             (int)(aDays[anIndex]),
00264             (int)(aMonths[anIndex]),
00265             (int)(aYears[anIndex]),
00266             (char*)(aNames[anIndex].c_str()));
00267     a = strlen(aProperty);
00268     aProperty[a++] = 1;
00269   }
00270 
00271   //Write delimeter of the section to define end of the modifications section
00272   aProperty[a++] = 30;
00273 
00274   //Write units if need
00275   if(units.size() > 0) {
00276     sprintf(&(aProperty[a]),"%s",units.c_str());
00277     a = strlen(aProperty);
00278   }
00279 
00280   aProperty[a++] = 1; //delimeter of the units and comments
00281 
00282   //Write comments if need
00283   if(comment.size() > 0) {
00284     sprintf(&(aProperty[a]),"%s",comment.c_str());
00285     a = strlen(aProperty);
00286     a++;
00287   }
00288   
00289   aProperty[a] = 0;
00290   std::string prop(aProperty);
00291   delete aProperty;
00292 
00293   return prop;
00294 }
00295 
00296 void SALOMEDSImpl_AttributeStudyProperties::SetUnits(const std::string& theUnits) {
00297   if(myUnits == theUnits)
00298     return;
00299   myUnits = theUnits;
00300 }
00301 
00302 std::string SALOMEDSImpl_AttributeStudyProperties::GetUnits() {
00303   return myUnits;
00304 }
00305 
00306 void SALOMEDSImpl_AttributeStudyProperties::SetComment(const std::string& theComment) {
00307   if(myComment == theComment)
00308     return;
00309   myComment = theComment;
00310 }
00311 
00312 std::string SALOMEDSImpl_AttributeStudyProperties::GetComment() {
00313   return myComment;
00314 }
00315 
00316 
00317 void SALOMEDSImpl_AttributeStudyProperties::Load(const std::string& value)
00318 {
00319   char* aCopy = (char*)value.c_str();
00320 
00321   int crMode = (int)aCopy[0];
00322   SetCreationMode(crMode);
00323 
00324   int anIndex;
00325   for (anIndex = 2; anIndex + 2 < value.size() ;) {
00326     char str[10];
00327     int aMinute, aHour, aDay, aMonth, aYear;
00328     str[0] = aCopy[anIndex++];
00329     str[1] = aCopy[anIndex++];
00330     str[2] = 0;
00331     aMinute = atoi(str);
00332     str[0] = aCopy[anIndex++];
00333     str[1] = aCopy[anIndex++];
00334     aHour =  atoi(str);
00335     str[0] = aCopy[anIndex++];
00336     str[1] = aCopy[anIndex++];
00337     aDay =  atoi(str);
00338     str[0] = aCopy[anIndex++];
00339     str[1] = aCopy[anIndex++];
00340     aMonth =  atoi(str);
00341     str[0] = aCopy[anIndex++];
00342     str[1] = aCopy[anIndex++];
00343     str[2] = aCopy[anIndex++];
00344     str[3] = aCopy[anIndex++];
00345     str[4] = 0;
00346     aYear = atoi(str);
00347 
00348     int aNameSize;
00349     for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
00350     char *aName = new char[aNameSize+1];
00351     strncpy(aName, &(aCopy[anIndex]), aNameSize);
00352     aName[aNameSize] = 0;
00353     SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
00354     delete [] (aName);
00355     anIndex += aNameSize + 1;
00356     
00357     //Check end of the modifications section
00358     if(anIndex < value.size() && aCopy[anIndex] == 30)
00359       break;
00360   }
00361   
00362   //Case then study contains units and comment properties
00363   if( anIndex < value.size() ) {
00364     anIndex++; //skip the delimeter of the sections: char(30)
00365     int unitsSize;
00366     for(unitsSize = 0; aCopy[anIndex+unitsSize] != 1; unitsSize++);
00367 
00368     if(unitsSize > 0) {
00369       char *anUnits = new char[unitsSize+1];
00370       strncpy(anUnits, &(aCopy[anIndex]), unitsSize);
00371       anUnits[unitsSize] = 0;
00372       SetUnits(anUnits);
00373       delete [] (anUnits);
00374     }
00375     anIndex += unitsSize + 1;
00376 
00377     int commentSize;
00378     for(commentSize = 0; aCopy[anIndex+commentSize] != 0; commentSize++);
00379 
00380     if(commentSize > 0) {
00381       char *aComment = new char[commentSize+1];
00382       strncpy(aComment, &(aCopy[anIndex]), commentSize);
00383       aComment[commentSize] = 0;
00384       SetComment(aComment);
00385       delete [] (aComment);
00386     }
00387     anIndex += commentSize;
00388   }
00389   
00390   if (aCopy[1] == 'l') {
00391     SetLocked(true);
00392   }
00393   SetModified(0);  
00394 }