1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOMEDSImpl_AttributeStudyProperties.cxx
23 // Author : Sergey RUIN
26 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
32 const std::string& SALOMEDSImpl_AttributeStudyProperties::GetID()
34 static std::string SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
35 return SALOMEDSImpl_AttributeStudyPropertiesID;
38 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_AttributeStudyProperties::Set(const DF_Label& label)
40 SALOMEDSImpl_AttributeStudyProperties* A = NULL;
41 if (!(A=(SALOMEDSImpl_AttributeStudyProperties*)label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID()))) {
42 A = new SALOMEDSImpl_AttributeStudyProperties();
43 label.AddAttribute(A);
48 SALOMEDSImpl_AttributeStudyProperties::SALOMEDSImpl_AttributeStudyProperties()
49 :SALOMEDSImpl_GenericAttribute("AttributeStudyProperties")
52 myLockChanged = false;
56 void SALOMEDSImpl_AttributeStudyProperties::Init()
67 void SALOMEDSImpl_AttributeStudyProperties::SetModification(const std::string& theUserName,
74 if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 ||
75 theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
81 myUserName.push_back(theUserName);
82 myMinute.push_back(theMinute);
83 myHour.push_back(theHour);
84 myDay.push_back(theDay);
85 myMonth.push_back(theMonth);
86 myYear.push_back(theYear);
89 void SALOMEDSImpl_AttributeStudyProperties::GetModifications
90 (vector<string>& theUserNames,
91 vector<int>& theMinutes,
92 vector<int>& theHours,
94 vector<int>& theMonths,
95 vector<int>& theYears) const
97 theUserNames = myUserName;
98 theMinutes = myMinute;
105 std::string SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
107 if (myUserName.size() == 0)
108 return std::string("");
109 return myUserName[0];
112 bool SALOMEDSImpl_AttributeStudyProperties::GetCreationDate
119 if (myMinute.size() != 0) {
120 theMinute = myMinute[0];
123 theMonth = myMonth[0];
130 void SALOMEDSImpl_AttributeStudyProperties::ChangeCreatorName(const std::string& theName)
132 if (myUserName.size() > 0) {
135 myUserName[0] = theName;
139 void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const int theMode)
146 int SALOMEDSImpl_AttributeStudyProperties::GetCreationMode() const
151 void SALOMEDSImpl_AttributeStudyProperties::SetModified(const int theModified)
153 myModified = theModified;
156 bool SALOMEDSImpl_AttributeStudyProperties::IsModified() const
158 return (myModified != 0);
161 int SALOMEDSImpl_AttributeStudyProperties::GetModified() const
166 void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const bool theLocked)
169 if (myLocked != theLocked) {
170 myLockChanged = true;
171 myLocked = theLocked;
175 bool SALOMEDSImpl_AttributeStudyProperties::IsLocked() const
180 bool SALOMEDSImpl_AttributeStudyProperties::IsLockChanged(const bool theErase) {
181 if (!myLockChanged) return false;
182 if (theErase) myLockChanged = false;
186 const std::string& SALOMEDSImpl_AttributeStudyProperties::ID() const
191 void SALOMEDSImpl_AttributeStudyProperties::Restore(DF_Attribute* with)
193 SALOMEDSImpl_AttributeStudyProperties* aProp =
194 dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(with);
197 vector<string> aNames;
198 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
199 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
200 for (int i = 0, len = aNames.size(); i < len; i++) {
201 myUserName.push_back(aNames[i]);
202 myMinute.push_back(aMinutes[i]);
203 myHour.push_back(aHours[i]);
204 myDay.push_back(aDays[i]);
205 myMonth.push_back(aMonths[i]);
206 myYear.push_back(aYears[i]);
208 myMode = aProp->GetCreationMode();
209 // myModified = aProp->GetModified();
210 // myLocked = aProp->IsLocked();
213 DF_Attribute* SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const
215 return new SALOMEDSImpl_AttributeStudyProperties();
218 void SALOMEDSImpl_AttributeStudyProperties::Paste(DF_Attribute* into)
220 SALOMEDSImpl_AttributeStudyProperties* aProp =
221 dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(into);
225 for(i = 0; i < myUserName.size(); i++) {
226 aProp->SetModification(myUserName[i],
227 myMinute[i], myHour[i],
228 myDay[i], myMonth[i], myYear[i]);
231 aProp->SetCreationMode(myMode);
232 // aProp->SetModified(myModified);
233 // aProp->SetLocked(myLocked);
237 string SALOMEDSImpl_AttributeStudyProperties::Save()
239 vector<string> aNames;
240 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
241 GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
243 int aLength, anIndex;
244 for (aLength = 0, anIndex = aNames.size()-1; anIndex >= 0; anIndex--)
245 aLength += aNames[anIndex].size() + 1;
247 char* aProperty = new char[3 + aLength + 12 * aNames.size()];
249 char crMode = (char)GetCreationMode();
251 sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u');
253 aLength = aNames.size();
255 for (anIndex = 0; anIndex < aLength; anIndex++) {
256 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
257 (int)(aMinutes[anIndex]),
258 (int)(aHours[anIndex]),
259 (int)(aDays[anIndex]),
260 (int)(aMonths[anIndex]),
261 (int)(aYears[anIndex]),
262 (char*)(aNames[anIndex].c_str()));
263 a = strlen(aProperty);
267 string prop(aProperty);
273 void SALOMEDSImpl_AttributeStudyProperties::Load(const string& value)
275 char* aCopy = (char*)value.c_str();
277 int crMode = (int)aCopy[0];
278 SetCreationMode(crMode);
281 for (anIndex = 2; anIndex + 2 < value.size() ;) {
283 int aMinute, aHour, aDay, aMonth, aYear;
284 str[0] = aCopy[anIndex++];
285 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++];
297 str[0] = aCopy[anIndex++];
298 str[1] = aCopy[anIndex++];
299 str[2] = aCopy[anIndex++];
300 str[3] = aCopy[anIndex++];
305 for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
306 char *aName = new char[aNameSize+1];
307 strncpy(aName, &(aCopy[anIndex]), aNameSize);
308 aName[aNameSize] = 0;
309 SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
311 anIndex += aNameSize + 1;
313 if (aCopy[1] == 'l') {