From bbbbf6c691f72b358121eaafce637f9eff41812e Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 15 Mar 2018 12:05:13 +0100 Subject: [PATCH] don't allow to set empty list of bodies for boolean operations don't update the body feature if boolean body list is empty --- src/Mod/PartDesign/Gui/Command.cpp | 14 +++++++++++--- src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 3492bcf408..ad31967970 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -678,7 +678,9 @@ bool CmdPartDesignNewSketch::isActive(void) //=========================================================================== void finishFeature(const Gui::Command* cmd, const std::string& FeatName, - App::DocumentObject* prevSolidFeature = nullptr, const bool hidePrevSolid = true) + App::DocumentObject* prevSolidFeature = nullptr, + const bool hidePrevSolid = true, + const bool updateDocument = true) { PartDesign::Body *pcActiveBody; @@ -691,7 +693,9 @@ void finishFeature(const Gui::Command* cmd, const std::string& FeatName, if (hidePrevSolid && prevSolidFeature && (prevSolidFeature != NULL)) cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument()); - cmd->updateActive(); + if (updateDocument) + cmd->updateActive(); + // #0001721: use '0' as edit value to avoid switching off selection in // ViewProviderGeometryObject::setEditViewer cmd->doCommand(cmd->Gui,"Gui.activeDocument().setEdit('%s', 0)", FeatName.c_str()); @@ -2186,6 +2190,9 @@ void CmdPartDesignBoolean::activated(int iMsg) std::string FeatName = getUniqueObjectName("Boolean"); doCommand(Doc,"App.activeDocument().%s.newObject('PartDesign::Boolean','%s')", pcActiveBody->getNameInDocument(), FeatName.c_str()); + // If we don't add an object to the boolean group then don't update the body + // as otherwise this will fail and it will be marked as invalid + bool updateDocument = false; if (BodyFilter.match() && !BodyFilter.Result.empty()) { std::vector bodies; std::vector >::iterator i = BodyFilter.Result.begin(); @@ -2197,12 +2204,13 @@ void CmdPartDesignBoolean::activated(int iMsg) } if (!bodies.empty()) { + updateDocument = true; std::string bodyString = PartDesignGui::buildLinkListPythonStr(bodies); doCommand(Doc,"App.activeDocument().%s.addObjects(%s)",FeatName.c_str(),bodyString.c_str()); } } - finishFeature(this, FeatName, nullptr, false); + finishFeature(this, FeatName, nullptr, false, updateDocument); } bool CmdPartDesignBoolean::isActive(void) diff --git a/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp b/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp index 8642825598..7857054484 100644 --- a/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp @@ -322,6 +322,11 @@ bool TaskDlgBooleanParameters::accept() try { std::vector bodies = parameter->getBodies(); + if (bodies.empty()) { + QMessageBox::warning(parameter, tr("Empty body list"), + tr("The body list cannot be empty")); + return false; + } std::stringstream str; str << "App.ActiveDocument." << name.c_str() << ".setObjects( ["; for (std::vector::const_iterator it = bodies.begin(); it != bodies.end(); ++it)