From 97103b3bf3cf76aadd12e9188569423f4d16542c Mon Sep 17 00:00:00 2001 From: Uwe Date: Wed, 22 Mar 2023 19:13:24 +0100 Subject: [PATCH] [FEM] use std::unique_ptr for all dialog objects - also fix too long line - also further clang automatic code style changes --- .../Fem/Gui/DlgSettingsFemExportAbaqusImp.cpp | 10 +- .../Fem/Gui/DlgSettingsFemExportAbaqusImp.h | 6 +- src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.cpp | 8 +- src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.h | 6 +- src/Mod/Fem/Gui/TaskAnalysisInfo.cpp | 13 +- src/Mod/Fem/Gui/TaskAnalysisInfo.h | 2 +- src/Mod/Fem/Gui/TaskCreateNodeSet.cpp | 39 +- src/Mod/Fem/Gui/TaskCreateNodeSet.h | 2 +- src/Mod/Fem/Gui/TaskDriver.cpp | 13 +- src/Mod/Fem/Gui/TaskDriver.h | 2 +- src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp | 83 ++-- src/Mod/Fem/Gui/TaskFemConstraintBearing.h | 10 +- src/Mod/Fem/Gui/TaskFemConstraintContact.cpp | 247 +++++++---- src/Mod/Fem/Gui/TaskFemConstraintContact.h | 7 +- .../Fem/Gui/TaskFemConstraintDisplacement.cpp | 8 +- .../Fem/Gui/TaskFemConstraintDisplacement.h | 10 +- src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp | 97 +++-- src/Mod/Fem/Gui/TaskFemConstraintFixed.h | 7 +- .../Gui/TaskFemConstraintFluidBoundary.cpp | 398 ++++++++++++------ .../Fem/Gui/TaskFemConstraintFluidBoundary.h | 10 +- src/Mod/Fem/Gui/TaskFemConstraintForce.cpp | 140 +++--- src/Mod/Fem/Gui/TaskFemConstraintForce.h | 10 +- src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp | 169 +++++--- src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h | 6 +- .../TaskFemConstraintInitialTemperature.cpp | 46 +- .../Gui/TaskFemConstraintInitialTemperature.h | 12 +- .../Gui/TaskFemConstraintPlaneRotation.cpp | 129 ++++-- .../Fem/Gui/TaskFemConstraintPlaneRotation.h | 10 +- src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp | 117 +++-- src/Mod/Fem/Gui/TaskFemConstraintPressure.h | 7 +- src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp | 123 ++++-- src/Mod/Fem/Gui/TaskFemConstraintSpring.h | 7 +- .../Fem/Gui/TaskFemConstraintTemperature.cpp | 120 ++++-- .../Fem/Gui/TaskFemConstraintTemperature.h | 4 +- .../Fem/Gui/TaskFemConstraintTransform.cpp | 231 ++++++---- src/Mod/Fem/Gui/TaskFemConstraintTransform.h | 6 +- src/Mod/Fem/Gui/TaskObjectName.cpp | 11 +- src/Mod/Fem/Gui/TaskObjectName.h | 2 +- src/Mod/Fem/Gui/TaskTetParameter.cpp | 15 +- src/Mod/Fem/Gui/TaskTetParameter.h | 2 +- .../Fem/Gui/ViewProviderFemPostFunction.cpp | 140 +++--- src/Mod/Fem/Gui/ViewProviderFemPostFunction.h | 9 +- 42 files changed, 1463 insertions(+), 831 deletions(-) diff --git a/src/Mod/Fem/Gui/DlgSettingsFemExportAbaqusImp.cpp b/src/Mod/Fem/Gui/DlgSettingsFemExportAbaqusImp.cpp index 2b9fbd8aa3..68c7b7fd3b 100644 --- a/src/Mod/Fem/Gui/DlgSettingsFemExportAbaqusImp.cpp +++ b/src/Mod/Fem/Gui/DlgSettingsFemExportAbaqusImp.cpp @@ -32,8 +32,9 @@ using namespace FemGui; -DlgSettingsFemExportAbaqusImp::DlgSettingsFemExportAbaqusImp( QWidget* parent ) - : PreferencePage( parent ), ui(new Ui_DlgSettingsFemExportAbaqus) +DlgSettingsFemExportAbaqusImp::DlgSettingsFemExportAbaqusImp(QWidget* parent) + : PreferencePage(parent), + ui(new Ui_DlgSettingsFemExportAbaqus) { ui->setupUi(this); } @@ -42,10 +43,7 @@ DlgSettingsFemExportAbaqusImp::DlgSettingsFemExportAbaqusImp( QWidget* parent ) * Destroys the object and frees any allocated resources */ DlgSettingsFemExportAbaqusImp::~DlgSettingsFemExportAbaqusImp() -{ - // no need to delete child widgets, Qt does it all for us - delete ui; -} +{} void DlgSettingsFemExportAbaqusImp::saveSettings() { diff --git a/src/Mod/Fem/Gui/DlgSettingsFemExportAbaqusImp.h b/src/Mod/Fem/Gui/DlgSettingsFemExportAbaqusImp.h index 1a86e4a2e6..60330bd774 100644 --- a/src/Mod/Fem/Gui/DlgSettingsFemExportAbaqusImp.h +++ b/src/Mod/Fem/Gui/DlgSettingsFemExportAbaqusImp.h @@ -22,12 +22,14 @@ * * ***************************************************************************/ - #ifndef FEMGUI_DLGSETTINGSFEMEXPORTABAQUSIMP_H #define FEMGUI_DLGSETTINGSFEMEXPORTABAQUSIMP_H +#include + #include + namespace FemGui { class Ui_DlgSettingsFemExportAbaqus; @@ -45,7 +47,7 @@ protected: void changeEvent(QEvent *e) override; private: - Ui_DlgSettingsFemExportAbaqus* ui; + std::unique_ptr ui; }; } // namespace FemGui diff --git a/src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.cpp b/src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.cpp index 83638ec86f..12032912cf 100644 --- a/src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.cpp +++ b/src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.cpp @@ -33,7 +33,8 @@ using namespace FemGui; DlgSettingsFemInOutVtkImp::DlgSettingsFemInOutVtkImp(QWidget* parent) - : PreferencePage(parent), ui(new Ui_DlgSettingsFemInOutVtk) + : PreferencePage(parent), + ui(new Ui_DlgSettingsFemInOutVtk) { ui->setupUi(this); } @@ -42,10 +43,7 @@ DlgSettingsFemInOutVtkImp::DlgSettingsFemInOutVtkImp(QWidget* parent) * Destroys the object and frees any allocated resources */ DlgSettingsFemInOutVtkImp::~DlgSettingsFemInOutVtkImp() -{ - // no need to delete child widgets, Qt does it all for us - delete ui; -} +{} void DlgSettingsFemInOutVtkImp::saveSettings() { diff --git a/src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.h b/src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.h index b9188e79f8..897cd9837a 100644 --- a/src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.h +++ b/src/Mod/Fem/Gui/DlgSettingsFemInOutVtkImp.h @@ -22,12 +22,14 @@ * * ***************************************************************************/ - #ifndef FEMGUI_DLGSETTINGSFEMINOUTVTKIMP_H #define FEMGUI_DLGSETTINGSFEMINOUTVTKIMP_H +#include + #include + namespace FemGui { class Ui_DlgSettingsFemInOutVtk; @@ -45,7 +47,7 @@ protected: void changeEvent(QEvent *e) override; private: - Ui_DlgSettingsFemInOutVtk* ui; + std::unique_ptr ui; }; } // namespace FemGui diff --git a/src/Mod/Fem/Gui/TaskAnalysisInfo.cpp b/src/Mod/Fem/Gui/TaskAnalysisInfo.cpp index dac7bef457..5f6aaa0e5a 100644 --- a/src/Mod/Fem/Gui/TaskAnalysisInfo.cpp +++ b/src/Mod/Fem/Gui/TaskAnalysisInfo.cpp @@ -32,15 +32,12 @@ using namespace FemGui; using namespace Gui; TaskAnalysisInfo::TaskAnalysisInfo(Fem::FemAnalysis* pcObject, QWidget* parent) - : TaskBox(Gui::BitmapFactory().pixmap("FEM_Analysis"), - tr("Nodes set"), - true, - parent), - pcObject(pcObject) + : TaskBox(Gui::BitmapFactory().pixmap("FEM_Analysis"), tr("Nodes set"), true, parent), + pcObject(pcObject), + ui(new Ui_TaskAnalysisInfo) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskAnalysisInfo(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -48,8 +45,6 @@ TaskAnalysisInfo::TaskAnalysisInfo(Fem::FemAnalysis* pcObject, QWidget* parent) } TaskAnalysisInfo::~TaskAnalysisInfo() -{ - delete ui; -} +{} #include "moc_TaskAnalysisInfo.cpp" diff --git a/src/Mod/Fem/Gui/TaskAnalysisInfo.h b/src/Mod/Fem/Gui/TaskAnalysisInfo.h index 5ef4fde3fe..c127315c7c 100644 --- a/src/Mod/Fem/Gui/TaskAnalysisInfo.h +++ b/src/Mod/Fem/Gui/TaskAnalysisInfo.h @@ -63,7 +63,7 @@ protected: private: QWidget* proxy; - Ui_TaskAnalysisInfo* ui; + std::unique_ptr ui; }; } //namespace FEMGUI_TaskAnalysisInfo_H diff --git a/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp b/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp index 411406a27a..4e69796b26 100644 --- a/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp +++ b/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp @@ -54,16 +54,13 @@ using namespace Gui; TaskCreateNodeSet::TaskCreateNodeSet(Fem::FemSetNodesObject* pcObject, QWidget* parent) - : TaskBox(Gui::BitmapFactory().pixmap("FEM_CreateNodesSet"), - tr("Nodes set"), - true, - parent), - pcObject(pcObject), - selectionMode(none) + : TaskBox(Gui::BitmapFactory().pixmap("FEM_CreateNodesSet"), tr("Nodes set"), true, parent), + pcObject(pcObject), + selectionMode(none), + ui(new Ui_TaskCreateNodeSet) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskCreateNodeSet(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -71,11 +68,16 @@ TaskCreateNodeSet::TaskCreateNodeSet(Fem::FemSetNodesObject* pcObject, QWidget* QObject::connect(ui->toolButton_Poly, &QToolButton::clicked, this, &TaskCreateNodeSet::Poly); QObject::connect(ui->toolButton_Pick, &QToolButton::clicked, this, &TaskCreateNodeSet::Pick); - QObject::connect(ui->comboBox, qOverload(&QComboBox::activated), this, &TaskCreateNodeSet::SwitchMethod); + QObject::connect(ui->comboBox, + qOverload(&QComboBox::activated), + this, + &TaskCreateNodeSet::SwitchMethod); // check if the Link to the FemMesh is defined assert(pcObject->FemMesh.getValue()); - MeshViewProvider = dynamic_cast(Gui::Application::Instance->getViewProvider(pcObject->FemMesh.getValue())); + MeshViewProvider = + dynamic_cast(Gui::Application::Instance->getViewProvider( + pcObject->FemMesh.getValue())); assert(MeshViewProvider); tempSet = pcObject->Nodes.getValues(); @@ -152,9 +154,13 @@ void TaskCreateNodeSet::DefineNodesCallback(void* ud, SoEventCallback* n) taskBox->DefineNodes(polygon, proj, role == Gui::SelectionRole::Inner ? true : false); } -void TaskCreateNodeSet::DefineNodes(const Base::Polygon2d& polygon, const Gui::ViewVolumeProjection& proj, bool inner) +void TaskCreateNodeSet::DefineNodes(const Base::Polygon2d& polygon, + const Gui::ViewVolumeProjection& proj, bool inner) { - const SMESHDS_Mesh* data = pcObject->FemMesh.getValue()->FemMesh.getValue().getSMesh()->GetMeshDS(); + const SMESHDS_Mesh* data = pcObject->FemMesh.getValue() + ->FemMesh.getValue() + .getSMesh() + ->GetMeshDS(); SMDS_NodeIteratorPtr aNodeIter = data->nodesIterator(); Base::Vector3f pt2d; @@ -192,16 +198,19 @@ void TaskCreateNodeSet::onSelectionChanged(const Gui::SelectionChanges& msg) tempSet.clear(); - Base::Console().Message("Picked Element:%i Face:%i\n", elem, face); if (!ui->checkBox_Add->isChecked()) { - std::set tmp = pcObject->FemMesh.getValue()->FemMesh.getValue().getSurfaceNodes(elem, face); + std::set tmp = pcObject->FemMesh.getValue() + ->FemMesh.getValue() + .getSurfaceNodes(elem, face); tempSet.insert(tmp.begin(), tmp.end()); } else { - tempSet = pcObject->FemMesh.getValue()->FemMesh.getValue().getSurfaceNodes(elem, face); + tempSet = pcObject->FemMesh.getValue() + ->FemMesh.getValue() + .getSurfaceNodes(elem, face); } selectionMode = none; @@ -211,10 +220,8 @@ void TaskCreateNodeSet::onSelectionChanged(const Gui::SelectionChanges& msg) } } - TaskCreateNodeSet::~TaskCreateNodeSet() { - delete ui; Gui::Selection().rmvSelectionGate(); } diff --git a/src/Mod/Fem/Gui/TaskCreateNodeSet.h b/src/Mod/Fem/Gui/TaskCreateNodeSet.h index 79316d668d..16c24f3e95 100644 --- a/src/Mod/Fem/Gui/TaskCreateNodeSet.h +++ b/src/Mod/Fem/Gui/TaskCreateNodeSet.h @@ -74,7 +74,7 @@ protected: private: QWidget* proxy; - Ui_TaskCreateNodeSet* ui; + std::unique_ptr ui; }; } //namespace PartDesignGui diff --git a/src/Mod/Fem/Gui/TaskDriver.cpp b/src/Mod/Fem/Gui/TaskDriver.cpp index f2589f3159..32cd7fb338 100644 --- a/src/Mod/Fem/Gui/TaskDriver.cpp +++ b/src/Mod/Fem/Gui/TaskDriver.cpp @@ -32,15 +32,12 @@ using namespace FemGui; using namespace Gui; TaskDriver::TaskDriver(Fem::FemAnalysis* pcObject, QWidget* parent) - : TaskBox(Gui::BitmapFactory().pixmap("FEM_CreateNodesSet"), - tr("Nodes set"), - true, - parent), - pcObject(pcObject) + : TaskBox(Gui::BitmapFactory().pixmap("FEM_CreateNodesSet"), tr("Nodes set"), true, parent), + pcObject(pcObject), + ui(new Ui_TaskDriver) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskDriver(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -48,8 +45,6 @@ TaskDriver::TaskDriver(Fem::FemAnalysis* pcObject, QWidget* parent) } TaskDriver::~TaskDriver() -{ - delete ui; -} +{} #include "moc_TaskDriver.cpp" diff --git a/src/Mod/Fem/Gui/TaskDriver.h b/src/Mod/Fem/Gui/TaskDriver.h index e10596f785..58fc8435ff 100644 --- a/src/Mod/Fem/Gui/TaskDriver.h +++ b/src/Mod/Fem/Gui/TaskDriver.h @@ -62,7 +62,7 @@ protected: private: QWidget* proxy; - Ui_TaskDriver* ui; + std::unique_ptr ui; }; } //namespace FemGui diff --git a/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp b/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp index ff734f14c2..659766555f 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp @@ -48,13 +48,13 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintBearing */ -TaskFemConstraintBearing::TaskFemConstraintBearing(ViewProviderFemConstraint *ConstraintView,QWidget *parent, - const char *pixmapname) - : TaskFemConstraint(ConstraintView, parent, pixmapname) +TaskFemConstraintBearing::TaskFemConstraintBearing(ViewProviderFemConstraint* ConstraintView, + QWidget* parent, const char* pixmapname) + : TaskFemConstraint(ConstraintView, parent, pixmapname), + ui(new Ui_TaskFemConstraintBearing) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintBearing(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -79,7 +79,8 @@ TaskFemConstraintBearing::TaskFemConstraintBearing(ViewProviderFemConstraint *Co ui->spinDistance->setMaximum(FLOAT_MAX); // Get the feature data - Fem::ConstraintBearing* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintBearing* pcConstraint = + static_cast(ConstraintView->getObject()); double distance = pcConstraint->Dist.getValue(); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -143,8 +144,10 @@ void TaskFemConstraintBearing::onSelectionChanged(const Gui::SelectionChanges& m if (selectionMode == selnone) return; - Fem::ConstraintBearing* pcConstraint = static_cast(ConstraintView->getObject()); - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(msg.pObjectName); + Fem::ConstraintBearing* pcConstraint = + static_cast(ConstraintView->getObject()); + App::DocumentObject* obj = + ConstraintView->getObject()->getDocument()->getObject(msg.pObjectName); Part::Feature* feat = static_cast(obj); TopoDS_Shape ref = feat->Shape.getShape().getSubShape(subName.c_str()); @@ -153,10 +156,13 @@ void TaskFemConstraintBearing::onSelectionChanged(const Gui::SelectionChanges& m std::vector SubElements = pcConstraint->References.getSubValues(); if (!Objects.empty()) { - QMessageBox::warning(this, tr("Selection error"), tr("Please use only a single reference for bearing constraint")); + QMessageBox::warning( + this, + tr("Selection error"), + tr("Please use only a single reference for bearing constraint")); return; } - if (subName.substr(0,4) != "Face") { + if (subName.substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } @@ -164,37 +170,41 @@ void TaskFemConstraintBearing::onSelectionChanged(const Gui::SelectionChanges& m // Only cylindrical faces allowed BRepAdaptor_Surface surface(TopoDS::Face(ref)); if (surface.GetType() != GeomAbs_Cylinder) { - QMessageBox::warning(this, tr("Selection error"), tr("Only cylindrical faces can be picked")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only cylindrical faces can be picked")); return; } // add the new reference Objects.push_back(obj); SubElements.push_back(subName); - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); ui->listReferences->addItem(makeRefText(obj, subName)); // Turn off reference selection mode onButtonReference(false); } else if (selectionMode == selloc) { - if (subName.substr(0,4) == "Face") { + if (subName.substr(0, 4) == "Face") { if (!Fem::Tools::isPlanar(TopoDS::Face(ref))) { - QMessageBox::warning(this, tr("Selection error"), tr("Only planar faces can be picked")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only planar faces can be picked")); return; } } - else if (subName.substr(0,4) == "Edge") { + else if (subName.substr(0, 4) == "Edge") { if (!Fem::Tools::isLinear(TopoDS::Edge(ref))) { - QMessageBox::warning(this, tr("Selection error"), tr("Only linear edges can be picked")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only linear edges can be picked")); return; } } else { - QMessageBox::warning(this, tr("Selection error"), tr("Only faces and edges can be picked")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only faces and edges can be picked")); return; } - std::vector references(1,subName); + std::vector references(1, subName); pcConstraint->Location.setValue(obj, references); ui->lineLocation->setText(makeRefText(obj, subName)); @@ -208,7 +218,8 @@ void TaskFemConstraintBearing::onSelectionChanged(const Gui::SelectionChanges& m void TaskFemConstraintBearing::onDistanceChanged(double l) { - Fem::ConstraintBearing* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintBearing* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->Dist.setValue(l); } @@ -231,7 +242,8 @@ void TaskFemConstraintBearing::onButtonLocation(const bool pressed) { void TaskFemConstraintBearing::onCheckAxial(const bool pressed) { - Fem::ConstraintBearing* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintBearing* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->AxialFree.setValue(pressed); } @@ -276,9 +288,7 @@ bool TaskFemConstraintBearing::getAxial() const } TaskFemConstraintBearing::~TaskFemConstraintBearing() -{ - delete ui; -} +{} bool TaskFemConstraintBearing::event(QEvent *e) { @@ -300,7 +310,8 @@ void TaskFemConstraintBearing::changeEvent(QEvent *e) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintBearing::TaskDlgFemConstraintBearing(ViewProviderFemConstraintBearing *ConstraintView) +TaskDlgFemConstraintBearing::TaskDlgFemConstraintBearing( + ViewProviderFemConstraintBearing* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -314,11 +325,15 @@ TaskDlgFemConstraintBearing::TaskDlgFemConstraintBearing(ViewProviderFemConstrai bool TaskDlgFemConstraintBearing::accept() { std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintBearing* parameterBearing = static_cast(parameter); + const TaskFemConstraintBearing* parameterBearing = + static_cast(parameter); try { - //Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "FEM force constraint changed")); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Dist = %f",name.c_str(), parameterBearing->getDistance()); + // Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "FEM force constraint changed")); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Dist = %f", + name.c_str(), + parameterBearing->getDistance()); std::string locname = parameterBearing->getLocationName().data(); std::string locobj = parameterBearing->getLocationObject().data(); @@ -327,12 +342,20 @@ bool TaskDlgFemConstraintBearing::accept() QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); buf = buf.arg(QString::fromStdString(locname)); buf = buf.arg(QString::fromStdString(locobj)); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Location = %s", name.c_str(), buf.toStdString().c_str()); - } else { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Location = None", name.c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Location = %s", + name.c_str(), + buf.toStdString().c_str()); + } + else { + Gui::Command::doCommand( + Gui::Command::Doc, "App.ActiveDocument.%s.Location = None", name.c_str()); } - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.AxialFree = %s", name.c_str(), parameterBearing->getAxial() ? "True" : "False"); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.AxialFree = %s", + name.c_str(), + parameterBearing->getAxial() ? "True" : "False"); } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintBearing.h b/src/Mod/Fem/Gui/TaskFemConstraintBearing.h index e8f6d6e04d..4b8d81d15a 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintBearing.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintBearing.h @@ -24,6 +24,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintBearing_H #define GUI_TASKVIEW_TaskFemConstraintBearing_H +#include #include #include "TaskFemConstraint.h" @@ -47,8 +48,9 @@ class TaskFemConstraintBearing : public TaskFemConstraint Q_OBJECT public: - explicit TaskFemConstraintBearing(ViewProviderFemConstraint *ConstraintView, QWidget *parent = nullptr, - const char* pixmapname = "FEM_ConstraintBearing"); + explicit TaskFemConstraintBearing(ViewProviderFemConstraint* ConstraintView, + QWidget* parent = nullptr, + const char* pixmapname = "FEM_ConstraintBearing"); ~TaskFemConstraintBearing() override; double getDistance() const; @@ -69,8 +71,7 @@ protected: void onSelectionChanged(const Gui::SelectionChanges& msg) override; protected: - Ui_TaskFemConstraintBearing* ui; - + std::unique_ptr ui; }; /// simulation dialog for the TaskView @@ -84,7 +85,6 @@ public: /// is called by the framework if the dialog is accepted (Ok) bool accept() override; - }; } //namespace FemGui diff --git a/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp b/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp index beac27c884..cf938685ed 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp @@ -45,11 +45,12 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintContact */ -TaskFemConstraintContact::TaskFemConstraintContact(ViewProviderFemConstraintContact *ConstraintView,QWidget *parent) - : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintContact") +TaskFemConstraintContact::TaskFemConstraintContact(ViewProviderFemConstraintContact* ConstraintView, + QWidget* parent) + : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintContact"), + ui(new Ui_TaskFemConstraintContact) { proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintContact(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -77,7 +78,8 @@ TaskFemConstraintContact::TaskFemConstraintContact(ViewProviderFemConstraintCont /* Note: */ // Get the feature data - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintContact* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -96,7 +98,8 @@ TaskFemConstraintContact::TaskFemConstraintContact(ViewProviderFemConstraintCont // QMessageBox::warning(this, tr("Objects.size"), QString::number(Objects.size())); if (Objects.size() == 1) { - QMessageBox::warning(this, tr("Selection error"), tr("Only one face in object! - moved to master face")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only one face in object! - moved to master face")); ui->lw_referencesMaster->addItem(makeRefText(Objects[0], SubElements[0])); } @@ -105,20 +108,22 @@ TaskFemConstraintContact::TaskFemConstraintContact(ViewProviderFemConstraintCont ui->lw_referencesSlave->addItem(makeRefText(Objects[0], SubElements[0])); } - //Selection buttons - connect(ui->btnAddSlave, &QToolButton::clicked, this, &TaskFemConstraintContact::addToSelectionSlave); - connect(ui->btnRemoveSlave, &QToolButton::clicked, this, &TaskFemConstraintContact::removeFromSelectionSlave); + // Selection buttons + connect(ui->btnAddSlave, &QToolButton::clicked, + this, &TaskFemConstraintContact::addToSelectionSlave); + connect(ui->btnRemoveSlave, &QToolButton::clicked, + this, &TaskFemConstraintContact::removeFromSelectionSlave); - connect(ui->btnAddMaster, &QToolButton::clicked, this, &TaskFemConstraintContact::addToSelectionMaster); - connect(ui->btnRemoveMaster, &QToolButton::clicked, this, &TaskFemConstraintContact::removeFromSelectionMaster); + connect(ui->btnAddMaster, &QToolButton::clicked, + this, &TaskFemConstraintContact::addToSelectionMaster); + connect(ui->btnRemoveMaster, &QToolButton::clicked, + this, &TaskFemConstraintContact::removeFromSelectionMaster); updateUI(); } TaskFemConstraintContact::~TaskFemConstraintContact() -{ - delete ui; -} +{} void TaskFemConstraintContact::updateUI() { @@ -138,8 +143,11 @@ void TaskFemConstraintContact::addToSelectionSlave() { int rows = ui->lw_referencesSlave->model()->rowCount(); std::vector selection = Gui::Selection().getSelectionEx();//gets vector of selected objects of active document - if (rows == 1){ - QMessageBox::warning(this, tr("Selection error"), tr("Only one master face and one slave face for a contact constraint!")); + if (rows == 1) { + QMessageBox::warning( + this, + tr("Selection error"), + tr("Only one master face and one slave face for a contact constraint!")); Gui::Selection().clearSelection(); return; } @@ -147,43 +155,55 @@ void TaskFemConstraintContact::addToSelectionSlave() QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - if ((rows == 0) && (selection.size() >= 2)){ - QMessageBox::warning(this, tr("Selection error"), tr("Only one slave face for a contact constraint!")); + if ((rows == 0) && (selection.size() >= 2)) { + QMessageBox::warning( + this, tr("Selection error"), tr("Only one slave face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintContact* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - if (subNames.size() != 1){ - QMessageBox::warning(this, tr("Selection error"), tr("Only one slave face for a contact constraint!")); + if (subNames.size() != 1) { + QMessageBox::warning( + this, tr("Selection error"), tr("Only one slave face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - bool addMe=true; + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + bool addMe = true; if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } - if (addMe){ + if (addMe) { QSignalBlocker block(ui->lw_referencesSlave); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); @@ -191,48 +211,59 @@ void TaskFemConstraintContact::addToSelectionSlave() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintContact::removeFromSelectionSlave() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.empty()){ + // gets vector of selected objects of active document + std::vector selection = Gui::Selection().getSelectionEx(); + if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintContact* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } std::sort(itemsToDel.begin(), itemsToDel.end()); - while (!itemsToDel.empty()){ + while (!itemsToDel.empty()) { Objects.erase(Objects.begin() + itemsToDel.back()); SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->lw_referencesSlave); ui->lw_referencesSlave->clear(); @@ -244,52 +275,68 @@ void TaskFemConstraintContact::removeFromSelectionSlave() void TaskFemConstraintContact::addToSelectionMaster() { int rows = ui->lw_referencesMaster->model()->rowCount(); - std::vector selection = Gui::Selection().getSelectionEx();//gets vector of selected objects of active document - if (rows == 1){ - QMessageBox::warning(this, tr("Selection error"), tr("Only one master face and one slave face for a contact constraint!")); + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document + if (rows == 1) { + QMessageBox::warning( + this, + tr("Selection error"), + tr("Only one master face and one slave face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - if (selection.empty()){ + if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - if ((rows == 0) && (selection.size() >= 2)){ - QMessageBox::warning(this, tr("Selection error"), tr("Only one master for a contact constraint!")); + if ((rows == 0) && (selection.size() >= 2)) { + QMessageBox::warning( + this, tr("Selection error"), tr("Only one master for a contact constraint!")); Gui::Selection().clearSelection(); return; } - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintContact* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())){ + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - const std::vector& subNames=it->getSubNames(); + const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - if (subNames.size() != 1){ - QMessageBox::warning(this, tr("Selection error"), tr("Only one master face for a contact constraint!")); + if (subNames.size() != 1) { + QMessageBox::warning( + this, tr("Selection error"), tr("Only one master face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element - bool addMe=true; + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + bool addMe = true; if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } - if (addMe){ + if (addMe) { QSignalBlocker block(ui->lw_referencesMaster); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); @@ -297,23 +344,26 @@ void TaskFemConstraintContact::addToSelectionMaster() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintContact::removeFromSelectionMaster() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.empty()){ + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document + if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintContact* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -321,24 +371,32 @@ void TaskFemConstraintContact::removeFromSelectionMaster() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr,SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } std::sort(itemsToDel.begin(), itemsToDel.end()); - while (!itemsToDel.empty()){ + while (!itemsToDel.empty()) { Objects.erase(Objects.begin() + itemsToDel.back()); SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->lw_referencesMaster); ui->lw_referencesMaster->clear(); @@ -389,7 +447,8 @@ void TaskFemConstraintContact::changeEvent(QEvent *) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintContact::TaskDlgFemConstraintContact(ViewProviderFemConstraintContact *ConstraintView) +TaskDlgFemConstraintContact::TaskDlgFemConstraintContact( + ViewProviderFemConstraintContact* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -407,29 +466,41 @@ void TaskDlgFemConstraintContact::open() QString msg = QObject::tr("Constraint Contact"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::runCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::runCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } bool TaskDlgFemConstraintContact::accept() { -/* Note: */ + /* Note: */ std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintContact* parameterContact = static_cast(parameter); + const TaskFemConstraintContact* parameterContact = + static_cast(parameter); try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Slope = %f", - name.c_str(), parameterContact->get_Slope()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Friction = %f", - name.c_str(), parameterContact->get_Friction()); - std::string scale = parameterContact->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Slope = %f", + name.c_str(), + parameterContact->get_Slope()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Friction = %f", + name.c_str(), + parameterContact->get_Friction()); + std::string scale = parameterContact->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); return false; } -/* */ + /* */ return TaskDlgFemConstraint::accept(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintContact.h b/src/Mod/Fem/Gui/TaskFemConstraintContact.h index da823f2e3f..96319c4e46 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintContact.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintContact.h @@ -26,6 +26,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintContact_H #define GUI_TASKVIEW_TaskFemConstraintContact_H +#include #include #include "TaskFemConstraint.h" @@ -40,7 +41,8 @@ class TaskFemConstraintContact : public TaskFemConstraint Q_OBJECT public: - explicit TaskFemConstraintContact(ViewProviderFemConstraintContact *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintContact(ViewProviderFemConstraintContact* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintContact() override; const std::string getReferences() const override; double get_Slope()const; @@ -60,8 +62,7 @@ protected: private: //void onSelectionChanged(const Gui::SelectionChanges& msg); void updateUI(); - Ui_TaskFemConstraintContact* ui; - + std::unique_ptr ui; }; class TaskDlgFemConstraintContact : public TaskDlgFemConstraint diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp index 5d918d7791..f641efc618 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp @@ -46,10 +46,10 @@ using namespace Gui; TaskFemConstraintDisplacement::TaskFemConstraintDisplacement( ViewProviderFemConstraintDisplacement* ConstraintView, QWidget* parent) - : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintDisplacement") + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintDisplacement"), + ui(new Ui_TaskFemConstraintDisplacement) { proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintDisplacement(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -174,9 +174,7 @@ TaskFemConstraintDisplacement::TaskFemConstraintDisplacement( } TaskFemConstraintDisplacement::~TaskFemConstraintDisplacement() -{ - delete ui; -} +{} void TaskFemConstraintDisplacement::updateUI() { diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.h b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.h index 390d95f83a..991a73b198 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.h @@ -26,6 +26,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintDisplacement_H #define GUI_TASKVIEW_TaskFemConstraintDisplacement_H +#include #include #include @@ -44,7 +45,8 @@ class TaskFemConstraintDisplacement : public TaskFemConstraintOnBoundary Q_OBJECT public: - explicit TaskFemConstraintDisplacement(ViewProviderFemConstraintDisplacement *ConstraintView, QWidget *parent = nullptr); + explicit TaskFemConstraintDisplacement(ViewProviderFemConstraintDisplacement* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintDisplacement() override; const std::string getReferences() const override; double get_spinxDisplacement()const; @@ -99,8 +101,7 @@ protected: private: void updateUI(); - Ui_TaskFemConstraintDisplacement* ui; - + std::unique_ptr ui; }; class TaskDlgFemConstraintDisplacement : public TaskDlgFemConstraint @@ -108,7 +109,8 @@ class TaskDlgFemConstraintDisplacement : public TaskDlgFemConstraint Q_OBJECT public: - explicit TaskDlgFemConstraintDisplacement(ViewProviderFemConstraintDisplacement *ConstraintView); + explicit TaskDlgFemConstraintDisplacement( + ViewProviderFemConstraintDisplacement* ConstraintView); void open() override; bool accept() override; bool reject() override; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp index b2f52f2cd6..60f5a475dc 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp @@ -43,11 +43,12 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintFixed */ -TaskFemConstraintFixed::TaskFemConstraintFixed(ViewProviderFemConstraintFixed* ConstraintView, QWidget* parent) - : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintFixed") +TaskFemConstraintFixed::TaskFemConstraintFixed(ViewProviderFemConstraintFixed* ConstraintView, + QWidget* parent) + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintFixed"), + ui(new Ui_TaskFemConstraintFixed) { //Note change "Fixed" in line above to new constraint name proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintFixed(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -64,7 +65,8 @@ TaskFemConstraintFixed::TaskFemConstraintFixed(ViewProviderFemConstraintFixed* C /* Note: */ // Get the feature data - Fem::ConstraintFixed* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFixed* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -87,9 +89,7 @@ TaskFemConstraintFixed::TaskFemConstraintFixed(ViewProviderFemConstraintFixed* C } TaskFemConstraintFixed::~TaskFemConstraintFixed() -{ - delete ui; -} +{} void TaskFemConstraintFixed::updateUI() { @@ -102,33 +102,46 @@ void TaskFemConstraintFixed::updateUI() void TaskFemConstraintFixed::addToSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + // gets vector of selected objects of active document + std::vector selection = Gui::Selection().getSelectionEx(); if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintFixed* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFixed* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } std::vector subNames = it->getSubNames(); - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + App::DocumentObject* obj = + ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element bool addMe = true; - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } - // limit constraint such that only vertexes or faces or edges can be used depending on what was selected first + // limit constraint such that only vertexes or faces or edges can be used depending + // on what was selected first std::string searchStr; if (subNames[subIt].find("Vertex") != std::string::npos) searchStr = "Vertex"; @@ -138,7 +151,8 @@ void TaskFemConstraintFixed::addToSelection() searchStr = "Face"; for (size_t iStr = 0; iStr < (SubElements.size()); ++iStr) { if (SubElements[iStr].find(searchStr) == std::string::npos) { - QString msg = tr("Only one type of selection (vertex,face or edge) per constraint allowed!"); + QString msg = tr( + "Only one type of selection (vertex,face or edge) per constraint allowed!"); QMessageBox::warning(this, tr("Selection error"), msg); addMe = false; break; @@ -152,23 +166,26 @@ void TaskFemConstraintFixed::addToSelection() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintFixed::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + // gets vector of selected objects of active document + std::vector selection = Gui::Selection().getSelectionEx(); if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintFixed* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFixed* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -176,12 +193,20 @@ void TaskFemConstraintFixed::removeFromSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -258,16 +283,24 @@ void TaskDlgFemConstraintFixed::open() QString msg = QObject::tr("Constraint fixed"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } bool TaskDlgFemConstraintFixed::accept() { std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintFixed* parameters = static_cast(parameter); + const TaskFemConstraintFixed* parameters = + static_cast(parameter); std::string scale = parameters->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale return TaskDlgFemConstraint::accept(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFixed.h b/src/Mod/Fem/Gui/TaskFemConstraintFixed.h index 2efdb08e2d..8bc939b842 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFixed.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintFixed.h @@ -24,6 +24,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintFixed_H #define GUI_TASKVIEW_TaskFemConstraintFixed_H +#include #include #include "TaskFemConstraintOnBoundary.h" @@ -38,7 +39,8 @@ class TaskFemConstraintFixed : public TaskFemConstraintOnBoundary Q_OBJECT public: - explicit TaskFemConstraintFixed(ViewProviderFemConstraintFixed *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintFixed(ViewProviderFemConstraintFixed* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintFixed() override; const std::string getReferences() const override; @@ -54,8 +56,7 @@ protected: private: void updateUI(); - Ui_TaskFemConstraintFixed* ui; - + std::unique_ptr ui; }; class TaskDlgFemConstraintFixed : public TaskDlgFemConstraint diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp index c8f7fd21c4..cd3195e795 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp @@ -54,14 +54,22 @@ using namespace FemGui; using namespace Gui; using namespace Fem; -//also defined in FemConstrainFluidBoundary and foamcasebuilder/basicbuilder.py, please update simultaneously -//the second (index 1) is the default enum, as index 0 causes compiling error -//static const char* BoundaryTypes[] = {"inlet","wall","outlet","freestream", "interface", NULL}; -static const char* WallSubtypes[] = { "unspecific", "fixed", "slip", "partialSlip", "moving", "rough", nullptr }; -static const char* InletSubtypes[] = { "unspecific","totalPressure","uniformVelocity","volumetricFlowRate","massFlowRate",nullptr }; -static const char* OutletSubtypes[] = { "unspecific","totalPressure","staticPressure","uniformVelocity", "outFlow", nullptr }; -static const char* InterfaceSubtypes[] = { "unspecific","symmetry","wedge","cyclic","empty", "coupled", nullptr }; -static const char* FreestreamSubtypes[] = { "unspecific", "freestream",nullptr }; +// also defined in FemConstrainFluidBoundary and foamcasebuilder/basicbuilder.py, please update +// simultaneously the second (index 1) is the default enum, as index 0 causes compiling error static +// const char* BoundaryTypes[] = {"inlet","wall","outlet","freestream", "interface", NULL}; +static const char* WallSubtypes[] = { + "unspecific", "fixed", "slip", "partialSlip", "moving", "rough", nullptr}; +static const char* InletSubtypes[] = {"unspecific", + "totalPressure", + "uniformVelocity", + "volumetricFlowRate", + "massFlowRate", + nullptr}; +static const char* OutletSubtypes[] = { + "unspecific", "totalPressure", "staticPressure", "uniformVelocity", "outFlow", nullptr}; +static const char* InterfaceSubtypes[] = { + "unspecific", "symmetry", "wedge", "cyclic", "empty", "coupled", nullptr}; +static const char* FreestreamSubtypes[] = {"unspecific", "freestream", nullptr}; static const char* InterfaceSubtypeHelpTexts[] = { "invalid,select other valid interface subtype", @@ -69,37 +77,47 @@ static const char* InterfaceSubtypeHelpTexts[] = { "axis symmetric front and back surfaces", "periodic boundary in pair, treated as physical connected", "front and back for single layer 2D mesh, also axis-sym axis line", - "exchange boundary vale with external program, need extra manual setup like file name", nullptr }; + "exchange boundary vale with external program, need extra manual setup like file name", + nullptr}; // defined in file FemConstraintFluidBoundary: // see Ansys fluet manual: Turbulence Specification method -//static const char* TurbulenceSpecifications[] = {"intensity&DissipationRate", "intensity&LengthScale","intensity&ViscosityRatio", "intensity&HydraulicDiameter",NULL}; -//activate the heat transfer and radiation model in Solver object explorer +// static const char* TurbulenceSpecifications[] = {"intensity&DissipationRate", +// "intensity&LengthScale","intensity&ViscosityRatio", "intensity&HydraulicDiameter",NULL}; activate +// the heat transfer and radiation model in Solver object explorer static const char* TurbulenceSpecificationHelpTexts[] = { - "explicitly specific intensity k [SI unit] and dissipation rate epsilon [] / omega []", - "intensity (0.05 ~ 0.15) and characteristic length scale of max eddy [m]", - "intensity (0.05 ~ 0.15) and turbulent viscosity ratio", - "for fully developed internal flow, Turbulence intensity (0-1.0) 0.05 typical", nullptr }; + "explicitly specific intensity k [SI unit] and dissipation rate epsilon [] / omega []", + "intensity (0.05 ~ 0.15) and characteristic length scale of max eddy [m]", + "intensity (0.05 ~ 0.15) and turbulent viscosity ratio", + "for fully developed internal flow, Turbulence intensity (0-1.0) 0.05 typical", + nullptr}; -//static const char* ThermalBoundaryTypes[] = {"fixedValue","zeroGradient", "fixedGradient", "mixed", "heatFlux", "HTC","coupled", NULL}; -static const char* ThermalBoundaryHelpTexts[] = { "fixed Temperature [K]", "no heat transfer on boundary", "fixed value gradient [K/m]", - "mixed fixedGradient and fixedValue", "fixed heat flux [W/m2]", "Heat transfer coeff [W/(M2)/K]", "conjugate heat transfer with solid", nullptr }; +// static const char* ThermalBoundaryTypes[] = {"fixedValue","zeroGradient", "fixedGradient", +// "mixed", "heatFlux", "HTC","coupled", NULL}; +static const char* ThermalBoundaryHelpTexts[] = {"fixed Temperature [K]", + "no heat transfer on boundary", + "fixed value gradient [K/m]", + "mixed fixedGradient and fixedValue", + "fixed heat flux [W/m2]", + "Heat transfer coeff [W/(M2)/K]", + "conjugate heat transfer with solid", + nullptr}; // enable & disable quantityUI once valueType is selected // internal function not declared in header file -void initComboBox(QComboBox* combo, const std::vector& textItems, const std::string& sItem) +void initComboBox(QComboBox* combo, const std::vector& textItems, + const std::string& sItem) { combo->blockSignals(true); - int iItem = 1; // the first one is "unspecific" (index 0) + int iItem = 1;// the first one is "unspecific" (index 0) combo->clear(); - for (unsigned int it = 0; it < textItems.size(); it++) - { + for (unsigned int it = 0; it < textItems.size(); it++) { combo->insertItem(it, Base::Tools::fromStdString(textItems[it])); - if (sItem == textItems[it]) - { + if (sItem == textItems[it]) { iItem = it; - //Base::Console().Warning("Found the subtype and set the current index as %d for subtype %s ComboBox\n", it, sItem); + // Base::Console().Warning("Found the subtype and set the current index as %d for + // subtype %s ComboBox\n", it, sItem); } } combo->setCurrentIndex(iItem); @@ -107,13 +125,14 @@ void initComboBox(QComboBox* combo, const std::vector& textItems, c } /* TRANSLATOR FemGui::TaskFemConstraintFluidBoundary */ -TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary(ViewProviderFemConstraintFluidBoundary* ConstraintView, QWidget* parent) - : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintFluidBoundary") - , dimension(-1) +TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary( + ViewProviderFemConstraintFluidBoundary* ConstraintView, QWidget* parent) + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintFluidBoundary"), + dimension(-1), + ui(new Ui_TaskFemConstraintFluidBoundary) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintFluidBoundary(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -170,7 +189,8 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary(ViewProviderFemCo buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove); // Get the feature data - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); Fem::FemAnalysis* pcAnalysis = nullptr; if (FemGui::ActiveAnalysisObserver::instance()->hasActiveObject()) { @@ -178,9 +198,10 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary(ViewProviderFemCo } else { App::Document* aDoc = pcConstraint->getDocument(); - std::vector fem = aDoc->getObjectsOfType(Fem::FemAnalysis::getClassTypeId()); + std::vector fem = + aDoc->getObjectsOfType(Fem::FemAnalysis::getClassTypeId()); if (!fem.empty()) { - pcAnalysis = static_cast(fem[0]); // get the first + pcAnalysis = static_cast(fem[0]);// get the first } } @@ -193,25 +214,29 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary(ViewProviderFemCo } } else { - Base::Console().Log("FemAnalysis object is not activated or no FemAnalysis in the active document, mesh dimension is unknown\n"); - dimension = -1; // unknown dimension of mesh + Base::Console().Log("FemAnalysis object is not activated or no FemAnalysis in the active " + "document, mesh dimension is unknown\n"); + dimension = -1;// unknown dimension of mesh } if (pcMesh) { - App::Property* prop = pcMesh->getPropertyByName("Shape"); // PropertyLink + App::Property* prop = pcMesh->getPropertyByName("Shape");// PropertyLink if (prop && prop->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) { App::PropertyLink* pcLink = static_cast(prop); Part::Feature* pcPart = dynamic_cast(pcLink->getValue()); - if (pcPart) { // deduct dimension from part_obj.Shape.ShapeType + if (pcPart) {// deduct dimension from part_obj.Shape.ShapeType const TopoDS_Shape& pShape = pcPart->Shape.getShape().getShape(); - const TopAbs_ShapeEnum shapeType = pShape.IsNull() ? TopAbs_SHAPE : pShape.ShapeType(); - if (shapeType == TopAbs_SOLID || shapeType == TopAbs_COMPSOLID) // COMPSOLID is solids connected by faces + const TopAbs_ShapeEnum shapeType = + pShape.IsNull() ? TopAbs_SHAPE : pShape.ShapeType(); + if (shapeType == TopAbs_SOLID + || shapeType == TopAbs_COMPSOLID)// COMPSOLID is solids connected by faces dimension = 3; else if (shapeType == TopAbs_FACE || shapeType == TopAbs_SHELL) dimension = 2; else if (shapeType == TopAbs_EDGE || shapeType == TopAbs_WIRE) dimension = 1; else - dimension = -1; // Vertex (0D) can not make mesh, Compound type might contain any types + dimension = + -1;// Vertex (0D) can not make mesh, Compound type might contain any types } } } @@ -228,39 +253,46 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary(ViewProviderFemCo pHeatTransferring = nullptr; pTurbulenceModel = nullptr; if (pcSolver) { - //if only it is CFD solver, otherwise exit by SIGSEGV error, detect getPropertyByName() != NULL + // if only it is CFD solver, otherwise exit by SIGSEGV error, detect getPropertyByName() != + // NULL if (pcSolver->getPropertyByName("HeatTransferring")) { - pHeatTransferring = static_cast(pcSolver->getPropertyByName("HeatTransferring")); + pHeatTransferring = + static_cast(pcSolver->getPropertyByName("HeatTransferring")); if (pHeatTransferring->getValue()) { ui->tabThermalBoundary->setEnabled(true); - initComboBox(ui->comboThermalBoundaryType, pcConstraint->ThermalBoundaryType.getEnumVector(), - pcConstraint->ThermalBoundaryType.getValueAsString()); + initComboBox(ui->comboThermalBoundaryType, + pcConstraint->ThermalBoundaryType.getEnumVector(), + pcConstraint->ThermalBoundaryType.getValueAsString()); ui->spinHTCoeffValue->setValue(pcConstraint->HTCoeffValue.getValue()); ui->spinHeatFluxValue->setValue(pcConstraint->HeatFluxValue.getValue()); ui->spinTemperatureValue->setValue(pcConstraint->TemperatureValue.getValue()); updateThermalBoundaryUI(); } else { - ui->tabThermalBoundary->setEnabled(false); // could be hidden - //Base::Console().Message("retrieve solver property HeatTransferring as false\n"); + ui->tabThermalBoundary->setEnabled(false);// could be hidden + // Base::Console().Message("retrieve solver property HeatTransferring as false\n"); } } else { ui->tabThermalBoundary->setEnabled(false); } if (pcSolver->getPropertyByName("TurbulenceModel")) { - pTurbulenceModel = static_cast(pcSolver->getPropertyByName("TurbulenceModel")); + pTurbulenceModel = static_cast( + pcSolver->getPropertyByName("TurbulenceModel")); if (pTurbulenceModel->getValueAsString() == std::string("laminar")) { ui->tabTurbulenceBoundary->setEnabled(false); } else { ui->tabTurbulenceBoundary->setEnabled(true); - ui->labelTurbulenceSpecification->setText(Base::Tools::fromStdString( - pTurbulenceModel->getValueAsString())); - initComboBox(ui->comboTurbulenceSpecification, pcConstraint->TurbulenceSpecification.getEnumVector(), - pcConstraint->TurbulenceSpecification.getValueAsString()); - ui->spinTurbulentIntensityValue->setValue(pcConstraint->TurbulentIntensityValue.getValue()); - ui->spinTurbulentLengthValue->setValue(pcConstraint->TurbulentLengthValue.getValue()); + ui->labelTurbulenceSpecification->setText( + Base::Tools::fromStdString(pTurbulenceModel->getValueAsString())); + initComboBox(ui->comboTurbulenceSpecification, + pcConstraint->TurbulenceSpecification.getEnumVector(), + pcConstraint->TurbulenceSpecification.getValueAsString()); + ui->spinTurbulentIntensityValue->setValue( + pcConstraint->TurbulentIntensityValue.getValue()); + ui->spinTurbulentLengthValue->setValue( + pcConstraint->TurbulentLengthValue.getValue()); updateTurbulenceUI(); } } @@ -269,7 +301,8 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary(ViewProviderFemCo } } else { - Base::Console().Warning("No solver object inside FemAnalysis object, default to non-thermal, non-turbulence\n"); + Base::Console().Warning( + "No solver object inside FemAnalysis object, default to non-thermal, non-turbulence\n"); } ui->tabWidget->setTabText(0, tr("Basic")); ui->tabWidget->setTabText(1, tr("Turbulence")); @@ -319,9 +352,10 @@ const Fem::FemSolverObject* TaskFemConstraintFluidBoundary::getFemSolver(void) c void TaskFemConstraintFluidBoundary::updateBoundaryTypeUI() { - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); std::string boundaryType = Base::Tools::toStdString(ui->comboBoundaryType->currentText()); - //std::string boundaryType = pcConstraint->BoundaryType.getValueAsString(); + // std::string boundaryType = pcConstraint->BoundaryType.getValueAsString(); // Update subtypes, any change here should be written back to FemConstraintFluidBoundary.cpp if (boundaryType == "wall") { @@ -353,7 +387,8 @@ void TaskFemConstraintFluidBoundary::updateBoundaryTypeUI() pcConstraint->Reversed.setValue(false); // outlet must point outward } else { - Base::Console().Error("Error: Fluid boundary type `%s` is not defined\n", boundaryType.c_str()); + Base::Console().Error("Error: Fluid boundary type `%s` is not defined\n", + boundaryType.c_str()); } //std::string subtypeLabel = boundaryType + std::string(" type"); //ui->labelSubtype->setText(QString::fromUtf8(subtypeLabel)); // too long to show in UI @@ -437,9 +472,11 @@ void TaskFemConstraintFluidBoundary::updateSubtypeUI() void TaskFemConstraintFluidBoundary::updateTurbulenceUI() { - ui->labelHelpText->setText(tr(TurbulenceSpecificationHelpTexts[ui->comboTurbulenceSpecification->currentIndex()])); + ui->labelHelpText->setText( + tr(TurbulenceSpecificationHelpTexts[ui->comboTurbulenceSpecification->currentIndex()])); /// hide/disable UI only happened in constructor, update helptext and label text here - std::string turbulenceSpec = Base::Tools::toStdString(ui->comboTurbulenceSpecification->currentText()); + std::string turbulenceSpec = + Base::Tools::toStdString(ui->comboTurbulenceSpecification->currentText()); ui->labelTurbulentIntensityValue->setText(tr("Intensity [0~1]")); if (turbulenceSpec == "intensity&DissipationRate") { ui->labelTurbulentLengthValue->setText(tr("Dissipation Rate [m2/s3]")); @@ -460,12 +497,15 @@ void TaskFemConstraintFluidBoundary::updateTurbulenceUI() void TaskFemConstraintFluidBoundary::updateThermalBoundaryUI() { - //Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); - //std::string thermalBoundaryType = pcConstraint->ThermalBoundaryType.getValueAsString(); + // Fem::ConstraintFluidBoundary* pcConstraint = + // static_cast(ConstraintView->getObject()); std::string + // thermalBoundaryType = pcConstraint->ThermalBoundaryType.getValueAsString(); - ui->labelHelpText->setText(tr(ThermalBoundaryHelpTexts[ui->comboThermalBoundaryType->currentIndex()])); - //to hide/disable UI according to subtype - std::string thermalBoundaryType = Base::Tools::toStdString(ui->comboThermalBoundaryType->currentText()); + ui->labelHelpText->setText( + tr(ThermalBoundaryHelpTexts[ui->comboThermalBoundaryType->currentIndex()])); + // to hide/disable UI according to subtype + std::string thermalBoundaryType = + Base::Tools::toStdString(ui->comboThermalBoundaryType->currentText()); ui->spinHTCoeffValue->setEnabled(false); ui->spinTemperatureValue->setEnabled(false); ui->spinHeatFluxValue->setEnabled(false); @@ -493,31 +533,36 @@ void TaskFemConstraintFluidBoundary::updateThermalBoundaryUI() ui->spinTemperatureValue->setEnabled(true); } else { - Base::Console().Error("Thermal boundary type `%s` is not defined\n", thermalBoundaryType.c_str()); + Base::Console().Error("Thermal boundary type `%s` is not defined\n", + thermalBoundaryType.c_str()); } } void TaskFemConstraintFluidBoundary::onBoundaryTypeChanged(void) { - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); - // temporarily change BoundaryType property, but command transaction should reset it back if you 'reject' late + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); + // temporarily change BoundaryType property, but command transaction should reset it back if you + // 'reject' late pcConstraint->BoundaryType.setValue(ui->comboBoundaryType->currentIndex()); updateBoundaryTypeUI(); - ConstraintView->updateData(&pcConstraint->BoundaryType); //force a 3D redraw + ConstraintView->updateData(&pcConstraint->BoundaryType);// force a 3D redraw // update view provider once BoundaryType changed, updateData() may be just enough - //FreeCAD.getDocument(pcConstraint->Document.getName()).recompute(); + // FreeCAD.getDocument(pcConstraint->Document.getName()).recompute(); bool ret = pcConstraint->recomputeFeature(); if (!ret) { std::string boundaryType = ui->comboBoundaryType->currentText().toStdString(); - Base::Console().Error("Fluid boundary recomputationg failed for boundaryType `%s` \n", boundaryType.c_str()); + Base::Console().Error("Fluid boundary recomputationg failed for boundaryType `%s` \n", + boundaryType.c_str()); } } void TaskFemConstraintFluidBoundary::onSubtypeChanged(void) { - updateSubtypeUI(); // todo: change color for different kind of subtype, Fem::ConstraintFluidBoundary::onChanged() and viewProvider + updateSubtypeUI();// todo: change color for different kind of subtype, + // Fem::ConstraintFluidBoundary::onChanged() and viewProvider } void TaskFemConstraintFluidBoundary::onBoundaryValueChanged(double) @@ -526,20 +571,25 @@ void TaskFemConstraintFluidBoundary::onBoundaryValueChanged(double) } void TaskFemConstraintFluidBoundary::onTurbulenceSpecificationChanged(void) { - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); - pcConstraint->TurbulenceSpecification.setValue(ui->comboTurbulenceSpecification->currentIndex()); + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); + pcConstraint->TurbulenceSpecification.setValue( + ui->comboTurbulenceSpecification->currentIndex()); updateTurbulenceUI(); } void TaskFemConstraintFluidBoundary::onThermalBoundaryTypeChanged(void) { - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->ThermalBoundaryType.setValue(ui->comboThermalBoundaryType->currentIndex()); updateThermalBoundaryUI(); } -void TaskFemConstraintFluidBoundary::onReferenceDeleted() { - TaskFemConstraintFluidBoundary::removeFromSelection(); //On right-click face is automatically selected, so just remove +void TaskFemConstraintFluidBoundary::onReferenceDeleted() +{ + TaskFemConstraintFluidBoundary::removeFromSelection();// On right-click face is automatically + // selected, so just remove } void TaskFemConstraintFluidBoundary::onButtonDirection(const bool pressed) @@ -550,27 +600,30 @@ void TaskFemConstraintFluidBoundary::onButtonDirection(const bool pressed) clearButtons(SelectionChangeModes::none); - //get vector of selected objects of active document + // get vector of selected objects of active document std::vector selection = Gui::Selection().getSelectionEx(); if (selection.empty()) { QMessageBox::warning(this, tr("Empty selection"), tr("Select an edge or a face, please.")); return; } - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); // we only handle the first selected object Gui::SelectionObject& selectionElement = selection.at(0); // we can only handle part objects if (!selectionElement.isObjectTypeOf(Part::Feature::getClassTypeId())) { - QMessageBox::warning(this, tr("Wrong selection"), tr("Selected object is not a part object!")); + QMessageBox::warning( + this, tr("Wrong selection"), tr("Selected object is not a part object!")); return; } // get the names of the subobjects const std::vector& subNames = selectionElement.getSubNames(); if (subNames.size() != 1) { - QMessageBox::warning(this, tr("Wrong selection"), tr("Only one planar face or edge can be selected!")); + QMessageBox::warning( + this, tr("Wrong selection"), tr("Only one planar face or edge can be selected!")); return; } @@ -584,18 +637,22 @@ void TaskFemConstraintFluidBoundary::onButtonDirection(const bool pressed) if (subNamesElement.substr(0, 4) == "Face") { if (!Fem::Tools::isPlanar(TopoDS::Face(ref))) { - QMessageBox::warning(this, tr("Wrong selection"), tr("Only planar faces can be picked for 3D")); + QMessageBox::warning( + this, tr("Wrong selection"), tr("Only planar faces can be picked for 3D")); return; } } - else if (subNamesElement.substr(0, 4) == "Edge") { // 2D or 3D can use edge as direction vector + else if (subNamesElement.substr(0, 4) == "Edge") {// 2D or 3D can use edge as direction vector if (!Fem::Tools::isLinear(TopoDS::Edge(ref))) { - QMessageBox::warning(this, tr("Wrong selection"), tr("Only planar edges can be picked for 2D")); + QMessageBox::warning( + this, tr("Wrong selection"), tr("Only planar edges can be picked for 2D")); return; } } else { - QMessageBox::warning(this, tr("Wrong selection"), tr("Only faces for 3D part or edges for 2D can be picked")); + QMessageBox::warning(this, + tr("Wrong selection"), + tr("Only faces for 3D part or edges for 2D can be picked")); return; } @@ -603,13 +660,14 @@ void TaskFemConstraintFluidBoundary::onButtonDirection(const bool pressed) pcConstraint->Direction.setValue(feat, direction); ui->lineDirection->setText(makeRefText(feat, subNamesElement)); - //Update UI + // Update UI updateUI(); } void TaskFemConstraintFluidBoundary::onCheckReverse(const bool pressed) { - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->Reversed.setValue(pressed); } @@ -720,22 +778,23 @@ bool TaskFemConstraintFluidBoundary::getReverse() const } TaskFemConstraintFluidBoundary::~TaskFemConstraintFluidBoundary() -{ - delete ui; -} +{} void TaskFemConstraintFluidBoundary::addToSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -744,15 +803,23 @@ void TaskFemConstraintFluidBoundary::addToSelection() App::DocumentObject* obj = it->getObject(); for (size_t subIt = 0; subIt < subNames.size(); ++subIt) {// for every selected sub element bool addMe = true; - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } - // limit constraint such that only vertexes or faces or edges can be used depending on what was selected first + // limit constraint such that only vertexes or faces or edges can be used depending on + // what was selected first std::string searchStr; if (subNames[subIt].find("Vertex") != std::string::npos) searchStr = "Vertex"; @@ -763,7 +830,8 @@ void TaskFemConstraintFluidBoundary::addToSelection() for (size_t iStr = 0; iStr < (SubElements.size()); ++iStr) { if (SubElements[iStr].find(searchStr) == std::string::npos) { - QString msg = tr("Only one type of selection (vertex,face or edge) per constraint allowed!"); + QString msg = tr( + "Only one type of selection (vertex,face or edge) per constraint allowed!"); QMessageBox::warning(this, tr("Selection error"), msg); addMe = false; break; @@ -777,23 +845,26 @@ void TaskFemConstraintFluidBoundary::addToSelection() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintFluidBoundary::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintFluidBoundary* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -801,12 +872,20 @@ void TaskFemConstraintFluidBoundary::removeFromSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -818,7 +897,7 @@ void TaskFemConstraintFluidBoundary::removeFromSelection() SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->listReferences); ui->listReferences->clear(); @@ -869,7 +948,8 @@ void TaskFemConstraintFluidBoundary::clearButtons(const SelectionChangeModes not // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintFluidBoundary::TaskDlgFemConstraintFluidBoundary(ViewProviderFemConstraintFluidBoundary* ConstraintView) +TaskDlgFemConstraintFluidBoundary::TaskDlgFemConstraintFluidBoundary( + ViewProviderFemConstraintFluidBoundary* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -892,17 +972,26 @@ void TaskDlgFemConstraintFluidBoundary::open() bool TaskDlgFemConstraintFluidBoundary::accept() { std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintFluidBoundary* boundary = static_cast(parameter); + const TaskFemConstraintFluidBoundary* boundary = + static_cast(parameter); - // no need to backup pcConstraint object content, if rejected, content can be recovered by transaction manager + // no need to backup pcConstraint object content, if rejected, content can be recovered by + // transaction manager try { - //Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Fluid boundary condition changed")); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.BoundaryType = '%s'", - name.c_str(), boundary->getBoundaryType().c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Subtype = '%s'", - name.c_str(), boundary->getSubtype().c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.BoundaryValue = %f", - name.c_str(), boundary->getBoundaryValue()); + // Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Fluid boundary condition + // changed")); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.BoundaryType = '%s'", + name.c_str(), + boundary->getBoundaryType().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Subtype = '%s'", + name.c_str(), + boundary->getSubtype().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.BoundaryValue = %f", + name.c_str(), + boundary->getBoundaryValue()); std::string dirname = boundary->getDirectionName().data(); std::string dirobj = boundary->getDirectionObject().data(); @@ -911,16 +1000,24 @@ bool TaskDlgFemConstraintFluidBoundary::accept() QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); buf = buf.arg(QString::fromStdString(dirname)); buf = buf.arg(QString::fromStdString(dirobj)); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Direction = %s", name.c_str(), buf.toStdString().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Direction = %s", + name.c_str(), + buf.toStdString().c_str()); } else { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Direction = None", name.c_str()); + Gui::Command::doCommand( + Gui::Command::Doc, "App.ActiveDocument.%s.Direction = None", name.c_str()); } - //Reverse control is done at BoundaryType selection, this UI is hidden from user - //Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %s", name.c_str(), boundary->getReverse() ? "True" : "False"); + // Reverse control is done at BoundaryType selection, this UI is hidden from user + // Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %s", + // name.c_str(), boundary->getReverse() ? "True" : "False"); - std::string scale = boundary->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + std::string scale = boundary->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale // solver specific setting, physical model selection const Fem::FemSolverObject* pcSolver = boundary->getFemSolver(); @@ -928,24 +1025,51 @@ bool TaskDlgFemConstraintFluidBoundary::accept() if (pcSolver) { App::PropertyBool* pHeatTransferring = nullptr; App::PropertyEnumeration* pTurbulenceModel = nullptr; - pHeatTransferring = static_cast(pcSolver->getPropertyByName("HeatTransferring")); - pTurbulenceModel = static_cast(pcSolver->getPropertyByName("TurbulenceModel")); + pHeatTransferring = + static_cast(pcSolver->getPropertyByName("HeatTransferring")); + pTurbulenceModel = static_cast( + pcSolver->getPropertyByName("TurbulenceModel")); if (pHeatTransferring && pHeatTransferring->getValue()) { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.ThermalBoundaryType = '%s'", name.c_str(), boundary->getThermalBoundaryType().c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.TemperatureValue = %f", name.c_str(), boundary->getTemperatureValue()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.HeatFluxValue = %f", name.c_str(), boundary->getHeatFluxValue()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.HTCoeffValue = %f", name.c_str(), boundary->getHTCoeffValue()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.ThermalBoundaryType = '%s'", + name.c_str(), + boundary->getThermalBoundaryType().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.TemperatureValue = %f", + name.c_str(), + boundary->getTemperatureValue()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.HeatFluxValue = %f", + name.c_str(), + boundary->getHeatFluxValue()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.HTCoeffValue = %f", + name.c_str(), + boundary->getHTCoeffValue()); } - if (pTurbulenceModel && std::string(pTurbulenceModel->getValueAsString()) != "laminar") { // Invisic and DNS flow also does not need this - //update turbulence and thermal boundary settings, only if those models are activated - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.TurbulenceSpecification = '%s'", name.c_str(), boundary->getTurbulenceSpecification().c_str()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.TurbulentIntensityValue = %f", name.c_str(), boundary->getTurbulentIntensityValue()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.TurbulentLengthValue = %f", name.c_str(), boundary->getTurbulentLengthValue()); + if (pTurbulenceModel + && std::string(pTurbulenceModel->getValueAsString()) + != "laminar") {// Invisic and DNS flow also does not need this + // update turbulence and thermal boundary settings, only if those models are + // activated + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.TurbulenceSpecification = '%s'", + name.c_str(), + boundary->getTurbulenceSpecification().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.TurbulentIntensityValue = %f", + name.c_str(), + boundary->getTurbulentIntensityValue()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.TurbulentLengthValue = %f", + name.c_str(), + boundary->getTurbulentLengthValue()); } } else { - Base::Console().Warning("FemSolverObject is not found in the FemAnalysis object, thermal and turbulence setting is not accepted\n"); + Base::Console().Warning("FemSolverObject is not found in the FemAnalysis object, " + "thermal and turbulence setting is not accepted\n"); } } catch (const Base::Exception& e) { diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.h b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.h index 2252e43624..24135a80b1 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.h @@ -23,6 +23,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintFluidBoundary_H #define GUI_TASKVIEW_TaskFemConstraintFluidBoundary_H +#include #include #include @@ -48,7 +49,8 @@ class TaskFemConstraintFluidBoundary : public TaskFemConstraintOnBoundary Q_OBJECT public: - explicit TaskFemConstraintFluidBoundary(ViewProviderFemConstraintFluidBoundary *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintFluidBoundary(ViewProviderFemConstraintFluidBoundary* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintFluidBoundary() override; const Fem::FemSolverObject* getFemSolver() const; @@ -98,7 +100,7 @@ private: void updateUI(); private: - Ui_TaskFemConstraintFluidBoundary* ui; + std::unique_ptr ui; int dimension; // -1: unknown, 2 for 2D and 3 for 3D Fem::FemSolverObject* pcSolver; App::PropertyBool* pHeatTransferring; @@ -111,13 +113,13 @@ class TaskDlgFemConstraintFluidBoundary : public TaskDlgFemConstraint Q_OBJECT public: - explicit TaskDlgFemConstraintFluidBoundary(ViewProviderFemConstraintFluidBoundary *ConstraintView); + explicit TaskDlgFemConstraintFluidBoundary( + ViewProviderFemConstraintFluidBoundary* ConstraintView); /// is called by the framework if the dialog is accepted (Ok) void open() override; bool accept() override; bool reject() override; - }; } //namespace FemGui diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp index 97db698df1..1ff2784840 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp @@ -47,12 +47,13 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintForce */ -TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* ConstraintView, QWidget* parent) - : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintForce") +TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* ConstraintView, + QWidget* parent) + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintForce"), + ui(new Ui_TaskFemConstraintForce) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintForce(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -78,7 +79,8 @@ TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* C ui->checkReverse->blockSignals(true); // Get the feature data - Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintForce* pcConstraint = + static_cast(ConstraintView->getObject()); double f = pcConstraint->Force.getValue(); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -123,33 +125,45 @@ void TaskFemConstraintForce::updateUI() void TaskFemConstraintForce::addToSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintForce* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element bool addMe = true; - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } - // limit constraint such that only vertexes or faces or edges can be used depending on what was selected first + // limit constraint such that only vertexes or faces or edges can be used depending on + // what was selected first std::string searchStr; if (subNames[subIt].find("Vertex") != std::string::npos) searchStr = "Vertex"; @@ -160,7 +174,8 @@ void TaskFemConstraintForce::addToSelection() for (size_t iStr = 0; iStr < (SubElements.size()); ++iStr) { if (SubElements[iStr].find(searchStr) == std::string::npos) { - QString msg = tr("Only one type of selection (vertex,face or edge) per constraint allowed!"); + QString msg = tr( + "Only one type of selection (vertex,face or edge) per constraint allowed!"); QMessageBox::warning(this, tr("Selection error"), msg); addMe = false; break; @@ -174,23 +189,26 @@ void TaskFemConstraintForce::addToSelection() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintForce::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintForce* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -198,12 +216,20 @@ void TaskFemConstraintForce::removeFromSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -215,7 +241,7 @@ void TaskFemConstraintForce::removeFromSelection() SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->listReferences); ui->listReferences->clear(); @@ -229,12 +255,15 @@ void TaskFemConstraintForce::removeFromSelection() void TaskFemConstraintForce::onForceChanged(double f) { - Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintForce* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->Force.setValue(f); } -void TaskFemConstraintForce::onReferenceDeleted() { - TaskFemConstraintForce::removeFromSelection(); //OvG: On right-click face is automatically selected, so just remove +void TaskFemConstraintForce::onReferenceDeleted() +{ + TaskFemConstraintForce::removeFromSelection();// OvG: On right-click face is automatically + // selected, so just remove } std::pair @@ -303,7 +332,8 @@ void TaskFemConstraintForce::onButtonDirection(const bool pressed) try { std::vector direction(1, link.second); - Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintForce* pcConstraint = + static_cast(ConstraintView->getObject()); // update the direction pcConstraint->Direction.setValue(link.first, direction); @@ -318,7 +348,8 @@ void TaskFemConstraintForce::onButtonDirection(const bool pressed) void TaskFemConstraintForce::onCheckReverse(const bool pressed) { - Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintForce* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->Reversed.setValue(pressed); } @@ -363,9 +394,7 @@ bool TaskFemConstraintForce::getReverse() const } TaskFemConstraintForce::~TaskFemConstraintForce() -{ - delete ui; -} +{} bool TaskFemConstraintForce::event(QEvent* e) { @@ -413,27 +442,32 @@ void TaskDlgFemConstraintForce::open() QString msg = QObject::tr("Constraint force"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } bool TaskDlgFemConstraintForce::accept() { std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintForce* parameterForce = static_cast(parameter); + const TaskFemConstraintForce* parameterForce = + static_cast(parameter); try { - //Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "FEM force constraint changed")); + // Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "FEM force constraint changed")); - if (parameterForce->getForce() <= 0) - { - QMessageBox::warning(parameter, tr("Input error"), tr("Please specify a force greater than 0")); + if (parameterForce->getForce() <= 0) { + QMessageBox::warning( + parameter, tr("Input error"), tr("Please specify a force greater than 0")); return false; } - else - { + else { QByteArray num = QByteArray::number(parameterForce->getForce()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Force = %s", name.c_str(), num.data()); + Gui::Command::doCommand( + Gui::Command::Doc, "App.ActiveDocument.%s.Force = %s", name.c_str(), num.data()); } std::string dirname = parameterForce->getDirectionName().data(); @@ -444,16 +478,26 @@ bool TaskDlgFemConstraintForce::accept() QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); buf = buf.arg(QString::fromStdString(dirname)); buf = buf.arg(QString::fromStdString(dirobj)); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Direction = %s", name.c_str(), buf.toStdString().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Direction = %s", + name.c_str(), + buf.toStdString().c_str()); } else { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Direction = None", name.c_str()); + Gui::Command::doCommand( + Gui::Command::Doc, "App.ActiveDocument.%s.Direction = None", name.c_str()); } - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Reversed = %s", name.c_str(), parameterForce->getReverse() ? "True" : "False"); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Reversed = %s", + name.c_str(), + parameterForce->getReverse() ? "True" : "False"); - scale = parameterForce->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + scale = parameterForce->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.h b/src/Mod/Fem/Gui/TaskFemConstraintForce.h index 9c5ca011e6..e48efba508 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.h @@ -24,6 +24,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintForce_H #define GUI_TASKVIEW_TaskFemConstraintForce_H +#include #include #include "TaskFemConstraintOnBoundary.h" @@ -48,7 +49,8 @@ class TaskFemConstraintForce : public TaskFemConstraintOnBoundary Q_OBJECT public: - explicit TaskFemConstraintForce(ViewProviderFemConstraintForce *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintForce(ViewProviderFemConstraintForce* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintForce() override; double getForce() const; const std::string getReferences() const override; @@ -70,11 +72,12 @@ protected: void clearButtons(const SelectionChangeModes notThis) override; private: - std::pair getDirection(const std::vector&) const; + std::pair + getDirection(const std::vector&) const; void updateUI(); private: - Ui_TaskFemConstraintForce* ui; + std::unique_ptr ui; }; /// simulation dialog for the TaskView @@ -89,7 +92,6 @@ public: void open() override; bool accept() override; bool reject() override; - }; } //namespace FemGui diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp index 2becfd32ee..edb13ea0ce 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp @@ -44,17 +44,19 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintHeatflux */ -TaskFemConstraintHeatflux::TaskFemConstraintHeatflux(ViewProviderFemConstraintHeatflux* ConstraintView, QWidget* parent) - : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintHeatflux") +TaskFemConstraintHeatflux::TaskFemConstraintHeatflux( + ViewProviderFemConstraintHeatflux* ConstraintView, QWidget* parent) + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintHeatflux"), + ui(new Ui_TaskFemConstraintHeatflux) { proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintHeatflux(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references createDeleteAction(ui->lw_references); - connect(deleteAction, &QAction::triggered, this, &TaskFemConstraintHeatflux::onReferenceDeleted); + connect(deleteAction, &QAction::triggered, + this, &TaskFemConstraintHeatflux::onReferenceDeleted); connect(ui->rb_convection, &QRadioButton::clicked, this, &TaskFemConstraintHeatflux::Conv); @@ -81,7 +83,8 @@ TaskFemConstraintHeatflux::TaskFemConstraintHeatflux(ViewProviderFemConstraintHe ui->btnRemove->blockSignals(true); // Get the feature data - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintHeatflux* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -96,9 +99,11 @@ TaskFemConstraintHeatflux::TaskFemConstraintHeatflux(ViewProviderFemConstraintHe if (constraint_type == "Convection") { ui->rb_convection->setChecked(1); ui->sw_heatflux->setCurrentIndex(0); - Base::Quantity t = Base::Quantity(pcConstraint->AmbientTemp.getValue(), Base::Unit::Temperature); + Base::Quantity t = + Base::Quantity(pcConstraint->AmbientTemp.getValue(), Base::Unit::Temperature); ui->if_ambienttemp->setValue(t); - Base::Quantity f = Base::Quantity(pcConstraint->FilmCoef.getValue(), Base::Unit::ThermalTransferCoefficient); + Base::Quantity f = Base::Quantity(pcConstraint->FilmCoef.getValue(), + Base::Unit::ThermalTransferCoefficient); ui->if_filmcoef->setValue(f); } else if (constraint_type == "DFlux") { @@ -131,9 +136,7 @@ TaskFemConstraintHeatflux::TaskFemConstraintHeatflux(ViewProviderFemConstraintHe } TaskFemConstraintHeatflux::~TaskFemConstraintHeatflux() -{ - delete ui; -} +{} void TaskFemConstraintHeatflux::updateUI() { @@ -146,34 +149,34 @@ void TaskFemConstraintHeatflux::updateUI() void TaskFemConstraintHeatflux::onAmbientTempChanged(double val) { - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintHeatflux* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->AmbientTemp.setValue(val);//[K] } -/*void TaskFemConstraintHeatflux::onFaceTempChanged(double val) -{ - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); - pcConstraint->FaceTemp.setValue(val); //[K] -}*/ - void TaskFemConstraintHeatflux::onFilmCoefChanged(double val) { - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); - pcConstraint->FilmCoef.setValue(val); // [W]/[[m^2]/[K]] + Fem::ConstraintHeatflux* pcConstraint = + static_cast(ConstraintView->getObject()); + pcConstraint->FilmCoef.setValue(val);// [W]/[[m^2]/[K]] } void TaskFemConstraintHeatflux::onHeatFluxChanged(double val) { - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintHeatflux* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->DFlux.setValue(val); - } void TaskFemConstraintHeatflux::Conv() { - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintHeatflux* pcConstraint = + static_cast(ConstraintView->getObject()); std::string name = ConstraintView->getObject()->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.ConstraintType = %s", name.c_str(), get_constraint_type().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.ConstraintType = %s", + name.c_str(), + get_constraint_type().c_str()); Base::Quantity t = Base::Quantity(300, Base::Unit::Temperature); ui->if_ambienttemp->setValue(t); pcConstraint->AmbientTemp.setValue(300); @@ -185,9 +188,13 @@ void TaskFemConstraintHeatflux::Conv() void TaskFemConstraintHeatflux::Flux() { - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintHeatflux* pcConstraint = + static_cast(ConstraintView->getObject()); std::string name = ConstraintView->getObject()->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.ConstraintType = %s", name.c_str(), get_constraint_type().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.ConstraintType = %s", + name.c_str(), + get_constraint_type().c_str()); Base::Quantity c = Base::Quantity(0, Base::Unit::HeatFlux); ui->if_heatflux->setValue(c); pcConstraint->DFlux.setValue(0); @@ -196,16 +203,19 @@ void TaskFemConstraintHeatflux::Flux() void TaskFemConstraintHeatflux::addToSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintHeatflux* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -216,21 +226,31 @@ void TaskFemConstraintHeatflux::addToSelection() if (!subNames.empty()) { for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) { if (subNames[subIt].substr(0, 4) != "Face") { - QMessageBox::warning(this, tr("Selection error"), tr("Selection must only consist of faces!")); + QMessageBox::warning( + this, tr("Selection error"), tr("Selection must only consist of faces!")); return; } } } else { - //fix me, if an object is selected completely, getSelectionEx does not return any SubElements + // fix me, if an object is selected completely, getSelectionEx does not return any + // SubElements } - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element bool addMe = true; - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } @@ -242,24 +262,27 @@ void TaskFemConstraintHeatflux::addToSelection() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintHeatflux::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintHeatflux* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -270,20 +293,30 @@ void TaskFemConstraintHeatflux::removeFromSelection() if (!subNames.empty()) { for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) { if (subNames[subIt].substr(0, 4) != "Face") { - QMessageBox::warning(this, tr("Selection error"), tr("Selection must only consist of faces!")); + QMessageBox::warning( + this, tr("Selection error"), tr("Selection must only consist of faces!")); return; } } } else { - //fix me, if an object is selected completely, getSelectionEx does not return any SubElements + // fix me, if an object is selected completely, getSelectionEx does not return any + // SubElements } - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -295,7 +328,7 @@ void TaskFemConstraintHeatflux::removeFromSelection() SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->lw_references); ui->lw_references->clear(); @@ -307,7 +340,8 @@ void TaskFemConstraintHeatflux::removeFromSelection() updateUI(); } -void TaskFemConstraintHeatflux::onReferenceDeleted() { +void TaskFemConstraintHeatflux::onReferenceDeleted() +{ TaskFemConstraintHeatflux::removeFromSelection(); } @@ -331,7 +365,8 @@ double TaskFemConstraintHeatflux::getAmbientTemp() const double TaskFemConstraintHeatflux::getFilmCoef() const { Base::Quantity filmcoef = ui->if_filmcoef->getQuantity(); - double filmcoef_in_units = filmcoef.getValueAs(Base::Quantity(1.0, Base::Unit::ThermalTransferCoefficient)); + double filmcoef_in_units = + filmcoef.getValueAs(Base::Quantity(1.0, Base::Unit::ThermalTransferCoefficient)); return filmcoef_in_units; } @@ -375,7 +410,8 @@ void TaskFemConstraintHeatflux::clearButtons(const SelectionChangeModes notThis) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintHeatflux::TaskDlgFemConstraintHeatflux(ViewProviderFemConstraintHeatflux* ConstraintView) +TaskDlgFemConstraintHeatflux::TaskDlgFemConstraintHeatflux( + ViewProviderFemConstraintHeatflux* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -393,27 +429,38 @@ void TaskDlgFemConstraintHeatflux::open() QString msg = QObject::tr("Constraint heat flux"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } bool TaskDlgFemConstraintHeatflux::accept() { std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintHeatflux* parameterHeatflux = static_cast(parameter); + const TaskFemConstraintHeatflux* parameterHeatflux = + static_cast(parameter); std::string scale = "1"; try { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.AmbientTemp = %f", - name.c_str(), parameterHeatflux->getAmbientTemp()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.AmbientTemp = %f", + name.c_str(), + parameterHeatflux->getAmbientTemp()); /*Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.FaceTemp = %f", name.c_str(), parameterHeatflux->getFaceTemp());*/ - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.FilmCoef = %f", - name.c_str(), parameterHeatflux->getFilmCoef()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.FilmCoef = %f", + name.c_str(), + parameterHeatflux->getFilmCoef()); - scale = parameterHeatflux->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", - name.c_str(), scale.c_str()); //OvG: implement modified scale + scale = parameterHeatflux->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h index e5dada8d0d..e83786ea93 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h @@ -26,6 +26,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintHeatflux_H #define GUI_TASKVIEW_TaskFemConstraintHeatflux_H +#include #include #include "TaskFemConstraintOnBoundary.h" @@ -40,7 +41,8 @@ class TaskFemConstraintHeatflux : public TaskFemConstraintOnBoundary Q_OBJECT public: - explicit TaskFemConstraintHeatflux(ViewProviderFemConstraintHeatflux *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintHeatflux(ViewProviderFemConstraintHeatflux* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintHeatflux() override; double getAmbientTemp() const; /*double getFaceTemp(void) const;*/ @@ -66,7 +68,7 @@ protected: private: void updateUI(); - Ui_TaskFemConstraintHeatflux* ui; + std::unique_ptr ui; }; class TaskDlgFemConstraintHeatflux : public TaskDlgFemConstraint diff --git a/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.cpp index 6d1b038c1b..0ca79fe1f6 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.cpp @@ -42,32 +42,33 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintInitialTemperature */ -TaskFemConstraintInitialTemperature::TaskFemConstraintInitialTemperature(ViewProviderFemConstraintInitialTemperature* ConstraintView, QWidget* parent) - : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintInitialTemperature") +TaskFemConstraintInitialTemperature::TaskFemConstraintInitialTemperature( + ViewProviderFemConstraintInitialTemperature* ConstraintView, QWidget* parent) + : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintInitialTemperature"), + ui(new Ui_TaskFemConstraintInitialTemperature) { proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintInitialTemperature(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); this->groupLayout()->addWidget(proxy); // Get the feature data - Fem::ConstraintInitialTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintInitialTemperature* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); // Fill data into dialog elements ui->if_temperature->setMinimum(0); ui->if_temperature->setMaximum(FLOAT_MAX); - Base::Quantity t = Base::Quantity(pcConstraint->initialTemperature.getValue(), Base::Unit::Temperature); + Base::Quantity t = + Base::Quantity(pcConstraint->initialTemperature.getValue(), Base::Unit::Temperature); ui->if_temperature->setValue(t); } TaskFemConstraintInitialTemperature::~TaskFemConstraintInitialTemperature() -{ - delete ui; -} +{} double TaskFemConstraintInitialTemperature::get_temperature() const { @@ -77,14 +78,15 @@ double TaskFemConstraintInitialTemperature::get_temperature() const } void TaskFemConstraintInitialTemperature::changeEvent(QEvent*) -{ -} +{} + //************************************************************************** // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintInitialTemperature::TaskDlgFemConstraintInitialTemperature(ViewProviderFemConstraintInitialTemperature* ConstraintView) +TaskDlgFemConstraintInitialTemperature::TaskDlgFemConstraintInitialTemperature( + ViewProviderFemConstraintInitialTemperature* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -101,21 +103,31 @@ void TaskDlgFemConstraintInitialTemperature::open() QString msg = QObject::tr("Constraint initial temperature"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } bool TaskDlgFemConstraintInitialTemperature::accept() { std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintInitialTemperature* parameterTemperature = static_cast(parameter); + const TaskFemConstraintInitialTemperature* parameterTemperature = + static_cast(parameter); try { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.initialTemperature = %f", - name.c_str(), parameterTemperature->get_temperature()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.initialTemperature = %f", + name.c_str(), + parameterTemperature->get_temperature()); - std::string scale = parameterTemperature->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + std::string scale = parameterTemperature->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.h b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.h index 9bc50b6454..f9200093cc 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.h @@ -26,6 +26,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintInitialTemperature_H #define GUI_TASKVIEW_TaskFemConstraintInitialTemperature_H +#include #include #include "TaskFemConstraint.h" @@ -40,7 +41,8 @@ class TaskFemConstraintInitialTemperature : public TaskFemConstraint Q_OBJECT public: - explicit TaskFemConstraintInitialTemperature(ViewProviderFemConstraintInitialTemperature *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintInitialTemperature( + ViewProviderFemConstraintInitialTemperature* ConstraintView, QWidget* parent = nullptr); ~TaskFemConstraintInitialTemperature() override; double get_temperature()const; @@ -48,10 +50,7 @@ protected: void changeEvent(QEvent *e) override; private: - //void onSelectionChanged(const Gui::SelectionChanges& msg); - void updateUI(); - Ui_TaskFemConstraintInitialTemperature* ui; - + std::unique_ptr ui; }; class TaskDlgFemConstraintInitialTemperature : public TaskDlgFemConstraint @@ -59,7 +58,8 @@ class TaskDlgFemConstraintInitialTemperature : public TaskDlgFemConstraint Q_OBJECT public: - explicit TaskDlgFemConstraintInitialTemperature(ViewProviderFemConstraintInitialTemperature *ConstraintView); + explicit TaskDlgFemConstraintInitialTemperature( + ViewProviderFemConstraintInitialTemperature* ConstraintView); void open() override; bool accept() override; bool reject() override; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp index a88e72eac7..1dc9303e0e 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp @@ -49,28 +49,30 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintPlaneRotation */ -TaskFemConstraintPlaneRotation::TaskFemConstraintPlaneRotation(ViewProviderFemConstraintPlaneRotation* ConstraintView, QWidget* parent) - : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintPlaneRotation") +TaskFemConstraintPlaneRotation::TaskFemConstraintPlaneRotation( + ViewProviderFemConstraintPlaneRotation* ConstraintView, QWidget* parent) + : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintPlaneRotation"), + ui(new Ui_TaskFemConstraintPlaneRotation) { //Note change "planerotation" in line above to new constraint name proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintPlaneRotation(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references createDeleteAction(ui->lw_references); - connect(deleteAction, &QAction::triggered, this, &TaskFemConstraintPlaneRotation::onReferenceDeleted); - + connect(deleteAction, &QAction::triggered, + this, &TaskFemConstraintPlaneRotation::onReferenceDeleted); connect(ui->lw_references, &QListWidget::currentItemChanged, - this, &TaskFemConstraintPlaneRotation::setSelection); + this, &TaskFemConstraintPlaneRotation::setSelection); connect(ui->lw_references, &QListWidget::itemClicked, - this, &TaskFemConstraintPlaneRotation::setSelection); + this, &TaskFemConstraintPlaneRotation::setSelection); this->groupLayout()->addWidget(proxy); /* Note: */ // Get the feature data - Fem::ConstraintPlaneRotation* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintPlaneRotation* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -85,17 +87,17 @@ TaskFemConstraintPlaneRotation::TaskFemConstraintPlaneRotation(ViewProviderFemCo ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); } - //Selection buttons - connect(ui->btnAdd, &QToolButton::clicked, this, &TaskFemConstraintPlaneRotation::addToSelection); - connect(ui->btnRemove, &QToolButton::clicked, this, &TaskFemConstraintPlaneRotation::removeFromSelection); + // Selection buttons + connect(ui->btnAdd, &QToolButton::clicked, + this, &TaskFemConstraintPlaneRotation::addToSelection); + connect(ui->btnRemove, &QToolButton::clicked, + this, &TaskFemConstraintPlaneRotation::removeFromSelection); updateUI(); } TaskFemConstraintPlaneRotation::~TaskFemConstraintPlaneRotation() -{ - delete ui; -} +{} void TaskFemConstraintPlaneRotation::updateUI() { @@ -110,47 +112,65 @@ void TaskFemConstraintPlaneRotation::addToSelection() { int rows = ui->lw_references->model()->rowCount(); if (rows == 1) { - QMessageBox::warning(this, tr("Selection error"), tr("Only one face can be selected for a plane rotation constraint!")); + QMessageBox::warning(this, + tr("Selection error"), + tr("Only one face can be selected for a plane rotation constraint!")); Gui::Selection().clearSelection(); return; } else { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintPlaneRotation* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintPlaneRotation* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); + it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { - QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); + QMessageBox::warning( + this, tr("Selection error"), tr("Selected object is not a part!")); return; } const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); if (subNames.size() == 1) { - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element bool addMe = true; if ((subNames[subIt].substr(0, 4) != "Face")) { - QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only faces can be picked")); return; } Part::Feature* feat = static_cast(obj); TopoDS_Shape ref = feat->Shape.getShape().getSubShape(subNames[subIt].c_str()); if ((subNames[subIt].substr(0, 4) == "Face")) { if (!Fem::Tools::isPlanar(TopoDS::Face(ref))) { - QMessageBox::warning(this, tr("Selection error"), tr("Only planar faces can be picked")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only planar faces can be picked")); return; } } - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection + // that matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old + // list then it was added before so don't add addMe = false; } } @@ -163,11 +183,14 @@ void TaskFemConstraintPlaneRotation::addToSelection() } } else { - QMessageBox::warning(this, tr("Selection error"), tr("Only one face can be selected for a plane rotation constraint!")); + QMessageBox::warning( + this, + tr("Selection error"), + tr("Only one face can be selected for a plane rotation constraint!")); Gui::Selection().clearSelection(); return; } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } @@ -176,16 +199,19 @@ void TaskFemConstraintPlaneRotation::addToSelection() void TaskFemConstraintPlaneRotation::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintPlaneRotation* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintPlaneRotation* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -193,12 +219,20 @@ void TaskFemConstraintPlaneRotation::removeFromSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -210,7 +244,7 @@ void TaskFemConstraintPlaneRotation::removeFromSelection() SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->lw_references); ui->lw_references->clear(); @@ -249,7 +283,8 @@ void TaskFemConstraintPlaneRotation::changeEvent(QEvent*) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintPlaneRotation::TaskDlgFemConstraintPlaneRotation(ViewProviderFemConstraintPlaneRotation* ConstraintView) +TaskDlgFemConstraintPlaneRotation::TaskDlgFemConstraintPlaneRotation( + ViewProviderFemConstraintPlaneRotation* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -267,16 +302,24 @@ void TaskDlgFemConstraintPlaneRotation::open() QString msg = QObject::tr("Constraint planerotation"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } bool TaskDlgFemConstraintPlaneRotation::accept() { std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintPlaneRotation* parameters = static_cast(parameter); - std::string scale = parameters->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + const TaskFemConstraintPlaneRotation* parameters = + static_cast(parameter); + std::string scale = parameters->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale return TaskDlgFemConstraint::accept(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.h b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.h index d324507e6d..1ad2707fcb 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.h @@ -26,6 +26,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintPlaneRotation_H #define GUI_TASKVIEW_TaskFemConstraintPlaneRotation_H +#include #include #include "TaskFemConstraint.h" @@ -40,7 +41,8 @@ class TaskFemConstraintPlaneRotation : public TaskFemConstraint Q_OBJECT public: - explicit TaskFemConstraintPlaneRotation(ViewProviderFemConstraintPlaneRotation *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintPlaneRotation(ViewProviderFemConstraintPlaneRotation* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintPlaneRotation() override; const std::string getReferences() const override; @@ -55,8 +57,7 @@ protected: private: void updateUI(); - Ui_TaskFemConstraintPlaneRotation* ui; - + std::unique_ptr ui; }; class TaskDlgFemConstraintPlaneRotation : public TaskDlgFemConstraint @@ -64,7 +65,8 @@ class TaskDlgFemConstraintPlaneRotation : public TaskDlgFemConstraint Q_OBJECT public: - explicit TaskDlgFemConstraintPlaneRotation(ViewProviderFemConstraintPlaneRotation *ConstraintView); + explicit TaskDlgFemConstraintPlaneRotation( + ViewProviderFemConstraintPlaneRotation* ConstraintView); void open() override; bool accept() override; bool reject() override; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp index 6010302d15..36088495cd 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -42,18 +42,19 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintPressure */ -TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPressure* ConstraintView, QWidget* parent) - : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintPressure") +TaskFemConstraintPressure::TaskFemConstraintPressure( + ViewProviderFemConstraintPressure* ConstraintView, QWidget* parent) + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintPressure"), + ui(new Ui_TaskFemConstraintPressure) { //Note change "pressure" in line above to new constraint name proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintPressure(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references createDeleteAction(ui->lw_references); - connect(deleteAction, &QAction::triggered, this, &TaskFemConstraintPressure::onReferenceDeleted); - + connect(deleteAction, &QAction::triggered, + this, &TaskFemConstraintPressure::onReferenceDeleted); connect(ui->lw_references, &QListWidget::currentItemChanged, this, &TaskFemConstraintPressure::setSelection); connect(ui->lw_references, &QListWidget::itemClicked, @@ -66,7 +67,8 @@ TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPr /* Note: */ // Get the feature data - Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintPressure* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -74,7 +76,8 @@ TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPr // Fill data into dialog elements ui->if_pressure->setMinimum(0); ui->if_pressure->setMaximum(FLOAT_MAX); - Base::Quantity p = Base::Quantity(1000 * (pcConstraint->Pressure.getValue()), Base::Unit::Stress); + Base::Quantity p = + Base::Quantity(1000 * (pcConstraint->Pressure.getValue()), Base::Unit::Stress); ui->if_pressure->setValue(p); bool reversed = pcConstraint->Reversed.getValue(); ui->checkBoxReverse->setChecked(reversed); @@ -96,9 +99,7 @@ TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPr } TaskFemConstraintPressure::~TaskFemConstraintPressure() -{ - delete ui; -} +{} void TaskFemConstraintPressure::updateUI() { @@ -111,22 +112,26 @@ void TaskFemConstraintPressure::updateUI() void TaskFemConstraintPressure::onCheckReverse(const bool pressed) { - Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintPressure* pcConstraint = + static_cast(ConstraintView->getObject()); pcConstraint->Reversed.setValue(pressed); } void TaskFemConstraintPressure::addToSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintPressure* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -134,17 +139,25 @@ void TaskFemConstraintPressure::addToSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element bool addMe = true; if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } @@ -156,23 +169,26 @@ void TaskFemConstraintPressure::addToSelection() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintPressure::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintPressure* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -180,12 +196,20 @@ void TaskFemConstraintPressure::removeFromSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -197,7 +221,7 @@ void TaskFemConstraintPressure::removeFromSelection() SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->lw_references); ui->lw_references->clear(); @@ -257,7 +281,8 @@ void TaskFemConstraintPressure::clearButtons(const SelectionChangeModes notThis) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintPressure::TaskDlgFemConstraintPressure(ViewProviderFemConstraintPressure* ConstraintView) +TaskDlgFemConstraintPressure::TaskDlgFemConstraintPressure( + ViewProviderFemConstraintPressure* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -275,7 +300,11 @@ void TaskDlgFemConstraintPressure::open() QString msg = QObject::tr("Constraint pressure"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } @@ -283,15 +312,23 @@ bool TaskDlgFemConstraintPressure::accept() { /* Note: */ std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintPressure* parameterPressure = static_cast(parameter); + const TaskFemConstraintPressure* parameterPressure = + static_cast(parameter); try { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Pressure = %f", - name.c_str(), parameterPressure->get_Pressure()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Reversed = %s", - name.c_str(), parameterPressure->get_Reverse() ? "True" : "False"); - std::string scale = parameterPressure->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Pressure = %f", + name.c_str(), + parameterPressure->get_Pressure()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Reversed = %s", + name.c_str(), + parameterPressure->get_Reverse() ? "True" : "False"); + std::string scale = parameterPressure->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.h b/src/Mod/Fem/Gui/TaskFemConstraintPressure.h index b1bf50b411..fd27a34fa0 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.h @@ -26,6 +26,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintPressure_H #define GUI_TASKVIEW_TaskFemConstraintPressure_H +#include #include #include "TaskFemConstraintOnBoundary.h" @@ -40,7 +41,8 @@ class TaskFemConstraintPressure : public TaskFemConstraintOnBoundary Q_OBJECT public: - explicit TaskFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintPressure(ViewProviderFemConstraintPressure* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintPressure() override; const std::string getReferences() const override; double get_Pressure()const; @@ -59,8 +61,7 @@ protected: private: void updateUI(); - Ui_TaskFemConstraintPressure* ui; - + std::unique_ptr ui; }; class TaskDlgFemConstraintPressure : public TaskDlgFemConstraint diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp index aea6b0b88e..87da58045b 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp @@ -42,11 +42,12 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintSpring */ -TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring* ConstraintView, QWidget* parent) - : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintSpring") +TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring* ConstraintView, + QWidget* parent) + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintSpring"), + ui(new Ui_TaskFemConstraintSpring) { proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintSpring(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -63,21 +64,26 @@ TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring /* Note: */ // Get the feature data - Fem::ConstraintSpring* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintSpring* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); // Fill data into dialog elements - ui->if_norm->setMinimum(0); // TODO fix this ------------------------------------------------------------------- + ui->if_norm->setMinimum( + 0);// TODO fix this ------------------------------------------------------------------- ui->if_norm->setMaximum(FLOAT_MAX); - Base::Quantity ns = Base::Quantity((pcConstraint->normalStiffness.getValue()), Base::Unit::Stiffness); + Base::Quantity ns = + Base::Quantity((pcConstraint->normalStiffness.getValue()), Base::Unit::Stiffness); ui->if_norm->setValue(ns); // Fill data into dialog elements - ui->if_tan->setMinimum(0); // TODO fix this ------------------------------------------------------------------- + ui->if_tan->setMinimum( + 0);// TODO fix this ------------------------------------------------------------------- ui->if_tan->setMaximum(FLOAT_MAX); - Base::Quantity ts = Base::Quantity((pcConstraint->tangentialStiffness.getValue()), Base::Unit::Stiffness); + Base::Quantity ts = + Base::Quantity((pcConstraint->tangentialStiffness.getValue()), Base::Unit::Stiffness); ui->if_tan->setValue(ts); /* */ @@ -98,9 +104,7 @@ TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring } TaskFemConstraintSpring::~TaskFemConstraintSpring() -{ - delete ui; -} +{} void TaskFemConstraintSpring::updateUI() { @@ -111,19 +115,21 @@ void TaskFemConstraintSpring::updateUI() } } - void TaskFemConstraintSpring::addToSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintSpring* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintSpring* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -131,17 +137,25 @@ void TaskFemConstraintSpring::addToSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element bool addMe = true; if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } @@ -153,23 +167,26 @@ void TaskFemConstraintSpring::addToSelection() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintSpring::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintSpring* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintSpring* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -177,12 +194,20 @@ void TaskFemConstraintSpring::removeFromSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -194,7 +219,7 @@ void TaskFemConstraintSpring::removeFromSelection() SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->lw_references); ui->lw_references->clear(); @@ -257,7 +282,8 @@ void TaskFemConstraintSpring::clearButtons(const SelectionChangeModes notThis) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintSpring::TaskDlgFemConstraintSpring(ViewProviderFemConstraintSpring* ConstraintView) +TaskDlgFemConstraintSpring::TaskDlgFemConstraintSpring( + ViewProviderFemConstraintSpring* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -275,7 +301,11 @@ void TaskDlgFemConstraintSpring::open() QString msg = QObject::tr("Constraint spring"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } @@ -283,16 +313,25 @@ bool TaskDlgFemConstraintSpring::accept() { /* Note: */ std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintSpring* parameterStiffness = static_cast(parameter); - //const TaskFemConstraintSpring* parameterTan = static_cast(parameter); + const TaskFemConstraintSpring* parameterStiffness = + static_cast(parameter); + // const TaskFemConstraintSpring* parameterTan = static_cast(parameter); try { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.normalStiffness = %f", - name.c_str(), parameterStiffness->get_normalStiffness()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.tangentialStiffness = %f", - name.c_str(), parameterStiffness->get_tangentialStiffness()); - std::string scale = parameterStiffness->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.normalStiffness = %f", + name.c_str(), + parameterStiffness->get_normalStiffness()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.tangentialStiffness = %f", + name.c_str(), + parameterStiffness->get_tangentialStiffness()); + std::string scale = parameterStiffness->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.h b/src/Mod/Fem/Gui/TaskFemConstraintSpring.h index 62da3938ca..e26975de28 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintSpring.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.h @@ -24,6 +24,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintSpring_H #define GUI_TASKVIEW_TaskFemConstraintSpring_H +#include #include #include "TaskFemConstraintOnBoundary.h" @@ -38,7 +39,8 @@ class TaskFemConstraintSpring : public TaskFemConstraintOnBoundary Q_OBJECT public: - explicit TaskFemConstraintSpring(ViewProviderFemConstraintSpring *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintSpring(ViewProviderFemConstraintSpring* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintSpring() override; const std::string getReferences() const override; double get_normalStiffness()const; @@ -56,8 +58,7 @@ protected: private: void updateUI(); - Ui_TaskFemConstraintSpring* ui; - + std::unique_ptr ui; }; class TaskDlgFemConstraintSpring : public TaskDlgFemConstraint diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp index e839b01a64..258f0b5c6b 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -45,11 +45,12 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintTemperature */ -TaskFemConstraintTemperature::TaskFemConstraintTemperature(ViewProviderFemConstraintTemperature* ConstraintView, QWidget* parent) - : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintTemperature") +TaskFemConstraintTemperature::TaskFemConstraintTemperature( + ViewProviderFemConstraintTemperature* ConstraintView, QWidget* parent) + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintTemperature"), + ui(new Ui_TaskFemConstraintTemperature) { proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintTemperature(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -73,7 +74,8 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature(ViewProviderFemConstr this->groupLayout()->addWidget(proxy); // Get the feature data - Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTemperature* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -88,7 +90,8 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature(ViewProviderFemConstr std::string str = "Temperature"; QString qstr = QString::fromStdString(str); ui->lbl_type->setText(qstr); - Base::Quantity t = Base::Quantity(pcConstraint->Temperature.getValue(), Base::Unit::Temperature); + Base::Quantity t = + Base::Quantity(pcConstraint->Temperature.getValue(), Base::Unit::Temperature); ui->if_temperature->setValue(t); } else if (constraint_type == "CFlux") { @@ -116,9 +119,7 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature(ViewProviderFemConstr } TaskFemConstraintTemperature::~TaskFemConstraintTemperature() -{ - delete ui; -} +{} void TaskFemConstraintTemperature::updateUI() { @@ -131,7 +132,8 @@ void TaskFemConstraintTemperature::updateUI() void TaskFemConstraintTemperature::onTempCfluxChanged(double val) { - Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTemperature* pcConstraint = + static_cast(ConstraintView->getObject()); if (ui->rb_temperature->isChecked()) { pcConstraint->Temperature.setValue(val); } @@ -142,9 +144,13 @@ void TaskFemConstraintTemperature::onTempCfluxChanged(double val) void TaskFemConstraintTemperature::Temp() { - Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTemperature* pcConstraint = + static_cast(ConstraintView->getObject()); std::string name = ConstraintView->getObject()->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.ConstraintType = %s", name.c_str(), get_constraint_type().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.ConstraintType = %s", + name.c_str(), + get_constraint_type().c_str()); std::string str = "Temperature"; QString qstr = QString::fromStdString(str); ui->lbl_type->setText(qstr); @@ -155,9 +161,13 @@ void TaskFemConstraintTemperature::Temp() void TaskFemConstraintTemperature::Flux() { - Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTemperature* pcConstraint = + static_cast(ConstraintView->getObject()); std::string name = ConstraintView->getObject()->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.ConstraintType = %s", name.c_str(), get_constraint_type().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.ConstraintType = %s", + name.c_str(), + get_constraint_type().c_str()); std::string str = "Concentrated heat flux"; QString qstr = QString::fromStdString(str); ui->lbl_type->setText(qstr); @@ -168,29 +178,41 @@ void TaskFemConstraintTemperature::Flux() void TaskFemConstraintTemperature::addToSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTemperature* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } std::vector subNames = it->getSubNames(); - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + App::DocumentObject* obj = + ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element bool addMe = true; - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } @@ -202,23 +224,26 @@ void TaskFemConstraintTemperature::addToSelection() } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintTemperature::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTemperature* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -226,12 +251,20 @@ void TaskFemConstraintTemperature::removeFromSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -243,7 +276,7 @@ void TaskFemConstraintTemperature::removeFromSelection() SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->lw_references); ui->lw_references->clear(); @@ -319,7 +352,8 @@ void TaskFemConstraintTemperature::clearButtons(const SelectionChangeModes notTh // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintTemperature::TaskDlgFemConstraintTemperature(ViewProviderFemConstraintTemperature* ConstraintView) +TaskDlgFemConstraintTemperature::TaskDlgFemConstraintTemperature( + ViewProviderFemConstraintTemperature* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -337,18 +371,26 @@ void TaskDlgFemConstraintTemperature::open() QString msg = QObject::tr("Constraint temperature"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } bool TaskDlgFemConstraintTemperature::accept() { std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintTemperature* parameterTemperature = static_cast(parameter); + const TaskFemConstraintTemperature* parameterTemperature = + static_cast(parameter); try { - std::string scale = parameterTemperature->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + std::string scale = parameterTemperature->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h index 6c176f7d4d..291d35c6e7 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h @@ -26,6 +26,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintTemperature_H #define GUI_TASKVIEW_TaskFemConstraintTemperature_H +#include #include #include @@ -65,8 +66,7 @@ protected: private: void updateUI(); - Ui_TaskFemConstraintTemperature* ui; - + std::unique_ptr ui; }; class TaskDlgFemConstraintTemperature : public TaskDlgFemConstraint diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp index d8615e273e..c61c6ee8da 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp @@ -48,17 +48,19 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintTransform */ -TaskFemConstraintTransform::TaskFemConstraintTransform(ViewProviderFemConstraintTransform* ConstraintView, QWidget* parent) - : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintTransform") +TaskFemConstraintTransform::TaskFemConstraintTransform( + ViewProviderFemConstraintTransform* ConstraintView, QWidget* parent) + : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintTransform"), + ui(new Ui_TaskFemConstraintTransform) { proxy = new QWidget(this); - ui = new Ui_TaskFemConstraintTransform(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); // create a context menu for the listview of the references createDeleteAction(ui->lw_Rect); - connect(deleteAction, &QAction::triggered, this, &TaskFemConstraintTransform::onReferenceDeleted); + connect(deleteAction, &QAction::triggered, + this, &TaskFemConstraintTransform::onReferenceDeleted); // highlight seletcted list items in the model connect(ui->lw_Rect, &QListWidget::currentItemChanged, @@ -83,7 +85,8 @@ TaskFemConstraintTransform::TaskFemConstraintTransform(ViewProviderFemConstraint this, &TaskFemConstraintTransform::z_Changed); // Get the feature data - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTransform* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -106,8 +109,12 @@ TaskFemConstraintTransform::TaskFemConstraintTransform(ViewProviderFemConstraint ui->lw_Rect->clear(); - //Transformable surfaces - Gui::Command::doCommand(Gui::Command::Doc, TaskFemConstraintTransform::getSurfaceReferences((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); + // Transformable surfaces + Gui::Command::doCommand( + Gui::Command::Doc, + TaskFemConstraintTransform::getSurfaceReferences( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str()); std::vector ObjDispl = pcConstraint->RefDispl.getValues(); std::vector SubElemDispl = pcConstraint->RefDispl.getSubValues(); @@ -130,26 +137,31 @@ TaskFemConstraintTransform::TaskFemConstraintTransform(ViewProviderFemConstraint int p = 0; for (std::size_t i = 0; i < ObjDispl.size(); i++) { for (std::size_t j = 0; j < Objects.size(); j++) { - if ((makeRefText(ObjDispl[i], SubElemDispl[i])) == (makeRefText(Objects[j], SubElements[j]))) { + if ((makeRefText(ObjDispl[i], SubElemDispl[i])) + == (makeRefText(Objects[j], SubElements[j]))) { p++; } } } - //Selection buttons + // Selection buttons connect(ui->btnAdd, &QToolButton::clicked, this, &TaskFemConstraintTransform::addToSelection); - connect(ui->btnRemove, &QToolButton::clicked, this, &TaskFemConstraintTransform::removeFromSelection); + connect(ui->btnRemove, + &QToolButton::clicked, + this, + &TaskFemConstraintTransform::removeFromSelection); updateUI(); if ((p == 0) && (!Objects.empty())) { - QMessageBox::warning(this, tr("Constraint update error"), tr("The transformable faces have changed. Please add only the transformable faces and remove non-transformable faces!")); + QMessageBox::warning(this, + tr("Constraint update error"), + tr("The transformable faces have changed. Please add only the " + "transformable faces and remove non-transformable faces!")); return; } } TaskFemConstraintTransform::~TaskFemConstraintTransform() -{ - delete ui; -} +{} const QString TaskFemConstraintTransform::makeText(const App::DocumentObject* obj) const { @@ -165,8 +177,10 @@ void TaskFemConstraintTransform::updateUI() } } -void TaskFemConstraintTransform::x_Changed(int i) { - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); +void TaskFemConstraintTransform::x_Changed(int i) +{ + Fem::ConstraintTransform* pcConstraint = + static_cast(ConstraintView->getObject()); double x = i; pcConstraint->X_rot.setValue(x); std::string name = ConstraintView->getObject()->getNameInDocument(); @@ -176,8 +190,10 @@ void TaskFemConstraintTransform::x_Changed(int i) { pcConstraint->References.setValues(Objects, SubElements); } -void TaskFemConstraintTransform::y_Changed(int i) { - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); +void TaskFemConstraintTransform::y_Changed(int i) +{ + Fem::ConstraintTransform* pcConstraint = + static_cast(ConstraintView->getObject()); double y = i; pcConstraint->Y_rot.setValue(y); std::string name = ConstraintView->getObject()->getNameInDocument(); @@ -187,8 +203,10 @@ void TaskFemConstraintTransform::y_Changed(int i) { pcConstraint->References.setValues(Objects, SubElements); } -void TaskFemConstraintTransform::z_Changed(int i) { - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); +void TaskFemConstraintTransform::z_Changed(int i) +{ + Fem::ConstraintTransform* pcConstraint = + static_cast(ConstraintView->getObject()); double z = i; pcConstraint->Z_rot.setValue(z); std::string name = ConstraintView->getObject()->getNameInDocument(); @@ -198,11 +216,16 @@ void TaskFemConstraintTransform::z_Changed(int i) { pcConstraint->References.setValues(Objects, SubElements); } -void TaskFemConstraintTransform::Rect() { +void TaskFemConstraintTransform::Rect() +{ ui->sw_transform->setCurrentIndex(0); std::string name = ConstraintView->getObject()->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.TransformType = %s", name.c_str(), get_transform_type().c_str()); - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.TransformType = %s", + name.c_str(), + get_transform_type().c_str()); + Fem::ConstraintTransform* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); if (!Objects.empty()) { setSelection(ui->lw_Rect->item(0)); @@ -210,14 +233,19 @@ void TaskFemConstraintTransform::Rect() { } } -void TaskFemConstraintTransform::Cyl() { +void TaskFemConstraintTransform::Cyl() +{ ui->sw_transform->setCurrentIndex(1); ui->sp_X->setValue(0); ui->sp_Y->setValue(0); ui->sp_Z->setValue(0); std::string name = ConstraintView->getObject()->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.TransformType = %s", name.c_str(), get_transform_type().c_str()); - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.TransformType = %s", + name.c_str(), + get_transform_type().c_str()); + Fem::ConstraintTransform* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); if (!Objects.empty()) { setSelection(ui->lw_Rect->item(0)); @@ -225,35 +253,39 @@ void TaskFemConstraintTransform::Cyl() { } } - void TaskFemConstraintTransform::addToSelection() { int rows = ui->lw_Rect->model()->rowCount(); - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } if (rows == 1) { - QMessageBox::warning(this, tr("Selection error"), tr("Only one face for rectangular transform constraint!")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only one face for rectangular transform constraint!")); Gui::Selection().clearSelection(); return; } if ((rows == 0) && (selection.size() >= 2)) { - QMessageBox::warning(this, tr("Selection error"), tr("Only one face for rectangular transform constraint!")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only one face for rectangular transform constraint!")); Gui::Selection().clearSelection(); return; } - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTransform* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector ObjDispl = pcConstraint->RefDispl.getValues(); std::vector SubElemDispl = pcConstraint->RefDispl.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -261,11 +293,13 @@ void TaskFemConstraintTransform::addToSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); if (subNames.size() != 1) { - QMessageBox::warning(this, tr("Selection error"), tr("Only one face for transform constraint!")); + QMessageBox::warning( + this, tr("Selection error"), tr("Only one face for transform constraint!")); Gui::Selection().clearSelection(); return; } - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element bool addMe = true; if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); @@ -277,40 +311,58 @@ void TaskFemConstraintTransform::addToSelection() TopoDS_Shape ref = feat->Shape.getShape().getSubShape(subNames[subIt].c_str()); BRepAdaptor_Surface surface(TopoDS::Face(ref)); if (surface.GetType() != GeomAbs_Cylinder) { - QMessageBox::warning(this, tr("Selection error"), tr("Only cylindrical faces can be picked")); + QMessageBox::warning(this, + tr("Selection error"), + tr("Only cylindrical faces can be picked")); return; } } } - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so don't add addMe = false; } } if (addMe) { - disconnect(ui->lw_Rect, &QListWidget::currentItemChanged, - this, &TaskFemConstraintTransform::setSelection); + disconnect(ui->lw_Rect, + &QListWidget::currentItemChanged, + this, + &TaskFemConstraintTransform::setSelection); for (std::size_t i = 0; i < ObjDispl.size(); i++) { - if ((makeRefText(ObjDispl[i], SubElemDispl[i])) == (makeRefText(obj, subNames[subIt]))) { + if ((makeRefText(ObjDispl[i], SubElemDispl[i])) + == (makeRefText(obj, subNames[subIt]))) { Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_Rect->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_Rect, &QListWidget::currentItemChanged, - this, &TaskFemConstraintTransform::setSelection); + connect(ui->lw_Rect, + &QListWidget::currentItemChanged, + this, + &TaskFemConstraintTransform::setSelection); } } if (Objects.empty()) { - QMessageBox::warning(this, tr("Selection error"), tr("Only transformable faces can be selected! Apply displacement constraint to surface first then apply constraint to surface")); + QMessageBox::warning( + this, + tr("Selection error"), + tr("Only transformable faces can be selected! Apply displacement " + "constraint to surface first then apply constraint to surface")); Gui::Selection().clearSelection(); return; } } } } - //Update UI + // Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); if (ui->rb_rect->isChecked()) { @@ -318,9 +370,9 @@ void TaskFemConstraintTransform::addToSelection() double n = normal.x; double m = normal.y; double l = normal.z; - //about Z-axis + // about Z-axis double about_z; - double mag_norm_z = sqrt(n * n + m * m); //normal vector mapped onto XY plane + double mag_norm_z = sqrt(n * n + m * m);// normal vector mapped onto XY plane if (mag_norm_z == 0) { about_z = 0; } @@ -330,17 +382,17 @@ void TaskFemConstraintTransform::addToSelection() if (n > 0) { about_z = about_z * (-1); } - //rotation to ZY plane + // rotation to ZY plane double m_p = n * sin(about_z * M_PI / 180) + m * cos(about_z * M_PI / 180); double l_p = l; - //about X-axis + // about X-axis double about_x; double mag_norm_x = sqrt(m_p * m_p + l_p * l_p); if (mag_norm_x == 0) { about_x = 0; } else { - about_x = -(acos(l_p / mag_norm_x) * 180 / M_PI); //rotation to the Z axis + about_x = -(acos(l_p / mag_norm_x) * 180 / M_PI);// rotation to the Z axis } ui->sp_X->setValue(round(about_x)); ui->sp_Z->setValue(round(about_z)); @@ -349,16 +401,19 @@ void TaskFemConstraintTransform::addToSelection() void TaskFemConstraintTransform::removeFromSelection() { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + std::vector selection = + Gui::Selection().getSelectionEx();// gets vector of selected objects of active document if (selection.empty()) { QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); + Fem::ConstraintTransform* pcConstraint = + static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object + for (std::vector::iterator it = selection.begin(); it != selection.end(); + ++it) {// for every selected object if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; @@ -366,12 +421,20 @@ void TaskFemConstraintTransform::removeFromSelection() const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); - for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element - for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); - itr != SubElements.end(); - itr = std::find(++itr, SubElements.end(), subNames[subIt])) - {// for every sub element in selection that matches one in old list - if (obj == Objects[std::distance(SubElements.begin(), itr)]) {//if selected sub element's object equals the one in old list then it was added before so mark for deletion + for (size_t subIt = 0; subIt < (subNames.size()); + ++subIt) {// for every selected sub element + for (std::vector::iterator itr = + std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, + SubElements.end(), + subNames[subIt])) {// for every sub element in selection that + // matches one in old list + if (obj + == Objects[std::distance( + SubElements.begin(), + itr)]) {// if selected sub element's object equals the one in old list then + // it was added before so mark for deletion itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } @@ -383,7 +446,7 @@ void TaskFemConstraintTransform::removeFromSelection() SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI + // Update UI { QSignalBlocker block(ui->lw_Rect); ui->lw_Rect->clear(); @@ -472,7 +535,8 @@ void TaskFemConstraintTransform::changeEvent(QEvent*) { // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFemConstraintTransform::TaskDlgFemConstraintTransform(ViewProviderFemConstraintTransform* ConstraintView) +TaskDlgFemConstraintTransform::TaskDlgFemConstraintTransform( + ViewProviderFemConstraintTransform* ConstraintView) { this->ConstraintView = ConstraintView; assert(ConstraintView); @@ -490,7 +554,11 @@ void TaskDlgFemConstraintTransform::open() QString msg = QObject::tr("Constraint transform"); Gui::Command::openCommand((const char*)msg.toUtf8()); ConstraintView->setVisible(true); - Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + Gui::Command::doCommand( + Gui::Command::Doc, + ViewProviderFemConstraint::gethideMeshShowPartStr( + (static_cast(ConstraintView->getObject()))->getNameInDocument()) + .c_str());// OvG: Hide meshes and show parts } } @@ -498,20 +566,31 @@ bool TaskDlgFemConstraintTransform::accept() { /* Note: */ std::string name = ConstraintView->getObject()->getNameInDocument(); - const TaskFemConstraintTransform* parameters = static_cast(parameter); + const TaskFemConstraintTransform* parameters = + static_cast(parameter); try { - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.X_rot = %f", - name.c_str(), parameters->get_X_rot()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Y_rot = %f", - name.c_str(), parameters->get_Y_rot()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Z_rot = %f", - name.c_str(), parameters->get_Z_rot()); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.TransformType = %s", - name.c_str(), parameters->get_transform_type().c_str()); - std::string scale = parameters->getScale(); //OvG: determine modified scale - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale - + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.X_rot = %f", + name.c_str(), + parameters->get_X_rot()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Y_rot = %f", + name.c_str(), + parameters->get_Y_rot()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Z_rot = %f", + name.c_str(), + parameters->get_Z_rot()); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.TransformType = %s", + name.c_str(), + parameters->get_transform_type().c_str()); + std::string scale = parameters->getScale();// OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Scale = %s", + name.c_str(), + scale.c_str());// OvG: implement modified scale } catch (const Base::Exception& e) { QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTransform.h b/src/Mod/Fem/Gui/TaskFemConstraintTransform.h index 0e35bc2cc5..837c675381 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.h @@ -27,6 +27,7 @@ #ifndef GUI_TASKVIEW_TaskFemConstraintTransform_H #define GUI_TASKVIEW_TaskFemConstraintTransform_H +#include #include #include "TaskFemConstraint.h" @@ -41,7 +42,8 @@ class TaskFemConstraintTransform : public TaskFemConstraint Q_OBJECT public: - explicit TaskFemConstraintTransform(ViewProviderFemConstraintTransform *ConstraintView,QWidget *parent = nullptr); + explicit TaskFemConstraintTransform(ViewProviderFemConstraintTransform* ConstraintView, + QWidget* parent = nullptr); ~TaskFemConstraintTransform() override; const std::string getReferences() const override; double get_X_rot()const; @@ -67,7 +69,7 @@ protected: private: void updateUI(); - Ui_TaskFemConstraintTransform* ui; + std::unique_ptr ui; }; class TaskDlgFemConstraintTransform : public TaskDlgFemConstraint diff --git a/src/Mod/Fem/Gui/TaskObjectName.cpp b/src/Mod/Fem/Gui/TaskObjectName.cpp index b1bd31493a..54f22d1ab2 100644 --- a/src/Mod/Fem/Gui/TaskObjectName.cpp +++ b/src/Mod/Fem/Gui/TaskObjectName.cpp @@ -42,11 +42,11 @@ TaskObjectName::TaskObjectName(App::DocumentObject *pcObject,QWidget *parent) tr("TaskObjectName"), true, parent), - pcObject(pcObject) + pcObject(pcObject), + ui(new Ui_TaskObjectName) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskObjectName(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -62,19 +62,14 @@ TaskObjectName::TaskObjectName(App::DocumentObject *pcObject,QWidget *parent) } - void TaskObjectName::TextChanged (const QString & text) { name = text.toUtf8().constData(); //pcObject->Label.setValue(text.toUtf8()); } - - TaskObjectName::~TaskObjectName() -{ - delete ui; -} +{} #include "moc_TaskObjectName.cpp" diff --git a/src/Mod/Fem/Gui/TaskObjectName.h b/src/Mod/Fem/Gui/TaskObjectName.h index 181dbdd1c1..c812798745 100644 --- a/src/Mod/Fem/Gui/TaskObjectName.h +++ b/src/Mod/Fem/Gui/TaskObjectName.h @@ -62,7 +62,7 @@ private: private: QWidget* proxy; - Ui_TaskObjectName* ui; + std::unique_ptr ui; }; } //namespace FemGui diff --git a/src/Mod/Fem/Gui/TaskTetParameter.cpp b/src/Mod/Fem/Gui/TaskTetParameter.cpp index 2854612b4a..89e9ed4c70 100644 --- a/src/Mod/Fem/Gui/TaskTetParameter.cpp +++ b/src/Mod/Fem/Gui/TaskTetParameter.cpp @@ -36,16 +36,13 @@ using namespace FemGui; using namespace Gui; -TaskTetParameter::TaskTetParameter(Fem::FemMeshShapeNetgenObject *pcObject,QWidget *parent) - : TaskBox(Gui::BitmapFactory().pixmap("FEM_CreateNodesSet"), - tr("Tet Parameter"), - true, - parent), - pcObject(pcObject) +TaskTetParameter::TaskTetParameter(Fem::FemMeshShapeNetgenObject* pcObject, QWidget* parent) + : TaskBox(Gui::BitmapFactory().pixmap("FEM_CreateNodesSet"), tr("Tet Parameter"), true, parent), + pcObject(pcObject), + ui(new Ui_TaskTetParameter) { // we need a separate container widget to add all controls to proxy = new QWidget(this); - ui = new Ui_TaskTetParameter(); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); @@ -83,9 +80,7 @@ TaskTetParameter::TaskTetParameter(Fem::FemMeshShapeNetgenObject *pcObject,QWidg } TaskTetParameter::~TaskTetParameter() -{ - delete ui; -} +{} void TaskTetParameter::SwitchMethod(int Value) { diff --git a/src/Mod/Fem/Gui/TaskTetParameter.h b/src/Mod/Fem/Gui/TaskTetParameter.h index 11fe5c45a0..9de4878727 100644 --- a/src/Mod/Fem/Gui/TaskTetParameter.h +++ b/src/Mod/Fem/Gui/TaskTetParameter.h @@ -75,7 +75,7 @@ protected: private: QWidget* proxy; - Ui_TaskTetParameter* ui; + std::unique_ptr ui; }; } //namespace FemGui diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp index a4a0e1b089..633f4df6a6 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp @@ -71,7 +71,8 @@ void FunctionWidget::setViewProvider(ViewProviderFemPostFunction* view) { m_view = view; m_object = static_cast(view->getObject()); - m_connection = m_object->getDocument()->signalChangedObject.connect(boost::bind(&FunctionWidget::onObjectsChanged, this, bp::_1, bp::_2)); + m_connection = m_object->getDocument()->signalChangedObject.connect( + boost::bind(&FunctionWidget::onObjectsChanged, this, bp::_1, bp::_2)); } void FunctionWidget::onObjectsChanged(const App::DocumentObject& obj, const App::Property& p) { @@ -119,13 +120,14 @@ void ViewProviderFemPostFunctionProvider::updateData(const App::Property* prop) void ViewProviderFemPostFunctionProvider::updateSize() { - std::vector< App::DocumentObject* > vec = claimChildren(); - for (std::vector< App::DocumentObject* >::iterator it = vec.begin(); it != vec.end(); ++it) { + std::vector vec = claimChildren(); + for (std::vector::iterator it = vec.begin(); it != vec.end(); ++it) { if (!(*it)->isDerivedFrom(Fem::FemPostFunction::getClassTypeId())) continue; - ViewProviderFemPostFunction* vp = static_cast(Gui::Application::Instance->getViewProvider(*it)); + ViewProviderFemPostFunction* vp = static_cast( + Gui::Application::Instance->getViewProvider(*it)); vp->AutoScaleFactorX.setValue(SizeX.getValue()); vp->AutoScaleFactorY.setValue(SizeY.getValue()); vp->AutoScaleFactorZ.setValue(SizeZ.getValue()); @@ -157,13 +159,16 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemPostFunction, Gui::ViewProviderDocumentOb ViewProviderFemPostFunction::ViewProviderFemPostFunction() : m_manip(nullptr), m_autoscale(false), m_isDragging(false), m_autoRecompute(false) { - ADD_PROPERTY_TYPE(AutoScaleFactorX, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); - ADD_PROPERTY_TYPE(AutoScaleFactorY, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); - ADD_PROPERTY_TYPE(AutoScaleFactorZ, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); - + ADD_PROPERTY_TYPE( + AutoScaleFactorX, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); + ADD_PROPERTY_TYPE( + AutoScaleFactorY, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); + ADD_PROPERTY_TYPE( + AutoScaleFactorZ, (1), "AutoScale", App::Prop_Hidden, "Automatic scaling factor"); + m_geometrySeperator = new SoSeparator(); m_geometrySeperator->ref(); - + m_scale = new SoScale(); m_scale->ref(); m_scale->scaleFactor = SbVec3f(1, 1, 1); @@ -227,7 +232,8 @@ SbBox3f ViewProviderFemPostFunction::getBoundingsOfView() const { SbBox3f box; Gui::Document* doc = this->getDocument(); - Gui::View3DInventor* view = qobject_cast(doc->getViewOfViewProvider(this)); + Gui::View3DInventor* view = + qobject_cast(doc->getViewOfViewProvider(this)); if (view) { Gui::View3DInventorViewer* viewer = view->getViewer(); box = viewer->getBoundingBox(); @@ -270,7 +276,8 @@ std::vector ViewProviderFemPostFunction::getDisplayModes() const void ViewProviderFemPostFunction::dragStartCallback(void* data, SoDragger*) { // This is called when a manipulator is about to manipulating - Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Edit Mirror")); + Gui::Application::Instance->activeDocument()->openCommand( + QT_TRANSLATE_NOOP("Command", "Edit Mirror")); static_cast(data)->m_isDragging = true; ViewProviderFemPostFunction* that = static_cast(data); @@ -352,7 +359,8 @@ void ViewProviderFemPostFunction::onChanged(const App::Property* prop) Gui::ViewProviderDocumentObject::onChanged(prop); if (m_autoscale) - m_scale->scaleFactor = SbVec3f(AutoScaleFactorX.getValue(), AutoScaleFactorY.getValue(), AutoScaleFactorZ.getValue()); + m_scale->scaleFactor = SbVec3f( + AutoScaleFactorX.getValue(), AutoScaleFactorY.getValue(), AutoScaleFactorZ.getValue()); } @@ -418,8 +426,8 @@ FunctionWidget* ViewProviderFemPostBoxFunction::createControlWidget() } BoxWidget::BoxWidget() + : ui(new Ui_BoxWidget) { - ui = new Ui_BoxWidget(); ui->setupUi(this); QSize size = ui->centerX->sizeForText(QStringLiteral("000000000000")); @@ -438,12 +446,18 @@ BoxWidget::BoxWidget() ui->width->setDecimals(UserDecimals); ui->height->setDecimals(UserDecimals); - connect(ui->centerX, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &BoxWidget::centerChanged); - connect(ui->centerY, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &BoxWidget::centerChanged); - connect(ui->centerZ, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &BoxWidget::centerChanged); - connect(ui->length, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &BoxWidget::lengthChanged); - connect(ui->width, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &BoxWidget::widthChanged); - connect(ui->height, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &BoxWidget::heightChanged); + connect(ui->centerX, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &BoxWidget::centerChanged); + connect(ui->centerY, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &BoxWidget::centerChanged); + connect(ui->centerZ, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &BoxWidget::centerChanged); + connect(ui->length, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &BoxWidget::lengthChanged); + connect(ui->width, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &BoxWidget::widthChanged); + connect(ui->height, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &BoxWidget::heightChanged); } BoxWidget::~BoxWidget() @@ -594,8 +608,8 @@ FunctionWidget* ViewProviderFemPostCylinderFunction::createControlWidget() } CylinderWidget::CylinderWidget() + : ui(new Ui_CylinderWidget) { - ui = new Ui_CylinderWidget(); ui->setupUi(this); QSize size = ui->centerX->sizeForText(QStringLiteral("000000000000")); @@ -615,13 +629,20 @@ CylinderWidget::CylinderWidget() ui->axisY->setDecimals(UserDecimals); ui->axisZ->setDecimals(UserDecimals); - connect(ui->centerX, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &CylinderWidget::centerChanged); - connect(ui->centerY, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &CylinderWidget::centerChanged); - connect(ui->centerZ, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &CylinderWidget::centerChanged); - connect(ui->axisX, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &CylinderWidget::axisChanged); - connect(ui->axisY, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &CylinderWidget::axisChanged); - connect(ui->axisZ, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &CylinderWidget::axisChanged); - connect(ui->radius, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &CylinderWidget::radiusChanged); + connect(ui->centerX, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &CylinderWidget::centerChanged); + connect(ui->centerY, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &CylinderWidget::centerChanged); + connect(ui->centerZ, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &CylinderWidget::centerChanged); + connect(ui->axisX, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &CylinderWidget::axisChanged); + connect(ui->axisY, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &CylinderWidget::axisChanged); + connect(ui->axisZ, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &CylinderWidget::axisChanged); + connect(ui->radius, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &CylinderWidget::radiusChanged); } CylinderWidget::~CylinderWidget() @@ -693,7 +714,8 @@ void CylinderWidget::axisChanged(double) void CylinderWidget::radiusChanged(double) { if (!blockObjectUpdates()) { - static_cast(getObject())->Radius.setValue(ui->radius->value().getValue()); + static_cast(getObject()) + ->Radius.setValue(ui->radius->value().getValue()); } } @@ -707,13 +729,14 @@ static const App::PropertyFloatConstraint::Constraints scaleConstraint = {1e-4, ViewProviderFemPostPlaneFunction::ViewProviderFemPostPlaneFunction() : m_detectscale(false) { - ADD_PROPERTY_TYPE(Scale, (1000.0), "Manipulator", App::Prop_None, "Scaling factor for the manipulator"); + ADD_PROPERTY_TYPE( + Scale, (1000.0), "Manipulator", App::Prop_None, "Scaling factor for the manipulator"); Scale.setConstraints(&scaleConstraint); sPixmap = "fem-post-geo-plane"; setAutoScale(true); - //setup the visualisation geometry + // setup the visualisation geometry getGeometryNode()->addChild(ShapeNodes::postPlane()); } @@ -747,7 +770,8 @@ void ViewProviderFemPostPlaneFunction::onChanged(const App::Property* prop) // get current matrix SbVec3f t, s; SbRotation r, so; - SbMatrix matrix = getManipulator()->getDragger()->getMotionMatrix(); // clazy:exclude=rule-of-two-soft + SbMatrix matrix = + getManipulator()->getDragger()->getMotionMatrix();// clazy:exclude=rule-of-two-soft matrix.getTransform(t, r, s, so); float scale = static_cast(Scale.getValue()); @@ -801,8 +825,8 @@ FunctionWidget* ViewProviderFemPostPlaneFunction::createControlWidget() PlaneWidget::PlaneWidget() + : ui(new Ui_PlaneWidget) { - ui = new Ui_PlaneWidget(); ui->setupUi(this); QSize size = ui->originX->sizeForText(QStringLiteral("000000000000")); @@ -821,12 +845,18 @@ PlaneWidget::PlaneWidget() ui->normalY->setDecimals(UserDecimals); ui->normalZ->setDecimals(UserDecimals); - connect(ui->originX, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &PlaneWidget::originChanged); - connect(ui->originY, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &PlaneWidget::originChanged); - connect(ui->originZ, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &PlaneWidget::originChanged); - connect(ui->normalX, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &PlaneWidget::normalChanged); - connect(ui->normalY, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &PlaneWidget::normalChanged); - connect(ui->normalZ, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &PlaneWidget::normalChanged); + connect(ui->originX, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &PlaneWidget::originChanged); + connect(ui->originY, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &PlaneWidget::originChanged); + connect(ui->originZ, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &PlaneWidget::originChanged); + connect(ui->normalX, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &PlaneWidget::normalChanged); + connect(ui->normalY, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &PlaneWidget::normalChanged); + connect(ui->normalZ, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &PlaneWidget::normalChanged); } PlaneWidget::~PlaneWidget() @@ -847,7 +877,8 @@ void PlaneWidget::setViewProvider(ViewProviderFemPostFunction* view) ui->originY->setUnit(unit); ui->originZ->setUnit(unit); setBlockObjectUpdates(false); - // The normal vector is unitless. It uses nevertheless Gui::PrefQuantitySpinBox to keep dialog uniform. + // The normal vector is unitless. It uses nevertheless Gui::PrefQuantitySpinBox to keep dialog + // uniform. onChange(func->Normal); onChange(func->Origin); } @@ -965,8 +996,8 @@ FunctionWidget* ViewProviderFemPostSphereFunction::createControlWidget() } SphereWidget::SphereWidget() + : ui(new Ui_SphereWidget) { - ui = new Ui_SphereWidget(); ui->setupUi(this); QSize size = ui->centerX->sizeForText(QStringLiteral("000000000000")); @@ -980,10 +1011,14 @@ SphereWidget::SphereWidget() ui->centerY->setDecimals(UserDecimals); ui->centerZ->setDecimals(UserDecimals); - connect(ui->centerX, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &SphereWidget::centerChanged); - connect(ui->centerY, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &SphereWidget::centerChanged); - connect(ui->centerZ, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &SphereWidget::centerChanged); - connect(ui->radius, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &SphereWidget::radiusChanged); + connect(ui->centerX, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &SphereWidget::centerChanged); + connect(ui->centerY, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &SphereWidget::centerChanged); + connect(ui->centerZ, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &SphereWidget::centerChanged); + connect(ui->radius, qOverload(&Gui::QuantitySpinBox::valueChanged), + this, &SphereWidget::radiusChanged); } SphereWidget::~SphereWidget() @@ -1039,7 +1074,8 @@ void SphereWidget::centerChanged(double) void SphereWidget::radiusChanged(double) { if (!blockObjectUpdates()) { - static_cast(getObject())->Radius.setValue(ui->radius->value().getValue()); + static_cast(getObject()) + ->Radius.setValue(ui->radius->value().getValue()); } } @@ -1163,17 +1199,19 @@ SoGroup* postSphere() int idx = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 21; j++) { - points->point.set1Value(idx, SbVec3f(std::sin(2 * M_PI / 20 * j) * std::cos(M_PI / 4 * i), - std::sin(2 * M_PI / 20 * j) * std::sin(M_PI / 4 * i), - std::cos(2 * M_PI / 20 * j))); + points->point.set1Value(idx, + SbVec3f(std::sin(2 * M_PI / 20 * j) * std::cos(M_PI / 4 * i), + std::sin(2 * M_PI / 20 * j) * std::sin(M_PI / 4 * i), + std::cos(2 * M_PI / 20 * j))); ++idx; } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 21; j++) { - points->point.set1Value(idx, SbVec3f(std::sin(M_PI / 4 * i) * std::cos(2 * M_PI / 20 * j), - std::sin(M_PI / 4 * i) * std::sin(2 * M_PI / 20 * j), - std::cos(M_PI / 4 * i))); + points->point.set1Value(idx, + SbVec3f(std::sin(M_PI / 4 * i) * std::cos(2 * M_PI / 20 * j), + std::sin(M_PI / 4 * i) * std::sin(2 * M_PI / 20 * j), + std::cos(M_PI / 4 * i))); ++idx; } } diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h index 7775e4ff20..c896b67bad 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.h @@ -171,7 +171,7 @@ private Q_SLOTS: void heightChanged(double); private: - Ui_BoxWidget* ui; + std::unique_ptr ui; }; class FemGuiExport ViewProviderFemPostBoxFunction : public ViewProviderFemPostFunction @@ -209,7 +209,7 @@ private Q_SLOTS: void radiusChanged(double); private: - Ui_CylinderWidget* ui; + std::unique_ptr ui; }; class FemGuiExport ViewProviderFemPostCylinderFunction : public ViewProviderFemPostFunction @@ -246,7 +246,7 @@ private Q_SLOTS: void normalChanged(double); private: - Ui_PlaneWidget* ui; + std::unique_ptr ui; }; class FemGuiExport ViewProviderFemPostPlaneFunction : public ViewProviderFemPostFunction @@ -289,7 +289,7 @@ private Q_SLOTS: void radiusChanged(double); private: - Ui_SphereWidget* ui; + std::unique_ptr ui; }; class FemGuiExport ViewProviderFemPostSphereFunction : public ViewProviderFemPostFunction @@ -310,7 +310,6 @@ protected: namespace ShapeNodes { - SoGroup* postBox(); SoGroup* postCylinder(); SoGroup* postPlane();