From 962dd417346b2727c8352e2cbd48e6003112e2c0 Mon Sep 17 00:00:00 2001 From: Uwe Date: Mon, 27 Mar 2023 19:08:05 +0200 Subject: [PATCH] [FEM] Transform constraint overhaul - fix warning about local scope - make the angles a PropertyAngle to handle the unit - also fix some too long code lines --- src/Mod/Fem/App/FemConstraintTransform.cpp | 55 ++++++++++++---- src/Mod/Fem/App/FemConstraintTransform.h | 8 ++- .../Fem/Gui/TaskFemConstraintTransform.cpp | 64 ++++++++++--------- src/Mod/Fem/Gui/TaskFemConstraintTransform.h | 6 +- src/Mod/Fem/Gui/TaskFemConstraintTransform.ui | 46 +++++++------ 5 files changed, 111 insertions(+), 68 deletions(-) diff --git a/src/Mod/Fem/App/FemConstraintTransform.cpp b/src/Mod/Fem/App/FemConstraintTransform.cpp index b427d6eb59..ce41ca3d83 100644 --- a/src/Mod/Fem/App/FemConstraintTransform.cpp +++ b/src/Mod/Fem/App/FemConstraintTransform.cpp @@ -34,22 +34,34 @@ static const char* TransformTypes[] = {"Cylindrical","Rectangular", nullptr}; ConstraintTransform::ConstraintTransform() { - ADD_PROPERTY(X_rot,(0.0)); //numeric value, 0.0 - ADD_PROPERTY(Y_rot,(0.0)); - ADD_PROPERTY(Z_rot,(0.0)); - ADD_PROPERTY_TYPE(TransformType,(1),"ConstraintTransform",(App::PropertyType)(App::Prop_None), + ADD_PROPERTY(X_rot, (0.0)); + ADD_PROPERTY(Y_rot, (0.0)); + ADD_PROPERTY(Z_rot, (0.0)); + ADD_PROPERTY_TYPE(TransformType, (1), "ConstraintTransform", + (App::PropertyType)(App::Prop_None), "Type of transform, rectangular or cylindrical"); TransformType.setEnums(TransformTypes); - ADD_PROPERTY_TYPE(RefDispl,(nullptr,nullptr),"ConstraintTransform",(App::PropertyType)(App::Prop_None),"Elements where the constraint is applied"); - ADD_PROPERTY_TYPE(NameDispl,(nullptr),"ConstraintTransform",(App::PropertyType)(App::Prop_None),"Elements where the constraint is applied"); - ADD_PROPERTY_TYPE(BasePoint,(Base::Vector3d(0,0,0)),"ConstraintTransform",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(RefDispl, (nullptr, nullptr), + "ConstraintTransform", (App::PropertyType)(App::Prop_None), + "Elements where the constraint is applied"); + // RefDispl must get a global scope, see + // https://forum.freecad.org/viewtopic.php?p=671402#p671402 + RefDispl.setScope(App::LinkScope::Global); + ADD_PROPERTY_TYPE(NameDispl, (nullptr), "ConstraintTransform", + (App::PropertyType)(App::Prop_None), + "Elements where the constraint is applied"); + ADD_PROPERTY_TYPE(BasePoint, (Base::Vector3d(0, 0, 0)), "ConstraintTransform", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Base point of cylindrical surface"); - ADD_PROPERTY_TYPE(Axis,(Base::Vector3d(0,1,0)),"ConstraintTransform",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(Axis, (Base::Vector3d(0, 1, 0)), "ConstraintTransform", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Axis of cylindrical surface"); - ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintTransform",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + ADD_PROPERTY_TYPE(Points, (Base::Vector3d()), "ConstraintTransform", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), "Points where symbols are drawn"); - ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintTransform",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), - "Normals where symbols are drawn"); + ADD_PROPERTY_TYPE(Normals, (Base::Vector3d()), "ConstraintTransform", + App::PropertyType(App::Prop_ReadOnly | App::Prop_Output), + "Normals where symbols are drawn"); Points.setValues(std::vector()); Normals.setValues(std::vector()); } @@ -64,6 +76,27 @@ const char* ConstraintTransform::getViewProviderName() const return "FemGui::ViewProviderFemConstraintTransform"; } +void ConstraintTransform::handleChangedPropertyType(Base::XMLReader& reader, + const char* TypeName, App::Property* prop) +{ + // properties _rot had App::PropertyFloat and were changed to App::PropertyAngle + if (prop == &X_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat X_rotProperty; + X_rotProperty.Restore(reader); + X_rot.setValue(X_rotProperty.getValue()); + } + else if (prop == &Y_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat Y_rotProperty; + Y_rotProperty.Restore(reader); + Y_rot.setValue(Y_rotProperty.getValue()); + } + else if (prop == &Z_rot && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat Z_rotProperty; + Z_rotProperty.Restore(reader); + Z_rot.setValue(Z_rotProperty.getValue()); + } +} + void ConstraintTransform::onChanged(const App::Property* prop) { Constraint::onChanged(prop); diff --git a/src/Mod/Fem/App/FemConstraintTransform.h b/src/Mod/Fem/App/FemConstraintTransform.h index 2449b7624a..e0c2705b3c 100644 --- a/src/Mod/Fem/App/FemConstraintTransform.h +++ b/src/Mod/Fem/App/FemConstraintTransform.h @@ -44,9 +44,9 @@ public: App::PropertyVectorList Normals; App::PropertyVector BasePoint; App::PropertyVector Axis; - App::PropertyFloat X_rot; - App::PropertyFloat Y_rot; - App::PropertyFloat Z_rot; + App::PropertyAngle X_rot; + App::PropertyAngle Y_rot; + App::PropertyAngle Z_rot; App::PropertyEnumeration TransformType; //etc /* */ @@ -58,6 +58,8 @@ public: const char* getViewProviderName() const override; protected: + void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, + App::Property* prop); void onChanged(const App::Property* prop) override; }; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp index c61c6ee8da..ba0c75f32e 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp @@ -77,11 +77,11 @@ TaskFemConstraintTransform::TaskFemConstraintTransform( connect(ui->rb_rect, &QRadioButton::clicked, this, &TaskFemConstraintTransform::Rect); connect(ui->rb_cylin, &QRadioButton::clicked, this, &TaskFemConstraintTransform::Cyl); - connect(ui->sp_X, qOverload(&QSpinBox::valueChanged), + connect(ui->sp_X, qOverload(&QuantitySpinBox::valueChanged), this, &TaskFemConstraintTransform::x_Changed); - connect(ui->sp_Y, qOverload(&QSpinBox::valueChanged), + connect(ui->sp_Y, qOverload(&QuantitySpinBox::valueChanged), this, &TaskFemConstraintTransform::y_Changed); - connect(ui->sp_Z, qOverload(&QSpinBox::valueChanged), + connect(ui->sp_Z, qOverload(&QuantitySpinBox::valueChanged), this, &TaskFemConstraintTransform::z_Changed); // Get the feature data @@ -92,9 +92,9 @@ TaskFemConstraintTransform::TaskFemConstraintTransform( std::vector SubElements = pcConstraint->References.getSubValues(); // Fill data into dialog elements - ui->sp_X->setValue(pcConstraint->X_rot.getValue()); - ui->sp_Y->setValue(pcConstraint->Y_rot.getValue()); - ui->sp_Z->setValue(pcConstraint->Z_rot.getValue()); + ui->sp_X->setValue(pcConstraint->X_rot.getQuantityValue()); + ui->sp_Y->setValue(pcConstraint->Y_rot.getQuantityValue()); + ui->sp_Z->setValue(pcConstraint->Z_rot.getQuantityValue()); std::string transform_type = pcConstraint->TransformType.getValueAsString(); if (transform_type == "Rectangular") { ui->sw_transform->setCurrentIndex(0); @@ -150,7 +150,13 @@ TaskFemConstraintTransform::TaskFemConstraintTransform( this, &TaskFemConstraintTransform::removeFromSelection); + // Bind input fields to properties + ui->sp_X->bind(pcConstraint->X_rot); + ui->sp_Y->bind(pcConstraint->Y_rot); + ui->sp_Z->bind(pcConstraint->Z_rot); + updateUI(); + if ((p == 0) && (!Objects.empty())) { QMessageBox::warning(this, tr("Constraint update error"), @@ -507,10 +513,18 @@ else:\n\ doc." + showConstr + ".NameDispl = []\n"; } -/* Note: */ -double TaskFemConstraintTransform::get_X_rot() const { return ui->sp_X->value(); } -double TaskFemConstraintTransform::get_Y_rot() const { return ui->sp_Y->value(); } -double TaskFemConstraintTransform::get_Z_rot() const { return ui->sp_Z->value(); } +std::string TaskFemConstraintTransform::get_X_rot() const +{ + return ui->sp_X->value().getSafeUserString().toStdString(); +} +std::string TaskFemConstraintTransform::get_Y_rot() const +{ + return ui->sp_Y->value().getSafeUserString().toStdString(); +} +std::string TaskFemConstraintTransform::get_Z_rot() const +{ + return ui->sp_Z->value().getSafeUserString().toStdString(); +} std::string TaskFemConstraintTransform::get_transform_type() const { std::string transform; @@ -570,27 +584,17 @@ bool TaskDlgFemConstraintTransform::accept() 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()); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.X_rot = \"%s\"", + name.c_str(), parameters->get_X_rot().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Y_rot = \"%s\"", + name.c_str(), parameters->get_Y_rot().c_str()); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Z_rot = \"%s\"", + name.c_str(), parameters->get_Z_rot().c_str()); + 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.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 837c675381..504da18f31 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.h @@ -46,9 +46,9 @@ public: QWidget* parent = nullptr); ~TaskFemConstraintTransform() override; const std::string getReferences() const override; - double get_X_rot()const; - double get_Y_rot()const; - double get_Z_rot()const; + std::string get_X_rot() const; + std::string get_Y_rot() const; + std::string get_Z_rot() const; std::string get_transform_type() const; static std::string getSurfaceReferences(const std::string showConstr); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTransform.ui b/src/Mod/Fem/Gui/TaskFemConstraintTransform.ui index a593ee43de..38707265db 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.ui +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.ui @@ -49,12 +49,6 @@ - - - 0 - 0 - - 0 @@ -71,12 +65,6 @@ - - - 0 - 0 - - 0 @@ -126,12 +114,15 @@ - + + + deg + - -360 + -360.000000000000000 - 360 + 360.000000000000000 @@ -147,12 +138,15 @@ - + + + deg + - -360 + -360.000000000000000 - 360 + 360.000000000000000 @@ -168,12 +162,15 @@ - + + + deg + - -360 + -360.000000000000000 - 360 + 360.000000000000000 @@ -219,6 +216,13 @@ + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+