From 4c763543675ec80cad142d3a2f8b4766ca64ac0f Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 24 Nov 2017 16:09:25 +0300 Subject: [PATCH] Delete folder operation --- src/ModelAPI/ModelAPI_Tools.cpp | 2 ++ src/ModuleBase/ModuleBase_Tools.cpp | 18 +++++++++++++++++- src/ModuleBase/ModuleBase_Tools.h | 8 ++++++++ src/XGUI/XGUI_DataModel.cpp | 14 +++++++------- src/XGUI/XGUI_Workshop.cpp | 15 +++++++++++++++ 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index f22b73c23..90d41f656 100755 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -382,6 +382,7 @@ bool removeFeaturesAndReferences(const std::set& theFeatures, return ModelAPI_Tools::removeFeatures(aFeatures, false); } +//*********************************************************************** bool removeFeatures(const std::set& theFeatures, const bool theFlushRedisplay) { @@ -406,6 +407,7 @@ bool removeFeatures(const std::set& theFeatures, return true; } +//*********************************************************************** // Fills the references list by all references of the feature from the references map. // This is a recusive method to find references by next found feature in the map of references. // \param theFeature a feature to find references diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 42a5381b5..32d61570b 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -1044,10 +1044,26 @@ void convertToFeatures(const QObjectPtrList& theObjects, std::set& t if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) { aFeature = ModelAPI_Feature::feature(anObject); } - theFeatures.insert(aFeature); + if (aFeature.get()) + theFeatures.insert(aFeature); + } +} + +//************************************************************** +void convertToFolders(const QObjectPtrList& theObjects, + std::set& theFolders) +{ + QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); + for(; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + FolderPtr aFeature = std::dynamic_pointer_cast(anObject); + if (aFeature.get()) + theFolders.insert(aFeature); } } + +//************************************************************** QString translate(const Events_InfoMessage& theMessage) { QString aMessage; diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 7bdaab757..8a179c25a 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -332,6 +333,13 @@ void MODULEBASE_EXPORT convertToFeatures(const QObjectPtrList& theObjects, std::set& theFeatures); +/// Converts a list of objects to set of folders. +/// \param theObjects a list of objects +/// \param theFeatures an out conteiner of features +void MODULEBASE_EXPORT convertToFolders(const QObjectPtrList& theObjects, + std::set& theFolders); + + /// Returns translation from the given data. /// If translation is not exists then it returns a string /// from the info data without translation diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 9a78e665b..df1eeb932 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -216,8 +216,8 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) { std::string aGroup = (*aIt); if (aDoc == aRootDoc) { // If root objects - int aRow = aRootDoc->size(aGroup); - if (aGroup == aRootType) { + int aRow = aRootDoc->size(aGroup, true); + if ((aGroup == aRootType) || (aGroup == ModelAPI_Folder::group())) { // Process root folder removeRow(aRow + aNbFolders); rebuildBranch(aNbFolders, aRow); @@ -233,7 +233,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // Check that some folders could erased QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(); foreach (QString aNotEmptyFolder, aNotEmptyFolders) { - if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup) == 0)) { + if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup, true) == 0)) { // Appears first object in folder which can not be shown empty removeRow(myXMLReader->rootFolderId(aGroup)); removeShownFolder(aRootDoc, aNotEmptyFolder); @@ -245,9 +245,9 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // Remove row for sub-document QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0); if (aDocRoot.isValid()) { - int aRow = aDoc->size(aGroup); + int aRow = aDoc->size(aGroup, true); int aNbSubFolders = foldersCount(aDoc.get()); - if (aGroup == aSubType) { + if ((aGroup == aSubType) || (aGroup == ModelAPI_Folder::group())) { // List of objects under document root removeRow(aRow + aNbSubFolders, aDocRoot); rebuildBranch(aNbSubFolders, aRow, aDocRoot); @@ -262,7 +262,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess } // Check that some folders could disappear QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false); - int aSize = aDoc->size(aGroup); + int aSize = aDoc->size(aGroup, true); foreach (QString aNotEmptyFolder, aNotEmptyFolders) { if ((aNotEmptyFolder.toStdString() == aGroup) && (aSize == 0)) { // Appears first object in folder which can not be shown empty @@ -918,7 +918,7 @@ QModelIndex } } } else { // If document is attached to feature - int aNb = aRootDoc->size(ModelAPI_Feature::group()); + int aNb = aRootDoc->size(ModelAPI_Feature::group(), true); ObjectPtr aObj; ResultPartPtr aPartRes; for (int i = 0; i < aNb; i++) { diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 805a5fe00..387df6660 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1525,6 +1525,9 @@ void XGUI_Workshop::deleteObjects() ModuleBase_Tools::convertToFeatures(anObjects, aFeatures); ModelAPI_Tools::findAllReferences(aFeatures, aReferences); + std::set aFolders; + ModuleBase_Tools::convertToFolders(anObjects, aFolders); + bool aDone = false; QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1"; aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", ")); @@ -1543,6 +1546,18 @@ void XGUI_Workshop::deleteObjects() aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end()); aDone = ModelAPI_Tools::removeFeatures(aFeatures, false); } + if (aFolders.size() > 0) { + std::set::const_iterator anIt = aFolders.begin(), + aLast = aFolders.end(); + for (; anIt != aLast; anIt++) { + FolderPtr aFolder = *anIt; + if (aFolder.get()) { + DocumentPtr aDoc = aFolder->document(); + aDoc->removeFolder(aFolder); + } + } + } + if (aDone) operationMgr()->commitOperation(); else -- 2.39.2