10 #include "ui_colorScaleEditorDlg.h"
27 #include <QColorDialog>
28 #include <QFileDialog>
29 #include <QHBoxLayout>
30 #include <QInputDialog>
35 #include <QMessageBox>
36 #include <QPlainTextEdit>
52 m_colorScale(currentScale),
54 m_associatedSF(nullptr),
56 m_minAbsoluteVal(0.0),
57 m_maxAbsoluteVal(1.0),
59 m_ui(new
Ui::ColorScaleEditorDlg) {
64 m_ui->colorScaleEditorFrame->setLayout(
new QHBoxLayout());
65 m_ui->colorScaleEditorFrame->layout()->setContentsMargins(0, 0, 0, 0);
69 connect(
m_ui->rampComboBox, SIGNAL(activated(
int)),
this,
73 connect(
m_ui->exportToolButton, SIGNAL(clicked()),
this,
75 connect(
m_ui->importToolButton, SIGNAL(clicked()),
this,
79 connect(
m_ui->renameToolButton, SIGNAL(clicked()),
this,
81 connect(
m_ui->saveToolButton, SIGNAL(clicked()),
this,
83 connect(
m_ui->deleteToolButton, SIGNAL(clicked()),
this,
85 connect(
m_ui->copyToolButton, SIGNAL(clicked()),
this,
87 connect(
m_ui->newToolButton, SIGNAL(clicked()),
this,
89 connect(
m_ui->scaleModeComboBox, SIGNAL(activated(
int)),
this,
99 connect(
m_ui->deleteSliderToolButton, SIGNAL(clicked()),
this,
101 connect(
m_ui->colorToolButton, SIGNAL(clicked()),
this,
103 connect(
m_ui->valueDoubleSpinBox, SIGNAL(valueChanged(
double)),
this,
107 connect(
m_ui->customLabelsGroupBox, SIGNAL(toggled(
bool)),
this,
109 connect(
m_ui->customLabelsPlainTextEdit, SIGNAL(textChanged()),
this,
113 connect(
m_ui->applyPushButton, SIGNAL(clicked()),
this, SLOT(
onApply()));
115 connect(
m_ui->closePushButton, SIGNAL(clicked()),
this, SLOT(
onClose()));
144 m_ui->rampComboBox->blockSignals(
true);
145 m_ui->rampComboBox->clear();
149 for (ccColorScalesManager::ScalesMap::const_iterator it =
152 m_ui->rampComboBox->addItem((*it)->getName(), (*it)->getUuid());
161 m_ui->rampComboBox->setCurrentIndex(pos);
163 m_ui->rampComboBox->blockSignals(
false);
167 QString UUID =
m_ui->rampComboBox->itemData(pos).toString();
194 QMessageBox::StandardButton button = QMessageBox::warning(
195 this,
"Current scale has been modified",
196 "Do you want to save modifications?",
197 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
198 QMessageBox::Cancel);
199 if (button == QMessageBox::Yes) {
203 }
else if (button == QMessageBox::Cancel) {
210 return (
m_ui->scaleModeComboBox->currentIndex() == 0 ?
true :
false);
222 m_ui->rampComboBox->blockSignals(
true);
223 m_ui->rampComboBox->setCurrentIndex(pos);
224 m_ui->rampComboBox->blockSignals(
false);
240 m_ui->rampComboBox->blockSignals(
true);
241 m_ui->rampComboBox->setCurrentIndex(pos);
242 m_ui->rampComboBox->blockSignals(
false);
250 m_ui->colorScaleParametersFrame->setEnabled(!isLocked);
251 m_ui->exportToolButton->setEnabled(!isLocked);
252 m_ui->lockWarningLabel->setVisible(isLocked);
253 m_ui->selectedSliderGroupBox->setEnabled(!isLocked);
255 m_ui->customLabelsGroupBox->blockSignals(
true);
256 m_ui->customLabelsGroupBox->setEnabled(!isLocked);
257 m_ui->customLabelsGroupBox->blockSignals(
false);
270 assert(isLocked ==
true);
278 if (customLabels.empty()) {
279 m_ui->customLabelsPlainTextEdit->blockSignals(
true);
280 m_ui->customLabelsPlainTextEdit->setPlainText(
282 m_ui->customLabelsPlainTextEdit->blockSignals(
false);
286 for (ccColorScale::LabelSet::const_iterator it =
287 customLabels.begin();
288 it != customLabels.end(); ++it, ++index) {
289 if (index != 0) text += QString(
"\n");
290 text += QString::number(it->value,
'f', 6);
291 if (!it->text.isEmpty()) {
292 text +=
" \"" + it->text +
'\"';
295 m_ui->customLabelsPlainTextEdit->blockSignals(
true);
296 m_ui->customLabelsPlainTextEdit->setPlainText(text);
297 m_ui->customLabelsPlainTextEdit->blockSignals(
false);
299 m_ui->customLabelsGroupBox->blockSignals(
true);
300 m_ui->customLabelsGroupBox->setChecked(!customLabels.empty());
301 m_ui->customLabelsGroupBox->blockSignals(
false);
310 m_ui->scaleModeComboBox->setCurrentIndex(isRelative ? 0 : 1);
311 m_ui->valueDoubleSpinBox->setSuffix(isRelative ? QString(
" %") : QString());
312 m_ui->valueDoubleSpinBox->blockSignals(
true);
314 m_ui->valueDoubleSpinBox->setRange(0.0, 100.0);
316 m_ui->valueDoubleSpinBox->setRange(-1.0e9, 1.0e9);
317 m_ui->valueDoubleSpinBox->blockSignals(
false);
326 m_ui->selectedSliderGroupBox->setEnabled(
329 m_ui->deleteSliderToolButton->setEnabled(
333 m_ui->valueDoubleSpinBox->blockSignals(
true);
334 m_ui->valueDoubleSpinBox->setValue(0.0);
335 m_ui->valueDoubleSpinBox->blockSignals(
false);
337 m_ui->valueLabel->setVisible(
false);
357 m_ui->valueDoubleSpinBox->blockSignals(
true);
358 m_ui->valueDoubleSpinBox->setValue(relativePos * 100.0);
359 m_ui->valueDoubleSpinBox->blockSignals(
false);
365 m_ui->valueLabel->setText(QString(
"(%1)").arg(actualValue));
366 m_ui->valueLabel->setVisible(
true);
368 m_ui->valueLabel->setVisible(
false);
372 m_ui->valueDoubleSpinBox->setEnabled(
373 index > 0 && index < m_scaleWidget->getStepCount() - 1);
377 double absoluteValue =
381 m_ui->valueDoubleSpinBox->blockSignals(
true);
382 m_ui->valueDoubleSpinBox->setValue(absoluteValue);
383 m_ui->valueDoubleSpinBox->blockSignals(
false);
384 m_ui->valueDoubleSpinBox->setEnabled(
true);
387 m_ui->valueLabel->setText(
388 QString(
"(%1 %)").arg(relativePos * 100.0));
389 m_ui->valueLabel->setVisible(
true);
398 if (selectedIndex >= 1 &&
410 if (selectedIndex < 0)
return;
416 QColor newCol = QColorDialog::getColor(slider->
getColor(),
this);
417 if (newCol.isValid()) {
428 if (selectedIndex < 0)
return;
436 assert(selectedIndex != 0 &&
440 assert(value >= 0.0 && value <= 1.0);
470 newSliders->front()->getRelativePos();
472 newSliders->back()->getRelativePos();
476 int newSelectedIndex = -1;
479 for (
int i = 0; i < newSliders->size(); ++i) {
480 double absoluteVal = newSliders->at(i)->getRelativePos();
481 if (absoluteVal == value) newSelectedIndex = i;
483 newSliders->at(i)->setRelativePos(relativePos);
498 assert(
m_ui->customLabelsGroupBox->isChecked());
501 QString text =
m_ui->customLabelsPlainTextEdit->toPlainText();
504 if (items.size() < 2) {
510 for (
int i = 0; i < items.size(); ++i) {
512 double d = items[i].toDouble(&ok);
518 }
catch (
const std::bad_alloc&) {
519 CVLog::Error(
"Not enough memory to save the custom labels!");
528 QString text =
m_ui->customLabelsPlainTextEdit->toPlainText();
531 if (items.size() < 2) {
533 CVLog::Error(
"Not enough labels defined (2 at least are required)");
537 for (
int i = 0; i < items.size(); ++i) {
539 items[i].toDouble(&ok);
543 QString(
"Invalid label value: '%1'").arg(items[i]));
558 QString previousText =
m_ui->customLabelsPlainTextEdit->toPlainText();
561 m_ui->customLabelsPlainTextEdit->blockSignals(
true);
562 m_ui->customLabelsPlainTextEdit->clear();
563 m_ui->customLabelsPlainTextEdit->blockSignals(
false);
568 m_ui->customLabelsPlainTextEdit->setPlainText(
584 double minVal, maxVal;
586 scale->setAbsolute(minVal, maxVal);
605 if (
m_ui->customLabelsGroupBox->isChecked() &&
621 if ((!isRelative || isRelative != wasRelative) &&
m_mainApp &&
626 for (
size_t i = 0; i < clouds.size(); ++i) {
653 if (
m_ui->customLabelsGroupBox->isChecked()) {
671 QInputDialog::getText(
this,
"Scale name",
"Name", QLineEdit::Normal,
673 if (!newName.isNull()) {
679 m_ui->rampComboBox->setItemText(pos, newName);
690 if (QMessageBox::warning(
this,
"Delete scale",
"Are you sure?",
691 QMessageBox::Yes | QMessageBox::No,
692 QMessageBox::No) == QMessageBox::No) {
700 int currentIndex =
m_ui->rampComboBox->currentIndex();
701 if (currentIndex == 0)
703 else if (currentIndex > 0)
710 m_ui->rampComboBox->itemData(currentIndex).toString());
756 QString currentPath =
761 QString
filename = QFileDialog::getSaveFileName(
this,
"Select output file",
762 currentPath,
"*.xml");
775 QString(
"[ColorScale] Scale '%1' successfully exported in '%2'")
784 QString currentPath =
789 QString
filename = QFileDialog::getOpenFileName(
790 this,
"Select color scale file", currentPath,
"*.xml");
808 QString message =
"A color scale with the same UUID";
809 if (otherScale->getName() == scale->getName())
810 message += QString(
" and the same name (%1)")
811 .arg(scale->getName());
812 message +=
" is already in store!";
815 "Do you want to force the importation of this new "
816 "scale? (a new UUID will be generated)";
818 if (QMessageBox::question(
this,
"UUID conflict", message,
820 QMessageBox::No) == QMessageBox::No) {
822 "[ccColorScaleEditorDialog::importScale] "
823 "Importation cancelled due to a conflicting UUID "
824 "(color scale may already be in store)");
828 scale->setUuid(QUuid::createUuid().
toString());
832 CVLog::Print(QString(
"[ccColorScaleEditorDialog::importScale] "
833 "Color scale '%1' successfully imported")
834 .arg(scale->getName()));
QStringList qtCompatSplitRegex(const QString &str, const QString &pattern, Qt::SplitBehavior behavior=Qt::KeepEmptyParts)
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Print(const char *format,...)
Prints out a formatted message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Color scale element as a widget.
Set of color scale elements (widgets)
void onCustomLabelsListChanged()
void setModified(bool state)
Sets modification flag state.
void relativeModeChanged(int)
void setAssociatedScalarField(ccScalarField *sf)
Sets associated scalar field (optional)
void toggleCustomLabelsList(bool)
double m_maxAbsoluteVal
Current max boundary for absolute scales.
ccScalarField * m_associatedSF
Associated scalar field.
double m_minAbsoluteVal
Current min boundary for absolute scales.
ccColorScalesManager * m_manager
Color scale manager.
ecvMainAppInterface * m_mainApp
Associated application (interface)
ccColorScale::Shared m_colorScale
Current active color scale.
bool exportCustomLabelsList(ccColorScale::LabelSet &labels)
Exports the custom labels list.
void changeSelectedStepValue(double)
void renameCurrentScale()
void exportCurrentScale()
bool checkCustomLabelsList(bool showWarnings)
Checks the custom labels list.
void colorScaleChanged(int)
bool m_modified
Modification flag.
bool canChangeCurrentScale()
If the current scale has been modified, ask the user what to do.
void changeSelectedStepColor()
void updateMainComboBox()
Updates main combox box with color scales manager.
void setScaleModeToRelative(bool isRelative)
ccColorScaleEditorWidget * m_scaleWidget
Color scale editor widget.
void deleteCurrentScale()
Ui::ColorScaleEditorDlg * m_ui
void deletecSelectedStep()
void setActiveScale(ccColorScale::Shared currentScale)
Sets active scale.
ccColorScaleEditorDialog(ccColorScalesManager *manager, ecvMainAppInterface *mainApp, ccColorScale::Shared currentScale=ccColorScale::Shared(nullptr), QWidget *parent=nullptr)
Default constructor.
bool isRelativeMode() const
Color scale element: one value + one color.
const QColor & getColor() const
Returns color.
double getRelativePos() const
Returns step position (relative to scale boundaries)
static Shared LoadFromXML(QString filename)
Loads a color scale from an XML file.
static ccColorScale::Shared Create(const QString &name)
Creates a new color scale (with auto-generated unique id)
QSharedPointer< ccColorScale > Shared
Shared pointer type.
std::set< Label > LabelSet
Type of a list of custom labels.
Color scales manager/container.
ccColorScale::Shared getScale(QString UUID) const
Returns a color scale based on its UUID.
void addScale(ccColorScale::Shared scale)
Adds a new color scale.
ScalesMap & map()
Access to the internal map.
void removeScale(QString UUID)
Removes a color scale.
ccColorScale::Shared getDefaultScale(DEFAULT_SCALES scale) const
Returns a pre-defined color scale.
static ccColorScalesManager * GetUniqueInstance()
Returns unique instance.
ccHObject * getParent() const
Returns parent object.
unsigned filterChildren(Container &filteredChildren, bool recursive=false, CV_CLASS_ENUM filter=CV_TYPES::OBJECT, bool strict=false) const
Collects the children corresponding to a certain pattern.
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
bool isKindOf(CV_CLASS_ENUM type) const
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
ccScalarField * getCurrentDisplayedScalarField() const
Returns the currently displayed scalar (or 0 if none)
static void SetButtonColor(QAbstractButton *button, const QColor &col)
Sets a button background color.
A scalar field associated to display-related parameters.
const ccColorScale::Shared & getColorScale() const
Returns associated color scale.
void setColorScale(ccColorScale::Shared scale)
Sets associated color scale.
ScalarField * getScalarField(int index) const
Returns a pointer to a specific scalar field.
unsigned getNumberOfScalarFields() const
Returns the number of associated (and active) scalar fields.
ScalarType getMin() const
Returns the minimum value.
ScalarType getMax() const
Returns the maximum value.
Main application interface (for plugins)
virtual ccHObject * dbRootObject()=0
Returns DB root (as a ccHObject)
virtual void refreshAll(bool only2D=false, bool forceRedraw=true)=0
Redraws all GL windows that have the 'refresh' flag on.
static const QString CurrentPath()
static const QString SaveFile()
static const QString LoadFile()
static char s_defaultEmptyCustomListText[]
constexpr Qt::SplitBehavior SkipEmptyParts
std::string toString(T x)
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb blue(0, 0, MAX)
QString defaultDocPath()
Shortcut for getting the documents location path.