From 595fbc9c1b6b9c0398cd0700675ae7f7dda1e0a0 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sat, 17 Aug 2024 10:12:28 -0400 Subject: [PATCH] [TD]detect breakObject inside Body --- src/Mod/TechDraw/App/DrawBrokenView.cpp | 1 - src/Mod/TechDraw/Gui/Command.cpp | 33 +++++++++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawBrokenView.cpp b/src/Mod/TechDraw/App/DrawBrokenView.cpp index 79d63fd75402..a22c2f480b5d 100644 --- a/src/Mod/TechDraw/App/DrawBrokenView.cpp +++ b/src/Mod/TechDraw/App/DrawBrokenView.cpp @@ -412,7 +412,6 @@ bool DrawBrokenView::isBreakObject(const App::DocumentObject& breakObj) //! horizontal or vertical bool DrawBrokenView::isBreakObjectSketch(const App::DocumentObject& breakObj) { - // Base::Console().Message("DBV::isBreakObjectSketch()\n"); TopoDS_Shape locShape = ShapeExtractor::getLocatedShape(&breakObj); if (locShape.IsNull()) { return false; diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 3023f4a7d442..c35cd443e5a9 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -545,12 +545,14 @@ void CmdTechDrawBrokenView::activated(int iMsg) std::vector xShapesFromBase; std::vector baseViews = getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); + TechDraw::DrawViewPart* dvp{nullptr}; if (!baseViews.empty()) { - TechDraw::DrawViewPart* dvp = static_cast(*baseViews.begin()); + dvp = static_cast(*baseViews.begin()); shapesFromBase = dvp->Source.getValues(); xShapesFromBase = dvp->XSource.getValues(); } + // get the shape objects from the selection std::vector shapes; std::vector xShapes; @@ -560,13 +562,14 @@ void CmdTechDrawBrokenView::activated(int iMsg) shapes.insert(shapes.end(), shapesFromBase.begin(), shapesFromBase.end()); shapes.insert(xShapes.end(), xShapesFromBase.begin(), xShapesFromBase.end()); - if (shapes.empty() && - xShapes.empty()) { + if (!dvp || (shapes.empty() && xShapes.empty())) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Empty selection"), QObject::tr("Please select objects to break or a base view and break definition objects.")); return; } + auto doc = dvp->getDocument(); + // pick the Break objects out of the selected pile std::vector selection = getSelection().getSelectionEx( nullptr, App::DocumentObject::getClassTypeId(), Gui::ResolveMode::NoResolve); @@ -574,8 +577,26 @@ void CmdTechDrawBrokenView::activated(int iMsg) std::vector breakObjects; for (auto& selObj : selection) { auto temp = selObj.getObject(); - if (DrawBrokenView::isBreakObject(*temp)) { - breakObjects.push_back(selObj.getObject()); + // a sketch outside a body is returned as an independent object in the selection + if (selObj.getSubNames().empty()) { + if (DrawBrokenView::isBreakObject(*temp)) { + breakObjects.push_back(selObj.getObject()); + } + continue; + } + // a sketch inside a body is returned as body + subelement, so we have to search through + // subnames to find it. This may(?) apply to App::Part and Group also? + auto subname = selObj.getSubNames().front(); + if (subname.back() == '.') { + subname = subname.substr(0, subname.length() - 1); + auto objects = doc->getObjects(); + for (auto& obj : objects) { + std::string objname{obj->getNameInDocument()}; + if (subname == objname && + DrawBrokenView::isBreakObject(*obj)) { + breakObjects.push_back(obj); + } + } } } if (breakObjects.empty()) { @@ -628,8 +649,6 @@ void CmdTechDrawBrokenView::activated(int iMsg) commitCommand(); -// Gui::Control().showDialog(new TaskDlgBrokenView(dbv)); - dbv->recomputeFeature(); }