From: dbv Date: Fri, 8 Jul 2016 12:44:20 +0000 (+0300) Subject: Issue #1540: Added attribute for array of double. X-Git-Tag: V_2.5.0~215 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=02fc4b8cac85322c7bb8c5a00f7fafa3665a0fc6;p=modules%2Fshaper.git Issue #1540: Added attribute for array of double. --- diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 11d98c427..d94f595e0 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -10,6 +10,7 @@ SET(PROJECT_HEADERS Model_Session.h Model_Data.h Model_AttributeDouble.h + Model_AttributeDoubleArray.h Model_AttributeDocRef.h Model_AttributeReference.h Model_AttributeRefAttr.h @@ -44,6 +45,7 @@ SET(PROJECT_SOURCES Model_Session.cpp Model_Data.cpp Model_AttributeDouble.cpp + Model_AttributeDoubleArray.cpp Model_AttributeDocRef.cpp Model_AttributeReference.cpp Model_AttributeRefAttr.cpp diff --git a/src/Model/Model_AttributeDoubleArray.cpp b/src/Model/Model_AttributeDoubleArray.cpp new file mode 100644 index 000000000..3a6b2ad9f --- /dev/null +++ b/src/Model/Model_AttributeDoubleArray.cpp @@ -0,0 +1,77 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_AttributeDoubleArray.cpp +// Created: 08 July 2016 +// Author: Dmitry Bobylev + +#include "Model_AttributeDoubleArray.h" + +#include +#include + +#include + +#include + +//================================================================================================== +int Model_AttributeDoubleArray::size() +{ + if (myArray.IsNull() || !myArray->IsValid()) { + // this could be on undo and then redo creation of the attribute + // in result creation it may be uninitialized + myIsInitialized = myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True; + } + // checking the validity because attribute (as a field) may be presented, + // but without label: it is undoed + return (myArray.IsNull() || !myArray->IsValid()) ? 0 : myArray->Length(); +} + +//================================================================================================== +void Model_AttributeDoubleArray::setSize(const int theSize) +{ + if (myArray.IsNull() || !myArray->IsValid()) { // create array if it is not done yet + if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array) + myArray = TDataStd_RealArray::Set(myLab, 0, theSize - 1); + owner()->data()->sendAttributeUpdated(this); + } + } else { // reset the old array + if (theSize) { + if (theSize != myArray->Length()) { // old data is not keept, a new array is created + Handle(TColStd_HArray1OfReal) aNewArray = new TColStd_HArray1OfReal(0, theSize - 1); + myArray->ChangeArray(aNewArray); + owner()->data()->sendAttributeUpdated(this); + } + } else { // size is zero => array must be erased + if (!myArray.IsNull()) { + myArray.Nullify(); + myLab.ForgetAttribute(TDataStd_RealArray::GetID()); + owner()->data()->sendAttributeUpdated(this); + } + } + } +} + +//================================================================================================== +void Model_AttributeDoubleArray::setValue(const int theIndex, + const double theValue) +{ + if (myArray->Value(theIndex) != theValue) { + myArray->SetValue(theIndex, theValue); + owner()->data()->sendAttributeUpdated(this); + } +} + +//================================================================================================== +double Model_AttributeDoubleArray::value(const int theIndex) +{ + return myArray->Value(theIndex); +} + +//================================================================================================== +Model_AttributeDoubleArray::Model_AttributeDoubleArray(TDF_Label& theLabel) +{ + myLab = theLabel; + // check the attribute could be already presented in this doc (after load document) + myIsInitialized = + myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True; +} diff --git a/src/Model/Model_AttributeDoubleArray.h b/src/Model/Model_AttributeDoubleArray.h new file mode 100644 index 000000000..74d960624 --- /dev/null +++ b/src/Model/Model_AttributeDoubleArray.h @@ -0,0 +1,52 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_AttributeDoubleArray.h +// Created: 08 July 2016 +// Author: Dmitry Bobylev + +#ifndef Model_AttributeDoubleArray_H_ +#define Model_AttributeDoubleArray_H_ + +#include "Model.h" + +#include + +#include +#include + +#include + +/// \class Model_AttributeDoubleArray +/// \ingroup DataModel +/// \brief API for the attribute that contains several double in the array inside. +class Model_AttributeDoubleArray: public ModelAPI_AttributeDoubleArray +{ +public: + /// Returns the size of the array (zero means that it is empty) + MODEL_EXPORT virtual int size(); + + /// Sets the new size of the array. The previous data is erased. + MODEL_EXPORT virtual void setSize(const int theSize); + + /// Defines the value of the array by index [0; size-1] + MODEL_EXPORT virtual void setValue(const int theIndex, + const double theValue); + + /// Returns the value by the index + MODEL_EXPORT virtual double value(const int theIndex); + +protected: + /// Initializes attibutes + Model_AttributeDoubleArray(TDF_Label& theLabel); + +private: + /// The OCCT array that keeps all values. + Handle_TDataStd_RealArray myArray; + + /// Stores the label as a field to set array if size is not null (null array is buggy in OCAF) + TDF_Label myLab; + + friend class Model_Data; +}; + +#endif diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 402dbd679..fe4ec99db 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -151,7 +152,9 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin anAttr = new Model_AttributeRefAttrList(anAttrLab); } else if (theAttrType == ModelAPI_AttributeIntArray::typeId()) { anAttr = new Model_AttributeIntArray(anAttrLab); - } + } else if (theAttrType == ModelAPI_AttributeDoubleArray::typeId()) { + anAttr = new Model_AttributeDoubleArray(anAttrLab); + } // create also GeomData attributes here because only here the OCAF structure is known else if (theAttrType == GeomData_Point::typeId()) { GeomData_Point* anAttribute = new GeomData_Point(); @@ -211,6 +214,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttrList, refattrlist); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray); +GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDoubleArray, realArray); std::shared_ptr Model_Data::attribute(const std::string& theID) { diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index e505d3751..c8a5a03d8 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -86,6 +86,8 @@ class Model_Data : public ModelAPI_Data MODEL_EXPORT virtual std::shared_ptr document(const std::string& theID); /// Returns the attribute that contains real value with double precision MODEL_EXPORT virtual std::shared_ptr real(const std::string& theID); + /// Returns the attribute that contains double values array + MODEL_EXPORT virtual std::shared_ptr realArray(const std::string& theID); /// Returns the attribute that contains integer value MODEL_EXPORT virtual std::shared_ptr integer(const std::string& theID); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 27298e20e..60036bc80 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -12,6 +12,7 @@ SET(PROJECT_HEADERS ModelAPI_AttributeIntArray.h ModelAPI_AttributeDocRef.h ModelAPI_AttributeDouble.h + ModelAPI_AttributeDoubleArray.h ModelAPI_AttributeInteger.h ModelAPI_AttributeRefAttr.h ModelAPI_AttributeReference.h @@ -50,6 +51,7 @@ SET(PROJECT_SOURCES ModelAPI_AttributeIntArray.cpp ModelAPI_AttributeDocRef.cpp ModelAPI_AttributeDouble.cpp + ModelAPI_AttributeDoubleArray.cpp ModelAPI_AttributeInteger.cpp ModelAPI_AttributeRefAttr.cpp ModelAPI_AttributeReference.cpp diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index b8fcaaa9d..23c6d8043 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -45,6 +45,7 @@ %shared_ptr(ModelAPI_Attribute) %shared_ptr(ModelAPI_AttributeDocRef) %shared_ptr(ModelAPI_AttributeDouble) +%shared_ptr(ModelAPI_AttributeDoubleArray) %shared_ptr(ModelAPI_AttributeInteger) %shared_ptr(ModelAPI_AttributeIntArray) %shared_ptr(ModelAPI_AttributeString) @@ -78,6 +79,7 @@ %include "ModelAPI_Attribute.h" %include "ModelAPI_AttributeDocRef.h" %include "ModelAPI_AttributeDouble.h" +%include "ModelAPI_AttributeDoubleArray.h" %include "ModelAPI_AttributeInteger.h" %include "ModelAPI_AttributeIntArray.h" %include "ModelAPI_AttributeString.h" @@ -100,7 +102,7 @@ %include "ModelAPI_Tools.h" %include "ModelAPI_ResultCompSolid.h" -// std::list -> [] +// std::list -> [] %template(StringList) std::list; %template(ObjectList) std::list >; %template(ResultList) std::list >; @@ -126,6 +128,7 @@ template std::shared_ptr shared_ptr_cast(std::shared_ptr // Attribute casts %template(modelAPI_AttributeDocRef) shared_ptr_cast; %template(modelAPI_AttributeDouble) shared_ptr_cast; +%template(modelAPI_AttributeDoubleArray) shared_ptr_cast; %template(modelAPI_AttributeInteger) shared_ptr_cast; %template(modelAPI_AttributeIntArray) shared_ptr_cast; %template(modelAPI_AttributeString) shared_ptr_cast; diff --git a/src/ModelAPI/ModelAPI_AttributeDoubleArray.cpp b/src/ModelAPI/ModelAPI_AttributeDoubleArray.cpp new file mode 100644 index 000000000..73aa27277 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeDoubleArray.cpp @@ -0,0 +1,23 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_AttributeDoubleArray.cpp +// Created: 8 July 2016 +// Author: Dmitry Bobylev + +#include "ModelAPI_AttributeDoubleArray.h" + +//================================================================================================== +std::string ModelAPI_AttributeDoubleArray::attributeType() +{ + return typeId(); +} + +//================================================================================================== +ModelAPI_AttributeDoubleArray::~ModelAPI_AttributeDoubleArray() +{ +} + +//================================================================================================== +ModelAPI_AttributeDoubleArray::ModelAPI_AttributeDoubleArray() +{ +} diff --git a/src/ModelAPI/ModelAPI_AttributeDoubleArray.h b/src/ModelAPI/ModelAPI_AttributeDoubleArray.h new file mode 100644 index 000000000..5106904fc --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeDoubleArray.h @@ -0,0 +1,54 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_AttributeDoubleArray.h +// Created: 08 July 2016 +// Author: Dmitry Bobylev + +#ifndef ModelAPI_AttributeDoubleArray_H_ +#define ModelAPI_AttributeDoubleArray_H_ + +#include +#include + +#include + +/// \class ModelAPI_AttributeDoubleArray +/// \ingroup DataModel +/// \brief API for the attribute that contains several double in the array inside. +class ModelAPI_AttributeDoubleArray: public ModelAPI_Attribute +{ +public: + /// Returns the size of the array (zero means that it is empty) + MODELAPI_EXPORT virtual int size() = 0; + + /// Sets the new size of the array. The previous data is erased. + MODELAPI_EXPORT virtual void setSize(const int theSize) = 0; + + /// Defines the value of the array by index [0; size-1] + MODELAPI_EXPORT virtual void setValue(const int theIndex, + const double theValue) = 0; + + /// Returns the value by the index + MODELAPI_EXPORT virtual double value(const int theIndex) = 0; + + /// Returns the type of this class of attributes + MODELAPI_EXPORT static std::string typeId() + { + return "DoubleArray"; + } + + /// Returns the type of this class of attributes, not static method + MODELAPI_EXPORT virtual std::string attributeType(); + + /// To virtually destroy the fields of successors + MODELAPI_EXPORT virtual ~ModelAPI_AttributeDoubleArray(); + +protected: + /// Objects are created for features automatically + MODELAPI_EXPORT ModelAPI_AttributeDoubleArray(); +}; + +/// Pointer on double attribute +typedef std::shared_ptr AttributeDoubleArrayPtr; + +#endif diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 320dffb40..71e9aee9d 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -21,6 +21,7 @@ class ModelAPI_Attribute; class ModelAPI_AttributeDocRef; class ModelAPI_AttributeInteger; class ModelAPI_AttributeDouble; +class ModelAPI_AttributeDoubleArray; class ModelAPI_AttributeReference; class ModelAPI_AttributeRefAttr; class ModelAPI_AttributeRefList; @@ -65,6 +66,8 @@ class MODELAPI_EXPORT ModelAPI_Data virtual std::shared_ptr document(const std::string& theID) = 0; /// Returns the attribute that contains real value with double precision virtual std::shared_ptr real(const std::string& theID) = 0; + /// Returns the attribute that contains double values array + virtual std::shared_ptr realArray(const std::string& theID) = 0; /// Returns the attribute that contains integer value virtual std::shared_ptr integer(const std::string& theID) = 0; /// Returns the attribute that contains reference to a feature diff --git a/src/ModelAPI/ModelAPI_swig.h b/src/ModelAPI/ModelAPI_swig.h index 377d1182d..ec816d77c 100644 --- a/src/ModelAPI/ModelAPI_swig.h +++ b/src/ModelAPI/ModelAPI_swig.h @@ -21,6 +21,7 @@ #include "ModelAPI_Attribute.h" #include "ModelAPI_AttributeDocRef.h" #include "ModelAPI_AttributeDouble.h" + #include "ModelAPI_AttributeDoubleArray.h" #include "ModelAPI_AttributeInteger.h" #include "ModelAPI_AttributeIntArray.h" #include "ModelAPI_AttributeString.h"