From 932fc1c1622a107f55ab03b3242691961ef28c76 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 5 Apr 2017 14:29:53 +0300 Subject: [PATCH] Fixes for issue #1936, issue #1956, issue #2035. Undo of Part delete restores the part, but to go inside and make it filled, it is necessary to activate the part first. --- src/Model/Model_Document.cpp | 6 ++++++ src/Model/Model_Document.h | 4 ++++ src/Model/Model_Objects.cpp | 11 +++++++++-- src/Model/Model_Objects.h | 3 +++ src/ModelAPI/ModelAPI_Document.h | 3 +++ src/PartSetPlugin/PartSetPlugin_Part.cpp | 9 +++++++++ src/PartSetPlugin/PartSetPlugin_Part.h | 3 +++ 7 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 7c93ab7b5..bf263768d 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -1629,3 +1629,9 @@ void Model_Document::restoreNodesState(std::list& theStates) const } } } + +void Model_Document::eraseAllFeatures() +{ + if (myObjs) + myObjs->eraseAllFeatures(); +} diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 639d84b0b..6d9c58b98 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -225,6 +225,10 @@ class Model_Document : public ModelAPI_Document /// Returns true if theLater is in history of features creation later than theCurrent MODEL_EXPORT virtual bool isLater(FeaturePtr theLater, FeaturePtr theCurrent) const; + /// Just removes all features without touching the document data (to be able undo) + MODEL_EXPORT virtual void eraseAllFeatures(); + + protected: //! Returns (creates if needed) the general label TDF_Label generalLabel() const; diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index f635941b3..b0964875d 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -269,6 +269,13 @@ void Model_Objects::removeFeature(FeaturePtr theFeature) } } +void Model_Objects::eraseAllFeatures() +{ + ModelAPI_EventCreator::get()->sendDeleted(myDoc, ModelAPI_Feature::group()); + myFeatures.Clear(); // just remove features without modification of DS + updateHistory(ModelAPI_Feature::group()); +} + void Model_Objects::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis) { TDF_Label aFeaturesLab = featuresLabel(); @@ -667,7 +674,7 @@ void Model_Objects::synchronizeFeatures( aFeature = myFeatures.Find(aFeatureLabel); aKeptFeatures.insert(aFeature); if (anUpdatedMap.Contains(aFeatureLabel)) { - if (!theOpen) { // on abort/undo/redo reinitialize attributes is something is changed + if (!theOpen) { // on abort/undo/redo reinitialize attributes if something is changed std::list > anAttrs = aFeature->data()->attributes(""); std::list >::iterator anAttr = anAttrs.begin(); @@ -1073,7 +1080,7 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set& t theProcessed.insert(theFeature); // for composites update subs recursively (sketch elements results are needed for the sketch) CompositeFeaturePtr aComp = std::dynamic_pointer_cast(theFeature); - if (aComp.get()) { + if (aComp.get() && aComp->getKind() != "Part") { // don't go inside of parts sub-features // update subs of composites first int aSubNum = aComp->numberOfSubs(); for(int a = 0; a < aSubNum; a++) { diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index c4bc24476..45b2ed0ba 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -212,6 +212,9 @@ class Model_Objects void synchronizeBackRefsForObject( const std::set>& theNewRefs, ObjectPtr theObject); + /// Just removes all features without touching the document data (to be able undo) + virtual void eraseAllFeatures(); + private: TDF_Label myMain; ///< main label of the data storage diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 427b33267..3d4d75f7f 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -184,6 +184,9 @@ public: /// Appends the values to theStates list. MODELAPI_EXPORT virtual void restoreNodesState(std::list& theStates) const = 0; + /// Just removes all features without touching the document data (to be able undo) + MODELAPI_EXPORT virtual void eraseAllFeatures() = 0; + protected: //! Only for SWIG wrapping it is here MODELAPI_EXPORT ModelAPI_Document(); diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 9c358dd7f..df8b64510 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -107,3 +107,12 @@ bool PartSetPlugin_Part::isSub(ObjectPtr theObject) const void PartSetPlugin_Part::removeFeature(std::shared_ptr theFeature) { } + +void PartSetPlugin_Part::erase() { + ResultPartPtr aResult = std::dynamic_pointer_cast(firstResult()); + if (aResult.get()) { + DocumentPtr aDoc = aResult->partDoc(); + aDoc->eraseAllFeatures(); + } + ModelAPI_Feature::erase(); +} diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h index 242848300..d6300ae91 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.h +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -70,6 +70,9 @@ class PartSetPlugin_Part : public ModelAPI_CompositeFeature /// Use plugin manager for features creation PartSetPlugin_Part(); + + /// Just removes all features of the part without touching the document data (to be able undo) + PARTSETPLUGIN_EXPORT virtual void erase(); }; #endif -- 2.39.2