From 62f00095cd1a2016b6f00b6c029cc5b0147bfc86 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 24 Apr 2014 10:55:20 -0400 Subject: [PATCH] Issue #1508 Solid tickBox for Part.Revolution Creates Solid for closed Edges & Wires --- src/Mod/Part/App/FeatureRevolution.cpp | 10 +++++-- src/Mod/Part/App/FeatureRevolution.h | 1 + src/Mod/Part/App/TopoShape.cpp | 38 ++++++++++++++++++++++++-- src/Mod/Part/App/TopoShape.h | 2 +- src/Mod/Part/Gui/DlgRevolution.cpp | 14 ++++++++-- src/Mod/Part/Gui/DlgRevolution.ui | 26 +++++++----------- 6 files changed, 67 insertions(+), 24 deletions(-) diff --git a/src/Mod/Part/App/FeatureRevolution.cpp b/src/Mod/Part/App/FeatureRevolution.cpp index ddb96db07..cd2250d17 100644 --- a/src/Mod/Part/App/FeatureRevolution.cpp +++ b/src/Mod/Part/App/FeatureRevolution.cpp @@ -38,10 +38,12 @@ PROPERTY_SOURCE(Part::Revolution, Part::Feature) Revolution::Revolution() { + //*** why not ADD_PROPERTY_TYPE?? ADD_PROPERTY(Source,(0)); ADD_PROPERTY(Base,(Base::Vector3d(0.0,0.0,0.0))); ADD_PROPERTY(Axis,(Base::Vector3d(0.0,0.0,1.0))); ADD_PROPERTY(Angle,(360.0)); + ADD_PROPERTY_TYPE(Solid,(false),"Base",App::Prop_None,"Make revolution a solid if possible"); Angle.setConstraints(&angleRangeU); } @@ -50,7 +52,8 @@ short Revolution::mustExecute() const if (Base.isTouched() || Axis.isTouched() || Angle.isTouched() || - Source.isTouched()) + Source.isTouched() || + Solid.isTouched()) return 1; return 0; } @@ -68,11 +71,14 @@ App::DocumentObjectExecReturn *Revolution::execute(void) Base::Vector3d v = Axis.getValue(); gp_Pnt pnt(b.x,b.y,b.z); gp_Dir dir(v.x,v.y,v.z); + Standard_Boolean isSolid = Solid.getValue() ? Standard_True : Standard_False; try { // Now, let's get the TopoDS_Shape + //TopoDS_Shape revolve = base->Shape.getShape().revolve(gp_Ax1(pnt, dir), + // Angle.getValue()/180.0f*M_PI); TopoDS_Shape revolve = base->Shape.getShape().revolve(gp_Ax1(pnt, dir), - Angle.getValue()/180.0f*M_PI); + Angle.getValue()/180.0f*M_PI,isSolid); if (revolve.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is null"); this->Shape.setValue(revolve); diff --git a/src/Mod/Part/App/FeatureRevolution.h b/src/Mod/Part/App/FeatureRevolution.h index 601bd4f51..545420c98 100644 --- a/src/Mod/Part/App/FeatureRevolution.h +++ b/src/Mod/Part/App/FeatureRevolution.h @@ -41,6 +41,7 @@ public: App::PropertyVector Base; App::PropertyVector Axis; App::PropertyFloatConstraint Angle; + App::PropertyBool Solid; /** @name methods override feature */ //@{ diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index eb1cbf768..228295ecd 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -51,6 +51,7 @@ # include # include # include +# include # include # include # include @@ -1864,10 +1865,41 @@ TopoDS_Shape TopoShape::makePrism(const gp_Vec& vec) const return mkPrism.Shape(); } -TopoDS_Shape TopoShape::revolve(const gp_Ax1& axis, double d) const +TopoDS_Shape TopoShape::revolve(const gp_Ax1& axis, double d, Standard_Boolean isSolid) const { - if (this->_Shape.IsNull()) Standard_Failure::Raise("cannot sweep empty shape"); - BRepPrimAPI_MakeRevol mkRevol(this->_Shape, axis,d); + if (this->_Shape.IsNull()) Standard_Failure::Raise("cannot revolve empty shape"); + + TopoDS_Face f; + TopoDS_Wire w; + TopoDS_Edge e; + Standard_Boolean convertFailed = false; + + TopoDS_Shape base = this->_Shape; + if ((isSolid) && (BRep_Tool::IsClosed(base)) && + ((base.ShapeType() == TopAbs_EDGE) || (base.ShapeType() == TopAbs_WIRE))) { + if (base.ShapeType() == TopAbs_EDGE) { + BRepBuilderAPI_MakeWire mkWire(TopoDS::Edge(base)); + if (mkWire.IsDone()) { + w = mkWire.Wire(); } + else { + convertFailed = true; } + } + else { + w = TopoDS::Wire(base);} + if (!convertFailed) { + BRepBuilderAPI_MakeFace mkFace(w); + if (mkFace.IsDone()) { + f = mkFace.Face(); + base = f; } + else { + convertFailed = true; } + } + } + + if (convertFailed) { + Base::Console().Message("TopoShape::revolve could not make Solid from Wire/Edge.\n");} + + BRepPrimAPI_MakeRevol mkRevol(base, axis,d); return mkRevol.Shape(); } diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 6c950bc5a..fdf2dca74 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -158,7 +158,7 @@ public: TopoDS_Shape makePipeShell(const TopTools_ListOfShape& profiles, const Standard_Boolean make_solid, const Standard_Boolean isFrenet = Standard_False, int transition=0) const; TopoDS_Shape makePrism(const gp_Vec&) const; - TopoDS_Shape revolve(const gp_Ax1&, double d) const; + TopoDS_Shape revolve(const gp_Ax1&, double d, Standard_Boolean isSolid=Standard_False) const; TopoDS_Shape makeSweep(const TopoDS_Shape& profile, double, int) const; TopoDS_Shape makeTube(double radius, double tol, int cont, int maxdeg, int maxsegm) const; TopoDS_Shape makeHelix(Standard_Real pitch, Standard_Real height, diff --git a/src/Mod/Part/Gui/DlgRevolution.cpp b/src/Mod/Part/Gui/DlgRevolution.cpp index 5a35f6c7b..80a8113d7 100644 --- a/src/Mod/Part/Gui/DlgRevolution.cpp +++ b/src/Mod/Part/Gui/DlgRevolution.cpp @@ -47,6 +47,9 @@ #include #include #include +#include + + using namespace PartGui; @@ -178,8 +181,12 @@ void DlgRevolution::accept() App::Document* activeDoc = App::GetApplication().getActiveDocument(); activeDoc->openTransaction("Revolve"); - QString shape, type, name; + QString shape, type, name, solid; QList items = ui->treeWidget->selectedItems(); + if (ui->checkSolid->isChecked()) { + solid = QString::fromAscii("True");} + else { + solid = QString::fromAscii("False");} for (QList::iterator it = items.begin(); it != items.end(); ++it) { shape = (*it)->data(0, Qt::UserRole).toString(); type = QString::fromAscii("Part::Revolution"); @@ -192,6 +199,7 @@ void DlgRevolution::accept() "FreeCAD.ActiveDocument.%2.Axis = (%4,%5,%6)\n" "FreeCAD.ActiveDocument.%2.Base = (%7,%8,%9)\n" "FreeCAD.ActiveDocument.%2.Angle = %10\n" + "FreeCAD.ActiveDocument.%2.Solid = %11\n" "FreeCADGui.ActiveDocument.%3.Visibility = False\n") .arg(type).arg(name).arg(shape) .arg(axis.x,0,'f',2) @@ -200,7 +208,9 @@ void DlgRevolution::accept() .arg(ui->xPos->value(),0,'f',2) .arg(ui->yPos->value(),0,'f',2) .arg(ui->zPos->value(),0,'f',2) - .arg(ui->angle->value(),0,'f',2); + .arg(ui->angle->value(),0,'f',2) + .arg(solid) + ; Gui::Application::Instance->runPythonCode((const char*)code.toAscii()); QByteArray to = name.toAscii(); QByteArray from = shape.toAscii(); diff --git a/src/Mod/Part/Gui/DlgRevolution.ui b/src/Mod/Part/Gui/DlgRevolution.ui index 6c5635118..23bb66443 100644 --- a/src/Mod/Part/Gui/DlgRevolution.ui +++ b/src/Mod/Part/Gui/DlgRevolution.ui @@ -7,7 +7,7 @@ 0 0 307 - 231 + 266 @@ -20,7 +20,7 @@ 6 - + 0 @@ -105,19 +105,6 @@ - - - - Qt::Vertical - - - - 21 - 21 - - - - @@ -136,13 +123,20 @@ - + Select line in 3D view + + + + Create Solid + + +