(#396) Setting default curve color on creation

This commit is contained in:
Pål Hagen 2015-09-03 10:55:54 +02:00
parent bcab7f2248
commit 9a6221b7e8
4 changed files with 59 additions and 7 deletions

View File

@ -20,14 +20,46 @@
#include "RicNewWellLogPlotCurveFeature.h"
#include "RimWellLogPlotTrace.h"
#include "RimWellLogExtractionCurve.h"
#include "RiuMainWindow.h"
#include "cafSelectionManager.h"
#include "cafPdmFieldCvfColor.h"
#include <QAction>
#include <QColor>
#include <vector>
#include "RiuMainWindow.h"
#include "RimWellLogExtractionCurve.h"
static const int RI_LOGPLOT_CURVECOLORSCOUNT = 15;
static const int RI_LOGPLOT_CURVECOLORS[] =
{
Qt::blue,
Qt::red,
Qt::green,
Qt::yellow,
Qt::magenta,
Qt::cyan,
Qt::gray,
Qt::darkBlue,
Qt::darkRed,
Qt::darkGreen,
Qt::darkYellow,
Qt::darkMagenta,
Qt::darkCyan,
Qt::darkGray,
Qt::black
};
//--------------------------------------------------------------------------------------------------
/// Pick default curve color from an index based palette
//--------------------------------------------------------------------------------------------------
static QColor sg_curveColorFromIndex(size_t curveIndex)
{
return QColor(Qt::GlobalColor(RI_LOGPLOT_CURVECOLORS[curveIndex % RI_LOGPLOT_CURVECOLORSCOUNT]));
}
CAF_CMD_SOURCE_INIT(RicNewWellLogPlotCurveFeature, "RicNewWellLogPlotCurveFeature");
@ -47,9 +79,15 @@ void RicNewWellLogPlotCurveFeature::onActionTriggered(bool isChecked)
RimWellLogPlotTrace* wellLogPlotTrace = selectedWellLogPlotTrace();
if (wellLogPlotTrace)
{
size_t curveIndex = wellLogPlotTrace->curveCount();
RimWellLogPlotCurve* curve = new RimWellLogExtractionCurve();
wellLogPlotTrace->addCurve(curve);
QColor curveColorQt = sg_curveColorFromIndex(curveIndex);
cvf::Color3f curveColor(curveColorQt.redF(), curveColorQt.greenF(), curveColorQt.blueF());
curve->setColor(curveColor);
curve->setDescription(QString("Curve %1").arg(wellLogPlotTrace->curveCount()));
wellLogPlotTrace->updateConnectedEditors();

View File

@ -43,6 +43,7 @@
//==================================================================================================
CAF_PDM_SOURCE_INIT(RimWellLogExtractionCurve, "WellLogEclipseCurve");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -68,7 +69,6 @@ RimWellLogExtractionCurve::RimWellLogExtractionCurve()
m_geomResultDefinition = new RimGeoMechResultDefinition;
CAF_PDM_InitField(&m_timeStep, "CurveTimeStep", 0,"Time Step", "", "", "");
}
//--------------------------------------------------------------------------------------------------
@ -140,6 +140,7 @@ void RimWellLogExtractionCurve::updatePlotData()
if (isNeedingUpdate)
{
m_plotCurve->setSamples(values.data(), depthValues.data(), (int)depthValues.size());
m_plotCurve->setPen(QPen(QColor(m_curveColor.value().rByte(), m_curveColor.value().gByte(), m_curveColor.value().bByte())));
RimWellLogPlot* wellLogPlot;
firstAnchestorOrThisOfType(wellLogPlot);

View File

@ -36,6 +36,8 @@ RimWellLogPlotCurve::RimWellLogPlotCurve()
m_showCurve.uiCapability()->setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_userName, "CurveDescription", "Name", "", "", "");
CAF_PDM_InitField(&m_curveColor, "Color", cvf::Color3f(cvf::Color3::BLACK), "Color", "", "", "");
m_plotCurve = new QwtPlotCurve;
m_plotCurve->setXAxis(QwtPlot::xTop);
m_plotCurve->setYAxis(QwtPlot::yLeft);
@ -108,6 +110,7 @@ void RimWellLogPlotCurve::updatePlotData()
depthValues.push_back(1000);
m_plotCurve->setSamples(values.data(), depthValues.data(), (int) depthValues.size());
m_plotCurve->setPen(QPen(QColor(m_curveColor.value().rByte(), m_curveColor.value().gByte(), m_curveColor.value().bByte())));
RimWellLogPlot* wellLogPlot;
firstAnchestorOrThisOfType(wellLogPlot);
@ -156,3 +159,11 @@ bool RimWellLogPlotCurve::depthRange(double* minimumDepth, double* maximumDepth)
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlotCurve::setColor(const cvf::Color3f& color)
{
m_curveColor = color;
}

View File

@ -21,6 +21,7 @@
#include "cafPdmObject.h"
#include "cafPdmField.h"
#include "cafPdmFieldCvfColor.h"
#include <vector>
@ -28,7 +29,6 @@ class RiuWellLogTracePlot;
class QwtPlotCurve;
class QString;
//==================================================================================================
///
///
@ -42,7 +42,9 @@ public:
void setDescription(QString description) {m_userName = description;}
void setPlot(RiuWellLogTracePlot* plot);
void setColor(const cvf::Color3f& color);
bool depthRange(double* minimumDepth, double* maximumDepth);
virtual void updatePlotData();
protected:
@ -53,9 +55,9 @@ protected:
virtual caf::PdmFieldHandle* userDescriptionField();
caf::PdmField<bool> m_showCurve;
caf::PdmField<QString> m_userName;
// caf::PdmField<QColor> m_curveColor;
caf::PdmField<bool> m_showCurve;
caf::PdmField<QString> m_userName;
caf::PdmField<cvf::Color3f> m_curveColor;
// caf::PdmField<Linestyle> m_lineStyle;
// caf::PdmField<int> m_lineWidth;