From 318c4b6ce9f75055e85288b3e1bef39277ffb4f6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 15 May 2014 12:37:39 +0200 Subject: [PATCH] + fixes #0001547: add Part Spiral to the selectable list of profiles for a Part Loft --- src/Mod/Part/App/PartFeatures.cpp | 27 +++++++++++++++++++++++++-- src/Mod/Part/Gui/TaskLoft.cpp | 17 ++++++++++++++++- src/Mod/Part/Gui/TaskSweep.cpp | 17 ++++++++++++++++- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/Mod/Part/App/PartFeatures.cpp b/src/Mod/Part/App/PartFeatures.cpp index bf923485edff..5c9a081c5e9c 100644 --- a/src/Mod/Part/App/PartFeatures.cpp +++ b/src/Mod/Part/App/PartFeatures.cpp @@ -35,6 +35,7 @@ # include # include # include +# include # include # include # include @@ -240,9 +241,20 @@ App::DocumentObjectExecReturn *Loft::execute(void) for (it = shapes.begin(); it != shapes.end(); ++it) { if (!(*it)->isDerivedFrom(Part::Feature::getClassTypeId())) return new App::DocumentObjectExecReturn("Linked object is not a shape."); - const TopoDS_Shape& shape = static_cast(*it)->Shape.getValue(); + TopoDS_Shape shape = static_cast(*it)->Shape.getValue(); if (shape.IsNull()) return new App::DocumentObjectExecReturn("Linked shape is invalid."); + + // Extract first element of a compound + if (shape.ShapeType() == TopAbs_COMPOUND) { + TopoDS_Iterator it(shape); + for (; it.More(); it.Next()) { + if (!it.Value().IsNull()) { + shape = it.Value(); + break; + } + } + } if (shape.ShapeType() == TopAbs_FACE) { TopoDS_Wire faceouterWire = ShapeAnalysis::OuterWire(TopoDS::Face(shape)); profiles.Append(faceouterWire); @@ -355,9 +367,20 @@ App::DocumentObjectExecReturn *Sweep::execute(void) for (it = shapes.begin(); it != shapes.end(); ++it) { if (!(*it)->isDerivedFrom(Part::Feature::getClassTypeId())) return new App::DocumentObjectExecReturn("Linked object is not a shape."); - const TopoDS_Shape& shape = static_cast(*it)->Shape.getValue(); + TopoDS_Shape shape = static_cast(*it)->Shape.getValue(); if (shape.IsNull()) return new App::DocumentObjectExecReturn("Linked shape is invalid."); + + // Extract first element of a compound + if (shape.ShapeType() == TopAbs_COMPOUND) { + TopoDS_Iterator it(shape); + for (; it.More(); it.Next()) { + if (!it.Value().IsNull()) { + shape = it.Value(); + break; + } + } + } // 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. // http://forum.freecadweb.org/viewtopic.php?f=10&t=2673&sid=fbcd2ff4589f0b2f79ed899b0b990648#p20268 diff --git a/src/Mod/Part/Gui/TaskLoft.cpp b/src/Mod/Part/Gui/TaskLoft.cpp index 0c361a4346d4..ed6c7c323f06 100644 --- a/src/Mod/Part/Gui/TaskLoft.cpp +++ b/src/Mod/Part/Gui/TaskLoft.cpp @@ -26,6 +26,7 @@ #ifndef _PreComp_ # include # include +# include #endif #include "ui_TaskLoft.h" @@ -95,9 +96,23 @@ void LoftWidget::findShapes() std::vector objs = activeDoc->getObjectsOfType(); for (std::vector::iterator it = objs.begin(); it!=objs.end(); ++it) { - const TopoDS_Shape& shape = (*it)->Shape.getValue(); + TopoDS_Shape shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; + // also allow compounds with a single face, wire, edge or vertex + if (shape.ShapeType() == TopAbs_COMPOUND) { + TopoDS_Iterator it(shape); + int numChilds=0; + TopoDS_Shape child; + for (; it.More(); it.Next(), numChilds++) { + if (!it.Value().IsNull()) + child = it.Value(); + } + + if (numChilds == 1) + shape = child; + } + if (shape.ShapeType() == TopAbs_FACE || shape.ShapeType() == TopAbs_WIRE || shape.ShapeType() == TopAbs_EDGE || diff --git a/src/Mod/Part/Gui/TaskSweep.cpp b/src/Mod/Part/Gui/TaskSweep.cpp index 487bdead507f..4b9cae0746f9 100644 --- a/src/Mod/Part/Gui/TaskSweep.cpp +++ b/src/Mod/Part/Gui/TaskSweep.cpp @@ -29,6 +29,7 @@ # include # include # include +# include #endif #include "ui_TaskSweep.h" @@ -118,9 +119,23 @@ void SweepWidget::findShapes() std::vector objs = activeDoc->getObjectsOfType(); for (std::vector::iterator it = objs.begin(); it!=objs.end(); ++it) { - const TopoDS_Shape& shape = (*it)->Shape.getValue(); + TopoDS_Shape shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; + // also allow compounds with a single face, wire, edge or vertex + if (shape.ShapeType() == TopAbs_COMPOUND) { + TopoDS_Iterator it(shape); + int numChilds=0; + TopoDS_Shape child; + for (; it.More(); it.Next(), numChilds++) { + if (!it.Value().IsNull()) + child = it.Value(); + } + + if (numChilds == 1) + shape = child; + } + if (shape.ShapeType() == TopAbs_FACE || shape.ShapeType() == TopAbs_WIRE || shape.ShapeType() == TopAbs_EDGE ||