From: sbh Date: Wed, 3 Sep 2014 07:27:27 +0000 (+0400) Subject: "Integer" Attribute added. X-Git-Tag: V_0.4.4~91 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c20717c0b994f654d4da7b9039e9f08c165929c3;p=modules%2Fshaper.git "Integer" Attribute added. --- diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index bd10db278..63d79a60e 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -13,6 +13,7 @@ SET(PROJECT_HEADERS Model_AttributeRefList.h Model_AttributeBoolean.h Model_AttributeString.h + Model_AttributeInteger.h Model_Events.h Model_Update.h Model_Validator.h @@ -35,6 +36,7 @@ SET(PROJECT_SOURCES Model_AttributeRefList.cpp Model_AttributeBoolean.cpp Model_AttributeString.cpp + Model_AttributeInteger.cpp Model_Events.cpp Model_Update.cpp Model_Validator.cpp diff --git a/src/Model/Model_AttributeInteger.cpp b/src/Model/Model_AttributeInteger.cpp new file mode 100644 index 000000000..1d72baa40 --- /dev/null +++ b/src/Model/Model_AttributeInteger.cpp @@ -0,0 +1,35 @@ +// File: Model_AttributeInteger.cpp +// Created: 03 sep 2014 +// Author: sbh + +#include + +#include +#include +#include + +#include +#include + +void Model_AttributeInteger::setValue(const int theValue) +{ + if (!myIsInitialized || myInteger->Get() != theValue) { + myInteger->Set(theValue); + owner()->data()->sendAttributeUpdated(this); + } +} + +int Model_AttributeInteger::value() +{ + return myInteger->Get(); +} + +Model_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel) +{ + // check the attribute could be already presented in this doc (after load document) + myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myInteger) == Standard_True; + if (!myIsInitialized) { + // create attribute: not initialized by value yet, just zero + myInteger = TDataStd_Integer::Set(theLabel, 0); + } +} diff --git a/src/Model/Model_AttributeInteger.h b/src/Model/Model_AttributeInteger.h new file mode 100644 index 000000000..c4be993be --- /dev/null +++ b/src/Model/Model_AttributeInteger.h @@ -0,0 +1,36 @@ +// File: Model_AttributeInteger.h +// Created: 03 sep 2014 +// Author: sbh + +#ifndef MODEL_ATTRIBUTEINTEGER_H_ +#define MODEL_ATTRIBUTEINTEGER_H_ + +#include +#include + +#include +#include + +/**\class Model_AttributeInteger + * \ingroup DataModel + * \brief Attribute that contains integer (int). + */ + +class Model_AttributeInteger : public ModelAPI_AttributeInteger +{ + Handle_TDataStd_Integer myInteger; + public: + /// Defines the int value + MODEL_EXPORT virtual void setValue(const int theValue); + + /// Returns the int value + MODEL_EXPORT virtual int value(); + + protected: + /// Initializes attibutes + Model_AttributeInteger(TDF_Label& theLabel); + + friend class Model_Data; +}; + +#endif diff --git a/src/Model/Model_AttributeString.cpp b/src/Model/Model_AttributeString.cpp index fa22e1022..8a9d6f0eb 100644 --- a/src/Model/Model_AttributeString.cpp +++ b/src/Model/Model_AttributeString.cpp @@ -1,6 +1,6 @@ // File: Model_AttributeString.cpp -// Created: 2 june 2014 -// Author: Vitaly Smetannikov +// Created: 25 august 2014 +// Author: sbh #include #include diff --git a/src/Model/Model_AttributeString.h b/src/Model/Model_AttributeString.h index 2695cbcf5..a75ddae6a 100644 --- a/src/Model/Model_AttributeString.h +++ b/src/Model/Model_AttributeString.h @@ -1,9 +1,9 @@ // File: Model_AttributeString.h -// Created: 2 june 2014 -// Author: Vitaly Smetannikov +// Created: 25 august 2014 +// Author: sbh -#ifndef Model_AttributeString_H_ -#define Model_AttributeString_H_ +#ifndef MODEL_ATTRIBUTESTRING_H_ +#define MODEL_ATTRIBUTESTRING_H_ #include #include @@ -20,12 +20,12 @@ class Model_AttributeString : public ModelAPI_AttributeString { - Handle_TDataStd_Name myString; ///< double is Real attribute + Handle_TDataStd_Name myString; public: - /// Defines the double value + /// Defines the std::string value MODEL_EXPORT virtual void setValue(const std::string& theValue); - /// Returns the double value + /// Returns the std::string value MODEL_EXPORT virtual std::string value(); protected: diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index dc80d9024..d97975153 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,8 @@ #include +#include + Model_Data::Model_Data() { } @@ -62,8 +65,14 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt ModelAPI_Attribute* anAttr = 0; if (theAttrType == ModelAPI_AttributeDocRef::type()) { anAttr = new Model_AttributeDocRef(anAttrLab); + } else if (theAttrType == Model_AttributeInteger::type()) { + anAttr = new Model_AttributeInteger(anAttrLab); } else if (theAttrType == ModelAPI_AttributeDouble::type()) { anAttr = new Model_AttributeDouble(anAttrLab); + } else if (theAttrType == Model_AttributeBoolean::type()) { + anAttr = new Model_AttributeBoolean(anAttrLab); + } else if (theAttrType == Model_AttributeString::type()) { + anAttr = new Model_AttributeString(anAttrLab); } else if (theAttrType == ModelAPI_AttributeReference::type()) { anAttr = new Model_AttributeReference(anAttrLab); } else if (theAttrType == ModelAPI_AttributeRefAttr::type()) { @@ -76,10 +85,6 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt anAttr = new GeomData_Dir(anAttrLab); } else if (theAttrType == GeomData_Point2D::type()) { anAttr = new GeomData_Point2D(anAttrLab); - } else if (theAttrType == Model_AttributeBoolean::type()) { - anAttr = new Model_AttributeBoolean(anAttrLab); - } else if (theAttrType == Model_AttributeString::type()) { - anAttr = new Model_AttributeString(anAttrLab); } if (anAttr) { myAttrs[theID] = boost::shared_ptr(anAttr); @@ -119,6 +124,21 @@ boost::shared_ptr Model_Data::real(const std::string& return aRes; } +boost::shared_ptr Model_Data::integer(const std::string& theID) +{ + std::map >::iterator aFound = myAttrs.find(theID); + if (aFound == myAttrs.end()) { + // TODO: generate error on unknown attribute request and/or add mechanism for customization + return boost::shared_ptr(); + } + boost::shared_ptr aRes = boost::dynamic_pointer_cast< + ModelAPI_AttributeInteger>(aFound->second); + if (!aRes) { + // TODO: generate error on invalid attribute type request + } + return aRes; +} + boost::shared_ptr Model_Data::boolean(const std::string& theID) { std::map >::iterator aFound = myAttrs.find(theID); diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 659778769..31ff67ff2 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,9 @@ class Model_Data : public ModelAPI_Data MODEL_EXPORT virtual boost::shared_ptr docRef(const std::string& theID); /// Returns the attribute that contains real value with double precision MODEL_EXPORT virtual boost::shared_ptr real(const std::string& theID); + /// Returns the attribute that contains integer value + MODEL_EXPORT virtual boost::shared_ptr + integer(const std::string& theID); /// Returns the attribute that contains reference to a feature MODEL_EXPORT virtual boost::shared_ptr reference(const std::string& theID); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index e10883473..d7493bb18 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -12,6 +12,7 @@ SET(PROJECT_HEADERS ModelAPI_Object.h ModelAPI_Document.h ModelAPI_Attribute.h + ModelAPI_AttributeInteger.h ModelAPI_AttributeDouble.h ModelAPI_AttributeDocRef.h ModelAPI_AttributeReference.h diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 29e75fe30..dbcb59eaf 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -12,6 +12,7 @@ #include "ModelAPI_Attribute.h" #include "ModelAPI_AttributeDocRef.h" #include "ModelAPI_AttributeDouble.h" + #include "ModelAPI_AttributeInteger.h" #include "ModelAPI_AttributeString.h" #include "ModelAPI_AttributeReference.h" #include "ModelAPI_AttributeRefAttr.h" @@ -50,6 +51,7 @@ %shared_ptr(ModelAPI_Attribute) %shared_ptr(ModelAPI_AttributeDocRef) %shared_ptr(ModelAPI_AttributeDouble) +%shared_ptr(ModelAPI_AttributeInteger) %shared_ptr(ModelAPI_AttributeString) %shared_ptr(ModelAPI_AttributeReference) %shared_ptr(ModelAPI_AttributeRefAttr) @@ -68,6 +70,7 @@ %include "ModelAPI_Attribute.h" %include "ModelAPI_AttributeDocRef.h" %include "ModelAPI_AttributeDouble.h" +%include "ModelAPI_AttributeInteger.h" %include "ModelAPI_AttributeString.h" %include "ModelAPI_AttributeReference.h" %include "ModelAPI_AttributeRefAttr.h" diff --git a/src/ModelAPI/ModelAPI_AttributeInteger.h b/src/ModelAPI/ModelAPI_AttributeInteger.h new file mode 100644 index 000000000..6e63cafe7 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeInteger.h @@ -0,0 +1,55 @@ +// File: ModelAPI_AttributeInteger.h +// Created: 2 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef MODELAPI_ATTRIBUTEINTEGER_H_ +#define MODELAPI_ATTRIBUTEINTEGER_H_ + +#include +#include + +#include + + +/**\class ModelAPI_AttributeInteger + * \ingroup DataModel + * \brief API for the attribute that contains integer (int). + */ + +class ModelAPI_AttributeInteger : public ModelAPI_Attribute +{ + public: + /// Defines the integer value + MODELAPI_EXPORT virtual void setValue(const int theValue) = 0; + + /// Returns the inhteger value + MODELAPI_EXPORT virtual int value() = 0; + + /// Returns the type of this class of attributes + MODELAPI_EXPORT static std::string type() + { + return "Integer"; + } + + /// Returns the type of this class of attributes, not static method + MODELAPI_EXPORT virtual std::string attributeType() + { + return type(); + } + + /// To virtually destroy the fields of successors + MODELAPI_EXPORT virtual ~ModelAPI_AttributeInteger() + { + } + + protected: + /// Objects are created for features automatically + MODELAPI_EXPORT ModelAPI_AttributeInteger() + { + } +}; + +//! Pointer on double attribute +typedef boost::shared_ptr AttributeIntegerPtr; + +#endif diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index b11bb66fb..ba9691136 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -11,6 +11,7 @@ #include class ModelAPI_AttributeDocRef; +class ModelAPI_AttributeInteger; class ModelAPI_AttributeDouble; class ModelAPI_AttributeReference; class ModelAPI_AttributeRefAttr; @@ -41,6 +42,8 @@ class MODELAPI_EXPORT ModelAPI_Data virtual boost::shared_ptr docRef(const std::string& theID) = 0; /// Returns the attribute that contains real value with double precision virtual boost::shared_ptr real(const std::string& theID) = 0; + /// Returns the attribute that contains integer value + virtual boost::shared_ptr integer(const std::string& theID) = 0; /// Returns the attribute that contains reference to a feature virtual boost::shared_ptr reference(const std::string& theID) = 0; /// Returns the attribute that contains reference to an attribute of a feature diff --git a/src/ModelAPI/ModelAPI_PluginManager.cpp b/src/ModelAPI/ModelAPI_PluginManager.cpp index 35048c425..52f14deba 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.cpp +++ b/src/ModelAPI/ModelAPI_PluginManager.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include