From 2a59d86975607f376eda3baf1a25d067438f0481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Fri, 5 Oct 2018 11:49:44 +0200 Subject: [PATCH] #3450 #3445 LGR export. New command feature --- .../ExportCommands/CMakeLists_files.cmake | 4 + .../RicExportCarfinForCompletionsFeature.cpp | 187 ++++++++++++++++++ .../RicExportCarfinForCompletionsFeature.h | 43 ++++ .../RicExportCarfinForCompletionsUi.cpp | 166 ++++++++++++++++ .../RicExportCarfinForCompletionsUi.h | 69 +++++++ .../RimContextCommandBuilder.cpp | 4 + .../ProjectDataModel/RimDialogData.cpp | 12 ++ .../ProjectDataModel/RimDialogData.h | 3 + 8 files changed, 488 insertions(+) create mode 100644 ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsFeature.cpp create mode 100644 ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsFeature.h create mode 100644 ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsUi.cpp create mode 100644 ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsUi.h diff --git a/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake index b6b2959113..df65ddb8b7 100644 --- a/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake @@ -19,6 +19,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicSnapshotViewToFileFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicExportSelectedWellPathsFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicExportVisibleWellPathsFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicExportWellPathsUi.h +${CMAKE_CURRENT_LIST_DIR}/RicExportCarfinForCompletionsFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicExportCarfinForCompletionsUi.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -42,6 +44,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicSnapshotViewToFileFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicExportSelectedWellPathsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicExportVisibleWellPathsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicExportWellPathsUi.cpp +${CMAKE_CURRENT_LIST_DIR}/RicExportCarfinForCompletionsFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicExportCarfinForCompletionsUi.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsFeature.cpp new file mode 100644 index 0000000000..74f44f6e1b --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsFeature.cpp @@ -0,0 +1,187 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicExportCarfinForCompletionsFeature.h" + +#include "RiaApplication.h" + +#include "CompletionExportCommands/RicWellPathExportCompletionDataFeature.h" +#include "RicExportCarfinForCompletionsUi.h" + +#include "RimDialogData.h" +#include "RimEclipseCase.h" +#include "RimWellPath.h" +#include "RimProject.h" +#include "RimWellPathCollection.h" + +#include "RiuPlotMainWindow.h" + +#include +#include +#include + +#include +#include + + +CAF_CMD_SOURCE_INIT(RicExportCarfinForCompletionsFeature, "RicExportCarfinForCompletionsFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicExportCarfinForCompletionsUi* RicExportCarfinForCompletionsFeature::openDialog() +{ + RiaApplication* app = RiaApplication::instance(); + RimProject* proj = app->project(); + + QString startPath = app->lastUsedDialogDirectory("WELL_PATH_EXPORT_DIR"); + if (startPath.isEmpty()) + { + QFileInfo fi(proj->fileName()); + startPath = fi.absolutePath(); + } + + RicExportCarfinForCompletionsUi* featureUi = app->project()->dialogData()->exportCarfinForCompletionsData(); + if (featureUi->exportFolder().isEmpty()) + { + featureUi->setExportFolder(startPath); + } + + if (!featureUi->caseToApply()) + { + std::vector cases; + app->project()->allCases(cases); + for (auto c : cases) + { + RimEclipseCase* eclipseCase = dynamic_cast(c); + if (eclipseCase != nullptr) + { + featureUi->setCase(eclipseCase); + break; + } + } + } + + caf::PdmUiPropertyViewDialog propertyDialog(nullptr, featureUi, "Export Carfin", "", QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + propertyDialog.resize(QSize(600, 230)); + + if (propertyDialog.exec() == QDialog::Accepted && !featureUi->exportFolder().isEmpty()) + { + app->setLastUsedDialogDirectory("WELL_PATH_EXPORT_DIR", featureUi->exportFolder()); + return featureUi; + } + return nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicExportCarfinForCompletionsFeature::isCommandEnabled() +{ + std::vector wellPaths = caf::selectedObjectsByTypeStrict(); + + return !wellPaths.empty(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportCarfinForCompletionsFeature::onActionTriggered(bool isChecked) +{ + std::vector wellPaths = visibleWellPaths(); + CVF_ASSERT(wellPaths.size() > 0); + + std::vector simWells; + QString dialogTitle = "Export Carfin"; + + auto dialogData = openDialog(); + if (dialogData) + { + + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportCarfinForCompletionsFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Export Carfin"); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RicExportCarfinForCompletionsFeature::visibleWellPaths() +{ + std::vector wellPaths; + + { + std::vector wellPathCollections; + caf::SelectionManager::instance()->objectsByType(&wellPathCollections); + + if (wellPathCollections.empty()) + { + std::vector selectedWellPaths; + caf::SelectionManager::instance()->objectsByType(&selectedWellPaths); + + if (!selectedWellPaths.empty()) + { + RimWellPathCollection* parent = nullptr; + selectedWellPaths[0]->firstAncestorOrThisOfType(parent); + if (parent) + { + wellPathCollections.push_back(parent); + } + } + } + + if (!wellPathCollections.empty()) + { + for (auto wellPathCollection : wellPathCollections) + { + for (const auto& wellPath : wellPathCollection->wellPaths()) + { + if (wellPath->showWellPath()) + { + wellPaths.push_back(wellPath); + } + } + } + } + else + { + // No well path or well path collection selected + + auto allWellPaths = RiaApplication::instance()->project()->allWellPaths(); + for (const auto& w : allWellPaths) + { + if (w->showWellPath()) + { + wellPaths.push_back(w); + } + } + + } + } + + std::set uniqueWellPaths(wellPaths.begin(), wellPaths.end()); + wellPaths.assign(uniqueWellPaths.begin(), uniqueWellPaths.end()); + + return wellPaths; +} diff --git a/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsFeature.h b/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsFeature.h new file mode 100644 index 0000000000..7ddf108ebd --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsFeature.h @@ -0,0 +1,43 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "cafCmdFeature.h" + +class RimSimWellInView; +class RimWellPath; +class RicExportCarfinForCompletionsUi; + +//================================================================================================== +/// +//================================================================================================== +class RicExportCarfinForCompletionsFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + + static RicExportCarfinForCompletionsUi* openDialog(); + +protected: + virtual bool isCommandEnabled() override; + virtual void onActionTriggered(bool isChecked) override; + virtual void setupActionLook(QAction* actionToSetup) override; + +public: + static std::vector visibleWellPaths(); +}; diff --git a/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsUi.cpp b/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsUi.cpp new file mode 100644 index 0000000000..f0f69dae58 --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsUi.cpp @@ -0,0 +1,166 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicExportCarfinForCompletionsUi.h" + +#include "RicCellRangeUi.h" + +#include "RimEclipseCase.h" +#include "RimTools.h" + +#include "cafPdmUiFilePathEditor.h" +#include "cafVecIjk.h" + + +CAF_PDM_SOURCE_INIT(RicExportCarfinForCompletionsUi, "RicExportCarfinForCompletionsUi"); + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicExportCarfinForCompletionsUi::RicExportCarfinForCompletionsUi() +{ + CAF_PDM_InitObject("Export CARFIN", "", "", ""); + + CAF_PDM_InitFieldNoDefault(&m_exportFolder, "ExportFolder", "Export Folder", "", "", ""); + m_exportFolder.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); + + CAF_PDM_InitFieldNoDefault(&m_caseToApply, "CaseToApply", "Source Case", "", "", ""); + + CAF_PDM_InitField(&m_cellCountI, "CellCountI", 2, "Cell Count I", "", "", ""); + CAF_PDM_InitField(&m_cellCountJ, "CellCountJ", 2, "Cell Count J", "", "", ""); + CAF_PDM_InitField(&m_cellCountK, "CellCountK", 2, "Cell Count K", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportCarfinForCompletionsUi::setCase(RimEclipseCase* rimCase) +{ + bool isDifferent = (rimCase != m_caseToApply); + + if (isDifferent) + { + m_caseToApply = rimCase; + setDefaultValuesFromCase(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::VecIjk RicExportCarfinForCompletionsUi::lgrCellCount() const +{ + return caf::VecIjk (m_cellCountI, m_cellCountJ, m_cellCountK); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicExportCarfinForCompletionsUi::exportFolder() const +{ + return m_exportFolder(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseCase* RicExportCarfinForCompletionsUi::caseToApply() const +{ + return m_caseToApply(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportCarfinForCompletionsUi::setExportFolder(const QString& folder) +{ + m_exportFolder = folder; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportCarfinForCompletionsUi::setDefaultValuesFromCase() +{ + if (m_caseToApply) + { + QString caseFolder = m_caseToApply->locationOnDisc(); + m_exportFolder = caseFolder; + } + + m_cellCountI = 2; + m_cellCountJ = 2; + m_cellCountK = 2; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QList RicExportCarfinForCompletionsUi::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) +{ + QList options; + + if (fieldNeedingOptions == &m_caseToApply) + { + RimTools::caseOptionItems(&options); + } + + return options; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportCarfinForCompletionsUi::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +{ + if (changedField == &m_caseToApply) + { + setDefaultValuesFromCase(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportCarfinForCompletionsUi::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) +{ + uiOrdering.add(&m_caseToApply); + uiOrdering.add(&m_exportFolder); + + caf::PdmUiGroup* gridRefinement = uiOrdering.addNewGroup("Grid Refinement"); + gridRefinement->add(&m_cellCountI); + gridRefinement->add(&m_cellCountJ); + gridRefinement->add(&m_cellCountK); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicExportCarfinForCompletionsUi::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) +{ + if (field == &m_exportFolder) + { + caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast(attribute); + if (myAttr) + { + myAttr->m_selectSaveFileName = true; + } + } +} + diff --git a/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsUi.h b/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsUi.h new file mode 100644 index 0000000000..fe45e3e943 --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicExportCarfinForCompletionsUi.h @@ -0,0 +1,69 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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" +#include "cafPdmPtrField.h" + +class RimEclipseCase; +class RicCellRangeUi; + +namespace caf { + class VecIjk; +} + +//================================================================================================== +/// +//================================================================================================== +class RicExportCarfinForCompletionsUi : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; + +public: + enum LgrSplitType { PER_CELL_LGR, SINGLE_LGR}; + + RicExportCarfinForCompletionsUi(); + + void setCase(RimEclipseCase* rimCase); + + caf::VecIjk lgrCellCount() const; + QString exportFolder() const; + RimEclipseCase* caseToApply() const; + + void setExportFolder(const QString& folder); + +private: + void setDefaultValuesFromCase(); + + virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override; + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; + virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; + virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override; + + +private: + caf::PdmField m_exportFolder; + caf::PdmPtrField m_caseToApply; + + caf::PdmField m_cellCountI; + caf::PdmField m_cellCountJ; + caf::PdmField m_cellCountK; +}; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index dfa446cd09..92906485c6 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -307,6 +307,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicExportVisibleWellPathsFeature"; menuBuilder.subMenuEnd(); + menuBuilder << "RicExportCarfinForCompletionsFeature"; + if ( dynamic_cast(uiItem) ) { menuBuilder << "RicShowWellPlanFeature"; @@ -766,6 +768,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder.subMenuEnd(); } + + menuBuilder << "RicExportCarfinForCompletionsFeature"; } menuBuilder << "RicCreateMultipleFracturesFeature"; diff --git a/ApplicationCode/ProjectDataModel/RimDialogData.cpp b/ApplicationCode/ProjectDataModel/RimDialogData.cpp index c8bb34c94d..0404d62ab2 100644 --- a/ApplicationCode/ProjectDataModel/RimDialogData.cpp +++ b/ApplicationCode/ProjectDataModel/RimDialogData.cpp @@ -23,6 +23,7 @@ #include "FractureCommands/RicCreateMultipleFracturesUi.h" #include "HoloLensCommands/RicHoloLensExportToFolderUi.h" #include "ExportCommands/RicExportWellPathsUi.h" +#include "ExportCommands/RicExportCarfinForCompletionsUi.h" CAF_PDM_SOURCE_INIT(RimDialogData, "RimDialogData"); @@ -47,6 +48,9 @@ RimDialogData::RimDialogData() CAF_PDM_InitFieldNoDefault(&m_exportWellPathsData, "ExportwellPathsData", "Export Well Paths Data", "", "", ""); m_exportWellPathsData = new RicExportWellPathsUi(); + + CAF_PDM_InitFieldNoDefault(&m_exportCarfinForCompletionsData, "ExportCarfinForCompletions", "Export Carfin", "", "", ""); + m_exportCarfinForCompletionsData = new RicExportCarfinForCompletionsUi(); } //-------------------------------------------------------------------------------------------------- @@ -114,3 +118,11 @@ RicExportWellPathsUi* RimDialogData::wellPathsExportData() const return m_exportWellPathsData; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicExportCarfinForCompletionsUi* RimDialogData::exportCarfinForCompletionsData() const +{ + return m_exportCarfinForCompletionsData; +} + diff --git a/ApplicationCode/ProjectDataModel/RimDialogData.h b/ApplicationCode/ProjectDataModel/RimDialogData.h index 55b8679824..8fd388636b 100644 --- a/ApplicationCode/ProjectDataModel/RimDialogData.h +++ b/ApplicationCode/ProjectDataModel/RimDialogData.h @@ -26,6 +26,7 @@ class RicExportCompletionDataSettingsUi; class RiuCreateMultipleFractionsUi; class RicHoloLensExportToFolderUi; class RicExportWellPathsUi; +class RicExportCarfinForCompletionsUi; //================================================================================================== /// @@ -55,6 +56,7 @@ public: RiuCreateMultipleFractionsUi* multipleFractionsData() const; RicHoloLensExportToFolderUi* holoLensExportToFolderData() const; RicExportWellPathsUi* wellPathsExportData() const; + RicExportCarfinForCompletionsUi* exportCarfinForCompletionsData() const; private: caf::PdmChildField m_exportCarfin; @@ -62,4 +64,5 @@ private: caf::PdmChildField m_multipleFractionsData; caf::PdmChildField m_holoLenseExportToFolderData; caf::PdmChildField m_exportWellPathsData; + caf::PdmChildField m_exportCarfinForCompletionsData; };