2015-08-28 07:25:14 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-09-18 05:29:23 -05:00
|
|
|
#include "RiuWellLogTrackPlot.h"
|
2015-08-28 07:25:14 -05:00
|
|
|
|
2015-09-04 08:57:34 -05:00
|
|
|
#include "RimWellLogPlot.h"
|
2015-09-18 05:29:23 -05:00
|
|
|
#include "RimWellLogPlotTrack.h"
|
2015-09-17 04:34:03 -05:00
|
|
|
#include "RimWellLogPlotCurve.h"
|
2015-09-04 08:57:34 -05:00
|
|
|
|
2015-09-17 03:53:37 -05:00
|
|
|
#include "RiuMainWindow.h"
|
|
|
|
|
|
|
|
#include "cafPdmUiTreeView.h"
|
|
|
|
|
2015-08-31 04:39:59 -05:00
|
|
|
#include "qwt_plot_grid.h"
|
2015-08-31 08:23:20 -05:00
|
|
|
#include "qwt_legend.h"
|
2015-08-31 05:45:28 -05:00
|
|
|
#include "qwt_scale_engine.h"
|
2015-09-01 08:48:53 -05:00
|
|
|
#include "qwt_plot_layout.h"
|
2015-09-11 05:35:59 -05:00
|
|
|
#include "qwt_scale_draw.h"
|
|
|
|
#include "qwt_text.h"
|
2015-09-17 04:34:03 -05:00
|
|
|
#include "qwt_plot_curve.h"
|
2015-08-31 04:39:59 -05:00
|
|
|
|
2015-09-04 08:57:34 -05:00
|
|
|
#include <QWheelEvent>
|
2015-09-17 04:34:03 -05:00
|
|
|
#include <QMouseEvent>
|
2015-09-04 10:11:16 -05:00
|
|
|
#include <QFont>
|
2015-09-04 08:57:34 -05:00
|
|
|
|
2015-09-17 04:40:05 -05:00
|
|
|
#include <float.h>
|
|
|
|
|
2015-09-04 08:57:34 -05:00
|
|
|
#define RIU_SCROLLWHEEL_ZOOMFACTOR 1.1
|
|
|
|
#define RIU_SCROLLWHEEL_PANFACTOR 0.1
|
|
|
|
|
2015-08-28 07:25:14 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
RiuWellLogTrackPlot::RiuWellLogTrackPlot(RimWellLogPlotTrack* plotTrackDefinition, QWidget* parent)
|
2015-08-28 07:25:14 -05:00
|
|
|
: QwtPlot(parent)
|
|
|
|
{
|
2015-09-18 05:29:23 -05:00
|
|
|
Q_ASSERT(plotTrackDefinition);
|
|
|
|
m_plotTrackDefinition = plotTrackDefinition;
|
2015-09-04 08:57:34 -05:00
|
|
|
|
2015-08-31 04:39:59 -05:00
|
|
|
m_grid = new QwtPlotGrid();
|
|
|
|
m_grid->attach(this);
|
|
|
|
|
2015-08-31 08:23:20 -05:00
|
|
|
m_legend = new QwtLegend(this);
|
|
|
|
insertLegend(m_legend, QwtPlot::TopLegend);
|
2015-09-17 03:53:37 -05:00
|
|
|
|
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
2015-08-31 02:34:41 -05:00
|
|
|
setDefaults();
|
2015-08-28 07:25:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
RiuWellLogTrackPlot::~RiuWellLogTrackPlot()
|
2015-08-28 07:25:14 -05:00
|
|
|
{
|
2015-08-31 04:39:59 -05:00
|
|
|
m_grid->detach();
|
|
|
|
delete m_grid;
|
2015-08-28 07:25:14 -05:00
|
|
|
}
|
2015-08-31 02:34:41 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
void RiuWellLogTrackPlot::setDefaults()
|
2015-08-31 02:34:41 -05:00
|
|
|
{
|
|
|
|
QPalette newPalette(palette());
|
|
|
|
newPalette.setColor(QPalette::Background, Qt::white);
|
|
|
|
setPalette(newPalette);
|
|
|
|
|
|
|
|
setAutoFillBackground(true);
|
|
|
|
setCanvasBackground(Qt::white);
|
2015-08-31 02:42:29 -05:00
|
|
|
|
|
|
|
QFrame* canvasFrame = dynamic_cast<QFrame*>(canvas());
|
|
|
|
if (canvasFrame)
|
|
|
|
{
|
|
|
|
canvasFrame->setFrameShape(QFrame::NoFrame);
|
|
|
|
}
|
2015-08-31 04:39:59 -05:00
|
|
|
|
2015-09-04 08:57:34 -05:00
|
|
|
canvas()->setMouseTracking(true);
|
|
|
|
canvas()->installEventFilter(this);
|
|
|
|
|
2015-08-31 04:39:59 -05:00
|
|
|
QPen gridPen(Qt::SolidLine);
|
|
|
|
gridPen.setColor(Qt::lightGray);
|
|
|
|
m_grid->setPen(gridPen);
|
2015-08-31 05:34:08 -05:00
|
|
|
|
|
|
|
enableAxis(QwtPlot::xTop, true);
|
|
|
|
enableAxis(QwtPlot::yLeft, true);
|
|
|
|
enableAxis(QwtPlot::xBottom, false);
|
|
|
|
enableAxis(QwtPlot::yRight, false);
|
2015-08-31 05:45:28 -05:00
|
|
|
|
2015-09-01 08:48:53 -05:00
|
|
|
plotLayout()->setAlignCanvasToScales(true);
|
|
|
|
|
2015-08-31 05:45:28 -05:00
|
|
|
axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Inverted, true);
|
2015-09-02 09:41:12 -05:00
|
|
|
|
|
|
|
// Align the canvas with the actual min and max values of the curves
|
|
|
|
axisScaleEngine(QwtPlot::xTop)->setAttribute(QwtScaleEngine::Floating, true);
|
|
|
|
axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Floating, true);
|
2015-09-03 04:55:24 -05:00
|
|
|
setAxisScale(QwtPlot::yLeft, 1000, 0);
|
|
|
|
setAxisScale(QwtPlot::xTop, -10, 100);
|
2015-09-03 07:21:08 -05:00
|
|
|
|
2015-09-04 10:11:16 -05:00
|
|
|
QFont xAxisFont = axisFont(QwtPlot::xTop);
|
|
|
|
xAxisFont.setPixelSize(9);
|
|
|
|
setAxisFont(QwtPlot::xTop, xAxisFont);
|
|
|
|
|
|
|
|
QFont yAxisFont = axisFont(QwtPlot::yLeft);
|
|
|
|
yAxisFont.setPixelSize(9);
|
|
|
|
setAxisFont(QwtPlot::yLeft, yAxisFont);
|
2015-09-11 05:35:59 -05:00
|
|
|
|
|
|
|
QwtText axisTitleY = axisTitle(QwtPlot::yLeft);
|
|
|
|
QFont yAxisTitleFont = axisTitleY.font();
|
2015-09-11 07:35:12 -05:00
|
|
|
yAxisTitleFont.setPixelSize(9);
|
|
|
|
yAxisTitleFont.setBold(false);
|
2015-09-11 05:35:59 -05:00
|
|
|
axisTitleY.setFont(yAxisTitleFont);
|
|
|
|
axisTitleY.setRenderFlags(Qt::AlignRight);
|
|
|
|
setAxisTitle(QwtPlot::yLeft, axisTitleY);
|
2015-08-31 02:34:41 -05:00
|
|
|
}
|
2015-08-31 10:21:21 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
void RiuWellLogTrackPlot::setDepthRange(double minDepth, double maxDepth)
|
2015-08-31 10:21:21 -05:00
|
|
|
{
|
|
|
|
// Note: Y-axis is inverted
|
|
|
|
setAxisScale(QwtPlot::yLeft, maxDepth, minDepth);
|
2015-09-22 04:54:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuWellLogTrackPlot::setXRange(double min, double max)
|
|
|
|
{
|
|
|
|
setAxisScale(QwtPlot::xTop, min, max);
|
2015-08-31 10:21:21 -05:00
|
|
|
}
|
2015-09-04 08:57:34 -05:00
|
|
|
|
2015-09-11 05:35:59 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
void RiuWellLogTrackPlot::setDepthTitle(const QString& title)
|
2015-09-11 05:35:59 -05:00
|
|
|
{
|
|
|
|
QwtText axisTitleY = axisTitle(QwtPlot::yLeft);
|
|
|
|
axisTitleY.setText(title);
|
|
|
|
setAxisTitle(QwtPlot::yLeft, axisTitleY);
|
|
|
|
}
|
|
|
|
|
2015-09-04 08:57:34 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
bool RiuWellLogTrackPlot::eventFilter(QObject* watched, QEvent* event)
|
2015-09-04 08:57:34 -05:00
|
|
|
{
|
|
|
|
if (watched == canvas())
|
|
|
|
{
|
|
|
|
QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>(event);
|
|
|
|
if (wheelEvent)
|
|
|
|
{
|
2015-09-18 05:29:23 -05:00
|
|
|
if (!m_plotTrackDefinition)
|
2015-09-04 08:57:34 -05:00
|
|
|
{
|
|
|
|
return QwtPlot::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
RimWellLogPlot* plotDefinition;
|
2015-09-18 05:29:23 -05:00
|
|
|
m_plotTrackDefinition->firstAnchestorOrThisOfType(plotDefinition);
|
2015-09-04 08:57:34 -05:00
|
|
|
if (!plotDefinition)
|
|
|
|
{
|
|
|
|
return QwtPlot::eventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wheelEvent->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
QwtScaleMap scaleMap = canvasMap(QwtPlot::yLeft);
|
|
|
|
double zoomCenter = scaleMap.invTransform(wheelEvent->pos().y());
|
|
|
|
|
|
|
|
if (wheelEvent->delta() > 0)
|
|
|
|
{
|
|
|
|
plotDefinition->zoomDepth(RIU_SCROLLWHEEL_ZOOMFACTOR, zoomCenter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plotDefinition->zoomDepth(1.0/RIU_SCROLLWHEEL_ZOOMFACTOR, zoomCenter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plotDefinition->panDepth(wheelEvent->delta() < 0 ? RIU_SCROLLWHEEL_PANFACTOR : -RIU_SCROLLWHEEL_PANFACTOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
event->accept();
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-17 04:34:03 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
|
|
|
if (mouseEvent)
|
|
|
|
{
|
2015-09-24 08:27:33 -05:00
|
|
|
if (mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonRelease)
|
2015-09-17 04:34:03 -05:00
|
|
|
{
|
|
|
|
selectClosestCurve(mouseEvent->pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-04 08:57:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return QwtPlot::eventFilter(watched, event);
|
|
|
|
}
|
2015-09-17 03:53:37 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
void RiuWellLogTrackPlot::focusInEvent(QFocusEvent* event)
|
2015-09-17 03:53:37 -05:00
|
|
|
{
|
2015-09-18 05:29:23 -05:00
|
|
|
if (m_plotTrackDefinition)
|
2015-09-17 03:53:37 -05:00
|
|
|
{
|
2015-09-18 05:29:23 -05:00
|
|
|
RiuMainWindow::instance()->projectTreeView()->selectAsCurrentItem(m_plotTrackDefinition);
|
2015-09-17 05:02:37 -05:00
|
|
|
clearFocus();
|
2015-09-17 03:53:37 -05:00
|
|
|
}
|
|
|
|
}
|
2015-09-17 04:34:03 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
void RiuWellLogTrackPlot::selectClosestCurve(const QPoint& pos)
|
2015-09-17 04:34:03 -05:00
|
|
|
{
|
|
|
|
QwtPlotCurve* closestCurve = NULL;
|
|
|
|
double distMin = DBL_MAX;
|
|
|
|
|
|
|
|
const QwtPlotItemList& itmList = itemList();
|
|
|
|
for (QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++)
|
|
|
|
{
|
|
|
|
if ((*it )->rtti() == QwtPlotItem::Rtti_PlotCurve )
|
|
|
|
{
|
|
|
|
QwtPlotCurve* candidateCurve = static_cast<QwtPlotCurve*>(*it);
|
|
|
|
double dist;
|
|
|
|
int idx = candidateCurve->closestPoint(pos, &dist);
|
|
|
|
if (dist < distMin)
|
|
|
|
{
|
|
|
|
closestCurve = candidateCurve;
|
|
|
|
distMin = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closestCurve)
|
|
|
|
{
|
2015-09-18 05:29:23 -05:00
|
|
|
RimWellLogPlotCurve* selectedCurve = m_plotTrackDefinition->curveDefinitionFromCurve(closestCurve);
|
2015-09-17 04:34:03 -05:00
|
|
|
if (selectedCurve)
|
|
|
|
{
|
|
|
|
RiuMainWindow::instance()->projectTreeView()->selectAsCurrentItem(selectedCurve);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-17 05:30:24 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
QSize RiuWellLogTrackPlot::sizeHint() const
|
2015-09-17 05:30:24 -05:00
|
|
|
{
|
|
|
|
return QSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-09-18 05:29:23 -05:00
|
|
|
QSize RiuWellLogTrackPlot::minimumSizeHint() const
|
2015-09-17 05:30:24 -05:00
|
|
|
{
|
|
|
|
return QSize(0, 0);
|
|
|
|
}
|
2015-09-22 04:54:58 -05:00
|
|
|
|