From: mpv Date: Tue, 24 Jun 2014 11:58:18 +0000 (+0400) Subject: Added the initialization of attributes flag and "attributes": method that returns... X-Git-Tag: V_0.4.4~258^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cb88e1dde1ee17d21a66639ea73ac8cdee7b16eb;p=modules%2Fshaper.git Added the initialization of attributes flag and "attributes": method that returns all attributes of Data --- diff --git a/src/GeomData/GeomData_Dir.cpp b/src/GeomData/GeomData_Dir.cpp index 44f04fe30..3800c938c 100644 --- a/src/GeomData/GeomData_Dir.cpp +++ b/src/GeomData/GeomData_Dir.cpp @@ -5,26 +5,26 @@ #include "GeomData_Dir.h" #include "GeomAPI_Dir.h" #include -#include "Model_Events.h" -#include +#include +#include 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& theDir) { setValue(theDir->x(), theDir->y(), theDir->z()); + owner()->data()->sendAttributeUpdated(this); } double GeomData_Dir::x() const @@ -50,8 +50,8 @@ boost::shared_ptr GeomData_Dir::dir() 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); } diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index da6299703..db942aff6 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -3,27 +3,27 @@ // Author: Mikhail PONIKAROV #include "GeomData_Point.h" -#include "Model_Events.h" -#include #include +#include +#include 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& thePoint) { setValue(thePoint->x(), thePoint->y(), thePoint->z()); + owner()->data()->sendAttributeUpdated(this); } double GeomData_Point::x() const @@ -50,8 +50,8 @@ boost::shared_ptr GeomData_Point::pnt() 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); } diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index 334d2070a..7e6f889c4 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -3,9 +3,9 @@ // Author: Mikhail PONIKAROV #include "GeomData_Point2D.h" -#include "Model_Events.h" -#include #include +#include +#include using namespace std; @@ -14,15 +14,14 @@ void GeomData_Point2D::setValue(const double theX, const double 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(owner(), anEvent); - Events_Loop::loop()->send(aMsg); + owner()->data()->sendAttributeUpdated(this); } } void GeomData_Point2D::setValue(const boost::shared_ptr& thePoint) { setValue(thePoint->x(), thePoint->y()); + owner()->data()->sendAttributeUpdated(this); } double GeomData_Point2D::x() const @@ -44,8 +43,8 @@ boost::shared_ptr GeomData_Point2D::pnt() 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); } diff --git a/src/Model/Model_AttributeBoolean.cpp b/src/Model/Model_AttributeBoolean.cpp index 5472dadf2..07c482b07 100644 --- a/src/Model/Model_AttributeBoolean.cpp +++ b/src/Model/Model_AttributeBoolean.cpp @@ -3,19 +3,17 @@ // Author: Vitaly Smetannikov #include "Model_AttributeBoolean.h" -#include "Model_Events.h" -#include +#include +#include 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); } } @@ -27,7 +25,8 @@ bool Model_AttributeBoolean::value() 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); } diff --git a/src/Model/Model_AttributeDocRef.cpp b/src/Model/Model_AttributeDocRef.cpp index dfb307f4d..83615e30e 100644 --- a/src/Model/Model_AttributeDocRef.cpp +++ b/src/Model/Model_AttributeDocRef.cpp @@ -4,20 +4,17 @@ #include "Model_AttributeDocRef.h" #include "Model_Application.h" -#include "Model_Events.h" -#include +#include +#include using namespace std; void Model_AttributeDocRef::setValue(boost::shared_ptr 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); } } @@ -32,8 +29,8 @@ boost::shared_ptr Model_AttributeDocRef::value() 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 diff --git a/src/Model/Model_AttributeDouble.cpp b/src/Model/Model_AttributeDouble.cpp index 88b4352a5..13b976c2e 100644 --- a/src/Model/Model_AttributeDouble.cpp +++ b/src/Model/Model_AttributeDouble.cpp @@ -3,18 +3,16 @@ // Author: Mikhail PONIKAROV #include "Model_AttributeDouble.h" -#include "Model_Events.h" -#include +#include +#include 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); } } @@ -26,7 +24,8 @@ double Model_AttributeDouble::value() 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.); } diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index 397977226..24bcddec1 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -4,10 +4,8 @@ #include "Model_AttributeRefAttr.h" #include "Model_Application.h" -#include "Model_Events.h" #include "Model_Data.h" #include -#include using namespace std; @@ -21,15 +19,12 @@ void Model_AttributeRefAttr::setAttr(boost::shared_ptr theAt boost::shared_ptr aData = boost::dynamic_pointer_cast(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 Model_AttributeRefAttr::attr() @@ -46,15 +41,12 @@ boost::shared_ptr 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 aData = boost::dynamic_pointer_cast(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); } } @@ -75,8 +67,8 @@ FeaturePtr Model_AttributeRefAttr::feature() 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 diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index af4cbd3ea..9e4dc8396 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -4,10 +4,8 @@ #include "Model_AttributeRefList.h" #include "Model_Application.h" -#include "Model_Events.h" #include "Model_Data.h" #include -#include #include using namespace std; @@ -18,9 +16,7 @@ void Model_AttributeRefList::append(FeaturePtr theFeature) boost::dynamic_pointer_cast(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) @@ -29,6 +25,7 @@ void Model_AttributeRefList::remove(FeaturePtr theFeature) boost::dynamic_pointer_cast(theFeature->data()); myRef->Remove(aData->label()); + owner()->data()->sendAttributeUpdated(this); } int Model_AttributeRefList::size() @@ -52,8 +49,8 @@ list Model_AttributeRefList::list() 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); } } diff --git a/src/Model/Model_AttributeReference.cpp b/src/Model/Model_AttributeReference.cpp index adcfe4ab4..e2ff01ce7 100644 --- a/src/Model/Model_AttributeReference.cpp +++ b/src/Model/Model_AttributeReference.cpp @@ -7,13 +7,12 @@ #include "Model_Events.h" #include "Model_Data.h" #include -#include using namespace std; void Model_AttributeReference::setValue(FeaturePtr theFeature) { - if (value() != theFeature) { + if (!myIsInitialized || value() != theFeature) { boost::shared_ptr aData = boost::dynamic_pointer_cast(theFeature->data()); if (myRef.IsNull()) { @@ -23,10 +22,7 @@ void Model_AttributeReference::setValue(FeaturePtr theFeature) } 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); } } @@ -46,8 +42,6 @@ FeaturePtr Model_AttributeReference::value() 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; } diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 31f9f36a0..60b7b540e 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -207,6 +207,25 @@ bool Model_Data::isValid() return !myLab.IsNull() && myLab.HasAttribute(); } +list > Model_Data::attributes(const string theType) +{ + list > aResult; + map >::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 #include #include diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 36f5f3614..eca52e960 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -63,6 +63,11 @@ public: /// Returns the generic attribute by identifier /// \param theID identifier of the attribute MODEL_EXPORT virtual boost::shared_ptr 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 > + 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 theAttr); @@ -82,6 +87,10 @@ public: /// \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); diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index acea353df..4a15abb88 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -19,6 +19,8 @@ class ModelAPI_Attribute { ///< needed here to emit signal that feature changed on change of the attribute boost::shared_ptr myFeature; +protected: // accessible from the attributes + bool myIsInitialized; public: /// Returns the type of this class of attributes, not static method @@ -34,9 +36,16 @@ public: /// Returns the owner of this attribute MODELAPI_EXPORT const boost::shared_ptr& 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;} }; diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 76967d181..5d6e36d5f 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -7,6 +7,7 @@ #include "ModelAPI.h" #include +#include #include class ModelAPI_AttributeDocRef; @@ -51,6 +52,10 @@ public: /// Returns the generic attribute by identifier /// \param theID identifier of the attribute virtual boost::shared_ptr 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 > + 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 theAttr) = 0; @@ -70,6 +75,10 @@ public: /// \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() {}