From 75b2e858a2fbad226756cf8b32500a65ea19ebd5 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 22 Sep 2017 12:16:21 +0200 Subject: [PATCH] add warning when compound with multiple solids/shells is selected --- src/Mod/PartDesign/Gui/CommandBody.cpp | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index d64d56124f..f221c96ac0 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -48,6 +48,7 @@ #include "Utils.h" #include "WorkflowManager.h" +#include //=========================================================================== @@ -135,7 +136,44 @@ void CmdPartDesignBody::activated(int iMsg) QObject::tr("Base feature (%1) belongs to other part.") .arg(QString::fromUtf8(baseFeature->Label.getValue()))); baseFeature = nullptr; - }; + } + // if a standard Part feature (not a PartDesign feature) is selected then check + // the number of solids/shells + else if (!baseFeature->isDerivedFrom(PartDesign::Feature::getClassTypeId())) { + const TopoDS_Shape& shape = static_cast(baseFeature)->Shape.getValue(); + if (!shape.IsNull()) { + int numSolids = 0; + int numShells = 0; + for (TopExp_Explorer xp(shape, TopAbs_SOLID); xp.More(); xp.Next()) { + numSolids++; + } + for (TopExp_Explorer xp(shape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next()) { + numShells++; + } + + QString warning; + if (numSolids > 1 && numShells == 0) { + warning = QObject::tr("The selected shape consists of multiple solids.\n" + "This may lead to unexpected results."); + } + else if (numShells > 1 && numSolids == 0) { + warning = QObject::tr("The selected shape consists of multiple shells.\n" + "This may lead to unexpected results."); + } + else if (numShells == 1 && numSolids == 0) { + warning = QObject::tr("The selected shape consists of only a shell.\n" + "This may lead to unexpected results."); + } + else if (numSolids + numShells > 1) { + warning = QObject::tr("The selected shape consists of multiple solids or shells.\n" + "This may lead to unexpected results."); + } + + if (!warning.isEmpty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Base feature"), warning); + } + } + } } } else {