From 5d7061a5b044747ff940e98ea58f64c6477f0bf7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 11 Jun 2012 13:22:11 +0200 Subject: [PATCH] Workaround for weird sweeping problem, allow to select several edges as path --- src/Mod/Part/App/PartFeatures.cpp | 19 +++++++++++++------ src/Mod/Part/Gui/TaskSweep.cpp | 28 ++++++++++++++-------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Mod/Part/App/PartFeatures.cpp b/src/Mod/Part/App/PartFeatures.cpp index 431e15741..45aec90d8 100644 --- a/src/Mod/Part/App/PartFeatures.cpp +++ b/src/Mod/Part/App/PartFeatures.cpp @@ -244,16 +244,19 @@ App::DocumentObjectExecReturn *Sweep::execute(void) if (!(spine && spine->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))) return new App::DocumentObjectExecReturn("No spine linked."); const std::vector& subedge = Spine.getSubValues(); - if (subedge.size() != 1) - return new App::DocumentObjectExecReturn("Not exactly one sub-shape linked."); TopoDS_Shape path; const Part::TopoShape& shape = static_cast(spine)->Shape.getValue(); if (!shape._Shape.IsNull()) { - if (!subedge[0].empty()) { - path = shape.getSubShape(subedge[0].c_str()); + try { + BRepBuilderAPI_MakeWire mkWire; + for (std::vector::const_iterator it = subedge.begin(); it != subedge.end(); ++it) { + TopoDS_Shape subshape = shape.getSubShape(it->c_str()); + mkWire.Add(TopoDS::Edge(subshape)); + } + path = mkWire.Wire(); } - else { + catch (Standard_Failure) { if (shape._Shape.ShapeType() == TopAbs_EDGE) path = shape._Shape; else if (shape._Shape.ShapeType() == TopAbs_WIRE) @@ -273,8 +276,12 @@ App::DocumentObjectExecReturn *Sweep::execute(void) const TopoDS_Shape& shape = static_cast(*it)->Shape.getValue(); if (shape.IsNull()) return new App::DocumentObjectExecReturn("Linked shape is invalid."); + // 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. + // https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=10&t=2673&sid=fbcd2ff4589f0b2f79ed899b0b990648#p20268 if (shape.ShapeType() == TopAbs_WIRE) { - profiles.Append(shape); + BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape)); + profiles.Append(mkWire.Wire()); } else if (shape.ShapeType() == TopAbs_EDGE) { BRepBuilderAPI_MakeWire mkWire(TopoDS::Edge(shape)); diff --git a/src/Mod/Part/Gui/TaskSweep.cpp b/src/Mod/Part/Gui/TaskSweep.cpp index 64e9995e4..63839c514 100644 --- a/src/Mod/Part/Gui/TaskSweep.cpp +++ b/src/Mod/Part/Gui/TaskSweep.cpp @@ -118,7 +118,7 @@ void SweepWidget::findShapes() bool SweepWidget::accept() { - Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1"); + Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1.."); Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 1"); bool matchEdge = edgeFilter.match(); bool matchPart = partFilter.match(); @@ -128,16 +128,14 @@ bool SweepWidget::accept() } // get the selected object - std::string objectName, subShape; + std::string selection; if (matchEdge) { const std::vector& result = edgeFilter.Result[0]; - const std::vector& edges = result[0].getSubNames(); - objectName = result.front().getFeatName(); - subShape = edges.front(); + selection = result.front().getAsPropertyLinkSubString(); } else { const std::vector& result = partFilter.Result[0]; - objectName = result.front().getFeatName(); + selection = result.front().getAsPropertyLinkSubString(); } QString list, solid, frenet; @@ -167,15 +165,17 @@ bool SweepWidget::accept() try { QString cmd; cmd = QString::fromAscii( - "App.getDocument('%6').addObject('Part::Sweep','Sweep')\n" - "App.getDocument('%6').ActiveObject.Sections=[%1]\n" - "App.getDocument('%6').ActiveObject.Spine=(FreeCAD.ActiveDocument.%2,['%3'])\n" - "App.getDocument('%6').ActiveObject.Solid=%4\n" - "App.getDocument('%6').ActiveObject.Frenet=%5\n" + "App.getDocument('%5').addObject('Part::Sweep','Sweep')\n" + "App.getDocument('%5').ActiveObject.Sections=[%1]\n" + "App.getDocument('%5').ActiveObject.Spine=%2\n" + "App.getDocument('%5').ActiveObject.Solid=%3\n" + "App.getDocument('%5').ActiveObject.Frenet=%4\n" ) - .arg(list).arg(QLatin1String(objectName.c_str())) - .arg(QLatin1String(subShape.c_str())) - .arg(solid).arg(frenet).arg(QString::fromAscii(d->document.c_str())); + .arg(list) + .arg(QLatin1String(selection.c_str())) + .arg(solid) + .arg(frenet) + .arg(QString::fromAscii(d->document.c_str())); Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str()); if (!doc) throw Base::Exception("Document doesn't exist anymore");