#4822 Countour Map Export: Add export to context menu in 3D view

This commit is contained in:
Magne Sjaastad 2019-10-23 17:03:09 +02:00
parent 13bb85ccd5
commit 4c48f557b0
3 changed files with 74 additions and 11 deletions

View File

@ -32,6 +32,9 @@
#include "RimProject.h" #include "RimProject.h"
#include "RimViewWindow.h" #include "RimViewWindow.h"
#include "RiuViewer.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmUiPropertyViewDialog.h" #include "cafPdmUiPropertyViewDialog.h"
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
#include "cafUtils.h" #include "cafUtils.h"
@ -57,10 +60,13 @@ RicExportContourMapToTextFeature::RicExportContourMapToTextFeature()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicExportContourMapToTextFeature::isCommandEnabled() bool RicExportContourMapToTextFeature::isCommandEnabled()
{ {
RimEclipseContourMapView* existingEclipseContourMap = caf::SelectionManager::instance() RimEclipseContourMapView* existingEclipseContourMap = nullptr;
->selectedItemOfType<RimEclipseContourMapView>(); RimGeoMechContourMapView* existingGeoMechContourMap = nullptr;
RimGeoMechContourMapView* existingGeoMechContourMap = caf::SelectionManager::instance()
->selectedItemOfType<RimGeoMechContourMapView>(); auto sourceViews = findContourMapView();
existingEclipseContourMap = sourceViews.first;
existingGeoMechContourMap = sourceViews.second;
return existingEclipseContourMap || existingGeoMechContourMap; return existingEclipseContourMap || existingGeoMechContourMap;
} }
@ -69,14 +75,17 @@ bool RicExportContourMapToTextFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicExportContourMapToTextFeature::onActionTriggered( bool isChecked ) void RicExportContourMapToTextFeature::onActionTriggered( bool isChecked )
{ {
RimContourMapProjection* contourMapProjection = nullptr; RimEclipseContourMapView* existingEclipseContourMap = nullptr;
RimEclipseContourMapView* existingEclipseContourMap = caf::SelectionManager::instance() RimGeoMechContourMapView* existingGeoMechContourMap = nullptr;
->selectedItemOfType<RimEclipseContourMapView>();
RimGeoMechContourMapView* existingGeoMechContourMap = caf::SelectionManager::instance() auto sourceViews = findContourMapView();
->selectedItemOfType<RimGeoMechContourMapView>(); existingEclipseContourMap = sourceViews.first;
existingGeoMechContourMap = sourceViews.second;
CAF_ASSERT( existingEclipseContourMap || existingGeoMechContourMap ); CAF_ASSERT( existingEclipseContourMap || existingGeoMechContourMap );
QString contourMapName; RimContourMapProjection* contourMapProjection = nullptr;
QString contourMapName;
if ( existingEclipseContourMap ) if ( existingEclipseContourMap )
{ {
m_viewId = existingEclipseContourMap->id(); m_viewId = existingEclipseContourMap->id();
@ -212,6 +221,46 @@ void RicExportContourMapToTextFeature::writeContourMapToStream( QTextStream&
formatter.tableCompleted(); formatter.tableCompleted();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<RimEclipseContourMapView*, RimGeoMechContourMapView*> RicExportContourMapToTextFeature::findContourMapView()
{
RimEclipseContourMapView* existingEclipseContourMap = nullptr;
RimGeoMechContourMapView* existingGeoMechContourMap = nullptr;
auto contextMenuWidget = dynamic_cast<RiuViewer*>(
caf::CmdFeatureManager::instance()->currentContextMenuTargetWidget() );
if ( contextMenuWidget )
{
{
auto candidate = dynamic_cast<RimEclipseContourMapView*>( contextMenuWidget->ownerReservoirView() );
if ( candidate )
{
existingEclipseContourMap = candidate;
}
}
{
auto candidate = dynamic_cast<RimGeoMechContourMapView*>( contextMenuWidget->ownerReservoirView() );
if ( candidate )
{
existingGeoMechContourMap = candidate;
}
}
}
if ( !existingEclipseContourMap && !existingGeoMechContourMap )
{
existingEclipseContourMap = caf::SelectionManager::instance()->selectedItemOfType<RimEclipseContourMapView>();
existingGeoMechContourMap = caf::SelectionManager::instance()->selectedItemOfType<RimGeoMechContourMapView>();
}
auto pair = std::make_pair( existingEclipseContourMap, existingGeoMechContourMap );
return pair;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -22,7 +22,12 @@
#include "cafCmdFeature.h" #include "cafCmdFeature.h"
#include "cafPdmField.h" #include "cafPdmField.h"
#include <utility>
class RimContourMapProjection; class RimContourMapProjection;
class RimEclipseContourMapView;
class RimGeoMechContourMapView;
class QTextStream; class QTextStream;
//================================================================================================== //==================================================================================================
@ -52,6 +57,9 @@ protected:
const QString& undefinedValueLabel, const QString& undefinedValueLabel,
bool excludeUndefinedValues ); bool excludeUndefinedValues );
private:
static std::pair<RimEclipseContourMapView*, RimGeoMechContourMapView*> findContourMapView();
private: private:
caf::PdmField<QString> m_exportFileName; caf::PdmField<QString> m_exportFileName;
caf::PdmField<bool> m_exportLocalCoordinates; caf::PdmField<bool> m_exportLocalCoordinates;

View File

@ -213,7 +213,9 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
} }
} }
// Build menue // Build menus
caf::CmdFeatureManager::instance()->setCurrentContextMenuTargetWidget( m_viewer );
QMenu menu; QMenu menu;
caf::CmdFeatureMenuBuilder menuBuilder; caf::CmdFeatureMenuBuilder menuBuilder;
@ -548,6 +550,8 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
{ {
} }
menuBuilder << "RicExportContourMapToTextFeature";
menuBuilder.appendToMenu( &menu ); menuBuilder.appendToMenu( &menu );
if ( !menu.isEmpty() ) if ( !menu.isEmpty() )
@ -555,6 +559,8 @@ void RiuViewerCommands::displayContextMenu( QMouseEvent* event )
menu.exec( event->globalPos() ); menu.exec( event->globalPos() );
} }
caf::CmdFeatureManager::instance()->setCurrentContextMenuTargetWidget( nullptr );
// Delete items in temporary selection // Delete items in temporary selection
Riu3dSelectionManager::instance()->deleteAllItems( Riu3dSelectionManager::RUI_TEMPORARY ); Riu3dSelectionManager::instance()->deleteAllItems( Riu3dSelectionManager::RUI_TEMPORARY );
} }