From 6bbab49723d579e593b56578d13d4e1d117f7772 Mon Sep 17 00:00:00 2001 From: donovaly Date: Sun, 9 Aug 2020 04:24:34 +0200 Subject: [PATCH] [PD and Part] add possibility to create skew prisms --- src/Mod/Part/App/PrimitiveFeature.cpp | 22 +- src/Mod/Part/App/PrimitiveFeature.h | 2 + src/Mod/Part/Gui/DlgPrimitives.cpp | 8 +- src/Mod/Part/Gui/DlgPrimitives.ui | 401 +++++++++++++++--- src/Mod/PartDesign/App/FeaturePrimitive.cpp | 22 +- src/Mod/PartDesign/App/FeaturePrimitive.h | 2 + .../Gui/TaskPrimitiveParameters.cpp | 82 +++- .../PartDesign/Gui/TaskPrimitiveParameters.h | 2 + .../PartDesign/Gui/TaskPrimitiveParameters.ui | 70 +++ 9 files changed, 515 insertions(+), 96 deletions(-) diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index a08441ed41..cd12701ca1 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -561,10 +561,15 @@ PROPERTY_SOURCE(Part::Prism, Part::Primitive) Prism::Prism(void) { - ADD_PROPERTY_TYPE(Polygon,(6.0),"Prism",App::Prop_None,"Number of sides in the polygon, of the prism"); - ADD_PROPERTY_TYPE(Circumradius,(2.0),"Prism",App::Prop_None,"Circumradius (centre to vertex) of the polygon, of the prism"); - ADD_PROPERTY_TYPE(Height,(10.0f),"Prism",App::Prop_None,"The height of the prism"); + ADD_PROPERTY_TYPE(Polygon, (6.0), "Prism", App::Prop_None, "Number of sides in the polygon, of the prism"); + ADD_PROPERTY_TYPE(Circumradius, (2.0), "Prism", App::Prop_None, "Circumradius (centre to vertex) of the polygon, of the prism"); + ADD_PROPERTY_TYPE(Height, (10.0f), "Prism", App::Prop_None, "The height of the prism"); + ADD_PROPERTY_TYPE(FirstSkew, (0.0f), "Prism", App::Prop_None, "Angle in first direction"); + ADD_PROPERTY_TYPE(SecondSkew, (0.0f), "Prism", App::Prop_None, "Angle in second direction"); Polygon.setConstraints(&polygonRange); + static const App::PropertyQuantityConstraint::Constraints angleConstraint = { -89.99999, 89.99999, 1.0 }; + FirstSkew.setConstraints(&angleConstraint); + SecondSkew.setConstraints(&angleConstraint); } short Prism::mustExecute() const @@ -575,6 +580,10 @@ short Prism::mustExecute() const return 1; if (Height.isTouched()) return 1; + if (FirstSkew.isTouched()) + return 1; + if (SecondSkew.isTouched()) + return 1; return Primitive::mustExecute(); } @@ -602,11 +611,14 @@ App::DocumentObjectExecReturn *Prism::execute(void) } mkPoly.Add(gp_Pnt(v.x,v.y,v.z)); BRepBuilderAPI_MakeFace mkFace(mkPoly.Wire()); - BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), gp_Vec(0,0,Height.getValue())); + // the direction vector for the prism is the height for z and the skew + BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), + gp_Vec(Height.getValue() * tan(Base::toRadians(FirstSkew.getValue())), + Height.getValue() * tan(Base::toRadians(SecondSkew.getValue())), + Height.getValue())); this->Shape.setValue(mkPrism.Shape()); } catch (Standard_Failure& e) { - return new App::DocumentObjectExecReturn(e.GetMessageString()); } diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index 7d9fafba21..b2cad57913 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -209,6 +209,8 @@ public: App::PropertyIntegerConstraint Polygon; App::PropertyLength Circumradius; App::PropertyLength Height; + App::PropertyAngle FirstSkew; + App::PropertyAngle SecondSkew; /** @name methods override feature */ //@{ diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index e9469f5ad5..75ec27c1ca 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -501,12 +501,16 @@ void DlgPrimitives::createPrimitive(const QString& placement) "App.ActiveDocument.%1.Polygon=%2\n" "App.ActiveDocument.%1.Circumradius=%3\n" "App.ActiveDocument.%1.Height=%4\n" - "App.ActiveDocument.%1.Placement=%5\n" - "App.ActiveDocument.%1.Label='%6'\n") + "App.ActiveDocument.%1.FirstSkew=%5\n" + "App.ActiveDocument.%1.SecondSkew=%6\n" + "App.ActiveDocument.%1.Placement=%7\n" + "App.ActiveDocument.%1.Label='%8'\n") .arg(name) .arg(ui.prismPolygon->value()) .arg(ui.prismCircumradius->value().getValue(),0,'f',Base::UnitsApi::getDecimals()) .arg(ui.prismHeight->value().getValue(),0,'f',Base::UnitsApi::getDecimals()) + .arg(ui.prismXSkew->value().getValue(), 0, 'f', Base::UnitsApi::getDecimals()) + .arg(ui.prismYSkew->value().getValue(), 0, 'f', Base::UnitsApi::getDecimals()) .arg(placement) .arg(tr("Prism")); } diff --git a/src/Mod/Part/Gui/DlgPrimitives.ui b/src/Mod/Part/Gui/DlgPrimitives.ui index 4a2490c8ea..2365214303 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.ui +++ b/src/Mod/Part/Gui/DlgPrimitives.ui @@ -180,7 +180,16 @@ Parameter - + + 9 + + + 9 + + + 9 + + 9 @@ -193,7 +202,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -201,7 +219,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -260,7 +287,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -284,7 +320,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -347,7 +392,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -358,7 +412,16 @@ 6 - + + 0 + + + 0 + + + 0 + + 0 @@ -408,7 +471,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -454,7 +526,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -465,7 +546,16 @@ 6 - + + 0 + + + 0 + + + 0 + + 0 @@ -515,7 +605,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -578,7 +677,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -596,7 +704,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -685,7 +802,16 @@ 6 - + + 0 + + + 0 + + + 0 + + 0 @@ -711,7 +837,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -742,7 +877,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -803,7 +947,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -875,7 +1028,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -893,7 +1055,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -979,7 +1150,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -1025,7 +1205,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -1033,7 +1222,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -1093,6 +1291,52 @@ + + + + Angle in first direction: + + + + + + + Angle in first direction + + + deg + + + -90.000000000000000 + + + 90.000000000000000 + + + + + + + Angle in second direction: + + + + + + + Angle in second direction + + + deg + + + -90.000000000000000 + + + 90.000000000000000 + + + @@ -1160,9 +1404,6 @@ mm - - 0.000000000000000 - @@ -1180,9 +1421,6 @@ mm - - 0.000000000000000 - @@ -1200,9 +1438,6 @@ mm - - 0.000000000000000 - @@ -1274,7 +1509,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -1295,7 +1539,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -1355,9 +1608,6 @@ deg - - 0.000000000000000 - @@ -1396,7 +1646,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -1417,7 +1676,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -1482,7 +1750,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -1514,9 +1791,6 @@ deg - - 0.000000000000000 - @@ -1637,9 +1911,6 @@ deg - - 0.000000000000000 - @@ -1708,9 +1979,6 @@ mm - - 0.000000000000000 - @@ -1718,9 +1986,6 @@ mm - - 0.000000000000000 - @@ -1728,9 +1993,6 @@ mm - - 0.000000000000000 - @@ -1843,9 +2105,6 @@ mm - - 0.000000000000000 - @@ -1853,9 +2112,6 @@ mm - - 0.000000000000000 - @@ -1863,9 +2119,6 @@ mm - - 0.000000000000000 - @@ -1917,7 +2170,16 @@ - + + 9 + + + 9 + + + 9 + + 9 @@ -1925,7 +2187,16 @@ - + + 0 + + + 0 + + + 0 + + 0 diff --git a/src/Mod/PartDesign/App/FeaturePrimitive.cpp b/src/Mod/PartDesign/App/FeaturePrimitive.cpp index a881928d62..759ee1a598 100644 --- a/src/Mod/PartDesign/App/FeaturePrimitive.cpp +++ b/src/Mod/PartDesign/App/FeaturePrimitive.cpp @@ -532,9 +532,14 @@ PROPERTY_SOURCE(PartDesign::Prism, PartDesign::FeaturePrimitive) Prism::Prism() { - ADD_PROPERTY_TYPE(Polygon,(6.0),"Prism",App::Prop_None,"Number of sides in the polygon, of the prism"); - ADD_PROPERTY_TYPE(Circumradius,(2.0),"Prism",App::Prop_None,"Circumradius (centre to vertex) of the polygon, of the prism"); - ADD_PROPERTY_TYPE(Height,(10.0f),"Prism",App::Prop_None,"The height of the prism"); + ADD_PROPERTY_TYPE(Polygon, (6.0), "Prism", App::Prop_None, "Number of sides in the polygon, of the prism"); + ADD_PROPERTY_TYPE(Circumradius, (2.0), "Prism", App::Prop_None, "Circumradius (centre to vertex) of the polygon, of the prism"); + ADD_PROPERTY_TYPE(Height, (10.0f), "Prism", App::Prop_None, "The height of the prism"); + ADD_PROPERTY_TYPE(FirstSkew, (0.0f), "Prism", App::Prop_None, "Angle in first direction"); + ADD_PROPERTY_TYPE(SecondSkew, (0.0f), "Prism", App::Prop_None, "Angle in second direction"); + static const App::PropertyQuantityConstraint::Constraints angleConstraint = { -89.99999, 89.99999, 1.0 }; + FirstSkew.setConstraints(&angleConstraint); + SecondSkew.setConstraints(&angleConstraint); primitiveType = FeaturePrimitive::Prism; } @@ -563,11 +568,14 @@ App::DocumentObjectExecReturn* Prism::execute(void) } mkPoly.Add(gp_Pnt(v.x,v.y,v.z)); BRepBuilderAPI_MakeFace mkFace(mkPoly.Wire()); - BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), gp_Vec(0,0,Height.getValue())); + // the direction vector for the prism is the height for z and the skew + BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), + gp_Vec(Height.getValue() * tan(Base::toRadians(FirstSkew.getValue())), + Height.getValue() * tan(Base::toRadians(SecondSkew.getValue())), + Height.getValue())); return FeaturePrimitive::execute(mkPrism.Shape()); } catch (Standard_Failure& e) { - return new App::DocumentObjectExecReturn(e.GetMessageString()); } @@ -582,6 +590,10 @@ short int Prism::mustExecute() const return 1; if (Height.isTouched()) return 1; + if (FirstSkew.isTouched()) + return 1; + if (SecondSkew.isTouched()) + return 1; return FeaturePrimitive::mustExecute(); } diff --git a/src/Mod/PartDesign/App/FeaturePrimitive.h b/src/Mod/PartDesign/App/FeaturePrimitive.h index d231646955..ca43701a00 100644 --- a/src/Mod/PartDesign/App/FeaturePrimitive.h +++ b/src/Mod/PartDesign/App/FeaturePrimitive.h @@ -318,6 +318,8 @@ public: App::PropertyIntegerConstraint Polygon; App::PropertyLength Circumradius; App::PropertyLength Height; + App::PropertyAngle FirstSkew; + App::PropertyAngle SecondSkew; /** @name methods override feature */ //@{ diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp index cb8de995b8..7342615712 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -24,30 +24,30 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +# include +# include # include # include -# include -# include +# include #endif #include "TaskPrimitiveParameters.h" #include "ui_TaskPrimitiveParameters.h" #include "ViewProviderDatumCS.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace PartDesignGui; @@ -192,6 +192,10 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) ui->prismCircumradius->bind(static_cast(vp->getObject())->Circumradius); ui->prismHeight->setValue(static_cast(vp->getObject())->Height.getValue()); ui->prismHeight->bind(static_cast(vp->getObject())->Height); + ui->prismXSkew->setValue(static_cast(vp->getObject())->FirstSkew.getValue()); + ui->prismXSkew->bind(static_cast(vp->getObject())->FirstSkew); + ui->prismYSkew->setValue(static_cast(vp->getObject())->SecondSkew.getValue()); + ui->prismYSkew->bind(static_cast(vp->getObject())->SecondSkew); ui->prismCircumradius->setMaximum(INT_MAX); ui->prismCircumradius->setMinimum(0.0); ui->prismHeight->setMaximum(INT_MAX); @@ -306,6 +310,8 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) //prism connect(ui->prismCircumradius, SIGNAL(valueChanged(double)), this, SLOT(onPrismCircumradiusChanged(double))); connect(ui->prismHeight, SIGNAL(valueChanged(double)), this, SLOT(onPrismHeightChanged(double))); + connect(ui->prismXSkew, SIGNAL(valueChanged(double)), this, SLOT(onPrismXSkewChanged(double))); + connect(ui->prismYSkew, SIGNAL(valueChanged(double)), this, SLOT(onPrismYSkewChanged(double))); connect(ui->prismPolygon, SIGNAL(valueChanged(int)), this, SLOT(onPrismPolygonChanged(int))); // wedge @@ -520,6 +526,40 @@ void TaskBoxPrimitives::onPrismHeightChanged(double v) { vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); } +void TaskBoxPrimitives::onPrismXSkewChanged(double v) { + PartDesign::Prism* sph = static_cast(vp->getObject()); + // we must assure that if the user incremented from e.g. 85 degree with the + // spin buttons he does not end at 90.0 but 89.9999 which is shown rounded to 90 degree + if ((v < 90.0) && (v > -90.0)) { + sph->FirstSkew.setValue(v); + } + else { + if (v == 90.0) + sph->FirstSkew.setValue(89.99999); + else if (v == -90.0) + sph->FirstSkew.setValue(-89.99999); + ui->prismXSkew->setValue(sph->FirstSkew.getQuantityValue()); + } + vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +} + +void TaskBoxPrimitives::onPrismYSkewChanged(double v) { + PartDesign::Prism* sph = static_cast(vp->getObject()); + // we must assure that if the user incremented from e.g. 85 degree with the + // spin buttons he does not end at 90.0 but 89.9999 which is shown rounded to 90 degree + if ((v < 90.0) && (v > -90.0)) { + sph->SecondSkew.setValue(v); + } + else { + if (v == 90.0) + sph->SecondSkew.setValue(89.99999); + else if (v == -90.0) + sph->SecondSkew.setValue(-89.99999); + ui->prismYSkew->setValue(sph->SecondSkew.getQuantityValue()); + } + vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +} + void TaskBoxPrimitives::onPrismPolygonChanged(int v) { PartDesign::Prism* sph = static_cast(vp->getObject()); sph->Polygon.setValue(v); @@ -692,11 +732,15 @@ void TaskBoxPrimitives::setPrimitive(App::DocumentObject *obj) cmd = QString::fromLatin1( "%1.Polygon=%2\n" "%1.Circumradius=%3\n" - "%1.Height=%4\n") + "%1.Height=%4\n" + "%1.FirstSkew=%5\n" + "%1.SecondSkew=%6\n") .arg(name) .arg(ui->prismPolygon->value()) - .arg(ui->prismCircumradius->value().getValue(),0,'f',Base::UnitsApi::getDecimals()) - .arg(ui->prismHeight->value().getValue(),0,'f',Base::UnitsApi::getDecimals()); + .arg(ui->prismCircumradius->value().getValue(), 0, 'f', Base::UnitsApi::getDecimals()) + .arg(ui->prismHeight->value().getValue(), 0, 'f', Base::UnitsApi::getDecimals()) + .arg(ui->prismXSkew->value().getValue(), 0, 'f', Base::UnitsApi::getDecimals()) + .arg(ui->prismYSkew->value().getValue(), 0, 'f', Base::UnitsApi::getDecimals()); break; case 8: // wedge cmd = QString::fromLatin1( diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h index db43aa2a78..0049d2017f 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h @@ -85,6 +85,8 @@ public Q_SLOTS: void onTorusAngle3Changed(double); void onPrismCircumradiusChanged(double); void onPrismHeightChanged(double); + void onPrismXSkewChanged(double); + void onPrismYSkewChanged(double); void onPrismPolygonChanged(int); void onWedgeXmaxChanged(double); void onWedgeXminChanged(double); diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.ui b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.ui index 52cb615919..bcacdbd4dd 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.ui @@ -1200,6 +1200,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 + + + @@ -1264,6 +1316,9 @@ + + false + mm @@ -1284,6 +1339,9 @@ + + false + mm @@ -1304,6 +1362,9 @@ + + false + mm @@ -1324,6 +1385,9 @@ + + false + mm @@ -1347,6 +1411,9 @@ + + false + mm @@ -2158,6 +2225,9 @@ + + false + 3