From d4a97d8e68f2ee0b9b146b8ff18f3261046f1879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Hagen?= Date: Thu, 20 Aug 2015 18:15:58 +0200 Subject: [PATCH] (#385) Implemented feature RicRangeFilterInsertFeature Did some refactoring, using common code for creation of cell range filters. --- .../Commands/CMakeLists_files.cmake | 6 +- .../Commands/RicRangeFilterExecImpl.cpp | 90 +++++++++++++++++++ .../Commands/RicRangeFilterExecImpl.h | 58 ++++++++++++ .../Commands/RicRangeFilterFeatureImpl.h | 2 +- .../Commands/RicRangeFilterInsertExec.cpp | 82 +++++++++++++++++ .../Commands/RicRangeFilterInsertExec.h | 41 +++++++++ .../Commands/RicRangeFilterInsertFeature.cpp | 32 ++++--- .../Commands/RicRangeFilterInsertFeature.h | 6 ++ .../Commands/RicRangeFilterNewExec.cpp | 72 +++++---------- .../Commands/RicRangeFilterNewExec.h | 22 +---- 10 files changed, 327 insertions(+), 84 deletions(-) create mode 100644 ApplicationCode/Commands/RicRangeFilterExecImpl.cpp create mode 100644 ApplicationCode/Commands/RicRangeFilterExecImpl.h create mode 100644 ApplicationCode/Commands/RicRangeFilterInsertExec.cpp create mode 100644 ApplicationCode/Commands/RicRangeFilterInsertExec.h diff --git a/ApplicationCode/Commands/CMakeLists_files.cmake b/ApplicationCode/Commands/CMakeLists_files.cmake index 79da037071..f5c8d7c8ed 100644 --- a/ApplicationCode/Commands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CMakeLists_files.cmake @@ -31,7 +31,9 @@ ${CEE_CURRENT_LIST_DIR}RicEclipseViewPasteFeature.h #${CEE_CURRENT_LIST_DIR}RicGridModelsCreateCaseGroupFromFiles.h #${CEE_CURRENT_LIST_DIR}RicGridModelsImport.h #${CEE_CURRENT_LIST_DIR}RicGridModelsImportInput.h -${CEE_CURRENT_LIST_DIR}RicPropertyFilterNewExec.cpp +${CEE_CURRENT_LIST_DIR}RicPropertyFilterNewExec.h +${CEE_CURRENT_LIST_DIR}RicRangeFilterExecImpl.h +${CEE_CURRENT_LIST_DIR}RicRangeFilterInsertExec.h ${CEE_CURRENT_LIST_DIR}RicRangeFilterInsertFeature.h ${CEE_CURRENT_LIST_DIR}RicRangeFilterNewFeature.h ${CEE_CURRENT_LIST_DIR}RicRangeFilterFeatureImpl.h @@ -82,6 +84,8 @@ ${CEE_CURRENT_LIST_DIR}RicEclipseViewPasteFeature.cpp #${CEE_CURRENT_LIST_DIR}RicGridModelsCreateCaseGroupFromFiles.cpp #${CEE_CURRENT_LIST_DIR}RicGridModelsImport.cpp #${CEE_CURRENT_LIST_DIR}RicGridModelsImportInput.cpp +${CEE_CURRENT_LIST_DIR}RicRangeFilterExecImpl.cpp +${CEE_CURRENT_LIST_DIR}RicRangeFilterInsertExec.cpp ${CEE_CURRENT_LIST_DIR}RicRangeFilterInsertFeature.cpp ${CEE_CURRENT_LIST_DIR}RicRangeFilterNewFeature.cpp ${CEE_CURRENT_LIST_DIR}RicRangeFilterFeatureImpl.cpp diff --git a/ApplicationCode/Commands/RicRangeFilterExecImpl.cpp b/ApplicationCode/Commands/RicRangeFilterExecImpl.cpp new file mode 100644 index 0000000000..875e47a744 --- /dev/null +++ b/ApplicationCode/Commands/RicRangeFilterExecImpl.cpp @@ -0,0 +1,90 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2015- Statoil ASA +// Copyright (C) 2015- Ceetron Solutions AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicRangeFilterExecImpl.h" + +#include "RimCellRangeFilter.h" +#include "RimCellRangeFilterCollection.h" + +#include "cvfAssert.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicRangeFilterExecImpl::RicRangeFilterExecImpl(RimCellRangeFilterCollection* rangeFilterCollection, RimCellRangeFilter* rangeFilter) + : CmdExecuteCommand(NULL) +{ + CVF_ASSERT(rangeFilterCollection); + m_cellRangeFilterCollection = rangeFilterCollection; + + m_cellRangeFilter = rangeFilter; + + m_iSlice = false; + m_jSlice = false; + m_kSlice = false; + + m_iSliceStart = -1; + m_jSliceStart = -1; + m_kSliceStart = -1; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicRangeFilterExecImpl::~RicRangeFilterExecImpl() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCellRangeFilter* RicRangeFilterExecImpl::createRangeFilter() +{ + CVF_ASSERT(m_cellRangeFilterCollection); + + RimCellRangeFilter* rangeFilter = new RimCellRangeFilter(); + + size_t flterIndex = m_cellRangeFilterCollection->rangeFilters().size() + 1; + + rangeFilter->name = QString("Range Filter (%1)").arg(flterIndex); + + if (m_iSlice) + { + rangeFilter->cellCountI = 1; + rangeFilter->name = QString("Slice I (%1)").arg(flterIndex); + } + + if (m_jSlice) + { + rangeFilter->cellCountJ = 1; + rangeFilter->name = QString("Slice J (%1)").arg(flterIndex); + } + + if (m_kSlice) + { + rangeFilter->cellCountK = 1; + rangeFilter->name = QString("Slice K (%1)").arg(flterIndex); + } + + if (m_iSliceStart > -1) rangeFilter->startIndexI = m_iSliceStart; + if (m_jSliceStart > -1) rangeFilter->startIndexJ = m_jSliceStart; + if (m_kSliceStart > -1) rangeFilter->startIndexK = m_kSliceStart; + + return rangeFilter; +} \ No newline at end of file diff --git a/ApplicationCode/Commands/RicRangeFilterExecImpl.h b/ApplicationCode/Commands/RicRangeFilterExecImpl.h new file mode 100644 index 0000000000..827385255e --- /dev/null +++ b/ApplicationCode/Commands/RicRangeFilterExecImpl.h @@ -0,0 +1,58 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2015- Statoil ASA +// Copyright (C) 2015- Ceetron Solutions AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdExecuteCommand.h" +#include "cafPdmPointer.h" + +class RimCellRangeFilter; +class RimCellRangeFilterCollection; + +//================================================================================================== +/// +//================================================================================================== +class RicRangeFilterExecImpl : public caf::CmdExecuteCommand +{ +public: + RicRangeFilterExecImpl(RimCellRangeFilterCollection* rangeFilterCollection, RimCellRangeFilter* rangeFilter = 0); + virtual ~RicRangeFilterExecImpl(); + + virtual QString name() = 0; + virtual void redo() = 0; + virtual void undo() = 0; + +public: + bool m_iSlice; + bool m_jSlice; + bool m_kSlice; + + int m_iSliceStart; + int m_jSliceStart; + int m_kSliceStart; + +protected: + RimCellRangeFilter* createRangeFilter(); + +protected: + caf::PdmPointer m_cellRangeFilterCollection; + caf::PdmPointer m_cellRangeFilter; +}; + + diff --git a/ApplicationCode/Commands/RicRangeFilterFeatureImpl.h b/ApplicationCode/Commands/RicRangeFilterFeatureImpl.h index 95639b9af8..f2a93af7af 100644 --- a/ApplicationCode/Commands/RicRangeFilterFeatureImpl.h +++ b/ApplicationCode/Commands/RicRangeFilterFeatureImpl.h @@ -31,7 +31,7 @@ public: static bool isRangeFilterCommandAvailable(); static RicRangeFilterNewExec* createRangeFilterExecCommand(); -private: +public: static RimCellRangeFilterCollection* findRangeFilterCollection(); }; diff --git a/ApplicationCode/Commands/RicRangeFilterInsertExec.cpp b/ApplicationCode/Commands/RicRangeFilterInsertExec.cpp new file mode 100644 index 0000000000..aff91a862e --- /dev/null +++ b/ApplicationCode/Commands/RicRangeFilterInsertExec.cpp @@ -0,0 +1,82 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2015- Statoil ASA +// Copyright (C) 2015- Ceetron Solutions AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicRangeFilterInsertExec.h" + +#include "RimCellRangeFilter.h" +#include "RimCellRangeFilterCollection.h" +#include "RimView.h" +#include "RiuMainWindow.h" + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicRangeFilterInsertExec::RicRangeFilterInsertExec(RimCellRangeFilterCollection* rangeFilterCollection, RimCellRangeFilter* rangeFilter) + : RicRangeFilterExecImpl(rangeFilterCollection, rangeFilter) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicRangeFilterInsertExec::~RicRangeFilterInsertExec() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicRangeFilterInsertExec::name() +{ + return "Create Range Filter"; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicRangeFilterInsertExec::redo() +{ + RimCellRangeFilter* rangeFilter = createRangeFilter(); + if (rangeFilter) + { + size_t index = m_cellRangeFilterCollection->rangeFilters.index(m_cellRangeFilter); + CVF_ASSERT(index < m_cellRangeFilterCollection->rangeFilters.size()); + + m_cellRangeFilterCollection->rangeFilters.insertAt(index, rangeFilter); + + rangeFilter->setDefaultValues(); + + m_cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED); + m_cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED_INACTIVE); + m_cellRangeFilterCollection->reservoirView()->scheduleCreateDisplayModelAndRedraw(); + + m_cellRangeFilterCollection->updateConnectedEditors(); + + RiuMainWindow::instance()->setCurrentObjectInTreeView(rangeFilter); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicRangeFilterInsertExec::undo() +{ +} diff --git a/ApplicationCode/Commands/RicRangeFilterInsertExec.h b/ApplicationCode/Commands/RicRangeFilterInsertExec.h new file mode 100644 index 0000000000..db47dd8890 --- /dev/null +++ b/ApplicationCode/Commands/RicRangeFilterInsertExec.h @@ -0,0 +1,41 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2015- Statoil ASA +// Copyright (C) 2015- Ceetron Solutions AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RicRangeFilterExecImpl.h" + +class RimCellRangeFilter; +class RimCellRangeFilterCollection; + +//================================================================================================== +/// +//================================================================================================== +class RicRangeFilterInsertExec : public RicRangeFilterExecImpl +{ +public: + RicRangeFilterInsertExec(RimCellRangeFilterCollection* rangeFilterCollection, RimCellRangeFilter* rangeFilter = 0); + virtual ~RicRangeFilterInsertExec(); + + virtual QString name(); + virtual void redo(); + virtual void undo(); +}; + + diff --git a/ApplicationCode/Commands/RicRangeFilterInsertFeature.cpp b/ApplicationCode/Commands/RicRangeFilterInsertFeature.cpp index d2fa8d7e23..1293bb7814 100644 --- a/ApplicationCode/Commands/RicRangeFilterInsertFeature.cpp +++ b/ApplicationCode/Commands/RicRangeFilterInsertFeature.cpp @@ -19,6 +19,9 @@ #include "RicRangeFilterInsertFeature.h" +#include "RicRangeFilterInsertExec.h" +#include "RicRangeFilterFeatureImpl.h" + #include "RimCellRangeFilter.h" #include "cafSelectionManager.h" @@ -35,17 +38,8 @@ CAF_CMD_SOURCE_INIT(RicRangeFilterInsertFeature, "RicRangeFilterInsertFeature"); //-------------------------------------------------------------------------------------------------- bool RicRangeFilterInsertFeature::isCommandEnabled() { - std::vector selectedRangeFilter; - caf::SelectionManager::instance()->objectsByType(&selectedRangeFilter); - - if (selectedRangeFilter.size() > 0) - { - return true; - } - else - { - return false; - } + std::vector selection = selectedCellRangeFilters(); + return selection.size() > 0; } //-------------------------------------------------------------------------------------------------- @@ -53,6 +47,11 @@ bool RicRangeFilterInsertFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicRangeFilterInsertFeature::onActionTriggered(bool isChecked) { + std::vector selection = selectedCellRangeFilters(); + RimCellRangeFilterCollection* rangeFilterCollection = RicRangeFilterFeatureImpl::findRangeFilterCollection(); + + RicRangeFilterInsertExec* filterExec = new RicRangeFilterInsertExec(rangeFilterCollection, selection[0]); + caf::CmdExecCommandManager::instance()->processExecuteCommand(filterExec); } //-------------------------------------------------------------------------------------------------- @@ -63,3 +62,14 @@ void RicRangeFilterInsertFeature::setupActionLook(QAction* actionToSetup) actionToSetup->setText("Insert Range Filter"); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RicRangeFilterInsertFeature::selectedCellRangeFilters() +{ + std::vector selection; + caf::SelectionManager::instance()->objectsByType(&selection); + + return selection; +} + diff --git a/ApplicationCode/Commands/RicRangeFilterInsertFeature.h b/ApplicationCode/Commands/RicRangeFilterInsertFeature.h index 5e46f0e4cf..9f47055d74 100644 --- a/ApplicationCode/Commands/RicRangeFilterInsertFeature.h +++ b/ApplicationCode/Commands/RicRangeFilterInsertFeature.h @@ -21,6 +21,9 @@ #include "cafCmdFeature.h" +#include + +class RimCellRangeFilter; //================================================================================================== /// @@ -34,6 +37,9 @@ protected: virtual bool isCommandEnabled(); virtual void onActionTriggered( bool isChecked ); virtual void setupActionLook( QAction* actionToSetup ); + +private: + static std::vector selectedCellRangeFilters(); }; diff --git a/ApplicationCode/Commands/RicRangeFilterNewExec.cpp b/ApplicationCode/Commands/RicRangeFilterNewExec.cpp index 7f52f444eb..16051fc0e8 100644 --- a/ApplicationCode/Commands/RicRangeFilterNewExec.cpp +++ b/ApplicationCode/Commands/RicRangeFilterNewExec.cpp @@ -28,18 +28,9 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RicRangeFilterNewExec::RicRangeFilterNewExec(RimCellRangeFilterCollection* rangeFilterCollection) - : CmdExecuteCommand(NULL) +RicRangeFilterNewExec::RicRangeFilterNewExec(RimCellRangeFilterCollection* rangeFilterCollection, RimCellRangeFilter* rangeFilter) + : RicRangeFilterExecImpl(rangeFilterCollection, rangeFilter) { - m_iSlice = false; - m_jSlice = false; - m_kSlice = false; - - m_iSliceStart = -1; - m_jSliceStart = -1; - m_kSliceStart = -1; - - cellRangeFilterCollection = rangeFilterCollection; } //-------------------------------------------------------------------------------------------------- @@ -47,7 +38,6 @@ RicRangeFilterNewExec::RicRangeFilterNewExec(RimCellRangeFilterCollection* range //-------------------------------------------------------------------------------------------------- RicRangeFilterNewExec::~RicRangeFilterNewExec() { - } //-------------------------------------------------------------------------------------------------- @@ -70,43 +60,21 @@ QString RicRangeFilterNewExec::name() //-------------------------------------------------------------------------------------------------- void RicRangeFilterNewExec::redo() { - assert(cellRangeFilterCollection); - - RimCellRangeFilter* rangeFilter = new RimCellRangeFilter(); - cellRangeFilterCollection->rangeFilters.push_back(rangeFilter); - rangeFilter->setDefaultValues(); - - rangeFilter->name = QString("Range Filter (%1)").arg(cellRangeFilterCollection->rangeFilters().size()); - - if (m_iSlice) + RimCellRangeFilter* rangeFilter = createRangeFilter(); + if (rangeFilter) { - rangeFilter->cellCountI = 1; - rangeFilter->name = QString("Slice I (%1)").arg(cellRangeFilterCollection->rangeFilters().size()); + m_cellRangeFilterCollection->rangeFilters.push_back(rangeFilter); + + rangeFilter->setDefaultValues(); + + m_cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED); + m_cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED_INACTIVE); + m_cellRangeFilterCollection->reservoirView()->scheduleCreateDisplayModelAndRedraw(); + + m_cellRangeFilterCollection->updateConnectedEditors(); + + RiuMainWindow::instance()->setCurrentObjectInTreeView(rangeFilter); } - - if (m_jSlice) - { - rangeFilter->cellCountJ = 1; - rangeFilter->name = QString("Slice J (%1)").arg(cellRangeFilterCollection->rangeFilters().size()); - } - - if (m_kSlice) - { - rangeFilter->cellCountK = 1; - rangeFilter->name = QString("Slice K (%1)").arg(cellRangeFilterCollection->rangeFilters().size()); - } - - if (m_iSliceStart > -1) rangeFilter->startIndexI = m_iSliceStart; - if (m_jSliceStart > -1) rangeFilter->startIndexJ = m_jSliceStart; - if (m_kSliceStart > -1) rangeFilter->startIndexK = m_kSliceStart; - - cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED); - cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED_INACTIVE); - cellRangeFilterCollection->reservoirView()->scheduleCreateDisplayModelAndRedraw(); - - cellRangeFilterCollection->updateConnectedEditors(); - - RiuMainWindow::instance()->setCurrentObjectInTreeView(rangeFilter); } //-------------------------------------------------------------------------------------------------- @@ -114,12 +82,12 @@ void RicRangeFilterNewExec::redo() //-------------------------------------------------------------------------------------------------- void RicRangeFilterNewExec::undo() { - assert(cellRangeFilterCollection); + assert(m_cellRangeFilterCollection); - cellRangeFilterCollection->rangeFilters.erase(cellRangeFilterCollection->rangeFilters.size() - 1); + m_cellRangeFilterCollection->rangeFilters.erase(m_cellRangeFilterCollection->rangeFilters.size() - 1); - cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED); - cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED_INACTIVE); + m_cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED); + m_cellRangeFilterCollection->reservoirView()->scheduleGeometryRegen(RANGE_FILTERED_INACTIVE); - cellRangeFilterCollection->updateConnectedEditors(); + m_cellRangeFilterCollection->updateConnectedEditors(); } diff --git a/ApplicationCode/Commands/RicRangeFilterNewExec.h b/ApplicationCode/Commands/RicRangeFilterNewExec.h index 7bfb85b95d..111fa81881 100644 --- a/ApplicationCode/Commands/RicRangeFilterNewExec.h +++ b/ApplicationCode/Commands/RicRangeFilterNewExec.h @@ -19,36 +19,20 @@ #pragma once -#include "cafCmdExecuteCommand.h" -#include "cafPdmPointer.h" - -class RimCellRangeFilterCollection; +#include "RicRangeFilterExecImpl.h" //================================================================================================== /// //================================================================================================== -class RicRangeFilterNewExec : public caf::CmdExecuteCommand +class RicRangeFilterNewExec : public RicRangeFilterExecImpl { public: - RicRangeFilterNewExec(RimCellRangeFilterCollection* rangeFilterCollection); - + RicRangeFilterNewExec(RimCellRangeFilterCollection* rangeFilterCollection, RimCellRangeFilter* rangeFilter = 0); virtual ~RicRangeFilterNewExec(); virtual QString name(); virtual void redo(); virtual void undo(); - -public: - bool m_iSlice; - bool m_jSlice; - bool m_kSlice; - - int m_iSliceStart; - int m_jSliceStart; - int m_kSliceStart; - -private: - caf::PdmPointer cellRangeFilterCollection; };