ResInsight/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp

190 lines
5.8 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016 Statoil ASA
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimSummaryPlot.h"
#include "RimSummaryCurve.h"
#include "RimSummaryPlotCollection.h"
#include "RiuResultQwtPlot.h"
#include "RiuSelectionColors.h"
#include "cvfBase.h"
#include "cvfColor3.h"
#include <QDateTime>
#include "RiuMainWindow.h"
CAF_PDM_SOURCE_INIT(RimSummaryPlot, "GraphPlot");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot::RimSummaryPlot()
{
CAF_PDM_InitObject("Graph", ":/WellLogPlot16x16.png", "", "");
CAF_PDM_InitField(&m_showWindow, "ShowWindow", true, "Show Summary Plot", "", "", "");
m_showWindow.uiCapability()->setUiHidden(true);
CAF_PDM_InitField(&m_userName, "PlotDescription", QString("Summary Plot"), "Name", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_curves, "SummaryCurves", "", "", "", "");
m_curves.uiCapability()->setUiHidden(true);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot::~RimSummaryPlot()
{
deletePlotWidget();
m_curves.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::deletePlotWidget()
{
2016-05-25 06:54:06 -05:00
if (m_qwtPlot)
{
2016-05-25 06:54:06 -05:00
m_qwtPlot->deleteLater();
m_qwtPlot = NULL;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuResultQwtPlot* RimSummaryPlot::viewer()
{
2016-05-25 06:54:06 -05:00
return m_qwtPlot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::addCurve(RimSummaryCurve* curve)
{
if (curve)
{
m_curves.push_back(curve);
2016-05-25 06:54:06 -05:00
if (m_qwtPlot)
{
2016-05-25 06:54:06 -05:00
curve->setParentQwtPlot(m_qwtPlot);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if (changedField == &m_showWindow)
{
if (m_showWindow)
{
loadDataAndUpdate();
}
else
{
updateViewerWidget();
}
uiCapability()->updateUiIconFromToggleField();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::loadDataAndUpdate()
{
updateViewerWidget();
for (size_t i = 0; i < m_curves.size(); i++)
{
RimSummaryCurve* curve = m_curves[i];
curve->loadDataAndUpdate();
}
// Todo: Update zoom
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::setDescription(const QString& description)
{
m_userName = description;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::updateViewerWidget()
{
if (m_showWindow())
{
2016-05-25 06:54:06 -05:00
if (!m_qwtPlot)
{
2016-05-25 06:54:06 -05:00
m_qwtPlot = new RiuResultQwtPlot(RiuMainWindow::instance());
for (size_t cIdx = 0; cIdx < m_curves.size(); ++cIdx )
{
2016-05-25 06:54:06 -05:00
m_curves[cIdx]->setParentQwtPlot(m_qwtPlot);
}
2016-05-25 06:54:06 -05:00
RiuMainWindow::instance()->addViewer(m_qwtPlot, std::vector<int>());
RiuMainWindow::instance()->setActiveViewer(m_qwtPlot);
}
//updateViewerWidgetWindowTitle();
}
else
{
2016-05-25 06:54:06 -05:00
if (m_qwtPlot)
{
//windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer);
2016-05-25 06:54:06 -05:00
RiuMainWindow::instance()->removeViewer(m_qwtPlot);
detachAllCurves();
2016-05-25 06:54:06 -05:00
delete m_qwtPlot;
m_qwtPlot = NULL;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::detachAllCurves()
{
for (size_t cIdx = 0; cIdx < m_curves.size(); ++cIdx)
{
m_curves[cIdx]->detachQwtCurve();
}
}