Commit cff52fb0 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

implement decorators persistency through QSettings.

parent a70b150f
......@@ -57,9 +57,8 @@ public slots:
// dtkVisualizationDecoratorScalarColorMap implementation
// ///////////////////////////////////////////////////////////////////
dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap(void): dtkVisualizationDecoratorWithClut(), d(new dtkVisualizationDecoratorScalarColorMapPrivate())
dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap(const QString& name): dtkVisualizationDecoratorWithClut(name), d(new dtkVisualizationDecoratorScalarColorMapPrivate())
{
this->setObjectName("Scalar ColorMap");
d->mapper = vtkSmartPointer<vtkDataSetMapper>::New();
d->mapper->SetColorModeToMapScalars();
......@@ -67,7 +66,7 @@ dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap
d->actor = vtkSmartPointer<vtkActor>::New();
d->actor->SetMapper(d->mapper);
d->actor->SetVisibility(true);
d->actor->SetVisibility(d_func()->default_visibility);
//////////
// Inspectors creation
......@@ -77,12 +76,17 @@ dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap
//////////
// Inspectors setup
d->show_actor_cb->setChecked(true);
d->show_actor_cb->setChecked(d_func()->default_visibility);
//////////
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_visibility",state == Qt::Checked);
settings.endGroup();
this->setVisibility(state == Qt::Checked);
this->draw();
});
......
......@@ -23,7 +23,7 @@ class DTKVISUALIZATION_EXPORT dtkVisualizationDecoratorScalarColorMap : public d
Q_OBJECT
public:
dtkVisualizationDecoratorScalarColorMap(void);
dtkVisualizationDecoratorScalarColorMap(const QString & name = QString("Scalar ColorMap"));
~dtkVisualizationDecoratorScalarColorMap(void);
public:
......
......@@ -71,6 +71,8 @@ public:
QComboBox *glyphs_source_cb = nullptr;
public:
double default_glyph_size;
QString default_glyph_shape ;
double size_multiplier = 1.;
QHash<QString, double> glyphs_sizes;
QHash<QString, QString> glyphs_sources;
......@@ -80,9 +82,16 @@ public:
// dtkVisualizationDecoratorScalarGlyphs implementation
// ///////////////////////////////////////////////////////////////////
dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(void): dtkVisualizationDecoratorWithClut(), d(new dtkVisualizationDecoratorScalarGlyphsPrivate())
dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(const QString& name): dtkVisualizationDecoratorWithClut(name), d(new dtkVisualizationDecoratorScalarGlyphsPrivate())
{
this->setObjectName("Scalar Glyphs");
QSettings settings;
settings.beginGroup("canvas");
d->default_glyph_size = settings.value(name+"_glyph_size", 1.0).toDouble();
d->default_glyph_shape = settings.value(name+"_glyph_shape", "Sphere").toString();
settings.endGroup();
d->source_arrow = vtkSmartPointer<vtkArrowSource>::New();
d->source_cube = vtkSmartPointer<vtkCubeSource>::New();
......@@ -93,15 +102,14 @@ dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(voi
d->source_sphere->SetThetaResolution(12.);
d->source_sphere->SetPhiResolution(12.);
double default_size = 1.;
d->source_arrow->SetShaftRadius(default_size);
d->source_arrow->SetTipRadius(default_size);
d->source_cube->SetXLength(default_size);
d->source_cube->SetYLength(default_size);
d->source_cube->SetZLength(default_size);
d->source_cylinder->SetRadius(default_size);
d->source_polygon->SetRadius(default_size);
d->source_sphere->SetRadius(default_size);
d->source_arrow->SetShaftRadius(d->default_glyph_size);
d->source_arrow->SetTipRadius(d->default_glyph_size);
d->source_cube->SetXLength(d->default_glyph_size);
d->source_cube->SetYLength(d->default_glyph_size);
d->source_cube->SetZLength(d->default_glyph_size);
d->source_cylinder->SetRadius(d->default_glyph_size);
d->source_polygon->SetRadius(d->default_glyph_size);
d->source_sphere->SetRadius(d->default_glyph_size);
d->cell_centers = vtkSmartPointer<vtkCellCenters>::New();
......@@ -115,11 +123,10 @@ dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(voi
d->mapper->SetColorModeToMapScalars();
d->mapper->SetInterpolateScalarsBeforeMapping(true);
d->mapper->SetScalarModeToUsePointFieldData();
// d->mapper->SetScalarVisibility(true);
d->actor = vtkSmartPointer<vtkActor>::New();
d->actor->SetMapper(d->mapper);
d->actor->SetVisibility(false);
d->actor->SetVisibility(d_func()->default_visibility);
//////////
// Inspectors creation
......@@ -131,7 +138,7 @@ dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(voi
//////////
// Inspectors setup
d->show_actor_cb->setChecked(false);
d->show_actor_cb->setChecked(d_func()->default_visibility);
d->glyphs_size_sb->setMaximum(1000);
d->glyphs_size_sb->setKeyboardTracking(false);
......@@ -146,12 +153,22 @@ dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(voi
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_visibility",state == Qt::Checked);
settings.endGroup();
this->setVisibility(state == Qt::Checked);
this->draw();
});
connect(d->glyphs_size_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double value) {
this->blockSignals(true);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_glyph_size", value);
settings.endGroup();
this->setCurrentGlyphsSize(value);
this->blockSignals(false);
this->draw();
......@@ -166,6 +183,10 @@ dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(voi
connect(d->glyphs_source_cb, &QComboBox::currentTextChanged, [=] (const QString& source) {
this->blockSignals(true);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_glyph_shape", source);
settings.endGroup();
this->setCurrentGlyphsSource(source);
this->blockSignals(false);
this->draw();
......@@ -232,11 +253,11 @@ void dtkVisualizationDecoratorScalarGlyphs::setData(const QVariant& data)
d->glyphs_sizes.clear();
d->glyphs_sources.clear();
for(auto field_name : d_func()->eligible_field_names) {
d->glyphs_sizes[field_name] = 1.;
d->glyphs_sources[field_name] = "Sphere";
d->glyphs_sizes[field_name] = d->default_glyph_size;
d->glyphs_sources[field_name] = d->default_glyph_shape;
}
emit this->currentGlyphsSizeChanged(1.);
emit this->currentGlyphsSourceChanged("Sphere");
emit this->currentGlyphsSizeChanged(d->default_glyph_size);
emit this->currentGlyphsSourceChanged(d->default_glyph_shape);
d_func()->sortEligibleFields();
......
......@@ -23,7 +23,7 @@ class DTKVISUALIZATION_EXPORT dtkVisualizationDecoratorScalarGlyphs : public dtk
Q_OBJECT
public:
dtkVisualizationDecoratorScalarGlyphs(void);
dtkVisualizationDecoratorScalarGlyphs(const QString & name = QString("Scalar Glyphs"));
~dtkVisualizationDecoratorScalarGlyphs(void);
public:
......
......@@ -66,9 +66,8 @@ public:
// dtkVisualizationDecoratorScalarIsolines implementation
// ///////////////////////////////////////////////////////////////////
dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines(void): dtkVisualizationDecoratorWithClut(), d(new dtkVisualizationDecoratorScalarIsolinesPrivate())
dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines(const QString& name): dtkVisualizationDecoratorWithClut(name), d(new dtkVisualizationDecoratorScalarIsolinesPrivate())
{
this->setObjectName("Scalar Isolines");
d->isolines = vtkSmartPointer<vtkContourFilter>::New();
......@@ -88,7 +87,7 @@ dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines
d->show_actor_cb = new QCheckBox;
d->isolines_counts_sb = new QSpinBox;
d->show_actor_cb->setChecked(false);
d->show_actor_cb->setChecked(d_func()->default_visibility);
d->isolines_counts_sb->setValue(10);
d->isolines_counts_sb->setMaximum(10000);
......@@ -97,6 +96,10 @@ dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_visibility",state == Qt::Checked);
settings.endGroup();
this->setVisibility(state == Qt::Checked);
this->draw();
});
......@@ -111,7 +114,7 @@ dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines
d_func()->inspectors << d->show_actor_cb << d->isolines_counts_sb;
this->setVisibility(false);
this->setVisibility(d_func()->default_visibility);
}
dtkVisualizationDecoratorScalarIsolines::~dtkVisualizationDecoratorScalarIsolines(void)
......
......@@ -22,7 +22,7 @@ class DTKVISUALIZATION_EXPORT dtkVisualizationDecoratorScalarIsolines : public d
{
Q_OBJECT
public:
dtkVisualizationDecoratorScalarIsolines(void);
dtkVisualizationDecoratorScalarIsolines(const QString & name = QString("Scalar Isolines"));
~dtkVisualizationDecoratorScalarIsolines(void);
public:
......
......@@ -79,9 +79,8 @@ public:
// dtkVisualizationDecoratorVectorStreamlines implementation
// ///////////////////////////////////////////////////////////////////
dtkVisualizationDecoratorVectorStreamlines::dtkVisualizationDecoratorVectorStreamlines(void): dtkVisualizationDecoratorWithClut(), d(new dtkVisualizationDecoratorVectorStreamlinesPrivate())
dtkVisualizationDecoratorVectorStreamlines::dtkVisualizationDecoratorVectorStreamlines(const QString& name): dtkVisualizationDecoratorWithClut(name), d(new dtkVisualizationDecoratorVectorStreamlinesPrivate())
{
this->setObjectName("Vector Streamlines 2D");
vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
matrix->Identity();
......@@ -105,7 +104,7 @@ dtkVisualizationDecoratorVectorStreamlines::dtkVisualizationDecoratorVectorStrea
d->actor = vtkSmartPointer<vtkActor>::New();
d->actor->SetMapper(d->mapper);
d->actor->SetVisibility(false);
d->actor->SetVisibility(d_func()->default_visibility);
d->actor->GetProperty()->SetColor(0, 0, 0);
d->actor->GetProperty()->SetLineWidth(3);
......@@ -125,27 +124,30 @@ dtkVisualizationDecoratorVectorStreamlines::dtkVisualizationDecoratorVectorStrea
d->show_actor_cb = new QCheckBox;
d->show_source_actor_cb = new QCheckBox;
d->show_actor_cb->setChecked(false);
d->show_source_actor_cb->setChecked(false);
d->show_actor_cb->setChecked(d_func()->default_visibility);
d->show_source_actor_cb->setChecked(d_func()->default_visibility);
//////////
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
if (state == Qt::Checked) {
this->show();
} else {
this->hide();
}
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_visibility",state == Qt::Checked);
settings.endGroup();
this->setVisibility(state == Qt::Checked);
this->draw();
});
connect(d->show_source_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
d->source_actor->SetVisibility(state == Qt::Checked);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
this->draw();
// FIXME: is it ok to replace this by draw() ?
// if (this->canvas() && this->canvas()->interactor()) {
// this->canvas()->interactor()->Render();
// this->canvas()->renderer()->GetRenderWindow()->Render();
// }
});
d->show_actor_cb->setObjectName("Display");
......@@ -250,16 +252,10 @@ void dtkVisualizationDecoratorVectorStreamlines::unsetCanvas(void)
d_func()->view = nullptr;
}
void dtkVisualizationDecoratorVectorStreamlines::show(void)
void dtkVisualizationDecoratorVectorStreamlines::setVisibility(bool visible)
{
d->actor->SetVisibility(true);
this->draw();
}
void dtkVisualizationDecoratorVectorStreamlines::hide(void)
{
d->actor->SetVisibility(false);
this->draw();
d->actor->SetVisibility(visible);
dtkVisualizationDecoratorWithClut::setVisibility(visible);
}
bool dtkVisualizationDecoratorVectorStreamlines::setCurrentFieldName(const QString& field_name)
......
......@@ -22,7 +22,7 @@ class DTKVISUALIZATION_EXPORT dtkVisualizationDecoratorVectorStreamlines : publi
{
Q_OBJECT
public:
dtkVisualizationDecoratorVectorStreamlines(void);
dtkVisualizationDecoratorVectorStreamlines(const QString &name = QString("Vector Streamlines 2D"));
~dtkVisualizationDecoratorVectorStreamlines(void);
public:
......@@ -35,8 +35,7 @@ protected:
void setColorMap(const QMap<double, QColor>&) override;
public:
void show(void);
void hide(void);
void setVisibility(bool visible) override;
protected:
bool isCurrentFieldUniform(void);
......
......@@ -68,7 +68,6 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
//////////
// Inspectors setup
this->colormap_editor->setValue("inferno");
QDoubleValidator *double_validator = new QDoubleValidator;
double_validator->setDecimals(9);
......@@ -131,7 +130,7 @@ void dtkVisualizationDecoratorWithClutPrivate::retrieveScalarData(vtkDataSetAttr
auto&& range = this->ranges[field_name];
field_data->GetArray(i)->GetRange(range.data());
this->color_transfer_functions[field_name] = "inferno";
this->color_transfer_functions[field_name] = this->default_color_map;
auto opacity_function = vtkSmartPointer<vtkPiecewiseFunction>::New();
opacity_function->RemoveAllPoints();
......@@ -156,7 +155,7 @@ void dtkVisualizationDecoratorWithClutPrivate::retrieveVectorData(vtkDataSetAttr
auto&& range = this->ranges[field_name];
field_data->GetArray(i)->GetRange(range.data(), -1);
this->color_transfer_functions[field_name] = "inferno";
this->color_transfer_functions[field_name] = this->default_color_map;
auto opacity_function = vtkSmartPointer<vtkPiecewiseFunction>::New();
opacity_function->RemoveAllPoints();
......@@ -213,7 +212,11 @@ void dtkVisualizationDecoratorWithClutPrivate::sortEligibleFields(void)
this->fields_box->clear();
this->fields_box->addItems(this->eligible_field_names);
}
this->fields_box->setCurrentText(this->eligible_field_names.first());
if (this->default_field_name.isEmpty()) {
this->fields_box->setCurrentText(this->eligible_field_names.first());
} else {
this->fields_box->setCurrentText(this->default_field_name);
}
}
}
......@@ -221,8 +224,22 @@ void dtkVisualizationDecoratorWithClutPrivate::sortEligibleFields(void)
// dtkVisualizationDecoratorWithClut implementation
// ///////////////////////////////////////////////////////////////////
dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkVisualizationDecorator(), d(new dtkVisualizationDecoratorWithClutPrivate)
dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(const QString& name): dtkVisualizationDecorator(), d(new dtkVisualizationDecoratorWithClutPrivate)
{
this->setObjectName(name);
QSettings settings;
settings.beginGroup("canvas");
d->default_visibility = settings.value(name+"_visibility", true).toBool();
d->default_field_name = settings.value(name+"_field_name").toString();
d->default_color_map = settings.value(name+"_colormap", "inferno").toString();
bool show_scalar_bar = settings.value(name+"_show_scalarbar", false).toBool();
settings.endGroup();
d->colormap_editor->setValue(d->default_color_map);
d->scalar_bar->SetVisibility(show_scalar_bar);
//////////
// Inspectors connections
......@@ -230,6 +247,12 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkV
connect(d->fields_box, &QComboBox::currentTextChanged, [=] (const QString& field_name) {
d->fields_box->blockSignals(true);
this->setCurrentFieldName(field_name);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_field_name", field_name);
settings.endGroup();
d->fields_box->blockSignals(false);
this->touch();
});
......@@ -261,12 +284,22 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkV
d->color_transfer_functions[d->current_field_name] = d->colormap_editor->name();
d->colormap_editor->blockSignals(true);
this->setColorMap(val);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_colormap", d->colormap_editor->name());
settings.endGroup();
d->colormap_editor->blockSignals(false);
this->draw();
});
connect(d->show_scalar_bar, &QCheckBox::stateChanged, [=] (int state) {
d->scalar_bar->SetVisibility(state == Qt::Checked);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_show_scalarbar", state == Qt::Checked);
settings.endGroup();
this->draw();
});
}
......@@ -343,7 +376,7 @@ bool dtkVisualizationDecoratorWithClut::setCurrentFieldName(const QString& field
d->fields_box->setCurrentText(d->current_field_name);
d->scalar_bar->UnconstrainedFontSizeOn();
d->scalar_bar->SetTitle(qPrintable(d->current_field_name));
d->scalar_bar->SetTitle(qPrintable(this->objectName()+"/"+d->current_field_name));
d->scalar_bar->Modified();
this->touch();
......
......@@ -36,7 +36,7 @@ public:
};
public:
dtkVisualizationDecoratorWithClut(void);
dtkVisualizationDecoratorWithClut(const QString & name = QString());
~dtkVisualizationDecoratorWithClut(void);
public:
......
......@@ -74,6 +74,9 @@ public:
public:
QStringList eligible_field_names;
QString current_field_name;
QString default_field_name;
QString default_color_map;
bool default_visibility = true;
public:
vtkSmartPointer<vtkColorTransferFunction> color_function;
......
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