From 84e382a5a651d5c6a0e49966d424786bcbd8a853 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 16 Nov 2021 00:58:55 +0100 Subject: [PATCH] PD: simplify Pad/Pocket commands --- src/Mod/PartDesign/Gui/Command.cpp | 85 +++++++++++------------------- 1 file changed, 32 insertions(+), 53 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 2736de484f..144e9a0494 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -1220,6 +1220,36 @@ void finishProfileBased(const Gui::Command* cmd, const Part::Feature* sketch, Ap finishFeature(cmd, Feat); } +void prepareProfileBased(Gui::Command* cmd, const std::string& which, double length) +{ + PartDesign::Body *pcActiveBody = PartDesignGui::getBody(true); + + if (!pcActiveBody) + return; + + auto worker = [cmd, length](Part::Feature* profile, App::DocumentObject *Feat) { + + if (!Feat) + return; + + // specific parameters for Pad/Pocket + FCMD_OBJ_CMD(Feat, "Length = " << length); + Gui::Command::updateActive(); + + Part::Part2DObject* sketch = dynamic_cast(profile); + + if (sketch) { + std::ostringstream str; + Gui::cmdAppObject(Feat, str << "ReferenceAxis = (" << Gui::Command::getObjectCmd(sketch) << ",['N_Axis'])"); + } + + finishProfileBased(cmd, sketch, Feat); + cmd->adjustCameraPosition(); + }; + + prepareProfileBased(pcActiveBody, cmd, which, worker); +} + //=========================================================================== // PartDesign_Pad //=========================================================================== @@ -1244,33 +1274,7 @@ void CmdPartDesignPad::activated(int iMsg) if (!PartDesignGui::assureModernWorkflow(doc)) return; - PartDesign::Body *pcActiveBody = PartDesignGui::getBody(true); - - if (!pcActiveBody) - return; - - Gui::Command* cmd = this; - auto worker = [cmd](Part::Feature* profile, App::DocumentObject *Feat) { - - if (!Feat) - return; - - // specific parameters for Pad - FCMD_OBJ_CMD(Feat, "Length = 10.0"); - Gui::Command::updateActive(); - - Part::Part2DObject* sketch = dynamic_cast(profile); - - if (sketch) { - std::ostringstream str; - Gui::cmdAppObject(Feat, str << "ReferenceAxis = (" << getObjectCmd(sketch) << ",['N_Axis'])"); - } - - finishProfileBased(cmd, sketch, Feat); - cmd->adjustCameraPosition(); - }; - - prepareProfileBased(pcActiveBody, this, "Pad", worker); + prepareProfileBased(this, "Pad", 10.0); } bool CmdPartDesignPad::isActive(void) @@ -1302,32 +1306,7 @@ void CmdPartDesignPocket::activated(int iMsg) if (!PartDesignGui::assureModernWorkflow(doc)) return; - PartDesign::Body *pcActiveBody = PartDesignGui::getBody(true); - - if (!pcActiveBody) - return; - - Gui::Command* cmd = this; - auto worker = [cmd](Part::Feature* profile, App::DocumentObject *Feat) { - - if (!Feat) - return; - - FCMD_OBJ_CMD(Feat, "Length = 10.0"); - Gui::Command::updateActive(); - - Part::Part2DObject* sketch = dynamic_cast(profile); - - if (sketch) { - std::ostringstream str; - Gui::cmdAppObject(Feat, str << "ReferenceAxis = (" << getObjectCmd(sketch) << ",['N_Axis'])"); - } - - finishProfileBased(cmd, sketch, Feat); - cmd->adjustCameraPosition(); - }; - - prepareProfileBased(pcActiveBody, this, "Pocket", worker); + prepareProfileBased(this, "Pocket", 5.0); } bool CmdPartDesignPocket::isActive(void)