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>
29 const std::string& SALOMEDSImpl_AttributeStudyProperties::GetID()
31 static std::string SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
32 return SALOMEDSImpl_AttributeStudyPropertiesID;
35 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_AttributeStudyProperties::Set(const DF_Label& label)
37 SALOMEDSImpl_AttributeStudyProperties* A = NULL;
38 if (!(A=(SALOMEDSImpl_AttributeStudyProperties*)label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID()))) {
39 A = new SALOMEDSImpl_AttributeStudyProperties();
40 label.AddAttribute(A);
45 SALOMEDSImpl_AttributeStudyProperties::SALOMEDSImpl_AttributeStudyProperties()
46 :SALOMEDSImpl_GenericAttribute("AttributeStudyProperties")
49 myLockChanged = false;
53 void SALOMEDSImpl_AttributeStudyProperties::Init()
64 void SALOMEDSImpl_AttributeStudyProperties::SetModification(const std::string& theUserName,
71 if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 ||
72 theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
78 myUserName.push_back(theUserName);
79 myMinute.push_back(theMinute);
80 myHour.push_back(theHour);
81 myDay.push_back(theDay);
82 myMonth.push_back(theMonth);
83 myYear.push_back(theYear);
86 void SALOMEDSImpl_AttributeStudyProperties::GetModifications
87 (vector<string>& theUserNames,
88 vector<int>& theMinutes,
89 vector<int>& theHours,
91 vector<int>& theMonths,
92 vector<int>& theYears) const
94 theUserNames = myUserName;
95 theMinutes = myMinute;
102 std::string SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
104 if (myUserName.size() == 0)
105 return std::string("");
106 return myUserName[0];
109 bool SALOMEDSImpl_AttributeStudyProperties::GetCreationDate
116 if (myMinute.size() != 0) {
117 theMinute = myMinute[0];
120 theMonth = myMonth[0];
127 void SALOMEDSImpl_AttributeStudyProperties::ChangeCreatorName(const std::string& theName)
129 if (myUserName.size() > 0) {
132 myUserName[0] = theName;
136 void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const int theMode)
143 int SALOMEDSImpl_AttributeStudyProperties::GetCreationMode() const
148 void SALOMEDSImpl_AttributeStudyProperties::SetModified(const int theModified)
150 myModified = theModified;
153 bool SALOMEDSImpl_AttributeStudyProperties::IsModified() const
155 return (myModified != 0);
158 int SALOMEDSImpl_AttributeStudyProperties::GetModified() const
163 void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const bool theLocked)
166 if (myLocked != theLocked) {
167 myLockChanged = true;
168 myLocked = theLocked;
172 bool SALOMEDSImpl_AttributeStudyProperties::IsLocked() const
177 bool SALOMEDSImpl_AttributeStudyProperties::IsLockChanged(const bool theErase) {
178 if (!myLockChanged) return false;
179 if (theErase) myLockChanged = false;
183 const std::string& SALOMEDSImpl_AttributeStudyProperties::ID() const
188 void SALOMEDSImpl_AttributeStudyProperties::Restore(DF_Attribute* with)
190 SALOMEDSImpl_AttributeStudyProperties* aProp =
191 dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(with);
194 vector<string> aNames;
195 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
196 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
197 for (int i = 0, len = aNames.size(); i < len; i++) {
198 myUserName.push_back(aNames[i]);
199 myMinute.push_back(aMinutes[i]);
200 myHour.push_back(aHours[i]);
201 myDay.push_back(aDays[i]);
202 myMonth.push_back(aMonths[i]);
203 myYear.push_back(aYears[i]);
205 myMode = aProp->GetCreationMode();
206 // myModified = aProp->GetModified();
207 // myLocked = aProp->IsLocked();
210 DF_Attribute* SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const
212 return new SALOMEDSImpl_AttributeStudyProperties();
215 void SALOMEDSImpl_AttributeStudyProperties::Paste(DF_Attribute* into)
217 SALOMEDSImpl_AttributeStudyProperties* aProp =
218 dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(into);
222 for(i = 0; i < myUserName.size(); i++) {
223 aProp->SetModification(myUserName[i],
224 myMinute[i], myHour[i],
225 myDay[i], myMonth[i], myYear[i]);
228 aProp->SetCreationMode(myMode);
229 // aProp->SetModified(myModified);
230 // aProp->SetLocked(myLocked);
234 string SALOMEDSImpl_AttributeStudyProperties::Save()
236 vector<string> aNames;
237 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
238 GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
240 int aLength, anIndex;
241 for (aLength = 0, anIndex = aNames.size()-1; anIndex >= 0; anIndex--)
242 aLength += aNames[anIndex].size() + 1;
244 char* aProperty = new char[3 + aLength + 12 * aNames.size()];
246 char crMode = (char)GetCreationMode();
248 sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u');
250 aLength = aNames.size();
252 for (anIndex = 0; anIndex < aLength; anIndex++) {
253 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
254 (int)(aMinutes[anIndex]),
255 (int)(aHours[anIndex]),
256 (int)(aDays[anIndex]),
257 (int)(aMonths[anIndex]),
258 (int)(aYears[anIndex]),
259 (char*)(aNames[anIndex].c_str()));
260 a = strlen(aProperty);
264 string prop(aProperty);
270 void SALOMEDSImpl_AttributeStudyProperties::Load(const string& value)
272 char* aCopy = (char*)value.c_str();
274 int crMode = (int)aCopy[0];
275 SetCreationMode(crMode);
278 for (anIndex = 2; anIndex + 2 < value.size() ;) {
280 int aMinute, aHour, aDay, aMonth, aYear;
281 str[0] = aCopy[anIndex++];
282 str[1] = aCopy[anIndex++];
285 str[0] = aCopy[anIndex++];
286 str[1] = aCopy[anIndex++];
288 str[0] = aCopy[anIndex++];
289 str[1] = aCopy[anIndex++];
291 str[0] = aCopy[anIndex++];
292 str[1] = aCopy[anIndex++];
294 str[0] = aCopy[anIndex++];
295 str[1] = aCopy[anIndex++];
296 str[2] = aCopy[anIndex++];
297 str[3] = aCopy[anIndex++];
302 for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
303 char *aName = new char[aNameSize+1];
304 strncpy(aName, &(aCopy[anIndex]), aNameSize);
305 aName[aNameSize] = 0;
306 SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
308 anIndex += aNameSize + 1;
310 if (aCopy[1] == 'l') {