Model_AttributeRefList.h
Model_AttributeBoolean.h
Model_AttributeString.h
+ Model_AttributeInteger.h
Model_Events.h
Model_Update.h
Model_Validator.h
Model_AttributeRefList.cpp
Model_AttributeBoolean.cpp
Model_AttributeString.cpp
+ Model_AttributeInteger.cpp
Model_Events.cpp
Model_Update.cpp
Model_Validator.cpp
--- /dev/null
+// File: Model_AttributeInteger.cpp
+// Created: 03 sep 2014
+// Author: sbh
+
+#include <Model_AttributeInteger.h>
+
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TDataStd_Integer.hxx>
+
+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);
+ }
+}
--- /dev/null
+// File: Model_AttributeInteger.h
+// Created: 03 sep 2014
+// Author: sbh
+
+#ifndef MODEL_ATTRIBUTEINTEGER_H_
+#define MODEL_ATTRIBUTEINTEGER_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeInteger.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_Integer.hxx>
+
+/**\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
// File: Model_AttributeString.cpp
-// Created: 2 june 2014
-// Author: Vitaly Smetannikov
+// Created: 25 august 2014
+// Author: sbh
#include <Model_AttributeString.h>
#include <ModelAPI_AttributeString.h>
// 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 <Model.h>
#include <ModelAPI_AttributeString.h>
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:
#include <Model_Data.h>
#include <Model_AttributeDocRef.h>
+#include <Model_AttributeInteger.h>
#include <Model_AttributeDouble.h>
#include <Model_AttributeReference.h>
#include <Model_AttributeRefAttr.h>
#include <TDataStd_Name.hxx>
+#include <string>
+
Model_Data::Model_Data()
{
}
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()) {
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<ModelAPI_Attribute>(anAttr);
return aRes;
}
+boost::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::string& theID)
+{
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::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<ModelAPI_AttributeInteger>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeInteger> aRes = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeInteger>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string& theID)
{
std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefList.h>
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string& theID);
/// Returns the attribute that contains real value with double precision
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
+ /// Returns the attribute that contains integer value
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeInteger>
+ integer(const std::string& theID);
/// Returns the attribute that contains reference to a feature
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
reference(const std::string& theID);
ModelAPI_Object.h
ModelAPI_Document.h
ModelAPI_Attribute.h
+ ModelAPI_AttributeInteger.h
ModelAPI_AttributeDouble.h
ModelAPI_AttributeDocRef.h
ModelAPI_AttributeReference.h
#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"
%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)
%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"
--- /dev/null
+// File: ModelAPI_AttributeInteger.h
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef MODELAPI_ATTRIBUTEINTEGER_H_
+#define MODELAPI_ATTRIBUTEINTEGER_H_
+
+#include <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+
+/**\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<ModelAPI_AttributeInteger> AttributeIntegerPtr;
+
+#endif
#include <boost/shared_ptr.hpp>
class ModelAPI_AttributeDocRef;
+class ModelAPI_AttributeInteger;
class ModelAPI_AttributeDouble;
class ModelAPI_AttributeReference;
class ModelAPI_AttributeRefAttr;
virtual boost::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string& theID) = 0;
/// Returns the attribute that contains real value with double precision
virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
+ /// Returns the attribute that contains integer value
+ virtual boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
/// Returns the attribute that contains reference to a feature
virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
/// Returns the attribute that contains reference to an attribute of a feature
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefAttr.h>