Skip to content

Commit

Permalink
+ allow to select whole wire in sweep panel
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed May 24, 2014
1 parent ce3a503 commit 51b2af5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
41 changes: 34 additions & 7 deletions src/Mod/Part/App/PartFeatures.cpp
Expand Up @@ -31,9 +31,11 @@
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
# include <TopoDS_Shell.hxx>
# include <TopTools_HSequenceOfShape.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepOffsetAPI_MakePipeShell.hxx>
# include <ShapeAnalysis.hxx>
# include <ShapeAnalysis_FreeBounds.hxx>
# include <TopTools_ListIteratorOfListOfShape.hxx>
# include <TopoDS_Iterator.hxx>
# include <TopExp_Explorer.hxx>
Expand Down Expand Up @@ -339,25 +341,50 @@ App::DocumentObjectExecReturn *Sweep::execute(void)
const Part::TopoShape& shape = static_cast<Part::Feature*>(spine)->Shape.getValue();
if (!shape._Shape.IsNull()) {
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));
if (!subedge.empty()) {
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();
}
path = mkWire.Wire();
}
catch (Standard_Failure) {
if (shape._Shape.ShapeType() == TopAbs_EDGE) {
path = shape._Shape;
}
else if (shape._Shape.ShapeType() == TopAbs_WIRE) {
BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape._Shape));
path = mkWire.Wire();
}
else if (shape._Shape.ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator it(shape._Shape);
for (; it.More(); it.Next()) {
if (it.Value().IsNull())
return new App::DocumentObjectExecReturn("In valid element in spine.");
if ((it.Value().ShapeType() != TopAbs_EDGE) &&
(it.Value().ShapeType() != TopAbs_WIRE)) {
return new App::DocumentObjectExecReturn("Element in spine is neither an edge nor a wire.");
}
}

Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape();
Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape();
for (TopExp_Explorer xp(shape._Shape, TopAbs_EDGE); xp.More(); xp.Next())
hEdges->Append(xp.Current());

ShapeAnalysis_FreeBounds::ConnectEdgesToWires(hEdges, Precision::Confusion(), Standard_True, hWires);
int len = hWires->Length();
if (len != 1)
return new App::DocumentObjectExecReturn("Spine is not connected.");
path = hWires->Value(1);
}
else {
return new App::DocumentObjectExecReturn("Spine is neither an edge nor a wire.");
}
}
catch (Standard_Failure) {
return new App::DocumentObjectExecReturn("Invalid spine.");
}
}

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Part/App/TopoShapeCompoundPy.xml
Expand Up @@ -19,7 +19,7 @@
<UserDocu>Add a shape to the compound.</UserDocu>
</Documentation>
</Methode>
<Methode Name="connectEdgesToWires">
<Methode Name="connectEdgesToWires" Const="true">
<Documentation>
<UserDocu>Build a compound of wires out of the edges of this compound.</UserDocu>
</Documentation>
Expand Down
51 changes: 49 additions & 2 deletions src/Mod/Part/Gui/TaskSweep.cpp
Expand Up @@ -28,8 +28,12 @@
# include <QMessageBox>
# include <QTextStream>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <Precision.hxx>
# include <ShapeAnalysis_FreeBounds.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Iterator.hxx>
# include <TopTools_HSequenceOfShape.hxx>
#endif

#include "ui_TaskSweep.h"
Expand All @@ -41,6 +45,7 @@
#include <Gui/Selection.h>
#include <Gui/SelectionFilter.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>

#include <Base/Console.h>
#include <Base/Interpreter.h>
Expand Down Expand Up @@ -81,10 +86,27 @@ class SweepWidget::Private
// shape is an edge or wire we can use it completely.
const TopoDS_Shape& shape = static_cast<Part::Feature*>(pObj)->Shape.getValue();
if (!shape.IsNull()) {
if (shape.ShapeType() == TopAbs_EDGE)
// a single edge
if (shape.ShapeType() == TopAbs_EDGE) {
return true;
if (shape.ShapeType() == TopAbs_WIRE)
}
// a single wire
if (shape.ShapeType() == TopAbs_WIRE) {
return true;
}
// a compound of only edges or wires
if (shape.ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator it(shape);
for (; it.More(); it.Next()) {
if (it.Value().IsNull())
return false;
if ((it.Value().ShapeType() != TopAbs_EDGE) &&
(it.Value().ShapeType() != TopAbs_WIRE))
return false;
}

return true;
}
}
}
else {
Expand Down Expand Up @@ -199,6 +221,30 @@ bool SweepWidget::isPathValid(const Gui::SelectionObject& sel) const
BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape._Shape));
pathShape = mkWire.Wire();
}
else if (shape._Shape.ShapeType() == TopAbs_COMPOUND) {
try {
TopoDS_Iterator it(shape._Shape);
for (; it.More(); it.Next()) {
if ((it.Value().ShapeType() != TopAbs_EDGE) &&
(it.Value().ShapeType() != TopAbs_WIRE)) {
return false;
}
}
Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape();
Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape();
for (TopExp_Explorer xp(shape._Shape, TopAbs_EDGE); xp.More(); xp.Next())
hEdges->Append(xp.Current());

ShapeAnalysis_FreeBounds::ConnectEdgesToWires(hEdges, Precision::Confusion(), Standard_True, hWires);
int len = hWires->Length();
if (len != 1)
return false;
pathShape = hWires->Value(1);
}
catch (...) {
return false;
}
}

return (!pathShape.IsNull());
}
Expand Down Expand Up @@ -255,6 +301,7 @@ bool SweepWidget::accept()
}

try {
Gui::WaitCursor wc;
QString cmd;
cmd = QString::fromAscii(
"App.getDocument('%5').addObject('Part::Sweep','Sweep')\n"
Expand Down

0 comments on commit 51b2af5

Please sign in to comment.