Skip to content

Commit

Permalink
[TD]detect breakObject inside Body
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and sliptonic committed Aug 19, 2024
1 parent 8913b84 commit 595fbc9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/Mod/TechDraw/App/DrawBrokenView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 26 additions & 7 deletions src/Mod/TechDraw/Gui/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,14 @@ void CmdTechDrawBrokenView::activated(int iMsg)
std::vector<App::DocumentObject*> xShapesFromBase;
std::vector<App::DocumentObject*> baseViews =
getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId());
TechDraw::DrawViewPart* dvp{nullptr};
if (!baseViews.empty()) {
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(*baseViews.begin());
dvp = static_cast<TechDraw::DrawViewPart*>(*baseViews.begin());
shapesFromBase = dvp->Source.getValues();
xShapesFromBase = dvp->XSource.getValues();
}


// get the shape objects from the selection
std::vector<App::DocumentObject*> shapes;
std::vector<App::DocumentObject*> xShapes;
Expand All @@ -560,22 +562,41 @@ 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<Gui::SelectionObject> selection = getSelection().getSelectionEx(
nullptr, App::DocumentObject::getClassTypeId(), Gui::ResolveMode::NoResolve);

std::vector<App::DocumentObject*> 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()) {
Expand Down Expand Up @@ -628,8 +649,6 @@ void CmdTechDrawBrokenView::activated(int iMsg)

commitCommand();

// Gui::Control().showDialog(new TaskDlgBrokenView(dbv));

dbv->recomputeFeature();
}

Expand Down

0 comments on commit 595fbc9

Please sign in to comment.