From c0e6debcfa4e8c64cf8270acc65f8b38608d0ba0 Mon Sep 17 00:00:00 2001 From: donovaly Date: Mon, 5 Apr 2021 13:59:03 +0200 Subject: [PATCH] [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 --- src/Mod/Part/App/PrimitiveFeature.cpp | 11 +++++- src/Mod/Part/App/PrimitiveFeature.h | 3 +- src/Mod/Part/Gui/DlgPrimitives.cpp | 20 +++++++++- src/Mod/Part/Gui/DlgPrimitives.ui | 54 ++++++++++++++++++++++++++- 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index fdb9630bd2..8d2dc9989f 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -30,6 +30,7 @@ # include # include # include +# include # include # include # include @@ -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(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) { diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index c32009903c..e9cd075e72 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -177,7 +177,8 @@ public: } }; -class PartExport Cylinder : public Primitive +class PartExport Cylinder : public Primitive, + public PrismExtension { PROPERTY_HEADER(Part::Cylinder); diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index b62a36ce37..ce19072f44 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -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(); } diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index f3b661d254..d912cf9556 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -442,7 +442,7 @@ - Angle: + Rotation angle: @@ -544,6 +544,58 @@ + + + + Angle in first direction: + + + + + + + Angle in first direction + + + false + + + deg + + + -90.000000000000000 + + + 90.000000000000000 + + + + + + + Angle in second direction: + + + + + + + Angle in second direction + + + false + + + deg + + + -90.000000000000000 + + + 90.000000000000000 + + +