From 2c5d9762904d572995855e2ce2239ea0c3463eb5 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 26 May 2015 15:46:01 +0300 Subject: [PATCH] Fix for removing sketch and sub-components not correct history position was defined --- src/Model/Model_Document.cpp | 17 ++++++++++------- src/Model/Model_Document.h | 3 +++ src/Model/Model_Objects.cpp | 18 +++++++++--------- src/Model/Model_Session.cpp | 1 - src/Model/Model_Update.cpp | 5 +++-- src/ModelAPI/ModelAPI_Document.h | 2 ++ src/ModelAPI/ModelAPI_Feature.cpp | 5 +++++ 7 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 0d35b4533..a554fd599 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -171,8 +171,7 @@ bool Model_Document::load(const char* theFileName, DocumentPtr theThis) setCurrentFeature(currentFeature(false), false); aSession->setCheckTransactions(true); aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false); - // this is done in Part result "activate", so no needed here. Causes not-blue active part. - //aSession->setActiveDocument(anApp->getDocument(myID), true); + aSession->setActiveDocument(anApp->getDocument(myID), true); } return !isError; } @@ -566,11 +565,6 @@ void Model_Document::refsToFeature(FeaturePtr theFeature, void Model_Document::removeFeature(FeaturePtr theFeature) { - // if this feature is current, make the current the previous feature - if (theFeature == currentFeature(false)) { - FeaturePtr aPrev = myObjs->nextFeature(theFeature, true); - setCurrentFeature(aPrev, false); - } myObjs->removeFeature(theFeature); } @@ -721,6 +715,15 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr aLoop->flush(aRedispEvent); } +void Model_Document::setCurrentFeatureUp() +{ + FeaturePtr aCurrent = currentFeature(false); + if (aCurrent.get()) { // if not, do nothing because null is the upper + FeaturePtr aPrev = myObjs->nextFeature(aCurrent, true); + setCurrentFeature(aPrev, false); + } +} + TDF_Label Model_Document::generalLabel() const { return myDoc->Main().FindChild(TAG_GENERAL); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 127934e03..7969d1724 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -133,6 +133,9 @@ class Model_Document : public ModelAPI_Document MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr theCurrent, const bool theVisible); + //! Makes the current feature one feature upper + MODEL_EXPORT virtual void setCurrentFeatureUp(); + /// Creates a construction cresults MODEL_EXPORT virtual std::shared_ptr createConstruction( const std::shared_ptr& theFeatureData, const int theIndex = 0); diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 9ebc1e4d8..9ca1a15d4 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -203,14 +203,7 @@ void Model_Objects::refsToFeature(FeaturePtr theFeature, void Model_Objects::removeFeature(FeaturePtr theFeature) { std::shared_ptr aData = std::static_pointer_cast(theFeature->data()); - if (aData) { - TDF_Label aFeatureLabel = aData->label().Father(); - if (myFeatures.IsBound(aFeatureLabel)) - myFeatures.UnBind(aFeatureLabel); - else - return; // not found feature => do not remove - - clearHistory(theFeature); + if (aData && aData->isValid()) { // checking that the sub-element of composite feature is removed: if yes, inform the owner std::set > aRefs; refsToFeature(theFeature, aRefs, false); @@ -224,6 +217,13 @@ void Model_Objects::removeFeature(FeaturePtr theFeature) } // erase fields theFeature->erase(); + + TDF_Label aFeatureLabel = aData->label().Father(); + if (myFeatures.IsBound(aFeatureLabel)) + myFeatures.UnBind(aFeatureLabel); + + clearHistory(theFeature); + static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP); // erase all attributes under the label of feature @@ -834,7 +834,7 @@ ResultPtr Model_Objects::findByName(const std::string theName) FeaturePtr Model_Objects::nextFeature(FeaturePtr theCurrent, const bool theReverse) { std::shared_ptr aData = std::static_pointer_cast(theCurrent->data()); - if (aData) { + if (aData && aData->isValid()) { TDF_Label aFeatureLabel = aData->label().Father(); Handle(TDataStd_ReferenceArray) aRefs; if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) { diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index d5a79927c..04229f2c2 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -49,7 +49,6 @@ bool Model_Session::save(const char* theFileName, std::list& theRes void Model_Session::closeAll() { Model_Application::getApplication()->deleteAllDocuments(); - //ROOT_DOC->close(true); } void Model_Session::startOperation(const std::string& theId) diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index e710c5a87..08a7d4097 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -413,10 +413,11 @@ void Model_Update::updateFeature(FeaturePtr theFeature) if (std::dynamic_pointer_cast(theFeature->document())->executeFeatures() || !theFeature->isPersistentResult()) { if (aFactory->validate(theFeature)) { + FeaturePtr aCurrent = theFeature->document()->currentFeature(false); if (myIsAutomatic || !theFeature->isPersistentResult() /* execute quick, not persistent results */ || (isUpdated(theFeature) && - (theFeature == theFeature->document()->currentFeature(false) || - theFeature->document()->currentFeature(false)->isMacro()))) // currently edited + (theFeature == aCurrent || + (aCurrent.get() && aCurrent->isMacro())))) // currently edited { if (aState == ModelAPI_StateDone || aState == ModelAPI_StateMustBeUpdated) { executeFeature(theFeature); diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 72a69e045..5f344ea08 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -99,6 +99,8 @@ public: //! \param theVisible use visible features only: flag is true for Object Browser functionality virtual void setCurrentFeature(std::shared_ptr theCurrent, const bool theVisible) = 0; + //! Makes the current feature one feature upper + virtual void setCurrentFeatureUp() = 0; /// To virtually destroy the fields of successors MODELAPI_EXPORT virtual ~ModelAPI_Document(); diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 1fe0244f0..ba51db260 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -117,6 +117,11 @@ const std::string& ModelAPI_Feature::documentToAdd() void ModelAPI_Feature::erase() { + // if this is the current feature, make the upper feature as current before removing + if (document().get() && document()->currentFeature(false).get() == this) { + document()->setCurrentFeatureUp(); + } + static Events_Loop* aLoop = Events_Loop::loop(); static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); -- 2.39.2