diff --git a/ApplicationLibCode/Commands/ApplicationCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/ApplicationCommands/CMakeLists_files.cmake index e2d3a74038..3be6c63f93 100644 --- a/ApplicationLibCode/Commands/ApplicationCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/ApplicationCommands/CMakeLists_files.cmake @@ -20,6 +20,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicSaveProjectNoGlobalPathsFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicShowClassNamesFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicShowPlotDataCtxFeature.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -44,6 +45,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicSaveProjectNoGlobalPathsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicShowClassNamesFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicShowPlotDataCtxFeature.cpp ) list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataCtxFeature.cpp b/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataCtxFeature.cpp new file mode 100644 index 0000000000..d5f358191f --- /dev/null +++ b/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataCtxFeature.cpp @@ -0,0 +1,29 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022 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 "RicShowPlotDataCtxFeature.h" + +CAF_CMD_SOURCE_INIT( RicShowPlotDataCtxFeature, "RicShowPlotDataCtxFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicShowPlotDataCtxFeature::isCommandEnabled() +{ + return true; +} diff --git a/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataCtxFeature.h b/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataCtxFeature.h new file mode 100644 index 0000000000..bb703f03d1 --- /dev/null +++ b/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataCtxFeature.h @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022 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 "RicShowPlotDataFeature.h" + +//================================================================================================== +/// +//================================================================================================== +class RicShowPlotDataCtxFeature : public RicShowPlotDataFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; +}; diff --git a/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp b/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp index 7d3dc74ed2..4c70fd8d58 100644 --- a/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp +++ b/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp @@ -25,6 +25,7 @@ #include "RimGridCrossPlot.h" #include "RimGridCrossPlotCurve.h" +#include "RimPlot.h" #include "RimProject.h" #include "RimSummaryCrossPlot.h" #include "RimSummaryPlot.h" @@ -173,30 +174,26 @@ bool RicShowPlotDataFeature::isCommandEnabled() return true; } - auto selectedSummaryPlots = caf::selectedObjectsByType(); - if ( selectedSummaryPlots.size() > 0 ) + std::vector selection; + getSelection( selection ); + + int validPlots = 0; + + for ( auto plot : selection ) { - for ( auto c : selectedSummaryPlots ) + if ( dynamic_cast( plot ) ) { - if ( dynamic_cast( c ) ) - { - return false; - } + return false; } - return true; + if ( dynamic_cast( plot ) != nullptr || + ( dynamic_cast( plot ) != nullptr || dynamic_cast( plot ) != nullptr || + dynamic_cast( plot ) != nullptr ) ) + { + validPlots++; + } } - - auto wellLogPlots = caf::selectedObjectsByType(); - if ( wellLogPlots.size() > 0 ) return true; - - auto gridCrossPlots = caf::selectedObjectsByType(); - if ( gridCrossPlots.size() > 0 ) return true; - - auto vfpPlots = caf::selectedObjectsByType(); - if ( vfpPlots.size() > 0 ) return true; - - return false; + return ( validPlots > 0 ); } //-------------------------------------------------------------------------------------------------- @@ -220,10 +217,45 @@ void RicShowPlotDataFeature::onActionTriggered( bool isChecked ) this->disableModelChangeContribution(); - std::vector selectedSummaryPlots = caf::selectedObjectsByType(); - std::vector wellLogPlots = caf::selectedObjectsByType(); - std::vector crossPlots = caf::selectedObjectsByType(); - std::vector vfpPlots = caf::selectedObjectsByType(); + std::vector selection; + getSelection( selection ); + + std::vector selectedSummaryPlots; + std::vector wellLogPlots; + std::vector crossPlots; + std::vector vfpPlots; + + for ( auto plot : selection ) + { + auto sumPlot = dynamic_cast( plot ); + if ( sumPlot ) + { + selectedSummaryPlots.push_back( sumPlot ); + continue; + } + + auto wellPlot = dynamic_cast( plot ); + if ( wellPlot ) + { + wellLogPlots.push_back( wellPlot ); + continue; + } + + auto xPlot = dynamic_cast( plot ); + if ( xPlot ) + { + crossPlots.push_back( xPlot ); + continue; + } + + auto vfpPlot = dynamic_cast( plot ); + if ( vfpPlot ) + { + vfpPlots.push_back( vfpPlot ); + continue; + } + } + if ( selectedSummaryPlots.empty() && wellLogPlots.empty() && crossPlots.empty() && vfpPlots.empty() ) { CVF_ASSERT( false ); @@ -303,3 +335,24 @@ void RicShowPlotDataFeature::showTextWindow( const QString& title, const QString plotwindow->addToTemporaryWidgets( textWiget ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicShowPlotDataFeature::getSelection( std::vector& selection ) +{ + if ( sender() ) + { + QVariant userData = this->userData(); + if ( !userData.isNull() && userData.canConvert() ) + { + RimPlot* plot = static_cast( userData.value() ); + if ( plot ) selection.push_back( plot ); + } + } + + if ( selection.empty() ) + { + caf::SelectionManager::instance()->objectsByType( &selection ); + } +} diff --git a/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.h b/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.h index 3e3c4a36f8..a16effac74 100644 --- a/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.h +++ b/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.h @@ -21,8 +21,10 @@ #include "cafCmdFeature.h" #include +#include class RiuTabbedTextProvider; +class RimPlot; //================================================================================================== /// @@ -36,6 +38,9 @@ protected: void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; +private: + void getSelection( std::vector& selection ); + public: static void showTabbedTextWindow( RiuTabbedTextProvider* textProvider ); static void showTextWindow( const QString& title, const QString& text ); diff --git a/ApplicationLibCode/Commands/PlotBuilderCommands/RicSplitMultiPlotFeature.cpp b/ApplicationLibCode/Commands/PlotBuilderCommands/RicSplitMultiPlotFeature.cpp index 6bfa01c2d6..626e2d27f5 100644 --- a/ApplicationLibCode/Commands/PlotBuilderCommands/RicSplitMultiPlotFeature.cpp +++ b/ApplicationLibCode/Commands/PlotBuilderCommands/RicSplitMultiPlotFeature.cpp @@ -46,7 +46,7 @@ bool RicSplitMultiPlotFeature::isCommandEnabled() return ( ( plot->summaryCurves().size() > 1 ) || ( plot->curveSets().size() > 1 ) ); } - return false; + return true; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake index fe183d08c8..e1067d594c 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/CMakeLists_files.cmake @@ -44,6 +44,8 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicNewPlotAxisPropertiesFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicShowSummaryPlotManagerFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicPasteSummaryMultiPlotFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicDeleteSubPlotCtxFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicEditSummaryPlotCtxFeature.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -92,6 +94,8 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicNewPlotAxisPropertiesFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicShowSummaryPlotManagerFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicPasteSummaryMultiPlotFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicDeleteSubPlotCtxFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicEditSummaryPlotCtxFeature.cpp ) list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.cpp new file mode 100644 index 0000000000..b9b107e2c7 --- /dev/null +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.cpp @@ -0,0 +1,29 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022 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 "RicDeleteSubPlotCtxFeature.h" + +CAF_CMD_SOURCE_INIT( RicDeleteSubPlotCtxFeature, "RicDeleteSubPlotCtxFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicDeleteSubPlotCtxFeature::isCommandEnabled() +{ + return true; +} diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.h new file mode 100644 index 0000000000..e0643f4783 --- /dev/null +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicDeleteSubPlotCtxFeature.h @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022 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 "WellLogCommands/RicDeleteSubPlotFeature.h" + +//================================================================================================== +/// +//================================================================================================== +class RicDeleteSubPlotCtxFeature : public RicDeleteSubPlotFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; +}; diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotCtxFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotCtxFeature.cpp new file mode 100644 index 0000000000..93974aa1ac --- /dev/null +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotCtxFeature.cpp @@ -0,0 +1,29 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022 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 "RicEditSummaryPlotCtxFeature.h" + +CAF_CMD_SOURCE_INIT( RicEditSummaryPlotCtxFeature, "RicEditSummaryPlotCtxFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicEditSummaryPlotCtxFeature::isCommandEnabled() +{ + return true; +} diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotCtxFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotCtxFeature.h new file mode 100644 index 0000000000..b1e307fc72 --- /dev/null +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotCtxFeature.h @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022 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 "RicEditSummaryPlotFeature.h" + +//================================================================================================== +/// +//================================================================================================== +class RicEditSummaryPlotCtxFeature : public RicEditSummaryPlotFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; +}; diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.cpp index 1daab4da12..a12729fea4 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.cpp @@ -133,6 +133,16 @@ RimSummaryPlot* RicEditSummaryPlotFeature::selectedSummaryPlot() { RimSummaryPlot* sumPlot = nullptr; + if ( sender() ) + { + QVariant userData = this->userData(); + if ( !userData.isNull() && userData.canConvert() ) + { + RimSummaryPlot* plot = static_cast( userData.value() ); + if ( plot ) return plot; + } + } + caf::PdmObject* selObj = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); if ( selObj ) { diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.h b/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.h index 29dca7d6c0..816093a460 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.h +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicEditSummaryPlotFeature.h @@ -43,5 +43,5 @@ protected: void setupActionLook( QAction* actionToSetup ) override; private: - static RimSummaryPlot* selectedSummaryPlot(); + RimSummaryPlot* selectedSummaryPlot(); }; diff --git a/ApplicationLibCode/Commands/WellLogCommands/RicDeleteSubPlotFeature.cpp b/ApplicationLibCode/Commands/WellLogCommands/RicDeleteSubPlotFeature.cpp index 571c5c92c5..56b6cba8bf 100644 --- a/ApplicationLibCode/Commands/WellLogCommands/RicDeleteSubPlotFeature.cpp +++ b/ApplicationLibCode/Commands/WellLogCommands/RicDeleteSubPlotFeature.cpp @@ -44,29 +44,10 @@ bool RicDeleteSubPlotFeature::isCommandEnabled() { if ( RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot() ) return false; - std::vector selection; - caf::SelectionManager::instance()->objectsByType( &selection ); + std::vector selection; + getSelection( selection ); - if ( selection.size() > 0 ) - { - if ( dynamic_cast( selection.front() ) ) return false; - - size_t plotsSelected = 0; - for ( caf::PdmObject* object : selection ) - { - RimMultiPlot* multiPlot = nullptr; - RimWellLogPlot* wellLogPlot = nullptr; - object->firstAncestorOrThisOfType( multiPlot ); - object->firstAncestorOrThisOfType( wellLogPlot ); - if ( dynamic_cast( object ) && ( multiPlot || wellLogPlot ) ) - { - plotsSelected++; - } - } - return plotsSelected == selection.size(); - } - - return false; + return ( selection.size() > 0 ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp b/ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp index d6db4b0782..1e5a4a920e 100644 --- a/ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp @@ -59,7 +59,17 @@ void RiuSummaryPlot::showContextMenu( QPoint pos ) QMenu menu; caf::CmdFeatureMenuBuilder menuBuilder; - menuBuilder << "RicShowPlotDataFeature"; + RimSummaryPlot* plot = dynamic_cast( plotWidget()->plotDefinition() ); + if ( plot ) + { + QVariant plotVariant( QVariant::fromValue( static_cast( plot ) ) ); + menuBuilder.addCmdFeatureWithUserData( "RicShowPlotDataCtxFeature", "Show Plot Data", plotVariant ); + menuBuilder.addCmdFeatureWithUserData( "RicEditSummaryPlotCtxFeature", "Edit Plot", plotVariant ); + menuBuilder.addCmdFeatureWithUserData( "RicSplitMultiPlotFeature", "Split into Multiple Plots", plotVariant ); + menuBuilder.addSeparator(); + menuBuilder.addCmdFeatureWithUserData( "RicDeleteSubPlotCtxFeature", "Delete Plot", plotVariant ); + } + menuBuilder.addSeparator(); double distanceFromClick = std::numeric_limits::infinity(); @@ -192,16 +202,6 @@ void RiuSummaryPlot::showContextMenu( QPoint pos ) } } - menuBuilder.addSeparator(); - - RimSummaryPlot* plot = dynamic_cast( plotWidget()->plotDefinition() ); - if ( plot ) - { - QVariant plotVariant( QVariant::fromValue( static_cast( plot ) ) ); - menuBuilder.addCmdFeatureWithUserData( "RicSplitMultiPlotFeature", "Split into Multiple Plots", plotVariant ); - menuBuilder.addCmdFeatureWithUserData( "RicDeleteSubPlotFeature", "Delete Plot", plotVariant ); - } - menuBuilder.appendToMenu( &menu ); if ( !menu.actions().empty() )