[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
This commit is contained in:
Uwe
2023-03-27 19:08:05 +02:00
parent 1b6e97066c
commit 962dd41734
5 changed files with 111 additions and 68 deletions

View File

@@ -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<Base::Vector3d>());
Normals.setValues(std::vector<Base::Vector3d>());
}
@@ -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);

View File

@@ -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;
};

View File

@@ -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<int>(&QSpinBox::valueChanged),
connect(ui->sp_X, qOverload<double>(&QuantitySpinBox::valueChanged),
this, &TaskFemConstraintTransform::x_Changed);
connect(ui->sp_Y, qOverload<int>(&QSpinBox::valueChanged),
connect(ui->sp_Y, qOverload<double>(&QuantitySpinBox::valueChanged),
this, &TaskFemConstraintTransform::y_Changed);
connect(ui->sp_Z, qOverload<int>(&QSpinBox::valueChanged),
connect(ui->sp_Z, qOverload<double>(&QuantitySpinBox::valueChanged),
this, &TaskFemConstraintTransform::z_Changed);
// Get the feature data
@@ -92,9 +92,9 @@ TaskFemConstraintTransform::TaskFemConstraintTransform(
std::vector<std::string> 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<const TaskFemConstraintTransform*>(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()));

View File

@@ -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);

View File

@@ -49,12 +49,6 @@
<layout class="QHBoxLayout" name="hLayout1">
<item>
<widget class="QToolButton" name="btnAdd">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -71,12 +65,6 @@
</item>
<item>
<widget class="QToolButton" name="btnRemove">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -126,12 +114,15 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="sp_X">
<widget class="Gui::QuantitySpinBox" name="sp_X">
<property name="unit" stdset="0">
<string notr="true">deg</string>
</property>
<property name="minimum">
<number>-360</number>
<double>-360.000000000000000</double>
</property>
<property name="maximum">
<number>360</number>
<double>360.000000000000000</double>
</property>
</widget>
</item>
@@ -147,12 +138,15 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="sp_Y">
<widget class="Gui::QuantitySpinBox" name="sp_Y">
<property name="unit" stdset="0">
<string notr="true">deg</string>
</property>
<property name="minimum">
<number>-360</number>
<double>-360.000000000000000</double>
</property>
<property name="maximum">
<number>360</number>
<double>360.000000000000000</double>
</property>
</widget>
</item>
@@ -168,12 +162,15 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="sp_Z">
<widget class="Gui::QuantitySpinBox" name="sp_Z">
<property name="unit" stdset="0">
<string notr="true">deg</string>
</property>
<property name="minimum">
<number>-360</number>
<double>-360.000000000000000</double>
</property>
<property name="maximum">
<number>360</number>
<double>360.000000000000000</double>
</property>
</widget>
</item>
@@ -219,6 +216,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>