From 43249f7af8fdc364e2cdd96903266a51088215d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Tue, 17 Jan 2017 13:06:57 +0100 Subject: [PATCH 01/27] Refactor related to #1106, #1107, #1109, #1113. Refactored the MDI control of windows. This might introduce problems. --- .../Application/RiaApplication.cpp | 10 + ApplicationCode/Application/RiaApplication.h | 2 + .../RicNewWellLogPlotFeatureImpl.cpp | 1 + .../ProjectDataModel/CMakeLists_files.cmake | 2 + .../Flow/RimWellAllocationPlot.cpp | 95 ++------- .../Flow/RimWellAllocationPlot.h | 15 +- .../ProjectDataModel/RimEclipseView.cpp | 26 +-- .../ProjectDataModel/RimEclipseView.h | 1 - .../ProjectDataModel/RimGeoMechView.cpp | 27 +-- .../ProjectDataModel/RimGeoMechView.h | 1 - .../RimMdiWindowController.cpp | 191 ++++++++++++++++++ .../ProjectDataModel/RimMdiWindowController.h | 139 +++++++++++++ ApplicationCode/ProjectDataModel/RimView.cpp | 134 ++++++------ ApplicationCode/ProjectDataModel/RimView.h | 11 +- .../ProjectDataModel/RimViewWindow.cpp | 137 ++++++++++--- .../ProjectDataModel/RimViewWindow.h | 47 ++++- .../ProjectDataModel/RimWellLogPlot.cpp | 92 ++------- .../ProjectDataModel/RimWellLogPlot.h | 10 +- .../ProjectDataModel/RimWellLogTrack.cpp | 6 +- .../Summary/RimSummaryPlot.cpp | 106 +++------- .../ProjectDataModel/Summary/RimSummaryPlot.h | 13 +- .../UserInterface/RiuMainPlotWindow.cpp | 1 + .../UserInterface/RiuMainPlotWindow.h | 8 +- .../UserInterface/RiuMainWindow.cpp | 1 + ApplicationCode/UserInterface/RiuMainWindow.h | 6 +- .../UserInterface/RiuMainWindowBase.h | 7 + .../UserInterface/RiuSummaryQwtPlot.cpp | 1 + ApplicationCode/UserInterface/RiuViewer.cpp | 3 +- .../UserInterface/RiuWellLogPlot.cpp | 1 + .../UserInterface/RiuWellLogPlot.h | 4 +- 30 files changed, 695 insertions(+), 403 deletions(-) create mode 100644 ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp create mode 100644 ApplicationCode/ProjectDataModel/RimMdiWindowController.h diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 7d47cc684b..f3c0daf6b8 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -1591,6 +1591,16 @@ RiuMainPlotWindow* RiaApplication::mainPlotWindow() return m_mainPlotWindow; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuMainWindowBase* RiaApplication::mainWindowByID(int mainWindowID) +{ + if (mainWindowID == 0) return RiuMainWindow::instance(); + else if (mainWindowID == 1) return m_mainPlotWindow; + else return nullptr; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaApplication.h b/ApplicationCode/Application/RiaApplication.h index f4c372c934..ba1377cab3 100644 --- a/ApplicationCode/Application/RiaApplication.h +++ b/ApplicationCode/Application/RiaApplication.h @@ -55,6 +55,7 @@ class RimViewWindow; class RimWellLogPlot; class RimWellAllocationPlot; +class RiuMainWindowBase; class RiuMainPlotWindow; class RiuRecentFileActionProvider; @@ -185,6 +186,7 @@ public: RiuMainPlotWindow* getOrCreateAndShowMainPlotWindow(); RiuMainPlotWindow* mainPlotWindow(); + RiuMainWindowBase* mainWindowByID(int mainWindowID); static RimViewWindow* activeViewWindow(); diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeatureImpl.cpp b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeatureImpl.cpp index 812cd4e4ae..fa821a4f0d 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeatureImpl.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeatureImpl.cpp @@ -39,6 +39,7 @@ RimWellLogPlot* RicNewWellLogPlotFeatureImpl::createWellLogPlot() CVF_ASSERT(wellLogPlotColl); RimWellLogPlot* plot = new RimWellLogPlot(); + plot->setAsPlotMDI(); wellLogPlotColl->wellLogPlots().push_back(plot); // Make sure the summary plot window is created and visible diff --git a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake index dbe7ba7e24..34b46278ae 100644 --- a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake @@ -83,6 +83,7 @@ ${CEE_CURRENT_LIST_DIR}RimPlotCurve.h ${CEE_CURRENT_LIST_DIR}RimEclipseInputCaseOpm.h ${CEE_CURRENT_LIST_DIR}RimIntersectionBox.h ${CEE_CURRENT_LIST_DIR}RimMultiSnapshotDefinition.h +${CEE_CURRENT_LIST_DIR}RimMdiWindowController.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -164,6 +165,7 @@ ${CEE_CURRENT_LIST_DIR}RimPlotCurve.cpp ${CEE_CURRENT_LIST_DIR}RimEclipseInputCaseOpm.cpp ${CEE_CURRENT_LIST_DIR}RimIntersectionBox.cpp ${CEE_CURRENT_LIST_DIR}RimMultiSnapshotDefinition.cpp +${CEE_CURRENT_LIST_DIR}RimMdiWindowController.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 116cc14183..0fdc2c6e6a 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -46,6 +46,8 @@ RimWellAllocationPlot::RimWellAllocationPlot() CAF_PDM_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_simulationWell, "SimulationWell", "Simulation Well", "", "", ""); + + this->setAsPlotMDI(); } //-------------------------------------------------------------------------------------------------- @@ -53,12 +55,9 @@ RimWellAllocationPlot::RimWellAllocationPlot() //-------------------------------------------------------------------------------------------------- RimWellAllocationPlot::~RimWellAllocationPlot() { - if (RiaApplication::instance()->mainPlotWindow()) - { - RiaApplication::instance()->mainPlotWindow()->removeViewer(m_wellAllocationPlot); - } + removeWidgetFromMDI(); - deletePlotWidget(); + deleteViewWidget(); } //-------------------------------------------------------------------------------------------------- @@ -74,12 +73,12 @@ void RimWellAllocationPlot::setSimulationWell(RimEclipseWell* simWell) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellAllocationPlot::deletePlotWidget() +void RimWellAllocationPlot::deleteViewWidget() { - if (m_wellAllocationPlot) + if (m_wellAllocationPlotWidget) { - m_wellAllocationPlot->deleteLater(); - m_wellAllocationPlot = nullptr; + m_wellAllocationPlotWidget->deleteLater(); + m_wellAllocationPlotWidget = nullptr; } } @@ -96,7 +95,7 @@ void RimWellAllocationPlot::updateFromWell() } setDescription(simName); - updateViewerWidget(); + updateViewerWidgetBasic(); } //-------------------------------------------------------------------------------------------------- @@ -104,7 +103,7 @@ void RimWellAllocationPlot::updateFromWell() //-------------------------------------------------------------------------------------------------- QWidget* RimWellAllocationPlot::viewWidget() { - return m_wellAllocationPlot; + return m_wellAllocationPlotWidget; } //-------------------------------------------------------------------------------------------------- @@ -148,17 +147,6 @@ QList RimWellAllocationPlot::calculateValueOptions(const return options; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellAllocationPlot::handleViewerDeletion() -{ - m_showWindow = false; - - uiCapability()->updateUiIconFromToggleField(); - updateConnectedEditors(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -166,7 +154,7 @@ void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedF { if (changedField == &m_showWindow) { - updateViewerWidget(); + updateViewerWidgetBasic(); uiCapability()->updateUiIconFromToggleField(); } @@ -181,16 +169,6 @@ void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedF } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellAllocationPlot::setupBeforeSave() -{ - if (m_wellAllocationPlot && RiaApplication::instance()->mainPlotWindow()) - { - this->setMdiWindowGeometry(RiaApplication::instance()->mainPlotWindow()->windowGeometryForViewer(m_wellAllocationPlot)); - } -} //-------------------------------------------------------------------------------------------------- /// @@ -225,59 +203,16 @@ QString RimWellAllocationPlot::description() const //-------------------------------------------------------------------------------------------------- void RimWellAllocationPlot::loadDataAndUpdate() { - updateViewerWidget(); + updateViewerWidgetBasic(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellAllocationPlot::updateViewerWidget() +QWidget* RimWellAllocationPlot::createViewWidget(QWidget* mainWindowParent) { - RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow(); - if (!mainPlotWindow) return; - - if (m_showWindow()) - { - if (!m_wellAllocationPlot) - { - m_wellAllocationPlot = new RiuWellAllocationPlot(this, mainPlotWindow); - - mainPlotWindow->addViewer(m_wellAllocationPlot, this->mdiWindowGeometry()); - mainPlotWindow->setActiveViewer(m_wellAllocationPlot); - } - - updateViewerWidgetWindowTitle(); - } - else - { - if (m_wellAllocationPlot) - { - this->setMdiWindowGeometry(mainPlotWindow->windowGeometryForViewer(m_wellAllocationPlot)); - - mainPlotWindow->removeViewer(m_wellAllocationPlot); - - deletePlotWidget(); - } - } + m_wellAllocationPlotWidget = new RiuWellAllocationPlot(this, mainWindowParent); + return m_wellAllocationPlotWidget; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellAllocationPlot::updateViewerWidgetWindowTitle() -{ - if (m_wellAllocationPlot) - { - m_wellAllocationPlot->setWindowTitle(m_userName); - - if (m_showPlotTitle) - { - m_wellAllocationPlot->setTitle(m_userName); - } - else - { - m_wellAllocationPlot->setTitle(""); - } - } -} diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index f604c002b8..1b0a671450 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -54,8 +54,6 @@ public: void loadDataAndUpdate(); - void handleViewerDeletion(); - virtual QWidget* viewWidget() override; virtual void zoomAll() override; @@ -67,16 +65,19 @@ protected: virtual caf::PdmFieldHandle* objectToggleField() { return &m_showWindow; } virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; - virtual void setupBeforeSave() override; virtual QImage snapshotWindowContent() override; private: - void updateViewerWidget(); - void updateViewerWidgetWindowTitle(); - void deletePlotWidget(); void updateFromWell(); + // RimViewWindow overrides + + virtual caf::PdmField* getShowWindowField() override { return &m_showWindow; } + virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; + virtual void deleteViewWidget() override; + + private: caf::PdmField m_showWindow; @@ -85,5 +86,5 @@ private: caf::PdmPtrField m_simulationWell; - QPointer m_wellAllocationPlot; + QPointer m_wellAllocationPlotWidget; }; diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index 620127fa03..a75bc380c1 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -159,26 +159,6 @@ RimEclipseView::~RimEclipseView() m_reservoir = NULL; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimEclipseView::updateViewerWidgetWindowTitle() -{ - if (m_viewer) - { - QString windowTitle; - if (m_reservoir.notNull()) - { - windowTitle = QString("%1 - %2").arg(m_reservoir->caseUserDescription()).arg(name); - } - else - { - windowTitle = name; - } - - m_viewer->layoutWidget()->setWindowTitle(windowTitle); - } -} //-------------------------------------------------------------------------------------------------- /// Clamp the current timestep to actual possibilities @@ -208,7 +188,7 @@ void RimEclipseView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c if (showWindow) { bool generateDisplayModel = (viewer() == NULL); - updateViewerWidget(); + updateViewerWidgetBasic(); if (generateDisplayModel) { @@ -709,7 +689,7 @@ void RimEclipseView::loadDataAndUpdate() this->faultResultSettings()->customFaultResult()->loadResult(); - updateViewerWidget(); + updateViewerWidgetBasic(); this->m_propertyFilterCollection()->loadAndInitializePropertyFilters(); @@ -731,6 +711,8 @@ void RimEclipseView::loadDataAndUpdate() //-------------------------------------------------------------------------------------------------- void RimEclipseView::initAfterRead() { + RimViewWindow::initAfterRead(); + this->faultResultSettings()->setReservoirView(this); this->cellResult()->setReservoirView(this); this->cellEdgeResult()->setReservoirView(this); diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.h b/ApplicationCode/ProjectDataModel/RimEclipseView.h index adc4ddc20b..f3966abdbe 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.h +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.h @@ -164,7 +164,6 @@ private: void updateLegends(); void updateMinMaxValuesAndAddLegendToView(QString legendLabel, RimEclipseCellColors* resultColors, RigCaseCellResultsData* cellResultsData); virtual void resetLegendsInViewer(); - virtual void updateViewerWidgetWindowTitle(); std::set allVisibleFaultGeometryTypes() const; void updateFaultColors(); diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp index 472a967cba..e5bd609b4b 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp @@ -99,28 +99,6 @@ RimGeoMechView::~RimGeoMechView(void) delete m_propertyFilterCollection; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimGeoMechView::updateViewerWidgetWindowTitle() -{ - if (m_viewer) - { - QString windowTitle; - if (m_geomechCase.notNull()) - { - windowTitle = QString("%1 - %2").arg(m_geomechCase->caseUserDescription()).arg(name); - } - else - { - windowTitle = name; - } - - m_viewer->layoutWidget()->setWindowTitle(windowTitle); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -156,7 +134,7 @@ void RimGeoMechView::loadDataAndUpdate() progress.incrementProgress(); progress.setProgressDescription("Create Display model"); - updateViewerWidget(); + updateViewerWidgetBasic(); this->geoMechPropertyFilterCollection()->loadAndInitializePropertyFilters(); @@ -504,7 +482,7 @@ void RimGeoMechView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c if (showWindow) { bool generateDisplayModel = (viewer() == NULL); - updateViewerWidget(); + updateViewerWidgetBasic(); if (generateDisplayModel) { @@ -532,6 +510,7 @@ void RimGeoMechView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c //-------------------------------------------------------------------------------------------------- void RimGeoMechView::initAfterRead() { + RimViewWindow::initAfterRead(); this->cellResult()->setGeoMechCase(m_geomechCase); this->updateUiIconFromToggleField(); diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.h b/ApplicationCode/ProjectDataModel/RimGeoMechView.h index a28aae99a4..0f59007179 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.h +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.h @@ -99,7 +99,6 @@ private: virtual void updateCurrentTimeStep(); virtual void updateStaticCellColors(); - virtual void updateViewerWidgetWindowTitle(); virtual void resetLegendsInViewer(); void updateLegends(); diff --git a/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp b/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp new file mode 100644 index 0000000000..88ba9f9ceb --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp @@ -0,0 +1,191 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RimMdiWindowController.h" +#include "RiuMainWindowBase.h" +#include "RiaApplication.h" +#include "RimViewWindow.h" + +CAF_PDM_XML_SOURCE_INIT(RimMdiWindowController, "MdiWindowController"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimMdiWindowController::RimMdiWindowController() +{ + CAF_PDM_InitField(&m_mainWindowID, "MainWindowID", -1, "", "", "", "" ); + CAF_PDM_InitField(& m_x , "xPos", -1, "", "", "", "" ); + CAF_PDM_InitField(& m_y , "yPos", -1, "", "", "", "" ); + CAF_PDM_InitField(& m_width , "Width", -1, "", "", "", "" ); + CAF_PDM_InitField(& m_height , "Height", -1, "", "", "", "" ); + CAF_PDM_InitField(& m_isMaximized, "IsMaximized", false, "", "", "", "" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimMdiWindowController::~RimMdiWindowController() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMdiWindowController::setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry) +{ + m_mainWindowID = windowGeometry.mainWindowID; + m_x = windowGeometry.x; + m_y = windowGeometry.y; + m_width = windowGeometry.width; + m_height = windowGeometry.height; + m_isMaximized = windowGeometry.isMaximized; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimMdiWindowGeometry RimMdiWindowController::mdiWindowGeometry() +{ + RimMdiWindowGeometry windowGeometry; + + windowGeometry.mainWindowID = m_mainWindowID; + windowGeometry.x = m_x ; + windowGeometry.y = m_y ; + windowGeometry.width = m_width ; + windowGeometry.height = m_height ; + windowGeometry.isMaximized = m_isMaximized ; + + return windowGeometry; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMdiWindowController::handleViewerDeletion() +{ + showWindowField() = false; + + uiCapability()->updateUiIconFromToggleField(); + updateConnectedEditors(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMdiWindowController::removeWindowFromMDI() +{ + RiuMainWindowBase* mainWin = getMainWindow(); + if (mainWin && viewWidget()) mainWin->removeViewer(viewWidget()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMdiWindowController::showWindowFieldChangedByUi() +{ + updateViewerWidget(); + + viewPdmObject()->uiCapability()->updateUiIconFromToggleField(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimViewWindow* RimMdiWindowController::viewPdmObject() +{ + RimViewWindow * viewWindowObj; + this->firstAncestorOrThisOfType(viewWindowObj); + return viewWindowObj; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmField& RimMdiWindowController::showWindowField() +{ + return *(viewPdmObject()->getShowWindowField()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* RimMdiWindowController::viewWidget() +{ + return viewPdmObject()->viewWidget(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuMainWindowBase* RimMdiWindowController::getMainWindow() +{ + return RiaApplication::instance()->mainWindowByID(m_mainWindowID); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMdiWindowController::setupBeforeSave() +{ + if ( viewWidget() && getMainWindow() ) + { + this->setMdiWindowGeometry(getMainWindow()->windowGeometryForViewer(viewWidget())); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMdiWindowController::updateViewerWidget() +{ + RiuMainWindowBase* mainWindow = getMainWindow(); + if ( !mainWindow ) return; + + if ( showWindowField() ) + { + if ( !viewWidget() ) + { + // m_wellAllocationPlotWidget = new RiuWellAllocationPlot(this, mainPlotWindow); + QWidget * viewWidget = viewPdmObject()->createViewWidget(mainWindow); + + mainWindow->addViewer(viewWidget, this->mdiWindowGeometry()); + mainWindow->setActiveViewer(viewWidget); + + viewPdmObject()->updateViewWidgetAfterCreation(); + } + else + { + mainWindow->setActiveViewer(viewWidget()); + } + + viewPdmObject()->updateViewerWidgetWindowTitle(); + } + else + { + if ( viewWidget() ) + { + this->setMdiWindowGeometry(mainWindow->windowGeometryForViewer(viewWidget())); + + mainWindow->removeViewer(viewWidget()); + + viewPdmObject()->deleteViewWidget(); + } + } +} + diff --git a/ApplicationCode/ProjectDataModel/RimMdiWindowController.h b/ApplicationCode/ProjectDataModel/RimMdiWindowController.h new file mode 100644 index 0000000000..b6f5fd6b1e --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimMdiWindowController.h @@ -0,0 +1,139 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "cafPdmObject.h" +#include "cafPdmChildField.h" +#include "cafPdmField.h" + +#if 0 +class RimMdiWindowController; + +class RimViewWindow : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; +public: + RimViewWindow(void); + virtual ~RimViewWindow(void) + { + if (m_windowController()) delete m_windowController(); + } + + void handleViewerDeletion() { if (m_windowController()) m_windowController->handleViewerDeletion(); } + void updateViewerWidgetBasic() { if (m_windowController()) m_windowController->updateViewerWidget(); } + + void setAs3DMDI() { setAsMDI(0); } + void setAsPlotMDI() { setAsMDI(1); } + + void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry); + RimMdiWindowGeometry mdiWindowGeometry(); + + virtual QImage snapshotWindowContent() = 0; + virtual void zoomAll() = 0; + +protected: + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override + { + if ( m_windowController() ) + { + if ( changedField == showWindowField() ) + { + m_windowController()->showWindowFieldChangedByUi(); + } + } + } + +private: + + ///////// Interface for the Window controller + friend class RimMdiWindowController; + + virtual QWidget* viewWidget() = 0; + virtual QWidget* createViewWidget(QWidget* mainWindowParent) = 0; + virtual void updateViewWidgetAfterCreation() = 0; + virtual void deleteViewWidget() = 0; + + virtual caf::PdmField* showWindowField() = 0; + + ////////// + + void setAsMDI(int mainWindowID) + { + if (!m_windowController()) + { + m_windowController = new RimMdiWindowController; + RimMdiWindowGeometry mwg; + mwg.mainWindowID = mainWindowID; + setMdiWindowGeometry(mwg); + } + } + + caf::PdmChildField m_windowController; + + // Obsolete field + caf::PdmField< std::vector > m_windowGeometry; +}; +#endif + +class RimViewWindow; +class RiuMainWindowBase; +struct RimMdiWindowGeometry; + +//================================================================================================== +/// +/// +//================================================================================================== +class RimMdiWindowController : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; + +public: + RimMdiWindowController(); + virtual ~RimMdiWindowController(); + + void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry); + RimMdiWindowGeometry mdiWindowGeometry(); + + void updateViewerWidget(); + void handleViewerDeletion(); + void removeWindowFromMDI(); + void showWindowFieldChangedByUi(); + +protected: + + RimViewWindow* viewPdmObject(); + caf::PdmField& showWindowField(); + QWidget* viewWidget(); + RiuMainWindowBase* getMainWindow(); + + // Overridden PDM methods + virtual void setupBeforeSave() override; + +private: + + caf::PdmField< int > m_mainWindowID; + + caf::PdmField< int > m_x; + caf::PdmField< int > m_y; + caf::PdmField< int > m_width; + caf::PdmField< int > m_height; + caf::PdmField< bool> m_isMaximized; +}; + + diff --git a/ApplicationCode/ProjectDataModel/RimView.cpp b/ApplicationCode/ProjectDataModel/RimView.cpp index 35f523ee79..f7b73c7f37 100644 --- a/ApplicationCode/ProjectDataModel/RimView.cpp +++ b/ApplicationCode/ProjectDataModel/RimView.cpp @@ -140,6 +140,8 @@ RimView::RimView(void) m_wellPathPipeVizModel = new cvf::ModelBasicList; m_wellPathPipeVizModel->setName("WellPathPipeModel"); + + this->setAs3DMDI(); } //-------------------------------------------------------------------------------------------------- @@ -169,12 +171,9 @@ RimView::~RimView(void) delete this->m_overlayInfoConfig(); - if (m_viewer) - { - RiuMainWindow::instance()->removeViewer(m_viewer->layoutWidget()); - } + removeWidgetFromMDI(); - delete m_viewer; + deleteViewWidget(); delete m_rangeFilterCollection; delete m_overrideRangeFilterCollection; @@ -193,64 +192,76 @@ RiuViewer* RimView::viewer() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimView::updateViewerWidget() +QWidget* RimView::createViewWidget(QWidget* mainWindowParent) { - if (showWindow()) - { - bool isViewerCreated = false; - if (!m_viewer) - { - QGLFormat glFormat; - glFormat.setDirectRendering(RiaApplication::instance()->useShaders()); + QGLFormat glFormat; + glFormat.setDirectRendering(RiaApplication::instance()->useShaders()); - m_viewer = new RiuViewer(glFormat, NULL); - m_viewer->setOwnerReservoirView(this); + m_viewer = new RiuViewer(glFormat, NULL); + m_viewer->setOwnerReservoirView(this); - RiuMainWindow::instance()->addViewer(m_viewer->layoutWidget(), mdiWindowGeometry()); - m_viewer->setDefaultPerspectiveNearPlaneDistance(10); - - this->resetLegendsInViewer(); - - m_viewer->updateNavigationPolicy(); - m_viewer->enablePerfInfoHud(RiaApplication::instance()->showPerformanceInfo()); - - isViewerCreated = true; - } - - RiuMainWindow::instance()->setActiveViewer(m_viewer->layoutWidget()); - - if(isViewerCreated) - { - m_viewer->mainCamera()->setViewMatrix(cameraPosition); - m_viewer->setPointOfInterest(cameraPointOfInterest()); - m_viewer->enableParallelProjection(!isPerspectiveView()); - } - m_viewer->mainCamera()->viewport()->setClearColor(cvf::Color4f(backgroundColor())); - - this->updateGridBoxData(); - this->createHighlightAndGridBoxDisplayModel(); - - m_viewer->update(); - } - else - { - if (m_viewer && m_viewer->layoutWidget()) - { - if (m_viewer->layoutWidget()->parentWidget()) - { - m_viewer->layoutWidget()->parentWidget()->hide(); - } - else - { - m_viewer->layoutWidget()->hide(); - } - } - } - - updateViewerWidgetWindowTitle(); + return m_viewer->layoutWidget(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimView::updateViewWidgetAfterCreation() +{ + m_viewer->setDefaultPerspectiveNearPlaneDistance(10); + + this->resetLegendsInViewer(); + + m_viewer->updateNavigationPolicy(); + m_viewer->enablePerfInfoHud(RiaApplication::instance()->showPerformanceInfo()); + + m_viewer->mainCamera()->setViewMatrix(cameraPosition); + m_viewer->setPointOfInterest(cameraPointOfInterest()); + m_viewer->enableParallelProjection(!isPerspectiveView()); + + m_viewer->mainCamera()->viewport()->setClearColor(cvf::Color4f(backgroundColor())); + + this->updateGridBoxData(); + this->createHighlightAndGridBoxDisplayModel(); + + m_viewer->update(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimView::updateViewerWidgetWindowTitle() +{ + if (m_viewer) + { + QString windowTitle; + if (ownerCase()) + { + windowTitle = QString("%1 - %2").arg(ownerCase()->caseUserDescription()).arg(name); + } + else + { + windowTitle = name; + } + + m_viewer->layoutWidget()->setWindowTitle(windowTitle); + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimView::deleteViewWidget() +{ + if (m_viewer) + { + m_viewer->deleteLater(); + m_viewer = nullptr; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -367,8 +378,6 @@ void RimView::setupBeforeSave() hasUserRequestedAnimation = m_viewer->isAnimationActive(); // JJS: This is not conceptually correct. The variable is updated as we go, and store the user intentions. But I guess that in practice... cameraPosition = m_viewer->mainCamera()->viewMatrix(); cameraPointOfInterest = m_viewer->pointOfInterest(); - - setMdiWindowGeometry(RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget())); } } @@ -617,9 +626,9 @@ void RimView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QV } else if (changedField == &backgroundColor) { - if (viewer() != NULL) + if (m_viewer != nullptr) { - updateViewerWidget(); + m_viewer->mainCamera()->viewport()->setClearColor(cvf::Color4f(backgroundColor())); } } else if (changedField == &maximumFrameRate) @@ -953,6 +962,7 @@ cvf::ref RimView::displayCoordTransform() //-------------------------------------------------------------------------------------------------- QWidget* RimView::viewWidget() { - return m_viewer; + if ( m_viewer ) return m_viewer->layoutWidget(); + else return nullptr; } diff --git a/ApplicationCode/ProjectDataModel/RimView.h b/ApplicationCode/ProjectDataModel/RimView.h index 374f7b5b3d..30ca0e0a14 100644 --- a/ApplicationCode/ProjectDataModel/RimView.h +++ b/ApplicationCode/ProjectDataModel/RimView.h @@ -199,9 +199,6 @@ protected: virtual void updateScaleTransform() = 0; virtual cvf::Transform* scaleTransform() = 0; - void updateViewerWidget(); - virtual void updateViewerWidgetWindowTitle() = 0; - virtual void resetLegendsInViewer() = 0; virtual void calculateCurrentTotalCellVisibility(cvf::UByteArray* totalVisibility) = 0; @@ -217,8 +214,14 @@ protected: // Overridden PDM methods: virtual void setupBeforeSave(); + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); - virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); + + virtual caf::PdmField* getShowWindowField() override { return &showWindow; } + virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; + virtual void updateViewWidgetAfterCreation() override; + virtual void updateViewerWidgetWindowTitle() override; + virtual void deleteViewWidget() override; cvf::ref m_currentReservoirCellVisibility; diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp index d7ea0b0309..5a07117493 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp @@ -17,7 +17,9 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RimViewWindow.h" - +#include "RimMdiWindowController.h" +#include "cvfAssert.h" +#include CAF_PDM_XML_ABSTRACT_SOURCE_INIT(RimViewWindow, "ViewWindow"); // Do not use. Abstract class @@ -26,9 +28,14 @@ CAF_PDM_XML_ABSTRACT_SOURCE_INIT(RimViewWindow, "ViewWindow"); // Do not use. Ab //-------------------------------------------------------------------------------------------------- RimViewWindow::RimViewWindow(void) { + CAF_PDM_InitFieldNoDefault(&m_windowController, "WindowController", "", "", "", ""); + m_windowController.uiCapability()->setUiHidden(true); + + + // Obsolete field CAF_PDM_InitFieldNoDefault(&m_windowGeometry, "WindowGeometry", "", "", "", ""); m_windowGeometry.uiCapability()->setUiHidden(true); - + m_windowGeometry.xmlCapability()->setIOWritable(false); } //-------------------------------------------------------------------------------------------------- @@ -36,7 +43,31 @@ RimViewWindow::RimViewWindow(void) //-------------------------------------------------------------------------------------------------- RimViewWindow::~RimViewWindow(void) { + if ( m_windowController() ) delete m_windowController() ; +} +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewWindow::removeWidgetFromMDI() +{ + if ( m_windowController() ) m_windowController->removeWindowFromMDI(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewWindow::handleViewerDeletion() +{ + if ( m_windowController() ) m_windowController->handleViewerDeletion(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewWindow::updateViewerWidgetBasic() +{ + if ( m_windowController() ) m_windowController->updateViewerWidget(); } //-------------------------------------------------------------------------------------------------- @@ -44,17 +75,10 @@ RimViewWindow::~RimViewWindow(void) //-------------------------------------------------------------------------------------------------- void RimViewWindow::setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry) { - std::vector geom; - geom.clear(); - if (windowGeometry.isValid()) - { - geom.push_back(windowGeometry.x); - geom.push_back(windowGeometry.y); - geom.push_back(windowGeometry.width); - geom.push_back(windowGeometry.height); - geom.push_back(windowGeometry.isMaximized); - } - m_windowGeometry.setValue(geom); + CVF_ASSERT(m_windowController()); + + if (m_windowController()) m_windowController()->setMdiWindowGeometry(windowGeometry); + } //-------------------------------------------------------------------------------------------------- @@ -62,17 +86,84 @@ void RimViewWindow::setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeome //-------------------------------------------------------------------------------------------------- RimMdiWindowGeometry RimViewWindow::mdiWindowGeometry() { + CVF_ASSERT(m_windowController()); - RimMdiWindowGeometry wg; - if (m_windowGeometry.value().size() == 5) - { - wg.x = m_windowGeometry.value()[0]; - wg.y = m_windowGeometry.value()[1]; - wg.width = m_windowGeometry.value()[2]; - wg.height = m_windowGeometry.value()[3]; - wg.isMaximized = m_windowGeometry.value()[4]; - } + if (m_windowController()) return m_windowController()->mdiWindowGeometry(); + else return RimMdiWindowGeometry(); - return wg; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewWindow::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +{ + if ( m_windowController() ) + { + if ( changedField == getShowWindowField() ) + { + m_windowController()->showWindowFieldChangedByUi(); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewWindow::updateViewerWidgetWindowTitle() +{ + if ( viewWidget() ) + { + caf::PdmUiFieldHandle* uiFieldHandle = this->userDescriptionField()->uiCapability(); + if ( uiFieldHandle ) + { + QVariant v = uiFieldHandle->uiValue(); + viewWidget()->setWindowTitle(v.toString()); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewWindow::setAsMDI(int mainWindowID) +{ + if ( !m_windowController() ) + { + m_windowController = new RimMdiWindowController; + RimMdiWindowGeometry mwg; + mwg.mainWindowID = mainWindowID; + setMdiWindowGeometry(mwg); + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +#include "RimView.h" + +void RimViewWindow::initAfterRead() +{ + if (m_windowGeometry.value().size() == 5) + { + RimMdiWindowGeometry wg; + int mainWindowID = -1; + + if (dynamic_cast (this)) + mainWindowID = 0; + else + mainWindowID = 1; + + wg.mainWindowID = mainWindowID; + wg.x = m_windowGeometry.value()[0]; + wg.y = m_windowGeometry.value()[1]; + wg.width = m_windowGeometry.value()[2]; + wg.height = m_windowGeometry.value()[3]; + wg.isMaximized = m_windowGeometry.value()[4]; + + setAsMDI(mainWindowID); + setMdiWindowGeometry(wg); + } } diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.h b/ApplicationCode/ProjectDataModel/RimViewWindow.h index d351aba516..bc8111b337 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.h @@ -20,13 +20,18 @@ #include "cafPdmObject.h" #include "cafPdmField.h" +#include "cafPdmChildField.h" #include +class RimMdiWindowController; + struct RimMdiWindowGeometry { - RimMdiWindowGeometry() : x(0), y(0), width(-1), height(-1) {} - bool isValid() const { return (width >= 0 && height >= 0);} + RimMdiWindowGeometry() : mainWindowID(-1), x(0), y(0), width(-1), height(-1) {} + bool isValid() const { return (mainWindowID >= 0 && width >= 0 && height >= 0);} + + int mainWindowID; int x; int y; @@ -42,15 +47,45 @@ public: RimViewWindow(void); virtual ~RimViewWindow(void); + void removeWidgetFromMDI(); + void handleViewerDeletion(); + void updateViewerWidgetBasic(); + + void setAs3DMDI() { setAsMDI(0); } + void setAsPlotMDI() { setAsMDI(1); } + void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry); RimMdiWindowGeometry mdiWindowGeometry(); - virtual QImage snapshotWindowContent() = 0; - virtual void zoomAll() = 0; + virtual QImage snapshotWindowContent() = 0; + virtual QWidget* viewWidget() = 0; - virtual QWidget* viewWidget() = 0; + virtual void zoomAll() = 0; -private: +protected: + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; + + + ///////// Interface for the Window controller + friend class RimMdiWindowController; + + virtual caf::PdmField* getShowWindowField() = 0; + virtual QWidget* createViewWidget(QWidget* mainWindowParent) = 0; + virtual void updateViewWidgetAfterCreation() {}; + virtual void updateViewerWidgetWindowTitle(); // Has real default implementation + virtual void deleteViewWidget() = 0; + + + ////////// + + void setAsMDI(int mainWindowID); + + caf::PdmChildField m_windowController; + + // Obsoleted field + virtual void initAfterRead() override; caf::PdmField< std::vector > m_windowGeometry; + + }; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index 2b9476659f..eb50b6e6ea 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -86,52 +86,11 @@ RimWellLogPlot::RimWellLogPlot() //-------------------------------------------------------------------------------------------------- RimWellLogPlot::~RimWellLogPlot() { - if (RiaApplication::instance()->mainPlotWindow()) - { - RiaApplication::instance()->mainPlotWindow()->removeViewer(m_viewer); - } + removeWidgetFromMDI(); - detachAllCurves(); m_tracks.deleteAllChildObjects(); - delete m_viewer; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellLogPlot::updateViewerWidget() -{ - RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow(); - if (!mainPlotWindow) return; - - if (m_showWindow()) - { - if (!m_viewer) - { - m_viewer = new RiuWellLogPlot(this, mainPlotWindow); - - recreateTrackPlots(); - - mainPlotWindow->addViewer(m_viewer, this->mdiWindowGeometry()); - mainPlotWindow->setActiveViewer(m_viewer); - } - - updateViewerWidgetWindowTitle(); - } - else - { - if (m_viewer) - { - this->setMdiWindowGeometry(mainPlotWindow->windowGeometryForViewer(m_viewer)); - - mainPlotWindow->removeViewer(m_viewer); - detachAllCurves(); - - delete m_viewer; - m_viewer = NULL; - } - } + deleteViewWidget(); } //-------------------------------------------------------------------------------------------------- @@ -147,7 +106,7 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } else { - updateViewerWidget(); + updateViewerWidgetBasic(); } uiCapability()->updateUiIconFromToggleField(); @@ -391,21 +350,6 @@ void RimWellLogPlot::depthZoomMinMax(double* minimumDepth, double* maximumDepth) } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellLogPlot::setupBeforeSave() -{ - if (m_viewer) - { - if (RiaApplication::instance()->mainPlotWindow()) - { - this->setMdiWindowGeometry(RiaApplication::instance()->mainPlotWindow()->windowGeometryForViewer(m_viewer)); - } - } -} - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -427,7 +371,7 @@ void RimWellLogPlot::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& //-------------------------------------------------------------------------------------------------- void RimWellLogPlot::loadDataAndUpdate() { - updateViewerWidget(); + updateViewerWidgetBasic(); updateTracks(); } @@ -548,29 +492,27 @@ QString RimWellLogPlot::description() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellLogPlot::updateViewerWidgetWindowTitle() +QWidget* RimWellLogPlot::createViewWidget(QWidget* mainWindowParent) { - if (m_viewer) - { - m_viewer->setWindowTitle(m_userName); - } + m_viewer = new RiuWellLogPlot(this, mainWindowParent); + + recreateTrackPlots(); + + return m_viewer; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellLogPlot::handleViewerDeletion() +void RimWellLogPlot::deleteViewWidget() { - m_showWindow = false; + detachAllCurves(); - if (m_viewer) - { - detachAllCurves(); - m_viewer = NULL; - } - - uiCapability()->updateUiIconFromToggleField(); - updateConnectedEditors(); + if (m_viewer) + { + m_viewer->deleteLater(); + m_viewer = nullptr; + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h index 1db858f1ef..bd3ecd56c2 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h @@ -91,7 +91,6 @@ protected: // Overridden PDM methods virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); - virtual void setupBeforeSave(); virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering); virtual caf::PdmFieldHandle* objectToggleField(); virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } @@ -100,13 +99,16 @@ protected: private: - void updateViewerWidget(); - void updateViewerWidgetWindowTitle(); void applyZoomAllDepths(); void applyDepthZoomFromVisibleDepth(); void recreateTrackPlots(); void detachAllCurves(); - void handleViewerDeletion(); + + // RimViewWindow overrides + + virtual caf::PdmField* getShowWindowField() override { return &m_showWindow; } + virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; + virtual void deleteViewWidget() override; private: caf::PdmField m_showWindow; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp index 580e5314cb..486b8bc51f 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp @@ -72,7 +72,11 @@ RimWellLogTrack::~RimWellLogTrack() { curves.deleteAllChildObjects(); - delete m_wellLogTrackPlotWidget; + if (m_wellLogTrackPlotWidget) + { + m_wellLogTrackPlotWidget->deleteLater(); + m_wellLogTrackPlotWidget = nullptr; + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index 35fb3eab11..dc0aa393ba 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -85,6 +85,8 @@ RimSummaryPlot::RimSummaryPlot() CAF_PDM_InitField(&m_isAutoZoom, "AutoZoom", true, "Auto Zoom", "", "", ""); m_isAutoZoom.uiCapability()->setUiHidden(true); + + setAsPlotMDI(); } //-------------------------------------------------------------------------------------------------- @@ -92,29 +94,14 @@ RimSummaryPlot::RimSummaryPlot() //-------------------------------------------------------------------------------------------------- RimSummaryPlot::~RimSummaryPlot() { - if (RiaApplication::instance()->mainPlotWindow()) - { - RiaApplication::instance()->mainPlotWindow()->removeViewer(m_qwtPlot); - } + removeWidgetFromMDI(); - deletePlotWidget(); + deleteViewWidget(); m_curves.deleteAllChildObjects(); m_curveFilters.deleteAllChildObjects(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::deletePlotWidget() -{ - if (m_qwtPlot) - { - m_qwtPlot->deleteLater(); - m_qwtPlot = NULL; - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -367,22 +354,6 @@ void RimSummaryPlot::updateTimeAxis() } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::handleViewerDeletion() -{ - m_showWindow = false; - - if (m_qwtPlot) - { - detachAllCurves(); - } - - uiCapability()->updateUiIconFromToggleField(); - updateConnectedEditors(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -512,7 +483,7 @@ void RimSummaryPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } else { - updateViewerWidget(); + updateViewerWidgetBasic(); } uiCapability()->updateUiIconFromToggleField(); @@ -524,16 +495,6 @@ void RimSummaryPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::setupBeforeSave() -{ - if (m_qwtPlot && RiaApplication::instance()->mainPlotWindow()) - { - this->setMdiWindowGeometry(RiaApplication::instance()->mainPlotWindow()->windowGeometryForViewer(m_qwtPlot)); - } -} //-------------------------------------------------------------------------------------------------- /// @@ -578,7 +539,7 @@ void RimSummaryPlot::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering //-------------------------------------------------------------------------------------------------- void RimSummaryPlot::loadDataAndUpdate() { - updateViewerWidget(); + updateViewerWidgetBasic(); for (RimSummaryCurveFilter* curveFilter: m_curveFilters) { @@ -669,44 +630,37 @@ QString RimSummaryPlot::description() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::updateViewerWidget() +QWidget* RimSummaryPlot::createViewWidget(QWidget* mainWindowParent) { - RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow(); - if (!mainPlotWindow) return; - - if (m_showWindow()) + if (!m_qwtPlot) { - if (!m_qwtPlot) + m_qwtPlot = new RiuSummaryQwtPlot(this, mainWindowParent); + + for(RimSummaryCurveFilter* curveFilter: m_curveFilters) { - m_qwtPlot = new RiuSummaryQwtPlot(this, mainPlotWindow); - - for(RimSummaryCurveFilter* curveFilter: m_curveFilters) - { - curveFilter->setParentQwtPlot(m_qwtPlot); - } - - for(RimSummaryCurve* curve : m_curves) - { - curve->setParentQwtPlot(m_qwtPlot); - } - - mainPlotWindow->addViewer(m_qwtPlot, this->mdiWindowGeometry()); - mainPlotWindow->setActiveViewer(m_qwtPlot); + curveFilter->setParentQwtPlot(m_qwtPlot); } - updateViewerWidgetWindowTitle(); + for(RimSummaryCurve* curve : m_curves) + { + curve->setParentQwtPlot(m_qwtPlot); + } } - else + + return m_qwtPlot; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::deleteViewWidget() +{ + detachAllCurves(); + + if (m_qwtPlot) { - if (m_qwtPlot) - { - this->setMdiWindowGeometry(mainPlotWindow->windowGeometryForViewer(m_qwtPlot)); - - mainPlotWindow->removeViewer(m_qwtPlot); - detachAllCurves(); - - deletePlotWidget(); - } + m_qwtPlot->deleteLater(); + m_qwtPlot = nullptr; } } diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h index 113dbfbb8b..1b6181b6d8 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -64,7 +64,7 @@ public: void loadDataAndUpdate(); - void handleViewerDeletion(); + void detachAllCurves(); void updateCaseNameHasChanged(); void updateAxes(); @@ -91,16 +91,11 @@ protected: virtual caf::PdmFieldHandle* objectToggleField() { return &m_showWindow; } virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; - virtual void setupBeforeSave() override; virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override; virtual QImage snapshotWindowContent() override; private: - void updateViewerWidget(); - void updateViewerWidgetWindowTitle(); - void detachAllCurves(); - void deletePlotWidget(); void updateAxis(RimDefines::PlotAxis plotAxis); std::vector curvesForAxis(RimDefines::PlotAxis plotAxis) const; @@ -109,6 +104,12 @@ private: void updateTimeAxis(); void setZoomIntervalsInQwtPlot(); + // RimViewWindow overrides + + virtual caf::PdmField* getShowWindowField() override { return &m_showWindow; } + virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; + void updateViewerWidgetWindowTitle() override; + virtual void deleteViewWidget() override; private: caf::PdmField m_showWindow; diff --git a/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp b/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp index 2eed8b3ee1..6ceb6c0ee9 100644 --- a/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp @@ -766,6 +766,7 @@ RimMdiWindowGeometry RiuMainPlotWindow::windowGeometryForWidget(QWidget* widget) if (widget) { + geo.mainWindowID = 1; geo.x = widget->pos().x(); geo.y = widget->pos().y(); geo.width = widget->size().width(); diff --git a/ApplicationCode/UserInterface/RiuMainPlotWindow.h b/ApplicationCode/UserInterface/RiuMainPlotWindow.h index 77f3fd2a89..2b7bf10bc6 100644 --- a/ApplicationCode/UserInterface/RiuMainPlotWindow.h +++ b/ApplicationCode/UserInterface/RiuMainPlotWindow.h @@ -57,9 +57,9 @@ public: void initializeGuiNewProjectLoaded(); void cleanupGuiBeforeProjectClose(); - void removeViewer( QWidget* viewer ); - void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry); - void setActiveViewer(QWidget* subWindow); + void removeViewer( QWidget* viewer ) override; + void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry) override; + void setActiveViewer(QWidget* subWindow) override; caf::PdmUiTreeView* projectTreeView() { return m_projectTreeView;} @@ -71,7 +71,7 @@ public: void setExpanded(const caf::PdmUiItem* uiItem, bool expanded); - RimMdiWindowGeometry windowGeometryForViewer(QWidget* viewer); + RimMdiWindowGeometry windowGeometryForViewer(QWidget* viewer) override; RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget); void tileWindows(); diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index f06c12efd1..dc8b0cc2e3 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -1638,6 +1638,7 @@ RimMdiWindowGeometry RiuMainWindow::windowGeometryForWidget(QWidget* widget) if (widget) { + geo.mainWindowID = 0; geo.x = widget->pos().x(); geo.y = widget->pos().y(); geo.width = widget->size().width(); diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index b01e20cea2..6f1b4123cd 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -77,9 +77,9 @@ public: void cleanupGuiCaseClose(); void cleanupGuiBeforeProjectClose(); - void removeViewer( QWidget* viewer ); - void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry); - void setActiveViewer(QWidget* subWindow); + void removeViewer( QWidget* viewer ) override; + void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry) override; + void setActiveViewer(QWidget* subWindow) override; void setResultInfo(const QString& info) const; diff --git a/ApplicationCode/UserInterface/RiuMainWindowBase.h b/ApplicationCode/UserInterface/RiuMainWindowBase.h index 4352d66b3f..ce4cafc65c 100644 --- a/ApplicationCode/UserInterface/RiuMainWindowBase.h +++ b/ApplicationCode/UserInterface/RiuMainWindowBase.h @@ -19,6 +19,7 @@ #pragma once #include +struct RimMdiWindowGeometry; class RiuMainWindowBase : public QMainWindow { @@ -29,6 +30,12 @@ public: virtual QString mainWindowName() = 0; + virtual void removeViewer( QWidget* viewer ) = 0; + virtual void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry)= 0; + virtual void setActiveViewer(QWidget* subWindow) = 0; + + virtual RimMdiWindowGeometry windowGeometryForViewer(QWidget* viewer) = 0; + void loadWinGeoAndDockToolBarLayout(); void saveWinGeoAndDockToolBarLayout(); void showWindow(); diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp index ff057bd04a..8410c4988b 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -151,6 +151,7 @@ RiuSummaryQwtPlot::~RiuSummaryQwtPlot() if (m_plotDefinition) { + m_plotDefinition->detachAllCurves(); m_plotDefinition->handleViewerDeletion(); } diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 6ab27d888b..63724f7e2d 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -182,8 +182,7 @@ RiuViewer::~RiuViewer() { if (m_rimView) { - m_rimView->showWindow = false; - m_rimView->uiCapability()->updateUiIconFromToggleField(); + m_rimView->handleViewerDeletion(); m_rimView->cameraPosition = m_mainCamera->viewMatrix(); m_rimView->cameraPointOfInterest = pointOfInterest(); diff --git a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp index 7bb414d2e6..87ea13cc60 100644 --- a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp @@ -65,6 +65,7 @@ RiuWellLogPlot::~RiuWellLogPlot() { if (m_plotDefinition) { + m_plotDefinition->detachAllCurves(); m_plotDefinition->handleViewerDeletion(); } } diff --git a/ApplicationCode/UserInterface/RiuWellLogPlot.h b/ApplicationCode/UserInterface/RiuWellLogPlot.h index b88398c527..79c9e7a6ff 100644 --- a/ApplicationCode/UserInterface/RiuWellLogPlot.h +++ b/ApplicationCode/UserInterface/RiuWellLogPlot.h @@ -72,8 +72,8 @@ private slots: private: QHBoxLayout* m_layout; QScrollBar* m_scrollBar; - QList m_legends; - QList m_trackPlots; + QList > m_legends; + QList > m_trackPlots; caf::PdmPointer m_plotDefinition; QTimer* m_scheduleUpdateChildrenLayoutTimer; }; From 8004e766eac9f58437fff0f200534857e26fee0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Thu, 19 Jan 2017 17:32:50 +0100 Subject: [PATCH 02/27] AppFwk: Improved the message when forgetting to delete a child object --- Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl index c41098357b..502b857348 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl @@ -52,7 +52,8 @@ caf::PdmChildField::PdmChildField(const DataTypePtr& fieldValue) template caf::PdmChildField::~PdmChildField() { - assert(m_fieldValue.isNull()); + bool The_object_owned_by_the_child_field_is_deleted = m_fieldValue.isNull(); + assert(The_object_owned_by_the_child_field_is_deleted); // Did you forget ? if (!m_fieldValue.isNull()) m_fieldValue.rawPtr()->removeAsParentField(this); m_fieldValue.setRawPtr(NULL); From 6fad753c4d3467bb7db1e88c6923d0ebf2e52dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Thu, 19 Jan 2017 17:35:47 +0100 Subject: [PATCH 03/27] #1131 Added update of the plot treeview when changing preferences --- ApplicationCode/Application/RiaApplication.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index f3c0daf6b8..234f1b9b92 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -1935,6 +1935,7 @@ void RiaApplication::applyPreferences() if (RiuMainWindow::instance() && RiuMainWindow::instance()->projectTreeView()) { RiuMainWindow::instance()->projectTreeView()->enableAppendOfClassNameToUiItemText(m_preferences->appendClassNameToUiText()); + if (mainPlotWindow()) mainPlotWindow()->projectTreeView()->enableAppendOfClassNameToUiItemText(m_preferences->appendClassNameToUiText()); } caf::FixedAtlasFont::FontSize fontSizeType = caf::FixedAtlasFont::POINT_SIZE_16; From 6bd8a4d51aa2563717d4599904e4d2bdc93c5700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Thu, 19 Jan 2017 17:39:43 +0100 Subject: [PATCH 04/27] #1106, #1107, #1009, #1113 Started using WellLog plot for the Accumulated Well Flow plot --- .../Flow/RimWellAllocationPlot.cpp | 53 +++++++++++++++++-- .../Flow/RimWellAllocationPlot.h | 5 ++ .../ProjectDataModel/RimViewWindow.cpp | 2 +- .../ProjectDataModel/RimWellLogPlot.cpp | 19 +++++++ .../ProjectDataModel/RimWellLogPlot.h | 5 ++ .../UserInterface/RiuWellAllocationPlot.cpp | 12 ++++- .../UserInterface/RiuWellAllocationPlot.h | 2 +- 7 files changed, 91 insertions(+), 7 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 0fdc2c6e6a..6b892cb626 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -26,6 +26,9 @@ #include "RiuMainPlotWindow.h" #include "RiuWellAllocationPlot.h" +#include "RimWellLogPlot.h" +#include "RimWellLogTrack.h" +#include "RigSingleWellResultsData.h" CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot"); @@ -44,9 +47,12 @@ RimWellAllocationPlot::RimWellAllocationPlot() m_userName.uiCapability()->setUiReadOnly(true); CAF_PDM_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", ""); - CAF_PDM_InitFieldNoDefault(&m_simulationWell, "SimulationWell", "Simulation Well", "", "", ""); + CAF_PDM_InitFieldNoDefault(&m_accumulatedWellFlowPlot, "AccumulatedWellFlowPlot", "Accumulated Well Flow", "", "", ""); + m_accumulatedWellFlowPlot.uiCapability()->setUiHidden(true); + + m_accumulatedWellFlowPlot = new RimWellLogPlot; this->setAsPlotMDI(); } @@ -56,6 +62,8 @@ RimWellAllocationPlot::RimWellAllocationPlot() RimWellAllocationPlot::~RimWellAllocationPlot() { removeWidgetFromMDI(); + + delete m_accumulatedWellFlowPlot(); deleteViewWidget(); } @@ -88,14 +96,42 @@ void RimWellAllocationPlot::deleteViewWidget() void RimWellAllocationPlot::updateFromWell() { QString simName = "None"; + size_t branchCount = 0; + + const RigWellResultFrame* wellResultFrame = nullptr; - if (m_simulationWell) + if (m_simulationWell && m_simulationWell->wellResults() )// && Timestep Ok ) { simName = m_simulationWell->name(); + wellResultFrame = &(m_simulationWell->wellResults()->wellResultFrame(1)); + branchCount = wellResultFrame->m_wellResultBranches.size(); } - setDescription(simName); - updateViewerWidgetBasic(); + size_t existingTrackCount = accumulatedWellFlowPlot()->trackCount(); + accumulatedWellFlowPlot()->setDescription("Accumulated Well Flow (" + simName + ")"); + + int neededExtraTrackCount = branchCount - existingTrackCount; + for (int etc = 0; etc < neededExtraTrackCount; ++etc) + { + RimWellLogTrack* plotTrack = new RimWellLogTrack(); + accumulatedWellFlowPlot()->addTrack(plotTrack); + } + + for (int etc = branchCount; etc < existingTrackCount; ++etc) + { + accumulatedWellFlowPlot()->removeTrackByIndex(accumulatedWellFlowPlot()->trackCount()- 1); + } + + for (size_t brIdx = 0; brIdx < branchCount; ++brIdx) + { + RimWellLogTrack* plotTrack = accumulatedWellFlowPlot()->trackByIndex(brIdx); + + plotTrack->setDescription(QString("Branch %1").arg(wellResultFrame->m_wellResultBranches[brIdx].m_ertBranchId)); + + } + + setDescription("Well Allocation (" + simName + ")"); + accumulatedWellFlowPlot()->updateConnectedEditors(); } //-------------------------------------------------------------------------------------------------- @@ -113,6 +149,14 @@ void RimWellAllocationPlot::zoomAll() { } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellLogPlot* RimWellAllocationPlot::accumulatedWellFlowPlot() +{ + return m_accumulatedWellFlowPlot(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -188,6 +232,7 @@ QImage RimWellAllocationPlot::snapshotWindowContent() void RimWellAllocationPlot::setDescription(const QString& description) { m_userName = description; + this->updateViewerWidgetWindowTitle(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index 1b0a671450..7ec71c239b 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -29,6 +29,7 @@ class RiuWellAllocationPlot; class RimEclipseWell; +class RimWellLogPlot; namespace caf { class PdmOptionItemInfo; @@ -57,6 +58,7 @@ public: virtual QWidget* viewWidget() override; virtual void zoomAll() override; + RimWellLogPlot* accumulatedWellFlowPlot(); virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override; @@ -83,8 +85,11 @@ private: caf::PdmField m_showPlotTitle; caf::PdmField m_userName; + //caf::PdmField m_showAccWellFlowPlot; caf::PdmPtrField m_simulationWell; QPointer m_wellAllocationPlotWidget; + + caf::PdmChildField m_accumulatedWellFlowPlot; }; diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp index 5a07117493..72be2d72ff 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp @@ -30,7 +30,7 @@ RimViewWindow::RimViewWindow(void) { CAF_PDM_InitFieldNoDefault(&m_windowController, "WindowController", "", "", "", ""); m_windowController.uiCapability()->setUiHidden(true); - + m_windowController.uiCapability()->setUiTreeChildrenHidden(true); // Obsolete field CAF_PDM_InitFieldNoDefault(&m_windowGeometry, "WindowGeometry", "", "", "", ""); diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index eb50b6e6ea..a7d7fd5431 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -199,6 +199,17 @@ void RimWellLogPlot::removeTrack(RimWellLogTrack* track) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellLogPlot::removeTrackByIndex(size_t index) +{ + CVF_ASSERT(index < m_tracks.size()); + + RimWellLogTrack* track = m_tracks[index]; + this->removeTrack(track); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -228,6 +239,14 @@ void RimWellLogPlot::moveTracks(RimWellLogTrack* insertAfterTrack, const std::ve updateTrackNames(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellLogTrack* RimWellLogPlot::trackByIndex(size_t index) +{ + return m_tracks[index]; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h index bd3ecd56c2..07d4243f5c 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h @@ -66,10 +66,14 @@ public: void addTrack(RimWellLogTrack* track); void insertTrack(RimWellLogTrack* track, size_t index); size_t trackCount() { return m_tracks.size();} + void removeTrackByIndex(size_t index); + void removeTrack(RimWellLogTrack* track); size_t trackIndex(RimWellLogTrack* track); void moveTracks(RimWellLogTrack* insertAfterTrack, const std::vector& tracksToMove); + RimWellLogTrack* trackByIndex(size_t index); + void loadDataAndUpdate(); void updateTracks(); void updateTrackNames(); @@ -104,6 +108,7 @@ private: void recreateTrackPlots(); void detachAllCurves(); +public: // Needed by RiuWellAllocation Plot // RimViewWindow overrides virtual caf::PdmField* getShowWindowField() override { return &m_showWindow; } diff --git a/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp b/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp index d124d98a29..01b0ada004 100644 --- a/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp @@ -22,6 +22,9 @@ #include "RiaApplication.h" #include "RimWellAllocationPlot.h" +#include "RimWellLogPlot.h" +#include "RimWellLogTrack.h" +#include "QBoxLayout" @@ -30,10 +33,17 @@ /// //-------------------------------------------------------------------------------------------------- RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefinition, QWidget* parent) - : QwtPlot(parent) + : QFrame(parent) { Q_ASSERT(plotDefinition); + this->setLayout(new QVBoxLayout()); + this->layout()->setMargin(0); + m_plotDefinition = plotDefinition; + QWidget* wellFlowWidget = m_plotDefinition->accumulatedWellFlowPlot()->createViewWidget(this); + this->layout()->addWidget(wellFlowWidget); + + } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuWellAllocationPlot.h b/ApplicationCode/UserInterface/RiuWellAllocationPlot.h index 55857c301a..9c4dd2e7c2 100644 --- a/ApplicationCode/UserInterface/RiuWellAllocationPlot.h +++ b/ApplicationCode/UserInterface/RiuWellAllocationPlot.h @@ -32,7 +32,7 @@ class RimWellAllocationPlot; // // //================================================================================================== -class RiuWellAllocationPlot : public QwtPlot +class RiuWellAllocationPlot : public QFrame { Q_OBJECT; public: From d8f75a32c61ba7fbcc8bbcdebe61fc302261e1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Thu, 19 Jan 2017 18:04:36 +0100 Subject: [PATCH 05/27] Removed compiler warnings --- .../ProjectDataModel/Flow/RimWellAllocationPlot.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 6b892cb626..b1e86cdd9a 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -96,7 +96,7 @@ void RimWellAllocationPlot::deleteViewWidget() void RimWellAllocationPlot::updateFromWell() { QString simName = "None"; - size_t branchCount = 0; + int branchCount = 0; const RigWellResultFrame* wellResultFrame = nullptr; @@ -104,10 +104,10 @@ void RimWellAllocationPlot::updateFromWell() { simName = m_simulationWell->name(); wellResultFrame = &(m_simulationWell->wellResults()->wellResultFrame(1)); - branchCount = wellResultFrame->m_wellResultBranches.size(); + branchCount = static_cast( wellResultFrame->m_wellResultBranches.size()); } - size_t existingTrackCount = accumulatedWellFlowPlot()->trackCount(); + int existingTrackCount = static_cast(accumulatedWellFlowPlot()->trackCount()); accumulatedWellFlowPlot()->setDescription("Accumulated Well Flow (" + simName + ")"); int neededExtraTrackCount = branchCount - existingTrackCount; From cd6ebc965aff6cfc39a38410d2a8178f697d3085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 09:44:12 +0100 Subject: [PATCH 06/27] #1106 Update data on loadDataAndUpdate --- ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index b1e86cdd9a..94f689e567 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -249,6 +249,7 @@ QString RimWellAllocationPlot::description() const void RimWellAllocationPlot::loadDataAndUpdate() { updateViewerWidgetBasic(); + updateFromWell(); } //-------------------------------------------------------------------------------------------------- From a1aec0b5e03655424fc6bfb97ee354441104e082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 10:32:01 +0100 Subject: [PATCH 07/27] Fixed compile error not catched by cotire compilation --- ApplicationCode/UserInterface/RiuWellLogPlot.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuWellLogPlot.h b/ApplicationCode/UserInterface/RiuWellLogPlot.h index 79c9e7a6ff..78aa2f87bf 100644 --- a/ApplicationCode/UserInterface/RiuWellLogPlot.h +++ b/ApplicationCode/UserInterface/RiuWellLogPlot.h @@ -19,10 +19,12 @@ #pragma once -#include -#include #include "cafPdmPointer.h" +#include +#include +#include + class RimWellLogPlot; class RiuWellLogTrack; From c025c2a3d744216e20def37341d5c1aedc58b598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 11:38:18 +0100 Subject: [PATCH 08/27] Renaming in the aftermath of the MDI window control refactorization. Aligned fieldChangedByUi in that respact as well. --- .../RicNewWellLogPlotFeatureImpl.cpp | 2 +- .../Flow/RimWellAllocationPlot.cpp | 19 ++++--- .../ProjectDataModel/RimEclipseView.cpp | 21 ++------ .../ProjectDataModel/RimGeoMechView.cpp | 19 ++----- .../RimMdiWindowController.cpp | 2 +- ApplicationCode/ProjectDataModel/RimView.cpp | 8 +-- ApplicationCode/ProjectDataModel/RimView.h | 2 +- .../ProjectDataModel/RimViewWindow.cpp | 30 +++++------ .../ProjectDataModel/RimViewWindow.h | 50 +++++++++---------- .../ProjectDataModel/RimWellLogPlot.cpp | 8 +-- .../Summary/RimSummaryPlot.cpp | 12 ++--- .../ProjectDataModel/Summary/RimSummaryPlot.h | 2 +- .../UserInterface/RiuSummaryQwtPlot.cpp | 2 +- ApplicationCode/UserInterface/RiuViewer.cpp | 2 +- .../UserInterface/RiuWellAllocationPlot.cpp | 2 +- .../UserInterface/RiuWellLogPlot.cpp | 2 +- 16 files changed, 82 insertions(+), 101 deletions(-) diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeatureImpl.cpp b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeatureImpl.cpp index fa821a4f0d..0f637f867d 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeatureImpl.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeatureImpl.cpp @@ -39,7 +39,7 @@ RimWellLogPlot* RicNewWellLogPlotFeatureImpl::createWellLogPlot() CVF_ASSERT(wellLogPlotColl); RimWellLogPlot* plot = new RimWellLogPlot(); - plot->setAsPlotMDI(); + plot->setAsPlotMdiWindow(); wellLogPlotColl->wellLogPlots().push_back(plot); // Make sure the summary plot window is created and visible diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 94f689e567..691056889c 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -53,7 +53,7 @@ RimWellAllocationPlot::RimWellAllocationPlot() m_accumulatedWellFlowPlot.uiCapability()->setUiHidden(true); m_accumulatedWellFlowPlot = new RimWellLogPlot; - this->setAsPlotMDI(); + this->setAsPlotMdiWindow(); } //-------------------------------------------------------------------------------------------------- @@ -61,7 +61,7 @@ RimWellAllocationPlot::RimWellAllocationPlot() //-------------------------------------------------------------------------------------------------- RimWellAllocationPlot::~RimWellAllocationPlot() { - removeWidgetFromMDI(); + removeMdiWindowFromMdiArea(); delete m_accumulatedWellFlowPlot(); @@ -198,14 +198,21 @@ void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedF { if (changedField == &m_showWindow) { - updateViewerWidgetBasic(); + if (m_showWindow) + { + loadDataAndUpdate(); + } + else + { + updateMdiWindowVisibility(); + } uiCapability()->updateUiIconFromToggleField(); } else if (changedField == &m_userName || changedField == &m_showPlotTitle) { - updateViewerWidgetWindowTitle(); + updateMdiWindowTitle(); } else if (changedField == &m_simulationWell) { @@ -232,7 +239,7 @@ QImage RimWellAllocationPlot::snapshotWindowContent() void RimWellAllocationPlot::setDescription(const QString& description) { m_userName = description; - this->updateViewerWidgetWindowTitle(); + this->updateMdiWindowTitle(); } //-------------------------------------------------------------------------------------------------- @@ -248,7 +255,7 @@ QString RimWellAllocationPlot::description() const //-------------------------------------------------------------------------------------------------- void RimWellAllocationPlot::loadDataAndUpdate() { - updateViewerWidgetBasic(); + updateMdiWindowVisibility(); updateFromWell(); } diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index a75bc380c1..e2d6e9cb5c 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -187,24 +187,11 @@ void RimEclipseView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c { if (showWindow) { - bool generateDisplayModel = (viewer() == NULL); - updateViewerWidgetBasic(); - - if (generateDisplayModel) - { - updateDisplayModelForWellResults(); - } + loadDataAndUpdate(); } else { - if (m_viewer) - { - this->setMdiWindowGeometry( RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget())); - - RiuMainWindow::instance()->removeViewer(m_viewer->layoutWidget()); - delete m_viewer; - m_viewer = NULL; - } + updateMdiWindowVisibility(); } this->updateUiIconFromToggleField(); @@ -689,7 +676,7 @@ void RimEclipseView::loadDataAndUpdate() this->faultResultSettings()->customFaultResult()->loadResult(); - updateViewerWidgetBasic(); + updateMdiWindowVisibility(); this->m_propertyFilterCollection()->loadAndInitializePropertyFilters(); @@ -697,6 +684,8 @@ void RimEclipseView::loadDataAndUpdate() this->faultCollection()->syncronizeFaults(); m_reservoirGridPartManager->clearGeometryCache(); + m_pipesPartManager->clearGeometryCache(); + m_wellSpheresPartManager->clearGeometryCache(); syncronizeWellsWithResults(); diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp index e5bd609b4b..bd6318fb81 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp @@ -134,7 +134,7 @@ void RimGeoMechView::loadDataAndUpdate() progress.incrementProgress(); progress.setProgressDescription("Create Display model"); - updateViewerWidgetBasic(); + updateMdiWindowVisibility(); this->geoMechPropertyFilterCollection()->loadAndInitializePropertyFilters(); @@ -481,24 +481,11 @@ void RimGeoMechView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c { if (showWindow) { - bool generateDisplayModel = (viewer() == NULL); - updateViewerWidgetBasic(); - - if (generateDisplayModel) - { - scheduleCreateDisplayModelAndRedraw(); - } + loadDataAndUpdate(); } else { - if (m_viewer) - { - this->setMdiWindowGeometry( RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget())); - - RiuMainWindow::instance()->removeViewer(m_viewer->layoutWidget()); - delete m_viewer; - m_viewer = NULL; - } + updateMdiWindowVisibility(); } this->updateUiIconFromToggleField(); diff --git a/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp b/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp index 88ba9f9ceb..11b87d2b91 100644 --- a/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp +++ b/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp @@ -174,7 +174,7 @@ void RimMdiWindowController::updateViewerWidget() mainWindow->setActiveViewer(viewWidget()); } - viewPdmObject()->updateViewerWidgetWindowTitle(); + viewPdmObject()->updateMdiWindowTitle(); } else { diff --git a/ApplicationCode/ProjectDataModel/RimView.cpp b/ApplicationCode/ProjectDataModel/RimView.cpp index f7b73c7f37..cbd0ddc97b 100644 --- a/ApplicationCode/ProjectDataModel/RimView.cpp +++ b/ApplicationCode/ProjectDataModel/RimView.cpp @@ -141,7 +141,7 @@ RimView::RimView(void) m_wellPathPipeVizModel = new cvf::ModelBasicList; m_wellPathPipeVizModel->setName("WellPathPipeModel"); - this->setAs3DMDI(); + this->setAs3DViewMdiWindow(); } //-------------------------------------------------------------------------------------------------- @@ -171,7 +171,7 @@ RimView::~RimView(void) delete this->m_overlayInfoConfig(); - removeWidgetFromMDI(); + removeMdiWindowFromMdiArea(); deleteViewWidget(); @@ -231,7 +231,7 @@ void RimView::updateViewWidgetAfterCreation() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimView::updateViewerWidgetWindowTitle() +void RimView::updateMdiWindowTitle() { if (m_viewer) { @@ -595,7 +595,7 @@ void RimView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QV } else if (changedField == &name) { - updateViewerWidgetWindowTitle(); + updateMdiWindowTitle(); if (viewController()) { diff --git a/ApplicationCode/ProjectDataModel/RimView.h b/ApplicationCode/ProjectDataModel/RimView.h index 30ca0e0a14..8df8a0d6f2 100644 --- a/ApplicationCode/ProjectDataModel/RimView.h +++ b/ApplicationCode/ProjectDataModel/RimView.h @@ -220,7 +220,7 @@ protected: virtual caf::PdmField* getShowWindowField() override { return &showWindow; } virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; virtual void updateViewWidgetAfterCreation() override; - virtual void updateViewerWidgetWindowTitle() override; + virtual void updateMdiWindowTitle() override; virtual void deleteViewWidget() override; cvf::ref m_currentReservoirCellVisibility; diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp index 72be2d72ff..99956e8d21 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp @@ -33,9 +33,9 @@ RimViewWindow::RimViewWindow(void) m_windowController.uiCapability()->setUiTreeChildrenHidden(true); // Obsolete field - CAF_PDM_InitFieldNoDefault(&m_windowGeometry, "WindowGeometry", "", "", "", ""); - m_windowGeometry.uiCapability()->setUiHidden(true); - m_windowGeometry.xmlCapability()->setIOWritable(false); + CAF_PDM_InitFieldNoDefault(&obsoleteField_windowGeometry, "WindowGeometry", "", "", "", ""); + obsoleteField_windowGeometry.uiCapability()->setUiHidden(true); + obsoleteField_windowGeometry.xmlCapability()->setIOWritable(false); } //-------------------------------------------------------------------------------------------------- @@ -49,7 +49,7 @@ RimViewWindow::~RimViewWindow(void) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimViewWindow::removeWidgetFromMDI() +void RimViewWindow::removeMdiWindowFromMdiArea() { if ( m_windowController() ) m_windowController->removeWindowFromMDI(); } @@ -57,7 +57,7 @@ void RimViewWindow::removeWidgetFromMDI() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimViewWindow::handleViewerDeletion() +void RimViewWindow::handleMdiWindowClosed() { if ( m_windowController() ) m_windowController->handleViewerDeletion(); } @@ -65,7 +65,7 @@ void RimViewWindow::handleViewerDeletion() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimViewWindow::updateViewerWidgetBasic() +void RimViewWindow::updateMdiWindowVisibility() { if ( m_windowController() ) m_windowController->updateViewerWidget(); } @@ -110,7 +110,7 @@ void RimViewWindow::fieldChangedByUi(const caf::PdmFieldHandle* changedField, co //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimViewWindow::updateViewerWidgetWindowTitle() +void RimViewWindow::updateMdiWindowTitle() { if ( viewWidget() ) { @@ -126,7 +126,7 @@ void RimViewWindow::updateViewerWidgetWindowTitle() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimViewWindow::setAsMDI(int mainWindowID) +void RimViewWindow::setAsMdiWindow(int mainWindowID) { if ( !m_windowController() ) { @@ -145,7 +145,7 @@ void RimViewWindow::setAsMDI(int mainWindowID) void RimViewWindow::initAfterRead() { - if (m_windowGeometry.value().size() == 5) + if (obsoleteField_windowGeometry.value().size() == 5) { RimMdiWindowGeometry wg; int mainWindowID = -1; @@ -156,13 +156,13 @@ void RimViewWindow::initAfterRead() mainWindowID = 1; wg.mainWindowID = mainWindowID; - wg.x = m_windowGeometry.value()[0]; - wg.y = m_windowGeometry.value()[1]; - wg.width = m_windowGeometry.value()[2]; - wg.height = m_windowGeometry.value()[3]; - wg.isMaximized = m_windowGeometry.value()[4]; + wg.x = obsoleteField_windowGeometry.value()[0]; + wg.y = obsoleteField_windowGeometry.value()[1]; + wg.width = obsoleteField_windowGeometry.value()[2]; + wg.height = obsoleteField_windowGeometry.value()[3]; + wg.isMaximized = obsoleteField_windowGeometry.value()[4]; - setAsMDI(mainWindowID); + setAsMdiWindow(mainWindowID); setMdiWindowGeometry(wg); } } diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.h b/ApplicationCode/ProjectDataModel/RimViewWindow.h index bc8111b337..e398bc802f 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.h @@ -47,24 +47,23 @@ public: RimViewWindow(void); virtual ~RimViewWindow(void); - void removeWidgetFromMDI(); - void handleViewerDeletion(); - void updateViewerWidgetBasic(); - - void setAs3DMDI() { setAsMDI(0); } - void setAsPlotMDI() { setAsMDI(1); } - - void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry); - RimMdiWindowGeometry mdiWindowGeometry(); - - virtual QImage snapshotWindowContent() = 0; - virtual QWidget* viewWidget() = 0; - - virtual void zoomAll() = 0; - -protected: - virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; - + void handleMdiWindowClosed(); + + void setAs3DViewMdiWindow() { setAsMdiWindow(0); } + void setAsPlotMdiWindow() { setAsMdiWindow(1); } + + void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry); + RimMdiWindowGeometry mdiWindowGeometry(); + + virtual QWidget* viewWidget() = 0; + + virtual QImage snapshotWindowContent() = 0; + virtual void zoomAll() = 0; + +protected: + + void removeMdiWindowFromMdiArea(); + void updateMdiWindowVisibility(); ///////// Interface for the Window controller friend class RimMdiWindowController; @@ -72,20 +71,19 @@ protected: virtual caf::PdmField* getShowWindowField() = 0; virtual QWidget* createViewWidget(QWidget* mainWindowParent) = 0; virtual void updateViewWidgetAfterCreation() {}; - virtual void updateViewerWidgetWindowTitle(); // Has real default implementation + virtual void updateMdiWindowTitle(); // Has real default implementation virtual void deleteViewWidget() = 0; - - ////////// - void setAsMDI(int mainWindowID); + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; + virtual void initAfterRead() override; + +private: + void setAsMdiWindow(int mainWindowID); caf::PdmChildField m_windowController; // Obsoleted field - virtual void initAfterRead() override; - caf::PdmField< std::vector > m_windowGeometry; - - + caf::PdmField< std::vector > obsoleteField_windowGeometry; }; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index a7d7fd5431..57fc6084c8 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -86,7 +86,7 @@ RimWellLogPlot::RimWellLogPlot() //-------------------------------------------------------------------------------------------------- RimWellLogPlot::~RimWellLogPlot() { - removeWidgetFromMDI(); + removeMdiWindowFromMdiArea(); m_tracks.deleteAllChildObjects(); @@ -106,7 +106,7 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } else { - updateViewerWidgetBasic(); + updateMdiWindowVisibility(); } uiCapability()->updateUiIconFromToggleField(); @@ -123,7 +123,7 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } else if (changedField == &m_userName) { - updateViewerWidgetWindowTitle(); + updateMdiWindowTitle(); } if (changedField == &m_depthType || changedField == &m_depthUnit) @@ -390,7 +390,7 @@ void RimWellLogPlot::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& //-------------------------------------------------------------------------------------------------- void RimWellLogPlot::loadDataAndUpdate() { - updateViewerWidgetBasic(); + updateMdiWindowVisibility(); updateTracks(); } diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index dc0aa393ba..5dfad70205 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -86,7 +86,7 @@ RimSummaryPlot::RimSummaryPlot() CAF_PDM_InitField(&m_isAutoZoom, "AutoZoom", true, "Auto Zoom", "", "", ""); m_isAutoZoom.uiCapability()->setUiHidden(true); - setAsPlotMDI(); + setAsPlotMdiWindow(); } //-------------------------------------------------------------------------------------------------- @@ -94,7 +94,7 @@ RimSummaryPlot::RimSummaryPlot() //-------------------------------------------------------------------------------------------------- RimSummaryPlot::~RimSummaryPlot() { - removeWidgetFromMDI(); + removeMdiWindowFromMdiArea(); deleteViewWidget(); @@ -483,7 +483,7 @@ void RimSummaryPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } else { - updateViewerWidgetBasic(); + updateMdiWindowVisibility(); } uiCapability()->updateUiIconFromToggleField(); @@ -491,7 +491,7 @@ void RimSummaryPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c else if (changedField == &m_userName || changedField == &m_showPlotTitle) { - updateViewerWidgetWindowTitle(); + updateMdiWindowTitle(); } } @@ -539,7 +539,7 @@ void RimSummaryPlot::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering //-------------------------------------------------------------------------------------------------- void RimSummaryPlot::loadDataAndUpdate() { - updateViewerWidgetBasic(); + updateMdiWindowVisibility(); for (RimSummaryCurveFilter* curveFilter: m_curveFilters) { @@ -667,7 +667,7 @@ void RimSummaryPlot::deleteViewWidget() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::updateViewerWidgetWindowTitle() +void RimSummaryPlot::updateMdiWindowTitle() { if (m_qwtPlot) { diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h index 1b6181b6d8..398d59ec7c 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -108,7 +108,7 @@ private: virtual caf::PdmField* getShowWindowField() override { return &m_showWindow; } virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; - void updateViewerWidgetWindowTitle() override; + void updateMdiWindowTitle() override; virtual void deleteViewWidget() override; private: diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp index 8410c4988b..c5a9918c39 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -152,7 +152,7 @@ RiuSummaryQwtPlot::~RiuSummaryQwtPlot() if (m_plotDefinition) { m_plotDefinition->detachAllCurves(); - m_plotDefinition->handleViewerDeletion(); + m_plotDefinition->handleMdiWindowClosed(); } m_plotMarker->detach(); diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 63724f7e2d..cfeae08d98 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -182,7 +182,7 @@ RiuViewer::~RiuViewer() { if (m_rimView) { - m_rimView->handleViewerDeletion(); + m_rimView->handleMdiWindowClosed(); m_rimView->cameraPosition = m_mainCamera->viewMatrix(); m_rimView->cameraPointOfInterest = pointOfInterest(); diff --git a/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp b/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp index 01b0ada004..4522082c08 100644 --- a/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp @@ -53,7 +53,7 @@ RiuWellAllocationPlot::~RiuWellAllocationPlot() { if (m_plotDefinition) { - m_plotDefinition->handleViewerDeletion(); + m_plotDefinition->handleMdiWindowClosed(); } } diff --git a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp index 87ea13cc60..478af15439 100644 --- a/ApplicationCode/UserInterface/RiuWellLogPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellLogPlot.cpp @@ -66,7 +66,7 @@ RiuWellLogPlot::~RiuWellLogPlot() if (m_plotDefinition) { m_plotDefinition->detachAllCurves(); - m_plotDefinition->handleViewerDeletion(); + m_plotDefinition->handleMdiWindowClosed(); } } From 51d6d21d77787f2d0b8bce88e47d4c01ed10667b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 14:56:08 +0100 Subject: [PATCH 09/27] Constified wellresultcell to cell --- ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp | 4 ++-- ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp index 5d56bd8881..9c933c0472 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp @@ -288,14 +288,14 @@ const cvf::UIntArray* RigEclipseCaseData::gridCellToResultWellIndex(size_t gridI //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigCell& RigEclipseCaseData::cellFromWellResultCell(const RigWellResultPoint& wellResultCell) +const RigCell& RigEclipseCaseData::cellFromWellResultCell(const RigWellResultPoint& wellResultCell) const { CVF_ASSERT(wellResultCell.isCell()); size_t gridIndex = wellResultCell.m_gridIndex; size_t gridCellIndex = wellResultCell.m_gridCellIndex; - std::vector grids; + std::vector grids; allGrids(&grids); return grids[gridIndex]->cell(gridCellIndex); diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h index d900e2d73a..668e5c54bf 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h @@ -86,7 +86,7 @@ public: const cvf::UByteArray* wellCellsInGrid(size_t gridIndex); const cvf::UIntArray* gridCellToResultWellIndex(size_t gridIndex); - RigCell& cellFromWellResultCell(const RigWellResultPoint& wellResultCell); + const RigCell& cellFromWellResultCell(const RigWellResultPoint& wellResultCell) const; bool findSharedSourceFace(cvf::StructGridInterface::FaceType& sharedSourceFace, const RigWellResultPoint& sourceWellCellResult, const RigWellResultPoint& otherWellCellResult) const; void computeActiveCellBoundingBoxes(); From d7782c6ddf285a1ca226ae16091ac2dd5f8bbeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 15:00:19 +0100 Subject: [PATCH 10/27] #1112 Refactored well centerline calculation a bit --- .../RigSimulationWellCenterLineCalculator.cpp | 521 ++++++++++-------- .../RigSimulationWellCenterLineCalculator.h | 12 + 2 files changed, 293 insertions(+), 240 deletions(-) diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp index 96e66e6629..602140d1cc 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp @@ -60,306 +60,307 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(RimEclip } const RigWellResultFrame& staticWellFrame = wellResults->m_staticWellCells; - if (staticWellFrame.m_wellResultBranches.size() == 0) return; - + bool isMultiSegmentWell = wellResults->isMultiSegmentWell(); + + calculateWellPipeCenterlineFromWellFrame(staticWellFrame, + eclipseCaseData, + isMultiSegmentWell, + isAutoDetectBranches, + pipeBranchesCLCoords, + pipeBranchesCellIds); + return; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(const RigWellResultFrame &wellFrame, + const RigEclipseCaseData* eclipseCaseData, + bool isMultiSegmentWell, + bool isAutoDetectBranches, + std::vector> &pipeBranchesCLCoords, + std::vector> &pipeBranchesCellIds) +{ // Initialize the return arrays pipeBranchesCLCoords.clear(); pipeBranchesCellIds.clear(); + if ( wellFrame.m_wellResultBranches.size() == 0 ) return; + // Well head // Match this position with well head position in RivWellHeadPartMgr::buildWellHeadParts() - const RigCell& whCell = eclipseCaseData->cellFromWellResultCell(staticWellFrame.m_wellHead); + + const RigCell& whCell = eclipseCaseData->cellFromWellResultCell(wellFrame.m_wellHead); cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K); - const RigWellResultPoint* whResCell = &(staticWellFrame.m_wellHead); + const RigWellResultPoint* whResCell = &(wellFrame.m_wellHead); - // Loop over all the well branches - const std::vector& resBranches = staticWellFrame.m_wellResultBranches; - bool hasResultCells = false; - if (resBranches.size()) + + const std::vector& resBranches = wellFrame.m_wellResultBranches; + + if ( ! hasAnyResultCells(resBranches) ) return; + + // Add extra coordinate between cell face and cell center + // to make sure the well pipe terminated in a segment parallel to z-axis + + cvf::Vec3d whIntermediate = whStartPos; + whIntermediate.z() = (whStartPos.z() + whCell.center().z()) / 2.0; + + const RigWellResultPoint* prevWellResPoint = NULL; + + CVF_ASSERT(isMultiSegmentWell || resBranches.size() <= 1); + + // The centerline is calculated by adding a point when the pipe enters a cell, + // and one when the line leaves the cell. + // For the sake of the loop: + // The currentResultPoint (Cell) and the one we index by the loop variable is the one we calculate the entry point to. + // The previous cell is the one we leave, and calculate the "out-point" from + + + for (size_t brIdx = 0; brIdx < resBranches.size(); brIdx++) { - for (size_t i = 0 ; i < resBranches.size(); ++i) + + // Skip empty branches. Do not know why they exist, but they make problems. + + const RigWellResultBranch& branch = resBranches[brIdx]; + if ( !hasAnyValidDataCells(branch) ) continue; + + prevWellResPoint = NULL; + + // Find the start the MSW well-branch centerline. Normal wells are started "once" at wellhead in the code above + + pipeBranchesCLCoords.push_back(std::vector()); + pipeBranchesCellIds.push_back(std::vector ()); + + if (brIdx == 0) { - if (resBranches[i].m_branchResultPoints.size() != 0) - { - hasResultCells = true; - break; - } + // The first branch contains segment number 1, and this is the only segment connected to well head + // See Eclipse documentation for the keyword WELSEGS + prevWellResPoint = whResCell; + + pipeBranchesCLCoords.back().push_back(whStartPos); + pipeBranchesCellIds.back().push_back(*prevWellResPoint); + + pipeBranchesCLCoords.back().push_back(whIntermediate); + pipeBranchesCellIds.back().push_back(*prevWellResPoint); } - } - if (hasResultCells) - { + // Loop over all the resultPoints in the branch - // Add extra coordinate between cell face and cell center - // to make sure the well pipe terminated in a segment parallel to z-axis - cvf::Vec3d whIntermediate = whStartPos; - whIntermediate.z() = (whStartPos.z() + whCell.center().z()) / 2.0; + const std::vector& resBranchCells = resBranches[brIdx].m_branchResultPoints; - const RigWellResultPoint* prevWellResPoint = NULL; - - CVF_ASSERT(wellResults->isMultiSegmentWell() || resBranches.size() <= 1); - - // The centerline is calculated by adding a point when the pipe enters a cell, - // and one when the line leaves the cell. - // For the sake of the loop: - // The currentResultPoint (Cell) and the one we index by the loop variable is the one we calculate the entry point to. - // The previous cell is the one we leave, and calculate the "out-point" from - - - for (size_t brIdx = 0; brIdx < resBranches.size(); brIdx++) + for (int cIdx = 0; cIdx < static_cast(resBranchCells.size()); cIdx++) // Need int because cIdx can temporarily end on -1 { + std::vector& branchCLCoords = pipeBranchesCLCoords.back(); + std::vector& branchCellIds = pipeBranchesCellIds.back(); - // Skip empty branches. Do not know why they exist, but they make problems. + const RigWellResultPoint& currentWellResPoint = resBranchCells[cIdx]; - bool hasValidData = false; - for (size_t cIdx = 0; cIdx < resBranches[brIdx].m_branchResultPoints.size(); ++cIdx) + // Ignore invalid cells + + if (!currentWellResPoint.isValid()) { - if (resBranches[brIdx].m_branchResultPoints[cIdx].isValid()) - { - hasValidData = true; - break; - } - } - if (!hasValidData) continue; - - - prevWellResPoint = NULL; - - // Find the start the MSW well-branch centerline. Normal wells are started "once" at wellhead in the code above - - pipeBranchesCLCoords.push_back(std::vector()); - pipeBranchesCellIds.push_back(std::vector ()); - - if (brIdx == 0) - { - // The first branch contains segment number 1, and this is the only segment connected to well head - // See Eclipse documentation for the keyword WELSEGS - prevWellResPoint = whResCell; - - pipeBranchesCLCoords.back().push_back(whStartPos); - pipeBranchesCellIds.back().push_back(*prevWellResPoint); - - pipeBranchesCLCoords.back().push_back(whIntermediate); - pipeBranchesCellIds.back().push_back(*prevWellResPoint); + //CVF_ASSERT(false); // Some segments does not get anything yet. + continue; } - // Loop over all the resultPoints in the branch + // Add cl contribution for a geometrical resultPoint by adding exit point from previous cell, + // and then the result point position - const std::vector& resBranchCells = resBranches[brIdx].m_branchResultPoints; - - for (int cIdx = 0; cIdx < static_cast(resBranchCells.size()); cIdx++) // Need int because cIdx can temporarily end on -1 + if (!currentWellResPoint.isCell()) { - std::vector& branchCLCoords = pipeBranchesCLCoords.back(); - std::vector& branchCellIds = pipeBranchesCellIds.back(); + // Use the interpolated value of branch head + CVF_ASSERT(currentWellResPoint.isPointValid()); - const RigWellResultPoint& currentWellResPoint = resBranchCells[cIdx]; + cvf::Vec3d currentPoint = currentWellResPoint.m_bottomPosition; - // Ignore invalid cells + // If we have a real previous cell, we need to go out of it, before adding the current point + // That is: add a CL-point describing where it leaves the previous cell. - if (!currentWellResPoint.isValid()) + if (prevWellResPoint && prevWellResPoint->isCell()) { - //CVF_ASSERT(false); // Some segments does not get anything yet. - continue; - } + // Create ray between the previous and this position - // Add cl contribution for a geometrical resultPoint by adding exit point from previous cell, - // and then the result point position + const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint); + cvf::Vec3d centerPreviousCell = prevCell.center(); - if (!currentWellResPoint.isCell()) - { - // Use the interpolated value of branch head - CVF_ASSERT(currentWellResPoint.isPointValid()); + cvf::Ray rayToThisCell; + rayToThisCell.setOrigin(centerPreviousCell); + rayToThisCell.setDirection((currentPoint - centerPreviousCell).getNormalized()); - cvf::Vec3d currentPoint = currentWellResPoint.m_bottomPosition; + cvf::Vec3d outOfPrevCell(centerPreviousCell); - // If we have a real previous cell, we need to go out of it, before adding the current point - // That is: add a CL-point describing where it leaves the previous cell. - - if (prevWellResPoint && prevWellResPoint->isCell()) + int intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); + //CVF_ASSERT(intersectionOk); + //CVF_ASSERT(intersectionOk); + if ((currentPoint - outOfPrevCell).lengthSquared() > 1e-3) { - // Create ray between the previous and this position + branchCLCoords.push_back(outOfPrevCell); + branchCellIds.push_back(RigWellResultPoint()); + } + } + + branchCLCoords.push_back(currentPoint); + branchCellIds.push_back(currentWellResPoint); + + prevWellResPoint = ¤tWellResPoint; + + continue; + } + + // + // Handle currentWellResPoint as a real cell result points. + // + + const RigCell& cell = eclipseCaseData->cellFromWellResultCell(currentWellResPoint); + + // Check if this and the previous cells has shared faces + + cvf::StructGridInterface::FaceType sharedFace; + if (prevWellResPoint && prevWellResPoint->isCell() && eclipseCaseData->findSharedSourceFace(sharedFace, currentWellResPoint, *prevWellResPoint)) + { + // If they share faces, the shared face center is used as point + // describing the entry of this cell. (And exit of the previous cell) + + branchCLCoords.push_back(cell.faceCenter(sharedFace)); + branchCellIds.push_back(currentWellResPoint); + } + else + { + // This and the previous cell does not share a face. + // Then we need to calculate the exit of the previous cell, and the entry point into this cell + + cvf::Vec3d centerPreviousCell(cvf::Vec3d::ZERO); + cvf::Vec3d centerThisCell = cell.center(); + bool distanceToWellHeadIsLonger = true; + + // If we have a previous well result point, use its center as measure point and ray intersection start + // when considering things. + + if (prevWellResPoint && prevWellResPoint->isValid()) + { + if (prevWellResPoint->isCell()) + { const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint); - cvf::Vec3d centerPreviousCell = prevCell.center(); + centerPreviousCell = prevCell.center(); + } + else + { + centerPreviousCell = prevWellResPoint->m_bottomPosition; + } + + distanceToWellHeadIsLonger = (centerThisCell - centerPreviousCell).lengthSquared() <= (centerThisCell - whStartPos).lengthSquared(); + } + + + // First make sure this cell is not starting a new "display" branch for none MSW's + + if ( isMultiSegmentWell + || !isAutoDetectBranches + || (prevWellResPoint == whResCell) + || distanceToWellHeadIsLonger) + { + // Not starting a "display" branch for normal wells + // Calculate the exit of the previous cell, and the entry point into this cell + + cvf::Vec3d intoThisCell(centerThisCell); // Use cell center as default for "into" point. + + if (prevWellResPoint && prevWellResPoint->isValid()) + { + // We have a defined previous point + // Create ray between the previous and this cell cvf::Ray rayToThisCell; rayToThisCell.setOrigin(centerPreviousCell); - rayToThisCell.setDirection((currentPoint - centerPreviousCell).getNormalized()); + rayToThisCell.setDirection((centerThisCell - centerPreviousCell).getNormalized()); - cvf::Vec3d outOfPrevCell(centerPreviousCell); + // Intersect with the current cell to find a better entry point than the cell center - int intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); - //CVF_ASSERT(intersectionOk); - //CVF_ASSERT(intersectionOk); - if ((currentPoint - outOfPrevCell).lengthSquared() > 1e-3) + int intersectionCount = cell.firstIntersectionPoint(rayToThisCell, &intoThisCell); + bool isPreviousResPointInsideCurrentCell = (intersectionCount % 2); // Must intersect uneven times to be inside. (1 % 2 = 1) + + // If we have a real previous cell, we need to go out of it, before entering this. + // That is: add a CL-point describing where it leaves the previous cell. + + if ( prevWellResPoint->isCell()) { - branchCLCoords.push_back(outOfPrevCell); - branchCellIds.push_back(RigWellResultPoint()); + cvf::Vec3d outOfPrevCell(centerPreviousCell); + + const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint); + bool intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); + //CVF_ASSERT(intersectionOk); + //CVF_ASSERT(intersectionOk); + if ((intoThisCell - outOfPrevCell).lengthSquared() > 1e-3) + { + branchCLCoords.push_back(outOfPrevCell); + branchCellIds.push_back(RigWellResultPoint()); + } + } + else if (isPreviousResPointInsideCurrentCell) + { + // Since the previous point actually is inside this cell, + /// use that as the entry point into this cell + intoThisCell = centerPreviousCell; } } - branchCLCoords.push_back(currentPoint); - branchCellIds.push_back(currentWellResPoint); - - prevWellResPoint = ¤tWellResPoint; - - continue; - } - - // - // Handle currentWellResPoint as a real cell result points. - // - - const RigCell& cell = eclipseCaseData->cellFromWellResultCell(currentWellResPoint); - - // Check if this and the previous cells has shared faces - - cvf::StructGridInterface::FaceType sharedFace; - if (prevWellResPoint && prevWellResPoint->isCell() && eclipseCaseData->findSharedSourceFace(sharedFace, currentWellResPoint, *prevWellResPoint)) - { - // If they share faces, the shared face center is used as point - // describing the entry of this cell. (And exit of the previous cell) - - branchCLCoords.push_back(cell.faceCenter(sharedFace)); + branchCLCoords.push_back(intoThisCell); branchCellIds.push_back(currentWellResPoint); } else { - // This and the previous cell does not share a face. - // Then we need to calculate the exit of the previous cell, and the entry point into this cell + // Need to start a "display branch" for a Normal Well. - cvf::Vec3d centerPreviousCell(cvf::Vec3d::ZERO); - cvf::Vec3d centerThisCell = cell.center(); - bool distanceToWellHeadIsLonger = true; + CVF_ASSERT(!isMultiSegmentWell); - // If we have a previous well result point, use its center as measure point and ray intersection start - // when considering things. + // This cell is further from the previous cell than from the well head, + // thus we interpret it as a new branch. - if (prevWellResPoint && prevWellResPoint->isValid()) - { - if (prevWellResPoint->isCell()) - { - const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint); - centerPreviousCell = prevCell.center(); - } - else - { - centerPreviousCell = prevWellResPoint->m_bottomPosition; - } + // First finish the current branch in the previous cell + //branchCLCoords.push_back(branchCLCoords.back() + 1.5*(centerPreviousCell - branchCLCoords.back()) ); + finishPipeCenterLine(pipeBranchesCLCoords, centerPreviousCell); - distanceToWellHeadIsLonger = (centerThisCell - centerPreviousCell).lengthSquared() <= (centerThisCell - whStartPos).lengthSquared(); - } - + // Create new display branch + pipeBranchesCLCoords.push_back(std::vector()); + pipeBranchesCellIds.push_back(std::vector ()); - // First make sure this cell is not starting a new "display" branch for none MSW's + // Start the new branch by entering the first cell (the wellhead) and intermediate + prevWellResPoint = whResCell; + pipeBranchesCLCoords.back().push_back(whStartPos); + pipeBranchesCellIds.back().push_back(*prevWellResPoint); - if ( wellResults->isMultiSegmentWell() - || !isAutoDetectBranches - || (prevWellResPoint == whResCell) - || distanceToWellHeadIsLonger) - { - // Not starting a "display" branch for normal wells - // Calculate the exit of the previous cell, and the entry point into this cell + // Include intermediate + pipeBranchesCLCoords.back().push_back(whIntermediate); + pipeBranchesCellIds.back().push_back(*prevWellResPoint); - cvf::Vec3d intoThisCell(centerThisCell); // Use cell center as default for "into" point. - - if (prevWellResPoint && prevWellResPoint->isValid()) - { - // We have a defined previous point - // Create ray between the previous and this cell - - cvf::Ray rayToThisCell; - rayToThisCell.setOrigin(centerPreviousCell); - rayToThisCell.setDirection((centerThisCell - centerPreviousCell).getNormalized()); - - // Intersect with the current cell to find a better entry point than the cell center - - int intersectionCount = cell.firstIntersectionPoint(rayToThisCell, &intoThisCell); - bool isPreviousResPointInsideCurrentCell = (intersectionCount % 2); // Must intersect uneven times to be inside. (1 % 2 = 1) - - // If we have a real previous cell, we need to go out of it, before entering this. - // That is: add a CL-point describing where it leaves the previous cell. - - if ( prevWellResPoint->isCell()) - { - cvf::Vec3d outOfPrevCell(centerPreviousCell); - - const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint); - bool intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); - //CVF_ASSERT(intersectionOk); - //CVF_ASSERT(intersectionOk); - if ((intoThisCell - outOfPrevCell).lengthSquared() > 1e-3) - { - branchCLCoords.push_back(outOfPrevCell); - branchCellIds.push_back(RigWellResultPoint()); - } - } - else if (isPreviousResPointInsideCurrentCell) - { - // Since the previous point actually is inside this cell, - /// use that as the entry point into this cell - intoThisCell = centerPreviousCell; - } - - } - - branchCLCoords.push_back(intoThisCell); - branchCellIds.push_back(currentWellResPoint); - } - else - { - // Need to start a "display branch" for a Normal Well. - - CVF_ASSERT(!wellResults->isMultiSegmentWell()); - - // This cell is further from the previous cell than from the well head, - // thus we interpret it as a new branch. - - // First finish the current branch in the previous cell - //branchCLCoords.push_back(branchCLCoords.back() + 1.5*(centerPreviousCell - branchCLCoords.back()) ); - finishPipeCenterLine(pipeBranchesCLCoords, centerPreviousCell); - - // Create new display branch - pipeBranchesCLCoords.push_back(std::vector()); - pipeBranchesCellIds.push_back(std::vector ()); - - // Start the new branch by entering the first cell (the wellhead) and intermediate - prevWellResPoint = whResCell; - pipeBranchesCLCoords.back().push_back(whStartPos); - pipeBranchesCellIds.back().push_back(*prevWellResPoint); - - // Include intermediate - pipeBranchesCLCoords.back().push_back(whIntermediate); - pipeBranchesCellIds.back().push_back(*prevWellResPoint); - - // Well now we need to step one back to take this cell again, but in the new branch. - cIdx--; - continue; - } + // Well now we need to step one back to take this cell again, but in the new branch. + cIdx--; + continue; } + } - prevWellResPoint = ¤tWellResPoint; - } - - // For the last cell, add the point 0.5 past the center of that cell - // Remember that prevWellResPoint actually is the last one in this branch. + prevWellResPoint = ¤tWellResPoint; + } - cvf::Vec3d centerLastCell; - if (prevWellResPoint && prevWellResPoint->isCell()) - { - const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint); - centerLastCell = prevCell.center(); - finishPipeCenterLine(pipeBranchesCLCoords, centerLastCell); - } - else - { - // Remove the ID that is superfluous since we will not add an ending point - pipeBranchesCellIds.back().pop_back(); - } + // For the last cell, add the point 0.5 past the center of that cell + // Remember that prevWellResPoint actually is the last one in this branch. + + if (prevWellResPoint && prevWellResPoint->isCell()) + { + const RigCell& prevCell = eclipseCaseData->cellFromWellResultCell(*prevWellResPoint); + cvf::Vec3d centerLastCell = prevCell.center(); + finishPipeCenterLine(pipeBranchesCLCoords, centerLastCell); + } + else + { + // Remove the ID that is superfluous since we will not add an ending point + pipeBranchesCellIds.back().pop_back(); } } + CVF_ASSERT(pipeBranchesCellIds.size() == pipeBranchesCLCoords.size()); for (size_t i = 0 ; i < pipeBranchesCellIds.size() ; ++i) { @@ -367,6 +368,46 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(RimEclip } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigSimulationWellCenterLineCalculator::hasAnyResultCells(const std::vector &resBranches) +{ + bool hasResultCells = false; + if ( resBranches.size() ) + { + for ( size_t i = 0 ; i < resBranches.size(); ++i ) + { + if ( resBranches[i].m_branchResultPoints.size() != 0 ) + { + hasResultCells = true; + break; + } + } + } + return hasResultCells; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigSimulationWellCenterLineCalculator::hasAnyValidDataCells(const RigWellResultBranch& branch) +{ + bool hasValidData = false; + for ( size_t cIdx = 0; cIdx < branch.m_branchResultPoints.size(); ++cIdx ) + { + if ( branch.m_branchResultPoints[cIdx].isValid() ) + { + hasValidData = true; + break; + } + } + + return hasValidData; +} + //-------------------------------------------------------------------------------------------------- /// All branches are completed using the point 0.5 past the center of /// last cell. diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h index 7fc3396a67..845c057d3d 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h @@ -23,6 +23,7 @@ #include class RimEclipseWell; +class RigEclipseCaseData; class RigSimulationWellCenterLineCalculator { @@ -30,7 +31,18 @@ public: static void calculateWellPipeCenterline(RimEclipseWell* m_rimWell, std::vector< std::vector >& pipeBranchesCLCoords, std::vector< std::vector >& pipeBranchesCellIds) ; + + static void calculateWellPipeCenterlineFromWellFrame(const RigWellResultFrame& wellFrame, + const RigEclipseCaseData* eclipseCaseData, + bool isMultiSegmentWell, + bool isAutoDetectBranches, + std::vector> & pipeBranchesCLCoords, + std::vector> & pipeBranchesCellIds); + + private: + static bool hasAnyResultCells(const std::vector &resBranches); + static bool hasAnyValidDataCells(const RigWellResultBranch& branch); static void finishPipeCenterLine( std::vector< std::vector > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter ) ; }; From 06b9f13e4147269a8d3c873756b488e0194de625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 15:57:04 +0100 Subject: [PATCH 11/27] #1112 Well centerline with cell centers improved, and moved to centerline calculator --- .../RivSimWellPipesPartMgr.cpp | 33 -------------- .../ProjectDataModel/RimEclipseWell.cpp | 11 +++++ .../ProjectDataModel/RimEclipseWell.h | 1 + .../RigSimulationWellCenterLineCalculator.cpp | 45 ++++++++++++++++++- .../RigSimulationWellCenterLineCalculator.h | 3 ++ 5 files changed, 58 insertions(+), 35 deletions(-) diff --git a/ApplicationCode/ModelVisualization/RivSimWellPipesPartMgr.cpp b/ApplicationCode/ModelVisualization/RivSimWellPipesPartMgr.cpp index 1407842d7a..ea85d02f43 100644 --- a/ApplicationCode/ModelVisualization/RivSimWellPipesPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivSimWellPipesPartMgr.cpp @@ -84,39 +84,6 @@ void RivSimWellPipesPartMgr::buildWellPipeParts() RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(m_rimWell.p(), m_pipeBranchesCLCoords, pipeBranchesCellIds); - RimEclipseWellCollection* wellColl = nullptr; - m_rimWell->firstAncestorOrThisOfType(wellColl); - if (wellColl && wellColl->wellPipeCoordType() == RimEclipseWellCollection::WELLPIPE_CELLCENTER) - { - // Compute coords based on connection centers - // Loop over all well cells, and overwrite with cell center instead of interpolated coordinates - - RigMainGrid* mainGrid = m_rimReservoirView->mainGrid(); - - for (size_t i = 0; i < pipeBranchesCellIds.size(); i++) - { - const std::vector& resPoints = pipeBranchesCellIds[i]; - for (size_t j = 0; j < resPoints.size(); j++) - { - if (resPoints[j].isCell()) - { - size_t gridIndex = resPoints[j].m_gridIndex; - size_t gridCellIndex = resPoints[j].m_gridCellIndex; - - if (gridIndex < mainGrid->gridCount()) - { - RigGridBase* rigGrid = mainGrid->gridByIndex(gridIndex); - if (gridCellIndex < rigGrid->cellCount()) - { - cvf::Vec3d center = rigGrid->cell(gridCellIndex).center(); - m_pipeBranchesCLCoords[i][j] = center; - } - } - } - } - } - } - double characteristicCellSize = m_rimReservoirView->mainGrid()->characteristicIJCellSize(); double pipeRadius = m_rimReservoirView->wellCollection()->pipeRadiusScaleFactor() *m_rimWell->pipeRadiusScaleFactor() * characteristicCellSize; diff --git a/ApplicationCode/ProjectDataModel/RimEclipseWell.cpp b/ApplicationCode/ProjectDataModel/RimEclipseWell.cpp index 41fc951a6e..447df1cc56 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseWell.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseWell.cpp @@ -296,6 +296,17 @@ bool RimEclipseWell::isWellSpheresVisible(size_t frameIndex) return false; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimEclipseWell::isUsingCellCenterForPipe() +{ + RimEclipseWellCollection* wellColl = nullptr; + this->firstAncestorOrThisOfType(wellColl); + + return (wellColl && wellColl->wellPipeCoordType() == RimEclipseWellCollection::WELLPIPE_CELLCENTER); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimEclipseWell.h b/ApplicationCode/ProjectDataModel/RimEclipseWell.h index a988571545..ff4e68fb55 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseWell.h +++ b/ApplicationCode/ProjectDataModel/RimEclipseWell.h @@ -50,6 +50,7 @@ public: bool isWellPipeVisible(size_t frameIndex); bool isWellSpheresVisible(size_t frameIndex); + bool isUsingCellCenterForPipe(); bool visibleCellsInstersectsWell(size_t frameIndex); diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp index 602140d1cc..30ce79549b 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp @@ -61,11 +61,13 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(RimEclip const RigWellResultFrame& staticWellFrame = wellResults->m_staticWellCells; bool isMultiSegmentWell = wellResults->isMultiSegmentWell(); + bool useAllCellCenters = rimWell->isUsingCellCenterForPipe(); calculateWellPipeCenterlineFromWellFrame(staticWellFrame, eclipseCaseData, isMultiSegmentWell, - isAutoDetectBranches, + isAutoDetectBranches, + useAllCellCenters, pipeBranchesCLCoords, pipeBranchesCellIds); return; @@ -73,12 +75,15 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(RimEclip //-------------------------------------------------------------------------------------------------- -/// +/// Based on the points and cells, calculate a pipe centerline +/// The returned CellIds is one less than the number of centerline points, +/// and are describing the lines between the points, starting with the first line //-------------------------------------------------------------------------------------------------- void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(const RigWellResultFrame &wellFrame, const RigEclipseCaseData* eclipseCaseData, bool isMultiSegmentWell, bool isAutoDetectBranches, + bool useAllCellCenters, std::vector> &pipeBranchesCLCoords, std::vector> &pipeBranchesCellIds) { @@ -360,6 +365,7 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellF } } + if (useAllCellCenters) addCellCenterPoints(eclipseCaseData, pipeBranchesCLCoords, pipeBranchesCellIds); CVF_ASSERT(pipeBranchesCellIds.size() == pipeBranchesCLCoords.size()); for (size_t i = 0 ; i < pipeBranchesCellIds.size() ; ++i) @@ -368,6 +374,41 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellF } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigSimulationWellCenterLineCalculator::addCellCenterPoints(const RigEclipseCaseData* eclipseCaseData, + std::vector> &pipeBranchesCLCoords, + std::vector> &pipeBranchesCellIds) +{ + for ( size_t brIdx = 0; brIdx < pipeBranchesCellIds.size(); brIdx++ ) + { + const std::vector& branchResPoints = pipeBranchesCellIds[brIdx]; + const std::vector& branchClPoints = pipeBranchesCLCoords[brIdx]; + + std::vector branchResPointsWithCellCenters; + std::vector branchClPointsWithCellCenters; + + for ( size_t cIdx = 0; cIdx < branchResPoints.size(); cIdx++ ) + { + branchResPointsWithCellCenters.push_back(branchResPoints[cIdx]); + branchClPointsWithCellCenters.push_back(branchClPoints[cIdx]); + + if ( branchResPoints[cIdx].isCell() ) + { + const RigCell& cell = eclipseCaseData->cellFromWellResultCell(branchResPoints[cIdx]); + cvf::Vec3d center = cell.center(); + branchClPointsWithCellCenters.push_back(center); + branchResPointsWithCellCenters.push_back(branchResPoints[cIdx]); + } + } + + branchClPointsWithCellCenters.push_back(branchClPoints[branchResPoints.size()]); + + pipeBranchesCellIds[brIdx] = branchResPointsWithCellCenters; + pipeBranchesCLCoords[brIdx] = branchClPointsWithCellCenters; + } +} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h index 845c057d3d..ac3fac8fa6 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h @@ -36,6 +36,7 @@ public: const RigEclipseCaseData* eclipseCaseData, bool isMultiSegmentWell, bool isAutoDetectBranches, + bool useAllCellCenters, std::vector> & pipeBranchesCLCoords, std::vector> & pipeBranchesCellIds); @@ -44,5 +45,7 @@ private: static bool hasAnyResultCells(const std::vector &resBranches); static bool hasAnyValidDataCells(const RigWellResultBranch& branch); static void finishPipeCenterLine( std::vector< std::vector > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter ) ; + + static void addCellCenterPoints(const RigEclipseCaseData* eclipseCaseData, std::vector> &pipeBranchesCLCoords, std::vector> &pipeBranchesCellIds); }; From 94f94af325fe0c972d61d76ddca09d69408e80db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 16:12:12 +0100 Subject: [PATCH 12/27] #1112 Added a flowrate to the well results. Waiting for ERT to include the reading. --- ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp | 1 + ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index f70adc460f..e3cccd30fe 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -969,6 +969,7 @@ RigWellResultPoint RifReaderEclipseOutput::createWellResultPoint(const RigGridBa resultPoint.m_ertBranchId = ertBranchId; resultPoint.m_ertSegmentId = ertSegmentId; + resultPoint.m_flowRate = 0.5; // Todo : Get from Ert } return resultPoint; diff --git a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h index 2015f05942..fc07ac13b7 100644 --- a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h +++ b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h @@ -39,7 +39,8 @@ struct RigWellResultPoint m_isOpen(false), m_ertBranchId(-1), m_ertSegmentId(-1), - m_bottomPosition(cvf::Vec3d::UNDEFINED) + m_bottomPosition(cvf::Vec3d::UNDEFINED), + m_flowRate(0.0) { } bool isPointValid() const @@ -66,6 +67,7 @@ struct RigWellResultPoint int m_ertSegmentId; cvf::Vec3d m_bottomPosition; //< The estimated bottom position of the well segment, when we have no grid cell connections for the segment. + double m_flowRate; }; //================================================================================================== From cebe5428beb59db6438e7521583d76d1348e2f4c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 20 Jan 2017 16:25:05 +0100 Subject: [PATCH 13/27] #1107 Moved showWindow field to RimViewWindow and removed showWindow field from derived classes --- .../ViewLink/RicShowAllLinkedViewsFeature.cpp | 3 +- .../Flow/RimWellAllocationPlot.cpp | 17 +---- .../Flow/RimWellAllocationPlot.h | 4 -- .../ProjectDataModel/RimEclipseView.cpp | 16 +---- .../ProjectDataModel/RimGeoMechView.cpp | 14 ---- .../RimMdiWindowController.cpp | 26 ++----- .../ProjectDataModel/RimMdiWindowController.h | 70 ------------------- ApplicationCode/ProjectDataModel/RimView.cpp | 13 +++- ApplicationCode/ProjectDataModel/RimView.h | 4 +- .../ProjectDataModel/RimViewWindow.cpp | 41 +++++++++-- .../ProjectDataModel/RimViewWindow.h | 15 ++-- .../ProjectDataModel/RimWellLogPlot.cpp | 26 +------ .../ProjectDataModel/RimWellLogPlot.h | 7 +- .../Summary/RimSummaryPlot.cpp | 19 +---- .../ProjectDataModel/Summary/RimSummaryPlot.h | 4 -- 15 files changed, 74 insertions(+), 205 deletions(-) diff --git a/ApplicationCode/Commands/ViewLink/RicShowAllLinkedViewsFeature.cpp b/ApplicationCode/Commands/ViewLink/RicShowAllLinkedViewsFeature.cpp index 2d41cc7e29..cfd8678b77 100644 --- a/ApplicationCode/Commands/ViewLink/RicShowAllLinkedViewsFeature.cpp +++ b/ApplicationCode/Commands/ViewLink/RicShowAllLinkedViewsFeature.cpp @@ -63,8 +63,7 @@ void RicShowAllLinkedViewsFeature::onActionTriggered(bool isChecked) for (size_t j = 0; j < views.size(); j++) { - views[j]->showWindow.setValueWithFieldChanged(true); - views[j]->uiCapability()->updateUiIconFromToggleField(); + views[j]->forceShowWindowOn(); } } } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 691056889c..921ee8f2ea 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -40,8 +40,6 @@ CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot"); RimWellAllocationPlot::RimWellAllocationPlot() { CAF_PDM_InitObject("Well Allocation Plot", ":/newIcon16x16.png", "", ""); - CAF_PDM_InitField(&m_showWindow, "ShowWindow", true, "Show Flow Diagnostics Plot", "", "", ""); - m_showWindow.uiCapability()->setUiHidden(true); CAF_PDM_InitField(&m_userName, "PlotDescription", QString("Flow Diagnostics Plot"), "Name", "", "", ""); m_userName.uiCapability()->setUiReadOnly(true); @@ -196,20 +194,9 @@ QList RimWellAllocationPlot::calculateValueOptions(const //-------------------------------------------------------------------------------------------------- void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) { - if (changedField == &m_showWindow) - { - if (m_showWindow) - { - loadDataAndUpdate(); - } - else - { - updateMdiWindowVisibility(); - } + RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue); - uiCapability()->updateUiIconFromToggleField(); - } - else if (changedField == &m_userName || + if (changedField == &m_userName || changedField == &m_showPlotTitle) { updateMdiWindowTitle(); diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index 7ec71c239b..ea048c79ee 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -64,7 +64,6 @@ public: protected: // Overridden PDM methods - virtual caf::PdmFieldHandle* objectToggleField() { return &m_showWindow; } virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; @@ -75,14 +74,11 @@ private: // RimViewWindow overrides - virtual caf::PdmField* getShowWindowField() override { return &m_showWindow; } virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; virtual void deleteViewWidget() override; private: - caf::PdmField m_showWindow; - caf::PdmField m_showPlotTitle; caf::PdmField m_userName; //caf::PdmField m_showAccWellFlowPlot; diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index e2d6e9cb5c..d6d3f926ac 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -183,21 +183,7 @@ void RimEclipseView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c { RimView::fieldChangedByUi(changedField, oldValue, newValue); - if (changedField == &showWindow) - { - if (showWindow) - { - loadDataAndUpdate(); - } - else - { - updateMdiWindowVisibility(); - } - - this->updateUiIconFromToggleField(); - } - - else if (changedField == &showInvalidCells) + if (changedField == &showInvalidCells) { this->scheduleGeometryRegen(INACTIVE); this->scheduleGeometryRegen(RANGE_FILTERED_INACTIVE); diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp index bd6318fb81..ed0fb12a3c 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp @@ -476,20 +476,6 @@ cvf::Transform* RimGeoMechView::scaleTransform() void RimGeoMechView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) { RimView::fieldChangedByUi(changedField, oldValue, newValue); - - if (changedField == &showWindow) - { - if (showWindow) - { - loadDataAndUpdate(); - } - else - { - updateMdiWindowVisibility(); - } - - this->updateUiIconFromToggleField(); - } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp b/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp index 11b87d2b91..5064c83b1e 100644 --- a/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp +++ b/ApplicationCode/ProjectDataModel/RimMdiWindowController.cpp @@ -17,9 +17,10 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RimMdiWindowController.h" -#include "RiuMainWindowBase.h" + #include "RiaApplication.h" #include "RimViewWindow.h" +#include "RiuMainWindowBase.h" CAF_PDM_XML_SOURCE_INIT(RimMdiWindowController, "MdiWindowController"); @@ -79,7 +80,7 @@ RimMdiWindowGeometry RimMdiWindowController::mdiWindowGeometry() //-------------------------------------------------------------------------------------------------- void RimMdiWindowController::handleViewerDeletion() { - showWindowField() = false; + viewPdmObject()->m_showWindow = false; uiCapability()->updateUiIconFromToggleField(); updateConnectedEditors(); @@ -94,16 +95,6 @@ void RimMdiWindowController::removeWindowFromMDI() if (mainWin && viewWidget()) mainWin->removeViewer(viewWidget()); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimMdiWindowController::showWindowFieldChangedByUi() -{ - updateViewerWidget(); - - viewPdmObject()->uiCapability()->updateUiIconFromToggleField(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -114,14 +105,6 @@ RimViewWindow* RimMdiWindowController::viewPdmObject() return viewWindowObj; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::PdmField& RimMdiWindowController::showWindowField() -{ - return *(viewPdmObject()->getShowWindowField()); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -157,11 +140,10 @@ void RimMdiWindowController::updateViewerWidget() RiuMainWindowBase* mainWindow = getMainWindow(); if ( !mainWindow ) return; - if ( showWindowField() ) + if ( viewPdmObject()->m_showWindow() ) { if ( !viewWidget() ) { - // m_wellAllocationPlotWidget = new RiuWellAllocationPlot(this, mainPlotWindow); QWidget * viewWidget = viewPdmObject()->createViewWidget(mainWindow); mainWindow->addViewer(viewWidget, this->mdiWindowGeometry()); diff --git a/ApplicationCode/ProjectDataModel/RimMdiWindowController.h b/ApplicationCode/ProjectDataModel/RimMdiWindowController.h index b6f5fd6b1e..4ba4062b70 100644 --- a/ApplicationCode/ProjectDataModel/RimMdiWindowController.h +++ b/ApplicationCode/ProjectDataModel/RimMdiWindowController.h @@ -22,74 +22,6 @@ #include "cafPdmChildField.h" #include "cafPdmField.h" -#if 0 -class RimMdiWindowController; - -class RimViewWindow : public caf::PdmObject -{ - CAF_PDM_HEADER_INIT; -public: - RimViewWindow(void); - virtual ~RimViewWindow(void) - { - if (m_windowController()) delete m_windowController(); - } - - void handleViewerDeletion() { if (m_windowController()) m_windowController->handleViewerDeletion(); } - void updateViewerWidgetBasic() { if (m_windowController()) m_windowController->updateViewerWidget(); } - - void setAs3DMDI() { setAsMDI(0); } - void setAsPlotMDI() { setAsMDI(1); } - - void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry); - RimMdiWindowGeometry mdiWindowGeometry(); - - virtual QImage snapshotWindowContent() = 0; - virtual void zoomAll() = 0; - -protected: - virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override - { - if ( m_windowController() ) - { - if ( changedField == showWindowField() ) - { - m_windowController()->showWindowFieldChangedByUi(); - } - } - } - -private: - - ///////// Interface for the Window controller - friend class RimMdiWindowController; - - virtual QWidget* viewWidget() = 0; - virtual QWidget* createViewWidget(QWidget* mainWindowParent) = 0; - virtual void updateViewWidgetAfterCreation() = 0; - virtual void deleteViewWidget() = 0; - - virtual caf::PdmField* showWindowField() = 0; - - ////////// - - void setAsMDI(int mainWindowID) - { - if (!m_windowController()) - { - m_windowController = new RimMdiWindowController; - RimMdiWindowGeometry mwg; - mwg.mainWindowID = mainWindowID; - setMdiWindowGeometry(mwg); - } - } - - caf::PdmChildField m_windowController; - - // Obsolete field - caf::PdmField< std::vector > m_windowGeometry; -}; -#endif class RimViewWindow; class RiuMainWindowBase; @@ -113,12 +45,10 @@ public: void updateViewerWidget(); void handleViewerDeletion(); void removeWindowFromMDI(); - void showWindowFieldChangedByUi(); protected: RimViewWindow* viewPdmObject(); - caf::PdmField& showWindowField(); QWidget* viewWidget(); RiuMainWindowBase* getMainWindow(); diff --git a/ApplicationCode/ProjectDataModel/RimView.cpp b/ApplicationCode/ProjectDataModel/RimView.cpp index cbd0ddc97b..5b81516552 100644 --- a/ApplicationCode/ProjectDataModel/RimView.cpp +++ b/ApplicationCode/ProjectDataModel/RimView.cpp @@ -73,9 +73,6 @@ RimView::RimView(void) CAF_PDM_InitField(&name, "UserDescription", QString(""), "Name", "", "", ""); - CAF_PDM_InitField(&showWindow, "ShowWindow", true, "Show 3D viewer", "", "", ""); - showWindow.uiCapability()->setUiHidden(true); - CAF_PDM_InitField(&cameraPosition, "CameraPosition", cvf::Mat4d::IDENTITY, "", "", "", ""); cameraPosition.uiCapability()->setUiHidden(true); @@ -523,6 +520,8 @@ bool RimView::isLightingDisabled() const //-------------------------------------------------------------------------------------------------- void RimView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) { + RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue); + if (changedField == &meshMode) { createDisplayModel(); @@ -966,3 +965,11 @@ QWidget* RimView::viewWidget() else return nullptr; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimView::forceShowWindowOn() +{ + m_showWindow.setValueWithFieldChanged(true); +} + diff --git a/ApplicationCode/ProjectDataModel/RimView.h b/ApplicationCode/ProjectDataModel/RimView.h index 8df8a0d6f2..3652124e56 100644 --- a/ApplicationCode/ProjectDataModel/RimView.h +++ b/ApplicationCode/ProjectDataModel/RimView.h @@ -82,7 +82,6 @@ public: caf::PdmField name; caf::PdmField scaleZ; - caf::PdmField showWindow; caf::PdmField cameraPosition; caf::PdmField cameraPointOfInterest; caf::PdmField isPerspectiveView; @@ -164,12 +163,12 @@ public: cvf::ref displayCoordTransform(); virtual QWidget* viewWidget() override; + void forceShowWindowOn(); public: virtual void loadDataAndUpdate() = 0; virtual RimCase* ownerCase() = 0; - virtual caf::PdmFieldHandle* objectToggleField() { return &showWindow; } virtual caf::PdmFieldHandle* userDescriptionField() { return &name; } protected: @@ -217,7 +216,6 @@ protected: virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); - virtual caf::PdmField* getShowWindowField() override { return &showWindow; } virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; virtual void updateViewWidgetAfterCreation() override; virtual void updateMdiWindowTitle() override; diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp index 99956e8d21..f72bb7aa9c 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp @@ -32,6 +32,9 @@ RimViewWindow::RimViewWindow(void) m_windowController.uiCapability()->setUiHidden(true); m_windowController.uiCapability()->setUiTreeChildrenHidden(true); + CAF_PDM_InitField(&m_showWindow, "ShowWindow", true, "Show Window", "", "", ""); + m_showWindow.uiCapability()->setUiHidden(true); + // Obsolete field CAF_PDM_InitFieldNoDefault(&obsoleteField_windowGeometry, "WindowGeometry", "", "", "", ""); obsoleteField_windowGeometry.uiCapability()->setUiHidden(true); @@ -67,7 +70,24 @@ void RimViewWindow::handleMdiWindowClosed() //-------------------------------------------------------------------------------------------------- void RimViewWindow::updateMdiWindowVisibility() { - if ( m_windowController() ) m_windowController->updateViewerWidget(); + if (m_windowController()) + { + m_windowController->updateViewerWidget(); + } + else + { + if (viewWidget()) + { + if (m_showWindow) + { + viewWidget()->show(); + } + else + { + viewWidget()->hide(); + } + } + } } //-------------------------------------------------------------------------------------------------- @@ -93,17 +113,30 @@ RimMdiWindowGeometry RimViewWindow::mdiWindowGeometry() } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmFieldHandle* RimViewWindow::objectToggleField() +{ + return &m_showWindow; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimViewWindow::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) { - if ( m_windowController() ) + if ( changedField == &m_showWindow ) { - if ( changedField == getShowWindowField() ) + if (m_showWindow) { - m_windowController()->showWindowFieldChangedByUi(); + loadDataAndUpdate(); } + else + { + updateMdiWindowVisibility(); + } + uiCapability()->updateUiIconFromToggleField(); } } diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.h b/ApplicationCode/ProjectDataModel/RimViewWindow.h index e398bc802f..ec0d6a575c 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.h @@ -60,29 +60,36 @@ public: virtual QImage snapshotWindowContent() = 0; virtual void zoomAll() = 0; -protected: - + // Derived classes are not supposed to override this function. The intention is to always use m_showWindow + // as the objectToggleField for this class. This way the visibility of a widget being part of a composite widget + // can be controlled from the project tree using check box toggles + virtual caf::PdmFieldHandle* objectToggleField() override final; + +protected: void removeMdiWindowFromMdiArea(); void updateMdiWindowVisibility(); ///////// Interface for the Window controller friend class RimMdiWindowController; - virtual caf::PdmField* getShowWindowField() = 0; virtual QWidget* createViewWidget(QWidget* mainWindowParent) = 0; virtual void updateViewWidgetAfterCreation() {}; virtual void updateMdiWindowTitle(); // Has real default implementation - virtual void deleteViewWidget() = 0; + virtual void deleteViewWidget() = 0; + virtual void loadDataAndUpdate() = 0; ////////// virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; virtual void initAfterRead() override; + caf::PdmField m_showWindow; + private: void setAsMdiWindow(int mainWindowID); caf::PdmChildField m_windowController; + // Obsoleted field caf::PdmField< std::vector > obsoleteField_windowGeometry; }; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index 57fc6084c8..44e2dd54fc 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -59,9 +59,6 @@ RimWellLogPlot::RimWellLogPlot() m_viewer = NULL; - CAF_PDM_InitField(&m_showWindow, "ShowWindow", true, "Show well log plot", "", "", ""); - m_showWindow.uiCapability()->setUiHidden(true); - CAF_PDM_InitField(&m_userName, "PlotDescription", QString("Well Log Plot"),"Name", "", "", ""); caf::AppEnum< RimWellLogPlot::DepthTypeEnum > depthType = MEASURED_DEPTH; @@ -98,20 +95,9 @@ RimWellLogPlot::~RimWellLogPlot() //-------------------------------------------------------------------------------------------------- void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) { - if (changedField == &m_showWindow) - { - if (m_showWindow) - { - loadDataAndUpdate(); - } - else - { - updateMdiWindowVisibility(); - } + RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue); - uiCapability()->updateUiIconFromToggleField(); - } - else if (changedField == &m_minVisibleDepth || changedField == &m_maxVisibleDepth) + if (changedField == &m_minVisibleDepth || changedField == &m_maxVisibleDepth) { applyDepthZoomFromVisibleDepth(); @@ -132,14 +118,6 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -caf::PdmFieldHandle* RimWellLogPlot::objectToggleField() -{ - return &m_showWindow; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h index 07d4243f5c..df7fb5881b 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h @@ -24,11 +24,11 @@ #include "cafPdmChildArrayField.h" #include "cafAppEnum.h" -#include #include "RimDefines.h" - #include "RimViewWindow.h" +#include + class RiuWellLogPlot; class RimWellLogTrack; @@ -96,7 +96,6 @@ protected: // Overridden PDM methods virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering); - virtual caf::PdmFieldHandle* objectToggleField(); virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } virtual QImage snapshotWindowContent() override; @@ -111,12 +110,10 @@ private: public: // Needed by RiuWellAllocation Plot // RimViewWindow overrides - virtual caf::PdmField* getShowWindowField() override { return &m_showWindow; } virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; virtual void deleteViewWidget() override; private: - caf::PdmField m_showWindow; caf::PdmField m_userName; caf::PdmField< caf::AppEnum< DepthTypeEnum > > m_depthType; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index 5dfad70205..422802aa9c 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -51,8 +51,6 @@ CAF_PDM_SOURCE_INIT(RimSummaryPlot, "SummaryPlot"); RimSummaryPlot::RimSummaryPlot() { CAF_PDM_InitObject("Summary Plot", ":/SummaryPlot16x16.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_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", ""); @@ -475,21 +473,10 @@ void RimSummaryPlot::addCurveFilter(RimSummaryCurveFilter* curveFilter) //-------------------------------------------------------------------------------------------------- void RimSummaryPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) { - if (changedField == &m_showWindow) - { - if (m_showWindow) - { - loadDataAndUpdate(); - } - else - { - updateMdiWindowVisibility(); - } + RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue); - uiCapability()->updateUiIconFromToggleField(); - } - else if (changedField == &m_userName || - changedField == &m_showPlotTitle) + if (changedField == &m_userName || + changedField == &m_showPlotTitle) { updateMdiWindowTitle(); } diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h index 398d59ec7c..94fee99742 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -88,7 +88,6 @@ public: protected: // Overridden PDM methods - virtual caf::PdmFieldHandle* objectToggleField() { return &m_showWindow; } virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override; @@ -106,14 +105,11 @@ private: // RimViewWindow overrides - virtual caf::PdmField* getShowWindowField() override { return &m_showWindow; } virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; void updateMdiWindowTitle() override; virtual void deleteViewWidget() override; private: - caf::PdmField m_showWindow; - caf::PdmField m_showPlotTitle; caf::PdmField m_userName; From 0d7da9788a5053be111e9e9ce1f260a70e667b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 17:20:09 +0100 Subject: [PATCH 14/27] #1112 Made conveninece methods to calculate well pipe centerline, and added possibility to do it pr timestep. --- .../RivSimWellPipesPartMgr.cpp | 2 +- .../ProjectDataModel/RimEclipseWell.cpp | 20 +++++++++ .../ProjectDataModel/RimEclipseWell.h | 14 +++++-- .../ProjectDataModel/RimIntersection.cpp | 2 +- .../RigSimulationWellCenterLineCalculator.cpp | 41 ++++++++++++++++++- .../RigSimulationWellCenterLineCalculator.h | 15 ++++--- 6 files changed, 83 insertions(+), 11 deletions(-) diff --git a/ApplicationCode/ModelVisualization/RivSimWellPipesPartMgr.cpp b/ApplicationCode/ModelVisualization/RivSimWellPipesPartMgr.cpp index ea85d02f43..901bb953f5 100644 --- a/ApplicationCode/ModelVisualization/RivSimWellPipesPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivSimWellPipesPartMgr.cpp @@ -82,7 +82,7 @@ void RivSimWellPipesPartMgr::buildWellPipeParts() m_pipeBranchesCLCoords.clear(); std::vector< std::vector > pipeBranchesCellIds; - RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(m_rimWell.p(), m_pipeBranchesCLCoords, pipeBranchesCellIds); + m_rimWell->calculateWellPipeStaticCenterLine(m_pipeBranchesCLCoords, pipeBranchesCellIds); double characteristicCellSize = m_rimReservoirView->mainGrid()->characteristicIJCellSize(); double pipeRadius = m_rimReservoirView->wellCollection()->pipeRadiusScaleFactor() *m_rimWell->pipeRadiusScaleFactor() * characteristicCellSize; diff --git a/ApplicationCode/ProjectDataModel/RimEclipseWell.cpp b/ApplicationCode/ProjectDataModel/RimEclipseWell.cpp index 447df1cc56..454cf674a2 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseWell.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseWell.cpp @@ -27,6 +27,7 @@ #include "RimIntersectionCollection.h" #include "cvfMath.h" +#include "RigSimulationWellCenterLineCalculator.h" CAF_PDM_SOURCE_INIT(RimEclipseWell, "Well"); @@ -114,6 +115,25 @@ caf::PdmFieldHandle* RimEclipseWell::objectToggleField() return &showWell; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimEclipseWell::calculateWellPipeStaticCenterLine(std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds) +{ + RigSimulationWellCenterLineCalculator::calculateWellPipeStaticCenterline(this, pipeBranchesCLCoords, pipeBranchesCellIds); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimEclipseWell::calculateWellPipeDynamicCenterLine(size_t timeStepIdx, + std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds) +{ + RigSimulationWellCenterLineCalculator::calculateWellPipeDynamicCenterline(this, timeStepIdx, pipeBranchesCLCoords, pipeBranchesCellIds); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimEclipseWell.h b/ApplicationCode/ProjectDataModel/RimEclipseWell.h index ff4e68fb55..d8a90e269d 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseWell.h +++ b/ApplicationCode/ProjectDataModel/RimEclipseWell.h @@ -30,7 +30,7 @@ // Include to make Pdm work for cvf::Color #include "cafPdmFieldCvfColor.h" -class RigSingleWellResultsData; +#include "RigSingleWellResultsData.h" //================================================================================================== /// @@ -57,8 +57,12 @@ public: virtual caf::PdmFieldHandle* userDescriptionField(); virtual caf::PdmFieldHandle* objectToggleField(); - virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); - virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering); + void calculateWellPipeStaticCenterLine( std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds); + + void calculateWellPipeDynamicCenterLine(size_t timeStepIdx, + std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds); caf::PdmField showWell; @@ -73,6 +77,10 @@ public: caf::PdmField wellPipeColor; caf::PdmField pipeRadiusScaleFactor; +protected: + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue); + virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering); + private: cvf::ref m_wellResults; size_t m_resultWellIndex; diff --git a/ApplicationCode/ProjectDataModel/RimIntersection.cpp b/ApplicationCode/ProjectDataModel/RimIntersection.cpp index c2ddb03f3f..1c7f37d076 100644 --- a/ApplicationCode/ProjectDataModel/RimIntersection.cpp +++ b/ApplicationCode/ProjectDataModel/RimIntersection.cpp @@ -393,7 +393,7 @@ void RimIntersection::updateWellCenterline() const { std::vector< std::vector > pipeBranchesCellIds; - RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(simulationWell(), m_wellBranchCenterlines, pipeBranchesCellIds); + simulationWell->calculateWellPipeStaticCenterLine(m_wellBranchCenterlines, pipeBranchesCellIds); } } else diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp index 30ce79549b..2282d97846 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp @@ -34,7 +34,7 @@ /// The returned CellIds is one less than the number of centerline points, /// and are describing the lines between the points, starting with the first line //-------------------------------------------------------------------------------------------------- -void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(RimEclipseWell* rimWell, +void RigSimulationWellCenterLineCalculator::calculateWellPipeStaticCenterline(RimEclipseWell* rimWell, std::vector< std::vector >& pipeBranchesCLCoords, std::vector< std::vector >& pipeBranchesCellIds) { @@ -74,6 +74,45 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterline(RimEclip } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigSimulationWellCenterLineCalculator::calculateWellPipeDynamicCenterline(RimEclipseWell* rimWell, + size_t timeStepIndex, + std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds) +{ + bool isAutoDetectBranches = false; + RigEclipseCaseData* eclipseCaseData = NULL; + RigSingleWellResultsData* wellResults = NULL; + + { + CVF_ASSERT(rimWell); + RimEclipseView* eclipseView; + rimWell->firstAncestorOrThisOfType(eclipseView); + CVF_ASSERT(eclipseView); + + isAutoDetectBranches = eclipseView->wellCollection()->isAutoDetectingBranches(); + eclipseCaseData = eclipseView->eclipseCase()->reservoirData(); + wellResults = rimWell->wellResults(); + + if ( !wellResults || !wellResults->hasWellResult(timeStepIndex) ) return; + } + + + const RigWellResultFrame& wellFrame = wellResults->wellResultFrame(timeStepIndex); + bool isMultiSegmentWell = wellResults->isMultiSegmentWell(); + bool useAllCellCenters = rimWell->isUsingCellCenterForPipe(); + + calculateWellPipeCenterlineFromWellFrame(wellFrame, + eclipseCaseData, + isMultiSegmentWell, + isAutoDetectBranches, + useAllCellCenters, + pipeBranchesCLCoords, + pipeBranchesCellIds); +} + //-------------------------------------------------------------------------------------------------- /// Based on the points and cells, calculate a pipe centerline /// The returned CellIds is one less than the number of centerline points, diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h index ac3fac8fa6..fe0b00b177 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h @@ -28,10 +28,17 @@ class RigEclipseCaseData; class RigSimulationWellCenterLineCalculator { public: - static void calculateWellPipeCenterline(RimEclipseWell* m_rimWell, - std::vector< std::vector >& pipeBranchesCLCoords, - std::vector< std::vector >& pipeBranchesCellIds) ; + static void calculateWellPipeStaticCenterline(RimEclipseWell* rimWell, + std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds) ; + static void calculateWellPipeDynamicCenterline(RimEclipseWell* rimWell, + size_t timeStepIndex, + std::vector< std::vector >& pipeBranchesCLCoords, + std::vector< std::vector >& pipeBranchesCellIds) ; + + +private: static void calculateWellPipeCenterlineFromWellFrame(const RigWellResultFrame& wellFrame, const RigEclipseCaseData* eclipseCaseData, bool isMultiSegmentWell, @@ -40,8 +47,6 @@ public: std::vector> & pipeBranchesCLCoords, std::vector> & pipeBranchesCellIds); - -private: static bool hasAnyResultCells(const std::vector &resBranches); static bool hasAnyValidDataCells(const RigWellResultBranch& branch); static void finishPipeCenterLine( std::vector< std::vector > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter ) ; From 6f48200bd354b3e3a3a9d9d393943c85e3f341b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 17:20:28 +0100 Subject: [PATCH 15/27] Made method protected --- ApplicationCode/ProjectDataModel/RimViewWindow.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.h b/ApplicationCode/ProjectDataModel/RimViewWindow.h index ec0d6a575c..25921fae10 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.h @@ -59,11 +59,6 @@ public: virtual QImage snapshotWindowContent() = 0; virtual void zoomAll() = 0; - - // Derived classes are not supposed to override this function. The intention is to always use m_showWindow - // as the objectToggleField for this class. This way the visibility of a widget being part of a composite widget - // can be controlled from the project tree using check box toggles - virtual caf::PdmFieldHandle* objectToggleField() override final; protected: void removeMdiWindowFromMdiArea(); @@ -79,6 +74,10 @@ protected: virtual void loadDataAndUpdate() = 0; ////////// + // Derived classes are not supposed to override this function. The intention is to always use m_showWindow + // as the objectToggleField for this class. This way the visibility of a widget being part of a composite widget + // can be controlled from the project tree using check box toggles + virtual caf::PdmFieldHandle* objectToggleField() override final; virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; virtual void initAfterRead() override; From b4308a857cc8db4f8410a3329fd926c7bcb800ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 20 Jan 2017 17:29:24 +0100 Subject: [PATCH 16/27] Added Comments --- .../ProjectDataModel/Flow/RimWellAllocationPlot.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 921ee8f2ea..951a3a95e5 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -103,6 +103,13 @@ void RimWellAllocationPlot::updateFromWell() simName = m_simulationWell->name(); wellResultFrame = &(m_simulationWell->wellResults()->wellResultFrame(1)); branchCount = static_cast( wellResultFrame->m_wellResultBranches.size()); + // // Todo : Use this instead, and use to calculate accumulated flow + // + // size_t timeStep = 0; // make field + // std::vector< std::vector > pipeBranchesCLCoords; + // std::vector< std::vector > pipeBranchesCellIds; + // m_simulationWell->calculateWellPipeDynamicCenterLine(timeStep, pipeBranchesCLCoords, pipeBranchesCellIds); + // branchCount = static_cast( pipeBranchesCLCoords.size()); } int existingTrackCount = static_cast(accumulatedWellFlowPlot()->trackCount()); @@ -120,11 +127,12 @@ void RimWellAllocationPlot::updateFromWell() accumulatedWellFlowPlot()->removeTrackByIndex(accumulatedWellFlowPlot()->trackCount()- 1); } + for (size_t brIdx = 0; brIdx < branchCount; ++brIdx) { RimWellLogTrack* plotTrack = accumulatedWellFlowPlot()->trackByIndex(brIdx); - plotTrack->setDescription(QString("Branch %1").arg(wellResultFrame->m_wellResultBranches[brIdx].m_ertBranchId)); + plotTrack->setDescription(QString("Branch %1").arg(brIdx+1)); } From 825c505443a4a90133f254ec8809bb7c226cf65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 23 Jan 2017 11:10:09 +0100 Subject: [PATCH 17/27] #1112, #1106 Added and removed fields to make the allocation plot have the needed data to do its calculation. Refacord the CenterLine calculation interface yet again to make it usable. --- .../RicShowWellAllocationPlotFeature.cpp | 2 +- .../Flow/RimWellAllocationPlot.cpp | 107 ++++++++++++------ .../Flow/RimWellAllocationPlot.h | 9 +- .../ReservoirDataModel/RigEclipseCaseData.cpp | 14 +++ .../ReservoirDataModel/RigEclipseCaseData.h | 3 +- .../RigSimulationWellCenterLineCalculator.cpp | 95 +++++++--------- .../RigSimulationWellCenterLineCalculator.h | 14 +-- .../RigSingleWellResultsData.cpp | 6 +- .../RigSingleWellResultsData.h | 4 +- 9 files changed, 148 insertions(+), 106 deletions(-) diff --git a/ApplicationCode/Commands/FlowCommands/RicShowWellAllocationPlotFeature.cpp b/ApplicationCode/Commands/FlowCommands/RicShowWellAllocationPlotFeature.cpp index 773904fc7a..8c8deffbdf 100644 --- a/ApplicationCode/Commands/FlowCommands/RicShowWellAllocationPlotFeature.cpp +++ b/ApplicationCode/Commands/FlowCommands/RicShowWellAllocationPlotFeature.cpp @@ -59,7 +59,7 @@ void RicShowWellAllocationPlotFeature::onActionTriggered(bool isChecked) RimFlowPlotCollection* flowPlotColl = RiaApplication::instance()->project()->mainPlotCollection->flowPlotCollection(); if (flowPlotColl) { - flowPlotColl->defaultPlot->setSimulationWell(eclWell); + flowPlotColl->defaultPlot->setFromSimulationWell(eclWell); flowPlotColl->defaultPlot->updateConnectedEditors(); // Make sure the summary plot window is created and visible diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 951a3a95e5..59ae7863da 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -29,7 +29,12 @@ #include "RimWellLogPlot.h" #include "RimWellLogTrack.h" #include "RigSingleWellResultsData.h" - +#include "RimEclipseResultCase.h" +#include "RimEclipseCellColors.h" +#include "RimFlowDiagSolution.h" +#include "RimEclipseCase.h" +#include "RigEclipseCaseData.h" +#include "RigSimulationWellCenterLineCalculator.h" CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot"); @@ -45,12 +50,18 @@ RimWellAllocationPlot::RimWellAllocationPlot() m_userName.uiCapability()->setUiReadOnly(true); CAF_PDM_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", ""); - CAF_PDM_InitFieldNoDefault(&m_simulationWell, "SimulationWell", "Simulation Well", "", "", ""); + + CAF_PDM_InitFieldNoDefault(&m_case, "CurveCase", "Case", "", "", ""); + m_case.uiCapability()->setUiTreeChildrenHidden(true); + + CAF_PDM_InitField(&m_timeStep, "PlotTimeStep", 0, "Time Step", "", "", ""); + CAF_PDM_InitField(&m_wellName, "WellName", QString("None"), "Well", "", "", ""); + CAF_PDM_InitFieldNoDefault(&m_flowDiagSolution, "FlowDiagSolution", "Flow Diag Solution", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_accumulatedWellFlowPlot, "AccumulatedWellFlowPlot", "Accumulated Well Flow", "", "", ""); m_accumulatedWellFlowPlot.uiCapability()->setUiHidden(true); - m_accumulatedWellFlowPlot = new RimWellLogPlot; + this->setAsPlotMdiWindow(); } @@ -69,9 +80,18 @@ RimWellAllocationPlot::~RimWellAllocationPlot() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellAllocationPlot::setSimulationWell(RimEclipseWell* simWell) +void RimWellAllocationPlot::setFromSimulationWell(RimEclipseWell* simWell) { - m_simulationWell = simWell; + RimEclipseView* eclView; + simWell->firstAncestorOrThisOfType(eclView); + RimEclipseResultCase* eclCase; + simWell->firstAncestorOrThisOfType(eclCase); + + m_case = eclCase; + m_wellName = simWell->wellResults()->m_wellName; + m_timeStep = eclView->currentTimeStep(); + + m_flowDiagSolution = eclView->cellResult()->flowDiagSolution(); updateFromWell(); } @@ -93,27 +113,31 @@ void RimWellAllocationPlot::deleteViewWidget() //-------------------------------------------------------------------------------------------------- void RimWellAllocationPlot::updateFromWell() { - QString simName = "None"; + if (!m_case) return; + + const RigSingleWellResultsData* wellResults = nullptr; + wellResults = m_case->reservoirData()->findWellResult(m_wellName); + + if (!wellResults) return; + int branchCount = 0; const RigWellResultFrame* wellResultFrame = nullptr; + std::vector< std::vector > pipeBranchesCLCoords; + std::vector< std::vector > pipeBranchesCellIds; - if (m_simulationWell && m_simulationWell->wellResults() )// && Timestep Ok ) - { - simName = m_simulationWell->name(); - wellResultFrame = &(m_simulationWell->wellResults()->wellResultFrame(1)); - branchCount = static_cast( wellResultFrame->m_wellResultBranches.size()); - // // Todo : Use this instead, and use to calculate accumulated flow - // - // size_t timeStep = 0; // make field - // std::vector< std::vector > pipeBranchesCLCoords; - // std::vector< std::vector > pipeBranchesCellIds; - // m_simulationWell->calculateWellPipeDynamicCenterLine(timeStep, pipeBranchesCLCoords, pipeBranchesCellIds); - // branchCount = static_cast( pipeBranchesCLCoords.size()); - } + RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(m_case->reservoirData(), + wellResults, + m_timeStep, + true, + true, + pipeBranchesCLCoords, + pipeBranchesCellIds); + + branchCount = static_cast(pipeBranchesCLCoords.size()); int existingTrackCount = static_cast(accumulatedWellFlowPlot()->trackCount()); - accumulatedWellFlowPlot()->setDescription("Accumulated Well Flow (" + simName + ")"); + accumulatedWellFlowPlot()->setDescription("Accumulated Well Flow (" + m_wellName + ")"); int neededExtraTrackCount = branchCount - existingTrackCount; for (int etc = 0; etc < neededExtraTrackCount; ++etc) @@ -136,7 +160,9 @@ void RimWellAllocationPlot::updateFromWell() } - setDescription("Well Allocation (" + simName + ")"); + // Todo: Calculate curve data + + setDescription("Well Allocation (" + m_wellName + ")"); accumulatedWellFlowPlot()->updateConnectedEditors(); } @@ -170,29 +196,44 @@ QList RimWellAllocationPlot::calculateValueOptions(const { QList options; - if (fieldNeedingOptions == &m_simulationWell) + if (fieldNeedingOptions == &m_wellName) { - RimView* activeView = RiaApplication::instance()->activeReservoirView(); - RimEclipseView* eclView = dynamic_cast(activeView); - - if (eclView && eclView->wellCollection()) + std::set sortedWellNames; + if ( m_case ) { - RimEclipseWellCollection* coll = eclView->wellCollection(); + const cvf::Collection& wellRes = m_case->reservoirData()->wellResults(); - caf::PdmChildArrayField& eclWells = coll->wells; - - QIcon simWellIcon(":/Well.png"); - for (RimEclipseWell* eclWell : eclWells) + for ( size_t wIdx = 0; wIdx < wellRes.size(); ++wIdx ) { - options.push_back(caf::PdmOptionItemInfo(eclWell->name(), eclWell, false, simWellIcon)); + sortedWellNames.insert(wellRes[wIdx]->m_wellName); } } + QIcon simWellIcon(":/Well.png"); + for ( const QString& wname: sortedWellNames ) + { + options.push_back(caf::PdmOptionItemInfo(wname, wname, false, simWellIcon)); + } + if (options.size() == 0) { options.push_front(caf::PdmOptionItemInfo("None", nullptr)); } } + else if (fieldNeedingOptions == &m_timeStep) + { + QStringList timeStepNames; + + if (m_case) + { + timeStepNames = m_case->timeStepStrings(); + } + + for (int i = 0; i < timeStepNames.size(); i++) + { + options.push_back(caf::PdmOptionItemInfo(timeStepNames[i], i)); + } + } return options; } @@ -209,7 +250,7 @@ void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedF { updateMdiWindowTitle(); } - else if (changedField == &m_simulationWell) + else if (changedField == &m_wellName) { updateFromWell(); } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index ea048c79ee..07ef43df1f 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -30,6 +30,7 @@ class RiuWellAllocationPlot; class RimEclipseWell; class RimWellLogPlot; +class RimEclipseResultCase; namespace caf { class PdmOptionItemInfo; @@ -48,7 +49,7 @@ public: RimWellAllocationPlot(); virtual ~RimWellAllocationPlot(); - void setSimulationWell(RimEclipseWell* simWell); + void setFromSimulationWell(RimEclipseWell* simWell); void setDescription(const QString& description); QString description() const; @@ -81,9 +82,11 @@ private: private: caf::PdmField m_showPlotTitle; caf::PdmField m_userName; - //caf::PdmField m_showAccWellFlowPlot; - caf::PdmPtrField m_simulationWell; + caf::PdmPtrField m_case; + caf::PdmField m_wellName; + caf::PdmField m_timeStep; + caf::PdmPtrField m_flowDiagSolution; QPointer m_wellAllocationPlotWidget; diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp index 9c933c0472..ebb0c5f7f8 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp @@ -262,6 +262,20 @@ void RigEclipseCaseData::setWellResults(const cvf::Collectionm_wellName == wellName) return m_wellResults[wIdx].p(); + } + + return nullptr; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h index 668e5c54bf..ac363ab2d7 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h @@ -82,7 +82,8 @@ public: void setWellResults(const cvf::Collection& data); const cvf::Collection& wellResults() { return m_wellResults; } - + const RigSingleWellResultsData* findWellResult(QString wellName) const; + const cvf::UByteArray* wellCellsInGrid(size_t gridIndex); const cvf::UIntArray* gridCellToResultWellIndex(size_t gridIndex); diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp index 2282d97846..e8b6d0d5d5 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.cpp @@ -38,39 +38,7 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeStaticCenterline(Ri std::vector< std::vector >& pipeBranchesCLCoords, std::vector< std::vector >& pipeBranchesCellIds) { - bool isAutoDetectBranches = false; - RigEclipseCaseData* eclipseCaseData = NULL; - RigSingleWellResultsData* wellResults = NULL; - - { - CVF_ASSERT(rimWell); - RimEclipseView* eclipseView; - rimWell->firstAncestorOrThisOfType(eclipseView); - CVF_ASSERT(eclipseView); - - isAutoDetectBranches = eclipseView->wellCollection()->isAutoDetectingBranches(); - eclipseCaseData = eclipseView->eclipseCase()->reservoirData(); - wellResults = rimWell->wellResults(); - } - - // Make sure we have computed the static representation of the well - if (wellResults->m_staticWellCells.m_wellResultBranches.size() == 0) - { - wellResults->computeStaticWellCellPath(); - } - - const RigWellResultFrame& staticWellFrame = wellResults->m_staticWellCells; - bool isMultiSegmentWell = wellResults->isMultiSegmentWell(); - bool useAllCellCenters = rimWell->isUsingCellCenterForPipe(); - - calculateWellPipeCenterlineFromWellFrame(staticWellFrame, - eclipseCaseData, - isMultiSegmentWell, - isAutoDetectBranches, - useAllCellCenters, - pipeBranchesCLCoords, - pipeBranchesCellIds); - return; + calculateWellPipeDynamicCenterline(rimWell, -1, pipeBranchesCLCoords, pipeBranchesCellIds); } @@ -82,31 +50,23 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeDynamicCenterline(R std::vector< std::vector >& pipeBranchesCLCoords, std::vector< std::vector >& pipeBranchesCellIds) { - bool isAutoDetectBranches = false; - RigEclipseCaseData* eclipseCaseData = NULL; - RigSingleWellResultsData* wellResults = NULL; + CVF_ASSERT(rimWell); - { - CVF_ASSERT(rimWell); - RimEclipseView* eclipseView; - rimWell->firstAncestorOrThisOfType(eclipseView); - CVF_ASSERT(eclipseView); + RigSingleWellResultsData* wellResults = rimWell->wellResults(); - isAutoDetectBranches = eclipseView->wellCollection()->isAutoDetectingBranches(); - eclipseCaseData = eclipseView->eclipseCase()->reservoirData(); - wellResults = rimWell->wellResults(); + RimEclipseView* eclipseView; + rimWell->firstAncestorOrThisOfType(eclipseView); - if ( !wellResults || !wellResults->hasWellResult(timeStepIndex) ) return; - } - + CVF_ASSERT(eclipseView); - const RigWellResultFrame& wellFrame = wellResults->wellResultFrame(timeStepIndex); - bool isMultiSegmentWell = wellResults->isMultiSegmentWell(); - bool useAllCellCenters = rimWell->isUsingCellCenterForPipe(); + RigEclipseCaseData* eclipseCaseData = eclipseView->eclipseCase()->reservoirData(); + bool isAutoDetectBranches = eclipseView->wellCollection()->isAutoDetectingBranches(); - calculateWellPipeCenterlineFromWellFrame(wellFrame, - eclipseCaseData, - isMultiSegmentWell, + bool useAllCellCenters = rimWell->isUsingCellCenterForPipe(); + + calculateWellPipeCenterlineFromWellFrame(eclipseCaseData, + wellResults, + static_cast(timeStepIndex), isAutoDetectBranches, useAllCellCenters, pipeBranchesCLCoords, @@ -118,14 +78,37 @@ void RigSimulationWellCenterLineCalculator::calculateWellPipeDynamicCenterline(R /// The returned CellIds is one less than the number of centerline points, /// and are describing the lines between the points, starting with the first line //-------------------------------------------------------------------------------------------------- -void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(const RigWellResultFrame &wellFrame, - const RigEclipseCaseData* eclipseCaseData, - bool isMultiSegmentWell, +void RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(const RigEclipseCaseData* eclipseCaseData, + const RigSingleWellResultsData* wellResults, + int timeStepIndex, bool isAutoDetectBranches, bool useAllCellCenters, std::vector> &pipeBranchesCLCoords, std::vector> &pipeBranchesCellIds) { + if ( !wellResults) return; + if ( timeStepIndex >= 0 && !wellResults->hasWellResult(timeStepIndex) ) return; + + const RigWellResultFrame* wellFramePtr = nullptr; + + if (timeStepIndex < 0) + { + // Make sure we have computed the static representation of the well + if (wellResults->m_staticWellCells.m_wellResultBranches.size() == 0) + { + wellResults->computeStaticWellCellPath(); + } + + wellFramePtr = &wellResults->m_staticWellCells; + } + else + { + wellFramePtr = &(wellResults->wellResultFrame(timeStepIndex)); + } + + const RigWellResultFrame& wellFrame = *wellFramePtr; + bool isMultiSegmentWell = wellResults->isMultiSegmentWell(); + // Initialize the return arrays pipeBranchesCLCoords.clear(); pipeBranchesCellIds.clear(); diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h index fe0b00b177..00d1c88305 100644 --- a/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCenterLineCalculator.h @@ -38,14 +38,14 @@ public: std::vector< std::vector >& pipeBranchesCellIds) ; -private: - static void calculateWellPipeCenterlineFromWellFrame(const RigWellResultFrame& wellFrame, - const RigEclipseCaseData* eclipseCaseData, - bool isMultiSegmentWell, - bool isAutoDetectBranches, + static void calculateWellPipeCenterlineFromWellFrame(const RigEclipseCaseData* eclipseCaseData, + const RigSingleWellResultsData* wellResults, + int timeStepIndex, + bool isAutoDetectBranches, bool useAllCellCenters, - std::vector> & pipeBranchesCLCoords, - std::vector> & pipeBranchesCellIds); + std::vector> &pipeBranchesCLCoords, + std::vector> &pipeBranchesCellIds); +private: static bool hasAnyResultCells(const std::vector &resBranches); static bool hasAnyValidDataCells(const RigWellResultBranch& branch); diff --git a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.cpp index b3af8e7f06..4cb37ea4e4 100644 --- a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.cpp @@ -121,7 +121,7 @@ bool operator== (const RigWellResultPoint& p1, const RigWellResultPoint& p2) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RigSingleWellResultsData::computeStaticWellCellPath() +void RigSingleWellResultsData::computeStaticWellCellPath() const { if (m_wellCellsTimeSteps.size() == 0) return; @@ -133,7 +133,7 @@ void RigSingleWellResultsData::computeStaticWellCellPath() for (size_t bIdx = 0; bIdx < m_wellCellsTimeSteps[0].m_wellResultBranches.size(); ++bIdx) { int branchErtId = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_ertBranchId; - std::vector& frameCells = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_branchResultPoints; + const std::vector& frameCells = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_branchResultPoints; std::list< RigWellResultPoint >& branch = staticWellBranches[branchErtId]; @@ -152,7 +152,7 @@ void RigSingleWellResultsData::computeStaticWellCellPath() for (size_t bIdx = 0; bIdx < m_wellCellsTimeSteps[tIdx].m_wellResultBranches.size(); ++bIdx) { int branchId = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_ertBranchId; - std::vector& resBranch = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_branchResultPoints; + const std::vector& resBranch = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_branchResultPoints; std::list< RigWellResultPoint >& stBranch = staticWellBranches[branchId]; std::list< RigWellResultPoint >::iterator sEndIt; diff --git a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h index fc07ac13b7..c03179d870 100644 --- a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h +++ b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h @@ -127,7 +127,7 @@ public: const RigWellResultFrame& wellResultFrame(size_t resultTimeStepIndex) const; - void computeStaticWellCellPath(); + void computeStaticWellCellPath() const ; void computeMappingFromResultTimeIndicesToWellTimeIndices(const std::vector& resultTimes); @@ -137,6 +137,6 @@ public: std::vector m_resultTimeStepIndexToWellTimeStepIndex; // Well result timesteps may differ from result timesteps std::vector< RigWellResultFrame > m_wellCellsTimeSteps; - RigWellResultFrame m_staticWellCells; + mutable RigWellResultFrame m_staticWellCells; }; From d71476b1aa3ce0a5227449dd3b692fe481c7909c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sat, 21 Jan 2017 12:26:21 +0100 Subject: [PATCH 18/27] System : Improved organization of ThirdParty libraries --- ApplicationCode/CMakeLists.txt | 8 ++------ CMakeLists.txt | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index 17dcf17d52..1cddba839e 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -289,9 +289,7 @@ endif() set( LINK_LIBRARIES - custom-opm-parser - custom-opm-flowdiagnostics - custom-opm-flowdiag-app + ${OPM_LIBRARIES} WellPathImportSsihub @@ -303,14 +301,12 @@ set( LINK_LIBRARIES ${ERT_LIBRARIES} - NRLib + ${THIRD_PARTY_LIBRARIES} ${OPENGL_LIBRARIES} ${QT_LIBRARIES} ${RI_BOOST_LIBRARIES} - - Qwt ) set( EXTERNAL_LINK_LIBRARIES ${ERT_LIBRARY_LIST} ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bf1ff5e2f..158efc45c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,13 +185,14 @@ else() ecl_well ert_geometry ert_util + ert_utilxx ) if (MSVC) set_property(TARGET ${ERT_LIBRARIES} ecl_lfs - PROPERTY FOLDER "ERT" + PROPERTY FOLDER "Thirdparty/ERT" ) endif() @@ -210,12 +211,32 @@ add_subdirectory(ThirdParty/custom-opm-parser/custom-opm-parser-tests) add_subdirectory(ThirdParty/custom-opm-flowdiagnostics) add_subdirectory(ThirdParty/custom-opm-flowdiag-app) +list(APPEND OPM_LIBRARIES + custom-opm-parser + custom-opm-flowdiagnostics + custom-opm-flowdiag-app +) + +set_property(TARGET + ${OPM_LIBRARIES} + PROPERTY FOLDER "Thirdparty/OPM" +) + +set_property(TARGET + opm-parser-tests + PROPERTY FOLDER "Thirdparty/OPM" +) + ################################################################################ # NRLib ################################################################################ add_subdirectory(ThirdParty/NRLib) +list(APPEND THIRD_PARTY_LIBRARIES + NRLib +) + ################################################################################ # Qt @@ -241,6 +262,15 @@ find_package( OpenGL ) add_subdirectory(ThirdParty/Qwt/src) +list(APPEND THIRD_PARTY_LIBRARIES + Qwt +) + +set_property(TARGET + ${THIRD_PARTY_LIBRARIES} + PROPERTY FOLDER "Thirdparty" +) + ################################################################################ # Vizualization Framework ################################################################################ From 699c2a110363a5a483f2289db6d74ebba02132d2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sat, 21 Jan 2017 12:36:14 +0100 Subject: [PATCH 19/27] #1116 Added nightcharts pie plotting library --- CMakeLists.txt | 11 + ThirdParty/nightcharts/CMakeLists.txt | 16 + ThirdParty/nightcharts/README.md | 41 ++ ThirdParty/nightcharts/nightcharts.cpp | 469 +++++++++++++++++++ ThirdParty/nightcharts/nightcharts.h | 88 ++++ ThirdParty/nightcharts/nightcharts.pri | 3 + ThirdParty/nightcharts/nightchartswidget.cpp | 44 ++ ThirdParty/nightcharts/nightchartswidget.h | 24 + 8 files changed, 696 insertions(+) create mode 100644 ThirdParty/nightcharts/CMakeLists.txt create mode 100644 ThirdParty/nightcharts/README.md create mode 100644 ThirdParty/nightcharts/nightcharts.cpp create mode 100644 ThirdParty/nightcharts/nightcharts.h create mode 100644 ThirdParty/nightcharts/nightcharts.pri create mode 100644 ThirdParty/nightcharts/nightchartswidget.cpp create mode 100644 ThirdParty/nightcharts/nightchartswidget.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 158efc45c5..222e53cb49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -271,6 +271,17 @@ set_property(TARGET PROPERTY FOLDER "Thirdparty" ) +################################################################################ +# Nightcharts +################################################################################ + +add_subdirectory(ThirdParty/nightcharts) + +list(APPEND THIRD_PARTY_LIBRARIES + nightcharts +) + + ################################################################################ # Vizualization Framework ################################################################################ diff --git a/ThirdParty/nightcharts/CMakeLists.txt b/ThirdParty/nightcharts/CMakeLists.txt new file mode 100644 index 0000000000..287617a83d --- /dev/null +++ b/ThirdParty/nightcharts/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required (VERSION 2.8) + +project (nightcharts) + +list (APPEND MAIN_SOURCE_FILES + nightcharts.h + nightcharts.cpp + nightchartswidget.h + nightchartswidget.cpp +) + +add_library( ${PROJECT_NAME} + STATIC + ${MAIN_SOURCE_FILES} +) + diff --git a/ThirdParty/nightcharts/README.md b/ThirdParty/nightcharts/README.md new file mode 100644 index 0000000000..9640923ce5 --- /dev/null +++ b/ThirdParty/nightcharts/README.md @@ -0,0 +1,41 @@ +# Nightcharts + +This class includes a drawing histogram, pies and pseudo 3D pies. +It has very simple API and high level usability. +http://qt-apps.org/content/show.php?action=content&content=132560 + +Licensed under LGPL 2.1 + +Example : + + + void MainWindow::paintEvent(QPaintEvent e*) + { + QWidget::paintEvent(e); + QPainter painter; + QFont font; + painter.begin(this); + Nightcharts PieChart; + PieChart.setType(Nightcharts::DPie);//{Histogramm,Pie,DPie}; + PieChart.setLegendType(Nightcharts::Round);//{Round,Vertical} + PieChart.setCords(100,100,this->width()/1.5,this->height()/1.5); + PieChart.addPiece("Item1",QColor(200,10,50),34); + PieChart.addPiece("Item2",Qt::green,27); + PieChart.addPiece("Item3",Qt::cyan,14); + PieChart.addPiece("Item4",Qt::yellow,7); + PieChart.addPiece("Item5",Qt::blue,4); + PieChart.draw(&painter); + PieChart.drawLegend(&painter); + } + +![3DPie example](http://qt-apps.org/CONTENT/content-pre1/132560-1.PNG) + +### How to use + + - Check out in any location (or add as a submodule) + - Write into Your main .pro file: + + ``` + include("path/to/nightcharts/nightcharts.pri") + + ``` diff --git a/ThirdParty/nightcharts/nightcharts.cpp b/ThirdParty/nightcharts/nightcharts.cpp new file mode 100644 index 0000000000..fffbc7c388 --- /dev/null +++ b/ThirdParty/nightcharts/nightcharts.cpp @@ -0,0 +1,469 @@ +/* + * NightCharts + * Copyright (C) 2010 by Alexander A. Avdonin, Artem N. Ivanov / ITGears Co. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Please contact gordos.kund@gmail.com with any questions on this license. + */ + +#define _USE_MATH_DEFINES +#include "nightcharts.h" + +Nightcharts::Nightcharts()//QPainter *painter) + +{ + font.setFamily("verdana"); + font.setPixelSize(15); + //painter = painter; + //painter->setFont(font); + ctype = Nightcharts::Dpie; + cltype = Nightcharts::Vertical; + cX = 0; + cY = 0; + cW = 100; + cH = 100; + lX = cX+cW+20; + lY = cY; + shadows = true; +} +Nightcharts::~Nightcharts() +{ + pieces.clear(); +} + +int Nightcharts::addPiece(QString name,Qt::GlobalColor color,float Percentage) +{ + this->nPiece++; + + pieceNC piece; + piece.addName(name); + piece.setColor(color); + piece.setPerc(Percentage); + pieces.append(piece); + + return 0; +} +int Nightcharts::addPiece(QString name, QColor color, float Percentage) +{ + this->nPiece++; + pieceNC piece; + piece.addName(name); + piece.setColor(color); + piece.setPerc(Percentage); + pieces.append(piece); + + return 0; +} +int Nightcharts::setCords(double x, double y, double w, double h) +{ + this->cX = x; + this->cY = y; + this->cW = w; + this->cH = h; + this->lX = cX+cW+20; + this->lY = cY; + + return 0; +} +int Nightcharts::setLegendCords(double x, double y) +{ + this->lX = x; + this->lY = y; + + return 0; +} + +int Nightcharts::setType(Nightcharts::type t) +{ + this->ctype = t; + + return 0; +} + +int Nightcharts::setLegendType(Nightcharts::legend_type t) +{ + this->cltype = t; + + return 0; +} +int Nightcharts::setFont(QFont f) +{ + this->font = f; + + return 0; +} + +int Nightcharts::setShadows(bool ok) +{ + this->shadows = ok; + + return 0; +} + +int Nightcharts::draw(QPainter *painter) +{ + painter->setRenderHint(QPainter::Antialiasing); + painter->setPen(Qt::NoPen); + if (this->ctype==Nightcharts::Pie) + { + pW = 0; + double pdegree = 0; + + //Options + QLinearGradient gradient(cX+0.5*cW,cY,cX+0.5*cW,cY+cH*2.5); + gradient.setColorAt(1,Qt::black); + + + //Draw + //pdegree = (360/100)*pieces[i].pPerc; + if (shadows) + { + double sumangle = 0; + for (int i=0;isetBrush(Qt::darkGray); + painter->drawPie(cX,cY+pW+5,cW,cH,palpha*16,sumangle*16); + } + + QPen pen; + pen.setWidth(2); + + for (int i=0;isetBrush(gradient); + pen.setColor(pieces[i].rgbColor); + painter->setPen(pen); + pdegree = 3.6*pieces[i].pPerc; + painter->drawPie(cX,cY,cW,cH,palpha*16,pdegree*16); + palpha += pdegree; + } + } + else if (this->ctype==Nightcharts::Dpie) + { + pW = 50; + double pdegree = 0; + QPointF p; + + QLinearGradient gradient(cX-0.5*cW,cY+cH/2,cX+1.5*cW,cY+cH/2); + gradient.setColorAt(0,Qt::black); + gradient.setColorAt(1,Qt::white); + QLinearGradient gradient_side(cX,cY+cH,cX+cW,cY+cH); + gradient_side.setColorAt(0,Qt::black); + + double sumangle = 0; + for (int i=0;isetBrush(Qt::darkGray); + painter->drawPie(cX,cY+pW+5,cW,cH,palpha*16,sumangle*16); + } + int q = GetQuater(palpha+sumangle); + + if (q ==2 || q==3) + { + QPointF p = GetPoint(palpha+sumangle); + QPointF points[4] = + { + QPointF(p.x(),p.y()), + QPointF(p.x(),p.y()+pW), + QPointF(cX+cW/2,cY+cH/2+pW), + QPointF(cX+cW/2,cY+cH/2) + }; + gradient_side.setColorAt(1,pieces[pieces.size()-1].rgbColor); + painter->setBrush(gradient_side); + painter->drawPolygon(points,4); + } + p = GetPoint(palpha); + q = GetQuater(palpha); + if (q ==1 || q==4) + { + QPointF points[4] = + { + QPointF(p.x(),p.y()), + QPointF(p.x(),p.y()+pW), + QPointF(cX+cW/2,cY+cH/2+pW), + QPointF(cX+cW/2,cY+cH/2) + }; + gradient_side.setColorAt(1,pieces[0].rgbColor); + painter->setBrush(gradient_side); + painter->drawPolygon(points,4); + } + + for (int i=0;isetBrush(gradient); + pdegree = 3.6*pieces[i].pPerc; + painter->drawPie(cX,cY,cW,cH,palpha*16,pdegree*16); + + double a_ = Angle360(palpha); + int q_ = GetQuater(palpha); + + palpha += pdegree; + + double a = Angle360(palpha); + int q = GetQuater(palpha); + + QPainterPath path; + p = GetPoint(palpha); + + if((q == 3 || q == 4) && (q_ == 3 || q_ == 4)) + { + // 1) + if (a>a_) + { + QPointF p_old = GetPoint(palpha-pdegree); + path.moveTo(p_old.x()-1,p_old.y()); + path.arcTo(cX,cY,cW,cH,palpha-pdegree,pdegree); + path.lineTo(p.x(),p.y()+pW); + path.arcTo(cX,cY+pW,cW,cH,palpha,-pdegree); + } + // 2) + else + { + path.moveTo(cX,cY+cH/2); + path.arcTo(cX,cY,cW,cH,180,Angle360(palpha)-180); + path.lineTo(p.x(),p.y()+pW); + path.arcTo(cX,cY+pW,cW,cH,Angle360(palpha),-Angle360(palpha)+180); + path.lineTo(cX,cY+cH/2); + + path.moveTo(p.x(),p.y()); + path.arcTo(cX,cY,cW,cH,palpha-pdegree,360-Angle360(palpha-pdegree)); + path.lineTo(cX+cW,cY+cH/2+pW); + path.arcTo(cX,cY+pW,cW,cH,0,-360+Angle360(palpha-pdegree)); + } + + } + // 3) + else if((q == 3 || q == 4) && (q_ == 1 || q_ == 2) && a>a_ ) + { + path.moveTo(cX,cY+cH/2); + path.arcTo(cX,cY,cW,cH,180,Angle360(palpha)-180); + path.lineTo(p.x(),p.y()+pW); + path.arcTo(cX,cY+pW,cW,cH,Angle360(palpha),-Angle360(palpha)+180); + path.lineTo(cX,cY+cH/2); + } + // 4) + else if((q == 1 || q == 2) && (q_ == 3 || q_ == 4) && asetBrush(gradient_side); + painter->drawPath(path); + } + } + } + else if (this->ctype==Nightcharts::Histogramm) + { + double pDist = 15; + double pW = (cW-(pieces.size())*pDist)/pieces.size(); + + QLinearGradient gradient(cX+cW/2,cY,cX+cW/2,cY+cH); + gradient.setColorAt(0,Qt::black); + QPen pen; + pen.setWidth(3); + + for (int i=0;isetPen(Qt::NoPen); + painter->setBrush(Qt::darkGray); + painter->drawRect(cX+pDist+i*(pW + pDist)-pDist/2,cY+cH-1,pW,-cH/100*pieces[i].pPerc+pDist/2-5); + } + gradient.setColorAt(1,pieces[i].rgbColor); + painter->setBrush(gradient); + pen.setColor(pieces[i].rgbColor); + painter->setPen(pen); + painter->drawRect(cX+pDist+i*(pW + pDist),cY+cH,pW,-cH/100*pieces[i].pPerc-5); + QString label = QString::number(pieces[i].pPerc)+"%"; + painter->setPen(Qt::SolidLine); + painter->drawText(cX+pDist+i*(pW + pDist)+pW/2-painter->fontMetrics().width(label)/2,cY+cH-cH/100*pieces[i].pPerc-painter->fontMetrics().height()/2,label); + } + painter->setPen(Qt::SolidLine); + for (int i=1;i<10;i++) + { + painter->drawLine(cX-3,cY+cH/10*i,cX+3,cY+cH/10*i); //äåëåíèÿ ïî îñè Y + //painter->drawText(cX-20,cY+cH/10*i,QString::number((10-i)*10)+"%"); + } + painter->drawLine(cX,cY+cH,cX,cY); //îñü Y + painter->drawLine(cX,cY,cX+4,cY+10); //ñòðåëêè + painter->drawLine(cX,cY,cX-4,cY+10); + painter->drawLine(cX,cY+cH,cX+cW,cY+cH); //îñü Õ + + } + return 0; +} + +void Nightcharts::drawLegend(QPainter *painter) +{ + //double ptext = 25; + double angle = palpha; + painter->setPen(Qt::SolidLine); + + switch(cltype) + { + /*case Nightcharts::Horizontal: + { + int dist = 5; + painter->setBrush(Qt::white); + float x = cX; + float y = cY+cH+20+dist; + //painter->drawRoundRect(cX+cW+20,cY,dist*2+200,pieces.size()*(fontmetr.height()+2*dist)+dist,15,15); + for (int i=0;isetBrush(pieces[i].rgbColor); + x += fontmetr.height()+2*dist; + if (i%3 == 0) + { + x = cX; + y += dist+fontmetr.height(); + } + painter->drawRect(x,y,fontmetr.height(),fontmetr.height()); + QString label = pieces[i].pname + " - " + QString::number(pieces[i].pPerc)+"%"; + painter->drawText(x+fontmetr.height()+dist,y+fontmetr.height()/2+dist,label); + x += fontmetr.width(label); + } + break; + }*/ + case Nightcharts::Vertical: + { + int dist = 5; + painter->setBrush(Qt::white); + //painter->drawRoundRect(cX+cW+20,cY,dist*2+200,pieces.size()*(painter->fontMetrics().height()+2*dist)+dist,15,15); + for (int i=pieces.size()-1;i>=0;i--) + { + painter->setBrush(pieces[i].rgbColor); + float x = lX+dist; + float y = lY+dist+i*(painter->fontMetrics().height()+2*dist); + painter->drawRect(x,y,painter->fontMetrics().height(),painter->fontMetrics().height()); + painter->drawText(x+painter->fontMetrics().height()+dist,y+painter->fontMetrics().height()/2+dist,pieces[i].pname + " - " + QString::number(pieces[i].pPerc)+"%"); + } + break; + } + case Nightcharts::Round: + for (int i=pieces.size()-1;i>=0;i--) + { + float len = 100; + double pdegree = 3.6*pieces[i].pPerc; + angle -= pdegree/2; + QPointF p = GetPoint(angle); + QPointF p_ = GetPoint(angle, cW+len,cH+len); + int q = GetQuater(angle); + if (q == 3 || q == 4) + { + p.setY(p.y()+pW/2); + p_.setY(p_.y()+pW/2); + } + painter->drawLine(p.x(),p.y(),p_.x(),p_.y()); + QString label = pieces[i].pname + " - " + QString::number(pieces[i].pPerc)+"%"; + float recW = painter->fontMetrics().width(label)+10; + float recH = painter->fontMetrics().height()+10; + p_.setX(p_.x()-recW/2 + recW/2*cos(angle*M_PI/180)); + p_.setY(p_.y()+recH/2 + recH/2*sin(angle*M_PI/180)); + painter->setBrush(Qt::white); + painter->drawRoundRect(p_.x() ,p_.y(), recW, -recH); + painter->drawText(p_.x()+5, p_.y()-recH/2+5, label); + angle -= pdegree/2; + } + break; + } +} + +QPointF Nightcharts::GetPoint(double angle, double R1, double R2) +{ + if (R1 == 0 && R2 == 0) + { + R1 = cW; + R2 = cH; + } + QPointF point; + double x = R1/2*cos(angle*M_PI/180); + x+=cW/2+cX; + double y = -R2/2*sin(angle*M_PI/180); + y+=cH/2+cY; + point.setX(x); + point.setY(y); + return point; +} + +int Nightcharts::GetQuater(double angle) +{ + angle = Angle360(angle); + + if(angle>=0 && angle<90) + return 1; + if(angle>=90 && angle<180) + return 2; + if(angle>=180 && angle<270) + return 3; + if(angle>=270 && angle<360) + return 4; +} + +double Nightcharts::Angle360(double angle) +{ + int i = (int)angle; + double delta = angle - i; + return (i%360 + delta); +} + +pieceNC::pieceNC() +{ +} +void pieceNC::addName(QString name) +{ + pname = name; +} +void pieceNC::setColor(Qt::GlobalColor color) +{ + rgbColor = color; +} +void pieceNC::setColor(QColor color) +{ + rgbColor = color; +} + +void pieceNC::setPerc(float Percentage) +{ + pPerc = Percentage; +} + +int Nightcharts::pieceCount() +{ + return pieces.count(); +} diff --git a/ThirdParty/nightcharts/nightcharts.h b/ThirdParty/nightcharts/nightcharts.h new file mode 100644 index 0000000000..c49e130179 --- /dev/null +++ b/ThirdParty/nightcharts/nightcharts.h @@ -0,0 +1,88 @@ +/* + * NightCharts + * Copyright (C) 2010 by Alexander A. Avdonin, Artem N. Ivanov / ITGears Co. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Please contact gordos.kund@gmail.com with any questions on this license. + */ +#ifndef NIGHTCHARTS_H +#define NIGHTCHARTS_H +#define PerConst = 3.6; +#include +#include +#include +#include +#include +#include + +class pieceNC +{ +public: + explicit pieceNC(); + void addName(QString name); + void setColor(Qt::GlobalColor); + void setColor(QColor color); + void setPerc(float Percentage); + + QString pname; + QColor rgbColor; + float pPerc; + +private: + +}; + +class Nightcharts +{ +public: + + explicit Nightcharts(); + ~Nightcharts(); + enum type { Histogramm , Pie, Dpie }; + enum legend_type{ /*Horizontal,*/ Vertical, Round }; + int addPiece(QString name,Qt::GlobalColor,float Percentage); + int addPiece(QString name,QColor, float Percentage); + int setCords(double x, double y, double w, double h); + int setLegendCords(double x, double y); + int setType(Nightcharts::type t); + int setLegendType(Nightcharts::legend_type t); + int setShadows(bool ok = true); + int setFont(QFont f); + int draw(QPainter *painter); + void drawLegend(QPainter *painter); + int pieceCount(); + double palpha; + +private: + double cX,cY,cW,cH,pW,lX,lY; + int nPiece; + bool shadows; + QVector pieces; + int ctype, cltype; + QFont font; + //QPainter *cpainter; + QPointF GetPoint(double angle, double R1 = 0, double R2 = 0); + int GetQuater(double angle); + double Angle360(double angle); + + +signals: + +public slots: + +}; + + +#endif // NIGHTCHARTS_H diff --git a/ThirdParty/nightcharts/nightcharts.pri b/ThirdParty/nightcharts/nightcharts.pri new file mode 100644 index 0000000000..0978360033 --- /dev/null +++ b/ThirdParty/nightcharts/nightcharts.pri @@ -0,0 +1,3 @@ +INCLUDEPATH+=$$PWD +SOURCES+=$$PWD/nightcharts.cpp +HEADERS+=$$PWD/nightcharts.h diff --git a/ThirdParty/nightcharts/nightchartswidget.cpp b/ThirdParty/nightcharts/nightchartswidget.cpp new file mode 100644 index 0000000000..d476c5e155 --- /dev/null +++ b/ThirdParty/nightcharts/nightchartswidget.cpp @@ -0,0 +1,44 @@ +#include "nightchartswidget.h" +#include "nightcharts.h" +NightchartsWidget::NightchartsWidget(QWidget *parent) : + QWidget(parent) +{ + clear(); +} +void NightchartsWidget::setType(Nightcharts::type t) +{ + _chart.setType(t); +} +void NightchartsWidget::clear() +{ + _chart = Nightcharts(); + _chart.setType(Nightcharts::Histogramm); + _chart.setLegendType(Nightcharts::Vertical); + + _margin_left = 16; + _margin_top = 16; + +} + +void NightchartsWidget::paintEvent(QPaintEvent * e) +{ + QWidget::paintEvent(e); + if(!_chart.pieceCount()) return ; + QPainter painter; + QFont font; + painter.begin(this); + int w = (this->width() - _margin_left - 150); + int h = (this->height() - _margin_top - 100); + int size = (w +#include +#include "nightcharts.h" +class NightchartsWidget : public QWidget +{ + Q_OBJECT +public: + explicit NightchartsWidget(QWidget *parent = 0); + void addItem(QString name, QColor color, float value); + void setType(Nightcharts::type type); + void clear(); +protected: + virtual void paintEvent(QPaintEvent * e); +private: + Nightcharts _chart; + int _margin_left; + int _margin_top; + +}; + +#endif // NIGHTCHARTSWIDGET_H From 09dacf1928c486a52017b75b6a18896a1334999c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sat, 21 Jan 2017 12:38:48 +0100 Subject: [PATCH 20/27] System : Set solution folder property at correct location --- CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 222e53cb49..1a0e668cd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,10 +266,6 @@ list(APPEND THIRD_PARTY_LIBRARIES Qwt ) -set_property(TARGET - ${THIRD_PARTY_LIBRARIES} - PROPERTY FOLDER "Thirdparty" -) ################################################################################ # Nightcharts @@ -282,6 +278,14 @@ list(APPEND THIRD_PARTY_LIBRARIES ) +################################################################################ +# Thirdparty libraries are put in ThirdParty solution folder +################################################################################ +set_property(TARGET + ${THIRD_PARTY_LIBRARIES} + PROPERTY FOLDER "Thirdparty" +) + ################################################################################ # Vizualization Framework ################################################################################ From 2511a59f8ae9183b3a6b7d5660da5f43ec57713d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 23 Jan 2017 08:49:14 +0100 Subject: [PATCH 21/27] #1116 Added RiuNightchartsWidget --- .../UserInterface/CMakeLists_files.cmake | 3 + .../UserInterface/RiuNightchartsWidget.cpp | 79 +++++++++++++++++++ .../UserInterface/RiuNightchartsWidget.h | 48 +++++++++++ 3 files changed, 130 insertions(+) create mode 100644 ApplicationCode/UserInterface/RiuNightchartsWidget.cpp create mode 100644 ApplicationCode/UserInterface/RiuNightchartsWidget.h diff --git a/ApplicationCode/UserInterface/CMakeLists_files.cmake b/ApplicationCode/UserInterface/CMakeLists_files.cmake index baf8b7aa0a..9e4df6ddec 100644 --- a/ApplicationCode/UserInterface/CMakeLists_files.cmake +++ b/ApplicationCode/UserInterface/CMakeLists_files.cmake @@ -40,6 +40,7 @@ ${CEE_CURRENT_LIST_DIR}RiuGeoMechXfTensorResultAccessor.h ${CEE_CURRENT_LIST_DIR}RiuFemTimeHistoryResultAccessor.h ${CEE_CURRENT_LIST_DIR}RiuExportMultipleSnapshotsWidget.h ${CEE_CURRENT_LIST_DIR}RiuWellAllocationPlot.h +${CEE_CURRENT_LIST_DIR}RiuNightchartsWidget.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -78,6 +79,7 @@ ${CEE_CURRENT_LIST_DIR}RiuGeoMechXfTensorResultAccessor.cpp ${CEE_CURRENT_LIST_DIR}RiuFemTimeHistoryResultAccessor.cpp ${CEE_CURRENT_LIST_DIR}RiuExportMultipleSnapshotsWidget.cpp ${CEE_CURRENT_LIST_DIR}RiuWellAllocationPlot.cpp +${CEE_CURRENT_LIST_DIR}RiuNightchartsWidget.cpp ) list(APPEND CODE_HEADER_FILES @@ -105,6 +107,7 @@ ${CEE_CURRENT_LIST_DIR}RiuSummaryQwtPlot.h ${CEE_CURRENT_LIST_DIR}RiuQwtScalePicker.h ${CEE_CURRENT_LIST_DIR}RiuExportMultipleSnapshotsWidget.h ${CEE_CURRENT_LIST_DIR}RiuWellAllocationPlot.h +${CEE_CURRENT_LIST_DIR}RiuNightchartsWidget.h ) list(APPEND QT_UI_FILES diff --git a/ApplicationCode/UserInterface/RiuNightchartsWidget.cpp b/ApplicationCode/UserInterface/RiuNightchartsWidget.cpp new file mode 100644 index 0000000000..54ea235c13 --- /dev/null +++ b/ApplicationCode/UserInterface/RiuNightchartsWidget.cpp @@ -0,0 +1,79 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RiuNightchartsWidget.h" + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuNightchartsWidget::RiuNightchartsWidget(QWidget* parent) : + QWidget(parent) +{ + clear(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuNightchartsWidget::setType(Nightcharts::type t) +{ + m_chart.setType(t); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuNightchartsWidget::clear() +{ + m_chart = Nightcharts(); + m_chart.setType(Nightcharts::Pie); + m_chart.setLegendType(Nightcharts::Vertical); + + m_marginLeft = 16; + m_marginTop = 16; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuNightchartsWidget::paintEvent(QPaintEvent* e) +{ + QWidget::paintEvent(e); + + if(!m_chart.pieceCount()) return ; + + QPainter painter; + QFont font; + painter.begin(this); + int w = (this->width() - m_marginLeft - 150); + int h = (this->height() - m_marginTop - 100); + int size = (w +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + + +#include "nightcharts/nightcharts.h" + +#include "cafPdmPointer.h" + +#include +#include + + +class RiuNightchartsWidget : public QWidget +{ + Q_OBJECT +public: + explicit RiuNightchartsWidget(QWidget* parent = 0); + + void addItem(QString name, QColor color, float value); + void setType(Nightcharts::type type); + void clear(); + +protected: + virtual void paintEvent(QPaintEvent* e); + +private: + Nightcharts m_chart; + int m_marginLeft; + int m_marginTop; +}; + From 055315085ed4eca374a24bd0e07e3b8ce0e18011 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 23 Jan 2017 08:51:50 +0100 Subject: [PATCH 22/27] #1108 Created settings object for "Well Allocation Factors" pie chart --- .../Flow/CMakeLists_files.cmake | 2 + .../Flow/RimFlowPlotCollection.cpp | 2 + .../Flow/RimTotalWellAllocationPlot.cpp | 262 ++++++++++++++++++ .../Flow/RimTotalWellAllocationPlot.h | 87 ++++++ .../Flow/RimWellAllocationPlot.cpp | 34 ++- .../Flow/RimWellAllocationPlot.h | 6 +- .../UserInterface/RiuWellAllocationPlot.cpp | 12 +- 7 files changed, 389 insertions(+), 16 deletions(-) create mode 100644 ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp create mode 100644 ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h diff --git a/ApplicationCode/ProjectDataModel/Flow/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/Flow/CMakeLists_files.cmake index 286b794cda..38b1dbb55d 100644 --- a/ApplicationCode/ProjectDataModel/Flow/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/Flow/CMakeLists_files.cmake @@ -8,12 +8,14 @@ set (SOURCE_GROUP_HEADER_FILES ${CEE_CURRENT_LIST_DIR}RimFlowDiagSolution.h ${CEE_CURRENT_LIST_DIR}RimFlowPlotCollection.h ${CEE_CURRENT_LIST_DIR}RimWellAllocationPlot.h +${CEE_CURRENT_LIST_DIR}RimTotalWellAllocationPlot.h ) set (SOURCE_GROUP_SOURCE_FILES ${CEE_CURRENT_LIST_DIR}RimFlowDiagSolution.cpp ${CEE_CURRENT_LIST_DIR}RimFlowPlotCollection.cpp ${CEE_CURRENT_LIST_DIR}RimWellAllocationPlot.cpp +${CEE_CURRENT_LIST_DIR}RimTotalWellAllocationPlot.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.cpp b/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.cpp index db04ab5213..a2b1ac998a 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.cpp @@ -47,5 +47,7 @@ RimFlowPlotCollection::RimFlowPlotCollection() //-------------------------------------------------------------------------------------------------- RimFlowPlotCollection::~RimFlowPlotCollection() { + delete defaultPlot(); + flowPlots.deleteAllChildObjects(); } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp new file mode 100644 index 0000000000..25c8a01bdf --- /dev/null +++ b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp @@ -0,0 +1,262 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RimTotalWellAllocationPlot.h" + +#include "RiaApplication.h" + +#include "RimEclipseView.h" +#include "RimEclipseWell.h" +#include "RimEclipseWellCollection.h" + +#include "RigSingleWellResultsData.h" + +#include "RimWellLogPlot.h" +#include "RimWellLogTrack.h" + +#include "RiuMainPlotWindow.h" +#include "RiuNightchartsWidget.h" +#include "RiuWellAllocationPlot.h" + + +CAF_PDM_SOURCE_INIT(RimTotalWellAllocationPlot, "TotalWellAllocationPlot"); + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimTotalWellAllocationPlot::RimTotalWellAllocationPlot() +{ + CAF_PDM_InitObject("Total Well Allocation Plot", ":/newIcon16x16.png", "", ""); + + CAF_PDM_InitField(&m_userName, "PlotDescription", QString("Total Well Allocation Plot"), "Name", "", "", ""); + m_userName.uiCapability()->setUiReadOnly(true); + + CAF_PDM_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", ""); + CAF_PDM_InitFieldNoDefault(&m_simulationWell, "SimulationWell", "Simulation Well", "", "", ""); + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimTotalWellAllocationPlot::~RimTotalWellAllocationPlot() +{ + removeMdiWindowFromMdiArea(); + + deleteViewWidget(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::setSimulationWell(RimEclipseWell* simWell) +{ + m_simulationWell = simWell; + + updateFromWell(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::deleteViewWidget() +{ + if (m_wellTotalAllocationPlotWidget) + { + m_wellTotalAllocationPlotWidget->deleteLater(); + m_wellTotalAllocationPlotWidget= nullptr; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::updateFromWell() +{ +/* + QString simName = "None"; + int branchCount = 0; + + const RigWellResultFrame* wellResultFrame = nullptr; + + if (m_simulationWell && m_simulationWell->wellResults() )// && Timestep Ok ) + { + simName = m_simulationWell->name(); + wellResultFrame = &(m_simulationWell->wellResults()->wellResultFrame(1)); + branchCount = static_cast( wellResultFrame->m_wellResultBranches.size()); + // // Todo : Use this instead, and use to calculate accumulated flow + // + // size_t timeStep = 0; // make field + // std::vector< std::vector > pipeBranchesCLCoords; + // std::vector< std::vector > pipeBranchesCellIds; + // m_simulationWell->calculateWellPipeDynamicCenterLine(timeStep, pipeBranchesCLCoords, pipeBranchesCellIds); + // branchCount = static_cast( pipeBranchesCLCoords.size()); + } + + int existingTrackCount = static_cast(accumulatedWellFlowPlot()->trackCount()); + accumulatedWellFlowPlot()->setDescription("Accumulated Well Flow (" + simName + ")"); + + int neededExtraTrackCount = branchCount - existingTrackCount; + for (int etc = 0; etc < neededExtraTrackCount; ++etc) + { + RimWellLogTrack* plotTrack = new RimWellLogTrack(); + accumulatedWellFlowPlot()->addTrack(plotTrack); + } + + for (int etc = branchCount; etc < existingTrackCount; ++etc) + { + accumulatedWellFlowPlot()->removeTrackByIndex(accumulatedWellFlowPlot()->trackCount()- 1); + } + + + for (size_t brIdx = 0; brIdx < branchCount; ++brIdx) + { + RimWellLogTrack* plotTrack = accumulatedWellFlowPlot()->trackByIndex(brIdx); + + plotTrack->setDescription(QString("Branch %1").arg(brIdx+1)); + + } + + setDescription("Well Allocation (" + simName + ")"); + accumulatedWellFlowPlot()->updateConnectedEditors(); +*/ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* RimTotalWellAllocationPlot::viewWidget() +{ + return m_wellTotalAllocationPlotWidget; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::zoomAll() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QList RimTotalWellAllocationPlot::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) +{ + QList options; + + if (fieldNeedingOptions == &m_simulationWell) + { + RimView* activeView = RiaApplication::instance()->activeReservoirView(); + RimEclipseView* eclView = dynamic_cast(activeView); + + if (eclView && eclView->wellCollection()) + { + RimEclipseWellCollection* coll = eclView->wellCollection(); + + caf::PdmChildArrayField& eclWells = coll->wells; + + QIcon simWellIcon(":/Well.png"); + for (RimEclipseWell* eclWell : eclWells) + { + options.push_back(caf::PdmOptionItemInfo(eclWell->name(), eclWell, false, simWellIcon)); + } + } + + if (options.size() == 0) + { + options.push_front(caf::PdmOptionItemInfo("None", nullptr)); + } + } + + return options; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +{ + RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue); + + if (changedField == &m_userName || + changedField == &m_showPlotTitle) + { + updateMdiWindowTitle(); + } + else if (changedField == &m_simulationWell) + { + updateFromWell(); + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QImage RimTotalWellAllocationPlot::snapshotWindowContent() +{ + QImage image; + + // TODO + + return image; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::setDescription(const QString& description) +{ + m_userName = description; + this->updateMdiWindowTitle(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimTotalWellAllocationPlot::description() const +{ + return m_userName(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::loadDataAndUpdate() +{ + updateMdiWindowVisibility(); + updateFromWell(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* RimTotalWellAllocationPlot::createViewWidget(QWidget* mainWindowParent) +{ + m_wellTotalAllocationPlotWidget = new RiuNightchartsWidget(mainWindowParent); + m_wellTotalAllocationPlotWidget->addItem("Item1", QColor(200, 10, 50), 34); + m_wellTotalAllocationPlotWidget->addItem("Item2", Qt::green, 27); + m_wellTotalAllocationPlotWidget->addItem("Item3", Qt::cyan, 14); + m_wellTotalAllocationPlotWidget->addItem("Item4", Qt::yellow, 7); + m_wellTotalAllocationPlotWidget->addItem("Item5", Qt::blue, 4); + + return m_wellTotalAllocationPlotWidget; +} + + diff --git a/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h new file mode 100644 index 0000000000..8bca8116ea --- /dev/null +++ b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h @@ -0,0 +1,87 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RimViewWindow.h" + +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmPtrField.h" + +#include + +class RiuWellAllocationPlot; +class RimEclipseWell; +class RimWellLogPlot; +class RiuNightchartsWidget; + +namespace caf { + class PdmOptionItemInfo; +} + + +//================================================================================================== +/// +/// +//================================================================================================== +class RimTotalWellAllocationPlot : public RimViewWindow +{ + CAF_PDM_HEADER_INIT; + +public: + RimTotalWellAllocationPlot(); + virtual ~RimTotalWellAllocationPlot(); + + void setSimulationWell(RimEclipseWell* simWell); + + void setDescription(const QString& description); + QString description() const; + + void loadDataAndUpdate(); + + virtual QWidget* viewWidget() override; + virtual void zoomAll() override; + + virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override; + + // RimViewWindow overrides + + virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; + virtual void deleteViewWidget() override; + +protected: + // Overridden PDM methods + virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; + + virtual QImage snapshotWindowContent() override; + +private: + void updateFromWell(); + + +private: + caf::PdmField m_showPlotTitle; + caf::PdmField m_userName; + + caf::PdmPtrField m_simulationWell; + + QPointer m_wellTotalAllocationPlotWidget; +}; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 59ae7863da..735888a63f 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -20,21 +20,23 @@ #include "RiaApplication.h" +#include "RigEclipseCaseData.h" +#include "RigSimulationWellCenterLineCalculator.h" +#include "RigSingleWellResultsData.h" + +#include "RimEclipseCase.h" +#include "RimEclipseCellColors.h" +#include "RimEclipseResultCase.h" #include "RimEclipseView.h" #include "RimEclipseWell.h" #include "RimEclipseWellCollection.h" +#include "RimFlowDiagSolution.h" +#include "RimTotalWellAllocationPlot.h" +#include "RimWellLogPlot.h" +#include "RimWellLogTrack.h" #include "RiuMainPlotWindow.h" #include "RiuWellAllocationPlot.h" -#include "RimWellLogPlot.h" -#include "RimWellLogTrack.h" -#include "RigSingleWellResultsData.h" -#include "RimEclipseResultCase.h" -#include "RimEclipseCellColors.h" -#include "RimFlowDiagSolution.h" -#include "RimEclipseCase.h" -#include "RigEclipseCaseData.h" -#include "RigSimulationWellCenterLineCalculator.h" CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot"); @@ -62,6 +64,11 @@ RimWellAllocationPlot::RimWellAllocationPlot() m_accumulatedWellFlowPlot.uiCapability()->setUiHidden(true); m_accumulatedWellFlowPlot = new RimWellLogPlot; + CAF_PDM_InitFieldNoDefault(&m_totalWellAllocationPlot, "TotalWellFlowPlot", "Total Well Flow", "", "", ""); + m_totalWellAllocationPlot.uiCapability()->setUiHidden(true); + + m_totalWellAllocationPlot = new RimTotalWellAllocationPlot; + this->setAsPlotMdiWindow(); } @@ -73,6 +80,7 @@ RimWellAllocationPlot::~RimWellAllocationPlot() removeMdiWindowFromMdiArea(); delete m_accumulatedWellFlowPlot(); + delete m_totalWellAllocationPlot(); deleteViewWidget(); } @@ -189,6 +197,14 @@ RimWellLogPlot* RimWellAllocationPlot::accumulatedWellFlowPlot() return m_accumulatedWellFlowPlot(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimTotalWellAllocationPlot* RimWellAllocationPlot::totalWellFlowPlot() +{ + return m_totalWellAllocationPlot(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index 07ef43df1f..560ab43f74 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -27,9 +27,10 @@ #include -class RiuWellAllocationPlot; class RimEclipseWell; +class RimTotalWellAllocationPlot; class RimWellLogPlot; +class RiuWellAllocationPlot; class RimEclipseResultCase; namespace caf { @@ -60,6 +61,7 @@ public: virtual void zoomAll() override; RimWellLogPlot* accumulatedWellFlowPlot(); + RimTotalWellAllocationPlot* totalWellFlowPlot(); virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override; @@ -78,7 +80,6 @@ private: virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; virtual void deleteViewWidget() override; - private: caf::PdmField m_showPlotTitle; caf::PdmField m_userName; @@ -91,4 +92,5 @@ private: QPointer m_wellAllocationPlotWidget; caf::PdmChildField m_accumulatedWellFlowPlot; + caf::PdmChildField m_totalWellAllocationPlot; }; diff --git a/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp b/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp index 4522082c08..60e0134d54 100644 --- a/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp +++ b/ApplicationCode/UserInterface/RiuWellAllocationPlot.cpp @@ -18,14 +18,14 @@ #include "RiuWellAllocationPlot.h" - #include "RiaApplication.h" #include "RimWellAllocationPlot.h" #include "RimWellLogPlot.h" #include "RimWellLogTrack.h" -#include "QBoxLayout" +#include "RimTotalWellAllocationPlot.h" +#include "QBoxLayout" @@ -36,14 +36,16 @@ RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefiniti : QFrame(parent) { Q_ASSERT(plotDefinition); - this->setLayout(new QVBoxLayout()); + this->setLayout(new QHBoxLayout()); this->layout()->setMargin(0); m_plotDefinition = plotDefinition; + + QWidget* totalFlowAllocationWidget = m_plotDefinition->totalWellFlowPlot()->createViewWidget(this); + this->layout()->addWidget(totalFlowAllocationWidget); + QWidget* wellFlowWidget = m_plotDefinition->accumulatedWellFlowPlot()->createViewWidget(this); this->layout()->addWidget(wellFlowWidget); - - } //-------------------------------------------------------------------------------------------------- From 5ffd2ac6265d555c70e5ef4ed6e2e2b5bb2c8b7a Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 23 Jan 2017 13:51:44 +0100 Subject: [PATCH 23/27] Fixed type compare --- ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp b/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp index d7b84eb870..a7a2e42fb8 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp @@ -332,7 +332,7 @@ QList RimEclipseResultDefinition::calculateValueOptions( if ( !hasFlowDiagFluxes ) { using ResCatEnum = caf::AppEnum< RimDefines::ResultCatType >; - for ( int i = 0; i < ResCatEnum::size(); ++i ) + for ( size_t i = 0; i < ResCatEnum::size(); ++i ) { RimDefines::ResultCatType resType = ResCatEnum::fromIndex(i); if ( resType != RimDefines::FLOW_DIAGNOSTICS ) From 7adafbe17c800f76522c75a5011c361c94d31334 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 23 Jan 2017 14:16:57 +0100 Subject: [PATCH 24/27] Fixed missing forward declare --- ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index 560ab43f74..e44c6f0dca 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -27,11 +27,12 @@ #include +class RimEclipseResultCase; class RimEclipseWell; +class RimFlowDiagSolution; class RimTotalWellAllocationPlot; class RimWellLogPlot; class RiuWellAllocationPlot; -class RimEclipseResultCase; namespace caf { class PdmOptionItemInfo; From b96b51284e83e385cf268cc7553a6b99bdd5da90 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 23 Jan 2017 14:43:52 +0100 Subject: [PATCH 25/27] Fixed invalid comparison between signed and unsigned --- .../ProjectDataModel/Flow/RimWellAllocationPlot.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 735888a63f..211f0e83d8 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -128,7 +128,7 @@ void RimWellAllocationPlot::updateFromWell() if (!wellResults) return; - int branchCount = 0; + size_t branchCount = 0; const RigWellResultFrame* wellResultFrame = nullptr; std::vector< std::vector > pipeBranchesCLCoords; @@ -142,19 +142,19 @@ void RimWellAllocationPlot::updateFromWell() pipeBranchesCLCoords, pipeBranchesCellIds); - branchCount = static_cast(pipeBranchesCLCoords.size()); + branchCount = pipeBranchesCLCoords.size(); - int existingTrackCount = static_cast(accumulatedWellFlowPlot()->trackCount()); + size_t existingTrackCount = accumulatedWellFlowPlot()->trackCount(); accumulatedWellFlowPlot()->setDescription("Accumulated Well Flow (" + m_wellName + ")"); - int neededExtraTrackCount = branchCount - existingTrackCount; - for (int etc = 0; etc < neededExtraTrackCount; ++etc) + size_t neededExtraTrackCount = branchCount - existingTrackCount; + for (size_t etc = 0; etc < neededExtraTrackCount; ++etc) { RimWellLogTrack* plotTrack = new RimWellLogTrack(); accumulatedWellFlowPlot()->addTrack(plotTrack); } - for (int etc = branchCount; etc < existingTrackCount; ++etc) + for (size_t etc = branchCount; etc < existingTrackCount; ++etc) { accumulatedWellFlowPlot()->removeTrackByIndex(accumulatedWellFlowPlot()->trackCount()- 1); } From 1b517a8e5e0364b9d971fd6156e5f41444eda632 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 24 Jan 2017 13:46:35 +0100 Subject: [PATCH 26/27] Added helper class for measured depth --- .../ReservoirDataModel/CMakeLists_files.cmake | 2 + .../RigSimulationWellCoordsAndMD.cpp | 104 ++++++++++++++++++ .../RigSimulationWellCoordsAndMD.h | 49 +++++++++ 3 files changed, 155 insertions(+) create mode 100644 ApplicationCode/ReservoirDataModel/RigSimulationWellCoordsAndMD.cpp create mode 100644 ApplicationCode/ReservoirDataModel/RigSimulationWellCoordsAndMD.h diff --git a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake index 2314978edd..09380fbc9c 100644 --- a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake @@ -49,6 +49,7 @@ ${CEE_CURRENT_LIST_DIR}RigTimeHistoryResultAccessor.h ${CEE_CURRENT_LIST_DIR}RigCurveDataTools.h ${CEE_CURRENT_LIST_DIR}RigSummaryCaseData.h ${CEE_CURRENT_LIST_DIR}RigLasFileExporter.h +${CEE_CURRENT_LIST_DIR}RigSimulationWellCoordsAndMD.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -92,6 +93,7 @@ ${CEE_CURRENT_LIST_DIR}RigTimeHistoryResultAccessor.cpp ${CEE_CURRENT_LIST_DIR}RigCurveDataTools.cpp ${CEE_CURRENT_LIST_DIR}RigSummaryCaseData.cpp ${CEE_CURRENT_LIST_DIR}RigLasFileExporter.cpp +${CEE_CURRENT_LIST_DIR}RigSimulationWellCoordsAndMD.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCoordsAndMD.cpp b/ApplicationCode/ReservoirDataModel/RigSimulationWellCoordsAndMD.cpp new file mode 100644 index 0000000000..a5e116e1d9 --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCoordsAndMD.cpp @@ -0,0 +1,104 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RigSimulationWellCoordsAndMD.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigSimulationWellCoordsAndMD::RigSimulationWellCoordsAndMD(const std::vector& wellPathPoints) +{ + m_wellPathPoints = wellPathPoints; + + computeMeasuredDepths(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const std::vector& RigSimulationWellCoordsAndMD::wellPathPoints() const +{ + return m_wellPathPoints; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const std::vector& RigSimulationWellCoordsAndMD::measuredDepths() const +{ + return m_measuredDepths; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::Vec3d RigSimulationWellCoordsAndMD::interpolatedPointAlongWellPath(double measuredDepth) const +{ + cvf::Vec3d wellPathPoint = cvf::Vec3d::ZERO; + + size_t i = 0; + while (i < m_measuredDepths.size() && m_measuredDepths.at(i) < measuredDepth) + { + i++; + } + + if (m_measuredDepths.size() > i) + { + if (i == 0) + { + //For measuredDepth same or lower than first point, use this first point + wellPathPoint = m_wellPathPoints.at(0); + } + else + { + //Do interpolation + double stepsize = (measuredDepth - m_measuredDepths.at(i - 1)) / + (m_measuredDepths.at(i) - m_measuredDepths.at(i - 1)); + wellPathPoint = m_wellPathPoints.at(i - 1) + stepsize * (m_wellPathPoints.at(i) - m_wellPathPoints.at(i - 1)); + } + } + else + { + //Use endpoint if measuredDepth same or higher than last point + wellPathPoint = m_wellPathPoints.at(i - 1); + } + + return wellPathPoint; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigSimulationWellCoordsAndMD::computeMeasuredDepths() +{ + cvf::Vec3d prev = cvf::Vec3d::UNDEFINED; + + double accumulatedMD = 0; + + for (const auto& point : m_wellPathPoints) + { + if (!prev.isUndefined()) + { + accumulatedMD += point.pointDistance(prev); + } + + m_measuredDepths.push_back(accumulatedMD); + + prev = point; + } +} diff --git a/ApplicationCode/ReservoirDataModel/RigSimulationWellCoordsAndMD.h b/ApplicationCode/ReservoirDataModel/RigSimulationWellCoordsAndMD.h new file mode 100644 index 0000000000..9db9d5c861 --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigSimulationWellCoordsAndMD.h @@ -0,0 +1,49 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "cvfBase.h" +#include "cvfVector3.h" + +#include + + + + +//================================================================================================== +/// +/// +//================================================================================================== +class RigSimulationWellCoordsAndMD +{ +public: + RigSimulationWellCoordsAndMD(const std::vector& wellPathPoints); + + const std::vector& wellPathPoints() const; + const std::vector& measuredDepths() const; + + cvf::Vec3d interpolatedPointAlongWellPath(double measuredDepth) const; + +private: + void computeMeasuredDepths(); + +private: + std::vector m_wellPathPoints; + std::vector m_measuredDepths; +}; From 5053112e3d667a48b8ea60ad5e6e2fa23dee9c07 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 24 Jan 2017 14:25:31 +0100 Subject: [PATCH 27/27] #1118 Calculate and display flow rate --- .../Flow/CMakeLists_files.cmake | 2 + .../Flow/RimFlowPlotCollection.cpp | 10 ++ .../Flow/RimFlowPlotCollection.h | 2 + .../Flow/RimWellAllocationPlot.cpp | 94 +++++++++--- .../Flow/RimWellAllocationPlot.h | 4 + .../Flow/RimWellFlowRateCurve.cpp | 135 ++++++++++++++++++ .../Flow/RimWellFlowRateCurve.h | 53 +++++++ .../RimMainPlotCollection.cpp | 3 +- 8 files changed, 282 insertions(+), 21 deletions(-) create mode 100644 ApplicationCode/ProjectDataModel/Flow/RimWellFlowRateCurve.cpp create mode 100644 ApplicationCode/ProjectDataModel/Flow/RimWellFlowRateCurve.h diff --git a/ApplicationCode/ProjectDataModel/Flow/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/Flow/CMakeLists_files.cmake index 38b1dbb55d..c30e97e6fa 100644 --- a/ApplicationCode/ProjectDataModel/Flow/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/Flow/CMakeLists_files.cmake @@ -9,6 +9,7 @@ ${CEE_CURRENT_LIST_DIR}RimFlowDiagSolution.h ${CEE_CURRENT_LIST_DIR}RimFlowPlotCollection.h ${CEE_CURRENT_LIST_DIR}RimWellAllocationPlot.h ${CEE_CURRENT_LIST_DIR}RimTotalWellAllocationPlot.h +${CEE_CURRENT_LIST_DIR}RimWellFlowRateCurve.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -16,6 +17,7 @@ ${CEE_CURRENT_LIST_DIR}RimFlowDiagSolution.cpp ${CEE_CURRENT_LIST_DIR}RimFlowPlotCollection.cpp ${CEE_CURRENT_LIST_DIR}RimWellAllocationPlot.cpp ${CEE_CURRENT_LIST_DIR}RimTotalWellAllocationPlot.cpp +${CEE_CURRENT_LIST_DIR}RimWellFlowRateCurve.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.cpp b/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.cpp index a2b1ac998a..bfecb6747d 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.cpp @@ -51,3 +51,13 @@ RimFlowPlotCollection::~RimFlowPlotCollection() flowPlots.deleteAllChildObjects(); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFlowPlotCollection::closeDefaultPlotWindowAndDeletePlots() +{ + defaultPlot->removeFromMdiAreaAndDeleteViewWidget(); + + flowPlots.deleteAllChildObjects(); +} diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.h b/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.h index affbbf2d6f..b3fa710a66 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowPlotCollection.h @@ -34,6 +34,8 @@ class RimFlowPlotCollection : public caf::PdmObject public: RimFlowPlotCollection(); virtual ~RimFlowPlotCollection(); + + void closeDefaultPlotWindowAndDeletePlots(); caf::PdmChildField defaultPlot; caf::PdmChildArrayField flowPlots; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 211f0e83d8..fdf341d81c 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -22,6 +22,7 @@ #include "RigEclipseCaseData.h" #include "RigSimulationWellCenterLineCalculator.h" +#include "RigSimulationWellCoordsAndMD.h" #include "RigSingleWellResultsData.h" #include "RimEclipseCase.h" @@ -32,6 +33,7 @@ #include "RimEclipseWellCollection.h" #include "RimFlowDiagSolution.h" #include "RimTotalWellAllocationPlot.h" +#include "RimWellFlowRateCurve.h" #include "RimWellLogPlot.h" #include "RimWellLogTrack.h" @@ -128,7 +130,6 @@ void RimWellAllocationPlot::updateFromWell() if (!wellResults) return; - size_t branchCount = 0; const RigWellResultFrame* wellResultFrame = nullptr; std::vector< std::vector > pipeBranchesCLCoords; @@ -142,34 +143,71 @@ void RimWellAllocationPlot::updateFromWell() pipeBranchesCLCoords, pipeBranchesCellIds); - branchCount = pipeBranchesCLCoords.size(); - - size_t existingTrackCount = accumulatedWellFlowPlot()->trackCount(); accumulatedWellFlowPlot()->setDescription("Accumulated Well Flow (" + m_wellName + ")"); + - size_t neededExtraTrackCount = branchCount - existingTrackCount; - for (size_t etc = 0; etc < neededExtraTrackCount; ++etc) + // Delete existing tracks { - RimWellLogTrack* plotTrack = new RimWellLogTrack(); - accumulatedWellFlowPlot()->addTrack(plotTrack); - } - - for (size_t etc = branchCount; etc < existingTrackCount; ++etc) - { - accumulatedWellFlowPlot()->removeTrackByIndex(accumulatedWellFlowPlot()->trackCount()- 1); + std::vector tracks; + accumulatedWellFlowPlot()->descendantsIncludingThisOfType(tracks); + + for (RimWellLogTrack* t : tracks) + { + accumulatedWellFlowPlot()->removeTrack(t); + delete t; + } } + CVF_ASSERT(accumulatedWellFlowPlot()->trackCount() == 0); + size_t branchCount = pipeBranchesCLCoords.size(); for (size_t brIdx = 0; brIdx < branchCount; ++brIdx) { - RimWellLogTrack* plotTrack = accumulatedWellFlowPlot()->trackByIndex(brIdx); + RimWellLogTrack* plotTrack = new RimWellLogTrack(); - plotTrack->setDescription(QString("Branch %1").arg(brIdx+1)); + // TODO: Description is overwritten by RimWellLogPlot::updateTrackNames() + // Add flag to control if this behavior + plotTrack->setDescription(QString("Branch %1").arg(brIdx + 1)); + accumulatedWellFlowPlot()->addTrack(plotTrack); + + std::vector curveCoords; + std::vector flowRate; + + { + std::vector branchCoords = pipeBranchesCLCoords[brIdx]; + std::vector branchResultPoints = pipeBranchesCellIds[brIdx]; + + RigWellResultPoint prevResultPoint; + + for (size_t i = 0; i < branchResultPoints.size(); i++) + { + const RigWellResultPoint& resultPoint = branchResultPoints[i]; + + if (i > 0 && prevResultPoint.m_gridCellIndex != resultPoint.m_gridCellIndex) + { + // Add an extra curve point when a cell transition is detected + curveCoords.push_back(branchCoords[i]); + flowRate.push_back(prevResultPoint.m_flowRate); + } + + curveCoords.push_back(branchCoords[i]); + flowRate.push_back(branchResultPoints[i].m_flowRate); + + prevResultPoint = resultPoint; + } + } + + RigSimulationWellCoordsAndMD helper(curveCoords); + + RimWellFlowRateCurve* curve = new RimWellFlowRateCurve; + curve->setFlowValues(helper.measuredDepths(), flowRate); + + plotTrack->addCurve(curve); + + curve->loadDataAndUpdate(); } - // Todo: Calculate curve data - setDescription("Well Allocation (" + m_wellName + ")"); accumulatedWellFlowPlot()->updateConnectedEditors(); } @@ -215,7 +253,7 @@ QList RimWellAllocationPlot::calculateValueOptions(const if (fieldNeedingOptions == &m_wellName) { std::set sortedWellNames; - if ( m_case ) + if ( m_case && m_case->reservoirData() ) { const cvf::Collection& wellRes = m_case->reservoirData()->wellResults(); @@ -240,7 +278,7 @@ QList RimWellAllocationPlot::calculateValueOptions(const { QStringList timeStepNames; - if (m_case) + if (m_case && m_case->reservoirData()) { timeStepNames = m_case->timeStepStrings(); } @@ -254,6 +292,23 @@ QList RimWellAllocationPlot::calculateValueOptions(const return options; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimWellAllocationPlot::wellName() const +{ + return m_wellName(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellAllocationPlot::removeFromMdiAreaAndDeleteViewWidget() +{ + removeMdiWindowFromMdiArea(); + deleteViewWidget(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -272,7 +327,6 @@ void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedF } } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index e44c6f0dca..91752e9d7b 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -66,6 +66,10 @@ public: virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override; + QString wellName() const; + + void removeFromMdiAreaAndDeleteViewWidget(); + protected: // Overridden PDM methods virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellFlowRateCurve.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellFlowRateCurve.cpp new file mode 100644 index 0000000000..bdd2126d40 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellFlowRateCurve.cpp @@ -0,0 +1,135 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RimWellFlowRateCurve.h" + +#include "RimWellAllocationPlot.h" + +#include "RiuLineSegmentQwtPlotCurve.h" + +#include "qwt_plot.h" +#include "RimWellLogPlot.h" + + + +//================================================================================================== +/// +/// +//================================================================================================== + +CAF_PDM_SOURCE_INIT(RimWellFlowRateCurve, "RimWellFlowRateCurve"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellFlowRateCurve::RimWellFlowRateCurve() +{ + CAF_PDM_InitObject("Flow Rate Curve", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellFlowRateCurve::~RimWellFlowRateCurve() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimWellFlowRateCurve::wellName() const +{ + QString name; + + RimWellAllocationPlot* wap = wellAllocationPlot(); + + if (wap) + { + name = wap->wellName(); + } + else + { + name = "Undefined"; + } + + return name; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimWellFlowRateCurve::wellLogChannelName() const +{ + return "Flow Rate"; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimWellFlowRateCurve::createCurveAutoName() +{ + return QString("%1 (%2)").arg(wellLogChannelName()).arg(wellName()); + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellFlowRateCurve::onLoadDataAndUpdate() +{ + RimWellLogCurve::updateCurvePresentation(); + + if (isCurveVisible()) + { + RimWellLogPlot* wellLogPlot; + firstAncestorOrThisOfType(wellLogPlot); + CVF_ASSERT(wellLogPlot); + + m_qwtPlotCurve->setTitle(createCurveAutoName()); + + RimDefines::DepthUnitType displayUnit = RimDefines::UNIT_METER; + m_qwtPlotCurve->setSamples(m_curveData->xPlotValues().data(), m_curveData->measuredDepthPlotValues(displayUnit).data(), static_cast(m_curveData->xPlotValues().size())); + m_qwtPlotCurve->setLineSegmentStartStopIndices(m_curveData->polylineStartStopIndices()); + + updateZoomInParentPlot(); + + if (m_parentQwtPlot) m_parentQwtPlot->replot(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellAllocationPlot* RimWellFlowRateCurve::wellAllocationPlot() const +{ + RimWellAllocationPlot* wap = nullptr; + this->firstAncestorOrThisOfType(wap); + + return wap; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellFlowRateCurve::setFlowValues(const std::vector& measuredDepths, const std::vector& flowRates) +{ + m_curveData = new RigWellLogCurveData; + m_curveData->setValuesAndMD(flowRates, measuredDepths, RimDefines::UNIT_METER, false); +} + diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellFlowRateCurve.h b/ApplicationCode/ProjectDataModel/Flow/RimWellFlowRateCurve.h new file mode 100644 index 0000000000..598f899184 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellFlowRateCurve.h @@ -0,0 +1,53 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RimWellLogCurve.h" + +#include "cafPdmPtrField.h" +#include "cafPdmChildField.h" + +class RimEclipseResultCase; +class RimWellAllocationPlot; + + +//================================================================================================== +/// +/// +//================================================================================================== +class RimWellFlowRateCurve : public RimWellLogCurve +{ + CAF_PDM_HEADER_INIT; +public: + RimWellFlowRateCurve(); + virtual ~RimWellFlowRateCurve(); + + void setFlowValues(const std::vector& measuredDepths, const std::vector& flowRates); + + virtual QString wellName() const override; + virtual QString wellLogChannelName() const override; + +protected: + virtual QString createCurveAutoName() override; + virtual void onLoadDataAndUpdate() override; + +private: + RimWellAllocationPlot* wellAllocationPlot() const; +}; + diff --git a/ApplicationCode/ProjectDataModel/RimMainPlotCollection.cpp b/ApplicationCode/ProjectDataModel/RimMainPlotCollection.cpp index 06ffd1cf9d..d82d8bf289 100644 --- a/ApplicationCode/ProjectDataModel/RimMainPlotCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimMainPlotCollection.cpp @@ -169,7 +169,8 @@ void RimMainPlotCollection::deleteAllContainedObjects() { m_wellLogPlotCollection()->wellLogPlots.deleteAllChildObjects(); m_summaryPlotCollection()->summaryPlots.deleteAllChildObjects(); - m_flowPlotCollection()->flowPlots.deleteAllChildObjects(); + + m_flowPlotCollection()->closeDefaultPlotWindowAndDeletePlots(); } #if 0