From 5ee0ac732ede71b1a7784be6870c5f21f6782565 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 19 May 2015 09:29:35 +0300 Subject: [PATCH] Linux compilation and isPreviewNeeded method implementation. --- src/Model/Model_Objects.cpp | 2 +- src/Model/Model_Objects.h | 2 +- src/Model/Model_Update.cpp | 62 ++++++++++++++++++++----------- src/Model/Model_Update.h | 4 ++ src/ModelAPI/ModelAPI_Feature.cpp | 5 +++ src/ModelAPI/ModelAPI_Feature.h | 5 +++ 6 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 0f661c874..e87508864 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -299,7 +299,7 @@ void Model_Objects::updateHistory(const std::string theGroup) myHistory.erase(aHIter); // erase from map => this means that it is not synchronized } -FeaturePtr Model_Objects::feature(TDF_Label& theLabel) const +FeaturePtr Model_Objects::feature(TDF_Label theLabel) const { if (myFeatures.IsBound(theLabel)) return myFeatures.Find(theLabel); diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index 06848a858..148c1c22a 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -53,7 +53,7 @@ class Model_Objects //! Returns the existing feature by the label //! \param theLabel base label of the feature - FeaturePtr feature(TDF_Label& theLabel) const; + FeaturePtr feature(TDF_Label theLabel) const; //! Returns the existing object: result or feature //! \param theLabel base label of the object diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index faa0ec14b..c560fa4ba 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -111,8 +111,19 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag for(; aCreatedIter != myJustCreated.end(); aCreatedIter++) { FeaturePtr aFeature = std::dynamic_pointer_cast(*aCreatedIter); - if (aFeature.get() && aFeature->isMacro()) { - aFeature->document()->removeFeature(aFeature); + if (aFeature.get()) { + // execute not-previewed feature on "apply" + if (!aFeature->isPreviewNeeded() && (myJustCreated.find(aFeature) != myJustCreated.end() || + myJustUpdated.find(aFeature) != myJustUpdated.end())) { + static ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators(); + if (aFactory->validate(aFeature)) { + executeFeature(aFeature); + } + } + // remove macro on apply + if (aFeature->isMacro()) { + aFeature->document()->removeFeature(aFeature); + } } } myJustCreated.clear(); @@ -346,33 +357,16 @@ void Model_Update::updateFeature(FeaturePtr theFeature) //std::cout<<"Update feature "<getKind()<<" must be updated = "<(theFeature->document())->executeFeatures() || - !theFeature->isPersistentResult()) { + if ((std::dynamic_pointer_cast(theFeature->document())->executeFeatures() || + !theFeature->isPersistentResult()) && theFeature->isPreviewNeeded()) { if (aFactory->validate(theFeature)) { if (myIsAutomatic || (myJustCreated.find(theFeature) != myJustCreated.end() || !theFeature->isPersistentResult() /* execute quick, not persistent results */)) { - // execute in try-catch to avoid internal problems of the feature if (aState == ModelAPI_StateDone || aState == ModelAPI_StateMustBeUpdated) { - theFeature->data()->execState(ModelAPI_StateDone); - try { - theFeature->execute(); - if (theFeature->data()->execState() != ModelAPI_StateDone) { - aState = ModelAPI_StateExecFailed; - } else { - aState = ModelAPI_StateDone; - } - } catch(...) { - aState = ModelAPI_StateExecFailed; - Events_Error::send( - "Feature " + theFeature->getKind() + " has failed during the execution"); - } - } - if (aState != ModelAPI_StateDone) { - theFeature->eraseResults(); + executeFeature(theFeature); } - redisplayWithResults(theFeature, aState); } else { // must be updatet, but not updated yet theFeature->data()->execState(ModelAPI_StateMustBeUpdated); const std::list >& aResults = theFeature->results(); @@ -392,3 +386,27 @@ void Model_Update::updateFeature(FeaturePtr theFeature) } } } + +void Model_Update::executeFeature(FeaturePtr theFeature) +{ + // execute in try-catch to avoid internal problems of the feature + ModelAPI_ExecState aState = ModelAPI_StateDone; + theFeature->data()->execState(ModelAPI_StateDone); + try { + theFeature->execute(); + if (theFeature->data()->execState() != ModelAPI_StateDone) { + aState = ModelAPI_StateExecFailed; + } else { + aState = ModelAPI_StateDone; + } + } catch(...) { + aState = ModelAPI_StateExecFailed; + Events_Error::send( + "Feature " + theFeature->getKind() + " has failed during the execution"); + } + if (aState != ModelAPI_StateDone) { + theFeature->eraseResults(); + } + redisplayWithResults(theFeature, aState); +} + diff --git a/src/Model/Model_Update.h b/src/Model/Model_Update.h index 89141313b..22fe573b9 100644 --- a/src/Model/Model_Update.h +++ b/src/Model/Model_Update.h @@ -56,6 +56,10 @@ protected: /// On operation start/end/abort the "Just" fileds must be cleared and processed in the right way /// \param theTotalUpdate force to updates everything that has been changed in this operation void processOperation(const bool theTotalUpdate); + + /// Performs the feature execution + /// \returns the status of execution + void executeFeature(std::shared_ptr theFeature); }; #endif diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index e7c16599a..3a85d388a 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -146,3 +146,8 @@ bool ModelAPI_Feature::isDisabled() const { return myIsDisabled; } + +bool ModelAPI_Feature::isPreviewNeeded() const +{ + return true; +} diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index c2f34865b..72d58660d 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -104,6 +104,11 @@ class ModelAPI_Feature : public ModelAPI_Object /// \returns false by default MODELAPI_EXPORT virtual bool isMacro() const; + /// Returns true if preview update during the edition needed. Otherwise the update-mechanism + /// calls the \a execute function only on "apply" of the operation + /// \returns true by default + MODELAPI_EXPORT virtual bool isPreviewNeeded() const; + /// Must return document where the new feature must be added to /// By default it is empty: it is added to the document this method is called to MODELAPI_EXPORT virtual const std::string& documentToAdd(); -- 2.39.2