(#504) Do not use autoscale for x-axis - simplified track/plot update code

This commit is contained in:
Magne Sjaastad 2015-09-22 11:54:58 +02:00
parent 7ded798055
commit b45e571888
8 changed files with 51 additions and 93 deletions

View File

@ -112,7 +112,6 @@ void RicAddWellLogToPlotFeature::onActionTriggered(bool isChecked)
plot->updateAvailableDepthRange();
plot->setVisibleDepthRangeFromContents();
plotTrack->updateXAxisRangeFromCurves();
plotTrack->viewer()->replot();
RiaApplication::instance()->project()->updateConnectedEditors();

View File

@ -131,44 +131,13 @@ void RimWellLogFileCurve::fieldChangedByUi(const caf::PdmFieldHandle* changedFie
{
RimWellLogPlotCurve::fieldChangedByUi(changedField, oldValue, newValue);
RimWellLogPlot* wellLoglot;
firstAnchestorOrThisOfType(wellLoglot);
RimWellLogPlotTrack* wellLoglotTrack;
firstAnchestorOrThisOfType(wellLoglotTrack);
if (changedField == &m_wellPath)
{
this->updatePlotData();
if (wellLoglot)
{
wellLoglot->updateAvailableDepthRange();
wellLoglot->setVisibleDepthRangeFromContents();
}
if (wellLoglotTrack)
{
wellLoglotTrack->updateXAxisRangeFromCurves();
}
}
else if (changedField == &m_wellLogChannnelName)
{
this->updatePlotData();
if (wellLoglot)
{
if (!wellLoglot->hasAvailableDepthRange())
{
wellLoglot->updateAvailableDepthRange();
wellLoglot->setVisibleDepthRangeFromContents();
}
if (wellLoglotTrack)
{
wellLoglotTrack->updateXAxisRangeFromCurves();
}
}
}
m_plot->replot();

View File

@ -287,18 +287,9 @@ void RimWellLogPlotCurve::updateOptionSensitivity()
//--------------------------------------------------------------------------------------------------
void RimWellLogPlotCurve::updateTrackAndPlotFromCurveData()
{
RimWellLogPlotTrack* plotTrack;
firstAnchestorOrThisOfType(plotTrack);
if (plotTrack)
{
plotTrack->updateXAxisRangeFromCurves();
}
RimWellLogPlot* wellLogPlot;
firstAnchestorOrThisOfType(wellLogPlot);
if (wellLogPlot && plotTrack)
if (wellLogPlot)
{
bool setDepthRange = !wellLogPlot->hasAvailableDepthRange();
wellLogPlot->updateAvailableDepthRange();
@ -307,9 +298,12 @@ void RimWellLogPlotCurve::updateTrackAndPlotFromCurveData()
{
wellLogPlot->setVisibleDepthRangeFromContents();
}
else if (plotTrack->curveCount() == 1)
{
plotTrack->updateAxisRangesAndReplot();
}
}
RimWellLogPlotTrack* plotTrack;
firstAnchestorOrThisOfType(plotTrack);
if (plotTrack)
{
plotTrack->updateAxisRangesAndReplot();
}
}

View File

@ -63,6 +63,7 @@ protected:
void updatePlotConfiguration();
void updateCurveVisibility();
void updateOptionSensitivity();
void updateTrackAndPlotFromCurveData();
// Overridden PDM methods
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);

View File

@ -62,7 +62,7 @@ RimWellLogPlotTrack::RimWellLogPlotTrack()
//--------------------------------------------------------------------------------------------------
RimWellLogPlotTrack::~RimWellLogPlotTrack()
{
delete m_viewer;
delete m_wellLogTrackPlotWidget;
}
//--------------------------------------------------------------------------------------------------
@ -80,12 +80,12 @@ void RimWellLogPlotTrack::fieldChangedByUi(const caf::PdmFieldHandle* changedFie
{
if (changedField == &m_show)
{
if (m_viewer) m_viewer->setVisible(m_show());
if (m_wellLogTrackPlotWidget) m_wellLogTrackPlotWidget->setVisible(m_show());
}
else if (changedField == &m_visibleXRangeMin || changedField == &m_visibleXRangeMax)
{
m_viewer->setAxisScale(QwtPlot::xTop, m_visibleXRangeMin, m_visibleXRangeMax);
m_viewer->replot();
m_wellLogTrackPlotWidget->setXRange(m_visibleXRangeMin, m_visibleXRangeMax);
m_wellLogTrackPlotWidget->replot();
}
}
@ -112,9 +112,9 @@ void RimWellLogPlotTrack::addCurve(RimWellLogPlotCurve* curve)
{
curves.push_back(curve);
if (m_viewer)
if (m_wellLogTrackPlotWidget)
{
curve->setPlot(m_viewer);
curve->setPlot(m_wellLogTrackPlotWidget);
}
}
@ -124,7 +124,7 @@ void RimWellLogPlotTrack::addCurve(RimWellLogPlotCurve* curve)
//--------------------------------------------------------------------------------------------------
RiuWellLogTrackPlot* RimWellLogPlotTrack::viewer()
{
return m_viewer;
return m_wellLogTrackPlotWidget;
}
//--------------------------------------------------------------------------------------------------
@ -178,21 +178,19 @@ bool RimWellLogPlotTrack::availableDepthRange(double* minimumDepth, double* maxi
//--------------------------------------------------------------------------------------------------
void RimWellLogPlotTrack::loadDataAndUpdate()
{
CVF_ASSERT(m_viewer);
CVF_ASSERT(m_wellLogTrackPlotWidget);
RimWellLogPlot* wellLogPlot;
firstAnchestorOrThisOfType(wellLogPlot);
if (wellLogPlot)
{
m_viewer->setDepthTitle(wellLogPlot->depthPlotTitle());
m_wellLogTrackPlotWidget->setDepthTitle(wellLogPlot->depthPlotTitle());
}
for (size_t cIdx = 0; cIdx < curves.size(); ++cIdx)
{
curves[cIdx]->updatePlotData();
}
updateXAxisRangeFromCurves();
}
//--------------------------------------------------------------------------------------------------
@ -200,12 +198,12 @@ void RimWellLogPlotTrack::loadDataAndUpdate()
//--------------------------------------------------------------------------------------------------
void RimWellLogPlotTrack::recreateViewer()
{
CVF_ASSERT(m_viewer == NULL);
CVF_ASSERT(m_wellLogTrackPlotWidget == NULL);
m_viewer = new RiuWellLogTrackPlot(this);
m_wellLogTrackPlotWidget = new RiuWellLogTrackPlot(this);
for (size_t cIdx = 0; cIdx < curves.size(); ++cIdx)
{
curves[cIdx]->setPlot(this->m_viewer);
curves[cIdx]->setPlot(this->m_wellLogTrackPlotWidget);
}
}
@ -225,9 +223,7 @@ void RimWellLogPlotTrack::detachAllCurves()
//--------------------------------------------------------------------------------------------------
void RimWellLogPlotTrack::updateAxisRangesAndReplot()
{
bool rangesChanged = false;
if (m_viewer)
if (m_wellLogTrackPlotWidget)
{
RimWellLogPlot* wellLogPlot;
firstAnchestorOrThisOfType(wellLogPlot);
@ -236,21 +232,13 @@ void RimWellLogPlotTrack::updateAxisRangesAndReplot()
double minimumDepth, maximumDepth;
wellLogPlot->visibleDepthRange(&minimumDepth, &maximumDepth);
m_viewer->setDepthRange(minimumDepth, maximumDepth);
rangesChanged = true;
m_wellLogTrackPlotWidget->setDepthRange(minimumDepth, maximumDepth);
}
// Assume auto-scaling on X-axis as long as curves exist, reset to default if not
if (curves.size() < 1)
{
m_viewer->setAxisScale(QwtPlot::xTop, RI_LOGPLOTTRACK_MINX_DEFAULT, RI_LOGPLOTTRACK_MAXX_DEFAULT);
rangesChanged = true;
}
updateXAxisRangeFromCurves();
m_wellLogTrackPlotWidget->setXRange(m_visibleXRangeMin, m_visibleXRangeMax);
if (rangesChanged)
{
m_viewer->replot();
}
m_wellLogTrackPlotWidget->replot();
}
}
@ -262,12 +250,7 @@ void RimWellLogPlotTrack::updateXAxisRangeFromCurves()
double minValue = HUGE_VAL;
double maxValue = -HUGE_VAL;
size_t curveCount = curves.size();
if (curveCount < 1) return;
bool rangeUpdated = false;
for (size_t cIdx = 0; cIdx < curveCount; cIdx++)
for (size_t cIdx = 0; cIdx < curves.size(); cIdx++)
{
double minCurveValue = HUGE_VAL;
double maxCurveValue = -HUGE_VAL;
@ -277,24 +260,25 @@ void RimWellLogPlotTrack::updateXAxisRangeFromCurves()
if (minCurveValue < minValue)
{
minValue = minCurveValue;
rangeUpdated = true;
}
if (maxCurveValue > maxValue)
{
maxValue = maxCurveValue;
rangeUpdated = true;
}
}
}
if (rangeUpdated)
if (minValue == HUGE_VAL)
{
m_visibleXRangeMin = minValue;
m_visibleXRangeMax = maxValue;
updateConnectedEditors();
minValue = RI_LOGPLOTTRACK_MINX_DEFAULT;
maxValue = RI_LOGPLOTTRACK_MAXX_DEFAULT;
}
m_visibleXRangeMin = minValue;
m_visibleXRangeMax = maxValue;
updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------

View File

@ -55,7 +55,6 @@ public:
bool availableDepthRange(double* minimumDepth, double* maximumDepth);
void updateAxisRangesAndReplot();
void updateXAxisRangeFromCurves();
RiuWellLogTrackPlot* viewer();
@ -69,6 +68,9 @@ protected:
virtual caf::PdmFieldHandle* userDescriptionField();
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering);
private:
void updateXAxisRangeFromCurves();
private:
caf::PdmField<bool> m_show;
caf::PdmField<QString> m_userName;
@ -76,5 +78,5 @@ private:
caf::PdmField<double> m_visibleXRangeMin;
caf::PdmField<double> m_visibleXRangeMax;
QPointer<RiuWellLogTrackPlot> m_viewer;
QPointer<RiuWellLogTrackPlot> m_wellLogTrackPlotWidget;
};

View File

@ -112,8 +112,6 @@ void RiuWellLogTrackPlot::setDefaults()
setAxisScale(QwtPlot::yLeft, 1000, 0);
setAxisScale(QwtPlot::xTop, -10, 100);
setAxisAutoScale(QwtPlot::xTop, true);
QFont xAxisFont = axisFont(QwtPlot::xTop);
xAxisFont.setPixelSize(9);
setAxisFont(QwtPlot::xTop, xAxisFont);
@ -138,7 +136,14 @@ void RiuWellLogTrackPlot::setDepthRange(double minDepth, double maxDepth)
{
// Note: Y-axis is inverted
setAxisScale(QwtPlot::yLeft, maxDepth, minDepth);
//replot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogTrackPlot::setXRange(double min, double max)
{
setAxisScale(QwtPlot::xTop, min, max);
}
//--------------------------------------------------------------------------------------------------
@ -272,3 +277,4 @@ QSize RiuWellLogTrackPlot::minimumSizeHint() const
{
return QSize(0, 0);
}

View File

@ -43,6 +43,9 @@ public:
void setDepthRange(double minDepth, double maxDepth);
void setDepthTitle(const QString& title);
void setXRange(double min, double max);
protected:
virtual bool eventFilter(QObject* watched, QEvent* event);
virtual void focusInEvent(QFocusEvent* event);