mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#339) Refactored execution of scripts for selected cases
Moved slotExecuteScriptForSelectedCases() from RiuMainWindow to RicExecuteScriptForCasesFeature.
This commit is contained in:
@@ -89,6 +89,12 @@ ${CEE_CURRENT_LIST_DIR}RicDeleteItemExecData.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicDeleteItemFeature.cpp
|
||||
)
|
||||
|
||||
set (QT_MOC_HEADERS
|
||||
${CEE_CURRENT_LIST_DIR}RicExecuteScriptForCasesFeature.h
|
||||
)
|
||||
|
||||
qt4_wrap_cpp(MOC_FILES_CPP ${QT_MOC_HEADERS})
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
#include "RicExecuteScriptForCasesFeature.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileInfo>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicExecuteScriptForCasesFeature, "RicExecuteScriptForCasesFeature");
|
||||
|
||||
@@ -50,7 +52,7 @@ bool RicExecuteScriptForCasesFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExecuteScriptForCasesFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
// Dummy - handled by RiuMainWindow::slotExecuteScriptForSelectedCases()
|
||||
// Dummy - handled by slotExecuteScriptForSelectedCases()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -60,3 +62,47 @@ void RicExecuteScriptForCasesFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setText("Execute script");
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExecuteScriptForCasesFeature::slotExecuteScriptForSelectedCases()
|
||||
{
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
if (!action) return;
|
||||
|
||||
QString scriptAbsolutePath = action->data().toString();
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString octavePath = app->octavePath();
|
||||
if (!octavePath.isEmpty())
|
||||
{
|
||||
// TODO: Must rename RimCalcScript::absolutePath to absoluteFileName, as the code below is confusing
|
||||
// absolutePath() is a function in QFileInfo
|
||||
|
||||
QFileInfo fi(scriptAbsolutePath);
|
||||
QString octaveFunctionSearchPath = fi.absolutePath();
|
||||
|
||||
QStringList arguments = app->octaveArguments();
|
||||
arguments.append("--path");
|
||||
arguments << octaveFunctionSearchPath;
|
||||
arguments << scriptAbsolutePath;
|
||||
|
||||
std::vector<RimCase*> selection;
|
||||
caf::SelectionManager::instance()->objectsByType(&selection);
|
||||
|
||||
// Get case ID from selected cases in selection model
|
||||
std::vector<int> caseIdsInSelection;
|
||||
for (size_t i = 0; i < selection.size(); i++)
|
||||
{
|
||||
RimCase* casePtr = selection[i];
|
||||
caseIdsInSelection.push_back(casePtr->caseId);
|
||||
}
|
||||
|
||||
if (caseIdsInSelection.size() > 0)
|
||||
{
|
||||
RiaApplication::instance()->launchProcessForMultipleCases(octavePath, arguments, caseIdsInSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
//==================================================================================================
|
||||
class RicExecuteScriptForCasesFeature : public caf::CmdFeature
|
||||
{
|
||||
Q_OBJECT
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
protected:
|
||||
@@ -34,6 +35,9 @@ protected:
|
||||
virtual bool isCommandEnabled();
|
||||
virtual void onActionTriggered( bool isChecked );
|
||||
virtual void setupActionLook( QAction* actionToSetup );
|
||||
|
||||
private slots:
|
||||
void slotExecuteScriptForSelectedCases();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user