From c4c030451847dd8816c814c7f2a4f482a57a38bc Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 7 Apr 2022 13:22:13 +0200 Subject: [PATCH] Fem: move handling of PostAutoRecompute to a central class and by default set its value to true --- src/Mod/Fem/Gui/CMakeLists.txt | 2 + src/Mod/Fem/Gui/Command.cpp | 11 ++--- src/Mod/Fem/Gui/FemSettings.cpp | 44 +++++++++++++++++++ src/Mod/Fem/Gui/FemSettings.h | 44 +++++++++++++++++++ src/Mod/Fem/Gui/TaskPostBoxes.cpp | 4 +- .../Fem/Gui/ViewProviderFemPostFunction.cpp | 4 +- 6 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 src/Mod/Fem/Gui/FemSettings.cpp create mode 100644 src/Mod/Fem/Gui/FemSettings.h diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 57bb497714..219ae4ebb1 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -313,6 +313,8 @@ SET(FemGui_SRCS_Module ActiveAnalysisObserver.cpp ActiveAnalysisObserver.h Command.cpp + FemSettings.cpp + FemSettings.h Resources/Fem.qrc PreCompiled.cpp PreCompiled.h diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index da53fdc29d..afc4c80d8c 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -53,6 +53,7 @@ #include #include "ActiveAnalysisObserver.h" +#include "FemSettings.h" #ifdef FC_USE_VTK #include @@ -1744,12 +1745,7 @@ CmdFemPostApllyChanges::CmdFemPostApllyChanges() void CmdFemPostApllyChanges::activated(int iMsg) { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Fem"); - - if (iMsg == 1) - hGrp->SetBool("PostAutoRecompute", true); - else - hGrp->SetBool("PostAutoRecompute", false); + FemGui::FemSettings().setPostAutoRecompute(iMsg == 1); } bool CmdFemPostApllyChanges::isActive(void) @@ -1764,8 +1760,7 @@ Gui::Action* CmdFemPostApllyChanges::createAction(void) { Gui::Action* pcAction = Command::createAction(); pcAction->setCheckable(true); - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Fem"); - pcAction->setChecked(hGrp->GetBool("PostAutoRecompute", false)); + pcAction->setChecked(FemGui::FemSettings().getPostAutoRecompute()); return pcAction; } diff --git a/src/Mod/Fem/Gui/FemSettings.cpp b/src/Mod/Fem/Gui/FemSettings.cpp new file mode 100644 index 0000000000..64e6dff4c3 --- /dev/null +++ b/src/Mod/Fem/Gui/FemSettings.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#include "FemSettings.h" +#include + +using namespace FemGui; + + +FemSettings::FemSettings() +{ + pGroup = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Fem"); +} + +void FemSettings::setPostAutoRecompute(bool on) +{ + pGroup->SetBool("PostAutoRecompute", on); +} + +bool FemSettings::getPostAutoRecompute() const +{ + return pGroup->GetBool("PostAutoRecompute", true); +} diff --git a/src/Mod/Fem/Gui/FemSettings.h b/src/Mod/Fem/Gui/FemSettings.h new file mode 100644 index 0000000000..03da65edb0 --- /dev/null +++ b/src/Mod/Fem/Gui/FemSettings.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef FEMGUI_SETTINGS_H +#define FEMGUI_SETTINGS_H + +#include + +namespace FemGui { + +class FemSettings +{ +public: + FemSettings(); + void setPostAutoRecompute(bool); + bool getPostAutoRecompute() const; + +private: + ParameterGrp::handle pGroup; +}; + +} //namespace FemGui + +#endif // FEMGUI_SETTINGS_H diff --git a/src/Mod/Fem/Gui/TaskPostBoxes.cpp b/src/Mod/Fem/Gui/TaskPostBoxes.cpp index 5003cf4dfb..8559a45853 100644 --- a/src/Mod/Fem/Gui/TaskPostBoxes.cpp +++ b/src/Mod/Fem/Gui/TaskPostBoxes.cpp @@ -55,6 +55,7 @@ #include "ui_TaskPostScalarClip.h" #include "ui_TaskPostWarpVector.h" +#include "FemSettings.h" #include "TaskPostBoxes.h" #include "ViewProviderFemPostFilter.h" #include "ViewProviderFemPostFunction.h" @@ -300,8 +301,7 @@ TaskPostBox::~TaskPostBox() { bool TaskPostBox::autoApply() { - ParameterGrp::handle pGroup = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Fem"); - return pGroup->GetBool("PostAutoRecompute", false); + return FemSettings().getPostAutoRecompute(); } void TaskPostBox::recompute() { diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp index 442a8447b5..a43338a786 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp @@ -55,6 +55,7 @@ #include "ViewProviderFemPostFunction.h" #include "ActiveAnalysisObserver.h" +#include "FemSettings.h" #include "TaskPostBoxes.h" #include "ui_PlaneWidget.h" @@ -268,8 +269,7 @@ void ViewProviderFemPostFunction::dragStartCallback(void* data, SoDragger*) reinterpret_cast(data)->m_isDragging = true; ViewProviderFemPostFunction* that = reinterpret_cast(data); - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Fem"); - that->m_autoRecompute = hGrp->GetBool("PostAutoRecompute", false); + that->m_autoRecompute = FemSettings().getPostAutoRecompute(); } void ViewProviderFemPostFunction::dragFinishCallback(void* data, SoDragger*)