1 // Copyright (C) 2007-2011 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, unitsSize = 0, commentSize = 0;;
242 for (aLength = 0, anIndex = aNames.size()-1; anIndex >= 0; anIndex--)
243 aLength += aNames[anIndex].size() + 1;
245 std::string units = GetUnits();
246 std::string comment = GetComment();
248 unitsSize = units.size();
249 commentSize = comment.size();
251 char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize];
253 char crMode = (char)GetCreationMode();
255 sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u');
257 aLength = aNames.size();
259 for (anIndex = 0; anIndex < aLength; anIndex++) {
260 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
261 (int)(aMinutes[anIndex]),
262 (int)(aHours[anIndex]),
263 (int)(aDays[anIndex]),
264 (int)(aMonths[anIndex]),
265 (int)(aYears[anIndex]),
266 (char*)(aNames[anIndex].c_str()));
267 a = strlen(aProperty);
271 //Write delimeter of the section to define end of the modifications section
274 //Write units if need
275 if(units.size() > 0) {
276 sprintf(&(aProperty[a]),"%s",units.c_str());
277 a = strlen(aProperty);
280 aProperty[a++] = 1; //delimeter of the units and comments
282 //Write comments if need
283 if(comment.size() > 0) {
284 sprintf(&(aProperty[a]),"%s",comment.c_str());
285 a = strlen(aProperty);
290 std::string prop(aProperty);
296 void SALOMEDSImpl_AttributeStudyProperties::SetUnits(const std::string& theUnits) {
297 if(myUnits == theUnits)
302 std::string SALOMEDSImpl_AttributeStudyProperties::GetUnits() {
306 void SALOMEDSImpl_AttributeStudyProperties::SetComment(const std::string& theComment) {
307 if(myComment == theComment)
309 myComment = theComment;
312 std::string SALOMEDSImpl_AttributeStudyProperties::GetComment() {
317 void SALOMEDSImpl_AttributeStudyProperties::Load(const std::string& value)
319 char* aCopy = (char*)value.c_str();
321 int crMode = (int)aCopy[0];
322 SetCreationMode(crMode);
325 for (anIndex = 2; anIndex + 2 < value.size() ;) {
327 int aMinute, aHour, aDay, aMonth, aYear;
328 str[0] = aCopy[anIndex++];
329 str[1] = aCopy[anIndex++];
332 str[0] = aCopy[anIndex++];
333 str[1] = aCopy[anIndex++];
335 str[0] = aCopy[anIndex++];
336 str[1] = aCopy[anIndex++];
338 str[0] = aCopy[anIndex++];
339 str[1] = aCopy[anIndex++];
341 str[0] = aCopy[anIndex++];
342 str[1] = aCopy[anIndex++];
343 str[2] = aCopy[anIndex++];
344 str[3] = aCopy[anIndex++];
349 for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
350 char *aName = new char[aNameSize+1];
351 strncpy(aName, &(aCopy[anIndex]), aNameSize);
352 aName[aNameSize] = 0;
353 SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
355 anIndex += aNameSize + 1;
357 //Check end of the modifications section
358 if(anIndex < value.size() && aCopy[anIndex] == 30)
362 //Case then study contains units and comment properties
363 if( anIndex < value.size() ) {
364 anIndex++; //skip the delimeter of the sections: char(30)
366 for(unitsSize = 0; aCopy[anIndex+unitsSize] != 1; unitsSize++);
369 char *anUnits = new char[unitsSize+1];
370 strncpy(anUnits, &(aCopy[anIndex]), unitsSize);
371 anUnits[unitsSize] = 0;
375 anIndex += unitsSize + 1;
378 for(commentSize = 0; aCopy[anIndex+commentSize] != 0; commentSize++);
380 if(commentSize > 0) {
381 char *aComment = new char[commentSize+1];
382 strncpy(aComment, &(aCopy[anIndex]), commentSize);
383 aComment[commentSize] = 0;
384 SetComment(aComment);
385 delete [] (aComment);
387 anIndex += commentSize;
390 if (aCopy[1] == 'l') {