mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
Prototyped command object infrastructure to be used in regression tests of Octave scripts
p4#: 22387
This commit is contained in:
@@ -42,6 +42,7 @@ ${CEE_CURRENT_LIST_DIR}RimUiTreeView.h
|
||||
${CEE_CURRENT_LIST_DIR}RimReservoirCellResultsCacher.h
|
||||
${CEE_CURRENT_LIST_DIR}RimStatisticsCaseEvaluator.h
|
||||
${CEE_CURRENT_LIST_DIR}RimMimeData.h
|
||||
${CEE_CURRENT_LIST_DIR}RimCommandObject.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -82,6 +83,7 @@ ${CEE_CURRENT_LIST_DIR}RimUiTreeView.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimReservoirCellResultsCacher.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimStatisticsCaseEvaluator.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimMimeData.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RimCommandObject.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 "RimCommandObject.h"
|
||||
#include "RiaApplication.h"
|
||||
#include "RimCalcScript.h"
|
||||
|
||||
#include "cafPdmUiTextEditor.h"
|
||||
#include "cafPdmDocument.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimCommandObject, "RimCommandObject");
|
||||
CAF_PDM_SOURCE_INIT(RimCommandExecuteScript, "RimCommandExecuteScript");
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCommandObject::RimCommandObject()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCommandObject::~RimCommandObject()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCommandExecuteScript::RimCommandExecuteScript()
|
||||
{
|
||||
CAF_PDM_InitField(&scriptText, "ScriptText", QString(), "ScriptText", "", "" ,"");
|
||||
scriptText.setUiEditorTypeName(caf::PdmUiTextEditor::uiEditorTypeName());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCommandExecuteScript::~RimCommandExecuteScript()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCommandExecuteScript::redo()
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString octavePath = app->octavePath();
|
||||
if (!octavePath.isEmpty())
|
||||
{
|
||||
// http://www.gnu.org/software/octave/doc/interpreter/Command-Line-Options.html#Command-Line-Options
|
||||
|
||||
QStringList arguments;
|
||||
arguments.append("--path");
|
||||
arguments << QApplication::applicationDirPath();
|
||||
|
||||
arguments.append("-q");
|
||||
|
||||
arguments.append("--eval");
|
||||
arguments << this->scriptText();
|
||||
|
||||
RiaApplication::instance()->launchProcess(octavePath, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCommandExecuteScript::undo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCommandFactory::createCommandObjects(const caf::PdmObjectGroup& selectedObjects, std::vector<RimCommandObject*>& commandObjects)
|
||||
{
|
||||
for (size_t i = 0; i < selectedObjects.objects.size(); i++)
|
||||
{
|
||||
caf::PdmObject* pdmObject = selectedObjects.objects[i];
|
||||
|
||||
if (dynamic_cast<RimCalcScript*>(pdmObject))
|
||||
{
|
||||
RimCalcScript* calcScript = dynamic_cast<RimCalcScript*>(pdmObject);
|
||||
|
||||
QFile file(calcScript->absolutePath);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QTextStream in(&file);
|
||||
QByteArray byteArray = file.readAll();
|
||||
QString scriptText(byteArray);
|
||||
|
||||
RimCommandExecuteScript* command = new RimCommandExecuteScript;
|
||||
command->scriptText = scriptText;
|
||||
|
||||
commandObjects.push_back(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
||||
//
|
||||
// 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 "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RimCommandObject : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
public:
|
||||
RimCommandObject();
|
||||
virtual ~RimCommandObject();
|
||||
|
||||
virtual void redo() {};
|
||||
virtual void undo() {};
|
||||
};
|
||||
|
||||
|
||||
class RimCommandExecuteScript : public RimCommandObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
public:
|
||||
RimCommandExecuteScript();
|
||||
virtual ~RimCommandExecuteScript();
|
||||
|
||||
caf::PdmField<QString> scriptText;
|
||||
|
||||
virtual void redo();
|
||||
virtual void undo();
|
||||
};
|
||||
|
||||
|
||||
class RimCommandFactory
|
||||
{
|
||||
public:
|
||||
static void createCommandObjects(const caf::PdmObjectGroup& selectedObjects, std::vector<RimCommandObject*>& commandObjects);
|
||||
};
|
||||
@@ -75,6 +75,9 @@ RimProject::RimProject(void)
|
||||
wellPathImport = new RimWellPathImport();
|
||||
wellPathImport.setUiHidden(true);
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&commandObjects, "CommandObjects", "CommandObjects", "", "", "");
|
||||
//wellPathImport.setUiHidden(true);
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(¤tModelIndexPath, "TreeViewCurrentModelIndexPath", "", "", "", "");
|
||||
currentModelIndexPath.setUiHidden(true);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "cafPdmDocument.h"
|
||||
#include "RimWellPathImport.h"
|
||||
#include "RimCommandObject.h"
|
||||
|
||||
class RimOilField;
|
||||
class RimCase;
|
||||
@@ -28,7 +29,6 @@ class RimScriptCollection;
|
||||
class RimIdenticalGridCaseGroup;
|
||||
class RigMainGrid;
|
||||
class RigCaseData;
|
||||
class RimWellPathCollection;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
caf::PdmPointersField<RimOilField*> oilFields;
|
||||
caf::PdmField<RimScriptCollection*> scriptCollection;
|
||||
caf::PdmField<RimWellPathImport*> wellPathImport;
|
||||
caf::PdmPointersField<RimCommandObject*> commandObjects;
|
||||
caf::PdmField<QString> treeViewState;
|
||||
caf::PdmField<QString> currentModelIndexPath;
|
||||
caf::PdmField<int> nextValidCaseId; // Unique case ID within a project, used to identify a case from Octave scripts
|
||||
|
||||
@@ -1084,3 +1084,21 @@ void RimUiTreeModelPdm::deleteAllWellPaths(const QModelIndex& itemIndex)
|
||||
clearClipboard();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeModelPdm::populateObjectGroupFromModelIndexList(const QModelIndexList& modelIndexList, caf::PdmObjectGroup* objectGroup)
|
||||
{
|
||||
CVF_ASSERT(objectGroup);
|
||||
|
||||
for (int i = 0; i < modelIndexList.size(); i++)
|
||||
{
|
||||
caf::PdmUiTreeItem* uiItem = UiTreeModelPdm::getTreeItemFromIndex(modelIndexList.at(i));
|
||||
|
||||
if (uiItem && uiItem->dataObject() && uiItem->dataObject().p())
|
||||
{
|
||||
objectGroup->addObject(uiItem->dataObject().p());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
|
||||
void addToParentAndBuildUiItems(caf::PdmUiTreeItem* parentTreeItem, int position, caf::PdmObject* pdmObject);
|
||||
|
||||
void populateObjectGroupFromModelIndexList(const QModelIndexList& modelIndexList, caf::PdmObjectGroup* objectGroup);
|
||||
void addObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects);
|
||||
void moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects);
|
||||
|
||||
|
||||
@@ -560,7 +560,6 @@ void RimUiTreeView::slotExecuteScript()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -574,6 +573,8 @@ void RimUiTreeView::slotExecuteScriptForSelectedCases()
|
||||
QModelIndex mi = RimUiTreeView::getModelIndexFromString(model(), encodedModelIndex);
|
||||
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
if (!myModel) return;
|
||||
|
||||
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(mi);
|
||||
if (uiItem)
|
||||
{
|
||||
@@ -618,7 +619,8 @@ void RimUiTreeView::slotExecuteScriptForSelectedCases()
|
||||
caf::PdmObjectGroup group;
|
||||
|
||||
QModelIndexList mil = m->selectedRows();
|
||||
populateObjectGroupFromModelIndexList(mil, &group);
|
||||
|
||||
myModel->populateObjectGroupFromModelIndexList(mil, &group);
|
||||
|
||||
std::vector<caf::PdmPointer<RimCase> > typedObjects;
|
||||
group.objectsByType(&typedObjects);
|
||||
@@ -909,7 +911,7 @@ void RimUiTreeView::slotCloseCase()
|
||||
caf::PdmObjectGroup group;
|
||||
|
||||
QModelIndexList mil = m->selectedRows();
|
||||
populateObjectGroupFromModelIndexList(mil, &group);
|
||||
myModel->populateObjectGroupFromModelIndexList(mil, &group);
|
||||
|
||||
std::vector<caf::PdmPointer<RimCase> > typedObjects;
|
||||
group.objectsByType(&typedObjects);
|
||||
@@ -1048,7 +1050,7 @@ void RimUiTreeView::createPdmObjectsFromClipboard(caf::PdmObjectGroup* objectGro
|
||||
if (!mdWithIndexes) return;
|
||||
|
||||
QModelIndexList indexList = mdWithIndexes->indexes();
|
||||
populateObjectGroupFromModelIndexList(indexList, objectGroup);
|
||||
myModel->populateObjectGroupFromModelIndexList(indexList, objectGroup);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1536,27 +1538,6 @@ void RimUiTreeView::slotToggleItemsOff()
|
||||
executeSelectionToggleOperation(TOGGLE_OFF);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::populateObjectGroupFromModelIndexList(const QModelIndexList& modelIndexList, caf::PdmObjectGroup* objectGroup)
|
||||
{
|
||||
CVF_ASSERT(objectGroup);
|
||||
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
if (!myModel) return;
|
||||
|
||||
for (int i = 0; i < modelIndexList.size(); i++)
|
||||
{
|
||||
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(modelIndexList.at(i));
|
||||
|
||||
if (uiItem && uiItem->dataObject() && uiItem->dataObject().p())
|
||||
{
|
||||
objectGroup->addObject(uiItem->dataObject().p());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -47,8 +47,6 @@ public:
|
||||
void applyTreeViewStateFromString(const QString& treeViewState);
|
||||
void storeTreeViewStateToString(QString& treeViewState);
|
||||
|
||||
void populateObjectGroupFromModelIndexList(const QModelIndexList& modelIndexList, caf::PdmObjectGroup* objectGroup);
|
||||
|
||||
static QModelIndex getModelIndexFromString(QAbstractItemModel* model, const QString& currentIndexString);
|
||||
static void encodeStringFromModelIndex(const QModelIndex mi, QString& currentIndexString);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user