///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2015- Statoil ASA // Copyright (C) 2015- Ceetron Solutions AS // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RicNewMultiPlotFeature.h" #include "RiaApplication.h" #include "RimMainPlotCollection.h" #include "RimMultiPlot.h" #include "RimMultiPlotCollection.h" #include "RimPlot.h" #include "RimProject.h" #include "RimSaturationPressurePlot.h" #include "RiuPlotMainWindowTools.h" #include #include "cafSelectionManager.h" #include "cvfAssert.h" RICF_SOURCE_INIT( RicNewMultiPlotFeature, "RicNewMultiPlotFeature", "createMultiPlot" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RicNewMultiPlotFeature::RicNewMultiPlotFeature() { CAF_PDM_InitFieldNoDefault( &m_plots, "plots", "Plots", "", "", "" ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- caf::PdmScriptResponse RicNewMultiPlotFeature::execute() { RimProject* project = RiaApplication::instance()->project(); RimMultiPlotCollection* plotCollection = project->mainPlotCollection()->multiPlotCollection(); RimMultiPlot* plotWindow = new RimMultiPlot; plotWindow->setMultiPlotTitle( QString( "Multi Plot %1" ).arg( plotCollection->multiPlots().size() + 1 ) ); plotWindow->setAsPlotMdiWindow(); plotCollection->addMultiPlot( plotWindow ); if ( !m_plots().empty() ) { std::vector plots; for ( auto ptr : m_plots() ) { plots.push_back( reinterpret_cast( ptr ) ); } for ( auto plot : plots ) { auto copy = dynamic_cast( plot->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) ); { // TODO: Workaround for fixing the PdmPointer in RimEclipseResultDefinition // caf::PdmPointer m_eclipseCase; // This pdmpointer must be changed to a ptrField auto saturationPressurePlotOriginal = dynamic_cast( plot ); auto saturationPressurePlotCopy = dynamic_cast( copy ); if ( saturationPressurePlotCopy && saturationPressurePlotOriginal ) { RimSaturationPressurePlot::fixPointersAfterCopy( saturationPressurePlotOriginal, saturationPressurePlotCopy ); } } plotWindow->addPlot( copy ); copy->resolveReferencesRecursively(); copy->revokeMdiWindowStatus(); copy->setShowWindow( true ); copy->loadDataAndUpdate(); } } project->updateAllRequiredEditors(); plotWindow->loadDataAndUpdate(); RiuPlotMainWindowTools::setExpanded( plotCollection, true ); RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow, true ); return caf::PdmScriptResponse(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicNewMultiPlotFeature::isCommandEnabled() { auto plots = selectedPlots(); std::vector selectedUiItems; caf::SelectionManager::instance()->selectedItems( selectedUiItems ); return !plots.empty() && plots.size() == selectedUiItems.size(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicNewMultiPlotFeature::onActionTriggered( bool isChecked ) { m_plots.v().clear(); auto plots = selectedPlots(); for ( RimPlot* plot : plots ) { m_plots.v().push_back( reinterpret_cast( plot ) ); } execute(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicNewMultiPlotFeature::setupActionLook( QAction* actionToSetup ) { actionToSetup->setText( "Create Multi Plot from Selected Plots" ); actionToSetup->setIcon( QIcon( ":/MultiPlot16x16.png" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RicNewMultiPlotFeature::selectedPlots() { std::vector uiItems; caf::SelectionManager::instance()->selectedItems( uiItems ); std::vector plots; for ( caf::PdmUiItem* uiItem : uiItems ) { RimPlot* plotInterface = dynamic_cast( uiItem ); if ( plotInterface ) { plots.push_back( plotInterface ); } } return plots; }