From 839fd1fec0edec29056c6be553b3b3701ced8ccc Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 18 Jul 2024 14:28:52 +0200 Subject: [PATCH] PD: Fix possible crash in primitive dialog --- .../Gui/TaskPrimitiveParameters.cpp | 966 +++++++++--------- .../PartDesign/Gui/TaskPrimitiveParameters.h | 10 + 2 files changed, 515 insertions(+), 461 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp index 20d8ed2eda..4cda76ead3 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -56,171 +56,171 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) this->groupLayout()->addWidget(proxy); int index = 0; - switch(static_cast(vp->getObject())->getPrimitiveType()) { + switch(getObject()->getPrimitiveType()) { case PartDesign::FeaturePrimitive::Box: index = 1; - ui->boxLength->setValue(static_cast(vp->getObject())->Length.getValue()); - ui->boxLength->bind(static_cast(vp->getObject())->Length); - ui->boxHeight->setValue(static_cast(vp->getObject())->Height.getValue()); - ui->boxHeight->bind(static_cast(vp->getObject())->Height); - ui->boxWidth->setValue(static_cast(vp->getObject())->Width.getValue()); - ui->boxWidth->bind(static_cast(vp->getObject())->Width); - ui->boxLength->setMinimum(static_cast(vp->getObject())->Length.getMinimum()); - ui->boxLength->setMaximum(static_cast(vp->getObject())->Length.getMaximum()); - ui->boxWidth->setMinimum(static_cast(vp->getObject())->Width.getMinimum()); - ui->boxWidth->setMaximum(static_cast(vp->getObject())->Width.getMaximum()); - ui->boxHeight->setMinimum(static_cast(vp->getObject())->Height.getMinimum()); - ui->boxHeight->setMaximum(static_cast(vp->getObject())->Height.getMaximum()); + ui->boxLength->setValue(getObject()->Length.getValue()); + ui->boxLength->bind(getObject()->Length); + ui->boxHeight->setValue(getObject()->Height.getValue()); + ui->boxHeight->bind(getObject()->Height); + ui->boxWidth->setValue(getObject()->Width.getValue()); + ui->boxWidth->bind(getObject()->Width); + ui->boxLength->setMinimum(getObject()->Length.getMinimum()); + ui->boxLength->setMaximum(getObject()->Length.getMaximum()); + ui->boxWidth->setMinimum(getObject()->Width.getMinimum()); + ui->boxWidth->setMaximum(getObject()->Width.getMaximum()); + ui->boxHeight->setMinimum(getObject()->Height.getMinimum()); + ui->boxHeight->setMaximum(getObject()->Height.getMaximum()); break; case PartDesign::FeaturePrimitive::Cylinder: index = 2; - ui->cylinderAngle->setValue(static_cast(vp->getObject())->Angle.getValue()); - ui->cylinderAngle->bind(static_cast(vp->getObject())->Angle); - ui->cylinderHeight->setValue(static_cast(vp->getObject())->Height.getValue()); - ui->cylinderHeight->bind(static_cast(vp->getObject())->Height); - ui->cylinderRadius->setValue(static_cast(vp->getObject())->Radius.getValue()); - ui->cylinderRadius->bind(static_cast(vp->getObject())->Radius); - ui->cylinderXSkew->setValue(static_cast(vp->getObject())->FirstAngle.getValue()); - ui->cylinderXSkew->bind(static_cast(vp->getObject())->FirstAngle); - ui->cylinderYSkew->setValue(static_cast(vp->getObject())->SecondAngle.getValue()); - ui->cylinderYSkew->bind(static_cast(vp->getObject())->SecondAngle); - ui->cylinderAngle->setMaximum(static_cast(vp->getObject())->Angle.getMaximum()); - ui->cylinderAngle->setMinimum(static_cast(vp->getObject())->Angle.getMinimum()); - ui->cylinderHeight->setMaximum(static_cast(vp->getObject())->Height.getMaximum()); - ui->cylinderHeight->setMinimum(static_cast(vp->getObject())->Height.getMinimum()); - ui->cylinderRadius->setMaximum(static_cast(vp->getObject())->Radius.getMaximum()); - ui->cylinderRadius->setMinimum(static_cast(vp->getObject())->Radius.getMinimum()); + ui->cylinderAngle->setValue(getObject()->Angle.getValue()); + ui->cylinderAngle->bind(getObject()->Angle); + ui->cylinderHeight->setValue(getObject()->Height.getValue()); + ui->cylinderHeight->bind(getObject()->Height); + ui->cylinderRadius->setValue(getObject()->Radius.getValue()); + ui->cylinderRadius->bind(getObject()->Radius); + ui->cylinderXSkew->setValue(getObject()->FirstAngle.getValue()); + ui->cylinderXSkew->bind(getObject()->FirstAngle); + ui->cylinderYSkew->setValue(getObject()->SecondAngle.getValue()); + ui->cylinderYSkew->bind(getObject()->SecondAngle); + ui->cylinderAngle->setMaximum(getObject()->Angle.getMaximum()); + ui->cylinderAngle->setMinimum(getObject()->Angle.getMinimum()); + ui->cylinderHeight->setMaximum(getObject()->Height.getMaximum()); + ui->cylinderHeight->setMinimum(getObject()->Height.getMinimum()); + ui->cylinderRadius->setMaximum(getObject()->Radius.getMaximum()); + ui->cylinderRadius->setMinimum(getObject()->Radius.getMinimum()); break; case PartDesign::FeaturePrimitive::Sphere: index = 4; - ui->sphereAngle1->setValue(static_cast(vp->getObject())->Angle1.getValue()); - ui->sphereAngle1->bind(static_cast(vp->getObject())->Angle1); - ui->sphereAngle2->setValue(static_cast(vp->getObject())->Angle2.getValue()); - ui->sphereAngle2->bind(static_cast(vp->getObject())->Angle2); - ui->sphereAngle3->setValue(static_cast(vp->getObject())->Angle3.getValue()); - ui->sphereAngle3->bind(static_cast(vp->getObject())->Angle3); - ui->sphereRadius->setValue(static_cast(vp->getObject())->Radius.getValue()); - ui->sphereRadius->bind(static_cast(vp->getObject())->Radius); + ui->sphereAngle1->setValue(getObject()->Angle1.getValue()); + ui->sphereAngle1->bind(getObject()->Angle1); + ui->sphereAngle2->setValue(getObject()->Angle2.getValue()); + ui->sphereAngle2->bind(getObject()->Angle2); + ui->sphereAngle3->setValue(getObject()->Angle3.getValue()); + ui->sphereAngle3->bind(getObject()->Angle3); + ui->sphereRadius->setValue(getObject()->Radius.getValue()); + ui->sphereRadius->bind(getObject()->Radius); ui->sphereAngle1->setMaximum(ui->sphereAngle2->rawValue()); // must geometrically be <= than sphereAngle2 - ui->sphereAngle1->setMinimum(static_cast(vp->getObject())->Angle1.getMinimum()); - ui->sphereAngle2->setMaximum(static_cast(vp->getObject())->Angle2.getMaximum()); + ui->sphereAngle1->setMinimum(getObject()->Angle1.getMinimum()); + ui->sphereAngle2->setMaximum(getObject()->Angle2.getMaximum()); ui->sphereAngle2->setMinimum(ui->sphereAngle1->rawValue()); - ui->sphereAngle3->setMaximum(static_cast(vp->getObject())->Angle3.getMaximum()); - ui->sphereAngle3->setMinimum(static_cast(vp->getObject())->Angle3.getMinimum()); - ui->sphereRadius->setMaximum(static_cast(vp->getObject())->Radius.getMaximum()); - ui->sphereRadius->setMinimum(static_cast(vp->getObject())->Radius.getMinimum()); + ui->sphereAngle3->setMaximum(getObject()->Angle3.getMaximum()); + ui->sphereAngle3->setMinimum(getObject()->Angle3.getMinimum()); + ui->sphereRadius->setMaximum(getObject()->Radius.getMaximum()); + ui->sphereRadius->setMinimum(getObject()->Radius.getMinimum()); break; case PartDesign::FeaturePrimitive::Cone: index = 3; - ui->coneAngle->setValue(static_cast(vp->getObject())->Angle.getValue()); - ui->coneAngle->bind(static_cast(vp->getObject())->Angle); - ui->coneHeight->setValue(static_cast(vp->getObject())->Height.getValue()); - ui->coneHeight->bind(static_cast(vp->getObject())->Height); - ui->coneRadius1->setValue(static_cast(vp->getObject())->Radius1.getValue()); - ui->coneRadius1->bind(static_cast(vp->getObject())->Radius1); - ui->coneRadius2->setValue(static_cast(vp->getObject())->Radius2.getValue()); - ui->coneRadius2->bind(static_cast(vp->getObject())->Radius2); - ui->coneAngle->setMaximum(static_cast(vp->getObject())->Angle.getMaximum()); - ui->coneAngle->setMinimum(static_cast(vp->getObject())->Angle.getMinimum()); - ui->coneHeight->setMaximum(static_cast(vp->getObject())->Height.getMaximum()); - ui->coneHeight->setMinimum(static_cast(vp->getObject())->Height.getMinimum()); - ui->coneRadius1->setMaximum(static_cast(vp->getObject())->Radius1.getMaximum()); - ui->coneRadius1->setMinimum(static_cast(vp->getObject())->Radius1.getMinimum()); - ui->coneRadius2->setMaximum(static_cast(vp->getObject())->Radius2.getMaximum()); - ui->coneRadius2->setMinimum(static_cast(vp->getObject())->Radius2.getMinimum()); + ui->coneAngle->setValue(getObject()->Angle.getValue()); + ui->coneAngle->bind(getObject()->Angle); + ui->coneHeight->setValue(getObject()->Height.getValue()); + ui->coneHeight->bind(getObject()->Height); + ui->coneRadius1->setValue(getObject()->Radius1.getValue()); + ui->coneRadius1->bind(getObject()->Radius1); + ui->coneRadius2->setValue(getObject()->Radius2.getValue()); + ui->coneRadius2->bind(getObject()->Radius2); + ui->coneAngle->setMaximum(getObject()->Angle.getMaximum()); + ui->coneAngle->setMinimum(getObject()->Angle.getMinimum()); + ui->coneHeight->setMaximum(getObject()->Height.getMaximum()); + ui->coneHeight->setMinimum(getObject()->Height.getMinimum()); + ui->coneRadius1->setMaximum(getObject()->Radius1.getMaximum()); + ui->coneRadius1->setMinimum(getObject()->Radius1.getMinimum()); + ui->coneRadius2->setMaximum(getObject()->Radius2.getMaximum()); + ui->coneRadius2->setMinimum(getObject()->Radius2.getMinimum()); break; case PartDesign::FeaturePrimitive::Ellipsoid: index = 5; - ui->ellipsoidAngle1->setValue(static_cast(vp->getObject())->Angle1.getValue()); - ui->ellipsoidAngle1->bind(static_cast(vp->getObject())->Angle1); - ui->ellipsoidAngle2->setValue(static_cast(vp->getObject())->Angle2.getValue()); - ui->ellipsoidAngle2->bind(static_cast(vp->getObject())->Angle2); - ui->ellipsoidAngle3->setValue(static_cast(vp->getObject())->Angle3.getValue()); - ui->ellipsoidAngle3->bind(static_cast(vp->getObject())->Angle3); - ui->ellipsoidRadius1->setValue(static_cast(vp->getObject())->Radius1.getValue()); - ui->ellipsoidRadius1->bind(static_cast(vp->getObject())->Radius1); - ui->ellipsoidRadius2->setValue(static_cast(vp->getObject())->Radius2.getValue()); - ui->ellipsoidRadius2->bind(static_cast(vp->getObject())->Radius2); - ui->ellipsoidRadius3->setValue(static_cast(vp->getObject())->Radius3.getValue()); - ui->ellipsoidRadius3->bind(static_cast(vp->getObject())->Radius3); + ui->ellipsoidAngle1->setValue(getObject()->Angle1.getValue()); + ui->ellipsoidAngle1->bind(getObject()->Angle1); + ui->ellipsoidAngle2->setValue(getObject()->Angle2.getValue()); + ui->ellipsoidAngle2->bind(getObject()->Angle2); + ui->ellipsoidAngle3->setValue(getObject()->Angle3.getValue()); + ui->ellipsoidAngle3->bind(getObject()->Angle3); + ui->ellipsoidRadius1->setValue(getObject()->Radius1.getValue()); + ui->ellipsoidRadius1->bind(getObject()->Radius1); + ui->ellipsoidRadius2->setValue(getObject()->Radius2.getValue()); + ui->ellipsoidRadius2->bind(getObject()->Radius2); + ui->ellipsoidRadius3->setValue(getObject()->Radius3.getValue()); + ui->ellipsoidRadius3->bind(getObject()->Radius3); ui->ellipsoidAngle1->setMaximum(ui->ellipsoidAngle2->rawValue()); // must geometrically be <= than sphereAngle2 - ui->ellipsoidAngle1->setMinimum(static_cast(vp->getObject())->Angle1.getMinimum()); - ui->ellipsoidAngle2->setMaximum(static_cast(vp->getObject())->Angle2.getMaximum()); + ui->ellipsoidAngle1->setMinimum(getObject()->Angle1.getMinimum()); + ui->ellipsoidAngle2->setMaximum(getObject()->Angle2.getMaximum()); ui->ellipsoidAngle2->setMinimum(ui->ellipsoidAngle1->rawValue()); - ui->ellipsoidAngle3->setMaximum(static_cast(vp->getObject())->Angle3.getMaximum()); - ui->ellipsoidAngle3->setMinimum(static_cast(vp->getObject())->Angle3.getMinimum()); - ui->ellipsoidRadius1->setMinimum(static_cast(vp->getObject())->Radius1.getMinimum()); - ui->ellipsoidRadius1->setMaximum(static_cast(vp->getObject())->Radius1.getMaximum()); - ui->ellipsoidRadius2->setMinimum(static_cast(vp->getObject())->Radius2.getMinimum()); - ui->ellipsoidRadius2->setMaximum(static_cast(vp->getObject())->Radius2.getMaximum()); - ui->ellipsoidRadius3->setMinimum(static_cast(vp->getObject())->Radius3.getMinimum()); - ui->ellipsoidRadius3->setMaximum(static_cast(vp->getObject())->Radius3.getMaximum()); + ui->ellipsoidAngle3->setMaximum(getObject()->Angle3.getMaximum()); + ui->ellipsoidAngle3->setMinimum(getObject()->Angle3.getMinimum()); + ui->ellipsoidRadius1->setMinimum(getObject()->Radius1.getMinimum()); + ui->ellipsoidRadius1->setMaximum(getObject()->Radius1.getMaximum()); + ui->ellipsoidRadius2->setMinimum(getObject()->Radius2.getMinimum()); + ui->ellipsoidRadius2->setMaximum(getObject()->Radius2.getMaximum()); + ui->ellipsoidRadius3->setMinimum(getObject()->Radius3.getMinimum()); + ui->ellipsoidRadius3->setMaximum(getObject()->Radius3.getMaximum()); break; case PartDesign::FeaturePrimitive::Torus: index = 6; - ui->torusAngle1->setValue(static_cast(vp->getObject())->Angle1.getValue()); - ui->torusAngle1->bind(static_cast(vp->getObject())->Angle1); - ui->torusAngle2->setValue(static_cast(vp->getObject())->Angle2.getValue()); - ui->torusAngle2->bind(static_cast(vp->getObject())->Angle2); - ui->torusAngle3->setValue(static_cast(vp->getObject())->Angle3.getValue()); - ui->torusAngle3->bind(static_cast(vp->getObject())->Angle3); - ui->torusRadius1->setValue(static_cast(vp->getObject())->Radius1.getValue()); - ui->torusRadius1->bind(static_cast(vp->getObject())->Radius1); - ui->torusRadius2->setValue(static_cast(vp->getObject())->Radius2.getValue()); - ui->torusRadius2->bind(static_cast(vp->getObject())->Radius2); + ui->torusAngle1->setValue(getObject()->Angle1.getValue()); + ui->torusAngle1->bind(getObject()->Angle1); + ui->torusAngle2->setValue(getObject()->Angle2.getValue()); + ui->torusAngle2->bind(getObject()->Angle2); + ui->torusAngle3->setValue(getObject()->Angle3.getValue()); + ui->torusAngle3->bind(getObject()->Angle3); + ui->torusRadius1->setValue(getObject()->Radius1.getValue()); + ui->torusRadius1->bind(getObject()->Radius1); + ui->torusRadius2->setValue(getObject()->Radius2.getValue()); + ui->torusRadius2->bind(getObject()->Radius2); ui->torusAngle1->setMaximum(ui->torusAngle2->rawValue()); // must geometrically be <= than sphereAngle2 - ui->torusAngle1->setMinimum(static_cast(vp->getObject())->Angle1.getMinimum()); - ui->torusAngle2->setMaximum(static_cast(vp->getObject())->Angle2.getMaximum()); + ui->torusAngle1->setMinimum(getObject()->Angle1.getMinimum()); + ui->torusAngle2->setMaximum(getObject()->Angle2.getMaximum()); ui->torusAngle2->setMinimum(ui->torusAngle1->rawValue()); - ui->torusAngle3->setMaximum(static_cast(vp->getObject())->Angle3.getMaximum()); - ui->torusAngle3->setMinimum(static_cast(vp->getObject())->Angle3.getMinimum()); + ui->torusAngle3->setMaximum(getObject()->Angle3.getMaximum()); + ui->torusAngle3->setMinimum(getObject()->Angle3.getMinimum()); // this is the outer radius that must not be smaller than the inner one // otherwise the geometry is impossible and we can even get a crash: // https://forum.freecad.org/viewtopic.php?f=3&t=44467 - ui->torusRadius1->setMaximum(static_cast(vp->getObject())->Radius1.getMaximum()); + ui->torusRadius1->setMaximum(getObject()->Radius1.getMaximum()); ui->torusRadius1->setMinimum(ui->torusRadius2->rawValue()); ui->torusRadius2->setMaximum(ui->torusRadius1->rawValue()); - ui->torusRadius2->setMinimum(static_cast(vp->getObject())->Radius2.getMinimum()); + ui->torusRadius2->setMinimum(getObject()->Radius2.getMinimum()); break; case PartDesign::FeaturePrimitive::Prism: index = 7; - ui->prismPolygon->setValue(static_cast(vp->getObject())->Polygon.getValue()); - ui->prismCircumradius->setValue(static_cast(vp->getObject())->Circumradius.getValue()); - 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())->FirstAngle.getValue()); - ui->prismXSkew->bind(static_cast(vp->getObject())->FirstAngle); - ui->prismYSkew->setValue(static_cast(vp->getObject())->SecondAngle.getValue()); - ui->prismYSkew->bind(static_cast(vp->getObject())->SecondAngle); - ui->prismCircumradius->setMaximum(static_cast(vp->getObject())->Circumradius.getMaximum()); - ui->prismCircumradius->setMinimum(static_cast(vp->getObject())->Circumradius.getMinimum()); - ui->prismHeight->setMaximum(static_cast(vp->getObject())->Height.getMaximum()); - ui->prismHeight->setMinimum(static_cast(vp->getObject())->Height.getMinimum()); + ui->prismPolygon->setValue(getObject()->Polygon.getValue()); + ui->prismCircumradius->setValue(getObject()->Circumradius.getValue()); + ui->prismCircumradius->bind(getObject()->Circumradius); + ui->prismHeight->setValue(getObject()->Height.getValue()); + ui->prismHeight->bind(getObject()->Height); + ui->prismXSkew->setValue(getObject()->FirstAngle.getValue()); + ui->prismXSkew->bind(getObject()->FirstAngle); + ui->prismYSkew->setValue(getObject()->SecondAngle.getValue()); + ui->prismYSkew->bind(getObject()->SecondAngle); + ui->prismCircumradius->setMaximum(getObject()->Circumradius.getMaximum()); + ui->prismCircumradius->setMinimum(getObject()->Circumradius.getMinimum()); + ui->prismHeight->setMaximum(getObject()->Height.getMaximum()); + ui->prismHeight->setMinimum(getObject()->Height.getMinimum()); break; case PartDesign::FeaturePrimitive::Wedge: index = 8; - ui->wedgeXmax->setValue(static_cast(vp->getObject())->Xmax.getValue()); - ui->wedgeXmax->bind(static_cast(vp->getObject())->Xmax); - ui->wedgeXmin->setValue(static_cast(vp->getObject())->Xmin.getValue()); - ui->wedgeXmin->bind(static_cast(vp->getObject())->Xmin); - ui->wedgeX2max->setValue(static_cast(vp->getObject())->X2max.getValue()); - ui->wedgeX2max->bind(static_cast(vp->getObject())->X2max); - ui->wedgeX2min->setValue(static_cast(vp->getObject())->X2min.getValue()); - ui->wedgeX2min->bind(static_cast(vp->getObject())->X2min); - ui->wedgeYmax->setValue(static_cast(vp->getObject())->Ymax.getValue()); - ui->wedgeYmax->bind(static_cast(vp->getObject())->Ymax); - ui->wedgeYmin->setValue(static_cast(vp->getObject())->Ymin.getValue()); - ui->wedgeYmin->bind(static_cast(vp->getObject())->Ymin); - ui->wedgeZmax->setValue(static_cast(vp->getObject())->Zmax.getValue()); - ui->wedgeZmax->bind(static_cast(vp->getObject())->Zmax); - ui->wedgeZmin->setValue(static_cast(vp->getObject())->Zmin.getValue()); - ui->wedgeZmin->bind(static_cast(vp->getObject())->Zmin); - ui->wedgeZ2max->setValue(static_cast(vp->getObject())->Z2max.getValue()); - ui->wedgeZ2max->bind(static_cast(vp->getObject())->Z2max); - ui->wedgeZ2min->setValue(static_cast(vp->getObject())->Z2min.getValue()); - ui->wedgeZ2min->bind(static_cast(vp->getObject())->Z2min); + ui->wedgeXmax->setValue(getObject()->Xmax.getValue()); + ui->wedgeXmax->bind(getObject()->Xmax); + ui->wedgeXmin->setValue(getObject()->Xmin.getValue()); + ui->wedgeXmin->bind(getObject()->Xmin); + ui->wedgeX2max->setValue(getObject()->X2max.getValue()); + ui->wedgeX2max->bind(getObject()->X2max); + ui->wedgeX2min->setValue(getObject()->X2min.getValue()); + ui->wedgeX2min->bind(getObject()->X2min); + ui->wedgeYmax->setValue(getObject()->Ymax.getValue()); + ui->wedgeYmax->bind(getObject()->Ymax); + ui->wedgeYmin->setValue(getObject()->Ymin.getValue()); + ui->wedgeYmin->bind(getObject()->Ymin); + ui->wedgeZmax->setValue(getObject()->Zmax.getValue()); + ui->wedgeZmax->bind(getObject()->Zmax); + ui->wedgeZmin->setValue(getObject()->Zmin.getValue()); + ui->wedgeZmin->bind(getObject()->Zmin); + ui->wedgeZ2max->setValue(getObject()->Z2max.getValue()); + ui->wedgeZ2max->bind(getObject()->Z2max); + ui->wedgeZ2min->setValue(getObject()->Z2min.getValue()); + ui->wedgeZ2min->bind(getObject()->Z2min); ui->wedgeXmin->setMinimum(INT_MIN); ui->wedgeXmin->setMaximum(ui->wedgeXmax->rawValue()); // must be < than wedgeXmax ui->wedgeYmin->setMinimum(INT_MIN); @@ -256,11 +256,10 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) this->attachDocument(doc); //show the parts coordinate system axis for selection - PartDesign::Body * body = PartDesign::Body::findBodyOf(vp->getObject()); - if(body) { + if(PartDesign::Body * body = PartDesign::Body::findBodyOf(getObject())) { try { App::Origin *origin = body->getOrigin(); - Gui::ViewProviderOrigin* vpOrigin; + Gui::ViewProviderOrigin* vpOrigin {}; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->setTemporaryVisibility(true, true); } catch (const Base::Exception &ex) { @@ -376,343 +375,425 @@ TaskBoxPrimitives::~TaskBoxPrimitives() { //hide the parts coordinate system axis for selection try { - PartDesign::Body * body = vp ? PartDesign::Body::findBodyOf(vp->getObject()) : nullptr; - if (body) { + auto obj = getObject(); + if (PartDesign::Body * body = obj ? PartDesign::Body::findBodyOf(obj) : nullptr) { App::Origin *origin = body->getOrigin(); Gui::ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); } - } catch (const Base::Exception &ex) { + } + catch (const Base::Exception &ex) { Base::Console().Error ("%s\n", ex.what () ); } } void TaskBoxPrimitives::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) { - if (this->vp == &Obj) + if (this->vp == &Obj) { this->vp = nullptr; -} - -void TaskBoxPrimitives::onBoxHeightChanged(double v) { - PartDesign::Box* box = static_cast(vp->getObject()); - box->Height.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onBoxWidthChanged(double v) { - PartDesign::Box* box = static_cast(vp->getObject()); - box->Width.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onBoxLengthChanged(double v) { - PartDesign::Box* box = static_cast(vp->getObject()); - box->Length.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onCylinderAngleChanged(double v) { - PartDesign::Cylinder* cyl = static_cast(vp->getObject()); - cyl->Angle.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onCylinderHeightChanged(double v) { - PartDesign::Cylinder* cyl = static_cast(vp->getObject()); - cyl->Height.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onCylinderRadiusChanged(double v) { - PartDesign::Cylinder* cyl = static_cast(vp->getObject()); - cyl->Radius.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onCylinderXSkewChanged(double v) { - PartDesign::Cylinder* cyl = static_cast(vp->getObject()); - // we must assure that if the user incremented from e.g. 85 degree with the - // spin buttons, they do not end at 90.0 but at 89.9999 which is shown rounded to 90 degree - if ((v < 90.0) && (v > -90.0)) { - cyl->FirstAngle.setValue(v); } - else { - if (v == 90.0) - cyl->FirstAngle.setValue(cyl->FirstAngle.getMaximum()); - else if (v == -90.0) - cyl->FirstAngle.setValue(cyl->FirstAngle.getMinimum()); - ui->cylinderXSkew->setValue(cyl->FirstAngle.getQuantityValue()); +} + +void TaskBoxPrimitives::onBoxHeightChanged(double v) +{ + if (auto box = getObject()) { + box->Height.setValue(v); + box->recomputeFeature(); } - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); } -void TaskBoxPrimitives::onCylinderYSkewChanged(double v) { - PartDesign::Cylinder* cyl = static_cast(vp->getObject()); - // we must assure that if the user incremented from e.g. 85 degree with the - // spin buttons, they do not end at 90.0 but at 89.9999 which is shown rounded to 90 degree - if ((v < 90.0) && (v > -90.0)) { - cyl->SecondAngle.setValue(v); +void TaskBoxPrimitives::onBoxWidthChanged(double v) +{ + if (auto box = getObject()) { + box->Width.setValue(v); + box->recomputeFeature(); } - else { - if (v == 90.0) - cyl->SecondAngle.setValue(cyl->SecondAngle.getMaximum()); - else if (v == -90.0) - cyl->SecondAngle.setValue(cyl->SecondAngle.getMinimum()); - ui->cylinderYSkew->setValue(cyl->SecondAngle.getQuantityValue()); +} + +void TaskBoxPrimitives::onBoxLengthChanged(double v) +{ + if (auto box = getObject()) { + box->Length.setValue(v); + box->recomputeFeature(); } - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); } -void TaskBoxPrimitives::onSphereAngle1Changed(double v) { - PartDesign::Sphere* sph = static_cast(vp->getObject()); - ui->sphereAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 - sph->Angle1.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onSphereAngle2Changed(double v) { - PartDesign::Sphere* sph = static_cast(vp->getObject()); - ui->sphereAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle2 - sph->Angle2.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onSphereAngle3Changed(double v) { - PartDesign::Sphere* sph = static_cast(vp->getObject()); - sph->Angle3.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onSphereRadiusChanged(double v) { - PartDesign::Sphere* sph = static_cast(vp->getObject()); - sph->Radius.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onConeAngleChanged(double v) { - - PartDesign::Cone* sph = static_cast(vp->getObject()); - sph->Angle.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onConeHeightChanged(double v) { - PartDesign::Cone* sph = static_cast(vp->getObject()); - sph->Height.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onConeRadius1Changed(double v) { - - PartDesign::Cone* sph = static_cast(vp->getObject()); - sph->Radius1.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onConeRadius2Changed(double v) { - - PartDesign::Cone* sph = static_cast(vp->getObject()); - sph->Radius2.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onEllipsoidAngle1Changed(double v) { - PartDesign::Ellipsoid* sph = static_cast(vp->getObject()); - ui->ellipsoidAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 - sph->Angle1.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onEllipsoidAngle2Changed(double v) { - PartDesign::Ellipsoid* sph = static_cast(vp->getObject()); - ui->ellipsoidAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle22 - sph->Angle2.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onEllipsoidAngle3Changed(double v) { - PartDesign::Ellipsoid* sph = static_cast(vp->getObject()); - sph->Angle3.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onEllipsoidRadius1Changed(double v) { - PartDesign::Ellipsoid* sph = static_cast(vp->getObject()); - sph->Radius1.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onEllipsoidRadius2Changed(double v) { - PartDesign::Ellipsoid* sph = static_cast(vp->getObject()); - sph->Radius2.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onEllipsoidRadius3Changed(double v) { - PartDesign::Ellipsoid* sph = static_cast(vp->getObject()); - sph->Radius3.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onTorusAngle1Changed(double v) { - PartDesign::Torus* sph = static_cast(vp->getObject()); - ui->torusAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 - sph->Angle1.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onTorusAngle2Changed(double v) { - PartDesign::Torus* sph = static_cast(vp->getObject()); - ui->torusAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle2 - sph->Angle2.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onTorusAngle3Changed(double v) { - PartDesign::Torus* sph = static_cast(vp->getObject()); - sph->Angle3.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onTorusRadius1Changed(double v) { - PartDesign::Torus* sph = static_cast(vp->getObject()); - // this is the outer radius that must not be smaller than the inner one - // otherwise the geometry is impossible and we can even get a crash: - // https://forum.freecad.org/viewtopic.php?f=3&t=44467 - ui->torusRadius2->setMaximum(v); - sph->Radius1.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onTorusRadius2Changed(double v) { - PartDesign::Torus* sph = static_cast(vp->getObject()); - ui->torusRadius1->setMinimum(v); - sph->Radius2.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onPrismCircumradiusChanged(double v) { - PartDesign::Prism* sph = static_cast(vp->getObject()); - sph->Circumradius.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); -} - -void TaskBoxPrimitives::onPrismHeightChanged(double v) { - PartDesign::Prism* sph = static_cast(vp->getObject()); - sph->Height.setValue(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, they do not end at 90.0 but at 89.9999 which is shown rounded to 90 degree - if ((v < 90.0) && (v > -90.0)) { - sph->FirstAngle.setValue(v); +void TaskBoxPrimitives::onCylinderAngleChanged(double v) +{ + if (auto cyl = getObject()) { + cyl->Angle.setValue(v); + cyl->recomputeFeature(); } - else { - if (v == 90.0) - sph->FirstAngle.setValue(89.99999); - else if (v == -90.0) - sph->FirstAngle.setValue(-89.99999); - ui->prismXSkew->setValue(sph->FirstAngle.getQuantityValue()); +} + +void TaskBoxPrimitives::onCylinderHeightChanged(double v) +{ + if (auto cyl = getObject()) { + cyl->Height.setValue(v); + cyl->recomputeFeature(); } - 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, they do not end at 90.0 but at 89.9999 which is shown rounded to 90 degree - if ((v < 90.0) && (v > -90.0)) { - sph->SecondAngle.setValue(v); +void TaskBoxPrimitives::onCylinderRadiusChanged(double v) +{ + if (auto cyl = getObject()) { + cyl->Radius.setValue(v); + cyl->recomputeFeature(); } - else { - if (v == 90.0) - sph->SecondAngle.setValue(89.99999); - else if (v == -90.0) - sph->SecondAngle.setValue(-89.99999); - ui->prismYSkew->setValue(sph->SecondAngle.getQuantityValue()); +} + +void TaskBoxPrimitives::onCylinderXSkewChanged(double v) +{ + if (auto cyl = getObject()) { + // we must assure that if the user incremented from e.g. 85 degree with the + // spin buttons, they do not end at 90.0 but at 89.9999 which is shown rounded to 90 degree + if ((v < 90.0) && (v > -90.0)) { + cyl->FirstAngle.setValue(v); + } + else { + if (v == 90.0) + cyl->FirstAngle.setValue(cyl->FirstAngle.getMaximum()); + else if (v == -90.0) + cyl->FirstAngle.setValue(cyl->FirstAngle.getMinimum()); + ui->cylinderXSkew->setValue(cyl->FirstAngle.getQuantityValue()); + } + cyl->recomputeFeature(); } - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); } -void TaskBoxPrimitives::onPrismPolygonChanged(int v) { - PartDesign::Prism* sph = static_cast(vp->getObject()); - sph->Polygon.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onCylinderYSkewChanged(double v) +{ + if (auto cyl = getObject()) { + // we must assure that if the user incremented from e.g. 85 degree with the + // spin buttons, they do not end at 90.0 but at 89.9999 which is shown rounded to 90 degree + if ((v < 90.0) && (v > -90.0)) { + cyl->SecondAngle.setValue(v); + } + else { + if (v == 90.0) + cyl->SecondAngle.setValue(cyl->SecondAngle.getMaximum()); + else if (v == -90.0) + cyl->SecondAngle.setValue(cyl->SecondAngle.getMinimum()); + ui->cylinderYSkew->setValue(cyl->SecondAngle.getQuantityValue()); + } + cyl->recomputeFeature(); + } } - -void TaskBoxPrimitives::onWedgeX2minChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeX2max->setMinimum(v); // wedgeX2min must be <= than wedgeX2max - sph->X2min.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onSphereAngle1Changed(double v) +{ + if (auto sph = getObject()) { + ui->sphereAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 + sph->Angle1.setValue(v); + sph->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeX2maxChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeX2min->setMaximum(v); // wedgeX2min must be <= than wedgeX2max - sph->X2max.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onSphereAngle2Changed(double v) +{ + if (auto sph = getObject()) { + ui->sphereAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle2 + sph->Angle2.setValue(v); + sph->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeXminChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeXmax->setMinimum(v); - sph->Xmin.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onSphereAngle3Changed(double v) +{ + if (auto sph = getObject()) { + sph->Angle3.setValue(v); + sph->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeXmaxChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeXmin->setMaximum(v); // must be < than wedgeXmax - sph->Xmax.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onSphereRadiusChanged(double v) +{ + if (auto sph = getObject()) { + sph->Radius.setValue(v); + sph->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeYminChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeYmax->setMinimum(v); // must be > than wedgeYmin - sph->Ymin.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onConeAngleChanged(double v) +{ + if (auto cone = getObject()) { + cone->Angle.setValue(v); + cone->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeYmaxChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeYmin->setMaximum(v); // must be < than wedgeYmax - sph->Ymax.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onConeHeightChanged(double v) +{ + if (auto cone = getObject()) { + cone->Height.setValue(v); + cone->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeZ2minChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeZ2max->setMinimum(v); // must be >= than wedgeZ2min - sph->Z2min.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onConeRadius1Changed(double v) +{ + if (auto cone = getObject()) { + cone->Radius1.setValue(v); + cone->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeZ2maxChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeZ2min->setMaximum(v); // must be <= than wedgeZ2max - sph->Z2max.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onConeRadius2Changed(double v) +{ + if (auto cone = getObject()) { + cone->Radius2.setValue(v); + cone->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeZminChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeZmax->setMinimum(v); // must be > than wedgeZmin - sph->Zmin.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onEllipsoidAngle1Changed(double v) +{ + if (auto ell = getObject()) { + ui->ellipsoidAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 + ell->Angle1.setValue(v); + ell->recomputeFeature(); + } } -void TaskBoxPrimitives::onWedgeZmaxChanged(double v) { - PartDesign::Wedge* sph = static_cast(vp->getObject()); - ui->wedgeZmin->setMaximum(v); // must be < than wedgeZmax - sph->Zmax.setValue(v); - vp->getObject()->getDocument()->recomputeFeature(vp->getObject()); +void TaskBoxPrimitives::onEllipsoidAngle2Changed(double v) +{ + if (auto ell = getObject()) { + ui->ellipsoidAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle22 + ell->Angle2.setValue(v); + ell->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onEllipsoidAngle3Changed(double v) +{ + if (auto ell = getObject()) { + ell->Angle3.setValue(v); + ell->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onEllipsoidRadius1Changed(double v) +{ + if (auto ell = getObject()) { + ell->Radius1.setValue(v); + ell->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onEllipsoidRadius2Changed(double v) +{ + if (auto ell = getObject()) { + ell->Radius2.setValue(v); + ell->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onEllipsoidRadius3Changed(double v) +{ + if (auto ell = getObject()) { + ell->Radius3.setValue(v); + ell->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onTorusAngle1Changed(double v) +{ + if (auto tor = getObject()) { + ui->torusAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 + tor->Angle1.setValue(v); + tor->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onTorusAngle2Changed(double v) +{ + if (auto tor = getObject()) { + ui->torusAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle2 + tor->Angle2.setValue(v); + tor->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onTorusAngle3Changed(double v) +{ + if (auto tor = getObject()) { + tor->Angle3.setValue(v); + tor->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onTorusRadius1Changed(double v) +{ + if (auto tor = getObject()) { + // this is the outer radius that must not be smaller than the inner one + // otherwise the geometry is impossible and we can even get a crash: + // https://forum.freecad.org/viewtopic.php?f=3&t=44467 + ui->torusRadius2->setMaximum(v); + tor->Radius1.setValue(v); + tor->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onTorusRadius2Changed(double v) +{ + if (auto tor = getObject()) { + ui->torusRadius1->setMinimum(v); + tor->Radius2.setValue(v); + tor->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onPrismCircumradiusChanged(double v) +{ + if (auto prim = getObject()) { + prim->Circumradius.setValue(v); + prim->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onPrismHeightChanged(double v) +{ + if (auto prim = getObject()) { + prim->Height.setValue(v); + prim->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onPrismXSkewChanged(double v) +{ + if (auto prim = getObject()) { + // we must assure that if the user incremented from e.g. 85 degree with the + // spin buttons, they do not end at 90.0 but at 89.9999 which is shown rounded to 90 degree + if ((v < 90.0) && (v > -90.0)) { + prim->FirstAngle.setValue(v); + } + else { + if (v == 90.0) + prim->FirstAngle.setValue(89.99999); + else if (v == -90.0) + prim->FirstAngle.setValue(-89.99999); + ui->prismXSkew->setValue(prim->FirstAngle.getQuantityValue()); + } + prim->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onPrismYSkewChanged(double v) +{ + if (auto prim = getObject()) { + // we must assure that if the user incremented from e.g. 85 degree with the + // spin buttons, they do not end at 90.0 but at 89.9999 which is shown rounded to 90 degree + if ((v < 90.0) && (v > -90.0)) { + prim->SecondAngle.setValue(v); + } + else { + if (v == 90.0) + prim->SecondAngle.setValue(89.99999); + else if (v == -90.0) + prim->SecondAngle.setValue(-89.99999); + ui->prismYSkew->setValue(prim->SecondAngle.getQuantityValue()); + } + prim->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onPrismPolygonChanged(int v) +{ + if (auto prim = getObject()) { + prim->Polygon.setValue(v); + prim->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeX2minChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeX2max->setMinimum(v); // wedgeX2min must be <= than wedgeX2max + wedge->X2min.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeX2maxChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeX2min->setMaximum(v); // wedgeX2min must be <= than wedgeX2max + wedge->X2max.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeXminChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeXmax->setMinimum(v); + wedge->Xmin.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeXmaxChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeXmin->setMaximum(v); // must be < than wedgeXmax + wedge->Xmax.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeYminChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeYmax->setMinimum(v); // must be > than wedgeYmin + wedge->Ymin.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeYmaxChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeYmin->setMaximum(v); // must be < than wedgeYmax + wedge->Ymax.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeZ2minChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeZ2max->setMinimum(v); // must be >= than wedgeZ2min + wedge->Z2min.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeZ2maxChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeZ2min->setMaximum(v); // must be <= than wedgeZ2max + wedge->Z2max.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeZminChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeZmax->setMinimum(v); // must be > than wedgeZmin + wedge->Zmin.setValue(v); + wedge->recomputeFeature(); + } +} + +void TaskBoxPrimitives::onWedgeZmaxChanged(double v) +{ + if (auto wedge = getObject()) { + ui->wedgeZmin->setMaximum(v); // must be < than wedgeZmax + wedge->Zmax.setValue(v); + wedge->recomputeFeature(); + } } @@ -884,48 +965,10 @@ bool TaskBoxPrimitives::setPrimitive(App::DocumentObject *obj) TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* PrimitiveView) : vp_prm(PrimitiveView) { - assert(PrimitiveView); primitive = new TaskBoxPrimitives(PrimitiveView); Content.push_back(primitive); - - /* - // handle visibility automation differently to the default method - auto customvisfunc = [] (bool opening_not_closing, - const std::string &postfix, - Gui::ViewProviderDocumentObject* vp, - App::DocumentObject *editObj, - const std::string& editSubName) { - if (opening_not_closing) { - QString code = QString::fromLatin1( - "import Show\n" - "_tv_%4 = Show.TempoVis(App.ActiveDocument, tag= 'PartGui::TaskAttacher')\n" - "tvObj = %1\n" - "dep_features = _tv_%4.get_all_dependent(%2, '%3')\n" - "if tvObj.isDerivedFrom('PartDesign::CoordinateSystem'):\n" - "\tvisible_features = [feat for feat in tvObj.InList if feat.isDerivedFrom('PartDesign::FeaturePrimitive')]\n" - "\tdep_features = [feat for feat in dep_features if feat not in visible_features]\n" - "\tdel(visible_features)\n" - "_tv_%4.hide(dep_features)\n" - "del(dep_features)\n" - "del(tvObj)" - ).arg( - QString::fromLatin1(Gui::Command::getObjectCmd(vp->getObject()).c_str()), - QString::fromLatin1(Gui::Command::getObjectCmd(editObj).c_str()), - QString::fromLatin1(editSubName.c_str()), - QString::fromLatin1(postfix.c_str())); - Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData()); - } else if(postfix.size()) { - QString code = QString::fromLatin1( - "_tv_%1.restore()\n" - "del(_tv_%1)" - ).arg(QString::fromLatin1(postfix.c_str())); - Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData()); - } - }; - parameter = new PartGui::TaskAttacher(PrimitiveView, nullptr, QString(), tr("Attachment"), customvisfunc); - */ parameter = new PartGui::TaskAttacher(PrimitiveView, nullptr, QString(), tr("Attachment")); Content.push_back(parameter); } @@ -952,7 +995,8 @@ bool TaskPrimitiveParameters::reject() return true; } -QDialogButtonBox::StandardButtons TaskPrimitiveParameters::getStandardButtons() const { +QDialogButtonBox::StandardButtons TaskPrimitiveParameters::getStandardButtons() const +{ return Gui::TaskView::TaskDialog::getStandardButtons(); } diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h index a57f8ab2da..821e40860d 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h @@ -101,6 +101,16 @@ private: /** Notifies when the object is about to be removed. */ void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) override; + template T* getObject() const + { + static_assert(std::is_base_of::value, "Wrong template argument"); + if (vp) { + return dynamic_cast(vp->getObject()); + } + + return nullptr; + } + private: QWidget* proxy; std::unique_ptr ui;