From 8bcab38d76d33264cd0e60565bd391030d5e9d2c Mon Sep 17 00:00:00 2001 From: Uwe Date: Fri, 10 Jun 2022 14:17:42 +0200 Subject: [PATCH] [FEM] fix unit handling of line filter - in contrary to other filters the properties have no unit handling (there are several bugs in line filter and to fix them, unit handling is necessary) --- src/Mod/Fem/App/FemPostFilter.cpp | 18 ++ src/Mod/Fem/App/FemPostFilter.h | 13 +- src/Mod/Fem/Gui/TaskPostBoxes.cpp | 29 +- src/Mod/Fem/Gui/TaskPostDataAlongLine.ui | 340 +++++++++++------------ 4 files changed, 211 insertions(+), 189 deletions(-) diff --git a/src/Mod/Fem/App/FemPostFilter.cpp b/src/Mod/Fem/App/FemPostFilter.cpp index 3bc0cae699..d8b0c620b9 100644 --- a/src/Mod/Fem/App/FemPostFilter.cpp +++ b/src/Mod/Fem/App/FemPostFilter.cpp @@ -236,6 +236,24 @@ DocumentObjectExecReturn* FemPostDataAlongLineFilter::execute(void) { return Fem::FemPostFilter::execute(); } +void FemPostDataAlongLineFilter::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop) +// transforms properties that had been changed +{ + // property Point1 had the App::PropertyVector and was changed to App::PropertyVectorDistance + if (prop == &Point1 && strcmp(TypeName, "App::PropertyVector") == 0) { + App::PropertyVector Point1Property; + // restore the PropertyFloat to be able to set its value + Point1Property.Restore(reader); + Point1.setValue(Point1Property.getValue()); + } + // property Point2 had the App::PropertyVector and was changed to App::PropertyVectorDistance + else if (prop == &Point2 && strcmp(TypeName, "App::PropertyVector") == 0) { + App::PropertyVector Point2Property; + Point2Property.Restore(reader); + Point2.setValue(Point2Property.getValue()); + } +} + void FemPostDataAlongLineFilter::onChanged(const Property* prop) { if (prop == &Point1) { diff --git a/src/Mod/Fem/App/FemPostFilter.h b/src/Mod/Fem/App/FemPostFilter.h index 23828b80c5..660f0e71b3 100644 --- a/src/Mod/Fem/App/FemPostFilter.h +++ b/src/Mod/Fem/App/FemPostFilter.h @@ -106,12 +106,12 @@ public: FemPostDataAlongLineFilter(void); virtual ~FemPostDataAlongLineFilter(); - App::PropertyVector Point2; - App::PropertyVector Point1; - App::PropertyInteger Resolution; - App::PropertyFloatList XAxisData; - App::PropertyFloatList YAxisData; - App::PropertyString PlotData; + App::PropertyVectorDistance Point1; + App::PropertyVectorDistance Point2; + App::PropertyInteger Resolution; + App::PropertyFloatList XAxisData; + App::PropertyFloatList YAxisData; + App::PropertyString PlotData; virtual const char* getViewProviderName(void) const { return "FemGui::ViewProviderFemPostDataAlongLine"; @@ -122,6 +122,7 @@ protected: virtual App::DocumentObjectExecReturn* execute(void); virtual void onChanged(const App::Property* prop); void GetAxisData(); + virtual void handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop); private: diff --git a/src/Mod/Fem/Gui/TaskPostBoxes.cpp b/src/Mod/Fem/Gui/TaskPostBoxes.cpp index 462b9f5a75..3d8bc53a1e 100644 --- a/src/Mod/Fem/Gui/TaskPostBoxes.cpp +++ b/src/Mod/Fem/Gui/TaskPostBoxes.cpp @@ -553,6 +553,24 @@ TaskPostDataAlongLine::TaskPostDataAlongLine(ViewProviderDocumentObject* view, Q QMetaObject::connectSlotsByName(this); this->groupLayout()->addWidget(proxy); + // set decimals before the edits are filled to avoid rounding mistakes + int UserDecimals = Base::UnitsApi::getDecimals(); + ui->point1X->setDecimals(UserDecimals); + ui->point1Y->setDecimals(UserDecimals); + ui->point1Z->setDecimals(UserDecimals); + ui->point2X->setDecimals(UserDecimals); + ui->point2Y->setDecimals(UserDecimals); + ui->point2Z->setDecimals(UserDecimals); + + Base::Unit lengthUnit = static_cast(getObject())->Point1.getUnit(); + ui->point1X->setUnit(lengthUnit); + ui->point1Y->setUnit(lengthUnit); + ui->point1Z->setUnit(lengthUnit); + lengthUnit = static_cast(getObject())->Point2.getUnit(); + ui->point2X->setUnit(lengthUnit); + ui->point2Y->setUnit(lengthUnit); + ui->point2Z->setUnit(lengthUnit); + const Base::Vector3d& vec1 = static_cast(getObject())->Point1.getValue(); ui->point1X->setValue(vec1.x); ui->point1Y->setValue(vec1.y); @@ -628,7 +646,8 @@ void TaskPostDataAlongLine::on_SelectPoints_clicked() { FemGui::PointMarker* marker = new FemGui::PointMarker(viewer, ObjName); viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), FemGui::TaskPostDataAlongLine::pointCallback, marker); - connect(marker, SIGNAL(PointsChanged(double, double, double, double, double, double)), this, SLOT(onChange(double, double, double, double, double, double))); + connect(marker, SIGNAL(PointsChanged(double, double, double, double, double, double)), this, + SLOT(onChange(double, double, double, double, double, double))); } } @@ -664,16 +683,16 @@ void TaskPostDataAlongLine::onChange(double x1, double y1, double z1, double x2, void TaskPostDataAlongLine::point1Changed(double) { - Base::Vector3d vec(ui->point1X->value(), ui->point1Y->value(), ui->point1Z->value()); std::string ObjName = static_cast(getObject())->Label.getValue(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Point1 = App.Vector(%f, %f, %f)", ObjName.c_str(), ui->point1X->value(), ui->point1Y->value(), ui->point1Z->value()); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Point1 = App.Vector(%f, %f, %f)", ObjName.c_str(), + ui->point1X->value().getValue(), ui->point1Y->value().getValue(), ui->point1Z->value().getValue()); } void TaskPostDataAlongLine::point2Changed(double) { - Base::Vector3d vec(ui->point2X->value(), ui->point2Y->value(), ui->point2Z->value()); std::string ObjName = static_cast(getObject())->Label.getValue(); - Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Point2 = App.Vector(%f, %f, %f)", ObjName.c_str(), ui->point2X->value(), ui->point2Y->value(), ui->point2Z->value()); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Point2 = App.Vector(%f, %f, %f)", ObjName.c_str(), + ui->point2X->value().getValue(), ui->point2Y->value().getValue(), ui->point2Z->value().getValue()); } void TaskPostDataAlongLine::resolutionChanged(int val) { diff --git a/src/Mod/Fem/Gui/TaskPostDataAlongLine.ui b/src/Mod/Fem/Gui/TaskPostDataAlongLine.ui index 7c80824e2a..173ebcdd8f 100644 --- a/src/Mod/Fem/Gui/TaskPostDataAlongLine.ui +++ b/src/Mod/Fem/Gui/TaskPostDataAlongLine.ui @@ -6,8 +6,8 @@ 0 0 - 482 - 363 + 300 + 302 @@ -15,172 +15,142 @@ - - - Qt::Horizontal + + + Coordinates + + + + + + 95 + 16777215 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Point 1 + + + Qt::AlignCenter + + + + + + + + 95 + 16777215 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 95 + 16777215 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Point 2 + + + Qt::AlignCenter + + + + + + + + 95 + 16777215 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 95 + 16777215 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 95 + 16777215 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + y + + + Qt::AlignCenter + + + + + + + z + + + Qt::AlignCenter + + + + + + + x + + + Qt::AlignCenter + + + + - - - - - - Point1 - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 70 - 0 - - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - - - - - - 0 - 0 - - - - - 70 - 0 - - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - - - - - - 0 - 0 - - - - - 70 - 0 - - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - - - - - - - - - Point2 - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 70 - 0 - - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - - - - - - 0 - 0 - - - - - 70 - 0 - - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - - - - - - 0 - 0 - - - - - 70 - 0 - - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - - - @@ -189,26 +159,33 @@ - - - QFormLayout::AllNonFixedFieldsGrow - - + + Resolution - + 999999999 - - + + + + Qt::Horizontal + + + + 40 + 20 + + + @@ -275,12 +252,19 @@ - SelectPoints - line - line_2 - line_3 - CreatePlot + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+ + Gui::PrefQuantitySpinBox + Gui::QuantitySpinBox +
Gui/PrefWidgets.h
+
+