diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp index a36969d594..ab91f7be3c 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp @@ -156,15 +156,18 @@ void RimGridCrossPlot::calculateZoomRangeAndUpdateQwt() //-------------------------------------------------------------------------------------------------- void RimGridCrossPlot::reattachCurvesToQwtAndReplot() { - for (auto curveSet : m_crossPlotCurveSets) + if (m_qwtPlot) { - curveSet->detachAllCurves(); - if (curveSet->isChecked()) + for (auto curveSet : m_crossPlotCurveSets) { - curveSet->setParentQwtPlotNoReplot(m_qwtPlot); + curveSet->detachAllCurves(); + if (curveSet->isChecked()) + { + curveSet->setParentQwtPlotNoReplot(m_qwtPlot); + } } + m_qwtPlot->replot(); } - m_qwtPlot->replot(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurve.cpp b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurve.cpp index e376d4f0eb..1ec48c0906 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurve.cpp +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurve.cpp @@ -42,39 +42,13 @@ CAF_PDM_SOURCE_INIT(RimGridCrossPlotCurve, "GridCrossPlotCurve"); -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimGridCrossPlotCurve::determineColorAndSymbol(int curveSetIndex, int categoryIndex, int nCategories, bool contrastColors) -{ - if (contrastColors) - { - const caf::ColorTable& colors = RiaColorTables::categoryPaletteColors(); - int colorIndex = categoryIndex + curveSetIndex; // Offset cycle for each curve set - setColor(colors.cycledColor3f(colorIndex)); - int numColors = (int)colors.size(); - - // Retain same symbol until we've gone full cycle in colors - int symbolIndex = categoryIndex / numColors; - - RiuQwtSymbol::PointSymbolEnum symbol = RiuQwtSymbol::cycledSymbolStyle(curveSetIndex, symbolIndex); - setSymbol(symbol); - } - else - { - const caf::ColorTable& colors = RiaColorTables::contrastCategoryPaletteColors(); - cvf::Color3ub cycledBaseColor = colors.cycledColor3ub(curveSetIndex); - caf::ColorTable hueConstColTable = RiaColorTables::createBrightnessBasedColorTable(cycledBaseColor, nCategories); - setColor(hueConstColTable.cycledColor3f(categoryIndex)); - RiuQwtSymbol::PointSymbolEnum symbol = RiuQwtSymbol::cycledFilledSymbolStyle(curveSetIndex); - setSymbol(symbol); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimGridCrossPlotCurve::RimGridCrossPlotCurve() + : m_curveSetIndex(0) + , m_categoryIndex(0) + , m_categoryCount(0) { CAF_PDM_InitObject("Cross Plot Points", ":/WellLogCurve16x16.png", "", ""); @@ -83,6 +57,24 @@ RimGridCrossPlotCurve::RimGridCrossPlotCurve() setSymbolSize(6); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimGridCrossPlotCurve::setCategoryInformation(int curveSetIndex, int categoryIndex, int categoryCount) +{ + m_curveSetIndex = curveSetIndex; + m_categoryIndex = categoryIndex; + m_categoryCount = categoryCount; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimGridCrossPlotCurve::setUseContrastColors(bool useContrastColors) +{ + m_useContrastColors = useContrastColors; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -93,6 +85,52 @@ void RimGridCrossPlotCurve::setSamples(const std::vector& xValues, const m_qwtPlotCurve->setSamples(&xValues[0], &yValues[0], static_cast(xValues.size())); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimGridCrossPlotCurve::updateCurveAppearance() +{ + determineColorAndSymbol(); + RimPlotCurve::updateCurveAppearance(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RimGridCrossPlotCurve::categoryIndex() const +{ + return m_categoryIndex; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimGridCrossPlotCurve::determineColorAndSymbol() +{ + if (m_useContrastColors) + { + const caf::ColorTable& colors = RiaColorTables::categoryPaletteColors(); + int colorIndex = m_categoryIndex + m_curveSetIndex; // Offset cycle for each curve set + setColor(colors.cycledColor3f(colorIndex)); + int numColors = (int)colors.size(); + + // Retain same symbol until we've gone full cycle in colors + int symbolIndex = m_categoryIndex / numColors; + + RiuQwtSymbol::PointSymbolEnum symbol = RiuQwtSymbol::cycledSymbolStyle(m_curveSetIndex, symbolIndex); + setSymbol(symbol); + } + else + { + const caf::ColorTable& colors = RiaColorTables::contrastCategoryPaletteColors(); + cvf::Color3ub cycledBaseColor = colors.cycledColor3ub(m_curveSetIndex); + caf::ColorTable hueConstColTable = RiaColorTables::createBrightnessBasedColorTable(cycledBaseColor, m_categoryCount); + setColor(hueConstColTable.cycledColor3f(m_categoryIndex)); + RiuQwtSymbol::PointSymbolEnum symbol = RiuQwtSymbol::cycledFilledSymbolStyle(m_curveSetIndex); + setSymbol(symbol); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurve.h b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurve.h index 4260bc6a38..05fb997b99 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurve.h +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurve.h @@ -40,14 +40,24 @@ class RimGridCrossPlotCurve : public RimPlotCurve public: RimGridCrossPlotCurve(); ~RimGridCrossPlotCurve() override = default; - void determineColorAndSymbol(int curveSetIndex, int categoryIndex, int nCategories, bool contrastColors = false); + void setCategoryInformation(int curveSetIndex, int categoryIndex, int categoryCount); + void setUseContrastColors(bool useContrastColors); void setSamples(const std::vector& xValues, const std::vector& yValues); - + void updateCurveAppearance() override; + int categoryIndex() const; protected: + + void determineColorAndSymbol(); void updateZoomInParentPlot() override; void updateLegendsInPlot() override; QString createCurveAutoName() override; void onLoadDataAndUpdate(bool updateParentPlot) override; void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; + +private: + int m_curveSetIndex; + int m_categoryIndex; + int m_categoryCount; + bool m_useContrastColors; }; diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.cpp b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.cpp index 2e6c251b25..146ea8220c 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.cpp +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.cpp @@ -208,7 +208,7 @@ QString RimGridCrossPlotCurveSet::createAutoName() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RimGridCrossPlotCurveSet::createShortAutoName() const +QString RimGridCrossPlotCurveSet::createCurveName() const { if (m_case() == nullptr) { @@ -282,7 +282,7 @@ void RimGridCrossPlotCurveSet::initAfterRead() //-------------------------------------------------------------------------------------------------- void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot) { - performAutoNameUpdate(); + updatePlotName(); detachAllCurves(); m_crossPlotCurves.deleteAllChildObjects(); @@ -315,29 +315,21 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot) RigEclipseCrossPlotResult result = RigEclipseCrossPlotDataExtractor::extract( eclipseCase->eclipseCaseData(), m_timeStep(), xAddress, yAddress, m_categorization(), catAddress, m_categoryBinCount, timeStepCellVisibilityMap); + m_categoryNames = result.categoryNameMap; for (const auto& sampleCategory : result.categorySamplesMap) { - RimGridCrossPlotCurve* curve = new RimGridCrossPlotCurve(); - - QString categoryName = result.categoryNameMap[sampleCategory.first]; - - if (categoryName.isEmpty()) - { - curve->setCustomName(createShortAutoName()); - } - else - { - curve->setCustomName(QString("%1 : %2").arg(createShortAutoName()).arg(categoryName)); - } - curve->determineColorAndSymbol(indexInPlot(), sampleCategory.first, (int)result.categorySamplesMap.size(), m_categorization() == FORMATION_CATEGORIZATION); + RimGridCrossPlotCurve* curve = new RimGridCrossPlotCurve(); + curve->setCategoryInformation(indexInPlot(), sampleCategory.first, (int)result.categorySamplesMap.size()); + curve->setUseContrastColors(m_categorization() == FORMATION_CATEGORIZATION); curve->setSamples(sampleCategory.second.first, sampleCategory.second.second); curve->updateCurveAppearance(); - curve->updateCurveNameAndUpdatePlotLegendAndTitle(); curve->updateUiIconFromPlotSymbol(); m_crossPlotCurves.push_back(curve); } + updateCurveNames(); + if (updateParentPlot) { triggerReplotAndTreeRebuild(); @@ -508,7 +500,28 @@ void RimGridCrossPlotCurveSet::triggerReplotAndTreeRebuild() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimGridCrossPlotCurveSet::performAutoNameUpdate() +void RimGridCrossPlotCurveSet::updateCurveNames() +{ + for (auto curve : m_crossPlotCurves()) + { + QString categoryName = m_categoryNames[curve->categoryIndex()]; + + if (categoryName.isEmpty()) + { + curve->setCustomName(createCurveName()); + } + else + { + curve->setCustomName(QString("%1 : %2").arg(createCurveName()).arg(categoryName)); + } + curve->updateCurveNameAndUpdatePlotLegendAndTitle(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimGridCrossPlotCurveSet::updatePlotName() { this->setName(createAutoName()); RimGridCrossPlot* parent; @@ -516,6 +529,16 @@ void RimGridCrossPlotCurveSet::performAutoNameUpdate() parent->performAutoNameUpdate(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimGridCrossPlotCurveSet::performAutoNameUpdate() +{ + updatePlotName(); + updateCurveNames(); + triggerReplotAndTreeRebuild(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.h b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.h index 93f69d72ad..73172cab81 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.h +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.h @@ -82,7 +82,7 @@ public: int indexInPlot() const; QString createAutoName() const override; - QString createShortAutoName() const; + QString createCurveName() const; void detachAllCurves(); void cellFilterViewUpdated(); @@ -99,12 +99,13 @@ protected: QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override; void triggerReplotAndTreeRebuild(); + void updateCurveNames(); + void updatePlotName(); void performAutoNameUpdate() override; void setDefaults(); void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override; private: - caf::PdmPtrField m_case; caf::PdmField m_timeStep; caf::PdmPtrField m_cellFilterView; @@ -118,4 +119,5 @@ private: caf::PdmChildArrayField m_crossPlotCurves; + std::map m_categoryNames; };