Commit 1608d0f2 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Modify range handlind and some beautifying stuff.

parent 8df56839
......@@ -165,9 +165,29 @@ public:
public:
QVector<dtkVisualizationWidgetsScalarControl*> sphere_seed_controls;
QVector<dtkVisualizationWidgetsScalarControl*> line_seed_controls;
void updateSeedControls();
public:
void updateSeedControls(void);
};
// ///////////////////////////////////////////////////////////////////
void dtkVisualizationDecoratorVectorStreamTracerPrivate::updateSeedControls(void)
{
const bool is_sphere = (cb_seed_type->currentText() == "Sphere");
for (auto* sphere_control : sphere_seed_controls) {
sphere_control->setVisible(is_sphere);
}
for (auto* line_control : line_seed_controls) {
line_control->setVisible(!is_sphere);
}
if (is_sphere) {
source_sphere_observer->Execute(source_sphere_widget, vtkCommand::InteractionEvent, nullptr);
} else {
source_line_observer->Execute(source_line_widget, vtkCommand::InteractionEvent, nullptr);
}
}
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationDecoratorVectorStreamTracer implementation
// ///////////////////////////////////////////////////////////////////
......@@ -241,6 +261,8 @@ dtkVisualizationDecoratorVectorStreamTracer::dtkVisualizationDecoratorVectorStre
//////////
// Inspectors creation and setup
d_func()->show_actor_cb->setObjectName("Streamlines");
d->cb_show_seed = new QCheckBox;
d->cb_show_seed->setObjectName("Display");
d->cb_show_seed->setChecked(true);
......@@ -262,7 +284,7 @@ dtkVisualizationDecoratorVectorStreamTracer::dtkVisualizationDecoratorVectorStre
d->cb_integrator_type->addItem("RK2");
d->cb_integrator_type->addItem("RK4");
d->cb_integrator_type->addItem("RK45");
d->cb_integrator_type->setCurrentIndex(0);
d->cb_integrator_type->setCurrentIndex(1);
d->cb_integrator_type->setObjectName("Type");
d->sp_integrator_max_steps = new QSpinBox;
......@@ -390,58 +412,51 @@ dtkVisualizationDecoratorVectorStreamTracer::dtkVisualizationDecoratorVectorStre
this->draw();
});
for (int i=0; i<6; ++i)
{
for (auto* seed_controls: { &d->sphere_seed_controls, &d->line_seed_controls })
{
if (i >= seed_controls->size())
{
for (int i=0; i<6; ++i) {
for (auto* seed_controls : { &d->sphere_seed_controls, &d->line_seed_controls }) {
if (i >= seed_controls->size()) {
continue;
}
dtkVisualizationWidgetsScalarControl *control = (*seed_controls)[i];
const bool is_sphere = (seed_controls == &d->sphere_seed_controls);
connect(control, QOverload<double>::of(&dtkVisualizationWidgetsScalarControl::valueChanged), [=] (double val)
{
vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New();
if (is_sphere)
{
if (i == 3) // radius
{
d->source_sphere->SetRadius(val);
} else {
double pos[3];
d->source_sphere->GetCenter(pos);
pos[i] = val;
d->source_sphere->SetCenter(pos);
}
d->source_sphere->GetPolyData(data);
} else {
double pos[3];
const int axis = (i % 3);
const bool is_point1 = (i < 3);
if (is_point1)
{
d->source_line->GetPoint1WorldPosition(pos);
} else {
d->source_line->GetPoint2WorldPosition(pos);
}
pos[axis] = val;
if (is_point1)
{
d->source_line->SetPoint1WorldPosition(pos);
} else {
d->source_line->SetPoint2WorldPosition(pos);
}
d->source_line->GetPolyData(data);
}
d->streamtracer->SetSourceData(data);
d->streamtracer->Modified();
this->draw();
});
{
vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New();
if (is_sphere) {
if (i == 3) {// radius
d->source_sphere->SetRadius(val);
} else {
double pos[3];
d->source_sphere->GetCenter(pos);
pos[i] = val;
d->source_sphere->SetCenter(pos);
}
d->source_sphere->GetPolyData(data);
} else {
double pos[3];
const int axis = (i % 3);
const bool is_point1 = (i < 3);
if (is_point1) {
d->source_line->GetPoint1WorldPosition(pos);
} else {
d->source_line->GetPoint2WorldPosition(pos);
}
pos[axis] = val;
if (is_point1) {
d->source_line->SetPoint1WorldPosition(pos);
} else {
d->source_line->SetPoint2WorldPosition(pos);
}
d->source_line->GetPolyData(data);
}
d->streamtracer->SetSourceData(data);
d->streamtracer->Modified();
this->draw();
});
}
}
......@@ -459,7 +474,7 @@ dtkVisualizationDecoratorVectorStreamTracer::dtkVisualizationDecoratorVectorStre
d->line_seed_controls[2],
d->line_seed_controls[3],
d->line_seed_controls[4],
d->line_seed_controls[5],});
d->line_seed_controls[5]});
QWidget *integrator_box = new dtkVisualizationWidgetsCategory("Integrator", {
d->cb_integrator_direction,
d->cb_integrator_type,
......@@ -692,24 +707,5 @@ void dtkVisualizationDecoratorVectorStreamTracer::setColorMap(const QMap<double,
d->mapper->Modified();
}
void dtkVisualizationDecoratorVectorStreamTracerPrivate::updateSeedControls()
{
const bool is_sphere = (cb_seed_type->currentText() == "Sphere");
for (auto* sphere_control : sphere_seed_controls)
{
sphere_control->setVisible(is_sphere);
}
for (auto* line_control : line_seed_controls)
{
line_control->setVisible(!is_sphere);
}
if (is_sphere)
{
source_sphere_observer->Execute(source_sphere_widget, vtkCommand::InteractionEvent, nullptr);
} else {
source_line_observer->Execute(source_line_widget, vtkCommand::InteractionEvent, nullptr);
}
}
//
// dtkVisualizationDecoratorVectorStreamTracer.cpp ends here
......@@ -19,6 +19,7 @@
#include "dtkVisualizationView2D.h"
#include <dtkVisualizationWidgets/dtkVisualizationWidgetsColorMapEditor.h>
#include <dtkFonts/dtkFontAwesome>
#include <dtkLog>
#include <QtGui>
......@@ -63,9 +64,11 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
this->field_components->addItem("Z");
this->field_components->setCurrentIndex(0);
this->fixed_range = new QCheckBox;
this->min_range = new QLineEdit;
this->max_range = new QLineEdit;
this->reset_range = new QPushButton;
this->reset_range->setIcon(dtkFontAwesome::instance()->icon(fa::undo));
this->reset_range->setToolTip("Reset to original range");
this->colormap_editor = new dtkVisualizationWidgetsColorMapEditor;
this->colormap_editor->setObjectName("Color Map");
......@@ -75,7 +78,7 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
QHBoxLayout *h_layout_range = new QHBoxLayout;
QWidget *range_widget = new QWidget;
range_widget->setObjectName("Fixed Range");
range_widget->setObjectName("Range");
//////////
// Inspectors setup
......@@ -89,9 +92,9 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
this->max_range->setValidator(double_validator);
h_layout_range->setAlignment(Qt::AlignLeft);
h_layout_range->addWidget(this->fixed_range);
h_layout_range->addWidget(this->min_range);
h_layout_range->addWidget(this->max_range);
h_layout_range->addWidget(this->reset_range);
range_widget->setLayout(h_layout_range);
......@@ -175,22 +178,6 @@ void dtkVisualizationDecoratorWithClutPrivate::retrieveVectorData(vtkDataSetAttr
range[0] = range[1] = 0;
this->color_transfer_functions[field_name] = this->default_color_map;
// auto&& range_magn = this->ranges[field_name + QString("__Magnitude")];
// field_data->GetArray(i)->GetRange(range_magn.data(), -1);
// this->color_transfer_functions[field_name + QString("__Magnitude")] = this->default_color_map;
// auto&& range_x = this->ranges[field_name + QString("__X")];
// field_data->GetArray(i)->GetRange(range_x.data(), 0);
// this->color_transfer_functions[field_name + QString("__X")] = this->default_color_map;
// auto&& range_y = this->ranges[field_name + QString("__Y")];
// field_data->GetArray(i)->GetRange(range_y.data(), 1);
// this->color_transfer_functions[field_name + QString("__Y")] = this->default_color_map;
// auto&& range_z = this->ranges[field_name + QString("__Z")];
// field_data->GetArray(i)->GetRange(range_z.data(), 2);
// this->color_transfer_functions[field_name + QString("__Z")] = this->default_color_map;
auto opacity_function = vtkSmartPointer<vtkPiecewiseFunction>::New();
opacity_function->RemoveAllPoints();
opacity_function->AddPoint(0, 0.);
......@@ -260,7 +247,7 @@ void dtkVisualizationDecoratorWithClutPrivate::updateRange(void)
{
auto&& range = this->ranges[this->current_field_name];
if (!this->fixed_range->isChecked()) {
if (this->original_range) {
// The following trick gives directly the right index value
// to extract in the GetRange method for the vector case.
int component_id = this->field_components->currentIndex() - 2;
......@@ -364,67 +351,73 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkV
//////////
// Inspectors connections
connect(d->fields_box, &QComboBox::currentTextChanged, [=] (const QString& field_name) {
this->setCurrentFieldName(field_name);
this->saveSettings("field_name", field_name);
this->touch();
});
connect(d->fields_box, &QComboBox::currentTextChanged, [=] (const QString& field_name)
{
this->setCurrentFieldName(field_name);
this->saveSettings("field_name", field_name);
this->touch();
});
connect(d->field_components, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (int component_id)
{
if (d->current_field_component != component_id) {
d->original_range = false;
}
d->current_field_component = component_id;
this->saveSettings("field_component", component_id);
this->saveSettings("original_range", d->original_range);
this->touch();
});
connect(d->min_range, &QLineEdit::editingFinished, [=] ()
{
d->original_range = false;
this->setCurrentRange(d->min_range->text().toDouble(), d->max_range->text().toDouble());
this->saveSettings("range_min", d->min_range->text().toDouble());
this->saveSettings("range_max", d->max_range->text().toDouble());
this->saveSettings("original_range", false);
this->touch();
});
connect(d->max_range, &QLineEdit::editingFinished, [=] ()
{
d->original_range = false;
this->setCurrentRange(d->min_range->text().toDouble(), d->max_range->text().toDouble());
this->saveSettings("range_min", d->min_range->text().toDouble());
this->saveSettings("range_max", d->max_range->text().toDouble());
this->saveSettings("original_range", false);
this->touch();
});
// Restores default ranges
connect(d->reset_range, QOverload<>::of(&QPushButton::released), [=] ()
{
d->original_range = true;
this->saveSettings("original_range", true);
this->touch();
});
connect(d->min_range, &QLineEdit::editingFinished, [=] () {
d->fixed_range->blockSignals(true);
d->fixed_range->setChecked(Qt::Checked);
d->fixed_range->blockSignals(false);
this->setCurrentRange(d->min_range->text().toDouble(), d->max_range->text().toDouble());
this->saveSettings("range_min", d->min_range->text().toDouble());
this->saveSettings("range_max", d->max_range->text().toDouble());
this->touch();
});
connect(d->max_range, &QLineEdit::editingFinished, [=] () {
d->fixed_range->blockSignals(true);
d->fixed_range->setChecked(Qt::Checked);
d->fixed_range->blockSignals(false);
this->setCurrentRange(d->min_range->text().toDouble(), d->max_range->text().toDouble());
this->saveSettings("range_min", d->min_range->text().toDouble());
this->saveSettings("range_max", d->max_range->text().toDouble());
this->touch();
});
// Restores default ranges when unchecked
connect(d->fixed_range, &QCheckBox::stateChanged, [=] (int state) {
this->touch();
this->saveSettings("fixed_range", state == Qt::Checked);
this->draw();
});
connect(d->colormap_editor, &dtkVisualizationWidgetsColorMapEditor::valueChanged,
[=] (const QMap<double, QColor>& val) {
d->color_transfer_functions[d->current_field_name] = d->colormap_editor->name();
d->colormap_editor->blockSignals(true);
this->setColorMap(val);
this->saveSettings("colormap", d->colormap_editor->name());
d->colormap_editor->blockSignals(false);
this->draw();
});
connect(d->show_scalar_bar, &QCheckBox::stateChanged, [=] (int state) {
d->scalar_bar->SetVisibility(state == Qt::Checked);
this->saveSettings("show_scalarbar", state == Qt::Checked);
this->draw();
});
connect(d->colormap_editor, &dtkVisualizationWidgetsColorMapEditor::valueChanged, [=] (const QMap<double, QColor>& val)
{
d->color_transfer_functions[d->current_field_name] = d->colormap_editor->name();
d->colormap_editor->blockSignals(true);
this->setColorMap(val);
this->saveSettings("colormap", d->colormap_editor->name());
d->colormap_editor->blockSignals(false);
this->draw();
});
connect(d->show_scalar_bar, &QCheckBox::stateChanged, [=] (int state)
{
d->scalar_bar->SetVisibility(state == Qt::Checked);
this->saveSettings("show_scalarbar", state == Qt::Checked);
this->draw();
});
}
void dtkVisualizationDecoratorWithClut::restoreSettings(void)
{
QString name = this->objectName();
if (name.isEmpty())
if (name.isEmpty()) {
return;
}
QSettings settings;
settings.beginGroup("canvas");
......@@ -444,14 +437,13 @@ void dtkVisualizationDecoratorWithClut::restoreSettings(void)
d->default_show_scalar_bar = settings.value(name+"_show_scalarbar", false).toBool();
double range_min = settings.value(name+"_range_min", -1.).toDouble();
double range_max = settings.value(name+"_range_max", -1.).toDouble();
bool fixed_range = settings.value(name+"_fixed_range", false).toBool();
bool original_range = settings.value(name+"_original_range", true).toBool();
settings.endGroup();
if (fixed_range && !d->default_field_name.isEmpty() && range_min != -1.0 && range_max != -1.0) {
if (!original_range && !d->default_field_name.isEmpty() && range_min != -1.0 && range_max != -1.0) {
this->setCurrentRange(range_min, range_max);
}
d->fixed_range->setChecked(fixed_range);
d->colormap_editor->blockSignals(true);
d->colormap_editor->setValue(d->default_color_map);
d->colormap_editor->blockSignals(false);
......
......@@ -28,6 +28,7 @@ class dtkVisualizationWidgetsColorMapEditor;
class QComboBox;
class QCheckBox;
class QLineEdit;
class QPushButton;
class vtkColorTransferFunction;
class vtkDataSet;
......@@ -65,9 +66,10 @@ public:
QComboBox *fields_box = nullptr;
QComboBox *field_components = nullptr;
QCheckBox *fixed_range = nullptr;
QPushButton *reset_range = nullptr;
QLineEdit *min_range = nullptr;
QLineEdit *max_range = nullptr;
bool original_range = true;
QCheckBox *show_scalar_bar = nullptr;
QCheckBox *show_actor_cb = nullptr;
......
#include "dtkVisualizationWidgetsCategory.h"
#include <dtkFonts/dtkFontAwesome>
#include <QtWidgets>
// ///////////////////////////////////////////////////////////////////
dtkVisualizationWidgetsCategory::dtkVisualizationWidgetsCategory(const QString& name, const QVector<QWidget*>& widgets, QWidget* parent) : QGroupBox(parent)
{
QLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0,0,0,0);
for (auto *widget: widgets)
{
for (auto *widget: widgets) {
const QString item_name = widget->objectName();
Q_ASSERT_X(item_name.length(), Q_FUNC_INFO, "widget name must not be empty when it is a category item");
QLayout *item_layout = new QHBoxLayout;
......@@ -21,11 +24,13 @@ dtkVisualizationWidgetsCategory::dtkVisualizationWidgetsCategory(const QString&
layout->addWidget(item_box);
item_box->setParent(this);
}
setObjectName(name);
setLayout(layout);
setStyleSheet("QGroupBox { background-color: transparent; margin: 0px; border: transparent; } ");
this->setObjectName(name);
this->setLayout(layout);
this->setStyleSheet("QGroupBox { background-color: transparent; margin: 0px; border: transparent; } ");
}
// ///////////////////////////////////////////////////////////////////
class dtkVisualizationWidgetsScalarControlPrivate
{
public:
......@@ -38,7 +43,7 @@ dtkVisualizationWidgetsScalarControl::dtkVisualizationWidgetsScalarControl(const
{
setObjectName(name);
d->spbox = new QDoubleSpinBox;
d->breset = new QPushButton;
d->breset = new QPushButton(dtkFontAwesome::instance()->icon(fa::undo), QString());
d->reset_value = reset;
QLayout *layout = new QHBoxLayout;
......@@ -48,11 +53,10 @@ dtkVisualizationWidgetsScalarControl::dtkVisualizationWidgetsScalarControl(const
d->spbox->setKeyboardTracking(false);
d->breset->setToolTip("Reset");
layout->addWidget(d->spbox);
layout->addWidget(new QLabel("R"));
layout->addWidget(d->breset);
layout->setContentsMargins(0,0,0,0);
setLayout(layout);
setValue(reset);
this->setLayout(layout);
this->setValue(reset);
connect(d->spbox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double val)
{
emit valueChanged(val);
......@@ -64,7 +68,7 @@ dtkVisualizationWidgetsScalarControl::dtkVisualizationWidgetsScalarControl(const
});
}
dtkVisualizationWidgetsScalarControl::~dtkVisualizationWidgetsScalarControl()
dtkVisualizationWidgetsScalarControl::~dtkVisualizationWidgetsScalarControl(void)
{
delete d;
}
......@@ -80,10 +84,8 @@ void dtkVisualizationWidgetsScalarControl::setResetValue(double value)
void dtkVisualizationWidgetsScalarControl::setVisible(bool visible)
{
QObject *p = parent();
QWidget *w = nullptr;
if (p && (w = dynamic_cast<QWidget*>(p)))
{
QWidget *w = dynamic_cast<QWidget*>(this->parent());
if (w) {
// we apply setVisible() to parent() because
// the parent includes the whole line, with QLabel (prefix, name)
w->setVisible(visible);
......@@ -91,6 +93,8 @@ void dtkVisualizationWidgetsScalarControl::setVisible(bool visible)
QWidget::setVisible(visible);
}
// ///////////////////////////////////////////////////////////////////
dtkVisualizationWidgetsScalarPositiveControl::dtkVisualizationWidgetsScalarPositiveControl(const QString& name, double reset, QWidget *parent) : dtkVisualizationWidgetsScalarControl(name, reset, parent)
{
d->spbox->setMinimum(0);
......
......@@ -3,13 +3,12 @@
#include <dtkVisualizationWidgetsExport>
#include <QGroupBox>
class dtkVisualizationWidgetsScalarControlPrivate;
class DTKVISUALIZATIONWIDGETS_EXPORT dtkVisualizationWidgetsCategory : public QGroupBox
{
public:
dtkVisualizationWidgetsCategory(const QString& name, const QVector<QWidget*>& widgets, QWidget* parent = nullptr);
dtkVisualizationWidgetsCategory(const QString& name, const QVector<QWidget*>& widgets, QWidget* parent = nullptr);
~dtkVisualizationWidgetsCategory(void) = default;
};
class DTKVISUALIZATIONWIDGETS_EXPORT dtkVisualizationWidgetsScalarControl : public QGroupBox
......@@ -17,15 +16,19 @@ class DTKVISUALIZATIONWIDGETS_EXPORT dtkVisualizationWidgetsScalarControl : publ
Q_OBJECT
public:
dtkVisualizationWidgetsScalarControl(const QString& name = "", double reset = 0, QWidget *parent = nullptr);
dtkVisualizationWidgetsScalarControl(const QString& name = "", double reset = 0, QWidget *parent = nullptr);
~dtkVisualizationWidgetsScalarControl(void);
public:
void setValue(double value);
void setResetValue(double value);
virtual ~dtkVisualizationWidgetsScalarControl();
virtual void setVisible(bool visible) override;
void setVisible(bool visible) override;
signals:
void valueChanged(double);
protected:
dtkVisualizationWidgetsScalarControlPrivate *d;
class dtkVisualizationWidgetsScalarControlPrivate *d;
};
class DTKVISUALIZATIONWIDGETS_EXPORT dtkVisualizationWidgetsScalarPositiveControl : public dtkVisualizationWidgetsScalarControl
......
......@@ -206,7 +206,7 @@ dtkVisualizationWidgetsColorMapEditor::dtkVisualizationWidgetsColorMapEditor(QWi
}
d->colormap_table = new dtkVisualizationWidgetsColorMapTable();
d->colormap_table->setFixedHeight(40);
d->colormap_table->setFixedHeight(21);
d->colormap_table->setMinimumWidth(120);
d->stacked_w = new QStackedWidget;
......
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