Issue #1508 Solid tickBox for Part.Revolution

Creates Solid for closed Edges & Wires
This commit is contained in:
WandererFan 2014-04-24 10:55:20 -04:00 committed by wmayer
parent 8ff9fb9db9
commit 62f00095cd
6 changed files with 67 additions and 24 deletions

View File

@ -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);

View File

@ -41,6 +41,7 @@ public:
App::PropertyVector Base;
App::PropertyVector Axis;
App::PropertyFloatConstraint Angle;
App::PropertyBool Solid;
/** @name methods override feature */
//@{

View File

@ -51,6 +51,7 @@
# include <BRepBuilderAPI_MakeSolid.hxx>
# include <BRepBuilderAPI_MakeVertex.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepBuilderAPI_MakeShell.hxx>
# include <BRepBuilderAPI_NurbsConvert.hxx>
# include <BRepBuilderAPI_FaceError.hxx>
# include <BRepBuilderAPI_Copy.hxx>
@ -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();
}

View File

@ -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,

View File

@ -47,6 +47,9 @@
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Mod/Part/App/Tools.h>
#include <Base/Console.h>
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<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
if (ui->checkSolid->isChecked()) {
solid = QString::fromAscii("True");}
else {
solid = QString::fromAscii("False");}
for (QList<QTreeWidgetItem *>::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();

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>307</width>
<height>231</height>
<height>266</height>
</rect>
</property>
<property name="windowTitle">
@ -20,7 +20,7 @@
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="1">
<item row="0" column="3">
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
@ -105,19 +105,6 @@
</item>
</layout>
</item>
<item row="2" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" rowspan="4">
<widget class="QTreeWidget" name="treeWidget">
<property name="selectionMode">
@ -136,13 +123,20 @@
</column>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="3">
<widget class="QPushButton" name="selectLine">
<property name="text">
<string>Select line in 3D view</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QCheckBox" name="checkSolid">
<property name="text">
<string>Create Solid</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>