Commit ce73db1c authored by Pierre Fernique's avatar Pierre Fernique

Merge branch 'develop' of https://gitlab.inria.fr/dtk/dtk-visualization into...

Merge branch 'develop' of https://gitlab.inria.fr/dtk/dtk-visualization into bug/enforce_active_scalar
parents 66f0a42c 8749c2f0
......@@ -44,6 +44,7 @@ class dtkVisualizationDecoratorClutEditorPrivate
{
public:
enum Support {
Unknown, //so that if not specified, it is unknown per defaut
Point,
Cell
};
......@@ -66,8 +67,11 @@ public:
QHash<QString, Support> supports;
public:
QComboBox *fields_box = nullptr;
QCheckBox *display_scalarbar = nullptr;
QComboBox *fields_box = nullptr;
QCheckBox *fixed_range = nullptr;
QLineEdit *min_range = nullptr;
QLineEdit *max_range = nullptr;
};
// ///////////////////////////////////////////////////////////////////
......@@ -103,6 +107,21 @@ void dtkVisualizationDecoratorClutEditor::draw(void)
Q_ASSERT(this->canvas()->renderer());
//update the color depending of the range
if(!d->fixed_range->isChecked()) {
double *range;
if (d->supports[d->current_field_name] == dtkVisualizationDecoratorClutEditorPrivate::Support::Point) {
d->dataset->GetPointData()->SetActiveScalars(qPrintable(d->current_field_name));
range = d->dataset->GetPointData()->GetScalars()->GetRange();
} else if (d->supports[d->current_field_name] == dtkVisualizationDecoratorClutEditorPrivate::Support::Cell) {
d->dataset->GetCellData()->SetActiveScalars(qPrintable(d->current_field_name));
range = d->dataset->GetCellData()->GetScalars()->GetRange();
}
this->setCurrentRange(range[0], range[1]);
}
}
void dtkVisualizationDecoratorClutEditor::setData(const QVariant& data)
......@@ -232,8 +251,54 @@ void dtkVisualizationDecoratorClutEditor::setCanvas(dtkVisualizationCanvas *canv
h_layout->addWidget(new QLabel("Field:"));
h_layout->addWidget(d->fields_box);
QWidget *scalar_w = new QWidget;
scalar_w->setLayout(h_layout);
QWidget *widget_bar_and_fields = new QWidget;
widget_bar_and_fields->setLayout(h_layout);
d->fixed_range = new QCheckBox;
d->fixed_range->setChecked(Qt::Unchecked);
QDoubleValidator *double_validator = new QDoubleValidator;
double_validator->setDecimals(3);
d->min_range = new QLineEdit;
d->max_range = new QLineEdit;
d->min_range->setValidator(double_validator);
d->max_range->setValidator(double_validator);
connect(d->min_range, &QLineEdit::textEdited, [=] (QString new_min) {
d->fixed_range->setChecked(Qt::Checked);
this->setCurrentRange(new_min.toDouble(), d->max_range->text().toDouble());
});
connect(d->max_range, &QLineEdit::textEdited, [=] (QString new_max) {
d->fixed_range->setChecked(Qt::Checked);
this->setCurrentRange(d->min_range->text().toDouble(), new_max.toDouble());
});
//restore default ranges when unchecked
connect(d->fixed_range, &QCheckBox::stateChanged, [=] (int state) {
if(state == Qt::Unchecked) {
double *range;
if (d->supports[d->current_field_name] == dtkVisualizationDecoratorClutEditorPrivate::Support::Point) {
d->dataset->GetPointData()->SetActiveScalars(qPrintable(d->current_field_name));
range = d->dataset->GetPointData()->GetScalars()->GetRange();
} else if (d->supports[d->current_field_name] == dtkVisualizationDecoratorClutEditorPrivate::Support::Cell) {
d->dataset->GetCellData()->SetActiveScalars(qPrintable(d->current_field_name));
range = d->dataset->GetCellData()->GetScalars()->GetRange();
}
this->setCurrentRange(range[0], range[1]);
}
});
QHBoxLayout *h_layout_range = new QHBoxLayout;
h_layout_range->setAlignment(Qt::AlignLeft);
h_layout_range->addWidget(new QLabel("Fixed Range:"));
h_layout_range->addWidget(d->fixed_range);
h_layout_range->addWidget(d->min_range);
h_layout_range->addWidget(d->max_range);
QWidget *range_widget = new QWidget;
range_widget->setLayout(h_layout_range);
connect(d->fields_box, &QComboBox::currentTextChanged,
this, &dtkVisualizationDecoratorClutEditor::setCurrentFieldName);
......@@ -243,17 +308,19 @@ void dtkVisualizationDecoratorClutEditor::setCanvas(dtkVisualizationCanvas *canv
dtkWidgetsOverlayPaneItem *pane_item = new dtkWidgetsOverlayPaneItem;
pane_item->setTitle("Clut Editor");
pane_item->addWidget(scalar_w);
pane_item->addWidget(widget_bar_and_fields);
pane_item->addWidget(clut_editor);
canvas_pane->addWidget(pane_item);
pane_item->addWidget(range_widget);
canvas_pane->addWidget(pane_item);
// clut_editor connections
connect(this, &dtkVisualizationDecoratorClutEditor::currentRangeChanged, [=] (double min, double max) {
//clut_editor->blockSignals(true);
clut_editor->setRange(min, max);
// clut_editor->blockSignals(false);
if(!d->fixed_range->isChecked()) {
d->min_range->setText(QString::number(min));
d->max_range->setText(QString::number(max));
}
});
connect(this, &dtkVisualizationDecoratorClutEditor::currentColorTransferFunctionChanged, [=] (vtkColorTransferFunction *color_transfer_function) {
......@@ -415,9 +482,13 @@ void dtkVisualizationDecoratorClutEditor::setCurrentRange(double min, double max
return;
}
d->ranges[d->current_field_name] = qMakePair(min, max);
emit this->currentRangeChanged(min, max);
if(min < max) {
d->ranges[d->current_field_name] = qMakePair(min, max);
emit this->currentRangeChanged(min, max);
} else {
qWarning() << "trying to set min > max : " << min << max;
qWarning() << "I wont do it .. :)";
}
}
//
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment