void ccColorScaleEditorDialog::onStepModified(int index) { if (index < 0 || index >= m_scaleWidget->getStepCount()) return; const ColorScaleElementSlider* slider = m_scaleWidget->getStep(index); assert(slider); ccQtHelpers::SetButtonColor(colorToolButton,slider->getColor()); if (m_colorScale) { const double relativePos = slider->getRelativePos(); if (isRelativeMode()) { valueDoubleSpinBox->blockSignals(true); valueDoubleSpinBox->setValue(relativePos*100.0); valueDoubleSpinBox->blockSignals(false); if (m_associatedSF) { //compute corresponding scalar value for associated SF double actualValue = m_associatedSF->getMin() + relativePos * (m_associatedSF->getMax() - m_associatedSF->getMin()); valueLabel->setText(QString("(%1)").arg(actualValue)); valueLabel->setVisible(true); } else { valueLabel->setVisible(false); } //can't change min and max boundaries in 'relative' mode! valueDoubleSpinBox->setEnabled(index > 0 && index < m_scaleWidget->getStepCount()-1); } else { //compute corresponding 'absolute' value from current dialog boundaries double absoluteValue = m_minAbsoluteVal + relativePos * (m_maxAbsoluteVal - m_minAbsoluteVal); valueDoubleSpinBox->blockSignals(true); valueDoubleSpinBox->setValue(absoluteValue); valueDoubleSpinBox->blockSignals(false); valueDoubleSpinBox->setEnabled(true); //display corresponding relative position as well valueLabel->setText(QString("(%1 %)").arg(relativePos*100.0)); valueLabel->setVisible(true); } setModified(true); } }
void ccColorScaleEditorDialog::saveCurrentScale() { if (!m_colorScale || m_colorScale->isLocked()) { assert(false); return; } m_scaleWidget->exportColorScale(m_colorScale); bool relativeMode = isRelativeMode(); if (relativeMode) m_colorScale->setRelative(); else m_colorScale->setAbsolute(m_minAbsoluteVal,m_maxAbsoluteVal); setModified(false); }
bool ccColorScaleEditorDialog::saveCurrentScale() { if (!m_colorScale || m_colorScale->isLocked()) { assert(false); return false; } //check the custom labels if (customLabelsGroupBox->isChecked() && !checkCustomLabelsList(true)) { //error message already issued return false; } m_scaleWidget->exportColorScale(m_colorScale); bool wasRelative = m_colorScale->isRelative(); bool isRelative = isRelativeMode(); if (isRelative) m_colorScale->setRelative(); else m_colorScale->setAbsolute(m_minAbsoluteVal,m_maxAbsoluteVal); //DGM: warning, if the relative state has changed //we must update all the SFs currently relying on this scale! if ((!isRelative || isRelative != wasRelative) && m_mainApp && m_mainApp->dbRootObject()) { ccHObject::Container clouds; m_mainApp->dbRootObject()->filterChildren(clouds, true, CC_TYPES::POINT_CLOUD, true); for (size_t i=0; i<clouds.size(); ++i) { ccPointCloud* cloud = static_cast<ccPointCloud*>(clouds[i]); for (unsigned j=0; j<cloud->getNumberOfScalarFields(); ++j) { ccScalarField* sf = static_cast<ccScalarField*>(cloud->getScalarField(j)); if (sf->getColorScale() == m_colorScale) { //trick: we unlink then re-link the color scale to update everything automatically sf->setColorScale(ccColorScale::Shared(0)); sf->setColorScale(m_colorScale); if (cloud->getCurrentDisplayedScalarField() == sf) { cloud->prepareDisplayForRefresh(); if (cloud->getParent() && cloud->getParent()->isKindOf(CC_TYPES::MESH)) { //for mesh vertices (just in case) cloud->getParent()->prepareDisplayForRefresh(); } } } } } m_mainApp->refreshAll(); } //save the custom labels if (customLabelsGroupBox->isChecked()) { exportCustomLabelsList(m_colorScale->customLabels()); } else { m_colorScale->customLabels().clear(); } setModified(false); return true; }
void ccColorScaleEditorDialog::changeSelectedStepValue(double value) { if (!m_scaleWidget) return; int selectedIndex = m_scaleWidget->getSelectedStepIndex(); if (selectedIndex < 0) return; const ColorScaleElementSlider* slider = m_scaleWidget->getStep(selectedIndex); assert(slider); bool relativeMode = isRelativeMode(); if (relativeMode) { assert(selectedIndex != 0 && selectedIndex+1 < m_scaleWidget->getStepCount()); value /= 100.0; //from percentage to relative position assert(value >= 0.0 && value <= 1.0); //eventually onStepModified will be called (and thus m_modified will be updated) m_scaleWidget->setStepRelativePosition(selectedIndex,value); } else //absolute scale mode { //we build up the new list based on absolute values SharedColorScaleElementSliders newSliders(new ColorScaleElementSliders()); { for (int i=0;i<m_scaleWidget->getStepCount();++i) { const ColorScaleElementSlider* slider = m_scaleWidget->getStep(i); double absolutePos = (i == selectedIndex ? value : m_minAbsoluteVal + slider->getRelativePos() * (m_maxAbsoluteVal - m_minAbsoluteVal)); newSliders->push_back(new ColorScaleElementSlider(absolutePos,slider->getColor())); } } //update min and max boundaries { newSliders->sort(); m_minAbsoluteVal = newSliders->front()->getRelativePos(); //absolute in fact! m_maxAbsoluteVal = newSliders->back()->getRelativePos(); //absolute in fact! } //convert absolute pos to relative ones int newSelectedIndex = -1; { double range = std::max(m_maxAbsoluteVal-m_minAbsoluteVal,1e-12); for (int i=0;i<newSliders->size();++i) { double absoluteVal = newSliders->at(i)->getRelativePos(); if (absoluteVal == value) newSelectedIndex = i; double relativePos = (absoluteVal-m_minAbsoluteVal)/range; newSliders->at(i)->setRelativePos(relativePos); } } //update the whole scale with new sliders m_scaleWidget->setSliders(newSliders); m_scaleWidget->setSelectedStepIndex(newSelectedIndex,true); setModified(true); } }