1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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"
31 const std::string& SALOMEDSImpl_AttributeStudyProperties::GetID()
33 static std::string SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F");
34 return SALOMEDSImpl_AttributeStudyPropertiesID;
37 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_AttributeStudyProperties::Set(const DF_Label& label)
39 SALOMEDSImpl_AttributeStudyProperties* A = NULL;
40 if (!(A=(SALOMEDSImpl_AttributeStudyProperties*)label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID()))) {
41 A = new SALOMEDSImpl_AttributeStudyProperties();
42 label.AddAttribute(A);
47 SALOMEDSImpl_AttributeStudyProperties::SALOMEDSImpl_AttributeStudyProperties()
48 :SALOMEDSImpl_GenericAttribute("AttributeStudyProperties")
51 myLockChanged = false;
56 void SALOMEDSImpl_AttributeStudyProperties::Init()
65 myComponentVersions.clear();
68 void SALOMEDSImpl_AttributeStudyProperties::SetModification(const std::string& theUserName,
75 if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 ||
76 theDay<0 || theDay>31 || theMonth<0 || theMonth>12)
82 myUserName.push_back(theUserName);
83 myMinute.push_back(theMinute);
84 myHour.push_back(theHour);
85 myDay.push_back(theDay);
86 myMonth.push_back(theMonth);
87 myYear.push_back(theYear);
90 void SALOMEDSImpl_AttributeStudyProperties::GetModifications
91 (std::vector<std::string>& theUserNames,
92 std::vector<int>& theMinutes,
93 std::vector<int>& theHours,
94 std::vector<int>& theDays,
95 std::vector<int>& theMonths,
96 std::vector<int>& theYears) const
98 theUserNames = myUserName;
99 theMinutes = myMinute;
106 std::string SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const
108 return myUserName.empty() ? std::string("") : myUserName[0];
111 bool SALOMEDSImpl_AttributeStudyProperties::GetCreationDate
118 if (myMinute.size() != 0) {
119 theMinute = myMinute[0];
122 theMonth = myMonth[0];
129 void SALOMEDSImpl_AttributeStudyProperties::ChangeCreatorName(const std::string& theName)
131 if (myUserName.size() > 0) {
134 myUserName[0] = theName;
138 void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const int theMode)
140 if (theMode == myMode) return;
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)
182 if (!myLockChanged) return false;
183 if (theErase) myLockChanged = false;
187 const std::string& SALOMEDSImpl_AttributeStudyProperties::ID() const
192 void SALOMEDSImpl_AttributeStudyProperties::Restore(DF_Attribute* with)
194 SALOMEDSImpl_AttributeStudyProperties* aProp =
195 dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(with);
198 std::vector<std::string> aNames;
199 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
200 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
201 for (int i = 0, len = aNames.size(); i < len; i++) {
202 myUserName.push_back(aNames[i]);
203 myMinute.push_back(aMinutes[i]);
204 myHour.push_back(aHours[i]);
205 myDay.push_back(aDays[i]);
206 myMonth.push_back(aMonths[i]);
207 myYear.push_back(aYears[i]);
209 myMode = aProp->GetCreationMode();
210 myComponentVersions = aProp->GetComponentsVersions();
211 // myModified = aProp->GetModified();
212 // myLocked = aProp->IsLocked();
215 DF_Attribute* SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const
217 return new SALOMEDSImpl_AttributeStudyProperties();
220 void SALOMEDSImpl_AttributeStudyProperties::Paste(DF_Attribute* into)
222 SALOMEDSImpl_AttributeStudyProperties* aProp =
223 dynamic_cast<SALOMEDSImpl_AttributeStudyProperties*>(into);
227 for(i = 0; i < myUserName.size(); i++) {
228 aProp->SetModification(myUserName[i],
229 myMinute[i], myHour[i],
230 myDay[i], myMonth[i], myYear[i]);
233 aProp->SetCreationMode(myMode);
234 aProp->SetComponentsVersions( myComponentVersions );
235 // aProp->SetModified(myModified);
236 // aProp->SetLocked(myLocked);
240 std::string SALOMEDSImpl_AttributeStudyProperties::Save()
242 std::vector<std::string> aNames;
243 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
244 GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
246 int aLength, anIndex, unitsSize = 0, commentSize = 0;;
247 for (aLength = 0, anIndex = aNames.size()-1; anIndex >= 0; anIndex--)
248 aLength += aNames[anIndex].size() + 1;
250 std::string units = GetUnits();
251 std::string comment = GetComment();
254 std::map<std::string, std::string> versions;
255 versionMap::const_iterator it;
256 for (aLength1 = 0, it = myComponentVersions.begin(); it != myComponentVersions.end(); ++it ) {
257 std::string vlist = "";
258 versionList vl = it->second;
259 versionList::const_iterator vlit;
260 for ( vlit = vl.begin(); vlit != vl.end(); ++vlit ) {
261 if ( vlist != "" ) vlist += ";";
264 versions[ it->first ] = vlist;
265 aLength1 += it->first.size() + vlist.size() + 2;
268 unitsSize = units.size();
269 commentSize = comment.size();
271 char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize + 1 + aLength1 ];
273 char crMode = (char)GetCreationMode();
275 sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u');
277 aLength = aNames.size();
279 for (anIndex = 0; anIndex < aLength; anIndex++) {
280 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
281 (int)(aMinutes[anIndex]),
282 (int)(aHours[anIndex]),
283 (int)(aDays[anIndex]),
284 (int)(aMonths[anIndex]),
285 (int)(aYears[anIndex]),
286 (char*)(aNames[anIndex].c_str()));
287 a = strlen(aProperty);
291 //Write delimeter of the section to define end of the modifications section
294 //Write units if need
295 if(units.size() > 0) {
296 sprintf(&(aProperty[a]),"%s",units.c_str());
297 a = strlen(aProperty);
300 aProperty[a++] = 1; //delimeter of the units and comments
302 //Write comments if need
303 if(comment.size() > 0) {
304 sprintf(&(aProperty[a]),"%s",comment.c_str());
305 a = strlen(aProperty);
308 aProperty[a++] = 30; //delimeter of the component versions
310 std::map<std::string, std::string>::const_iterator versionsIt;
311 for ( versionsIt = versions.begin(); versionsIt != versions.end(); ++versionsIt ) {
312 sprintf(&(aProperty[a]),"%s=%s",
313 (char*)(versionsIt->first.c_str()),
314 (char*)(versionsIt->second.c_str()));
315 a = strlen(aProperty);
320 std::string prop(aProperty);
326 void SALOMEDSImpl_AttributeStudyProperties::SetUnits(const std::string& theUnits)
328 if(myUnits == theUnits)
337 std::string SALOMEDSImpl_AttributeStudyProperties::GetUnits() const
342 void SALOMEDSImpl_AttributeStudyProperties::SetComment(const std::string& theComment)
344 if(myComment == theComment)
350 myComment = theComment;
353 std::string SALOMEDSImpl_AttributeStudyProperties::GetComment() const
358 void SALOMEDSImpl_AttributeStudyProperties::SetComponentVersion(const std::string& theComponent, const std::string& theVersion)
360 if (!theComponent.empty()) {
363 if (myComponentVersions.find(theComponent) == myComponentVersions.end()) myComponentVersions[theComponent] = versionList();
364 if (myComponentVersions[theComponent].empty() || myComponentVersions[theComponent].back() != theVersion)
365 myComponentVersions[theComponent].push_back(theVersion);
369 std::vector<std::string> SALOMEDSImpl_AttributeStudyProperties::GetStoredComponents() const
371 std::vector<std::string> components;
372 versionMap::const_iterator it;
373 for (it = myComponentVersions.begin(); it != myComponentVersions.end(); ++it)
374 components.push_back(it->first);
378 std::string SALOMEDSImpl_AttributeStudyProperties::GetComponentVersion(const std::string& theComponent) const
380 versionList versions = GetComponentVersions(theComponent);
381 return versions.size() > 0 ? versions[0] : std::string("");
384 std::vector<std::string> SALOMEDSImpl_AttributeStudyProperties::GetComponentVersions(const std::string& theComponent) const
386 versionList versions;
387 versionMap::const_iterator it = myComponentVersions.find(theComponent);
388 if ( it != myComponentVersions.end() ) versions = it->second;
392 std::map< std::string, std::vector<std::string> > SALOMEDSImpl_AttributeStudyProperties::GetComponentsVersions() const
394 return myComponentVersions;
397 void SALOMEDSImpl_AttributeStudyProperties::SetComponentsVersions( const std::map< std::string, std::vector<std::string> >& theVersions )
399 myComponentVersions = theVersions;
402 void SALOMEDSImpl_AttributeStudyProperties::Load(const std::string& value)
404 char* aCopy = (char*)value.c_str();
406 int crMode = (int)aCopy[0];
407 SetCreationMode(crMode);
410 // number 13 below is minimal size of modification data record, which has form:
411 // mmhhddMMyyyyname1, where
412 // - mm: minute = 2 bytes
413 // - hh: hour = 2 bytes
414 // - dd: day = 2 bytes
415 // - MM: month = 2 bytes
416 // - yyyy: year = 4 bytes
417 // - name: user's name = arbitrary value, minimal length is 0 bytes
418 // - 1 : records delimiter = 1 byte
419 for (anIndex = 2; anIndex + 13 < value.size() ;) {
421 int aMinute, aHour, aDay, aMonth, aYear;
422 str[0] = aCopy[anIndex++];
423 str[1] = aCopy[anIndex++];
426 str[0] = aCopy[anIndex++];
427 str[1] = aCopy[anIndex++];
429 str[0] = aCopy[anIndex++];
430 str[1] = aCopy[anIndex++];
432 str[0] = aCopy[anIndex++];
433 str[1] = aCopy[anIndex++];
435 str[0] = aCopy[anIndex++];
436 str[1] = aCopy[anIndex++];
437 str[2] = aCopy[anIndex++];
438 str[3] = aCopy[anIndex++];
443 for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++);
444 char *aName = new char[aNameSize+1];
445 strncpy(aName, &(aCopy[anIndex]), aNameSize);
446 aName[aNameSize] = 0;
447 SetModification(aName,aMinute,aHour,aDay,aMonth,aYear);
449 anIndex += aNameSize + 1;
451 //Check end of the modifications section
452 if(anIndex < value.size() && aCopy[anIndex] == 30)
456 //Case when study contains units and comment properties
457 if( anIndex < value.size() ) {
458 anIndex++; //skip the delimeter of the sections: char(30)
460 for(unitsSize = 0; aCopy[anIndex+unitsSize] != 1; unitsSize++);
463 char *anUnits = new char[unitsSize+1];
464 strncpy(anUnits, &(aCopy[anIndex]), unitsSize);
465 anUnits[unitsSize] = 0;
469 anIndex += unitsSize + 1;
472 for(commentSize = 0; aCopy[anIndex+commentSize] != 0 && aCopy[anIndex+commentSize] != 30; commentSize++);
474 if(commentSize > 0) {
475 char *aComment = new char[commentSize+1];
476 strncpy(aComment, &(aCopy[anIndex]), commentSize);
477 aComment[commentSize] = 0;
478 SetComment(aComment);
479 delete [] (aComment);
481 anIndex += commentSize + 1;
484 //Case when study contains components versions
485 if( anIndex < value.size() ) {
486 while ( anIndex < value.size() && aCopy[anIndex] != 0 ) {
488 for(modSize = 0; aCopy[anIndex+modSize] != '='; modSize++);
490 for(verSize = 0; aCopy[anIndex+modSize+1+verSize] != 1; verSize++);
493 char *aModule = new char[modSize+1];
494 strncpy(aModule, &(aCopy[anIndex]), modSize);
495 aModule[modSize] = 0;
496 char *aVersions = new char[verSize+1];
498 strncpy(aVersions, &(aCopy[anIndex+modSize+1]), verSize);
499 aVersions[verSize] = 0;
501 std::string mVersions = aVersions;
502 int start = 0, idx = mVersions.find( ';', start );
503 while ( idx != std::string::npos ) {
504 SetComponentVersion( aModule, mVersions.substr( start, idx-start ) );
506 idx = mVersions.find( ';', start );
508 SetComponentVersion( aModule, mVersions.substr( start ) );
511 delete [] (aVersions);
512 anIndex += modSize + 1 + verSize + 1;
517 if (aCopy[1] == 'l') {