Files
ResInsight/ApplicationLibCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp
T

201 lines
7.0 KiB
C++
Raw Normal View History

2017-03-15 20:15:04 +01:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
2017-03-15 20:15:04 +01:00
// 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.
//
2017-03-15 20:15:04 +01:00
// 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 <http://www.gnu.org/licenses/gpl.html>
2017-03-15 20:15:04 +01:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicShowPlotDataFeature.h"
#include "RiaFeatureCommandContext.h"
2019-05-06 10:36:05 +02:00
#include "RiaGuiApplication.h"
2017-03-15 20:15:04 +01:00
#include "SummaryPlotCommands/RicAsciiExportSummaryPlotFeature.h"
2017-03-15 20:15:04 +01:00
#include "RimPlainPlotDataProducer.h"
#include "RimPlot.h"
#include "RimPlotWindow.h"
#include "RimReportPlotGroup.h"
#include "RimTabbedTextProducer.h"
#include "RimTabbedTextProvider.h"
2018-04-27 06:28:08 +02:00
#include "RiuPlotMainWindow.h"
#include "RiuTextDialog.h"
2017-03-15 20:15:04 +01:00
#include "cafSelectionManagerTools.h"
2017-03-15 20:15:04 +01:00
#include <QAction>
CAF_CMD_SOURCE_INIT( RicShowPlotDataFeature, "RicShowPlotDataFeature" );
2017-03-15 20:15:04 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-06-26 14:28:46 +02:00
bool RicShowPlotDataFeature::isCommandEnabled() const
2017-03-15 20:15:04 +01:00
{
QString content = RiaFeatureCommandContext::instance()->contentString();
if ( !content.isEmpty() )
{
return true;
}
std::vector<RimPlotWindow*> selection;
getSelection( selection );
for ( auto plot : selection )
{
if ( dynamic_cast<const RimTabbedTextProducer*>( plot ) ) return true;
if ( dynamic_cast<const RimReportPlotGroup*>( plot ) ) return true;
if ( dynamic_cast<const RimPlainPlotDataProducer*>( plot ) ) return true;
}
return false;
2017-03-15 20:15:04 +01:00
}
//--------------------------------------------------------------------------------------------------
///
2017-03-15 20:15:04 +01:00
//--------------------------------------------------------------------------------------------------
void RicShowPlotDataFeature::onActionTriggered( bool isChecked )
2017-03-15 20:15:04 +01:00
{
QString content = RiaFeatureCommandContext::instance()->contentString();
if ( !content.isEmpty() )
{
QString title = "Data Content";
{
QString titleCandidate = RiaFeatureCommandContext::instance()->titleString();
if ( !titleCandidate.isEmpty() ) title = titleCandidate;
}
RicShowPlotDataFeature::showTextWindow( title, content );
return;
}
disableModelChangeContribution();
std::vector<RimPlotWindow*> selection;
getSelection( selection );
auto showPlainForProducer = []( RimPlainPlotDataProducer* producer )
{
QString title = producer->description();
QString text = title + "\n\n" + producer->asciiDataForPlotExport();
RicShowPlotDataFeature::showTextWindow( title, text );
};
for ( auto* plot : selection )
{
if ( auto* producer = dynamic_cast<RimTabbedTextProducer*>( plot ) )
{
RicShowPlotDataFeature::showTabbedTextWindow( producer->createTabbedTextProvider() );
continue;
}
2023-01-18 09:18:00 +01:00
if ( auto* group = dynamic_cast<RimReportPlotGroup*>( plot ) )
{
for ( auto* child : group->childPlotsForTextExport() )
{
if ( child ) showPlainForProducer( child );
}
continue;
}
if ( auto* plainProducer = dynamic_cast<RimPlainPlotDataProducer*>( plot ) )
2023-01-18 09:18:00 +01:00
{
showPlainForProducer( plainProducer );
2023-01-18 09:18:00 +01:00
}
}
2017-03-15 20:15:04 +01:00
}
//--------------------------------------------------------------------------------------------------
///
2017-03-15 20:15:04 +01:00
//--------------------------------------------------------------------------------------------------
void RicShowPlotDataFeature::setupActionLook( QAction* actionToSetup )
2017-03-15 20:15:04 +01:00
{
actionToSetup->setText( "Show Plot Data" );
2020-10-01 17:25:19 +02:00
actionToSetup->setIcon( QIcon( ":/PlotWindow.svg" ) );
2017-03-15 20:15:04 +01:00
}
//--------------------------------------------------------------------------------------------------
///
2017-03-15 20:15:04 +01:00
//--------------------------------------------------------------------------------------------------
void RicShowPlotDataFeature::showTabbedTextWindow( std::unique_ptr<RimTabbedTextProvider> textProvider )
{
2019-05-06 10:36:05 +02:00
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
CAF_ASSERT( plotwindow );
auto* textWidget = new RiuTabbedTextDialog( std::move( textProvider ) );
textWidget->setMinimumSize( 800, 600 );
QObject::connect( textWidget,
&RiuTabbedTextDialog::exportToFileRequested,
[]( const QString& title, const QString& text )
{
QString defaultDir = RicAsciiExportSummaryPlotFeature::defaultExportDir();
QString fileName = RicAsciiExportSummaryPlotFeature::getFileNameFromUserDialog( title, defaultDir );
if ( fileName.isEmpty() ) return;
RicAsciiExportSummaryPlotFeature::exportTextToFile( fileName, text );
} );
plotwindow->addToTemporaryWidgets( textWidget );
textWidget->show();
textWidget->redrawText();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicShowPlotDataFeature::showTextWindow( const QString& title, const QString& text )
2017-03-15 20:15:04 +01:00
{
2019-05-06 10:36:05 +02:00
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
CAF_ASSERT( plotwindow );
2017-03-15 20:15:04 +01:00
auto* textWiget = new RiuTextDialog( RiaGuiApplication::widgetToUseAsParent() );
textWiget->setMinimumSize( 400, 600 );
2017-03-15 20:15:04 +01:00
textWiget->setWindowTitle( title );
textWiget->setText( text );
2017-03-15 20:15:04 +01:00
textWiget->show();
plotwindow->addToTemporaryWidgets( textWiget );
2017-03-15 20:15:04 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-06-26 14:28:46 +02:00
void RicShowPlotDataFeature::getSelection( std::vector<RimPlotWindow*>& selection ) const
{
if ( sender() )
{
QVariant userData = this->userData();
if ( !userData.isNull() && userData.canConvert<void*>() )
{
2023-10-11 08:54:52 +02:00
auto* plot = static_cast<RimPlot*>( userData.value<void*>() );
if ( plot ) selection.push_back( plot );
}
}
if ( selection.empty() )
{
2023-05-26 11:47:26 +02:00
auto selectedObjects = caf::selectedObjectsByType<caf::PdmObject*>();
for ( auto obj : selectedObjects )
{
if ( !obj ) continue;
if ( auto plotWindow = obj->firstAncestorOrThisOfType<RimPlotWindow>() )
{
selection.push_back( plotWindow );
}
}
}
}