Workaround for weird sweeping problem, allow to select several edges as path
This commit is contained in:
parent
6c16628f4e
commit
5d7061a5b0
|
@ -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<std::string>& 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<Part::Feature*>(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<std::string>::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<Part::Feature*>(*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));
|
||||
|
|
|
@ -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<Gui::SelectionObject>& result = edgeFilter.Result[0];
|
||||
const std::vector<std::string>& edges = result[0].getSubNames();
|
||||
objectName = result.front().getFeatName();
|
||||
subShape = edges.front();
|
||||
selection = result.front().getAsPropertyLinkSubString();
|
||||
}
|
||||
else {
|
||||
const std::vector<Gui::SelectionObject>& 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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user