Implement creation of combination plots from selected plots

This commit is contained in:
Gaute Lindkvist 2019-10-31 15:12:54 +01:00
parent 30db19a1d0
commit e8c745d704
7 changed files with 115 additions and 17 deletions

View File

@ -24,27 +24,31 @@
#include "RimGridPlotWindow.h"
#include "RimGridPlotWindowCollection.h"
#include "RimMainPlotCollection.h"
#include "RimPlotInterface.h"
#include "RimProject.h"
#include "RiuPlotMainWindowTools.h"
#include <QAction>
#include "cafSelectionManager.h"
#include "cvfAssert.h"
CAF_CMD_SOURCE_INIT( RicNewGridPlotWindowFeature, "RicNewGridPlotWindowFeature" );
RICF_SOURCE_INIT( RicNewGridPlotWindowFeature, "RicNewGridPlotWindowFeature", "createCombinationPlot" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewGridPlotWindowFeature::isCommandEnabled()
RicNewGridPlotWindowFeature::RicNewGridPlotWindowFeature()
{
return true;
CAF_PDM_InitObject( "Create Combination Plot", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_plots, "plots", "Plots", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewGridPlotWindowFeature::onActionTriggered( bool isChecked )
RicfCommandResponse RicNewGridPlotWindowFeature::execute()
{
RimProject* project = RiaApplication::instance()->project();
RimGridPlotWindowCollection* plotCollection = project->mainPlotCollection()->combinationPlotCollection();
@ -53,12 +57,58 @@ void RicNewGridPlotWindowFeature::onActionTriggered( bool isChecked )
plotWindow->setDescription( QString( "Combination Plot %1" ).arg( plotCollection->gridPlotWindows().size() + 1 ) );
plotWindow->setAsPlotMdiWindow();
plotCollection->addGridPlotWindow( plotWindow );
plotCollection->updateAllRequiredEditors();
if ( !m_plots().empty() )
{
std::vector<RimPlotInterface*> plotInterfaces;
for ( auto ptr : m_plots() )
{
plotInterfaces.push_back( reinterpret_cast<RimPlotInterface*>( ptr ) );
}
plotWindow->movePlotsToThis( plotInterfaces, nullptr );
}
plotCollection->updateAllRequiredEditors();
plotWindow->loadDataAndUpdate();
RiuPlotMainWindowTools::setExpanded( plotCollection, true );
RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow, true );
return RicfCommandResponse();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewGridPlotWindowFeature::isCommandEnabled()
{
RimGridPlotWindowCollection* gridPlotCollection = caf::SelectionManager::instance()
->selectedItemOfType<RimGridPlotWindowCollection>();
if ( gridPlotCollection )
{
return true;
}
auto selectedPlots = selectedPlotInterfaces();
std::vector<caf::PdmUiItem*> selectedUiItems;
caf::SelectionManager::instance()->selectedItems( selectedUiItems );
return !selectedPlots.empty() && selectedPlots.size() == selectedUiItems.size();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewGridPlotWindowFeature::onActionTriggered( bool isChecked )
{
m_plots.v().clear();
auto selectedPlots = selectedPlotInterfaces();
for ( RimPlotInterface* plotInterface : selectedPlots )
{
m_plots.v().push_back( reinterpret_cast<uintptr_t>( plotInterface ) );
}
execute();
}
//--------------------------------------------------------------------------------------------------
@ -66,6 +116,34 @@ void RicNewGridPlotWindowFeature::onActionTriggered( bool isChecked )
//--------------------------------------------------------------------------------------------------
void RicNewGridPlotWindowFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "New Empty Combination Plot" );
actionToSetup->setIcon( QIcon( ":/WellLogPlot16x16.png" ) );
if ( selectedPlotInterfaces().empty() )
{
actionToSetup->setText( "New Empty Combination Plot" );
actionToSetup->setIcon( QIcon( ":/WellLogPlot16x16.png" ) );
}
else
{
actionToSetup->setText( "Create Combination Plot from selected plots" );
actionToSetup->setIcon( QIcon( ":/WellLogPlot16x16.png" ) );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPlotInterface*> RicNewGridPlotWindowFeature::selectedPlotInterfaces()
{
std::vector<caf::PdmUiItem*> uiItems;
caf::SelectionManager::instance()->selectedItems( uiItems );
std::vector<RimPlotInterface*> plotInterfaces;
for ( caf::PdmUiItem* uiItem : uiItems )
{
RimPlotInterface* plotInterface = dynamic_cast<RimPlotInterface*>( uiItem );
if ( plotInterface )
{
plotInterfaces.push_back( plotInterface );
}
}
return plotInterfaces;
}

View File

@ -18,18 +18,35 @@
#pragma once
#include "RicfCommandObject.h"
#include "cafCmdFeature.h"
#include "cafPdmField.h"
#include <vector>
class RimPlotInterface;
//==================================================================================================
///
//==================================================================================================
class RicNewGridPlotWindowFeature : public caf::CmdFeature
class RicNewGridPlotWindowFeature : public caf::CmdFeature, public RicfCommandObject
{
CAF_CMD_HEADER_INIT;
RICF_HEADER_INIT;
public:
RicNewGridPlotWindowFeature();
virtual RicfCommandResponse execute() override;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
static std::vector<RimPlotInterface*> selectedPlotInterfaces();
private:
caf::PdmField<std::vector<uint64_t>> m_plots;
};

View File

@ -466,10 +466,6 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicNewWellLogPlotFeature";
menuBuilder << "RicNewWellBoreStabilityPlotFeature";
}
else if ( dynamic_cast<RimGridPlotWindowCollection*>( uiItem ) )
{
menuBuilder << "RicNewGridPlotWindowFeature";
}
else if ( dynamic_cast<RimRftPlotCollection*>( uiItem ) )
{
menuBuilder << "RicNewRftPlotFeature";
@ -871,6 +867,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicDeleteSummaryCaseCollectionFeature";
menuBuilder << "RicCloseObservedDataFeature";
menuBuilder << "RicNewGridPlotWindowFeature";
// Work in progress -- End
appendCreateCompletions( menuBuilder, menuBuilder.itemCount() > 0u );
bool addedExportWellPaths = appendExportWellPaths( menuBuilder, menuBuilder.itemCount() > 0u ) > 0;

View File

@ -114,14 +114,14 @@ void RimGridPlotWindow::insertPlot( RimPlotInterface* plot, size_t index )
if ( plot )
{
m_plots.insert( index, toPdmObjectAsserted( plot ) );
plot->setChecked( true );
if ( m_viewer )
{
plot->createPlotWidget();
plot->setChecked( true );
m_viewer->insertPlot( plot->viewer(), index );
plot->updateAfterInsertingIntoGridPlotWindow();
}
plot->updateAfterInsertingIntoGridPlotWindow();
onPlotAdditionOrRemoval();
}

View File

@ -342,7 +342,6 @@ void RimWellLogExtractionCurve::onLoadDataAndUpdate( bool updateParentPlot )
RimWellLogPlot* wellLogPlot;
firstAncestorOrThisOfType( wellLogPlot );
CVF_ASSERT( wellLogPlot );
if ( !wellLogPlot ) return;
displayUnit = wellLogPlot->depthUnit();

View File

@ -209,7 +209,7 @@ RimSummaryPlot::RimSummaryPlot()
m_textCurveSetEditor = new RimSummaryPlotFilterTextCurveSetEditor;
m_isCrossPlot = false;
m_isDraggable = false;
m_isDraggable = true;
m_nameHelperAllCurves.reset( new RimSummaryPlotNameHelper );

View File

@ -193,10 +193,16 @@ void RiuGridPlotWindow::removePlot( RiuQwtPlotWidget* plotWidget )
plotWidget->setParent( nullptr );
RiuQwtPlotLegend* legend = m_legends[plotWidgetIdx];
legend->setParent( nullptr );
m_legends.removeAt( plotWidgetIdx );
m_legendColumns.removeAt( plotWidgetIdx );
delete legend;
QLabel* subTitle = m_subTitles[plotWidgetIdx];
subTitle->setParent( nullptr );
m_subTitles.removeAt( plotWidgetIdx );
delete subTitle;
scheduleUpdate();
}