ADD_DEFINITIONS(-DGEOMDATA_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
ADD_LIBRARY(GeomData SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI GeomAPI)
+TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI GeomAPI Events)
INCLUDE_DIRECTORIES(
../ModelAPI
../GeomAPI
../Events
../Config
+ ../Model
${CAS_INCLUDE_DIRS}
)
#include "GeomData_Dir.h"
#include "GeomAPI_Dir.h"
#include <gp_Dir.hxx>
+#include "Model_Events.h"
+#include <Events_Loop.h>
using namespace std;
void GeomData_Dir::setValue(const double theX, const double theY, const double theZ)
{
- myCoords->SetValue(0, theX);
- myCoords->SetValue(1, theY);
- myCoords->SetValue(2, theZ);
+ if (myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) {
+ myCoords->SetValue(0, theX);
+ myCoords->SetValue(1, theY);
+ myCoords->SetValue(2, theZ);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
+ Events_Loop::loop()->send(aMsg);
+ }
}
double GeomData_Dir::x() const
// Author: Mikhail PONIKAROV
#include "GeomData_Point.h"
+#include "Model_Events.h"
+#include <Events_Loop.h>
using namespace std;
void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
{
- myCoords->SetValue(0, theX);
- myCoords->SetValue(1, theY);
- myCoords->SetValue(2, theZ);
+ if (myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) {
+ myCoords->SetValue(0, theX);
+ myCoords->SetValue(1, theY);
+ myCoords->SetValue(2, theZ);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
+ Events_Loop::loop()->send(aMsg);
+ }
}
double GeomData_Point::x() const
// Author: Mikhail PONIKAROV
#include "GeomData_Point2D.h"
+#include "Model_Events.h"
+#include <Events_Loop.h>
using namespace std;
void GeomData_Point2D::setValue(const double theX, const double theY)
{
- myCoords->SetValue(0, theX);
- myCoords->SetValue(1, theY);
+ if (myCoords->Value(0) != theX || myCoords->Value(1) != theY) {
+ myCoords->SetValue(0, theX);
+ myCoords->SetValue(1, theY);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
+ Events_Loop::loop()->send(aMsg);
+ }
}
double GeomData_Point2D::x() const
#include "Model_AttributeDocRef.h"
#include "Model_Application.h"
+#include "Model_Events.h"
+#include <Events_Loop.h>
using namespace std;
void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc)
{
- myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
+ TCollection_ExtendedString aNewID(theDoc->id().c_str());
+ if (myComment->Get() != aNewID) {
+ myComment->Set(TCollection_ExtendedString(theDoc->id().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_Document> Model_AttributeDocRef::value()
// Author: Mikhail PONIKAROV
#include "Model_AttributeDouble.h"
+#include "Model_Events.h"
+#include <Events_Loop.h>
using namespace std;
void Model_AttributeDouble::setValue(const double theValue)
{
- myReal->Set(theValue);
+ if (myReal->Get() != theValue) {
+ myReal->Set(theValue);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
+ Events_Loop::loop()->send(aMsg);
+ }
}
double Model_AttributeDouble::value()
else if (theAttrType == GeomData_Point2D::type())
anAttr = new GeomData_Point2D(anAttrLab);
- if (anAttr)
+ if (anAttr) {
myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
+ anAttr->setFeature(myFeature);
+ }
else
; // TODO: generate error on unknown attribute request and/or add mechanism for customization
}
#include <map>
class ModelAPI_Attribute;
+class ModelAPI_Feature;
/**\class Model_Data
* \ingroup DataModel
/// All attributes of the object identified by the attribute ID
std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> > myAttrs;
- boost::shared_ptr<ModelAPI_Document> myDoc; ///< document this feature belongs to
+ /// needed here to emit signal that feature changed on change of the attribute
+ boost::shared_ptr<ModelAPI_Feature> myFeature;
Model_Data();
/// \param theAttrType type of the created attribute (received from the type method)
MODEL_EXPORT virtual void addAttribute(std::string theID, std::string theAttrType);
- /// Returns the document of this data
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document() {return myDoc;}
-
/// Puts feature to the document data sub-structure
MODEL_EXPORT void setLabel(TDF_Label& theLab);
- /// Sets the document of this data
- MODEL_EXPORT virtual void setDocument(const boost::shared_ptr<ModelAPI_Document>& theDoc) {myDoc = theDoc;}
+ /// Sets the feature of this data
+ MODEL_EXPORT virtual void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+ {myFeature = theFeature;}
};
#endif
TDF_Label aGroupLab = groupLabel(aGroup);
TDF_Label anObjLab = aGroupLab.NewChild();
boost::shared_ptr<Model_Data> aData(new Model_Data);
+ aData->setFeature(theFeature);
aData->setLabel(anObjLab);
boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
- aData->setDocument(aThis);
theFeature->setData(aData);
+ theFeature->setDoc(aThis);
setUniqueName(theFeature);
theFeature->initAttributes();
// keep the feature ID to restore document later correctly
// event: feature is added
static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
- ModelAPI_FeatureUpdatedMessage aMsg(aThis, theFeature, anEvent);
+ Model_FeatureUpdatedMessage aMsg(theFeature, anEvent);
Events_Loop::loop()->send(aMsg);
}
int Model_Document::featureIndex(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
- if (theFeature->data()->document().get() != this) {
- return theFeature->data()->document()->featureIndex(theFeature);
+ if (theFeature->document().get() != this) {
+ return theFeature->document()->featureIndex(theFeature);
}
boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
Handle(TDataStd_Integer) aFeatureIndex;
myGroups.erase(aGroupName);
aGroupNamesIter = myGroupsNames.erase(aGroupNamesIter);
// say that features were deleted from group
- ModelAPI_FeatureDeletedMessage aMsg(aThis, aGroupName);
+ Model_FeatureDeletedMessage aMsg(aThis, aGroupName);
Events_Loop::loop()->send(aMsg);
}
// create new groups basing on the following data model update
if (aDSTag > aFeatureTag) { // feature is removed
aFIter = aFeatures.erase(aFIter);
// event: model is updated
- ModelAPI_FeatureDeletedMessage aMsg(aThis, aGroupName);
+ Model_FeatureDeletedMessage aMsg(aThis, aGroupName);
Events_Loop::loop()->send(aMsg);
} else if (aDSTag < aFeatureTag) { // a new feature is inserted
// create a feature
boost::shared_ptr<Model_Data> aData(new Model_Data);
TDF_Label aLab = aFLabIter.Value()->Label();
aData->setLabel(aLab);
- aData->setDocument(Model_Application::getApplication()->getDocument(myID));
+ aData->setFeature(aFeature);
+ aFeature->setDoc(aThis);
aFeature->setData(aData);
aFeature->initAttributes();
// event: model is updated
static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
- ModelAPI_FeatureUpdatedMessage aMsg(aThis, aFeature, anEvent);
+ Model_FeatureUpdatedMessage aMsg(aFeature, anEvent);
Events_Loop::loop()->send(aMsg);
if (aFIter == aFeatures.end()) {
#include <Model_Events.h>
#include <Events_Loop.h>
-ModelAPI_FeatureUpdatedMessage::ModelAPI_FeatureUpdatedMessage(
- const boost::shared_ptr<ModelAPI_Document>& theDoc,
- const boost::shared_ptr<ModelAPI_Feature>& theFeature, const Events_ID& theEvent)
- : Events_Message(theEvent, 0), myFeature(theFeature), myDoc(theDoc)
-{}
-
-ModelAPI_FeatureDeletedMessage::ModelAPI_FeatureDeletedMessage(
+Model_FeatureDeletedMessage::Model_FeatureDeletedMessage(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
: Events_Message(messageId(), 0), myDoc(theDoc), myGroup(theGroup)
{
}
-const Events_ID ModelAPI_FeatureDeletedMessage::messageId()
+const Events_ID Model_FeatureDeletedMessage::messageId()
{
static Events_ID MY_ID = Events_Loop::eventByName(EVENT_FEATURE_DELETED);
return MY_ID;
static const char * EVENT_FEATURE_DELETED = "FeatureDeleted";
/// Message that feature was changed (used for Object Browser update)
-class ModelAPI_FeatureUpdatedMessage : public Events_Message {
- boost::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
+class Model_FeatureUpdatedMessage : public Events_Message {
boost::shared_ptr<ModelAPI_Feature> myFeature; ///< which feature is changed
public:
/// sender is not important, all information is located in the feature
- ModelAPI_FeatureUpdatedMessage(
- const boost::shared_ptr<ModelAPI_Document>& theDoc,
+ Model_FeatureUpdatedMessage(
const boost::shared_ptr<ModelAPI_Feature>& theFeature,
- const Events_ID& theEvent);
+ const Events_ID& theEvent) : Events_Message(theEvent, 0), myFeature(theFeature)
+ {}
/// Returns the feature that has been updated
boost::shared_ptr<ModelAPI_Feature> feature() const {return myFeature;}
- /// Returns the document that has been updated
- boost::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
};
/// Message that feature was deleted (used for Object Browser update)
-class ModelAPI_FeatureDeletedMessage : public Events_Message {
+class Model_FeatureDeletedMessage : public Events_Message {
boost::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
std::string myGroup; ///< group identifier that contained the deleted feature
public:
/// creates a message by initialization of fields
- ModelAPI_FeatureDeletedMessage(const boost::shared_ptr<ModelAPI_Document>& theDoc,
+ Model_FeatureDeletedMessage(const boost::shared_ptr<ModelAPI_Document>& theDoc,
const std::string& theGroup);
/// Returns the ID of this message (EVENT_FEATURE_DELETED)
#include "ModelAPI.h"
#include <string>
+#include <boost/shared_ptr.hpp>
+
+class ModelAPI_Feature;
/**\class ModelAPI_Attribute
* \ingroup DataModel
* \brief Generic attribute of the Object.
*/
-class MODELAPI_EXPORT ModelAPI_Attribute
+class ModelAPI_Attribute
{
+ ///< needed here to emit signal that feature changed on change of the attribute
+ boost::shared_ptr<ModelAPI_Feature> myFeature;
public:
/// Returns the type of this class of attributes, not static method
- virtual std::string attributeType() = 0;
+ MODELAPI_EXPORT virtual std::string attributeType() = 0;
/// To virtually destroy the fields of successors
- virtual ~ModelAPI_Attribute() {}
+ MODELAPI_EXPORT virtual ~ModelAPI_Attribute() {}
+
+ MODELAPI_EXPORT void setFeature(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+ {myFeature = theFeature;}
+ MODELAPI_EXPORT const boost::shared_ptr<ModelAPI_Feature>& feature()
+ {return myFeature;}
protected:
/// Objects are created for features automatically
ModelAPI_Attribute(){}
* \brief Attribute that contains reference to another document.
*/
-class MODELAPI_EXPORT ModelAPI_AttributeDocRef : public ModelAPI_Attribute
+class ModelAPI_AttributeDocRef : public ModelAPI_Attribute
{
public:
/// Defines the document referenced from this attribute
- virtual void setValue(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
+ MODELAPI_EXPORT virtual void setValue(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
/// Returns document referenced from this attribute
- virtual boost::shared_ptr<ModelAPI_Document> value() = 0;
+ MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> value() = 0;
/// Returns the type of this class of attributes
- static std::string type() {return "DocRef";}
+ MODELAPI_EXPORT static std::string type() {return "DocRef";}
/// Returns the type of this class of attributes, not static method
- virtual std::string attributeType() {return type();}
+ MODELAPI_EXPORT virtual std::string attributeType() {return type();}
/// To virtually destroy the fields of successors
- virtual ~ModelAPI_AttributeDocRef() {}
+ MODELAPI_EXPORT virtual ~ModelAPI_AttributeDocRef() {}
protected:
/// Objects are created for features automatically
- ModelAPI_AttributeDocRef()
+ MODELAPI_EXPORT ModelAPI_AttributeDocRef()
{}
};
* \brief Attribute that contains real value with double precision.
*/
-class MODELAPI_EXPORT ModelAPI_AttributeDouble : public ModelAPI_Attribute
+class ModelAPI_AttributeDouble : public ModelAPI_Attribute
{
public:
/// Defines the double value
- virtual void setValue(const double theValue) = 0;
+ MODELAPI_EXPORT virtual void setValue(const double theValue) = 0;
/// Returns the double value
- virtual double value() = 0;
+ MODELAPI_EXPORT virtual double value() = 0;
/// Returns the type of this class of attributes
- static std::string type() {return "Double";}
+ MODELAPI_EXPORT static std::string type() {return "Double";}
/// Returns the type of this class of attributes, not static method
- virtual std::string attributeType() {return type();}
+ MODELAPI_EXPORT virtual std::string attributeType() {return type();}
/// To virtually destroy the fields of successors
- virtual ~ModelAPI_AttributeDouble() {}
+ MODELAPI_EXPORT virtual ~ModelAPI_AttributeDouble() {}
protected:
/// Objects are created for features automatically
- ModelAPI_AttributeDouble()
+ MODELAPI_EXPORT ModelAPI_AttributeDouble()
{}
};
/// \param theAttrType type of the created attribute (received from the type method)
virtual void addAttribute(std::string theID, std::string theAttrType) = 0;
- /// Returns the document of this data
- virtual boost::shared_ptr<ModelAPI_Document> document() = 0;
-
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Data() {}
class ModelAPI_Feature
{
boost::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
+ boost::shared_ptr<ModelAPI_Document> myDoc; ///< document this feature belongs to
public:
/// Returns the kind of a feature (like "Point")
MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> documentToAdd()
{return ModelAPI_PluginManager::get()->currentDocument();}
+ /// Returns document this feature belongs to
+ MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
+ {return myDoc;}
+
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Feature() {}
/// Sets the data manager of an object (document does)
MODELAPI_EXPORT void setData(boost::shared_ptr<ModelAPI_Data> theData) {myData = theData;}
+ /// Sets the data manager of an object (document does)
+ MODELAPI_EXPORT void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc) {myDoc = theDoc;}
+
friend class Model_Document;
};
{
// Created object event *******************
if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_CREATED) {
- const ModelAPI_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
- boost::shared_ptr<ModelAPI_Document> aDoc = aUpdMsg->document();
+ const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
+ boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
if (aDoc == myDocument) { // If root objects
if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Updsate only Parts group
// Deteted object event ***********************
} else if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_DELETED) {
- const ModelAPI_FeatureDeletedMessage* aUpdMsg = dynamic_cast<const ModelAPI_FeatureDeletedMessage*>(theMessage);
+ const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
boost::shared_ptr<ModelAPI_Document> aDoc = aUpdMsg->document();
if (aDoc == myDocument) { // If root objects