2019-09-11 02:33:03 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019- 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 <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-09-12 01:43:09 -05:00
|
|
|
#include "RicCreatePlotFromSelectionFeature.h"
|
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
#include "RicSelectPlotTemplateUi.h"
|
|
|
|
#include "RicSummaryPlotTemplateTools.h"
|
|
|
|
|
2019-09-11 02:33:03 -05:00
|
|
|
#include "RiaGuiApplication.h"
|
2019-09-11 04:40:22 -05:00
|
|
|
#include "RiaLogging.h"
|
2019-09-11 02:33:03 -05:00
|
|
|
#include "RiaSummaryTools.h"
|
|
|
|
|
2019-09-12 01:43:09 -05:00
|
|
|
#include "PlotTemplates/RimPlotTemplateFileItem.h"
|
2019-09-19 04:39:32 -05:00
|
|
|
#include "RimDialogData.h"
|
2019-09-11 02:33:03 -05:00
|
|
|
#include "RimMainPlotCollection.h"
|
|
|
|
#include "RimProject.h"
|
|
|
|
#include "RimSummaryCase.h"
|
|
|
|
#include "RimSummaryCurve.h"
|
|
|
|
#include "RimSummaryPlot.h"
|
|
|
|
#include "RimSummaryPlotCollection.h"
|
|
|
|
#include "RimWellPath.h"
|
|
|
|
|
2019-09-12 01:43:09 -05:00
|
|
|
#include "RiuPlotMainWindow.h"
|
|
|
|
|
2019-09-11 02:33:03 -05:00
|
|
|
#include "cafPdmObject.h"
|
2019-09-12 01:43:09 -05:00
|
|
|
#include "cafPdmUiPropertyViewDialog.h"
|
2019-09-11 02:33:03 -05:00
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
|
|
CAF_CMD_SOURCE_INIT( RicCreatePlotFromSelectionFeature, "RicCreatePlotFromSelectionFeature" );
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicCreatePlotFromSelectionFeature::isCommandEnabled()
|
|
|
|
{
|
2019-09-19 04:39:32 -05:00
|
|
|
return !selectedSummaryCases().empty();
|
2019-09-11 02:33:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
|
|
|
|
{
|
2019-09-19 04:39:32 -05:00
|
|
|
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
|
2019-09-11 02:33:03 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
RicSelectPlotTemplateUi* ui = RiaGuiApplication::instance()->project()->dialogData()->selectPlotTemplateUi();
|
2019-09-11 02:33:03 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, ui, "Select Plot Template", "" );
|
2019-09-11 02:33:03 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
if ( propertyDialog.exec() != QDialog::Accepted ) return;
|
2019-09-11 02:33:03 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
if ( ui->selectedPlotTemplates().empty() ) return;
|
2019-09-12 01:43:09 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
QString fileName = ui->selectedPlotTemplates().front()->absoluteFilePath();
|
|
|
|
std::vector<RimSummaryCase*> sumCases = selectedSummaryCases();
|
2019-09-12 01:43:09 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName );
|
|
|
|
if ( newSummaryPlot )
|
|
|
|
{
|
|
|
|
RimSummaryPlotCollection* plotColl =
|
|
|
|
RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
|
2019-09-12 01:43:09 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
plotColl->summaryPlots.push_back( newSummaryPlot );
|
|
|
|
newSummaryPlot->resolveReferencesRecursively();
|
|
|
|
newSummaryPlot->initAfterReadRecursively();
|
2019-09-12 01:43:09 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
QString nameOfCopy = QString( "Copy of " ) + newSummaryPlot->description();
|
|
|
|
newSummaryPlot->setDescription( nameOfCopy );
|
2019-09-11 02:33:03 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
auto summaryCurves = newSummaryPlot->summaryCurves();
|
2019-09-11 02:33:03 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
for ( const auto& curve : summaryCurves )
|
2019-09-11 02:33:03 -05:00
|
|
|
{
|
2019-09-19 04:39:32 -05:00
|
|
|
auto fieldHandle = curve->findField( "SummaryCase" );
|
|
|
|
if ( fieldHandle )
|
2019-09-11 02:33:03 -05:00
|
|
|
{
|
2019-09-19 04:39:32 -05:00
|
|
|
auto referenceString = fieldHandle->xmlCapability()->referenceString();
|
|
|
|
auto stringList = referenceString.split( " " );
|
|
|
|
if ( stringList.size() == 2 )
|
2019-09-12 01:43:09 -05:00
|
|
|
{
|
2019-09-19 04:39:32 -05:00
|
|
|
QString indexAsString = stringList[1];
|
2019-09-11 02:33:03 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
bool conversionOk = false;
|
|
|
|
int index = indexAsString.toUInt( &conversionOk );
|
2019-09-11 02:33:03 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
if ( conversionOk && index < sumCases.size() )
|
2019-09-11 02:33:03 -05:00
|
|
|
{
|
2019-09-19 04:39:32 -05:00
|
|
|
curve->setSummaryCaseY( sumCases[index] );
|
2019-09-11 02:33:03 -05:00
|
|
|
}
|
2019-09-12 01:43:09 -05:00
|
|
|
}
|
2019-09-11 02:33:03 -05:00
|
|
|
}
|
|
|
|
}
|
2019-09-19 04:39:32 -05:00
|
|
|
|
|
|
|
plotColl->updateConnectedEditors();
|
|
|
|
|
|
|
|
newSummaryPlot->loadDataAndUpdate();
|
2019-09-11 02:33:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicCreatePlotFromSelectionFeature::setupActionLook( QAction* actionToSetup )
|
|
|
|
{
|
|
|
|
actionToSetup->setText( "Create Plot from Template" );
|
2019-09-12 01:43:09 -05:00
|
|
|
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
|
2019-09-11 02:33:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RimSummaryCase*> RicCreatePlotFromSelectionFeature::selectedSummaryCases() const
|
|
|
|
{
|
|
|
|
std::vector<RimSummaryCase*> objects;
|
|
|
|
caf::SelectionManager::instance()->objectsByType( &objects );
|
|
|
|
|
|
|
|
return objects;
|
|
|
|
}
|