From: mpv Date: Wed, 27 May 2015 13:54:28 +0000 (+0300) Subject: Make the expressions in double attributes and points updated after the parameter... X-Git-Tag: V_1.2.0~51 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f003def34d1a3dd56e87329920d1950f080c58d1;p=modules%2Fshaper.git Make the expressions in double attributes and points updated after the parameter value is also updated --- diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index ef48bfc28..7ae96b859 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -67,11 +67,7 @@ void GeomData_Point::setText(const std::string& theX, myTextArray->SetValue(2, aZ); owner()->data()->sendAttributeUpdated(this); // Send it to evaluator to convert into the double and store in the attribute - static Events_ID anId = ModelAPI_AttributeEvalMessage::eventId(); - std::shared_ptr aMessage = - std::shared_ptr(new ModelAPI_AttributeEvalMessage(anId, this)); - aMessage->setAttribute(owner()->data()->attribute(id())); // to get shared pointer to this - Events_Loop::loop()->send(aMessage); + ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this); } } diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index 9637c248e..e02de3eef 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -56,11 +56,7 @@ void GeomData_Point2D::setText(const std::string& theX, myTextArray->SetValue(1, aY); owner()->data()->sendAttributeUpdated(this); // Send it to evaluator to convert into the double and store in the attribute - static Events_ID anId = ModelAPI_AttributeEvalMessage::eventId(); - std::shared_ptr aMessage = - std::shared_ptr(new ModelAPI_AttributeEvalMessage(anId, this)); - aMessage->setAttribute(owner()->data()->attribute(id())); // to get shared pointer to this - Events_Loop::loop()->send(aMessage); + ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this); } } diff --git a/src/Model/Model_AttributeDouble.cpp b/src/Model/Model_AttributeDouble.cpp index 3ef3e3c41..0736eddc0 100644 --- a/src/Model/Model_AttributeDouble.cpp +++ b/src/Model/Model_AttributeDouble.cpp @@ -47,12 +47,9 @@ void Model_AttributeDouble::setText(const std::string& theValue) if (myText->Get() != aValue) { myText->Set(aValue); owner()->data()->sendAttributeUpdated(this); + // Send it to evaluator to convert into the double and store in the attribute - static Events_ID anId = ModelAPI_AttributeEvalMessage::eventId(); - std::shared_ptr aMessage = - std::shared_ptr(new ModelAPI_AttributeEvalMessage(anId, this)); - aMessage->setAttribute(owner()->data()->attribute(id())); // to get shared pointer to this - Events_Loop::loop()->send(aMessage); + ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this); } } diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 765ff1582..2b138d418 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -58,6 +58,7 @@ Model_Update::Model_Update() Config_Prop::Boolean, "false"); myIsAutomatic = Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true"; + myIsParamUpdated = false; } void Model_Update::processEvent(const std::shared_ptr& theMessage) @@ -93,6 +94,9 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag if (!std::dynamic_pointer_cast(*anObjIter).get()) { isOnlyResults = false; } + if ((*anObjIter)->groupName() == ModelAPI_ResultParameter::group()) { + myIsParamUpdated = true; + } // created objects are always must be up to date (python box feature) // and updated not in internal uptation chain if (theMessage->eventID() == kCreatedEvent) { @@ -136,6 +140,7 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag } myJustCreated.clear(); myJustUpdated.clear(); + myIsParamUpdated = false; } } @@ -275,6 +280,9 @@ void Model_Update::updateArguments(FeaturePtr theFeature) { AttributeDoublePtr aDouble = std::dynamic_pointer_cast(*aDoubleIter); if (aDouble.get() && !aDouble->text().empty()) { + if (myIsParamUpdated) { + ModelAPI_AttributeEvalMessage::send(aDouble, this); + } if (aDouble->expressionInvalid()) { aState = ModelAPI_StateInvalidArgument; } @@ -289,6 +297,9 @@ void Model_Update::updateArguments(FeaturePtr theFeature) { AttributePointPtr aPointAttribute = std::dynamic_pointer_cast(*anIter); if (aPointAttribute.get()) { + if (myIsParamUpdated) { + ModelAPI_AttributeEvalMessage::send(aPointAttribute, this); + } if ((!aPointAttribute->textX().empty() && aPointAttribute->expressionInvalid(0)) || (!aPointAttribute->textY().empty() && aPointAttribute->expressionInvalid(1)) || (!aPointAttribute->textZ().empty() && aPointAttribute->expressionInvalid(2))) @@ -305,6 +316,9 @@ void Model_Update::updateArguments(FeaturePtr theFeature) { AttributePoint2DPtr aPoint2DAttribute = std::dynamic_pointer_cast(*anIter); if (aPoint2DAttribute.get()) { + if (myIsParamUpdated) { + ModelAPI_AttributeEvalMessage::send(aPoint2DAttribute, this); + } if ((!aPoint2DAttribute->textX().empty() && aPoint2DAttribute->expressionInvalid(0)) || (!aPoint2DAttribute->textY().empty() && aPoint2DAttribute->expressionInvalid(1))) aState = ModelAPI_StateInvalidArgument; diff --git a/src/Model/Model_Update.h b/src/Model/Model_Update.h index a2d239a93..c28d30b25 100644 --- a/src/Model/Model_Update.h +++ b/src/Model/Model_Update.h @@ -31,6 +31,8 @@ class Model_Update : public Events_Listener bool myIsExecuted; /// to know execute or not automatically all update bool myIsAutomatic; + /// to know that some parameter was changed during this operation + bool myIsParamUpdated; public: /// Is called only once, on startup of the application diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 89be2d899..741aa0a8b 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -170,21 +170,33 @@ class ModelAPI_AttributeEvalMessage : public Events_Message AttributePtr myAttribute; public: - /// Creates an empty message - MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0); - /// The virtual destructor - MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage(); /// Static. Returns EventID of the message. - MODELAPI_EXPORT static Events_ID eventId() + MODELAPI_EXPORT static Events_ID& eventId() { static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest"); - return Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID); + static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID); + return anId; + } + + /// usefull method that creates and sends the AttributeEvalMessage event + MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender) + { + std::shared_ptr aMessage = + std::shared_ptr( + new ModelAPI_AttributeEvalMessage(eventId(), theSender)); + aMessage->setAttribute(theAttribute); + Events_Loop::loop()->send(aMessage); } + /// Creates an empty message + MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0); + /// The virtual destructor + MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage(); + /// Returns a document stored in the message MODELAPI_EXPORT AttributePtr attribute() const; - /// Sets a document to the message - MODELAPI_EXPORT void setAttribute(AttributePtr theDocument); + /// Sets an attribute to the message + MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute); }; #endif