Update Curve Names when changing parameters

This commit is contained in:
Gaute Lindkvist 2019-02-28 18:30:07 +01:00
parent d1c14f9729
commit b4d8dc7819
5 changed files with 131 additions and 55 deletions

View File

@ -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();
}
//--------------------------------------------------------------------------------------------------

View File

@ -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<double>& xValues, const
m_qwtPlotCurve->setSamples(&xValues[0], &yValues[0], static_cast<int>(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);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -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<double>& xValues, const std::vector<double>& 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;
};

View File

@ -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();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -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<caf::PdmOptionItemInfo> 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<RimCase*> m_case;
caf::PdmField<int> m_timeStep;
caf::PdmPtrField<RimGridView*> m_cellFilterView;
@ -118,4 +119,5 @@ private:
caf::PdmChildArrayField<RimGridCrossPlotCurve*> m_crossPlotCurves;
std::map<int, QString> m_categoryNames;
};