Fem: Add calculator filter
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
#include <Mod/Fem/App/FemPostBranchFilter.h>
|
||||
#include <Mod/Fem/App/FemPostPipeline.h>
|
||||
|
||||
#include "ui_TaskPostCalculator.h"
|
||||
#include "ui_TaskPostClip.h"
|
||||
#include "ui_TaskPostContours.h"
|
||||
#include "ui_TaskPostCut.h"
|
||||
@@ -323,6 +324,9 @@ void TaskDlgPost::open()
|
||||
void TaskDlgPost::clicked(int button)
|
||||
{
|
||||
if (button == QDialogButtonBox::Apply) {
|
||||
for (auto box : m_boxes) {
|
||||
box->apply();
|
||||
}
|
||||
recompute();
|
||||
}
|
||||
}
|
||||
@@ -2123,4 +2127,130 @@ void TaskPostWarpVector::onMinValueChanged(double)
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// calculator filter
|
||||
static const std::vector<std::string> calculatorOperators = {
|
||||
"+", "-", "*", "/", "-", "^", "abs", "cos", "sin", "tan", "exp",
|
||||
"log", "pow", "sqrt", "iHat", "jHat", "kHat", "cross", "dot", "mag", "norm"};
|
||||
|
||||
TaskPostCalculator::TaskPostCalculator(ViewProviderFemPostCalculator* view, QWidget* parent)
|
||||
: TaskPostBox(view,
|
||||
Gui::BitmapFactory().pixmap("FEM_PostFilterCalculator"),
|
||||
tr("Calculator options"),
|
||||
parent)
|
||||
, ui(new Ui_TaskPostCalculator)
|
||||
{
|
||||
// we load the views widget
|
||||
proxy = new QWidget(this);
|
||||
ui->setupUi(proxy);
|
||||
setupConnections();
|
||||
this->groupLayout()->addWidget(proxy);
|
||||
|
||||
// load the default values
|
||||
auto obj = getObject<Fem::FemPostCalculatorFilter>();
|
||||
ui->let_field_name->blockSignals(true);
|
||||
ui->let_field_name->setText(QString::fromUtf8(obj->FieldName.getValue()));
|
||||
ui->let_field_name->blockSignals(false);
|
||||
|
||||
ui->let_function->blockSignals(true);
|
||||
ui->let_function->setText(QString::fromUtf8(obj->Function.getValue()));
|
||||
ui->let_function->blockSignals(false);
|
||||
|
||||
ui->ckb_replace_invalid->setChecked(obj->ReplaceInvalid.getValue());
|
||||
ui->dsb_replacement_value->setEnabled(obj->ReplaceInvalid.getValue());
|
||||
ui->dsb_replacement_value->setValue(obj->ReplacementValue.getValue());
|
||||
ui->dsb_replacement_value->setMaximum(std::numeric_limits<double>::max());
|
||||
ui->dsb_replacement_value->setMinimum(std::numeric_limits<double>::lowest());
|
||||
|
||||
// fill available fields
|
||||
for (const auto& f : obj->getScalarVariables()) {
|
||||
ui->cb_scalars->addItem(QString::fromStdString(f));
|
||||
}
|
||||
for (const auto& f : obj->getVectorVariables()) {
|
||||
ui->cb_vectors->addItem(QString::fromStdString(f));
|
||||
}
|
||||
|
||||
QStringList qOperators;
|
||||
for (const auto& o : calculatorOperators) {
|
||||
qOperators << QString::fromStdString(o);
|
||||
}
|
||||
ui->cb_operators->addItems(qOperators);
|
||||
|
||||
ui->cb_scalars->setCurrentIndex(-1);
|
||||
ui->cb_vectors->setCurrentIndex(-1);
|
||||
ui->cb_operators->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
TaskPostCalculator::~TaskPostCalculator() = default;
|
||||
|
||||
void TaskPostCalculator::setupConnections()
|
||||
{
|
||||
connect(ui->dsb_replacement_value,
|
||||
qOverload<double>(&QDoubleSpinBox::valueChanged),
|
||||
this,
|
||||
&TaskPostCalculator::onReplacementValueChanged);
|
||||
connect(ui->ckb_replace_invalid,
|
||||
&QCheckBox::toggled,
|
||||
this,
|
||||
&TaskPostCalculator::onReplaceInvalidChanged);
|
||||
connect(ui->cb_scalars,
|
||||
qOverload<int>(&QComboBox::activated),
|
||||
this,
|
||||
&TaskPostCalculator::onScalarsActivated);
|
||||
connect(ui->cb_vectors,
|
||||
qOverload<int>(&QComboBox::activated),
|
||||
this,
|
||||
&TaskPostCalculator::onVectorsActivated);
|
||||
connect(ui->cb_operators,
|
||||
qOverload<int>(&QComboBox::activated),
|
||||
this,
|
||||
&TaskPostCalculator::onOperatorsActivated);
|
||||
}
|
||||
|
||||
void TaskPostCalculator::onReplaceInvalidChanged(bool state)
|
||||
{
|
||||
auto obj = static_cast<Fem::FemPostCalculatorFilter*>(getObject());
|
||||
obj->ReplaceInvalid.setValue(state);
|
||||
ui->dsb_replacement_value->setEnabled(state);
|
||||
recompute();
|
||||
}
|
||||
|
||||
void TaskPostCalculator::onReplacementValueChanged(double value)
|
||||
{
|
||||
auto obj = static_cast<Fem::FemPostCalculatorFilter*>(getObject());
|
||||
obj->ReplacementValue.setValue(value);
|
||||
recompute();
|
||||
}
|
||||
|
||||
void TaskPostCalculator::onScalarsActivated(int index)
|
||||
{
|
||||
QString item = ui->cb_scalars->itemText(index);
|
||||
ui->let_function->insert(item);
|
||||
}
|
||||
|
||||
void TaskPostCalculator::onVectorsActivated(int index)
|
||||
{
|
||||
QString item = ui->cb_vectors->itemText(index);
|
||||
ui->let_function->insert(item);
|
||||
}
|
||||
|
||||
void TaskPostCalculator::onOperatorsActivated(int index)
|
||||
{
|
||||
QString item = ui->cb_operators->itemText(index);
|
||||
ui->let_function->insert(item);
|
||||
}
|
||||
|
||||
void TaskPostCalculator::apply()
|
||||
{
|
||||
auto obj = getObject<Fem::FemPostCalculatorFilter>();
|
||||
std::string function = ui->let_function->text().toStdString();
|
||||
std::string name = ui->let_field_name->text().toStdString();
|
||||
obj->Function.setValue(function);
|
||||
obj->FieldName.setValue(name);
|
||||
recompute();
|
||||
|
||||
auto view = getTypedView<ViewProviderFemPostCalculator>();
|
||||
view->Field.setValue(obj->FieldName.getValue());
|
||||
}
|
||||
|
||||
#include "moc_TaskPostBoxes.cpp"
|
||||
|
||||
Reference in New Issue
Block a user