diff --git a/src/Mod/Fem/App/FemConstraintPressure.cpp b/src/Mod/Fem/App/FemConstraintPressure.cpp index 5381846f52..e6a06c4efb 100644 --- a/src/Mod/Fem/App/FemConstraintPressure.cpp +++ b/src/Mod/Fem/App/FemConstraintPressure.cpp @@ -58,6 +58,21 @@ const char* ConstraintPressure::getViewProviderName() const return "FemGui::ViewProviderFemConstraintPressure"; } +void ConstraintPressure::handleChangedPropertyType(Base::XMLReader& reader, + const char* TypeName, + App::Property* prop) +{ + // property Pressure had App::PropertyFloat and was changed to App::PropertyPressure + if (prop == &Pressure && strcmp(TypeName, "App::PropertyFloat") == 0) { + App::PropertyFloat PressureProperty; + // restore the PropertyFloat to be able to set its value + PressureProperty.Restore(reader); + // the old implementation or pressure stored the value as MPa + // therefore we must convert the value with a factor 1000 + Pressure.setValue(PressureProperty.getValue() * 1000.0); + } +} + void ConstraintPressure::onChanged(const App::Property* prop) { Constraint::onChanged(prop); diff --git a/src/Mod/Fem/App/FemConstraintPressure.h b/src/Mod/Fem/App/FemConstraintPressure.h index 7ebb3ca754..1bb67410f6 100644 --- a/src/Mod/Fem/App/FemConstraintPressure.h +++ b/src/Mod/Fem/App/FemConstraintPressure.h @@ -37,7 +37,7 @@ class FemExport ConstraintPressure: public Fem::Constraint public: ConstraintPressure(); - App::PropertyFloat Pressure; + App::PropertyPressure Pressure; App::PropertyBool Reversed; App::PropertyVectorList Points; App::PropertyVectorList Normals; @@ -49,6 +49,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/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp index dec2df4f65..39e73aa5a6 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -52,6 +52,33 @@ TaskFemConstraintPressure::TaskFemConstraintPressure( ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); + this->groupLayout()->addWidget(proxy); + + // Get the feature data + Fem::ConstraintPressure* pcConstraint = + static_cast(ConstraintView->getObject()); + + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + // Fill data into dialog elements + ui->if_pressure->setUnit(pcConstraint->Pressure.getUnit()); + ui->if_pressure->setMinimum(0); + ui->if_pressure->setMaximum(FLOAT_MAX); + ui->if_pressure->setValue(pcConstraint->Pressure.getQuantityValue()); + ui->if_pressure->bind(pcConstraint->Pressure); + + bool reversed = pcConstraint->Reversed.getValue(); + ui->checkBoxReverse->setChecked(reversed); + + ui->lw_references->clear(); + for (std::size_t i = 0; i < Objects.size(); i++) { + ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i])); + } + if (!Objects.empty()) { + ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); + } + // create a context menu for the listview of the references createDeleteAction(ui->lw_references); connect(deleteAction, @@ -72,37 +99,9 @@ TaskFemConstraintPressure::TaskFemConstraintPressure( this, &TaskFemConstraintPressure::onCheckReverse); - this->groupLayout()->addWidget(proxy); - - /* Note: */ - // Get the feature data - Fem::ConstraintPressure* pcConstraint = - static_cast(ConstraintView->getObject()); - - std::vector Objects = pcConstraint->References.getValues(); - std::vector SubElements = pcConstraint->References.getSubValues(); - - // 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); - ui->if_pressure->setValue(p); - bool reversed = pcConstraint->Reversed.getValue(); - ui->checkBoxReverse->setChecked(reversed); - /* */ - - ui->lw_references->clear(); - for (std::size_t i = 0; i < Objects.size(); i++) { - ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i])); - } - if (!Objects.empty()) { - ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); - } - // Selection buttons - buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd); - buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove); + buttonGroup->addButton(ui->btnAdd, static_cast(SelectionChangeModes::refAdd)); + buttonGroup->addButton(ui->btnRemove, static_cast(SelectionChangeModes::refRemove)); updateUI(); } @@ -252,12 +251,9 @@ const std::string TaskFemConstraintPressure::getReferences() const return TaskFemConstraint::getReferences(items); } -/* Note: */ -double TaskFemConstraintPressure::get_Pressure() const +std::string TaskFemConstraintPressure::get_Pressure() const { - Base::Quantity pressure = ui->if_pressure->getQuantity(); - double pressure_in_MPa = pressure.getValueAs(Base::Quantity::MegaPascal); - return pressure_in_MPa; + return ui->if_pressure->value().getSafeUserString().toStdString(); } bool TaskFemConstraintPressure::get_Reverse() const @@ -323,9 +319,9 @@ bool TaskDlgFemConstraintPressure::accept() try { Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.Pressure = %f", + "App.ActiveDocument.%s.Pressure = \"%s\"", name.c_str(), - parameterPressure->get_Pressure()); + parameterPressure->get_Pressure().c_str()); Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Reversed = %s", name.c_str(), diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.h b/src/Mod/Fem/Gui/TaskFemConstraintPressure.h index d540829388..a1efc14a0b 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.h @@ -46,7 +46,7 @@ public: QWidget* parent = nullptr); ~TaskFemConstraintPressure() override; const std::string getReferences() const override; - double get_Pressure() const; + std::string get_Pressure() const; bool get_Reverse() const; private Q_SLOTS: diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.ui b/src/Mod/Fem/Gui/TaskFemConstraintPressure.ui index fbe97414c9..b3e9ff5200 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.ui +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.ui @@ -70,12 +70,12 @@ - - - 0 MPa - + - MPa + + + + 0.000000000000000 @@ -92,9 +92,9 @@ - Gui::InputField - QLineEdit -
Gui/InputField.h
+ Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
diff --git a/src/Mod/Fem/femobjects/constraint_initialpressure.py b/src/Mod/Fem/femobjects/constraint_initialpressure.py index 2b2914eb4d..c28297fe55 100644 --- a/src/Mod/Fem/femobjects/constraint_initialpressure.py +++ b/src/Mod/Fem/femobjects/constraint_initialpressure.py @@ -51,5 +51,5 @@ class ConstraintInitialPressure(base_fempythonobject.BaseFemPythonObject): "Parameter", "Initial Pressure" ) - # App::PropertyPressure is in kPa and we initialize 1 bar - obj.Pressure = 100 + # we initialize 1 bar + obj.Pressure = "100 kPa" diff --git a/src/Mod/Fem/femsolver/calculix/write_constraint_pressure.py b/src/Mod/Fem/femsolver/calculix/write_constraint_pressure.py index e1bb23b696..18aee620b0 100644 --- a/src/Mod/Fem/femsolver/calculix/write_constraint_pressure.py +++ b/src/Mod/Fem/femsolver/calculix/write_constraint_pressure.py @@ -25,6 +25,7 @@ __title__ = "FreeCAD FEM calculix constraint pressure" __author__ = "Bernd Hahnebach" __url__ = "https://www.freecad.org" +import FreeCAD def get_analysis_types(): return ["buckling", "static", "thermomech"] @@ -47,7 +48,9 @@ def write_meshdata_constraint(f, femobj, prs_obj, ccxwriter): # floats read from ccx should use {:.13G}, see comment in writer module rev = -1 if prs_obj.Reversed else 1 - press_rev = rev * prs_obj.Pressure + # the pressure has to be output in MPa + pressure_quantity = FreeCAD.Units.Quantity(prs_obj.Pressure.getValueAs("MPa")) + press_rev = rev * pressure_quantity f.write("*DLOAD\n") for ref_shape in femobj["PressureFaces"]: @@ -57,12 +60,12 @@ def write_meshdata_constraint(f, femobj, prs_obj, ccxwriter): f.write("** " + ref_shape[0] + "\n") for face, fno in ref_shape[1]: if fno > 0: # solid mesh face - f.write("{},P{},{:.13G}\n".format(face, fno, press_rev)) + f.write("{},P{},{}\n".format(face, fno, press_rev)) # on shell mesh face: fno == 0 # normal of element face == face normal elif fno == 0: - f.write("{},P,{:.13G}\n".format(face, press_rev)) + f.write("{},P,{}\n".format(face, press_rev)) # on shell mesh face: fno == -1 # normal of element face opposite direction face normal elif fno == -1: - f.write("{},P,{:.13G}\n".format(face, -1 * press_rev)) + f.write("{},P,{}\n".format(face, -1 * press_rev)) diff --git a/src/Mod/Fem/femsolver/elmer/equations/deformation_writer.py b/src/Mod/Fem/femsolver/elmer/equations/deformation_writer.py index ef50ec7da6..295a9a9a38 100644 --- a/src/Mod/Fem/femsolver/elmer/equations/deformation_writer.py +++ b/src/Mod/Fem/femsolver/elmer/equations/deformation_writer.py @@ -82,7 +82,7 @@ class DeformationWriter: for obj in self.write.getMember("Fem::ConstraintPressure"): if obj.References: for name in obj.References[0][1]: - pressure = self.write.getFromUi(obj.Pressure, "MPa", "M/(L*T^2)") + pressure = float(obj.Pressure.getValueAs("Pa")) if not obj.Reversed: pressure *= -1 self.write.boundary(name, "Normal Force", pressure) diff --git a/src/Mod/Fem/femsolver/elmer/equations/elasticity_writer.py b/src/Mod/Fem/femsolver/elmer/equations/elasticity_writer.py index 2e52062b32..60c5327504 100644 --- a/src/Mod/Fem/femsolver/elmer/equations/elasticity_writer.py +++ b/src/Mod/Fem/femsolver/elmer/equations/elasticity_writer.py @@ -298,7 +298,7 @@ class ElasticityWriter: for obj in self.write.getMember("Fem::ConstraintPressure"): if obj.References: for name in obj.References[0][1]: - pressure = self.write.getFromUi(obj.Pressure, "MPa", "M/(L*T^2)") + pressure = float(obj.Pressure.getValueAs("Pa")) if not obj.Reversed: pressure *= -1 self.write.boundary(name, "Normal Force", pressure) diff --git a/src/Mod/Fem/femsolver/elmer/equations/flow_writer.py b/src/Mod/Fem/femsolver/elmer/equations/flow_writer.py index 8649ba4a84..c19451bb4b 100644 --- a/src/Mod/Fem/femsolver/elmer/equations/flow_writer.py +++ b/src/Mod/Fem/femsolver/elmer/equations/flow_writer.py @@ -261,7 +261,7 @@ class Flowwriter: for obj in self.write.getMember("Fem::ConstraintPressure"): if obj.References: for name in obj.References[0][1]: - pressure = self.write.getFromUi(obj.Pressure, "MPa", "M/(L*T^2)") + pressure = float(obj.Pressure.getValueAs("Pa")) if obj.Reversed: pressure *= -1 self.write.boundary(name, "External Pressure", pressure)