diff --git a/ApplicationCode/Commands/RicExportContourMapToTextFeature.cpp b/ApplicationCode/Commands/RicExportContourMapToTextFeature.cpp index 11ae7e1f43..128d537f4f 100644 --- a/ApplicationCode/Commands/RicExportContourMapToTextFeature.cpp +++ b/ApplicationCode/Commands/RicExportContourMapToTextFeature.cpp @@ -32,6 +32,9 @@ #include "RimProject.h" #include "RimViewWindow.h" +#include "RiuViewer.h" + +#include "cafCmdFeatureManager.h" #include "cafPdmUiPropertyViewDialog.h" #include "cafSelectionManager.h" #include "cafUtils.h" @@ -57,10 +60,13 @@ RicExportContourMapToTextFeature::RicExportContourMapToTextFeature() //-------------------------------------------------------------------------------------------------- bool RicExportContourMapToTextFeature::isCommandEnabled() { - RimEclipseContourMapView* existingEclipseContourMap = caf::SelectionManager::instance() - ->selectedItemOfType(); - RimGeoMechContourMapView* existingGeoMechContourMap = caf::SelectionManager::instance() - ->selectedItemOfType(); + RimEclipseContourMapView* existingEclipseContourMap = nullptr; + RimGeoMechContourMapView* existingGeoMechContourMap = nullptr; + + auto sourceViews = findContourMapView(); + existingEclipseContourMap = sourceViews.first; + existingGeoMechContourMap = sourceViews.second; + return existingEclipseContourMap || existingGeoMechContourMap; } @@ -69,14 +75,17 @@ bool RicExportContourMapToTextFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicExportContourMapToTextFeature::onActionTriggered( bool isChecked ) { - RimContourMapProjection* contourMapProjection = nullptr; - RimEclipseContourMapView* existingEclipseContourMap = caf::SelectionManager::instance() - ->selectedItemOfType(); - RimGeoMechContourMapView* existingGeoMechContourMap = caf::SelectionManager::instance() - ->selectedItemOfType(); + RimEclipseContourMapView* existingEclipseContourMap = nullptr; + RimGeoMechContourMapView* existingGeoMechContourMap = nullptr; + + auto sourceViews = findContourMapView(); + existingEclipseContourMap = sourceViews.first; + existingGeoMechContourMap = sourceViews.second; + CAF_ASSERT( existingEclipseContourMap || existingGeoMechContourMap ); - QString contourMapName; + RimContourMapProjection* contourMapProjection = nullptr; + QString contourMapName; if ( existingEclipseContourMap ) { m_viewId = existingEclipseContourMap->id(); @@ -212,6 +221,46 @@ void RicExportContourMapToTextFeature::writeContourMapToStream( QTextStream& formatter.tableCompleted(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair RicExportContourMapToTextFeature::findContourMapView() +{ + RimEclipseContourMapView* existingEclipseContourMap = nullptr; + RimGeoMechContourMapView* existingGeoMechContourMap = nullptr; + + auto contextMenuWidget = dynamic_cast( + caf::CmdFeatureManager::instance()->currentContextMenuTargetWidget() ); + + if ( contextMenuWidget ) + { + { + auto candidate = dynamic_cast( contextMenuWidget->ownerReservoirView() ); + if ( candidate ) + { + existingEclipseContourMap = candidate; + } + } + { + auto candidate = dynamic_cast( contextMenuWidget->ownerReservoirView() ); + if ( candidate ) + { + existingGeoMechContourMap = candidate; + } + } + } + + if ( !existingEclipseContourMap && !existingGeoMechContourMap ) + { + existingEclipseContourMap = caf::SelectionManager::instance()->selectedItemOfType(); + existingGeoMechContourMap = caf::SelectionManager::instance()->selectedItemOfType(); + } + + auto pair = std::make_pair( existingEclipseContourMap, existingGeoMechContourMap ); + + return pair; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/RicExportContourMapToTextFeature.h b/ApplicationCode/Commands/RicExportContourMapToTextFeature.h index 962e715620..9719bf02ce 100644 --- a/ApplicationCode/Commands/RicExportContourMapToTextFeature.h +++ b/ApplicationCode/Commands/RicExportContourMapToTextFeature.h @@ -22,7 +22,12 @@ #include "cafCmdFeature.h" #include "cafPdmField.h" +#include + class RimContourMapProjection; +class RimEclipseContourMapView; +class RimGeoMechContourMapView; + class QTextStream; //================================================================================================== @@ -52,6 +57,9 @@ protected: const QString& undefinedValueLabel, bool excludeUndefinedValues ); +private: + static std::pair findContourMapView(); + private: caf::PdmField m_exportFileName; caf::PdmField m_exportLocalCoordinates; diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index 4943bf7393..ac8dc0023c 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -213,7 +213,9 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event ) } } - // Build menue + // Build menus + + caf::CmdFeatureManager::instance()->setCurrentContextMenuTargetWidget( m_viewer ); QMenu menu; caf::CmdFeatureMenuBuilder menuBuilder; @@ -548,6 +550,8 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event ) { } + menuBuilder << "RicExportContourMapToTextFeature"; + menuBuilder.appendToMenu( &menu ); if ( !menu.isEmpty() ) @@ -555,6 +559,8 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event ) menu.exec( event->globalPos() ); } + caf::CmdFeatureManager::instance()->setCurrentContextMenuTargetWidget( nullptr ); + // Delete items in temporary selection Riu3dSelectionManager::instance()->deleteAllItems( Riu3dSelectionManager::RUI_TEMPORARY ); }