2017-10-12 00:30:37 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-23 07:42:38 -05:00
|
|
|
#include "RimSummaryCalculationVariable.h"
|
2017-10-12 00:30:37 -05:00
|
|
|
|
2018-05-16 03:57:43 -05:00
|
|
|
#include "RiaApplication.h"
|
2017-10-12 00:30:37 -05:00
|
|
|
#include "RiaSummaryCurveDefinition.h"
|
|
|
|
|
2018-05-16 03:57:43 -05:00
|
|
|
#include "RifEclipseSummaryAddressQMetaType.h"
|
|
|
|
|
|
|
|
#include "RimProject.h"
|
2017-11-08 06:09:05 -06:00
|
|
|
#include "RimSummaryAddress.h"
|
2017-10-23 07:42:38 -05:00
|
|
|
#include "RimSummaryCalculation.h"
|
2017-10-12 00:30:37 -05:00
|
|
|
#include "RimSummaryCase.h"
|
|
|
|
#include "RimSummaryCurve.h"
|
|
|
|
|
|
|
|
#include "RiuSummaryCurveDefSelectionDialog.h"
|
|
|
|
|
|
|
|
#include "cafPdmUiPushButtonEditor.h"
|
2018-06-13 04:41:32 -05:00
|
|
|
#include "cafPdmUiTableViewEditor.h"
|
2017-10-12 00:30:37 -05:00
|
|
|
|
|
|
|
|
2017-10-23 07:42:38 -05:00
|
|
|
CAF_PDM_SOURCE_INIT(RimSummaryCalculationVariable, "RimSummaryCalculationVariable");
|
2017-10-12 00:30:37 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
RimSummaryCalculationVariable::RimSummaryCalculationVariable()
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
2017-10-23 07:42:38 -05:00
|
|
|
CAF_PDM_InitObject("RimSummaryCalculationVariable", ":/octave.png", "", "");
|
2017-10-12 00:30:37 -05:00
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_name, "VariableName", "Variable Name", "", "", "");
|
2017-10-13 06:47:01 -05:00
|
|
|
m_name.uiCapability()->setUiReadOnly(true);
|
2017-10-12 00:30:37 -05:00
|
|
|
|
2017-12-15 08:19:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault(&m_button, "PushButton", "", "", "", "");
|
2017-10-12 00:30:37 -05:00
|
|
|
m_button.uiCapability()->setUiEditorTypeName(caf::PdmUiPushButtonEditor::uiEditorTypeName());
|
|
|
|
m_button.xmlCapability()->disableIO();
|
|
|
|
|
2017-12-15 08:19:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault(&m_summaryAddressUi, "SummaryAddressUi", "Summary Address", "", "", "");
|
2017-10-23 07:42:38 -05:00
|
|
|
m_summaryAddressUi.registerGetMethod(this, &RimSummaryCalculationVariable::summaryAddressDisplayString);
|
2017-10-12 00:30:37 -05:00
|
|
|
m_summaryAddressUi.xmlCapability()->disableIO();
|
2017-10-13 07:33:26 -05:00
|
|
|
m_summaryAddressUi.uiCapability()->setUiReadOnly(true);
|
|
|
|
|
2017-12-15 08:19:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault(&m_case, "SummaryCase", "Summary Case", "", "", "");
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_summaryAddress, "SummaryAddress", "Summary Address", "", "", "");
|
|
|
|
|
2017-10-12 00:30:37 -05:00
|
|
|
m_summaryAddress = new RimSummaryAddress;
|
|
|
|
}
|
|
|
|
|
2017-10-13 05:22:35 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
QString RimSummaryCalculationVariable::name() const
|
2017-10-13 05:22:35 -05:00
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
void RimSummaryCalculationVariable::setName(const QString& name)
|
2017-10-13 05:22:35 -05:00
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
}
|
|
|
|
|
2017-10-12 00:30:37 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
void RimSummaryCalculationVariable::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
|
|
|
if (changedField == &m_button)
|
|
|
|
{
|
2017-10-13 06:47:01 -05:00
|
|
|
bool updateContainingEditor = false;
|
|
|
|
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
2017-10-12 02:28:34 -05:00
|
|
|
RiuSummaryCurveDefSelectionDialog dlg(nullptr);
|
2018-05-14 14:31:56 -05:00
|
|
|
dlg.hideEnsembles();
|
2018-05-16 03:57:43 -05:00
|
|
|
|
|
|
|
readDataFromApplicationStore(&dlg);
|
2017-10-12 00:30:37 -05:00
|
|
|
|
2017-10-12 02:28:34 -05:00
|
|
|
if (dlg.exec() == QDialog::Accepted)
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
2017-11-15 08:20:47 -06:00
|
|
|
std::vector<RiaSummaryCurveDefinition> curveSelection = dlg.curveSelection();
|
|
|
|
if (curveSelection.size() > 0)
|
2017-10-12 02:28:34 -05:00
|
|
|
{
|
2017-11-15 08:20:47 -06:00
|
|
|
m_case = curveSelection[0].summaryCase();
|
|
|
|
m_summaryAddress->setAddress(curveSelection[0].summaryAddress());
|
2017-10-13 06:47:01 -05:00
|
|
|
|
2018-05-16 03:57:43 -05:00
|
|
|
writeDataToApplicationStore();
|
|
|
|
|
2017-10-13 06:47:01 -05:00
|
|
|
updateContainingEditor = true;
|
2017-10-12 02:28:34 -05:00
|
|
|
}
|
2017-10-12 00:30:37 -05:00
|
|
|
}
|
|
|
|
}
|
2017-10-12 02:28:34 -05:00
|
|
|
|
2017-10-13 06:47:01 -05:00
|
|
|
if (updateContainingEditor)
|
|
|
|
{
|
2017-10-23 07:27:04 -05:00
|
|
|
RimSummaryCalculation* rimCalculation = nullptr;
|
2017-10-13 06:47:01 -05:00
|
|
|
this->firstAncestorOrThisOfTypeAsserted(rimCalculation);
|
2017-10-13 08:35:19 -05:00
|
|
|
|
|
|
|
// RimCalculation is pointed to by RicSummaryCurveCalculator in a PtrField
|
|
|
|
// Update editors connected to RicSummaryCurveCalculator
|
|
|
|
std::vector<caf::PdmObjectHandle*> referringObjects;
|
|
|
|
rimCalculation->objectsWithReferringPtrFields(referringObjects);
|
|
|
|
for (auto o : referringObjects)
|
|
|
|
{
|
|
|
|
o->uiCapability()->updateConnectedEditors();
|
|
|
|
}
|
2017-10-13 06:47:01 -05:00
|
|
|
}
|
2017-10-12 00:30:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
QString RimSummaryCalculationVariable::summaryAddressDisplayString() const
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
2018-05-15 04:32:26 -05:00
|
|
|
QString caseName;
|
|
|
|
if (m_case() ) caseName = m_case()->caseName();
|
|
|
|
|
|
|
|
return RiaSummaryCurveDefinition::curveDefinitionText(caseName, m_summaryAddress()->address());
|
2017-10-12 00:30:37 -05:00
|
|
|
}
|
|
|
|
|
2017-10-16 15:04:00 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
RimSummaryCase* RimSummaryCalculationVariable::summaryCase()
|
2017-10-16 15:04:00 -05:00
|
|
|
{
|
|
|
|
return m_case();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
RimSummaryAddress* RimSummaryCalculationVariable::summaryAddress()
|
2017-10-16 15:04:00 -05:00
|
|
|
{
|
|
|
|
return m_summaryAddress();
|
|
|
|
}
|
|
|
|
|
2017-10-12 00:30:37 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
void RimSummaryCalculationVariable::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
|
|
|
uiOrdering.add(&m_name);
|
|
|
|
uiOrdering.add(&m_summaryAddressUi);
|
|
|
|
uiOrdering.add(&m_button);
|
|
|
|
|
|
|
|
uiOrdering.skipRemainingFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-10-23 07:42:38 -05:00
|
|
|
void RimSummaryCalculationVariable::defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
|
2017-10-12 00:30:37 -05:00
|
|
|
{
|
2018-06-13 04:41:32 -05:00
|
|
|
caf::PdmUiTableViewPushButtonEditorAttribute* attr = dynamic_cast<caf::PdmUiTableViewPushButtonEditorAttribute*>(attribute);
|
2017-10-12 00:30:37 -05:00
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
attr->registerPushButtonTextForFieldKeyword(m_button.keyword(), "Edit");
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 03:57:43 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimSummaryCalculationVariable::readDataFromApplicationStore(RiuSummaryCurveDefSelectionDialog* selectionDialog) const
|
|
|
|
{
|
|
|
|
if (!selectionDialog) return;
|
|
|
|
|
|
|
|
auto sumCase = m_case();
|
|
|
|
auto sumAddress = m_summaryAddress->address();
|
|
|
|
if (!sumCase && !sumAddress.isValid())
|
|
|
|
{
|
|
|
|
QVariant var = RiaApplication::instance()->cacheDataObject("CalculatorSummaryAddress");
|
|
|
|
|
|
|
|
auto lastUsedAddress = var.value<RifEclipseSummaryAddress>();
|
|
|
|
if (lastUsedAddress.isValid())
|
|
|
|
{
|
|
|
|
sumAddress = lastUsedAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString lastUsedSummaryCaseString = RiaApplication::instance()->cacheDataObject("CalculatorSummaryCase").toString();
|
|
|
|
|
|
|
|
auto* lastUsedSummaryCase = dynamic_cast<RimSummaryCase*>(
|
|
|
|
caf::PdmReferenceHelper::objectFromReference(RiaApplication::instance()->project(), lastUsedSummaryCaseString));
|
|
|
|
if (lastUsedSummaryCase)
|
|
|
|
{
|
|
|
|
sumCase = lastUsedSummaryCase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectionDialog->setCaseAndAddress(sumCase, sumAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimSummaryCalculationVariable::writeDataToApplicationStore() const
|
|
|
|
{
|
|
|
|
QString refFromProjectToObject =
|
|
|
|
caf::PdmReferenceHelper::referenceFromRootToObject(RiaApplication::instance()->project(), m_case);
|
|
|
|
RiaApplication::instance()->setCacheDataObject("CalculatorSummaryCase", refFromProjectToObject);
|
|
|
|
|
|
|
|
QVariant sumAdrVar = QVariant::fromValue(m_summaryAddress->address());
|
|
|
|
RiaApplication::instance()->setCacheDataObject("CalculatorSummaryAddress", sumAdrVar);
|
|
|
|
}
|