[Part] add direction to cylinder primitive
We already have the possibility to create skewed prisms. I recently stumbled upon that I would need this feature for cylinders too. This PR takes the existing prism extrude direction feature and use it for cylinders too
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
# include <BRepPrimAPI_MakePrism.hxx>
|
||||
# include <BRepPrimAPI_MakeRevol.hxx>
|
||||
# include <BRepPrimAPI_MakeSphere.hxx>
|
||||
# include <BRepPrim_Cylinder.hxx>
|
||||
# include <BRepPrim_Wedge.hxx>
|
||||
# include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
# include <BRepBuilderAPI_MakeFace.hxx>
|
||||
@@ -529,6 +530,8 @@ Cylinder::Cylinder(void)
|
||||
ADD_PROPERTY_TYPE(Height,(10.0f),"Cylinder",App::Prop_None,"The height of the cylinder");
|
||||
ADD_PROPERTY_TYPE(Angle,(360.0f),"Cylinder",App::Prop_None,"The angle of the cylinder");
|
||||
Angle.setConstraints(&angleRangeU);
|
||||
|
||||
PrismExtension::initExtension(this);
|
||||
}
|
||||
|
||||
short Cylinder::mustExecute() const
|
||||
@@ -549,11 +552,15 @@ App::DocumentObjectExecReturn *Cylinder::execute(void)
|
||||
return new App::DocumentObjectExecReturn("Radius of cylinder too small");
|
||||
if (Height.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Height of cylinder too small");
|
||||
if (Angle.getValue() < Precision::Confusion())
|
||||
return new App::DocumentObjectExecReturn("Rotation angle of cylinder too small");
|
||||
try {
|
||||
BRepPrimAPI_MakeCylinder mkCylr(Radius.getValue(),
|
||||
Height.getValue(),
|
||||
Angle.getValue()/180.0f*M_PI);
|
||||
TopoDS_Shape ResultShape = mkCylr.Shape();
|
||||
Base::toRadians<double>(Angle.getValue()));
|
||||
// the direction vector for the prism is the height for z and the given angle
|
||||
BRepPrim_Cylinder prim = mkCylr.Cylinder();
|
||||
TopoDS_Shape ResultShape = makePrism(Height.getValue(), prim.BottomFace());
|
||||
this->Shape.setValue(ResultShape);
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
|
||||
@@ -177,7 +177,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class PartExport Cylinder : public Primitive
|
||||
class PartExport Cylinder : public Primitive,
|
||||
public PrismExtension
|
||||
{
|
||||
PROPERTY_HEADER(Part::Cylinder);
|
||||
|
||||
|
||||
@@ -358,6 +358,10 @@ DlgPrimitives::DlgPrimitives(QWidget* parent, Part::Primitive* feature)
|
||||
ui->cylinderRadius->bind(cyl->Radius);
|
||||
ui->cylinderHeight->setValue(cyl->Height.getQuantityValue());
|
||||
ui->cylinderHeight->bind(cyl->Height);
|
||||
ui->cylinderXSkew->setValue(cyl->FirstAngle.getQuantityValue());
|
||||
ui->cylinderXSkew->bind(cyl->FirstAngle);
|
||||
ui->cylinderYSkew->setValue(cyl->SecondAngle.getQuantityValue());
|
||||
ui->cylinderYSkew->bind(cyl->SecondAngle);
|
||||
ui->cylinderAngle->setValue(cyl->Angle.getQuantityValue());
|
||||
ui->cylinderAngle->bind(cyl->Angle);
|
||||
|
||||
@@ -365,6 +369,8 @@ DlgPrimitives::DlgPrimitives(QWidget* parent, Part::Primitive* feature)
|
||||
connect(mapper, SIGNAL(mapped(QWidget*)), this, SLOT(onChangeCylinder(QWidget*)));
|
||||
connectSignalMapper(ui->cylinderRadius, SIGNAL(valueChanged(double)), mapper);
|
||||
connectSignalMapper(ui->cylinderHeight, SIGNAL(valueChanged(double)), mapper);
|
||||
connectSignalMapper(ui->cylinderXSkew, SIGNAL(valueChanged(double)), mapper);
|
||||
connectSignalMapper(ui->cylinderYSkew, SIGNAL(valueChanged(double)), mapper);
|
||||
connectSignalMapper(ui->cylinderAngle, SIGNAL(valueChanged(double)), mapper);
|
||||
}
|
||||
else if (type == Part::Cone::getClassTypeId()) {
|
||||
@@ -744,12 +750,16 @@ QString DlgPrimitives::createCylinder(const QString& objectName, const QString&
|
||||
"App.ActiveDocument.%1.Radius=%2\n"
|
||||
"App.ActiveDocument.%1.Height=%3\n"
|
||||
"App.ActiveDocument.%1.Angle=%4\n"
|
||||
"App.ActiveDocument.%1.Placement=%5\n"
|
||||
"App.ActiveDocument.%1.Label='%6'\n")
|
||||
"App.ActiveDocument.%1.FirstAngle=%5\n"
|
||||
"App.ActiveDocument.%1.SecondAngle=%6\n"
|
||||
"App.ActiveDocument.%1.Placement=%7\n"
|
||||
"App.ActiveDocument.%1.Label='%8'\n")
|
||||
.arg(objectName)
|
||||
.arg(ui->cylinderRadius->value().getValue(),0,'f',Base::UnitsApi::getDecimals())
|
||||
.arg(ui->cylinderHeight->value().getValue(),0,'f',Base::UnitsApi::getDecimals())
|
||||
.arg(ui->cylinderAngle->value().getValue(),0,'f',Base::UnitsApi::getDecimals())
|
||||
.arg(ui->cylinderXSkew->value().getValue(),0,'f',Base::UnitsApi::getDecimals())
|
||||
.arg(ui->cylinderYSkew->value().getValue(),0,'f',Base::UnitsApi::getDecimals())
|
||||
.arg(placement)
|
||||
.arg(tr("Cylinder"));
|
||||
}
|
||||
@@ -1494,6 +1504,12 @@ void DlgPrimitives::onChangeCylinder(QWidget* widget)
|
||||
else if (widget == ui->cylinderAngle) {
|
||||
cyl->Angle.setValue(ui->cylinderAngle->value().getValue());
|
||||
}
|
||||
else if (widget == ui->cylinderXSkew) {
|
||||
cyl->FirstAngle.setValue(ui->cylinderXSkew->value().getValue());
|
||||
}
|
||||
else if (widget == ui->cylinderYSkew) {
|
||||
cyl->SecondAngle.setValue(ui->cylinderYSkew->value().getValue());
|
||||
}
|
||||
|
||||
cyl->recomputeFeature();
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Angle:</string>
|
||||
<string>Rotation angle:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -544,6 +544,58 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelCylinderXSkew">
|
||||
<property name="text">
|
||||
<string>Angle in first direction:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="cylinderXSkew">
|
||||
<property name="toolTip">
|
||||
<string>Angle in first direction</string>
|
||||
</property>
|
||||
<property name="keyboardTracking" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">deg</string>
|
||||
</property>
|
||||
<property name="minimum" stdset="0">
|
||||
<double>-90.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum" stdset="0">
|
||||
<double>90.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelCylinderYSkew">
|
||||
<property name="text">
|
||||
<string>Angle in second direction:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="cylinderYSkew">
|
||||
<property name="toolTip">
|
||||
<string>Angle in second direction</string>
|
||||
</property>
|
||||
<property name="keyboardTracking" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">deg</string>
|
||||
</property>
|
||||
<property name="minimum" stdset="0">
|
||||
<double>-90.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum" stdset="0">
|
||||
<double>90.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user