mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
Added support for asyncronous commands
Implemented command to issue a recompute of statistics for a statistics case on project loading p4#: 22417
This commit is contained in:
parent
39178578de
commit
91adbe79bf
@ -1289,12 +1289,12 @@ void RiaApplication::saveSnapshotForAllViews(const QString& snapshotFolderName)
|
||||
QString snapshotPath = projectDir.absolutePath();
|
||||
snapshotPath += "/" + snapshotFolderName;
|
||||
|
||||
RimAnalysisModels* analysisModels = m_project->activeOilField() ? m_project->activeOilField()->analysisModels() : NULL;
|
||||
if (analysisModels == NULL) return;
|
||||
std::vector<RimCase*> projectCases;
|
||||
m_project->allCases(projectCases);
|
||||
|
||||
for (size_t i = 0; i < analysisModels->cases().size(); ++i)
|
||||
for (size_t i = 0; i < projectCases.size(); i++)
|
||||
{
|
||||
RimCase* ri = analysisModels->cases()[i];
|
||||
RimCase* ri = projectCases[i];
|
||||
if (!ri) continue;
|
||||
|
||||
for (size_t j = 0; j < ri->reservoirViews().size(); j++)
|
||||
@ -1736,6 +1736,23 @@ void RiaApplication::addCommandObject(RimCommandObject* commandObject)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaApplication::executeCommandObjects()
|
||||
{
|
||||
std::list< RimCommandObject* >::iterator it = m_commandQueue.begin();
|
||||
while (it != m_commandQueue.end())
|
||||
{
|
||||
RimCommandObject* toBeRemoved = *it;
|
||||
if (!toBeRemoved->isAsyncronous())
|
||||
{
|
||||
toBeRemoved->redo();
|
||||
|
||||
it++;
|
||||
m_commandQueue.remove(toBeRemoved);
|
||||
}
|
||||
else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_commandQueue.size() > 0)
|
||||
{
|
||||
std::list< RimCommandObject* >::iterator it = m_commandQueue.begin();
|
||||
|
@ -19,15 +19,37 @@
|
||||
#include "RimCommandObject.h"
|
||||
#include "RiaApplication.h"
|
||||
#include "RimCalcScript.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "cafPdmUiTextEditor.h"
|
||||
#include "cafPdmUiPushButtonEditor.h"
|
||||
#include "cafPdmDocument.h"
|
||||
|
||||
#include <QFile>
|
||||
#include "RimStatisticsCase.h"
|
||||
|
||||
// Included due to template use in pdm fields
|
||||
#include "RimReservoirView.h"
|
||||
#include "RimReservoirCellResultsCacher.h"
|
||||
#include "RimResultSlot.h"
|
||||
#include "RimCellEdgeResultSlot.h"
|
||||
#include "RimCellRangeFilterCollection.h"
|
||||
#include "RimCellPropertyFilterCollection.h"
|
||||
#include "RimWellCollection.h"
|
||||
#include "Rim3dOverlayInfoConfig.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimScriptCollection.h"
|
||||
#include "RimIdenticalGridCaseGroup.h"
|
||||
#include "RimAnalysisModels.h"
|
||||
#include "RimWellPathCollection.h"
|
||||
#include "RimCaseCollection.h"
|
||||
|
||||
|
||||
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimCommandObject, "RimCommandObject");
|
||||
CAF_PDM_SOURCE_INIT(RimCommandExecuteScript, "RimCommandExecuteScript");
|
||||
CAF_PDM_SOURCE_INIT(RimCommandIssueFieldChanged, "RimCommandIssueFieldChanged");
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -140,6 +162,14 @@ void RimCommandExecuteScript::fieldChangedByUi(const caf::PdmFieldHandle* change
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimCommandExecuteScript::isAsyncronous()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -169,5 +199,147 @@ void RimCommandFactory::createCommandObjects(const caf::PdmObjectGroup& selected
|
||||
commandObjects->push_back(command);
|
||||
}
|
||||
}
|
||||
else if (dynamic_cast<RimStatisticsCase*>(pdmObject))
|
||||
{
|
||||
RimStatisticsCase* statisticsCase = dynamic_cast<RimStatisticsCase*>(pdmObject);
|
||||
|
||||
RimCommandIssueFieldChanged* command = new RimCommandIssueFieldChanged;
|
||||
command->objectName = statisticsCase->uiName();
|
||||
command->fieldName = statisticsCase->m_calculateEditCommand.keyword();
|
||||
command->fieldValueToApply = "true";
|
||||
|
||||
commandObjects->push_back(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCommandIssueFieldChanged::RimCommandIssueFieldChanged()
|
||||
{
|
||||
CAF_PDM_InitFieldNoDefault(&commandName, "CommandName", "CommandName", "", "", "");
|
||||
|
||||
CAF_PDM_InitField(&objectName, "ObjectName", QString(), "ObjectName", "", "" ,"");
|
||||
CAF_PDM_InitField(&fieldName, "FieldName", QString(), "FieldName", "", "" ,"");
|
||||
CAF_PDM_InitField(&fieldValueToApply, "FieldValueToApply", QString(), "FieldValueToApply", "", "" ,"");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCommandIssueFieldChanged::~RimCommandIssueFieldChanged()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCommandIssueFieldChanged::redo()
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
PdmObject* project = app->project();
|
||||
|
||||
caf::PdmObject* pdmObject = findObjectByName(project, this->objectName);
|
||||
|
||||
if (pdmObject)
|
||||
{
|
||||
caf::PdmFieldHandle* fieldHandle = findFieldByKeyword(pdmObject, this->fieldName);
|
||||
|
||||
if (fieldHandle)
|
||||
{
|
||||
QVariant variantValue(this->fieldValueToApply);
|
||||
fieldHandle->setValueFromUi(variantValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCommandIssueFieldChanged::undo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* RimCommandIssueFieldChanged::userDescriptionField()
|
||||
{
|
||||
return &commandName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimCommandIssueFieldChanged::childObjects(caf::PdmObject* pdmObject, std::vector<caf::PdmObject*>& children)
|
||||
{
|
||||
if (!pdmObject) return;
|
||||
|
||||
std::vector<caf::PdmFieldHandle*> fields;
|
||||
pdmObject->fields(fields);
|
||||
|
||||
size_t fIdx;
|
||||
for (fIdx = 0; fIdx < fields.size(); ++fIdx)
|
||||
{
|
||||
if (fields[fIdx]) fields[fIdx]->childObjects(&children);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObject* RimCommandIssueFieldChanged::findObjectByName(caf::PdmObject* pdmObject, const QString& objectName)
|
||||
{
|
||||
std::vector<caf::PdmFieldHandle*> fields;
|
||||
pdmObject->fields(fields);
|
||||
|
||||
if (pdmObject->uiName() == objectName)
|
||||
{
|
||||
return pdmObject;
|
||||
}
|
||||
|
||||
|
||||
for (size_t fIdx = 0; fIdx < fields.size(); fIdx++)
|
||||
{
|
||||
if (fields[fIdx])
|
||||
{
|
||||
std::vector<caf::PdmObject*> children;
|
||||
fields[fIdx]->childObjects(&children);
|
||||
|
||||
for (size_t cIdx = 0; cIdx < children.size(); cIdx++)
|
||||
{
|
||||
PdmObject* candidateObj = findObjectByName(children[cIdx], objectName);
|
||||
if (candidateObj)
|
||||
{
|
||||
return candidateObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* RimCommandIssueFieldChanged::findFieldByKeyword(caf::PdmObject* pdmObject, const QString& keywordName)
|
||||
{
|
||||
std::vector<caf::PdmFieldHandle*> fields;
|
||||
pdmObject->fields(fields);
|
||||
|
||||
for (size_t fIdx = 0; fIdx < fields.size(); fIdx++)
|
||||
{
|
||||
if (fields[fIdx] && fields[fIdx]->keyword() == keywordName)
|
||||
{
|
||||
return fields[fIdx];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,6 +36,8 @@ public:
|
||||
RimCommandObject();
|
||||
virtual ~RimCommandObject();
|
||||
|
||||
virtual bool isAsyncronous() { return false; };
|
||||
|
||||
virtual void redo() {};
|
||||
virtual void undo() {};
|
||||
};
|
||||
@ -64,6 +66,35 @@ public:
|
||||
virtual caf::PdmFieldHandle* userDescriptionField();
|
||||
|
||||
virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue );
|
||||
|
||||
virtual bool isAsyncronous();
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RimCommandIssueFieldChanged : public RimCommandObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
public:
|
||||
RimCommandIssueFieldChanged();
|
||||
virtual ~RimCommandIssueFieldChanged();
|
||||
|
||||
caf::PdmField<QString> commandName;
|
||||
caf::PdmField<QString> objectName;
|
||||
caf::PdmField<QString> fieldName;
|
||||
caf::PdmField<QString> fieldValueToApply;
|
||||
|
||||
virtual void redo();
|
||||
virtual void undo();
|
||||
|
||||
virtual caf::PdmFieldHandle* userDescriptionField();
|
||||
|
||||
private:
|
||||
void childObjects(caf::PdmObject* pdmObject, std::vector<caf::PdmObject*>& children);
|
||||
caf::PdmObject* findObjectByName(caf::PdmObject* root, const QString& objectName);
|
||||
caf::PdmFieldHandle* findFieldByKeyword(caf::PdmObject* pdmObject, const QString& fieldName);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -461,6 +461,7 @@ void RimStatisticsCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField
|
||||
else
|
||||
{
|
||||
computeStatistics();
|
||||
updateConnectedEditorsAndReservoirViews();
|
||||
}
|
||||
m_calculateEditCommand = false;
|
||||
}
|
||||
@ -642,6 +643,28 @@ bool RimStatisticsCase::hasComputedStatistics() const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimStatisticsCase::updateConnectedEditorsAndReservoirViews()
|
||||
{
|
||||
for (size_t i = 0; i < reservoirViews.size(); ++i)
|
||||
{
|
||||
if (reservoirViews[i])
|
||||
{
|
||||
// As new result might have been introduced, update all editors connected
|
||||
reservoirViews[i]->cellResult->updateConnectedEditors();
|
||||
|
||||
// It is usually not needed to create new display model, but if any derived geometry based on generated data (from Octave)
|
||||
// a full display model rebuild is required
|
||||
reservoirViews[i]->scheduleCreateDisplayModelAndRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
this->updateConnectedEditors();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -650,16 +673,7 @@ void RimStatisticsCase::clearComputedStatistics()
|
||||
reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->clearAllResults();
|
||||
reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS)->clearAllResults();
|
||||
|
||||
for (size_t i = 0; i < reservoirViews().size(); i++)
|
||||
{
|
||||
RimReservoirView* reservoirView = reservoirViews()[i];
|
||||
CVF_ASSERT(reservoirView);
|
||||
|
||||
reservoirView->scheduleGeometryRegen(RivReservoirViewPartMgr::ACTIVE);
|
||||
reservoirView->createDisplayModelAndRedraw();
|
||||
}
|
||||
|
||||
this->updateConnectedEditors();
|
||||
updateConnectedEditorsAndReservoirViews();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
INTERPOLATED_OBSERVATION
|
||||
};
|
||||
|
||||
caf::PdmField< bool > m_calculateEditCommand;
|
||||
|
||||
private:
|
||||
RimIdenticalGridCaseGroup* caseGroup();
|
||||
@ -76,6 +77,8 @@ private:
|
||||
void updateSelectionSummaryLabel();
|
||||
void updatePercentileUiVisibility();
|
||||
|
||||
void updateConnectedEditorsAndReservoirViews();
|
||||
|
||||
void setWellResultsAndUpdateViews(const cvf::Collection<RigSingleWellResultsData>& sourceCaseWellResults);
|
||||
|
||||
// Pdm system overrides
|
||||
@ -86,7 +89,6 @@ private:
|
||||
virtual void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute );
|
||||
|
||||
// Fields
|
||||
caf::PdmField< bool > m_calculateEditCommand;
|
||||
|
||||
caf::PdmField< caf::AppEnum< RimDefines::ResultCatType > > m_resultType;
|
||||
caf::PdmField< caf::AppEnum< RimDefines::PorosityModelType > > m_porosityModel;
|
||||
|
Loading…
Reference in New Issue
Block a user