1 // Copyright (C) 2007-2010 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
23 // File : SALOMEDSImpl_AttributeStudyProperties.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
30 const std::string& SALOMEDSImpl_AttributeStudyProperties::GetID()
32 static std::string SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
33 return SALOMEDSImpl_AttributeStudyPropertiesID;
36 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_AttributeStudyProperties::Set(const DF_Label& label)
38 SALOMEDSImpl_AttributeStudyProperties* A = NULL;
39 if (!(A=(SALOMEDSImpl_AttributeStudyProperties*)label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID()))) {
40 A = new SALOMEDSImpl_AttributeStudyProperties();
41 label.AddAttribute(A);
46 SALOMEDSImpl_AttributeStudyProperties::SALOMEDSImpl_AttributeStudyProperties()
47 :SALOMEDSImpl_GenericAttribute("AttributeStudyProperties")
50 myLockChanged = false;
54 void SALOMEDSImpl_AttributeStudyProperties::Init()
65 void SALOMEDSImpl_AttributeStudyProperties::SetModification(const std::string& theUserName,
72 if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 ||
73 theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
79 myUserName.push_back(theUserName);
80 myMinute.push_back(theMinute);
81 myHour.push_back(theHour);
82 myDay.push_back(theDay);
83 myMonth.push_back(theMonth);
84 myYear.push_back(theYear);
87 void SALOMEDSImpl_AttributeStudyProperties::GetModifications
88 (std::vector<std::string>& theUserNames,
89 std::vector<int>& theMinutes,
90 std::vector<int>& theHours,
91 std::vector<int>& theDays,
92 std::vector<int>& theMonths,
93 std::vector<int>& theYears) const
95 theUserNames = myUserName;
96 theMinutes = myMinute;
103 std::string SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
105 if (myUserName.size() == 0)
106 return std::string("");
107 return myUserName[0];
110 bool SALOMEDSImpl_AttributeStudyProperties::GetCreationDate
117 if (myMinute.size() != 0) {
118 theMinute = myMinute[0];
121 theMonth = myMonth[0];
128 void SALOMEDSImpl_AttributeStudyProperties::ChangeCreatorName(const std::string& theName)
130 if (myUserName.size() > 0) {
133 myUserName[0] = theName;
137 void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const int theMode)
144 int SALOMEDSImpl_AttributeStudyProperties::GetCreationMode() const
149 void SALOMEDSImpl_AttributeStudyProperties::SetModified(const int theModified)
151 myModified = theModified;
154 bool SALOMEDSImpl_AttributeStudyProperties::IsModified() const
156 return (myModified != 0);
159 int SALOMEDSImpl_AttributeStudyProperties::GetModified() const
164 void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const bool theLocked)
167 if (myLocked != theLocked) {
168 myLockChanged = true;
169 myLocked = theLocked;
173 bool SALOMEDSImpl_AttributeStudyProperties::IsLocked() const
178 bool SALOMEDSImpl_AttributeStudyProperties::IsLockChanged(const bool theErase) {
179 if (!myLockChanged) return false;
180 if (theErase) myLockChanged = false;
184 const std::string& SALOMEDSImpl_AttributeStudyProperties::ID() const
189 void SALOMEDSImpl_AttributeStudyProperties::Restore(DF_Attribute* with)
191 SALOMEDSImpl_AttributeStudyProperties* aProp =
192 dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(with);
195 std::vector<std::string> aNames;
196 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
197 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
198 for (int i = 0, len = aNames.size(); i < len; i++) {
199 myUserName.push_back(aNames[i]);
200 myMinute.push_back(aMinutes[i]);
201 myHour.push_back(aHours[i]);
202 myDay.push_back(aDays[i]);
203 myMonth.push_back(aMonths[i]);
204 myYear.push_back(aYears[i]);
206 myMode = aProp->GetCreationMode();
207 // myModified = aProp->GetModified();
208 // myLocked = aProp->IsLocked();
211 DF_Attribute* SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const
213 return new SALOMEDSImpl_AttributeStudyProperties();
216 void SALOMEDSImpl_AttributeStudyProperties::Paste(DF_Attribute* into)
218 SALOMEDSImpl_AttributeStudyProperties* aProp =
219 dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(into);
223 for(i = 0; i < myUserName.size(); i++) {
224 aProp->SetModification(myUserName[i],
225 myMinute[i], myHour[i],
226 myDay[i], myMonth[i], myYear[i]);
229 aProp->SetCreationMode(myMode);
230 // aProp->SetModified(myModified);
231 // aProp->SetLocked(myLocked);
235 std::string SALOMEDSImpl_AttributeStudyProperties::Save()
237 std::vector<std::string> aNames;
238 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
239 GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
241 int aLength, anIndex;
242 for (aLength = 0, anIndex = aNames.size()-1; anIndex >= 0; anIndex--)
243 aLength += aNames[anIndex].size() + 1;
245 char* aProperty = new char[3 + aLength + 12 * aNames.size()];
247 char crMode = (char)GetCreationMode();
249 sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u');
251 aLength = aNames.size();
253 for (anIndex = 0; anIndex < aLength; anIndex++) {
254 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
255 (int)(aMinutes[anIndex]),
256 (int)(aHours[anIndex]),
257 (int)(aDays[anIndex]),
258 (int)(aMonths[anIndex]),
259 (int)(aYears[anIndex]),
260 (char*)(aNames[anIndex].c_str()));
261 a = strlen(aProperty);
265 std::string prop(aProperty);
271 void SALOMEDSImpl_AttributeStudyProperties::Load(const std::string& value)
273 char* aCopy = (char*)value.c_str();
275 int crMode = (int)aCopy[0];
276 SetCreationMode(crMode);
279 for (anIndex = 2; anIndex + 2 < value.size() ;) {
281 int aMinute, aHour, aDay, aMonth, aYear;
282 str[0] = aCopy[anIndex++];
283 str[1] = aCopy[anIndex++];
286 str[0] = aCopy[anIndex++];
287 str[1] = aCopy[anIndex++];
289 str[0] = aCopy[anIndex++];
290 str[1] = aCopy[anIndex++];
292 str[0] = aCopy[anIndex++];
293 str[1] = aCopy[anIndex++];
295 str[0] = aCopy[anIndex++];
296 str[1] = aCopy[anIndex++];
297 str[2] = aCopy[anIndex++];
298 str[3] = aCopy[anIndex++];
303 for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
304 char *aName = new char[aNameSize+1];
305 strncpy(aName, &(aCopy[anIndex]), aNameSize);
306 aName[aNameSize] = 0;
307 SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
309 anIndex += aNameSize + 1;
311 if (aCopy[1] == 'l') {