Model_Data.h
Model_AttributeDouble.h
Model_AttributeDocRef.h
+ Model_AttributeReference.h
+ Model_AttributeRefAttr.h
Model_Events.h
)
Model_Data.cpp
Model_AttributeDouble.cpp
Model_AttributeDocRef.cpp
+ Model_AttributeReference.cpp
+ Model_AttributeRefAttr.cpp
Model_Events.cpp
)
--- /dev/null
+// File: ModelAPI_AttributeRefAttr.cxx
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_AttributeRefAttr.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+#include <ModelAPI_Feature.h>
+#include <Events_Loop.h>
+
+using namespace std;
+
+void Model_AttributeRefAttr::setValue(boost::shared_ptr<ModelAPI_Attribute> theAttr)
+{
+ if (value() != theAttr) {
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(theAttr->feature()->data());
+ if (myRef.IsNull()) {
+ boost::shared_ptr<Model_Data> aMyData =
+ boost::dynamic_pointer_cast<Model_Data>(feature()->data());
+ TDF_Reference::Set(aMyData->label(), aData->label());
+ } else {
+ myRef->Set(aData->label());
+ }
+ myID->Set(aData->id(theAttr).c_str());
+
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
+ Events_Loop::loop()->send(aMsg);
+ }
+}
+
+boost::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::value()
+{
+ if (!myRef.IsNull()) {
+ boost::shared_ptr<Model_Document> aDoc =
+ boost::dynamic_pointer_cast<Model_Document>(feature()->document());
+ if (aDoc) {
+ TDF_Label aRefLab = myRef->Get();
+ TDF_Label aFeatureLab = aRefLab.Father();
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(aDoc->feature(aRefLab)->data());
+ return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString());
+ }
+ }
+ // not initialized
+ return boost::shared_ptr<ModelAPI_Attribute>();
+}
+
+Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myID)) {
+ // create attribute: not initialized by value yet
+ TDataStd_Comment::Set(theLabel, "");
+ // reference attribute is not set to the label!
+ }
+}
--- /dev/null
+// File: Model_AttributeRefAttr.h
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_AttributeRefAttr_HeaderFile
+#define Model_AttributeRefAttr_HeaderFile
+
+#include "Model.h"
+#include "ModelAPI_AttributeRefAttr.h"
+#include <TDF_Label.hxx>
+#include <TDF_Reference.hxx>
+#include <TDataStd_Comment.hxx>
+
+/**\class Model_AttributeRefAttr
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to an attribute of a feature
+ * (located in the same document).
+ */
+
+class Model_AttributeRefAttr : public ModelAPI_AttributeRefAttr
+{
+ Handle_TDF_Reference myRef; ///< reference to the feature label
+ Handle_TDataStd_Comment myID; ///< ID of the referenced attirbute
+public:
+ /// Defines the attribute referenced from this attribute
+ MODEL_EXPORT virtual void setValue(boost::shared_ptr<ModelAPI_Attribute> theAttr);
+
+ /// Returns attribute referenced from this attribute
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> value();
+
+protected:
+ /// Objects are created for features automatically
+ MODEL_EXPORT Model_AttributeRefAttr(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
--- /dev/null
+// File: ModelAPI_AttributeReference.cxx
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_AttributeReference.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+#include <ModelAPI_Feature.h>
+#include <Events_Loop.h>
+
+using namespace std;
+
+void Model_AttributeReference::setValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ if (value() != theFeature) {
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ if (myRef.IsNull()) {
+ boost::shared_ptr<Model_Data> aMyData =
+ boost::dynamic_pointer_cast<Model_Data>(feature()->data());
+ TDF_Reference::Set(aMyData->label(), aData->label());
+ } else {
+ myRef->Set(aData->label());
+ }
+
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
+ Events_Loop::loop()->send(aMsg);
+ }
+}
+
+boost::shared_ptr<ModelAPI_Feature> Model_AttributeReference::value()
+{
+ if (!myRef.IsNull()) {
+ boost::shared_ptr<Model_Document> aDoc =
+ boost::dynamic_pointer_cast<Model_Document>(feature()->document());
+ if (aDoc) {
+ TDF_Label aRefLab = myRef->Get();
+ return aDoc->feature(aRefLab);
+ }
+ }
+ // not initialized
+ return boost::shared_ptr<ModelAPI_Feature>();
+}
+
+Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDF_Reference::GetID(), myRef)) {
+ // create attribute: not initialized by value yet: attribute is not set to the label!
+ }
+}
--- /dev/null
+// File: Model_AttributeReference.h
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_AttributeReference_HeaderFile
+#define Model_AttributeReference_HeaderFile
+
+#include "Model.h"
+#include "ModelAPI_AttributeReference.h"
+#include <TDF_Label.hxx>
+#include <TDF_Reference.hxx>
+
+/**\class Model_AttributeReference
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to feature (located in the same document).
+ */
+
+class Model_AttributeReference : public ModelAPI_AttributeReference
+{
+ Handle_TDF_Reference myRef; ///< references to the feature label
+public:
+ /// Defines the feature referenced from this attribute
+ MODEL_EXPORT virtual void setValue(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+ /// Returns feature referenced from this attribute
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> value();
+
+protected:
+ /// Objects are created for features automatically
+ MODEL_EXPORT Model_AttributeReference(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_Data.h>
#include <Model_AttributeDocRef.h>
#include <Model_AttributeDouble.h>
+#include <Model_AttributeReference.h>
+#include <Model_AttributeRefAttr.h>
#include <GeomData_Point.h>
#include <GeomData_Point2D.h>
#include <GeomData_Dir.h>
anAttr = new Model_AttributeDocRef(anAttrLab);
else if (theAttrType == ModelAPI_AttributeDouble::type())
anAttr = new Model_AttributeDouble(anAttrLab);
+ else if (theAttrType == ModelAPI_AttributeReference::type())
+ anAttr = new Model_AttributeReference(anAttrLab);
+ else if (theAttrType == ModelAPI_AttributeRefAttr::type())
+ anAttr = new Model_AttributeRefAttr(anAttrLab);
else if (theAttrType == GeomData_Point::type())
anAttr = new GeomData_Point(anAttrLab);
else if (theAttrType == GeomData_Dir::type())
return aRes;
}
+boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const string theID)
+{
+ map<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_AttributeReference>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeReference> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
+boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const string theID)
+{
+ map<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_AttributeRefAttr>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
{
boost::shared_ptr<ModelAPI_Attribute> aResult;
return aResult;
return myAttrs[theID];
}
+
+const string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute> theAttr)
+{
+ map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+ for(; anAttr != myAttrs.end(); anAttr++) {
+ if (anAttr->second == theAttr) return anAttr->first;
+ }
+ // not found
+ static string anEmpty;
+ return anEmpty;
+}
Model_Data();
+ /// Returns label of this feature
TDF_Label label() {return myLab;}
friend class Model_Document;
+ friend class Model_AttributeReference;
+ friend class Model_AttributeRefAttr;
public:
/// Returns the name of the feature visible by the user in the object browser
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 reference to a feature
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
+ reference(const std::string theID);
+ /// Returns the attribute that contains reference to an attribute of a feature
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
+ refattr(const std::string theID);
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID);
+ /// Identifier by the id (not fast, iteration by map)
+ /// \param theAttr attribute already created in this data
+ MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute> theAttr);
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
ModelAPI_Attribute.h
ModelAPI_AttributeDouble.h
ModelAPI_AttributeDocRef.h
+ ModelAPI_AttributeReference.h
+ ModelAPI_AttributeRefAttr.h
)
SET(PROJECT_SOURCES
#include "ModelAPI_Attribute.h"
#include "ModelAPI_AttributeDocRef.h"
#include "ModelAPI_AttributeDouble.h"
+ #include "ModelAPI_AttributeReference.h"
+ #include "ModelAPI_AttributeRefAttr.h"
%}
// to avoid error on this
%shared_ptr(ModelAPI_Attribute)
%shared_ptr(ModelAPI_AttributeDocRef)
%shared_ptr(ModelAPI_AttributeDouble)
+%shared_ptr(ModelAPI_AttributeReference)
+%shared_ptr(ModelAPI_AttributeRefAttr)
// all supported interfaces
%include "ModelAPI_Document.h"
%include "ModelAPI_Attribute.h"
%include "ModelAPI_AttributeDocRef.h"
%include "ModelAPI_AttributeDouble.h"
+%include "ModelAPI_AttributeReference.h"
+%include "ModelAPI_AttributeRefAttr.h"
--- /dev/null
+// File: ModelAPI_AttributeRefAttr.h
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeRefAttr_HeaderFile
+#define ModelAPI_AttributeRefAttr_HeaderFile
+
+#include "ModelAPI_Attribute.h"
+
+/**\class ModelAPI_AttributeRefAttr
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to an attribute of a feature
+ * (located in the same document).
+ */
+
+class ModelAPI_AttributeRefAttr : public ModelAPI_Attribute
+{
+public:
+ /// Defines the attribute referenced from this attribute
+ MODELAPI_EXPORT virtual void setValue(boost::shared_ptr<ModelAPI_Attribute> theAttr) = 0;
+
+ /// Returns attribute referenced from this attribute
+ MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> value() = 0;
+
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string type() {return "RefAttr";}
+
+ /// 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_AttributeRefAttr() {}
+
+protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeRefAttr()
+ {}
+};
+
+#endif
--- /dev/null
+// File: ModelAPI_AttributeReference.h
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeReference_HeaderFile
+#define ModelAPI_AttributeReference_HeaderFile
+
+#include "ModelAPI_Attribute.h"
+
+/**\class ModelAPI_AttributeReference
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to feature (located in the same document).
+ */
+
+class ModelAPI_AttributeReference : public ModelAPI_Attribute
+{
+public:
+ /// Defines the feature referenced from this attribute
+ MODELAPI_EXPORT virtual void setValue(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+
+ /// Returns feature referenced from this attribute
+ MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> value() = 0;
+
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string type() {return "Reference";}
+
+ /// 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_AttributeReference() {}
+
+protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeReference()
+ {}
+};
+
+#endif
class ModelAPI_AttributeDocRef;
class ModelAPI_AttributeDouble;
+class ModelAPI_AttributeReference;
+class ModelAPI_AttributeRefAttr;
class ModelAPI_Document;
class ModelAPI_Attribute;
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 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
+ virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string theID) = 0;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID) = 0;
+ /// Identifier by the id (not fast, iteration by map)
+ /// \param theAttr attribute already created in this data
+ virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute> theAttr) = 0;
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
#include <ModelAPI_Attribute.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeRefAttr.h>
#ifdef WIN32
#include <windows.h>