2021-09-23 09:59:29 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2021- 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 "RimSurfaceIntersectionCurve.h"
|
|
|
|
|
|
|
|
|
|
#include "RimAnnotationLineAppearance.h"
|
|
|
|
|
#include "RimEnsembleSurface.h"
|
|
|
|
|
#include "RimSurface.h"
|
|
|
|
|
#include "RimSurfaceCollection.h"
|
2023-08-30 10:52:31 +02:00
|
|
|
#include "RimTools.h"
|
2021-09-23 09:59:29 +02:00
|
|
|
|
|
|
|
|
#include "cafPdmUiTreeSelectionEditor.h"
|
|
|
|
|
|
2026-08-08 09:40:39 +02:00
|
|
|
#include <QStringList>
|
|
|
|
|
|
2021-09-23 09:59:29 +02:00
|
|
|
CAF_PDM_SOURCE_INIT( RimSurfaceIntersectionCurve, "RimSurfaceIntersectionCurve" );
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimSurfaceIntersectionCurve::RimSurfaceIntersectionCurve()
|
|
|
|
|
: objectChanged( this )
|
|
|
|
|
{
|
2022-01-07 08:31:52 +01:00
|
|
|
CAF_PDM_InitObject( "SurfaceIntersectionCurve", ":/SummaryCurve16x16.png" );
|
2021-09-23 09:59:29 +02:00
|
|
|
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_lineAppearance, "LineAppearance", "Line Appearance" );
|
2021-09-23 09:59:29 +02:00
|
|
|
m_lineAppearance = new RimAnnotationLineAppearance;
|
|
|
|
|
m_lineAppearance->objectChanged.connect( this, &RimSurfaceIntersectionCurve::onObjectChanged );
|
|
|
|
|
uiCapability()->setUiTreeChildrenHidden( true );
|
|
|
|
|
|
2026-08-08 09:40:39 +02:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_surfaces, "Surfaces", "Surfaces" );
|
|
|
|
|
m_surfaces.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() );
|
|
|
|
|
m_surfaces.registerKeywordAlias( "Surface1" );
|
|
|
|
|
|
|
|
|
|
CAF_PDM_InitField( &m_useCustomColor, "UseCustomColor", false, "Custom Color" );
|
2021-09-23 09:59:29 +02:00
|
|
|
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_nameProxy, "NameProxy", "Name" );
|
2021-09-23 09:59:29 +02:00
|
|
|
m_nameProxy.registerGetMethod( this, &RimSurfaceIntersectionCurve::objectName );
|
|
|
|
|
m_nameProxy.uiCapability()->setUiHidden( true );
|
|
|
|
|
|
|
|
|
|
setDeletable( true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-08-08 09:40:39 +02:00
|
|
|
std::vector<RimSurface*> RimSurfaceIntersectionCurve::surfaces() const
|
2021-09-23 09:59:29 +02:00
|
|
|
{
|
2026-08-08 09:40:39 +02:00
|
|
|
return m_surfaces.ptrReferencedObjectsByType();
|
2021-09-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimAnnotationLineAppearance* RimSurfaceIntersectionCurve::lineAppearance() const
|
|
|
|
|
{
|
|
|
|
|
return m_lineAppearance();
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-08 09:40:39 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
cvf::Color3f RimSurfaceIntersectionCurve::colorForSurface( const RimSurface* surface ) const
|
|
|
|
|
{
|
|
|
|
|
if ( !m_useCustomColor() && surface ) return surface->color();
|
|
|
|
|
|
|
|
|
|
return m_lineAppearance->color();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 09:59:29 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
caf::PdmFieldHandle* RimSurfaceIntersectionCurve::userDescriptionField()
|
|
|
|
|
{
|
|
|
|
|
return &m_nameProxy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 10:48:40 +01:00
|
|
|
void RimSurfaceIntersectionCurve::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
2021-09-23 09:59:29 +02:00
|
|
|
{
|
2026-08-08 09:40:39 +02:00
|
|
|
if ( changedField == &m_surfaces || changedField == &m_useCustomColor )
|
|
|
|
|
{
|
|
|
|
|
updateColorFromSurface();
|
|
|
|
|
updateConnectedEditors();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 09:59:29 +02:00
|
|
|
onObjectChanged( this );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 10:48:40 +01:00
|
|
|
QList<caf::PdmOptionItemInfo> RimSurfaceIntersectionCurve::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
|
2021-09-23 09:59:29 +02:00
|
|
|
{
|
|
|
|
|
QList<caf::PdmOptionItemInfo> options;
|
|
|
|
|
|
2026-08-08 09:40:39 +02:00
|
|
|
if ( fieldNeedingOptions == &m_surfaces )
|
2021-09-23 09:59:29 +02:00
|
|
|
{
|
2023-08-30 10:52:31 +02:00
|
|
|
RimSurfaceCollection* surfColl = RimTools::surfaceCollection();
|
2021-09-23 09:59:29 +02:00
|
|
|
|
|
|
|
|
appendOptionItemsForSources( 0, surfColl, true, options );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceIntersectionCurve::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
|
|
|
{
|
2026-08-08 09:40:39 +02:00
|
|
|
uiOrdering.add( &m_surfaces );
|
|
|
|
|
|
2021-09-23 09:59:29 +02:00
|
|
|
caf::PdmUiGroup* group = uiOrdering.addNewGroup( "Line Appearance" );
|
2026-08-08 09:40:39 +02:00
|
|
|
group->add( &m_useCustomColor );
|
|
|
|
|
|
|
|
|
|
// The color defined in the Surfaces collection is used unless the user asks for a custom color
|
|
|
|
|
updateColorFromSurface();
|
|
|
|
|
m_lineAppearance->setColorReadOnly( !m_useCustomColor() );
|
2021-09-23 09:59:29 +02:00
|
|
|
m_lineAppearance->uiOrdering( uiConfigName, *group );
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-08 09:40:39 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceIntersectionCurve::initAfterRead()
|
|
|
|
|
{
|
|
|
|
|
updateColorFromSurface();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 09:59:29 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceIntersectionCurve::onObjectChanged( const caf::SignalEmitter* emitter )
|
|
|
|
|
{
|
|
|
|
|
objectChanged.send();
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-08 09:40:39 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// Keep the color of the line appearance in sync with the first surface, so the read-only color field
|
|
|
|
|
/// shows the color used to draw the curve
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceIntersectionCurve::updateColorFromSurface()
|
|
|
|
|
{
|
|
|
|
|
if ( m_useCustomColor() ) return;
|
|
|
|
|
|
|
|
|
|
auto surfaces = m_surfaces.ptrReferencedObjectsByType();
|
|
|
|
|
if ( surfaces.empty() || !surfaces.front() ) return;
|
|
|
|
|
|
|
|
|
|
m_lineAppearance->setColor( surfaces.front()->color() );
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 09:59:29 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RimSurfaceIntersectionCurve::objectName() const
|
|
|
|
|
{
|
2026-08-08 09:40:39 +02:00
|
|
|
auto nameForSurface = []( const RimSurface* surface ) -> QString
|
2021-09-23 09:59:29 +02:00
|
|
|
{
|
2026-08-08 09:40:39 +02:00
|
|
|
auto ensembleSurface = surface->firstAncestorOfType<RimEnsembleSurface>();
|
2021-10-05 14:23:20 +02:00
|
|
|
if ( ensembleSurface )
|
2021-09-23 09:59:29 +02:00
|
|
|
{
|
2026-08-08 09:40:39 +02:00
|
|
|
return ensembleSurface->collectionName() + "( " + surface->fullName() + " )";
|
2021-09-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-08 09:40:39 +02:00
|
|
|
return surface->fullName();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QStringList names;
|
|
|
|
|
for ( auto surface : m_surfaces.ptrReferencedObjectsByType() )
|
|
|
|
|
{
|
|
|
|
|
if ( surface ) names.push_back( nameForSurface( surface ) );
|
2021-09-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-08 09:40:39 +02:00
|
|
|
if ( names.isEmpty() ) return "Surface Curve";
|
|
|
|
|
|
|
|
|
|
return names.join( ", " );
|
2021-09-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceIntersectionCurve::appendOptionItemsForSources( int currentLevel,
|
|
|
|
|
RimSurfaceCollection* currentCollection,
|
|
|
|
|
bool showEnsembleSurfaces,
|
|
|
|
|
QList<caf::PdmOptionItemInfo>& options )
|
|
|
|
|
{
|
|
|
|
|
if ( !currentCollection ) return;
|
|
|
|
|
|
|
|
|
|
caf::IconProvider surfaceIcon( ":/ReservoirSurface16x16.png" );
|
|
|
|
|
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo::createHeader( currentCollection->collectionName(), true ) );
|
|
|
|
|
|
|
|
|
|
for ( auto surf : currentCollection->surfaces() )
|
|
|
|
|
{
|
2021-10-05 14:23:20 +02:00
|
|
|
auto itemInfo = caf::PdmOptionItemInfo( surf->fullName(), surf, false, surfaceIcon );
|
2021-09-23 09:59:29 +02:00
|
|
|
itemInfo.setLevel( currentLevel + 1 );
|
|
|
|
|
options.push_back( itemInfo );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto ensembleSurface = dynamic_cast<RimEnsembleSurface*>( currentCollection );
|
|
|
|
|
if ( !ensembleSurface || ( showEnsembleSurfaces && ensembleSurface ) )
|
|
|
|
|
{
|
|
|
|
|
for ( auto subColl : currentCollection->subCollections() )
|
|
|
|
|
{
|
|
|
|
|
appendOptionItemsForSources( currentLevel, subColl, showEnsembleSurfaces, options );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|