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-11-04 09:14:42 -06:00
|
|
|
#include "RiuWellLogTrack.h"
|
2015-08-28 07:25:14 -05:00
|
|
|
|
2015-09-04 08:57:34 -05:00
|
|
|
#include "RimWellLogPlot.h"
|
2015-11-04 09:14:42 -06:00
|
|
|
#include "RimWellLogTrack.h"
|
2015-11-04 09:22:53 -06:00
|
|
|
#include "RimWellLogCurve.h"
|
2015-09-04 08:57:34 -05:00
|
|
|
|
2016-06-28 03:58:22 -05:00
|
|
|
#include "RiuMainPlotWindow.h"
|
2015-09-17 03:53:37 -05:00
|
|
|
|
2015-08-31 08:23:20 -05:00
|
|
|
#include "qwt_legend.h"
|
2015-12-07 03:07:51 -06:00
|
|
|
#include "qwt_plot_curve.h"
|
|
|
|
#include "qwt_plot_grid.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"
|
2015-12-07 03:07:51 -06:00
|
|
|
#include "qwt_scale_engine.h"
|
2015-09-11 05:35:59 -05:00
|
|
|
#include "qwt_text.h"
|
2015-08-31 04:39:59 -05:00
|
|
|
|
2015-09-04 10:11:16 -05:00
|
|
|
#include <QFont>
|
2015-12-07 03:07:51 -06:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QWheelEvent>
|
2015-09-04 08:57:34 -05:00
|
|
|
|
2015-09-17 04:40:05 -05:00
|
|
|
#include <float.h>
|
2016-06-28 03:58:22 -05:00
|
|
|
#include "RiaApplication.h"
|
2015-09-17 04:40:05 -05:00
|
|
|
|
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-11-04 08:57:06 -06:00
|
|
|
RiuWellLogTrack::RiuWellLogTrack(RimWellLogTrack* 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-10-30 15:35:43 -05:00
|
|
|
|
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-11-04 08:57:06 -06:00
|
|
|
RiuWellLogTrack::~RiuWellLogTrack()
|
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-11-04 08:57:06 -06:00
|
|
|
void RiuWellLogTrack::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-11-04 08:57:06 -06:00
|
|
|
void RiuWellLogTrack::setDepthZoom(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
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-11-04 08:57:06 -06:00
|
|
|
void RiuWellLogTrack::setXRange(double min, double max)
|
2015-09-22 04:54:58 -05:00
|
|
|
{
|
|
|
|
setAxisScale(QwtPlot::xTop, min, max);
|
2015-10-29 08:13:44 -05:00
|
|
|
setAxisScale(QwtPlot::xBottom, 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-11-04 08:57:06 -06:00
|
|
|
void RiuWellLogTrack::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-11-04 08:57:06 -06:00
|
|
|
bool RiuWellLogTrack::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;
|
2016-09-21 06:59:41 -05:00
|
|
|
m_plotTrackDefinition->firstAncestorOrThisOfType(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)
|
|
|
|
{
|
2015-10-27 08:44:53 -05:00
|
|
|
plotDefinition->setDepthZoomByFactorAndCenter(RIU_SCROLLWHEEL_ZOOMFACTOR, zoomCenter);
|
2015-09-04 08:57:34 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-27 08:44:53 -05:00
|
|
|
plotDefinition->setDepthZoomByFactorAndCenter(1.0/RIU_SCROLLWHEEL_ZOOMFACTOR, zoomCenter);
|
2015-09-04 08:57:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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-11-04 08:57:06 -06:00
|
|
|
void RiuWellLogTrack::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
|
|
|
{
|
2016-06-28 03:58:22 -05:00
|
|
|
RiaApplication::instance()->getOrCreateAndShowMainPlotWindow()->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-11-04 08:57:06 -06:00
|
|
|
void RiuWellLogTrack::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);
|
2016-06-29 06:39:26 -05:00
|
|
|
double dist = DBL_MAX;
|
2015-10-26 05:09:57 -05:00
|
|
|
candidateCurve->closestPoint(pos, &dist);
|
2015-09-17 04:34:03 -05:00
|
|
|
if (dist < distMin)
|
|
|
|
{
|
|
|
|
closestCurve = candidateCurve;
|
|
|
|
distMin = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-25 03:25:44 -05:00
|
|
|
if (closestCurve && distMin < 20)
|
2015-09-17 04:34:03 -05:00
|
|
|
{
|
2015-11-04 09:19:38 -06:00
|
|
|
RimWellLogCurve* selectedCurve = m_plotTrackDefinition->curveDefinitionFromCurve(closestCurve);
|
2015-09-17 04:34:03 -05:00
|
|
|
if (selectedCurve)
|
|
|
|
{
|
2016-06-28 03:58:22 -05:00
|
|
|
RiaApplication::instance()->getOrCreateAndShowMainPlotWindow()->selectAsCurrentItem(selectedCurve);
|
2015-09-17 04:34:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-17 05:30:24 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-11-04 08:57:06 -06:00
|
|
|
QSize RiuWellLogTrack::sizeHint() const
|
2015-09-17 05:30:24 -05:00
|
|
|
{
|
|
|
|
return QSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-11-04 08:57:06 -06:00
|
|
|
QSize RiuWellLogTrack::minimumSizeHint() const
|
2015-09-17 05:30:24 -05:00
|
|
|
{
|
|
|
|
return QSize(0, 0);
|
|
|
|
}
|
2015-09-22 04:54:58 -05:00
|
|
|
|
2015-10-30 15:35:43 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-11-04 08:57:06 -06:00
|
|
|
bool RiuWellLogTrack::isRimTrackVisible()
|
2015-10-30 15:35:43 -05:00
|
|
|
{
|
|
|
|
if (m_plotTrackDefinition)
|
|
|
|
{
|
|
|
|
return m_plotTrackDefinition->isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|