Skip to content

Commit

Permalink
[FEM] fix unit handling of line filter
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
donovaly committed Jun 10, 2022
1 parent fdaca02 commit d4c180e
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 189 deletions.
18 changes: 18 additions & 0 deletions src/Mod/Fem/App/FemPostFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions src/Mod/Fem/App/FemPostFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ class FemExport FemPostDataAlongLineFilter : public FemPostFilter {
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";
Expand All @@ -122,6 +122,7 @@ class FemExport FemPostDataAlongLineFilter : public FemPostFilter {
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:

Expand Down
29 changes: 24 additions & 5 deletions src/Mod/Fem/Gui/TaskPostBoxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fem::FemPostDataAlongLineFilter*>(getObject())->Point1.getUnit();
ui->point1X->setUnit(lengthUnit);
ui->point1Y->setUnit(lengthUnit);
ui->point1Z->setUnit(lengthUnit);
lengthUnit = static_cast<Fem::FemPostDataAlongLineFilter*>(getObject())->Point2.getUnit();
ui->point2X->setUnit(lengthUnit);
ui->point2Y->setUnit(lengthUnit);
ui->point2Z->setUnit(lengthUnit);

const Base::Vector3d& vec1 = static_cast<Fem::FemPostDataAlongLineFilter*>(getObject())->Point1.getValue();
ui->point1X->setValue(vec1.x);
ui->point1Y->setValue(vec1.y);
Expand Down Expand Up @@ -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)));
}
}

Expand Down Expand Up @@ -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<Fem::FemPostDataAlongLineFilter*>(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<Fem::FemPostDataAlongLineFilter*>(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) {
Expand Down

0 comments on commit d4c180e

Please sign in to comment.