#5632 Python method commands (#5649)

* General PdmObjectMethods for scripting.
This commit is contained in:
Gaute Lindkvist
2020-03-10 14:11:22 +01:00
committed by GitHub
parent 587478cbd1
commit c51aa91c42
145 changed files with 2646 additions and 1587 deletions

View File

@@ -23,6 +23,8 @@
#include "RicSaveProjectFeature.h"
#include "Riu3DMainWindowTools.h"
#include "cafPdmFieldIOScriptability.h"
#include <QAction>
#include <QMessageBox>
@@ -33,21 +35,21 @@ RICF_SOURCE_INIT( RicSaveProjectAsFeature, "RicSaveProjectAsFeature", "saveProje
//--------------------------------------------------------------------------------------------------
RicSaveProjectAsFeature::RicSaveProjectAsFeature()
{
RICF_InitFieldNoDefault( &m_filePath, "filePath", "", "", "", "" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_filePath, "filePath", "", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse RicSaveProjectAsFeature::execute()
caf::PdmScriptResponse RicSaveProjectAsFeature::execute()
{
this->disableModelChangeContribution();
QString errorMessage;
if ( !RiaApplication::instance()->saveProjectAs( m_filePath(), &errorMessage ) )
{
return RicfCommandResponse( RicfCommandResponse::COMMAND_ERROR, errorMessage );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, errorMessage );
}
return RicfCommandResponse();
return caf::PdmScriptResponse();
}
//--------------------------------------------------------------------------------------------------
@@ -73,7 +75,7 @@ void RicSaveProjectAsFeature::onActionTriggered( bool isChecked )
}
auto response = execute();
if ( response.status() != RicfCommandResponse::COMMAND_OK )
if ( response.status() != caf::PdmScriptResponse::COMMAND_OK )
{
QString displayMessage = response.messages().join( "\n" );
if ( RiaGuiApplication::isRunning() )

View File

@@ -32,7 +32,7 @@ class RicSaveProjectAsFeature : public caf::CmdFeature, public RicfCommandObject
public:
RicSaveProjectAsFeature();
RicfCommandResponse execute() override;
caf::PdmScriptResponse execute() override;
protected:
// Overrides

View File

@@ -38,7 +38,7 @@ RicSaveProjectFeature::RicSaveProjectFeature()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse RicSaveProjectFeature::execute()
caf::PdmScriptResponse RicSaveProjectFeature::execute()
{
this->disableModelChangeContribution();
@@ -55,10 +55,10 @@ RicfCommandResponse RicSaveProjectFeature::execute()
if ( !worked )
{
return RicfCommandResponse( RicfCommandResponse::COMMAND_ERROR, errorMessage );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, errorMessage );
}
return RicfCommandResponse();
return caf::PdmScriptResponse();
}
//--------------------------------------------------------------------------------------------------
@@ -88,7 +88,7 @@ void RicSaveProjectFeature::onActionTriggered( bool isChecked )
}
auto response = execute();
if ( response.status() != RicfCommandResponse::COMMAND_OK )
if ( response.status() != caf::PdmScriptResponse::COMMAND_OK )
{
QString displayMessage = response.messages().join( "\n" );
if ( RiaGuiApplication::isRunning() )

View File

@@ -32,7 +32,7 @@ class RicSaveProjectFeature : public caf::CmdFeature, public RicfCommandObject
public:
RicSaveProjectFeature();
RicfCommandResponse execute() override;
caf::PdmScriptResponse execute() override;
protected:
// Overrides

View File

@@ -36,6 +36,7 @@
#include "RiuViewer.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmFieldIOScriptability.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cafSelectionManager.h"
#include "cafUtils.h"
@@ -49,11 +50,11 @@ RICF_SOURCE_INIT( RicExportContourMapToTextFeature, "RicExportContourMapToTextFe
RicExportContourMapToTextFeature::RicExportContourMapToTextFeature()
{
RICF_InitFieldNoDefault( &m_exportFileName, "exportFileName", "", "", "", "" );
RICF_InitFieldNoDefault( &m_exportLocalCoordinates, "exportLocalCoordinates", "", "", "", "" );
RICF_InitFieldNoDefault( &m_undefinedValueLabel, "undefinedValueLabel", "", "", "", "" );
RICF_InitFieldNoDefault( &m_excludeUndefinedValues, "excludeUndefinedValues", "", "", "", "" );
RICF_InitField( &m_viewId, "viewId", -1, "View Id", "", "", "" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_exportFileName, "exportFileName", "", "", "", "" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_exportLocalCoordinates, "exportLocalCoordinates", "", "", "", "" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_undefinedValueLabel, "undefinedValueLabel", "", "", "", "" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_excludeUndefinedValues, "excludeUndefinedValues", "", "", "", "" );
CAF_PDM_InitScriptableFieldWithIO( &m_viewId, "viewId", -1, "View Id", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
@@ -127,13 +128,13 @@ void RicExportContourMapToTextFeature::onActionTriggered( bool isChecked )
m_undefinedValueLabel = featureUi.undefinedValueLabel();
m_excludeUndefinedValues = featureUi.excludeUndefinedValues();
RicfCommandResponse response = execute();
QStringList messages = response.messages();
caf::PdmScriptResponse response = execute();
QStringList messages = response.messages();
if ( !messages.empty() )
{
QString displayMessage = QString( "Problem exporting contour map:\n%2" ).arg( messages.join( "\n" ) );
if ( response.status() == RicfCommandResponse::COMMAND_ERROR )
if ( response.status() == caf::PdmScriptResponse::COMMAND_ERROR )
{
RiaLogging::error( displayMessage );
}
@@ -273,10 +274,10 @@ void RicExportContourMapToTextFeature::setupActionLook( QAction* actionToSetup )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse RicExportContourMapToTextFeature::execute()
caf::PdmScriptResponse RicExportContourMapToTextFeature::execute()
{
RicfCommandResponse response;
QStringList errorMessages, warningMessages;
caf::PdmScriptResponse response;
QStringList errorMessages, warningMessages;
RiaApplication* app = RiaApplication::instance();
@@ -297,7 +298,7 @@ RicfCommandResponse RicExportContourMapToTextFeature::execute()
if ( !myView )
{
response.updateStatus( RicfCommandResponse::COMMAND_ERROR, "No contour map view found" );
response.updateStatus( caf::PdmScriptResponse::COMMAND_ERROR, "No contour map view found" );
return response;
}
@@ -339,7 +340,7 @@ RicfCommandResponse RicExportContourMapToTextFeature::execute()
for ( QString errorMessage : errorMessages )
{
response.updateStatus( RicfCommandResponse::COMMAND_ERROR, errorMessage );
response.updateStatus( caf::PdmScriptResponse::COMMAND_ERROR, errorMessage );
}
return response;

View File

@@ -39,7 +39,7 @@ class RicExportContourMapToTextFeature : public caf::CmdFeature, public RicfComm
public:
RicExportContourMapToTextFeature();
RicfCommandResponse execute() override;
caf::PdmScriptResponse execute() override;
protected:
bool isCommandEnabled() override;

View File

@@ -47,7 +47,7 @@ RicNewMultiPlotFeature::RicNewMultiPlotFeature()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCommandResponse RicNewMultiPlotFeature::execute()
caf::PdmScriptResponse RicNewMultiPlotFeature::execute()
{
RimProject* project = RiaApplication::instance()->project();
RimMultiPlotCollection* plotCollection = project->mainPlotCollection()->multiPlotCollection();
@@ -84,7 +84,7 @@ RicfCommandResponse RicNewMultiPlotFeature::execute()
RiuPlotMainWindowTools::setExpanded( plotCollection, true );
RiuPlotMainWindowTools::selectAsCurrentItem( plotWindow, true );
return RicfCommandResponse();
return caf::PdmScriptResponse();
}
//--------------------------------------------------------------------------------------------------

View File

@@ -37,7 +37,7 @@ class RicNewMultiPlotFeature : public caf::CmdFeature, public RicfCommandObject
public:
RicNewMultiPlotFeature();
virtual RicfCommandResponse execute() override;
virtual caf::PdmScriptResponse execute() override;
protected:
// Overrides

View File

@@ -78,7 +78,8 @@ RimEnsembleCurveSet* RicNewSummaryEnsembleCurveSetFeature::addDefaultCurveSet( R
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( std::vector<RimSummaryCaseCollection*> ensembles )
RimSummaryPlot*
RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( std::vector<RimSummaryCaseCollection*> ensembles )
{
RiaGuiApplication* app = RiaGuiApplication::instance();
RimProject* proj = app->project();
@@ -102,6 +103,7 @@ void RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( std:
mainPlotWindow->selectAsCurrentItem( firstCurveSetCreated );
mainPlotWindow->updateSummaryPlotToolBar();
}
return plot;
}
//--------------------------------------------------------------------------------------------------

View File

@@ -34,7 +34,7 @@ class RicNewSummaryEnsembleCurveSetFeature : public caf::CmdFeature
CAF_CMD_HEADER_INIT;
public:
static void createPlotForCurveSetsAndUpdate( std::vector<RimSummaryCaseCollection*> ensembles );
static RimSummaryPlot* createPlotForCurveSetsAndUpdate( std::vector<RimSummaryCaseCollection*> ensembles );
protected:
// Overrides

View File

@@ -40,6 +40,8 @@
#include "RiuPlotMainWindow.h"
#include "cafPdmFieldIOScriptability.h"
#include "cafPdmFieldScriptability.h"
#include "cafSelectionManagerTools.h"
#include "cvfAssert.h"
@@ -208,6 +210,29 @@ void extractPlotObjectsFromSelection( std::vector<RimSummaryCase*>* se
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicNewDefaultSummaryPlotFeature::createFromSummaryCases( RimSummaryPlotCollection* plotCollection,
const std::vector<RimSummaryCase*>& summaryCases )
{
RimSummaryPlot* newPlot = plotCollection->createSummaryPlotWithAutoTitle();
for ( RimSummaryCase* sumCase : summaryCases )
{
RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( newPlot, sumCase );
}
newPlot->applyDefaultCurveAppearances();
newPlot->loadDataAndUpdate();
plotCollection->updateConnectedEditors();
RiuPlotMainWindowTools::setExpanded( newPlot );
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
return newPlot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -234,20 +259,7 @@ void RicNewDefaultSummaryPlotFeature::onActionTriggered( bool isChecked )
{
RimSummaryPlotCollection* sumPlotColl =
RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
RimSummaryPlot* newPlot = sumPlotColl->createSummaryPlotWithAutoTitle();
for ( RimSummaryCase* sumCase : selectedIndividualSummaryCases )
{
RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( newPlot, sumCase );
}
newPlot->applyDefaultCurveAppearances();
newPlot->loadDataAndUpdate();
sumPlotColl->updateConnectedEditors();
RiuPlotMainWindowTools::setExpanded( newPlot );
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
createFromSummaryCases( sumPlotColl, selectedIndividualSummaryCases );
}
else
{
@@ -276,3 +288,42 @@ void RicNewDefaultSummaryPlotFeature::setupActionLook( QAction* actionToSetup )
}
actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) );
}
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSummaryPlotCollection, RimSummaryPlotCollection_newSummaryPlot, "NewSummaryPlot" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlotCollection_newSummaryPlot::RimSummaryPlotCollection_newSummaryPlot( caf::PdmObjectHandle* self )
: caf::PdmObjectMethod( self )
{
CAF_PDM_InitObject( "Create Summary Plot", "", "", "Create a new Summary Plot" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_summaryCases, "SummaryCases", "", "", "", "Summary Cases" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_ensembles, "Ensembles", "", "", "", "Ensembles" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* RimSummaryPlotCollection_newSummaryPlot::execute()
{
if ( !m_summaryCases.empty() )
{
return RicNewDefaultSummaryPlotFeature::createFromSummaryCases( self<RimSummaryPlotCollection>(),
m_summaryCases.ptrReferencedObjects() );
}
else if ( !m_ensembles.empty() )
{
return RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( m_ensembles.ptrReferencedObjects() );
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSummaryPlotCollection_newSummaryPlot::deleteObjectAfterReply() const
{
return false;
}

View File

@@ -18,10 +18,14 @@
#pragma once
#include "RicfCommandObject.h"
#include "cafCmdFeature.h"
#include "cafPdmPtrArrayField.h"
class RimSummaryPlotCollection;
class RimSummaryCase;
class RimSummaryCaseCollection;
class RimSummaryPlot;
//==================================================================================================
@@ -45,9 +49,31 @@ class RicNewDefaultSummaryPlotFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static RimSummaryPlot* createFromSummaryCases( RimSummaryPlotCollection* plotCollection,
const std::vector<RimSummaryCase*>& summaryCases );
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};
//==================================================================================================
///
//==================================================================================================
class RimSummaryPlotCollection_newSummaryPlot : public caf::PdmObjectMethod
{
CAF_PDM_HEADER_INIT;
public:
RimSummaryPlotCollection_newSummaryPlot( caf::PdmObjectHandle* self );
caf::PdmObjectHandle* execute();
bool deleteObjectAfterReply() const override;
private:
caf::PdmPtrArrayField<RimSummaryCase*> m_summaryCases;
caf::PdmPtrArrayField<RimSummaryCaseCollection*> m_ensembles;
};

View File

@@ -31,6 +31,8 @@
#include "Riu3DMainWindowTools.h"
#include "cafPdmFieldIOScriptability.h"
#include <QAction>
#include <QFileDialog>
#include <QMessageBox>
@@ -62,11 +64,11 @@ RICF_SOURCE_INIT( RicImportWellPaths, "RicWellPathsImportFileFeature", "importWe
//--------------------------------------------------------------------------------------------------
RicImportWellPaths::RicImportWellPaths()
{
RICF_InitFieldNoDefault( &m_wellPathFolder, "wellPathFolder", "", "", "", "" );
RICF_InitFieldNoDefault( &m_wellPathFiles, "wellPathFiles", "", "", "", "" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_wellPathFolder, "wellPathFolder", "", "", "", "" );
CAF_PDM_InitScriptableFieldWithIONoDefault( &m_wellPathFiles, "wellPathFiles", "", "", "", "" );
}
RicfCommandResponse RicImportWellPaths::execute()
caf::PdmScriptResponse RicImportWellPaths::execute()
{
QStringList errorMessages, warningMessages;
QStringList wellPathFiles;
@@ -115,7 +117,7 @@ RicfCommandResponse RicImportWellPaths::execute()
}
}
RicfCommandResponse response;
caf::PdmScriptResponse response;
if ( !wellPathFiles.empty() )
{
std::vector<RimWellPath*> importedWellPaths = importWellPaths( wellPathFiles, &warningMessages );
@@ -137,12 +139,12 @@ RicfCommandResponse RicImportWellPaths::execute()
for ( QString warningMessage : warningMessages )
{
response.updateStatus( RicfCommandResponse::COMMAND_WARNING, warningMessage );
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warningMessage );
}
for ( QString errorMessage : errorMessages )
{
response.updateStatus( RicfCommandResponse::COMMAND_ERROR, errorMessage );
response.updateStatus( caf::PdmScriptResponse::COMMAND_ERROR, errorMessage );
}
return response;
@@ -219,9 +221,9 @@ void RicImportWellPaths::onActionTriggered( bool isChecked )
if ( wellPathFilePaths.size() >= 1 )
{
m_wellPathFiles.v() = std::vector<QString>( wellPathFilePaths.begin(), wellPathFilePaths.end() );
RicfCommandResponse response = execute();
QStringList messages = response.messages();
m_wellPathFiles.v() = std::vector<QString>( wellPathFilePaths.begin(), wellPathFilePaths.end() );
caf::PdmScriptResponse response = execute();
QStringList messages = response.messages();
if ( !messages.empty() )
{
@@ -231,7 +233,7 @@ void RicImportWellPaths::onActionTriggered( bool isChecked )
{
QMessageBox::warning( Riu3DMainWindowTools::mainWindowWidget(), "Well Path Loading", displayMessage );
}
if ( response.status() == RicfCommandResponse::COMMAND_ERROR )
if ( response.status() == caf::PdmScriptResponse::COMMAND_ERROR )
{
RiaLogging::error( displayMessage );
}

View File

@@ -40,7 +40,7 @@ class RicImportWellPaths : public caf::CmdFeature, public RicfCommandObject
public:
RicImportWellPaths();
RicfCommandResponse execute() override;
caf::PdmScriptResponse execute() override;
protected:
static std::vector<RimWellPath*> importWellPaths( const QStringList& wellPathFilePaths, QStringList* errorMessages );