#1323 User selects destination plot for time history curves

This commit is contained in:
Magne Sjaastad 2017-03-19 21:41:13 +01:00
parent 79905ae474
commit fdbefb787a
5 changed files with 278 additions and 23 deletions

View File

@ -15,6 +15,7 @@ ${CEE_CURRENT_LIST_DIR}RicPasteSummaryPlotFeature.h
${CEE_CURRENT_LIST_DIR}RicPasteSummaryCurveFeature.h
${CEE_CURRENT_LIST_DIR}RicAsciiExportSummaryPlotFeature.h
${CEE_CURRENT_LIST_DIR}RicNewGridTimeHistoryCurveFeature.h
${CEE_CURRENT_LIST_DIR}RicSelectSummaryPlotUI.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -27,6 +28,7 @@ ${CEE_CURRENT_LIST_DIR}RicPasteSummaryPlotFeature.cpp
${CEE_CURRENT_LIST_DIR}RicPasteSummaryCurveFeature.cpp
${CEE_CURRENT_LIST_DIR}RicAsciiExportSummaryPlotFeature.cpp
${CEE_CURRENT_LIST_DIR}RicNewGridTimeHistoryCurveFeature.cpp
${CEE_CURRENT_LIST_DIR}RicSelectSummaryPlotUI.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -21,19 +21,23 @@
#include "RiaApplication.h"
#include "RicNewSummaryCurveFeature.h"
#include "RicSelectSummaryPlotUI.h"
#include "WellLogCommands/RicWellLogPlotCurveFeatureImpl.h"
#include "RimGridTimeHistoryCurve.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RiuMainPlotWindow.h"
#include "RiuSelectionManager.h"
#include "cvfAssert.h"
#include "cafPdmReferenceHelper.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cvfAssert.h"
#include "cvfColor3.h"
#include <QAction>
@ -44,8 +48,35 @@ CAF_CMD_SOURCE_INIT(RicNewGridTimeHistoryCurveFeature, "RicNewGridTimeHistoryCur
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewGridTimeHistoryCurveFeature::createCurveFromSelectionItem(const RiuSelectionItem* selectionItem)
void RicNewGridTimeHistoryCurveFeature::createCurveFromSelectionItem(const RiuSelectionItem* selectionItem, RimSummaryPlot* plot)
{
CVF_ASSERT(selectionItem);
CVF_ASSERT(plot);
RimGridTimeHistoryCurve* newCurve = new RimGridTimeHistoryCurve();
newCurve->setFromSelectionItem(selectionItem);
newCurve->setYAxis(RimDefines::PLOT_AXIS_RIGHT);
newCurve->setLineThickness(2);
cvf::Color3f curveColor = RicWellLogPlotCurveFeatureImpl::curveColorFromTable(plot->curveCount());
newCurve->setColor(curveColor);
plot->addGridTimeHistoryCurve(newCurve);
newCurve->loadDataAndUpdate();
plot->updateConnectedEditors();
RiaApplication::instance()->getOrCreateAndShowMainPlotWindow()->selectAsCurrentItem(newCurve);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicNewGridTimeHistoryCurveFeature::userSelectedSummaryPlot()
{
const QString lastUsedViewKey("lastUsedSummaryPlotKey");
RimProject* project = RiaApplication::instance()->project();
CVF_ASSERT(project);
@ -55,30 +86,53 @@ void RicNewGridTimeHistoryCurveFeature::createCurveFromSelectionItem(const RiuSe
RimSummaryPlotCollection* summaryPlotColl = mainPlotColl->summaryPlotCollection();
CVF_ASSERT(summaryPlotColl);
RimSummaryPlot* plot = nullptr;
if (summaryPlotColl->summaryPlots().size() > 0)
RimSummaryPlot* defaultSelectedPlot = nullptr;
{
plot = summaryPlotColl->summaryPlots()[0];
QString lastUsedPlotRef = RiaApplication::instance()->cacheDataObject(lastUsedViewKey).toString();
RimSummaryPlot* lastUsedPlot = dynamic_cast<RimSummaryPlot*>(caf::PdmReferenceHelper::objectFromReference(RiaApplication::instance()->project(), lastUsedPlotRef));
if (lastUsedPlot)
{
defaultSelectedPlot = lastUsedPlot;
}
if (!defaultSelectedPlot)
{
defaultSelectedPlot = RiaApplication::instance()->activeSummaryPlot();
}
if (!defaultSelectedPlot && summaryPlotColl->summaryPlots().size() > 0)
{
defaultSelectedPlot = summaryPlotColl->summaryPlots()[0];
}
}
if (plot)
RicSelectSummaryPlotUI featureUi;
if (defaultSelectedPlot)
{
RimGridTimeHistoryCurve* newCurve = new RimGridTimeHistoryCurve();
newCurve->setFromSelectionItem(selectionItem);
newCurve->setYAxis(RimDefines::PLOT_AXIS_RIGHT);
newCurve->setLineThickness(2);
cvf::Color3f curveColor = RicWellLogPlotCurveFeatureImpl::curveColorFromTable(plot->curveCount());
newCurve->setColor(curveColor);
plot->addGridTimeHistoryCurve(newCurve);
newCurve->loadDataAndUpdate();
plot->updateConnectedEditors();
RiaApplication::instance()->getOrCreateAndShowMainPlotWindow()->selectAsCurrentItem(newCurve);
featureUi.setDefaultSummaryPlot(defaultSelectedPlot);
}
caf::PdmUiPropertyViewDialog propertyDialog(NULL, &featureUi, "Select Summary Plot", "");
propertyDialog.resize(QSize(400, 200));
if (propertyDialog.exec() != QDialog::Accepted) return nullptr;
RimSummaryPlot* summaryPlot = nullptr;
if (featureUi.createNewPlot())
{
RimSummaryPlot* plot = new RimSummaryPlot();
summaryPlotColl->summaryPlots().push_back(plot);
plot->setDescription(featureUi.newPlotName());
summaryPlot = plot;
}
else
{
summaryPlot = featureUi.selectedSummaryPlot();
}
return summaryPlot;
}
//--------------------------------------------------------------------------------------------------
@ -102,12 +156,16 @@ bool RicNewGridTimeHistoryCurveFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicNewGridTimeHistoryCurveFeature::onActionTriggered(bool isChecked)
{
RimSummaryPlot* summaryPlot = RicNewGridTimeHistoryCurveFeature::userSelectedSummaryPlot();
if (!summaryPlot) return;
std::vector<RiuSelectionItem*> items;
RiuSelectionManager::instance()->selectedItems(items);
CVF_ASSERT(items.size() > 0);
for (auto item : items)
{
RicNewGridTimeHistoryCurveFeature::createCurveFromSelectionItem(item);
RicNewGridTimeHistoryCurveFeature::createCurveFromSelectionItem(item, summaryPlot);
}
}

View File

@ -21,6 +21,7 @@
#include "cafCmdFeature.h"
class RiuSelectionItem;
class RimSummaryPlot;
//==================================================================================================
///
@ -36,5 +37,6 @@ protected:
virtual void setupActionLook( QAction* actionToSetup ) override;
private:
static void createCurveFromSelectionItem(const RiuSelectionItem* selectionItem);
static void createCurveFromSelectionItem(const RiuSelectionItem* selectionItem, RimSummaryPlot* plot);
static RimSummaryPlot* userSelectedSummaryPlot();
};

View File

@ -0,0 +1,138 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 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 "RicSelectSummaryPlotUI.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
#include "RimProject.h"
#include "RiaApplication.h"
#include "RimSummaryPlotCollection.h"
#include "RimMainPlotCollection.h"
#include "RimSummaryPlot.h"
CAF_PDM_SOURCE_INIT(RicSelectSummaryPlotUI, "RicSelectSummaryPlotUI");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSelectSummaryPlotUI::RicSelectSummaryPlotUI()
{
CAF_PDM_InitObject("RicSelectSummaryPlotUI", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedSummaryPlot, "SelectedSummaryPlot", "Select Summary Plot", "", "", "");
CAF_PDM_InitField(&m_createNewPlot, "CreateNewPlot", false, "Create New Plot", "", "", "");
CAF_PDM_InitField(&m_newSummaryPlotName, "NewViewName", QString("Summary Plot"), "New Summary Plot Name", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSelectSummaryPlotUI::setDefaultSummaryPlot(RimSummaryPlot* summaryPlot)
{
m_selectedSummaryPlot = summaryPlot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicSelectSummaryPlotUI::selectedSummaryPlot() const
{
return m_selectedSummaryPlot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSelectSummaryPlotUI::createNewPlot() const
{
return m_createNewPlot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSelectSummaryPlotUI::newPlotName() const
{
return m_newSummaryPlotName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RicSelectSummaryPlotUI::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly)
{
QList<caf::PdmOptionItemInfo> options;
if (fieldNeedingOptions == &m_selectedSummaryPlot)
{
for (RimSummaryPlot* plot : RicSelectSummaryPlotUI::summaryPlots())
{
QIcon icon = plot->uiCapability()->uiIcon();
QString displayName = plot->description();
options.push_back(caf::PdmOptionItemInfo(displayName, plot, false, icon));
}
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSelectSummaryPlotUI::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
if (RicSelectSummaryPlotUI::summaryPlots().size() == 0)
{
m_createNewPlot = true;
}
if (m_createNewPlot)
{
m_newSummaryPlotName.uiCapability()->setUiReadOnly(false);
m_selectedSummaryPlot.uiCapability()->setUiReadOnly(true);
}
else
{
m_newSummaryPlotName.uiCapability()->setUiReadOnly(true);
m_selectedSummaryPlot.uiCapability()->setUiReadOnly(false);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryPlot*> RicSelectSummaryPlotUI::summaryPlots()
{
RimProject* project = RiaApplication::instance()->project();
CVF_ASSERT(project);
RimMainPlotCollection* mainPlotColl = project->mainPlotCollection();
CVF_ASSERT(mainPlotColl);
RimSummaryPlotCollection* summaryPlotColl = mainPlotColl->summaryPlotCollection();
CVF_ASSERT(summaryPlotColl);
std::vector<RimSummaryPlot*> sumPlots;
summaryPlotColl->descendantsIncludingThisOfType(sumPlots);
return sumPlots;
}

View File

@ -0,0 +1,55 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
class RimSummaryPlot;
//==================================================================================================
///
//==================================================================================================
class RicSelectSummaryPlotUI : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RicSelectSummaryPlotUI();
void setDefaultSummaryPlot(RimSummaryPlot* summaryPlot);
RimSummaryPlot* selectedSummaryPlot() const;
bool createNewPlot() const;
QString newPlotName() const;
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override;
protected:
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
private:
static std::vector<RimSummaryPlot*> summaryPlots();
private:
caf::PdmPtrField<RimSummaryPlot*> m_selectedSummaryPlot;
caf::PdmField<bool> m_createNewPlot;
caf::PdmField<QString> m_newSummaryPlotName;
};