From 5905e018e30ae6867720c08ed2ba7745a0f94585 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 24 Jun 2016 11:33:39 +0300 Subject: [PATCH] Bug #1596: Export does not work Warning in Sketch to delete invalid sketch features. --- src/ExchangePlugin/plugin-Exchange.xml | 8 +----- src/ModuleBase/ModuleBase_Tools.cpp | 9 ++++--- src/ModuleBase/ModuleBase_Tools.h | 3 ++- src/PartSet/PartSet_SketcherMgr.cpp | 34 +++++++++++++++++--------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/ExchangePlugin/plugin-Exchange.xml b/src/ExchangePlugin/plugin-Exchange.xml index 531f36667..f428938d9 100755 --- a/src/ExchangePlugin/plugin-Exchange.xml +++ b/src/ExchangePlugin/plugin-Exchange.xml @@ -9,13 +9,7 @@ - - - - - - + diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 127ceb3f7..8f184df15 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -1041,7 +1041,8 @@ bool hasModuleDocumentFeature(const std::set& theFeatures) bool askToDelete(const std::set theFeatures, const std::map >& theReferences, QWidget* theParent, - std::set& theReferencesToDelete) + std::set& theReferencesToDelete, + const std::string& thePrefixInfo) { QString aNotActivatedDocWrn; std::string aNotActivatedNames; @@ -1120,16 +1121,18 @@ bool askToDelete(const std::set theFeatures, aMessageBox.setDefaultButton(QMessageBox::No); QString aText; + if (!thePrefixInfo.empty()) + aText = thePrefixInfo.c_str(); QString aSep = ", "; if (!aPartFeatureNames.empty()) aText += QString(QObject::tr("The following parts will be deleted: %1.\n")).arg(aPartFeatureNames.join(aSep)); if (!aNotActivatedDocWrn.isEmpty()) aText += aNotActivatedDocWrn; if (!anOtherFeatureNames.empty()) - aText += QString(QObject::tr("Selected features are used in the following features: %1.\nThese features will be deleted.\n")) + aText += QString(QObject::tr("Features are used in the following features: %1.\nThese features will be deleted.\n")) .arg(anOtherFeatureNames.join(aSep)); if (!aParamFeatureNames.empty()) { - aText += QString(QObject::tr("Selected parameters are used in the following features: %1.\nThese features will be deleted.\nOr parameters could be replaced by their values.\n")) + aText += QString(QObject::tr("Parameters are used in the following features: %1.\nThese features will be deleted.\nOr parameters could be replaced by their values.\n")) .arg(aParamFeatureNames.join(aSep)); QPushButton *aReplaceButton = aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole); } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 665ee6008..244afca4c 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -295,7 +295,8 @@ bool MODULEBASE_EXPORT hasModuleDocumentFeature(const std::set& theF bool MODULEBASE_EXPORT askToDelete(const std::set aFeatures, const std::map >& theReferences, QWidget* theParent, - std::set& theReferencesToDelete); + std::set& theReferencesToDelete, + const std::string& thePrefixInfo = ""); /// Converts a list of objects to set of corresponded features. If object is result, it is ingored /// because the feauture only might be removed. But if result is in a parameter group, the feature diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 6059ab187..29ff74c11 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -875,7 +875,6 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) myCurrentSketch->setDisplayed(false); // Remove invalid sketch entities - /* std::set anInvalidFeatures; ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators(); for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { @@ -885,17 +884,30 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) anInvalidFeatures.insert(aFeature); } } - std::map > aReferences; - ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false); - std::set aFeatureRefsToDelete; - if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(), aFeatureRefsToDelete)) { - if (!aFeatureRefsToDelete.empty()) - anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end()); - bool aDone = ModelAPI_Tools::removeFeatures(anInvalidFeatures, false); + if (!anInvalidFeatures.empty()) { + std::map > aReferences; + ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false); + + std::set::const_iterator anIt = anInvalidFeatures.begin(), + aLast = anInvalidFeatures.end(); + // separate features to references to parameter features and references to others + QStringList anInvalidFeatureNames; + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = *anIt; + if (aFeature.get()) + anInvalidFeatureNames.append(aFeature->name().c_str()); + } + std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n"). + arg(anInvalidFeatureNames.join(", ")).toStdString().c_str(); + std::set aFeatureRefsToDelete; + if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(), + aFeatureRefsToDelete, aPrefixInfo)) { + if (!aFeatureRefsToDelete.empty()) + anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end()); + ModelAPI_Tools::removeFeatures(anInvalidFeatures, false); + } } - else - return; - */ + // Display sketcher objects for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { FeaturePtr aFeature = myCurrentSketch->subFeature(i); -- 2.39.2