diff --git a/ApplicationCode/Commands/CompletionCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/CompletionCommands/CMakeLists_files.cmake index 866a15cee4..d8ba86a90d 100644 --- a/ApplicationCode/Commands/CompletionCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CompletionCommands/CMakeLists_files.cmake @@ -8,6 +8,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicNewPerforationIntervalFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewPerforationIntervalAtMeasuredDepthFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewValveFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewValveTemplateFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicDeleteValveTemplateFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicWellPathImportCompletionsFileFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicWellPathImportPerforationIntervalsFeature.h ) @@ -21,6 +22,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicNewPerforationIntervalFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewPerforationIntervalAtMeasuredDepthFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewValveFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewValveTemplateFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicDeleteValveTemplateFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicWellPathImportCompletionsFileFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicWellPathImportPerforationIntervalsFeature.cpp ) diff --git a/ApplicationCode/Commands/CompletionCommands/RicDeleteValveTemplateFeature.cpp b/ApplicationCode/Commands/CompletionCommands/RicDeleteValveTemplateFeature.cpp new file mode 100644 index 0000000000..0125acde7c --- /dev/null +++ b/ApplicationCode/Commands/CompletionCommands/RicDeleteValveTemplateFeature.cpp @@ -0,0 +1,82 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor 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 "RicDeleteValveTemplateFeature.h" + +#include "RimProject.h" +#include "RimValveTemplate.h" +#include "RimValveTemplateCollection.h" +#include "RimWellPathValve.h" + +#include "cafSelectionManager.h" + +#include + +CAF_CMD_SOURCE_INIT(RicDeleteValveTemplateFeature, "RicDeleteValveTemplateFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicDeleteValveTemplateFeature::isCommandEnabled() +{ + if (caf::SelectionManager::instance()->selectedItemOfType()) + { + return true; + } + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicDeleteValveTemplateFeature::onActionTriggered(bool isChecked) +{ + RimValveTemplate* valveTemplate = caf::SelectionManager::instance()->selectedItemOfType(); + + if (valveTemplate) + { + RimProject* project = nullptr; + valveTemplate->firstAncestorOrThisOfTypeAsserted(project); + std::vector valves; + project->descendantsIncludingThisOfType(valves); + for (RimWellPathValve* valve : valves) + { + if (valve->valveTemplate() == valveTemplate) + { + valve->setValveTemplate(nullptr); + valve->updateAllRequiredEditors(); + } + } + + RimValveTemplateCollection* collection = nullptr; + valveTemplate->firstAncestorOrThisOfTypeAsserted(collection); + collection->removeAndDeleteValveTemplate(valveTemplate); + collection->updateAllRequiredEditors(); + + project->scheduleCreateDisplayModelAndRedrawAllViews(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicDeleteValveTemplateFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Delete Valve Template"); + actionToSetup->setIcon(QIcon(":/Erase.png")); +} + diff --git a/ApplicationCode/Commands/CompletionCommands/RicDeleteValveTemplateFeature.h b/ApplicationCode/Commands/CompletionCommands/RicDeleteValveTemplateFeature.h new file mode 100644 index 0000000000..caed93c6d5 --- /dev/null +++ b/ApplicationCode/Commands/CompletionCommands/RicDeleteValveTemplateFeature.h @@ -0,0 +1,35 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor 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 RicDeleteValveTemplateFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + // Overrides + bool isCommandEnabled() override; + void onActionTriggered(bool isChecked) override; + void setupActionLook(QAction* actionToSetup) override; +}; diff --git a/ApplicationCode/Commands/CompletionCommands/RicNewValveTemplateFeature.cpp b/ApplicationCode/Commands/CompletionCommands/RicNewValveTemplateFeature.cpp index 794cae44c8..aea3fa3cde 100644 --- a/ApplicationCode/Commands/CompletionCommands/RicNewValveTemplateFeature.cpp +++ b/ApplicationCode/Commands/CompletionCommands/RicNewValveTemplateFeature.cpp @@ -25,6 +25,7 @@ #include "RimValveTemplateCollection.h" #include "RimOilField.h" #include "RimProject.h" +#include "RimWellPathValve.h" #include "Riu3DMainWindowTools.h" @@ -39,12 +40,16 @@ CAF_CMD_SOURCE_INIT(RicNewValveTemplateFeature, "RicNewValveTemplateFeature"); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicNewValveTemplateFeature::selectValveTemplateAndUpdate(RimValveTemplateCollection* templateCollection, - RimValveTemplate* valveTemplate) +void RicNewValveTemplateFeature::selectValveTemplateAndUpdate(RimValveTemplate* valveTemplate) { valveTemplate->loadDataAndUpdate(); - templateCollection->updateConnectedEditors(); + RimValveTemplateCollection* templateCollection = nullptr; + valveTemplate->firstAncestorOrThisOfType(templateCollection); + if (templateCollection) + { + templateCollection->updateConnectedEditors(); + } RimProject* project = RiaApplication::instance()->project(); @@ -65,26 +70,48 @@ void RicNewValveTemplateFeature::selectValveTemplateAndUpdate(RimValveTemplateCo //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicNewValveTemplateFeature::onActionTriggered(bool isChecked) +void RicNewValveTemplateFeature::createNewValveTemplateForValveAndUpdate(RimWellPathValve* valve) +{ + RimValveTemplate* valveTemplate = createNewValveTemplate(); + valve->setValveTemplate(valveTemplate); + selectValveTemplateAndUpdate(valveTemplate); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimValveTemplate* RicNewValveTemplateFeature::createNewValveTemplate() { RimProject* project = RiaApplication::instance()->project(); CVF_ASSERT(project); RimOilField* oilfield = project->activeOilField(); - if (oilfield == nullptr) return; + if (oilfield == nullptr) return nullptr; RimValveTemplateCollection* valveTemplateColl = oilfield->valveTemplateCollection(); if (valveTemplateColl) { RimValveTemplate* valveTemplate = new RimValveTemplate(); - QString userLabel = QString("Valve Template #%1").arg(valveTemplateColl->valveTemplates().size() + 1); + QString userLabel = QString("Valve Template #%1").arg(valveTemplateColl->valveTemplates().size() + 1); valveTemplate->setUserLabel(userLabel); valveTemplateColl->addValveTemplate(valveTemplate); valveTemplate->setUnitSystem(valveTemplateColl->defaultUnitSystemType()); valveTemplate->setDefaultValuesFromUnits(); + return valveTemplate; + } + return nullptr; +} - selectValveTemplateAndUpdate(valveTemplateColl, valveTemplate); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicNewValveTemplateFeature::onActionTriggered(bool isChecked) +{ + RimValveTemplate* valveTemplate = createNewValveTemplate(); + if (valveTemplate) + { + selectValveTemplateAndUpdate(valveTemplate); } } diff --git a/ApplicationCode/Commands/CompletionCommands/RicNewValveTemplateFeature.h b/ApplicationCode/Commands/CompletionCommands/RicNewValveTemplateFeature.h index 6cb54222fc..fa2aa61480 100644 --- a/ApplicationCode/Commands/CompletionCommands/RicNewValveTemplateFeature.h +++ b/ApplicationCode/Commands/CompletionCommands/RicNewValveTemplateFeature.h @@ -24,6 +24,7 @@ class RimValveTemplate; class RimValveTemplateCollection; +class RimWellPathValve; //================================================================================================== /// @@ -33,10 +34,10 @@ class RicNewValveTemplateFeature : public caf::CmdFeature CAF_CMD_HEADER_INIT; public: - static void selectValveTemplateAndUpdate(RimValveTemplateCollection* templateCollection, - RimValveTemplate* valveTemplate); - + static void selectValveTemplateAndUpdate(RimValveTemplate* valveTemplate); + static void createNewValveTemplateForValveAndUpdate(RimWellPathValve* valve); protected: + static RimValveTemplate* createNewValveTemplate(); void onActionTriggered(bool isChecked) override; void setupActionLook(QAction* actionToSetup) override; bool isCommandEnabled() override; diff --git a/ApplicationCode/Commands/RicDeleteItemExec.cpp b/ApplicationCode/Commands/RicDeleteItemExec.cpp index 439c976f23..a4f10ee4bb 100644 --- a/ApplicationCode/Commands/RicDeleteItemExec.cpp +++ b/ApplicationCode/Commands/RicDeleteItemExec.cpp @@ -51,8 +51,6 @@ #include "RiuPlotMainWindow.h" #include "RimFractureTemplateCollection.h" -#include "RimValveTemplateCollection.h" - #include "cafNotificationCenter.h" #include "cafPdmChildArrayField.h" @@ -156,11 +154,9 @@ void RicDeleteItemExec::redo() } - RimValveTemplateCollection* valveTemplateColl; RimFractureTemplateCollection* fracTemplateColl; parentObj->firstAncestorOrThisOfType(fracTemplateColl); - parentObj->firstAncestorOrThisOfType(valveTemplateColl); - if (fracTemplateColl || valveTemplateColl) + if (fracTemplateColl) { RimProject* proj = nullptr; parentObj->firstAncestorOrThisOfType(proj); diff --git a/ApplicationCode/Commands/RicDeleteItemFeature.cpp b/ApplicationCode/Commands/RicDeleteItemFeature.cpp index 968b5d12a7..075bcdd279 100644 --- a/ApplicationCode/Commands/RicDeleteItemFeature.cpp +++ b/ApplicationCode/Commands/RicDeleteItemFeature.cpp @@ -60,7 +60,6 @@ #include "RimSimWellFracture.h" #include "RimSimWellFractureCollection.h" #include "RimStimPlanFractureTemplate.h" -#include "RimValveTemplate.h" #include "RimWellPathFracture.h" #include "RimWellPathFractureCollection.h" @@ -123,7 +122,6 @@ bool isDeletable(caf::PdmUiItem* uiItem) if (dynamic_cast(uiItem)) return true; if (dynamic_cast(uiItem)) return true; if (dynamic_cast(uiItem)) return true; - if (dynamic_cast(uiItem)) return true; if (dynamic_cast(uiItem)) return true; if (dynamic_cast(uiItem)) return true; if (dynamic_cast(uiItem)) return true; diff --git a/ApplicationCode/ProjectDataModel/Completions/RimValveTemplate.h b/ApplicationCode/ProjectDataModel/Completions/RimValveTemplate.h index b25d45559f..aa61c6f90a 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimValveTemplate.h +++ b/ApplicationCode/ProjectDataModel/Completions/RimValveTemplate.h @@ -47,7 +47,6 @@ public: QString typeLabel() const; QString fullLabel() const; void setUserLabel(const QString& userLabel); - protected: QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override; @@ -68,6 +67,5 @@ private: caf::PdmField m_flowCoefficient; // AICDs caf::PdmChildField m_aicdParameters; - }; diff --git a/ApplicationCode/ProjectDataModel/Completions/RimValveTemplateCollection.cpp b/ApplicationCode/ProjectDataModel/Completions/RimValveTemplateCollection.cpp index 2f1c1a173f..0aacd531b8 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimValveTemplateCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Completions/RimValveTemplateCollection.cpp @@ -66,6 +66,15 @@ void RimValveTemplateCollection::addValveTemplate(RimValveTemplate* valveTemplat m_valveDefinitions.push_back(valveTemplate); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimValveTemplateCollection::removeAndDeleteValveTemplate(RimValveTemplate* valveTemplate) +{ + m_valveDefinitions.removeChildObject(valveTemplate); + delete valveTemplate; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Completions/RimValveTemplateCollection.h b/ApplicationCode/ProjectDataModel/Completions/RimValveTemplateCollection.h index 3d559645c3..a6bfe3f814 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimValveTemplateCollection.h +++ b/ApplicationCode/ProjectDataModel/Completions/RimValveTemplateCollection.h @@ -40,6 +40,7 @@ public: std::vector valveTemplates() const; void addValveTemplate(RimValveTemplate* valveTemplate); + void removeAndDeleteValveTemplate(RimValveTemplate* valveTemplate); RiaEclipseUnitTools::UnitSystemType defaultUnitSystemType() const; void setDefaultUnitSystemBasedOnLoadedCases(); diff --git a/ApplicationCode/ProjectDataModel/Completions/RimWellPathValve.cpp b/ApplicationCode/ProjectDataModel/Completions/RimWellPathValve.cpp index 4708ebce08..505f389f4a 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimWellPathValve.cpp +++ b/ApplicationCode/ProjectDataModel/Completions/RimWellPathValve.cpp @@ -22,6 +22,8 @@ #include "RiaColorTables.h" #include "RiaEclipseUnitTools.h" +#include "Riu3DMainWindowTools.h" + #include "RigWellPath.h" #include "RimMultipleValveLocations.h" @@ -30,7 +32,10 @@ #include "RimValveTemplate.h" #include "RimWellPath.h" +#include "CompletionCommands/RicNewValveTemplateFeature.h" + #include "cafPdmUiDoubleSliderEditor.h" +#include "cafPdmUiToolButtonEditor.h" CAF_PDM_SOURCE_INIT(RimWellPathValve, "WellPathValve"); @@ -42,14 +47,15 @@ RimWellPathValve::RimWellPathValve() CAF_PDM_InitObject("WellPathValve", ":/ICDValve16x16.png", "", ""); CAF_PDM_InitFieldNoDefault(&m_valveTemplate, "ValveTemplate", "Valve Template", "", "", ""); - - CAF_PDM_InitField(&m_measuredDepth, "StartMeasuredDepth", 0.0, "Start MD", "", "", ""); - m_measuredDepth.uiCapability()->setUiEditorTypeName(caf::PdmUiDoubleSliderEditor::uiEditorTypeName()); - + CAF_PDM_InitField(&m_measuredDepth, "StartMeasuredDepth", 0.0, "Start MD", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_multipleValveLocations, "ValveLocations", "Valve Locations", "", "", ""); + CAF_PDM_InitField(&m_createOrEditValveTemplate, "CreateTemplate", false, "Create new", "", "", ""); + + m_measuredDepth.uiCapability()->setUiEditorTypeName(caf::PdmUiDoubleSliderEditor::uiEditorTypeName()); m_multipleValveLocations = new RimMultipleValveLocations; m_multipleValveLocations.uiCapability()->setUiTreeHidden(true); m_multipleValveLocations.uiCapability()->setUiTreeChildrenHidden(true); + m_createOrEditValveTemplate.uiCapability()->setUiEditorTypeName(caf::PdmUiToolButtonEditor::uiEditorTypeName()); nameField()->uiCapability()->setUiReadOnly(true); } @@ -150,6 +156,14 @@ double RimWellPathValve::flowCoefficient() const return 0.0; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimValveTemplate* RimWellPathValve::valveTemplate() const +{ + return m_valveTemplate; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -407,6 +421,18 @@ void RimWellPathValve::fieldChangedByUi(const caf::PdmFieldHandle* changedField, applyValveLabelAndIcon(); this->updateConnectedEditors(); } + else if (changedField == &m_createOrEditValveTemplate) + { + m_createOrEditValveTemplate = false; + if (m_valveTemplate == nullptr) + { + RicNewValveTemplateFeature::createNewValveTemplateForValveAndUpdate(this); + } + else + { + Riu3DMainWindowTools::selectAsCurrentItem(m_valveTemplate()); + } + } RimPerforationInterval* perfInterval; this->firstAncestorOrThisOfTypeAsserted(perfInterval); @@ -426,7 +452,23 @@ void RimWellPathValve::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering uiOrdering.add(&m_valveTemplate); - if (componentType() == RiaDefines::UNDEFINED_COMPONENT) return; + { + uiOrdering.add(&m_createOrEditValveTemplate, false); + if (m_valveTemplate() == nullptr) + { + m_createOrEditValveTemplate.uiCapability()->setUiName("New"); + } + else + { + m_createOrEditValveTemplate.uiCapability()->setUiName("Edit"); + } + } + + if (m_valveTemplate()) + { + caf::PdmUiGroup* group = uiOrdering.addNewGroup("Parameters from Template"); + m_valveTemplate->uiOrdering("InsideValve", *group); + } if (componentType() == RiaDefines::ICV || componentType() == RiaDefines::ICD) { @@ -454,13 +496,8 @@ void RimWellPathValve::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering caf::PdmUiGroup* group = uiOrdering.addNewGroup("Multiple Valve Locations"); m_multipleValveLocations->uiOrdering(uiConfigName, *group); } - - if (m_valveTemplate) - { - caf::PdmUiGroup* group = uiOrdering.addNewGroup("Parameters from Template"); - m_valveTemplate->uiOrdering("InsideValve", *group); - } - + + uiOrdering.skipRemainingFields(true); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Completions/RimWellPathValve.h b/ApplicationCode/ProjectDataModel/Completions/RimWellPathValve.h index 4b27827214..993a7fc18a 100644 --- a/ApplicationCode/ProjectDataModel/Completions/RimWellPathValve.h +++ b/ApplicationCode/ProjectDataModel/Completions/RimWellPathValve.h @@ -50,6 +50,7 @@ public: std::vector valveLocations() const; double orificeDiameter(RiaEclipseUnitTools::UnitSystem unitSystem) const; double flowCoefficient() const; + RimValveTemplate* valveTemplate() const; void setValveTemplate(RimValveTemplate* valveTemplate); void applyValveLabelAndIcon(); const RimWellPathAicdParameters* aicdParameters() const; @@ -82,7 +83,7 @@ private: caf::PdmPtrField m_valveTemplate; caf::PdmField m_measuredDepth; caf::PdmChildField m_multipleValveLocations; - + caf::PdmField m_createOrEditValveTemplate; }; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 621ad1c5ef..e1a2c28ee2 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -664,6 +664,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() { menuBuilder << "RicNewValveTemplateFeature"; } + else if (dynamic_cast(uiItem)) + { + menuBuilder << "RicDeleteValveTemplateFeature"; + } else if (dynamic_cast(uiItem)) { menuBuilder << "RicPasteEllipseFractureFeature";