#include "GeomData_Dir.h"
#include "GeomAPI_Dir.h"
#include <gp_Dir.hxx>
-#include "Model_Events.h"
-#include <Events_Loop.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void GeomData_Dir::setValue(const double theX, const double theY, const double theZ)
{
- if (myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) {
+ if (!myIsInitialized || 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(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
void GeomData_Dir::setValue(const boost::shared_ptr<GeomAPI_Dir>& theDir)
{
setValue(theDir->x(), theDir->y(), theDir->z());
+ owner()->data()->sendAttributeUpdated(this);
}
double GeomData_Dir::x() const
GeomData_Dir::GeomData_Dir(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
}
// Author: Mikhail PONIKAROV
#include "GeomData_Point.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
#include <GeomAPI_Pnt.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
{
- if (myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) {
+ if (!myIsInitialized || 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(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
void GeomData_Point::setValue(const boost::shared_ptr<GeomAPI_Pnt>& thePoint)
{
setValue(thePoint->x(), thePoint->y(), thePoint->z());
+ owner()->data()->sendAttributeUpdated(this);
}
double GeomData_Point::x() const
GeomData_Point::GeomData_Point(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
}
// Author: Mikhail PONIKAROV
#include "GeomData_Point2D.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
#include <GeomAPI_Pnt2d.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
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(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
void GeomData_Point2D::setValue(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
{
setValue(thePoint->x(), thePoint->y());
+ owner()->data()->sendAttributeUpdated(this);
}
double GeomData_Point2D::x() const
GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myCoords = TDataStd_RealArray::Set(theLabel, 0, 1);
}
// Author: Vitaly Smetannikov
#include "Model_AttributeBoolean.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void Model_AttributeBoolean::setValue(bool theValue)
{
Standard_Boolean aValue = theValue ? Standard_True : Standard_False;
- if (myBool->Get() != aValue) {
+ if (!myIsInitialized || myBool->Get() != aValue) {
myBool->Set(aValue);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel)
{
// check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myBool)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myBool) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myBool = TDataStd_Integer::Set(theLabel, 0);
}
#include "Model_AttributeDocRef.h"
#include "Model_Application.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc)
{
TCollection_ExtendedString aNewID(theDoc->id().c_str());
- if (myComment->Get() != aNewID) {
+ if (!myIsInitialized || myComment->Get() != aNewID) {
myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just empty string
myComment = TDataStd_Comment::Set(theLabel, "");
} else { // document was already referenced: try to set it as loaded by demand
// Author: Mikhail PONIKAROV
#include "Model_AttributeDouble.h"
-#include "Model_Events.h"
-#include <Events_Loop.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
using namespace std;
void Model_AttributeDouble::setValue(const double theValue)
{
- if (myReal->Get() != theValue) {
+ if (!myIsInitialized || myReal->Get() != theValue) {
myReal->Set(theValue);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
{
// check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Real::GetID(), myReal) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
myReal = TDataStd_Real::Set(theLabel, 0.);
}
#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;
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theAttr->owner()->data());
string anID = aData->id(theAttr);
- if (feature() == theAttr->owner() && myID->Get().IsEqual(anID.c_str()))
+ if (myIsInitialized && feature() == theAttr->owner() && myID->Get().IsEqual(anID.c_str()))
return; // nothing is changed
myRef->Set(aData->label());
myID->Set(aData->id(theAttr).c_str());
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
boost::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::attr()
void Model_AttributeRefAttr::setFeature(FeaturePtr theFeature)
{
- if (myID->Get().Length() != 0 || feature() != theFeature) {
+ if (!myIsInitialized || myID->Get().Length() != 0 || feature() != theFeature) {
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
myRef->Set(aData->label());
myID->Set(""); // feature is identified by the empty ID
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
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)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True;
+ if (!myIsInitialized) {
// create attribute: not initialized by value yet
myID = TDataStd_Comment::Set(theLabel, "");
myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized: reference to itself
#include "Model_AttributeRefList.h"
#include "Model_Application.h"
-#include "Model_Events.h"
#include "Model_Data.h"
#include <ModelAPI_Feature.h>
-#include <Events_Loop.h>
#include <TDF_ListIteratorOfLabelList.hxx>
using namespace std;
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
myRef->Append(aData->label());
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
void Model_AttributeRefList::remove(FeaturePtr theFeature)
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
myRef->Remove(aData->label());
+ owner()->data()->sendAttributeUpdated(this);
}
int Model_AttributeRefList::size()
Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
{
- // check the attribute could be already presented in this doc (after load document)
- if (!theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef)) {
+ myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
+ if (!myIsInitialized) {
myRef = TDataStd_ReferenceList::Set(theLabel);
}
}
#include "Model_Events.h"
#include "Model_Data.h"
#include <ModelAPI_Feature.h>
-#include <Events_Loop.h>
using namespace std;
void Model_AttributeReference::setValue(FeaturePtr theFeature)
{
- if (value() != theFeature) {
+ if (!myIsInitialized || value() != theFeature) {
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
if (myRef.IsNull()) {
} else {
myRef->Set(aData->label());
}
-
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
- Events_Loop::loop()->send(aMsg);
+ owner()->data()->sendAttributeUpdated(this);
}
}
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!
- }
+ // not initialized by value yet: attribute is not set to the label!
+ myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
}
return !myLab.IsNull() && myLab.HasAttribute();
}
+list<boost::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const string theType)
+{
+ list<boost::shared_ptr<ModelAPI_Attribute> > aResult;
+ map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter = myAttrs.begin();
+ for(; anAttrsIter != myAttrs.end(); anAttrsIter++) {
+ if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
+ }
+ }
+ return aResult;
+}
+
+void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
+{
+ theAttr->setInitialized();
+ static const Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(myFeature, anEvent);
+ Events_Loop::loop()->send(aMsg);
+}
+
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TopoDS_Shape.hxx>
/// 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);
+ /// Returns all attributes ofthe feature of the given type
+ /// or all attributes if "theType" is empty
+ MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
+ attributes(const std::string theType);
+
/// 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);
/// \param theAttrType type of the created attribute (received from the type method)
MODEL_EXPORT virtual void addAttribute(std::string theID, std::string theAttrType);
+ /// Useful method for "set" methods of the attributes: sends an UPDATE event and
+ /// makes attribute initialized
+ MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
+
/// Puts feature to the document data sub-structure
MODEL_EXPORT void setLabel(TDF_Label& theLab);
{
///< needed here to emit signal that feature changed on change of the attribute
boost::shared_ptr<ModelAPI_Feature> myFeature;
+protected: // accessible from the attributes
+ bool myIsInitialized;
public:
/// Returns the type of this class of attributes, not static method
/// Returns the owner of this attribute
MODELAPI_EXPORT const boost::shared_ptr<ModelAPI_Feature>& owner()
{return myFeature;}
+
+ /// Returns true if attribute was initialized by some value
+ MODELAPI_EXPORT bool isInitialized() {return myIsInitialized;}
+
+ /// Makes attribute initialized
+ MODELAPI_EXPORT void setInitialized() {myIsInitialized = true;}
+
protected:
/// Objects are created for features automatically
- ModelAPI_Attribute(){}
+ ModelAPI_Attribute() {myIsInitialized = false;}
};
#include "ModelAPI.h"
#include <string>
+#include <list>
#include <boost/shared_ptr.hpp>
class ModelAPI_AttributeDocRef;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID) = 0;
+ /// Returns all attributes ofthe feature of the given type
+ /// or all attributes if "theType" is empty
+ virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
+ attributes(const std::string theType) = 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;
/// \param theAttrType type of the created attribute (received from the type method)
virtual void addAttribute(std::string theID, std::string theAttrType) = 0;
+ /// Useful method for "set" methods of the attributes: sends an UPDATE event and
+ /// makes attribute initialized
+ virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
+
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Data() {}