#1977 Curve Calculator : Create calculation description from addresses

This commit is contained in:
Magne Sjaastad 2017-10-13 14:33:26 +02:00
parent 15f71c29fa
commit 82aee8f5bf
6 changed files with 66 additions and 7 deletions

View File

@ -154,6 +154,14 @@ void RicSummaryCurveCalculator::fieldChangedByUi(const caf::PdmFieldHandle* chan
//--------------------------------------------------------------------------------------------------
void RicSummaryCurveCalculator::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
if (!m_currentCalculation())
{
if (calculationCollection()->calculations().size() > 0)
{
m_currentCalculation = calculationCollection()->calculations()[0];
}
}
{
caf::PdmUiGroup* group = uiOrdering.addNewGroupWithKeyword("Calculated Summaries", RicSummaryCurveCalculator::calculatedSummariesGroupName());
group->add(&m_currentCalculation);
@ -174,6 +182,7 @@ void RicSummaryCurveCalculator::defineUiOrdering(QString uiConfigName, caf::PdmU
// group->add(&m_newVariable);
// group->add(&m_deleteVariable);
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -41,8 +41,6 @@ public:
RimCalculation* currentCalculation() const;
private:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;

View File

@ -113,6 +113,10 @@ caf::PdmFieldHandle* RimCalculation::userDescriptionField()
//--------------------------------------------------------------------------------------------------
bool RimCalculation::parseExpression()
{
// The expression parser handles only variables in lower case
QString lowerVariant = m_expression().toLower();
m_expression = lowerVariant;
QString leftHandSideVariableName = RimCalculation::findLeftHandSide(m_expression);
if (leftHandSideVariableName.isEmpty()) return false;
@ -152,6 +156,8 @@ bool RimCalculation::parseExpression()
}
}
this->updateConnectedEditors();
return true;
}
@ -243,3 +249,42 @@ RimCalculationVariable* RimCalculation::findByName(const QString& name) const
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimCalculation::buildCalculationName() const
{
QString name = "Default Calculation Name";
QString lhs = RimCalculation::findLeftHandSide(m_expression);
if (!lhs.isEmpty())
{
name = lhs;
name += " ( ";
for (RimCalculationVariable* v : m_variables)
{
name += v->summaryAddressDisplayString();
if (v != m_variables[m_variables.size() - 1])
{
name += ", ";
}
}
name += " )";
}
return name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCalculation::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
m_description = buildCalculationName();
}

View File

@ -35,8 +35,8 @@ class RimCalculation : public caf::PdmObject
public:
RimCalculation();
void setDescription(const QString& description);
QString description() const;
void setDescription(const QString& description);
QString description() const;
caf::PdmChildArrayFieldHandle* variables();
RimCalculationVariable* addVariable();
@ -53,6 +53,10 @@ private:
static QString findLeftHandSide(const QString& expresion);
RimCalculationVariable* findByName(const QString& name) const;
QString buildCalculationName() const;
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
private:
caf::PdmField<QString> m_description;
caf::PdmField<QString> m_expression;

View File

@ -50,6 +50,8 @@ RimCalculationVariable::RimCalculationVariable()
CAF_PDM_InitFieldNoDefault(&m_summaryAddressUi, "SummaryAddressUi", "Summary Address", "", "", "");
m_summaryAddressUi.registerGetMethod(this, &RimCalculationVariable::summaryAddressDisplayString);
m_summaryAddressUi.xmlCapability()->disableIO();
m_summaryAddressUi.uiCapability()->setUiReadOnly(true);
CAF_PDM_InitFieldNoDefault(&m_case, "SummaryCase", "Summary Case", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_summaryAddress, "SummaryAddress", "Summary Address", "", "", "");

View File

@ -40,11 +40,12 @@ class RimCalculationVariable : public caf::PdmObject
public:
RimCalculationVariable();
QString name() const;
void setName(const QString& name);
QString name() const;
void setName(const QString& name);
QString summaryAddressDisplayString() const;
private:
QString summaryAddressDisplayString() const;
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;