diff --git a/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake index 8e4c8b573a..ec80c9eaaf 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake @@ -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 diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewGridTimeHistoryCurveFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicNewGridTimeHistoryCurveFeature.cpp index f4d95d9e95..92afe8a131 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewGridTimeHistoryCurveFeature.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewGridTimeHistoryCurveFeature.cpp @@ -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 @@ -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(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 items; RiuSelectionManager::instance()->selectedItems(items); + CVF_ASSERT(items.size() > 0); for (auto item : items) { - RicNewGridTimeHistoryCurveFeature::createCurveFromSelectionItem(item); + RicNewGridTimeHistoryCurveFeature::createCurveFromSelectionItem(item, summaryPlot); } } diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewGridTimeHistoryCurveFeature.h b/ApplicationCode/Commands/SummaryPlotCommands/RicNewGridTimeHistoryCurveFeature.h index 9553a47a79..3dbd33f8d4 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewGridTimeHistoryCurveFeature.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewGridTimeHistoryCurveFeature.h @@ -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(); }; diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSelectSummaryPlotUI.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSelectSummaryPlotUI.cpp new file mode 100644 index 0000000000..31497ecbdd --- /dev/null +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSelectSummaryPlotUI.cpp @@ -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 +// 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 RicSelectSummaryPlotUI::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) +{ + QList 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 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 sumPlots; + summaryPlotColl->descendantsIncludingThisOfType(sumPlots); + + return sumPlots; +} + diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSelectSummaryPlotUI.h b/ApplicationCode/Commands/SummaryPlotCommands/RicSelectSummaryPlotUI.h new file mode 100644 index 0000000000..cd2f97be90 --- /dev/null +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSelectSummaryPlotUI.h @@ -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 +// 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 calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override; + +protected: + virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; + +private: + static std::vector summaryPlots(); + +private: + caf::PdmPtrField m_selectedSummaryPlot; + caf::PdmField m_createNewPlot; + caf::PdmField m_newSummaryPlotName; +}; +