From: rnv Date: Fri, 25 Mar 2011 09:59:56 +0000 (+0000) Subject: Implementation of the "16566: EDF PAL 514: Implement system of units (milimeters... X-Git-Tag: Start_BR_19998_21191~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5e4cb825f2e1faab3c8283772e45b5bc9d5f8ccf;p=modules%2Fkernel.git Implementation of the "16566: EDF PAL 514: Implement system of units (milimeters, meters, inch...)" issue. --- diff --git a/idl/SALOMEDS_Attributes.idl b/idl/SALOMEDS_Attributes.idl index bd40d4277..af55bd5f0 100644 --- a/idl/SALOMEDS_Attributes.idl +++ b/idl/SALOMEDS_Attributes.idl @@ -1626,6 +1626,30 @@ module SALOMEDS \param withCreator \c true if creation record should be also added to the resulting list or \c false otherwise */ void GetModificationsList(out StringSeq authors, out LongSeq minutes, out LongSeq hours, out LongSeq days, out LongSeq months, out LongSeq years, in boolean withCreator); + + /*! + \brief Sets the comment of the study. + \param comment comment of the study. + */ + void SetComment(in string comment); + + /*! + \brief Returns comment of the study. + \return comment + */ + string GetComment(); + + /*! + \brief Sets the units of the study. + \param units units of the study. + */ + void SetUnits(in string units); + + /*! + \brief Returns units of the study. + \return units + */ + string GetUnits(); }; //========================================================================== diff --git a/src/SALOMEDS/SALOMEDS_AttributeStudyProperties.cxx b/src/SALOMEDS/SALOMEDS_AttributeStudyProperties.cxx index 8a5412bd6..bcdf223a3 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeStudyProperties.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeStudyProperties.cxx @@ -269,3 +269,53 @@ void SALOMEDS_AttributeStudyProperties::GetModificationsList(std::vector(_local_impl); + anImpl->SetComment(theComment); + } else + ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetComment(theComment.c_str()); +} + +std::string SALOMEDS_AttributeStudyProperties::GetComment() +{ + std::string aComment; + if (_isLocal) { + SALOMEDS::Locker lock; + aComment = dynamic_cast(_local_impl)->GetComment(); + } + else + aComment = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetComment(); + return aComment; +} + + +void SALOMEDS_AttributeStudyProperties::SetUnits(const std::string& theUnits) +{ + if (_isLocal) { + CheckLocked(); + SALOMEDS::Locker lock; + SALOMEDSImpl_AttributeStudyProperties* anImpl = + dynamic_cast(_local_impl); + anImpl->SetUnits(theUnits); + } else + ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->SetUnits(theUnits.c_str()); +} + +std::string SALOMEDS_AttributeStudyProperties::GetUnits() +{ + std::string anUnits; + if (_isLocal) { + SALOMEDS::Locker lock; + anUnits = dynamic_cast(_local_impl)->GetUnits(); + } + else + anUnits = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUnits(); + return anUnits; +} diff --git a/src/SALOMEDS/SALOMEDS_AttributeStudyProperties.hxx b/src/SALOMEDS/SALOMEDS_AttributeStudyProperties.hxx index cb921fdbb..847d55ff3 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeStudyProperties.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeStudyProperties.hxx @@ -76,6 +76,13 @@ public: std::vector& theYears, bool theWithCreator); + virtual void SetUnits(const std::string& theUnits); + virtual std::string GetUnits(); + + virtual void SetComment(const std::string& theComment); + virtual std::string GetComment(); + + }; diff --git a/src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.cxx index 20a218e76..570f4551b 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.cxx @@ -187,3 +187,34 @@ void SALOMEDS_AttributeStudyProperties_i::GetModificationsList(SALOMEDS::StringS (*theYears)[a] = aYears[ind-1]; } } + +void SALOMEDS_AttributeStudyProperties_i::SetComment(const char* theComment) +{ + SALOMEDS::Locker lock; + CheckLocked(); + dynamic_cast(_impl)->SetComment(std::string(theComment)); +} + +char* SALOMEDS_AttributeStudyProperties_i::GetComment() +{ + SALOMEDS::Locker lock; + std::string C = dynamic_cast(_impl)->GetComment(); + CORBA::String_var c_s = CORBA::string_dup(C.c_str()); + return c_s._retn(); +} + +void SALOMEDS_AttributeStudyProperties_i::SetUnits(const char* theUnits) +{ + SALOMEDS::Locker lock; + CheckLocked(); + dynamic_cast(_impl)->SetUnits(std::string(theUnits)); +} + +char* SALOMEDS_AttributeStudyProperties_i::GetUnits() +{ + SALOMEDS::Locker lock; + std::string U = dynamic_cast(_impl)->GetUnits(); + CORBA::String_var c_s = CORBA::string_dup(U.c_str()); + return c_s._retn(); +} + diff --git a/src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.hxx b/src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.hxx index 361965c6b..3e8532721 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeStudyProperties_i.hxx @@ -68,6 +68,11 @@ public: SALOMEDS::LongSeq_out theYears, CORBA::Boolean theWithCreator); + virtual void SetComment(const char* theComment); + virtual char* GetComment(); + + virtual void SetUnits(const char* theUnits); + virtual char* GetUnits(); }; diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeStudyProperties.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeStudyProperties.hxx index 8faffe422..ba6ad2a0d 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_AttributeStudyProperties.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeStudyProperties.hxx @@ -60,6 +60,13 @@ public: std::vector& theMonths, std::vector& theYears, bool theWithCreator) = 0; + + virtual void SetUnits(const std::string& theUnits) = 0; + virtual std::string GetUnits() = 0; + + virtual void SetComment(const std::string& theComment) = 0; + virtual std::string GetComment() = 0; + }; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.cxx index bee6dcc00..755e95a3e 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.cxx @@ -238,11 +238,17 @@ std::string SALOMEDSImpl_AttributeStudyProperties::Save() std::vector aMinutes, aHours, aDays, aMonths, aYears; GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears); - int aLength, anIndex; + int aLength, anIndex, unitsSize = 0, commentSize = 0;; for (aLength = 0, anIndex = aNames.size()-1; anIndex >= 0; anIndex--) aLength += aNames[anIndex].size() + 1; - char* aProperty = new char[3 + aLength + 12 * aNames.size()]; + std::string units = GetUnits(); + std::string comment = GetComment(); + + unitsSize = units.size(); + commentSize = comment.size(); + + char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize]; char crMode = (char)GetCreationMode(); @@ -261,6 +267,25 @@ std::string SALOMEDSImpl_AttributeStudyProperties::Save() a = strlen(aProperty); aProperty[a++] = 1; } + + //Write delimeter of the section to define end of the modifications section + aProperty[a++] = 30; + + //Write units if need + if(units.size() > 0) { + sprintf(&(aProperty[a]),"%s",units.c_str()); + a = strlen(aProperty); + } + + aProperty[a++] = 1; //delimeter of the units and comments + + //Write comments if need + if(comment.size() > 0) { + sprintf(&(aProperty[a]),"%s",comment.c_str()); + a = strlen(aProperty); + a++; + } + aProperty[a] = 0; std::string prop(aProperty); delete aProperty; @@ -268,6 +293,27 @@ std::string SALOMEDSImpl_AttributeStudyProperties::Save() return prop; } +void SALOMEDSImpl_AttributeStudyProperties::SetUnits(const std::string& theUnits) { + if(myUnits == theUnits) + return; + myUnits = theUnits; +} + +std::string SALOMEDSImpl_AttributeStudyProperties::GetUnits() { + return myUnits; +} + +void SALOMEDSImpl_AttributeStudyProperties::SetComment(const std::string& theComment) { + if(myComment == theComment) + return; + myComment = theComment; +} + +std::string SALOMEDSImpl_AttributeStudyProperties::GetComment() { + return myComment; +} + + void SALOMEDSImpl_AttributeStudyProperties::Load(const std::string& value) { char* aCopy = (char*)value.c_str(); @@ -307,9 +353,42 @@ void SALOMEDSImpl_AttributeStudyProperties::Load(const std::string& value) SetModification(aName,aMinute,aHour,aDay,aMonth,aYear); delete [] (aName); anIndex += aNameSize + 1; + + //Check end of the modifications section + if(anIndex < value.size() && aCopy[anIndex] == 30) + break; + } + + //Case then study contains units and comment properties + if( anIndex < value.size() ) { + anIndex++; //skip the delimeter of the sections: char(30) + int unitsSize; + for(unitsSize = 0; aCopy[anIndex+unitsSize] != 1; unitsSize++); + + if(unitsSize > 0) { + char *anUnits = new char[unitsSize+1]; + strncpy(anUnits, &(aCopy[anIndex]), unitsSize); + anUnits[unitsSize] = 0; + SetUnits(anUnits); + delete [] (anUnits); + } + anIndex += unitsSize + 1; + + int commentSize; + for(commentSize = 0; aCopy[anIndex+commentSize] != 0; commentSize++); + + if(commentSize > 0) { + char *aComment = new char[commentSize+1]; + strncpy(aComment, &(aCopy[anIndex]), commentSize); + aComment[commentSize] = 0; + SetComment(aComment); + delete [] (aComment); + } + anIndex += commentSize; } + if (aCopy[1] == 'l') { SetLocked(true); } - SetModified(0); + SetModified(0); } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.hxx index 4efbfd86b..6d945cb3d 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.hxx @@ -72,6 +72,12 @@ public: void ChangeCreatorName(const std::string& theUserName); + void SetUnits(const std::string& theUnits); + std::string GetUnits(); + + void SetComment(const std::string& theComment); + std::string GetComment(); + void SetCreationMode(const int theMode); int GetCreationMode() const; @@ -95,6 +101,8 @@ private: std::vector myDay; std::vector myMonth; std::vector myYear; + std::string myUnits; + std::string myComment; int myMode; int myModified; bool myLocked; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx index 2e2e012ae..b809a9c9d 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx @@ -417,12 +417,30 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy, aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears); - int aLength = 0, anIndex, i; + std::string units = aProp->GetUnits(); + std::string comment = aProp->GetComment(); + + int aLength = 0, anIndex, i, unitsSize = 0, commentSize = 0; for(i=1; i<=aNames.size(); i++) aLength += aNames[i-1].size() + 1; - - //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, "zero" byte - char* aProperty = new char[3 + aLength + 12 * aNames.size()]; + + unitsSize = units.size(); + commentSize = comment.size(); + + //string format: + //locked flag, modified flag, + //minutes, hours, day, months, year, user name, char(1), + //minutes, hours, day, months, year, user name, char(1), + //....................................................., + //....................................................., + //....................................................., + //minutes, hours, day, months, year, user name, char(1), char(30) <- !!!! used to define end of section with modifications !!!! + //units, char(1), comment, char(0) + + //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, 1 byte (char(30) section delimeter) + // unit length + 1, comment length, "zero" byte + + char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize ]; sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u'); @@ -440,8 +458,27 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy, a = strlen(aProperty); aProperty[a++] = 1; } - aProperty[a] = 0; + //Write delimeter of the section to define end of the modifications section + aProperty[a++] = 30; + + //Write units if need + if(units.size() > 0) { + sprintf(&(aProperty[a]),"%s",units.c_str()); + a = strlen(aProperty); + } + + aProperty[a++] = 1; + + //Write comments if need + if(comment.size() > 0) { + sprintf(&(aProperty[a]),"%s",comment.c_str()); + a = strlen(aProperty); + a++; + } + + aProperty[a] = 0; + name_len = (hdf_int32) a; size[0] = name_len + 1 ; hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1); @@ -450,7 +487,7 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy, hdf_dataset->CloseOnDisk(); hdf_dataset=0; //will be deleted by hdf_sco_group destructor delete [] aProperty; - + aProp->SetModified(0); return true; }