2017-03-15 20:15:04 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-06-23 15:18:17 +02:00
|
|
|
//
|
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.
|
2019-06-23 15:18:17 +02:00
|
|
|
//
|
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.
|
2019-06-23 15:18:17 +02:00
|
|
|
//
|
|
|
|
|
// 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"
|
|
|
|
|
|
2019-06-23 15:18:17 +02:00
|
|
|
#include "RiaFeatureCommandContext.h"
|
2019-05-06 10:36:05 +02:00
|
|
|
#include "RiaGuiApplication.h"
|
2017-03-15 20:15:04 +01:00
|
|
|
|
2026-04-20 13:05:37 +02:00
|
|
|
#include "SummaryPlotCommands/RicAsciiExportSummaryPlotFeature.h"
|
2017-03-15 20:15:04 +01:00
|
|
|
|
2026-04-20 13:05:37 +02:00
|
|
|
#include "RimPlainPlotDataProducer.h"
|
|
|
|
|
#include "RimPlot.h"
|
|
|
|
|
#include "RimPlotWindow.h"
|
|
|
|
|
#include "RimReportPlotGroup.h"
|
|
|
|
|
#include "RimTabbedTextProducer.h"
|
|
|
|
|
#include "RimTabbedTextProvider.h"
|
2024-05-03 09:58:55 +02:00
|
|
|
|
2018-04-27 06:28:08 +02:00
|
|
|
#include "RiuPlotMainWindow.h"
|
2017-12-13 19:02:39 +01:00
|
|
|
#include "RiuTextDialog.h"
|
2017-03-15 20:15:04 +01:00
|
|
|
|
2017-10-19 09:09:22 +02:00
|
|
|
#include "cafSelectionManagerTools.h"
|
2017-03-15 20:15:04 +01:00
|
|
|
|
|
|
|
|
#include <QAction>
|
2017-04-03 17:36:36 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
CAF_CMD_SOURCE_INIT( RicShowPlotDataFeature, "RicShowPlotDataFeature" );
|
2017-03-15 20:15:04 +01:00
|
|
|
|
2019-03-11 11:39:23 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-23 15:18:17 +02:00
|
|
|
///
|
2017-04-03 17:36:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-06-26 14:28:46 +02:00
|
|
|
bool RicShowPlotDataFeature::isCommandEnabled() const
|
2017-03-15 20:15:04 +01:00
|
|
|
{
|
2019-06-23 15:18:17 +02:00
|
|
|
QString content = RiaFeatureCommandContext::instance()->contentString();
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( !content.isEmpty() )
|
2019-06-23 15:18:17 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-14 13:20:05 +02:00
|
|
|
std::vector<RimPlotWindow*> selection;
|
2022-08-08 13:34:27 +02:00
|
|
|
getSelection( selection );
|
|
|
|
|
|
|
|
|
|
for ( auto plot : selection )
|
2017-12-18 14:50:08 +01:00
|
|
|
{
|
2026-04-20 13:05:37 +02:00
|
|
|
if ( dynamic_cast<const RimTabbedTextProducer*>( plot ) ) return true;
|
|
|
|
|
if ( dynamic_cast<const RimReportPlotGroup*>( plot ) ) return true;
|
|
|
|
|
if ( dynamic_cast<const RimPlainPlotDataProducer*>( plot ) ) return true;
|
2017-12-18 14:50:08 +01:00
|
|
|
}
|
2026-04-20 13:05:37 +02:00
|
|
|
return false;
|
2017-03-15 20:15:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-23 15:18:17 +02:00
|
|
|
///
|
2017-03-15 20:15:04 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicShowPlotDataFeature::onActionTriggered( bool isChecked )
|
2017-03-15 20:15:04 +01:00
|
|
|
{
|
2019-06-23 15:18:17 +02:00
|
|
|
QString content = RiaFeatureCommandContext::instance()->contentString();
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( !content.isEmpty() )
|
2019-06-23 15:18:17 +02:00
|
|
|
{
|
|
|
|
|
QString title = "Data Content";
|
|
|
|
|
{
|
|
|
|
|
QString titleCandidate = RiaFeatureCommandContext::instance()->titleString();
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( !titleCandidate.isEmpty() ) title = titleCandidate;
|
2019-06-23 15:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
RicShowPlotDataFeature::showTextWindow( title, content );
|
2019-06-23 15:18:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 09:04:14 +02:00
|
|
|
disableModelChangeContribution();
|
2017-04-20 10:38:58 +02:00
|
|
|
|
2022-10-14 13:20:05 +02:00
|
|
|
std::vector<RimPlotWindow*> selection;
|
2022-08-08 13:34:27 +02:00
|
|
|
getSelection( selection );
|
|
|
|
|
|
2026-04-20 13:05:37 +02:00
|
|
|
auto showPlainForProducer = []( RimPlainPlotDataProducer* producer )
|
2022-08-08 13:34:27 +02:00
|
|
|
{
|
2026-04-20 13:05:37 +02:00
|
|
|
QString title = producer->description();
|
|
|
|
|
QString text = title + "\n\n" + producer->asciiDataForPlotExport();
|
|
|
|
|
RicShowPlotDataFeature::showTextWindow( title, text );
|
|
|
|
|
};
|
2023-10-18 08:50:04 +02:00
|
|
|
|
2026-04-20 13:05:37 +02:00
|
|
|
for ( auto* plot : selection )
|
|
|
|
|
{
|
|
|
|
|
if ( auto* producer = dynamic_cast<RimTabbedTextProducer*>( plot ) )
|
2022-08-08 13:34:27 +02:00
|
|
|
{
|
2026-04-20 13:05:37 +02:00
|
|
|
RicShowPlotDataFeature::showTabbedTextWindow( producer->createTabbedTextProvider() );
|
2022-10-14 13:20:05 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-01-18 09:18:00 +01:00
|
|
|
|
2026-04-20 13:05:37 +02:00
|
|
|
if ( auto* group = dynamic_cast<RimReportPlotGroup*>( plot ) )
|
2026-04-16 16:45:44 +02:00
|
|
|
{
|
2026-04-20 13:05:37 +02:00
|
|
|
for ( auto* child : group->childPlotsForTextExport() )
|
|
|
|
|
{
|
|
|
|
|
if ( child ) showPlainForProducer( child );
|
|
|
|
|
}
|
2026-04-16 16:45:44 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 13:05:37 +02:00
|
|
|
if ( auto* plainProducer = dynamic_cast<RimPlainPlotDataProducer*>( plot ) )
|
2023-01-18 09:18:00 +01:00
|
|
|
{
|
2026-04-20 13:05:37 +02:00
|
|
|
showPlainForProducer( plainProducer );
|
2023-01-18 09:18:00 +01:00
|
|
|
}
|
2022-08-08 13:34:27 +02:00
|
|
|
}
|
2017-03-15 20:15:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-23 15:18:17 +02:00
|
|
|
///
|
2017-03-15 20:15:04 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicShowPlotDataFeature::setupActionLook( QAction* actionToSetup )
|
2017-03-15 20:15:04 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02: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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-06-23 15:18:17 +02:00
|
|
|
///
|
2017-03-15 20:15:04 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-04-20 13:05:37 +02:00
|
|
|
void RicShowPlotDataFeature::showTabbedTextWindow( std::unique_ptr<RimTabbedTextProvider> textProvider )
|
2018-07-02 11:45:05 +02:00
|
|
|
{
|
2019-05-06 10:36:05 +02:00
|
|
|
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
|
2026-08-06 21:18:33 +02:00
|
|
|
CAF_ASSERT( plotwindow );
|
2018-07-02 11:45:05 +02:00
|
|
|
|
2026-04-20 13:05:37 +02:00
|
|
|
auto* textWidget = new RiuTabbedTextDialog( std::move( textProvider ) );
|
2019-09-06 10:40:57 +02:00
|
|
|
textWidget->setMinimumSize( 800, 600 );
|
2026-04-20 13:05:37 +02:00
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
} );
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
plotwindow->addToTemporaryWidgets( textWidget );
|
2019-03-11 11:39:23 +01:00
|
|
|
textWidget->show();
|
|
|
|
|
textWidget->redrawText();
|
2018-07-02 11:45:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
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();
|
2026-08-06 21:18:33 +02:00
|
|
|
CAF_ASSERT( plotwindow );
|
2017-03-15 20:15:04 +01:00
|
|
|
|
2026-01-21 19:11:41 +01:00
|
|
|
auto* textWiget = new RiuTextDialog( RiaGuiApplication::widgetToUseAsParent() );
|
2019-09-06 10:40:57 +02:00
|
|
|
textWiget->setMinimumSize( 400, 600 );
|
2017-03-15 20:15:04 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
textWiget->setWindowTitle( title );
|
|
|
|
|
textWiget->setText( text );
|
2017-03-15 20:15:04 +01:00
|
|
|
|
|
|
|
|
textWiget->show();
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
plotwindow->addToTemporaryWidgets( textWiget );
|
2017-03-15 20:15:04 +01:00
|
|
|
}
|
2022-08-08 13:34:27 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-06-26 14:28:46 +02:00
|
|
|
void RicShowPlotDataFeature::getSelection( std::vector<RimPlotWindow*>& selection ) const
|
2022-08-08 13:34:27 +02:00
|
|
|
{
|
|
|
|
|
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*>() );
|
2022-08-08 13:34:27 +02:00
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-08 13:34:27 +02:00
|
|
|
}
|
|
|
|
|
}
|