From: mpv Date: Wed, 17 Apr 2019 14:29:42 +0000 (+0300) Subject: Fix for the issue #2909 : Folder becomes empty after "export to GEOM" X-Git-Tag: V9_3_0rc2^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FV9_3_BR;p=modules%2Fshaper.git Fix for the issue #2909 : Folder becomes empty after "export to GEOM" --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 8b26c6a03..26cb173d5 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -2037,6 +2037,16 @@ void Model_Document::eraseAllFeatures() myObjs->eraseAllFeatures(); } +std::shared_ptr Model_Document::nextFeature( + std::shared_ptr theCurrent, const bool theReverse) const +{ + if (theCurrent.get() && myObjs) { + int anIndex = kUNDEFINED_FEATURE_INDEX; + return myObjs->nextFeature(theCurrent, anIndex, theReverse); + } + return FeaturePtr(); // nothing by default +} + void Model_Document::setExecuteFeatures(const bool theFlag) { myExecuteFeatures = theFlag; diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 8778402e0..a61cc6ad4 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -299,6 +299,11 @@ class Model_Document : public ModelAPI_Document /// Just removes all features without touching the document data (to be able undo) MODEL_EXPORT virtual void eraseAllFeatures(); + /// Returns the next (from the history point of view) feature, any: invisible or disabled + /// \param theCurrent previous to the resulting feature + /// \param theReverse if it is true, iterates in reversed order (next becomes previous) + MODEL_EXPORT virtual std::shared_ptr nextFeature( + std::shared_ptr theCurrent, const bool theReverse = false) const; protected: //! Returns (creates if needed) the general label diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 6e368d7e4..9cc95bad2 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -253,6 +253,12 @@ public: /// Just removes all features without touching the document data (to be able undo) MODELAPI_EXPORT virtual void eraseAllFeatures() = 0; + /// Returns the next (from the history point of view) feature, any: invisible or disabled + /// \param theCurrent previous to the resulting feature + /// \param theReverse if it is true, iterates in reversed order (next becomes previous) + MODELAPI_EXPORT virtual std::shared_ptr nextFeature( + std::shared_ptr theCurrent, const bool theReverse = false) const = 0; + protected: //! Only for SWIG wrapping it is here MODELAPI_EXPORT ModelAPI_Document(); diff --git a/src/ModelAPI/ModelAPI_Folder.cpp b/src/ModelAPI/ModelAPI_Folder.cpp index df1ac82a6..439330c9a 100644 --- a/src/ModelAPI/ModelAPI_Folder.cpp +++ b/src/ModelAPI/ModelAPI_Folder.cpp @@ -42,3 +42,16 @@ void ModelAPI_Folder::initAttributes() void ModelAPI_Folder::execute() { } + +std::shared_ptr ModelAPI_Folder::lastVisibleFeature() +{ + FeaturePtr aResult; + AttributeReferencePtr aLastFeatAttr = data()->reference(LAST_FEATURE_ID()); + if (!aLastFeatAttr.get()) + return aResult; + aResult = ModelAPI_Feature::feature(aLastFeatAttr->value()); + while(aResult.get() && !aResult->isInHistory()) { // searching for previous feature + aResult = aResult->document()->nextFeature(aResult, true); + } + return aResult; +} diff --git a/src/ModelAPI/ModelAPI_Folder.h b/src/ModelAPI/ModelAPI_Folder.h index 7945ff12d..1fd19958e 100644 --- a/src/ModelAPI/ModelAPI_Folder.h +++ b/src/ModelAPI/ModelAPI_Folder.h @@ -92,6 +92,10 @@ public: return data()->reference(theID); } + /// Returns the last visible feature in the folder, passing through invisible, + /// that may appear as the last ones. + MODELAPI_EXPORT std::shared_ptr lastVisibleFeature(); + protected: /// This method is called just after creation of the object: it must initialize /// all fields, normally initialized in the constructor diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index dcd677d5a..5779d33bb 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -772,14 +772,10 @@ void PartSet_Tools::getFirstAndLastIndexInFolder(const ObjectPtr& theFolder, if (!aFirstFeatureInFolder.get()) return; - AttributeReferencePtr aLastFeatAttr = - aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID()); - if (!aLastFeatAttr.get()) - return; - FeaturePtr aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value()); + FeaturePtr aLastFeatureInFolder = aFolder->lastVisibleFeature(); if (!aLastFeatureInFolder.get()) return; theFirst = aDoc->index(aFirstFeatureInFolder); theLast = aDoc->index(aLastFeatureInFolder); -} \ No newline at end of file +}