From 498040e9eee0228887bf6de17998b6ba452fae66 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 26 Aug 2018 17:02:01 +0200 Subject: [PATCH] Part sweep now accepts compounds of edges that build a wire --- src/Mod/Part/App/PartFeatures.cpp | 31 ++++++++++++++++++++++++++----- src/Mod/Part/Gui/TaskSweep.cpp | 23 ++++++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/Mod/Part/App/PartFeatures.cpp b/src/Mod/Part/App/PartFeatures.cpp index 314b1b1280..419b123b36 100644 --- a/src/Mod/Part/App/PartFeatures.cpp +++ b/src/Mod/Part/App/PartFeatures.cpp @@ -308,7 +308,8 @@ App::DocumentObjectExecReturn *Loft::execute(void) if (shape.IsNull()) return new App::DocumentObjectExecReturn("Linked shape is invalid."); - // Extract first element of a compound + // Allow compounds with a single face, wire or vertex or + // if there are only edges building one wire if (shape.ShapeType() == TopAbs_COMPOUND) { Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape(); Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape(); @@ -479,15 +480,35 @@ App::DocumentObjectExecReturn *Sweep::execute(void) if (shape.IsNull()) return new App::DocumentObjectExecReturn("Linked shape is invalid."); - // Extract first element of a compound + // Allow compounds with a single face, wire or vertex or + // if there are only edges building one wire if (shape.ShapeType() == TopAbs_COMPOUND) { + Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape(); + Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape(); + TopoDS_Iterator it(shape); - for (; it.More(); it.Next()) { + int numChilds=0; + TopoDS_Shape child; + for (; it.More(); it.Next(), numChilds++) { if (!it.Value().IsNull()) { - shape = it.Value(); - break; + child = it.Value(); + if (child.ShapeType() == TopAbs_EDGE) { + hEdges->Append(child); + } } } + + // a single child + if (numChilds == 1) { + shape = child; + } + // or all children are edges + else if (hEdges->Length() == numChilds) { + ShapeAnalysis_FreeBounds::ConnectEdgesToWires(hEdges, + Precision::Confusion(), Standard_False, hWires); + if (hWires->Length() == 1) + shape = hWires->Value(1); + } } // There is a weird behaviour of BRepOffsetAPI_MakePipeShell when trying to add the wire as is. // If we re-create the wire then everything works fine. diff --git a/src/Mod/Part/Gui/TaskSweep.cpp b/src/Mod/Part/Gui/TaskSweep.cpp index a311542d87..375c9b992a 100644 --- a/src/Mod/Part/Gui/TaskSweep.cpp +++ b/src/Mod/Part/Gui/TaskSweep.cpp @@ -163,18 +163,35 @@ void SweepWidget::findShapes() TopoDS_Shape shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; - // also allow compounds with a single face, wire, edge or vertex + // also allow compounds with a single face, wire or vertex or + // if there are only edges building one wire if (shape.ShapeType() == TopAbs_COMPOUND) { + Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape(); + Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape(); + TopoDS_Iterator it(shape); int numChilds=0; TopoDS_Shape child; for (; it.More(); it.Next(), numChilds++) { - if (!it.Value().IsNull()) + if (!it.Value().IsNull()) { child = it.Value(); + if (child.ShapeType() == TopAbs_EDGE) { + hEdges->Append(child); + } + } } - if (numChilds == 1) + // a single child + if (numChilds == 1) { shape = child; + } + // or all children are edges + else if (hEdges->Length() == numChilds) { + ShapeAnalysis_FreeBounds::ConnectEdgesToWires(hEdges, + Precision::Confusion(), Standard_False, hWires); + if (hWires->Length() == 1) + shape = hWires->Value(1); + } } if (shape.ShapeType() == TopAbs_FACE ||