2020-12-07 09:49:58 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2020 Equinor 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.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RimCustomObjectiveFunctionWeight.h"
|
|
|
|
|
|
|
|
#include "RiaStdStringTools.h"
|
2021-02-17 03:18:21 -06:00
|
|
|
#include "RiaSummaryCurveDefinition.h"
|
2020-12-07 09:49:58 -06:00
|
|
|
|
|
|
|
#include "RimCustomObjectiveFunction.h"
|
|
|
|
#include "RimEnsembleCurveSet.h"
|
2021-06-09 09:25:19 -05:00
|
|
|
#include "RimObjectiveFunctionTools.h"
|
2020-12-07 09:49:58 -06:00
|
|
|
#include "RimSummaryAddress.h"
|
|
|
|
|
|
|
|
#include "RiuSummaryVectorSelectionDialog.h"
|
|
|
|
|
|
|
|
#include "cafPdmUiLineEditor.h"
|
|
|
|
#include "cafPdmUiPushButtonEditor.h"
|
|
|
|
#include "cafPdmUiTreeSelectionEditor.h"
|
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT( RimCustomObjectiveFunctionWeight, "RimCustomObjectiveFunctionWeight" );
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimCustomObjectiveFunctionWeight::RimCustomObjectiveFunctionWeight()
|
|
|
|
{
|
2022-01-07 01:31:52 -06:00
|
|
|
CAF_PDM_InitObject( "Custom Objective Function Weight", ":/ObjectiveFunctionWeight.svg" );
|
2020-12-07 09:49:58 -06:00
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_title, "WeightTitle", "Title" );
|
2020-12-07 09:49:58 -06:00
|
|
|
m_title.registerGetMethod( this, &RimCustomObjectiveFunctionWeight::title );
|
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_objectiveValuesSummaryAddressesUiField, "SelectedObjectiveSummaryVar", "Vector" );
|
2020-12-07 09:49:58 -06:00
|
|
|
m_objectiveValuesSummaryAddressesUiField.xmlCapability()->disableIO();
|
|
|
|
m_objectiveValuesSummaryAddressesUiField.uiCapability()->setUiEditorTypeName( caf::PdmUiLineEditor::uiEditorTypeName() );
|
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_objectiveValuesSummaryAddresses, "ObjectiveSummaryAddress", "Summary Address" );
|
2021-10-13 06:39:46 -05:00
|
|
|
m_objectiveValuesSummaryAddresses.uiCapability()->setUiTreeHidden( true );
|
2020-12-07 09:49:58 -06:00
|
|
|
m_objectiveValuesSummaryAddresses.uiCapability()->setUiTreeChildrenHidden( true );
|
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_objectiveValuesSelectSummaryAddressPushButton, "SelectObjectiveSummaryAddress", "" );
|
2020-12-07 09:49:58 -06:00
|
|
|
caf::PdmUiPushButtonEditor::configureEditorForField( &m_objectiveValuesSelectSummaryAddressPushButton );
|
|
|
|
m_objectiveValuesSelectSummaryAddressPushButton.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
|
|
|
m_objectiveValuesSelectSummaryAddressPushButton = false;
|
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitField( &m_weightValue, "WeightValue", 1.0, "Weight" );
|
2020-12-07 09:49:58 -06:00
|
|
|
m_weightValue.uiCapability()->setUiEditorTypeName( caf::PdmUiLineEditor::uiEditorTypeName() );
|
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_objectiveFunction, "ObjectiveFunction", "Objective Function" );
|
2023-05-22 08:44:37 -05:00
|
|
|
m_objectiveFunction.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() );
|
2020-12-07 09:49:58 -06:00
|
|
|
|
|
|
|
setDeletable( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimCustomObjectiveFunctionWeight::title() const
|
|
|
|
{
|
|
|
|
std::vector<RifEclipseSummaryAddress> addressVector;
|
|
|
|
for ( RimSummaryAddress* address : m_objectiveValuesSummaryAddresses )
|
|
|
|
{
|
|
|
|
addressVector.push_back( address->address() );
|
|
|
|
}
|
|
|
|
return QString( "%0 * %1::%2%3%4" )
|
|
|
|
.arg( m_weightValue, 0, 'f', 2 )
|
2021-06-09 09:25:19 -05:00
|
|
|
.arg( caf::AppEnum<RimObjectiveFunction::FunctionType>( m_objectiveFunction() ).text() )
|
2020-12-07 09:49:58 -06:00
|
|
|
.arg( addressVector.size() > 1 ? "(" : "" )
|
|
|
|
.arg( QString::fromStdString( RifEclipseSummaryAddress::generateStringFromAddresses( addressVector, " + " ) ) )
|
|
|
|
.arg( addressVector.size() > 1 ? ")" : "" );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimCustomObjectiveFunctionWeight::setSummaryAddress( RifEclipseSummaryAddress address )
|
|
|
|
{
|
|
|
|
RimSummaryAddress* summaryAddress = new RimSummaryAddress();
|
|
|
|
summaryAddress->setAddress( address );
|
|
|
|
m_objectiveValuesSummaryAddresses.push_back( summaryAddress );
|
|
|
|
parentObjectiveFunction()->onWeightChanged();
|
2020-12-10 08:59:17 -06:00
|
|
|
updateAddressesUiField();
|
2020-12-07 09:49:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RifEclipseSummaryAddress> RimCustomObjectiveFunctionWeight::summaryAddresses() const
|
|
|
|
{
|
|
|
|
std::vector<RifEclipseSummaryAddress> addresses;
|
|
|
|
for ( auto address : m_objectiveValuesSummaryAddresses )
|
|
|
|
{
|
|
|
|
addresses.push_back( address->address() );
|
|
|
|
}
|
|
|
|
return addresses;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimObjectiveFunction::FunctionType RimCustomObjectiveFunctionWeight::objectiveFunction() const
|
|
|
|
{
|
|
|
|
return m_objectiveFunction();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
double RimCustomObjectiveFunctionWeight::weightValue() const
|
|
|
|
{
|
|
|
|
return m_weightValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 03:48:40 -06:00
|
|
|
QList<caf::PdmOptionItemInfo> RimCustomObjectiveFunctionWeight::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
|
2020-12-07 09:49:58 -06:00
|
|
|
{
|
|
|
|
QList<caf::PdmOptionItemInfo> options;
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 03:48:40 -06:00
|
|
|
void RimCustomObjectiveFunctionWeight::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
2020-12-07 09:49:58 -06:00
|
|
|
{
|
|
|
|
if ( changedField == &m_objectiveValuesSummaryAddressesUiField )
|
|
|
|
{
|
|
|
|
updateAddressesUiField();
|
|
|
|
}
|
|
|
|
else if ( changedField == &m_objectiveValuesSelectSummaryAddressPushButton )
|
|
|
|
{
|
|
|
|
RiuSummaryVectorSelectionDialog dlg( nullptr );
|
2021-06-09 09:25:19 -05:00
|
|
|
RimObjectiveFunctionTools::configureDialogForObjectiveFunctions( &dlg );
|
2020-12-07 09:49:58 -06:00
|
|
|
RimSummaryCaseCollection* candidateEnsemble = parentCurveSet()->summaryCaseCollection();
|
|
|
|
|
|
|
|
std::vector<RifEclipseSummaryAddress> candidateAddresses;
|
2023-05-12 14:41:34 -05:00
|
|
|
for ( auto address : m_objectiveValuesSummaryAddresses().childrenByType() )
|
2020-12-07 09:49:58 -06:00
|
|
|
{
|
|
|
|
candidateAddresses.push_back( address->address() );
|
|
|
|
}
|
|
|
|
|
|
|
|
dlg.setEnsembleAndAddresses( candidateEnsemble, candidateAddresses );
|
|
|
|
|
|
|
|
if ( dlg.exec() == QDialog::Accepted )
|
|
|
|
{
|
|
|
|
auto curveSelection = dlg.curveSelection();
|
|
|
|
if ( !curveSelection.empty() )
|
|
|
|
{
|
2022-05-31 05:56:45 -05:00
|
|
|
m_objectiveValuesSummaryAddresses.deleteChildren();
|
2020-12-07 09:49:58 -06:00
|
|
|
for ( auto address : curveSelection )
|
|
|
|
{
|
|
|
|
RimSummaryAddress* summaryAddress = new RimSummaryAddress();
|
2023-09-20 02:22:33 -05:00
|
|
|
summaryAddress->setAddress( address.summaryAddressY() );
|
2020-12-07 09:49:58 -06:00
|
|
|
m_objectiveValuesSummaryAddresses.push_back( summaryAddress );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateAddressesUiField();
|
|
|
|
m_objectiveValuesSelectSummaryAddressPushButton = false;
|
|
|
|
parentObjectiveFunction()->onWeightChanged();
|
|
|
|
}
|
|
|
|
else if ( changedField == &m_weightValue )
|
|
|
|
{
|
|
|
|
parentObjectiveFunction()->onWeightChanged();
|
|
|
|
}
|
|
|
|
else if ( changedField == &m_objectiveFunction )
|
|
|
|
{
|
|
|
|
parentObjectiveFunction()->onWeightChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimCustomObjectiveFunctionWeight::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
|
|
{
|
|
|
|
uiOrdering.add( &m_objectiveValuesSummaryAddressesUiField );
|
2020-12-08 11:36:13 -06:00
|
|
|
uiOrdering.add( &m_objectiveValuesSelectSummaryAddressPushButton, { false, 1, 0 } );
|
2020-12-07 09:49:58 -06:00
|
|
|
uiOrdering.add( &m_weightValue );
|
|
|
|
uiOrdering.add( &m_objectiveFunction );
|
|
|
|
|
|
|
|
uiOrdering.skipRemainingFields( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimCustomObjectiveFunctionWeight::defineEditorAttribute( const caf::PdmFieldHandle* field,
|
|
|
|
QString uiConfigName,
|
|
|
|
caf::PdmUiEditorAttribute* attribute )
|
|
|
|
{
|
|
|
|
if ( field == &m_weightValue )
|
|
|
|
{
|
|
|
|
caf::PdmUiLineEditorAttribute* myAttr = dynamic_cast<caf::PdmUiLineEditorAttribute*>( attribute );
|
|
|
|
if ( !myAttr )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
myAttr->validator = new QDoubleValidator( 0.0, 9999.0, 2 );
|
|
|
|
}
|
|
|
|
else if ( field == &m_objectiveValuesSelectSummaryAddressPushButton )
|
|
|
|
{
|
|
|
|
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
|
|
|
|
if ( attrib )
|
|
|
|
{
|
|
|
|
attrib->m_buttonText = "...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
caf::PdmFieldHandle* RimCustomObjectiveFunctionWeight::userDescriptionField()
|
|
|
|
{
|
|
|
|
return &m_title;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimEnsembleCurveSet* RimCustomObjectiveFunctionWeight::parentCurveSet() const
|
|
|
|
{
|
2023-05-12 14:41:34 -05:00
|
|
|
return firstAncestorOrThisOfType<RimEnsembleCurveSet>();
|
2020-12-07 09:49:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimCustomObjectiveFunction* RimCustomObjectiveFunctionWeight::parentObjectiveFunction() const
|
|
|
|
{
|
2023-05-12 14:41:34 -05:00
|
|
|
return firstAncestorOrThisOfType<RimCustomObjectiveFunction>();
|
2020-12-07 09:49:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimCustomObjectiveFunctionWeight::updateAddressesUiField()
|
|
|
|
{
|
|
|
|
std::vector<RifEclipseSummaryAddress> addressVector;
|
|
|
|
for ( RimSummaryAddress* address : m_objectiveValuesSummaryAddresses )
|
|
|
|
{
|
|
|
|
addressVector.push_back( address->address() );
|
|
|
|
}
|
2023-02-26 03:48:40 -06:00
|
|
|
m_objectiveValuesSummaryAddressesUiField = QString::fromStdString( RifEclipseSummaryAddress::generateStringFromAddresses( addressVector ) );
|
2020-12-07 09:49:58 -06:00
|
|
|
}
|