(#339) Refactored execution of scripts for selected cases

Moved slotExecuteScriptForSelectedCases() from RiuMainWindow to
RicExecuteScriptForCasesFeature.
This commit is contained in:
Pål Hagen 2015-08-19 13:23:26 +02:00
parent ea87fc0746
commit 28e7c8b19c
7 changed files with 69 additions and 50 deletions

View File

@ -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}
)

View File

@ -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);
}
}
}

View File

@ -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();
};

View File

@ -49,6 +49,7 @@
#include <QDir>
#include "cafCmdFeature.h"
#include "ToggleCommands/RicToggleItemsFeatureImpl.h"
#include "RicExecuteScriptForCasesFeature.h"
CAF_PDM_SOURCE_INIT(RimProject, "ResInsightProject");
@ -677,9 +678,9 @@ void RimProject::actionsBasedOnSelection(QMenu& contextMenu)
else if (commandIds[i] == "RicExecuteScriptForCasesFeature")
{
// Execute script on selection of cases
RiuMainWindow* ruiMainWindow = RiuMainWindow::instance();
if (ruiMainWindow)
{
RiuMainWindow* ruiMainWindow = RiuMainWindow::instance();
if (ruiMainWindow)
{
std::vector<RimCase*> cases;
ruiMainWindow->selectedCases(cases);
@ -736,13 +737,19 @@ void RimProject::appendScriptItems(QMenu* menu, RimScriptCollection* scriptColle
RiuMainWindow* mainWindow = RiuMainWindow::instance();
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
CVF_ASSERT(commandManager);
RicExecuteScriptForCasesFeature* executeScriptFeature = dynamic_cast<RicExecuteScriptForCasesFeature*>(commandManager->getCommandFeature("RicExecuteScriptForCasesFeature"));
CVF_ASSERT(executeScriptFeature);
for (size_t i = 0; i < scriptCollection->calcScripts.size(); i++)
{
RimCalcScript* calcScript = scriptCollection->calcScripts[i];
QFileInfo fi(calcScript->absolutePath());
QString menuText = fi.baseName();
QAction* scriptAction = subMenu->addAction(menuText, mainWindow, SLOT(slotExecuteScriptForSelectedCases()));
QAction* scriptAction = subMenu->addAction(menuText, executeScriptFeature, SLOT(slotExecuteScriptForSelectedCases()));
scriptAction->setData(QVariant(calcScript->absolutePath()));
}

View File

@ -596,7 +596,7 @@ void RimUiTreeView::slotNewScript()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
// OBSOLETE - see RicExecuteScriptFeature
// OBSOLETE - see RicExecuteScriptForCasesFeature
void RimUiTreeView::slotExecuteScript()
{
QModelIndex index = currentIndex();

View File

@ -2253,46 +2253,3 @@ void RiuMainWindow::customMenuRequested(const QPoint& pos)
menu.exec(globalPos);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindow::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);
}
}
}

View File

@ -283,7 +283,6 @@ private slots:
void selectedObjectsChanged();
void customMenuRequested(const QPoint& pos);
void slotExecuteScriptForSelectedCases();
// Animation slots