From 1eb0444bd5b80e103f21f5dbbfb8f95db7e8a79a Mon Sep 17 00:00:00 2001 From: Florian Foinant-Willig Date: Mon, 12 Feb 2024 18:21:53 +0100 Subject: [PATCH] Part & PartDesign Cone: allow equal radii (#12219) * PartDesign_Cone: allow equal radii * fix R2 < R1 * Part_Cone: allow equal radii --- src/Mod/Part/App/PrimitiveFeature.cpp | 21 +++++++++++++------ src/Mod/PartDesign/App/FeaturePrimitive.cpp | 10 ++++++--- .../Gui/TaskPrimitiveParameters.cpp | 6 ------ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index d77265d5aa..900fe17d81 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -658,12 +658,21 @@ App::DocumentObjectExecReturn *Cone::execute() if (Height.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Height of cone too small"); try { - // Build a cone - BRepPrimAPI_MakeCone mkCone(Radius1.getValue(), - Radius2.getValue(), - Height.getValue(), - Angle.getValue()/180.0f*M_PI); - TopoDS_Shape ResultShape = mkCone.Shape(); + TopoDS_Shape ResultShape; + if (std::abs(Radius1.getValue() - Radius2.getValue()) < Precision::Confusion()){ + //Build a cylinder + BRepPrimAPI_MakeCylinder mkCylr(Radius1.getValue(), + Height.getValue(), + 2.0 * M_PI); + ResultShape = mkCylr.Shape(); + } else { + // Build a cone + BRepPrimAPI_MakeCone mkCone(Radius1.getValue(), + Radius2.getValue(), + Height.getValue(), + Angle.getValue()/180.0f*M_PI); + ResultShape = mkCone.Shape(); + } this->Shape.setValue(ResultShape); } catch (Standard_Failure& e) { diff --git a/src/Mod/PartDesign/App/FeaturePrimitive.cpp b/src/Mod/PartDesign/App/FeaturePrimitive.cpp index 331c56dbea..d07b36d390 100644 --- a/src/Mod/PartDesign/App/FeaturePrimitive.cpp +++ b/src/Mod/PartDesign/App/FeaturePrimitive.cpp @@ -354,17 +354,21 @@ App::DocumentObjectExecReturn* Cone::execute() return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Radius of cone cannot be negative")); if (Radius2.getValue() < 0.0) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Radius of cone cannot be negative")); - if (Radius1.getValue() == Radius2.getValue()) - return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "The radii for cones must not be equal")); if (Height.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Height of cone too small")); try { + if (std::abs(Radius1.getValue() - Radius2.getValue()) < Precision::Confusion()){ + //Build a cylinder + BRepPrimAPI_MakeCylinder mkCylr(Radius1.getValue(), + Height.getValue(), + 2.0 * M_PI); + return FeaturePrimitive::execute(mkCylr.Shape()); + } // Build a cone BRepPrimAPI_MakeCone mkCone(Radius1.getValue(), Radius2.getValue(), Height.getValue(), Base::toRadians(Angle.getValue())); - return FeaturePrimitive::execute(mkCone.Shape()); } catch (Standard_Failure& e) { diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp index cc245ba675..20d8ed2eda 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -755,12 +755,6 @@ bool TaskBoxPrimitives::setPrimitive(App::DocumentObject *obj) break; case 3: // cone - // the cone radii must not be equal - if (ui->coneRadius1->value().getValue() == ui->coneRadius2->value().getValue()) { - QMessageBox::warning(Gui::getMainWindow(), tr("Cone radii are equal"), - tr("The radii for cones must not be equal!")); - return false; - } cmd = QString::fromLatin1( "%1.Radius1='%2'\n" "%1.Radius2='%3'\n"