#6285 Add context menu stacking/unstacking of curves

This commit is contained in:
Gaute Lindkvist 2020-08-10 19:59:13 +02:00
parent c3982a5782
commit e0cf133721
9 changed files with 387 additions and 2 deletions

View File

@ -93,6 +93,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicExportContourMapToTextFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportContourMapToTextUi.h
${CMAKE_CURRENT_LIST_DIR}/RicNewMultiPlotFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportFractureModelPlotToFileFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicStackSelectedCurvesFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicUnstackSelectedCurvesFeature.h
)
@ -184,6 +186,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicExportContourMapToTextFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportContourMapToTextUi.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewMultiPlotFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportFractureModelPlotToFileFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicStackSelectedCurvesFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicUnstackSelectedCurvesFeature.cpp
)

View File

@ -0,0 +1,149 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicStackSelectedCurvesFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "cafPdmFieldIOScriptability.h"
#include "cafPdmObject.h"
#include "cafPdmScriptResponse.h"
#include "cafPdmUiItem.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QMessageBox>
RICF_SOURCE_INIT( RicStackSelectedCurvesFeature, "RicStackSelectedCurvesFeature", "stackCurves" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicStackSelectedCurvesFeature::RicStackSelectedCurvesFeature()
{
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_curves, "curves", "", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPlotCurve*>
RicStackSelectedCurvesFeature::plotCurvesFromSelection( const std::vector<caf::PdmUiItem*>& selectedItems )
{
std::vector<RimPlotCurve*> selectedPlotCurves;
for ( caf::PdmUiItem* uiItem : selectedItems )
{
auto plotCurve = dynamic_cast<RimPlotCurve*>( uiItem );
if ( plotCurve )
{
selectedPlotCurves.push_back( plotCurve );
}
}
return selectedPlotCurves;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPlotCurve*>
RicStackSelectedCurvesFeature::subsetOfPlotCurvesFromStacking( const std::vector<RimPlotCurve*>& plotCurves,
bool isStacked )
{
std::vector<RimPlotCurve*> matchingPlotCurves;
for ( RimPlotCurve* plotCurve : plotCurves )
{
if ( plotCurve->isStacked() == isStacked )
{
matchingPlotCurves.push_back( plotCurve );
}
}
return matchingPlotCurves;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicStackSelectedCurvesFeature::execute()
{
if ( m_curves().empty() )
{
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, "No Curves Provided" );
}
for ( auto plotCurve : m_curves() )
{
plotCurve->setIsStacked( true );
}
return caf::PdmScriptResponse();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicStackSelectedCurvesFeature::isCommandEnabled()
{
std::vector<caf::PdmUiItem*> selectedItems;
caf::SelectionManager::instance()->selectedItems( selectedItems );
auto plotCurves = plotCurvesFromSelection( selectedItems );
if ( plotCurves.size() != selectedItems.size() ) return false;
auto unstackedPlotCurves = subsetOfPlotCurvesFromStacking( plotCurves, false );
return !unstackedPlotCurves.empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicStackSelectedCurvesFeature::onActionTriggered( bool isChecked )
{
std::vector<caf::PdmUiItem*> selectedItems;
caf::SelectionManager::instance()->selectedItems( selectedItems );
auto plotCurves = plotCurvesFromSelection( selectedItems );
auto unstackedPlotCurves = subsetOfPlotCurvesFromStacking( plotCurves, false );
m_curves.setValue( unstackedPlotCurves );
caf::PdmScriptResponse response = execute();
if ( response.status() != caf::PdmScriptResponse::COMMAND_OK )
{
QString displayMessage = response.messages().join( "\n" );
if ( RiaGuiApplication::isRunning() )
{
QMessageBox::warning( nullptr, "Error when saving project file", displayMessage );
}
RiaLogging::error( displayMessage );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicStackSelectedCurvesFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Stack Selected Curves" );
}

View File

@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RicfCommandObject.h"
#include "RimPlotCurve.h"
#include "cafCmdFeature.h"
#include "cafPdmPtrArrayField.h"
#include <vector>
//==================================================================================================
///
//==================================================================================================
class RicStackSelectedCurvesFeature : public caf::CmdFeature, public RicfCommandObject
{
RICF_HEADER_INIT;
public:
RicStackSelectedCurvesFeature();
caf::PdmScriptResponse execute() override;
static std::vector<RimPlotCurve*> plotCurvesFromSelection( const std::vector<caf::PdmUiItem*>& selectedItems );
static std::vector<RimPlotCurve*> subsetOfPlotCurvesFromStacking( const std::vector<RimPlotCurve*>& plotCurves,
bool isStacked );
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
caf::PdmPtrArrayField<RimPlotCurve*> m_curves;
};

View File

@ -0,0 +1,109 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicUnstackSelectedCurvesFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "cafPdmFieldIOScriptability.h"
#include "cafPdmObject.h"
#include "cafPdmScriptResponse.h"
#include "cafPdmUiItem.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QMessageBox>
RICF_SOURCE_INIT( RicUnstackSelectedCurvesFeature, "RicUnstackSelectedCurvesFeature", "unstackCurves" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicUnstackSelectedCurvesFeature::RicUnstackSelectedCurvesFeature()
{
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_curves, "curves", "", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicUnstackSelectedCurvesFeature::execute()
{
if ( m_curves().empty() )
{
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, "No Curves Provided" );
}
for ( auto plotCurve : m_curves() )
{
plotCurve->setIsStacked( false );
}
return caf::PdmScriptResponse();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicUnstackSelectedCurvesFeature::isCommandEnabled()
{
std::vector<caf::PdmUiItem*> selectedItems;
caf::SelectionManager::instance()->selectedItems( selectedItems );
auto plotCurves = RicStackSelectedCurvesFeature::plotCurvesFromSelection( selectedItems );
if ( plotCurves.size() != selectedItems.size() ) return false;
auto stackedPlotCurves = RicStackSelectedCurvesFeature::subsetOfPlotCurvesFromStacking( plotCurves, true );
return !stackedPlotCurves.empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicUnstackSelectedCurvesFeature::onActionTriggered( bool isChecked )
{
std::vector<caf::PdmUiItem*> selectedItems;
caf::SelectionManager::instance()->selectedItems( selectedItems );
auto plotCurves = RicStackSelectedCurvesFeature::plotCurvesFromSelection( selectedItems );
auto unstackedPlotCurves = RicStackSelectedCurvesFeature::subsetOfPlotCurvesFromStacking( plotCurves, true );
m_curves.setValue( unstackedPlotCurves );
caf::PdmScriptResponse response = execute();
if ( response.status() != caf::PdmScriptResponse::COMMAND_OK )
{
QString displayMessage = response.messages().join( "\n" );
if ( RiaGuiApplication::isRunning() )
{
QMessageBox::warning( nullptr, "Error when saving project file", displayMessage );
}
RiaLogging::error( displayMessage );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicUnstackSelectedCurvesFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Unstack Selected Curves" );
}

View File

@ -0,0 +1,48 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RicStackSelectedCurvesFeature.h"
#include "RicfCommandObject.h"
#include "RimPlotCurve.h"
#include "cafCmdFeature.h"
#include "cafPdmPtrArrayField.h"
//==================================================================================================
///
//==================================================================================================
class RicUnstackSelectedCurvesFeature : public caf::CmdFeature, public RicfCommandObject
{
RICF_HEADER_INIT;
public:
RicUnstackSelectedCurvesFeature();
caf::PdmScriptResponse execute() override;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
caf::PdmPtrArrayField<RimPlotCurve*> m_curves;
};

View File

@ -665,6 +665,9 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicSetSourceSteppingSummaryCurveFeature";
menuBuilder << "RicClearSourceSteppingSummaryCurveFeature";
menuBuilder << "Separator";
menuBuilder << "RicStackSelectedCurvesFeature";
menuBuilder << "RicUnstackSelectedCurvesFeature";
menuBuilder << "Separator";
menuBuilder << "RicCopyReferencesToClipboardFeature";
menuBuilder << "Separator";
menuBuilder << "RicEditSummaryCurveCalculationFeature";
@ -969,6 +972,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder.addSeparator();
menuBuilder << "RicConvertGroupToEnsembleFeature";
menuBuilder.addSeparator();
menuBuilder.addSeparator();
menuBuilder << "RicStackSelectedCurvesFeature";
menuBuilder << "RicUnstackSelectedCurvesFeature";
menuBuilder.addSeparator();
menuBuilder << "RicFlyToObjectFeature";

View File

@ -740,6 +740,22 @@ bool RimPlotCurve::isStackedWithPhaseColors() const
return m_isStackedWithPhaseColors;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::setIsStacked( bool stacked )
{
m_isStacked = stacked;
if ( !m_isStacked() && m_fillStyle() != Qt::NoBrush )
{
// Switch off area fill when turning off stacking.
m_fillStyle = Qt::NoBrush;
}
stackingChanged.send( m_isStacked() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -125,6 +125,7 @@ public:
void assignStackColor( size_t index, size_t count );
bool isStacked() const;
bool isStackedWithPhaseColors() const;
void setIsStacked( bool stacked );
protected:
virtual QString createCurveAutoName() = 0;

View File

@ -1370,10 +1370,10 @@ void RimSummaryPlot::childFieldChangedByUi( const caf::PdmFieldHandle* changedCh
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::updateStackedCurveData()
{
loadDataAndUpdate();
updateStackedCurveDataForAxis( RiaDefines::PlotAxis::PLOT_AXIS_LEFT );
updateStackedCurveDataForAxis( RiaDefines::PlotAxis::PLOT_AXIS_RIGHT );
loadDataAndUpdate();
}
//--------------------------------------------------------------------------------------------------