2020-01-03 13:49:12 +01: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 "RimSurfaceCollection.h"
|
2020-05-03 11:29:33 +02:00
|
|
|
|
2020-01-03 13:49:12 +01:00
|
|
|
#include "RiaColorTables.h"
|
2020-05-03 11:29:33 +02:00
|
|
|
#include "RiaLogging.h"
|
2026-08-07 08:34:58 +02:00
|
|
|
#include "RiaNameUniquenessTools.h"
|
2020-05-03 11:29:33 +02:00
|
|
|
|
2021-09-24 12:21:16 +02:00
|
|
|
#include "Rim2dIntersectionView.h"
|
|
|
|
|
#include "Rim2dIntersectionViewCollection.h"
|
|
|
|
|
#include "RimCase.h"
|
2021-08-17 13:38:12 +02:00
|
|
|
#include "RimEnsembleSurface.h"
|
2020-05-03 11:29:33 +02:00
|
|
|
#include "RimFileSurface.h"
|
2025-03-07 09:11:42 +01:00
|
|
|
#include "RimFractureSurface.h"
|
2020-05-03 11:29:33 +02:00
|
|
|
#include "RimGridCaseSurface.h"
|
2020-01-06 11:30:06 +01:00
|
|
|
#include "RimGridView.h"
|
2020-01-03 13:49:12 +01:00
|
|
|
#include "RimProject.h"
|
2025-05-28 09:50:45 +02:00
|
|
|
#include "RimRegularFileSurface.h"
|
2021-05-18 14:28:54 +02:00
|
|
|
#include "RimRegularLegendConfig.h"
|
2023-10-03 09:04:46 +02:00
|
|
|
#include "RimSeismicSectionCollection.h"
|
2020-01-03 13:49:12 +01:00
|
|
|
#include "RimSurface.h"
|
2020-01-06 11:30:06 +01:00
|
|
|
#include "RimSurfaceInView.h"
|
2021-05-18 14:28:54 +02:00
|
|
|
#include "RimSurfaceResultDefinition.h"
|
2020-01-03 13:49:12 +01:00
|
|
|
|
2024-07-24 10:25:42 +02:00
|
|
|
#include "cafCmdFeatureMenuBuilder.h"
|
2025-03-07 09:11:42 +01:00
|
|
|
#include "cafPdmFieldReorderCapability.h"
|
2020-08-26 12:31:23 +02:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
|
|
|
|
#include "cafPdmObjectScriptingCapability.h"
|
|
|
|
|
|
2021-09-23 09:59:29 +02:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
2021-05-18 14:28:54 +02:00
|
|
|
|
2020-01-03 13:49:12 +01:00
|
|
|
CAF_PDM_SOURCE_INIT( RimSurfaceCollection, "SurfaceCollection" );
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimSurfaceCollection::RimSurfaceCollection()
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
CAF_PDM_InitScriptableObject( "Surfaces", ":/Folder.png" );
|
2020-01-03 13:49:12 +01:00
|
|
|
|
2025-11-19 14:33:21 +01:00
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_collectionName, "SurfaceUserDescription", "Name" );
|
|
|
|
|
m_collectionName.registerKeywordAlias( "SurfaceUserDecription" );
|
|
|
|
|
|
2020-08-26 12:31:23 +02:00
|
|
|
m_collectionName = "Surfaces";
|
2020-08-24 11:09:22 +02:00
|
|
|
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_subCollections, "SubCollections", "Surfaces" );
|
2020-08-26 12:31:23 +02:00
|
|
|
auto reorderability = caf::PdmFieldReorderCapability::addToField( &m_subCollections );
|
2020-08-24 11:09:22 +02:00
|
|
|
reorderability->orderChanged.connect( this, &RimSurfaceCollection::orderChanged );
|
|
|
|
|
|
2026-05-12 14:24:43 +02:00
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_items, "SurfacesField", "Surfaces" );
|
2020-08-24 11:09:22 +02:00
|
|
|
|
|
|
|
|
setDeletable( true );
|
2020-01-03 13:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 11:13:38 +01:00
|
|
|
RimSurfaceCollection::~RimSurfaceCollection()
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-01-03 13:49:12 +01:00
|
|
|
|
2020-08-24 11:09:22 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-05-12 14:24:43 +02:00
|
|
|
RimSurfaceCollection* RimSurfaceCollection::createTopmost()
|
2020-08-24 11:09:22 +02:00
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
auto* coll = new RimSurfaceCollection();
|
|
|
|
|
coll->setAsTopmostFolder();
|
|
|
|
|
coll->uiCapability()->setUiIconFromResourceString( ":/ReservoirSurfaces16x16.png" );
|
|
|
|
|
return coll;
|
2020-08-24 11:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-03 13:49:12 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::addSurface( RimSurface* surface )
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
m_items.push_back( surface );
|
2026-08-07 08:34:58 +02:00
|
|
|
ensureUniqueSurfaceName( surface );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::ensureUniqueSurfaceName( RimSurface* surface )
|
|
|
|
|
{
|
|
|
|
|
if ( !surface ) return;
|
|
|
|
|
|
|
|
|
|
RiaNameUniquenessTools::ensureUniqueAmongSiblings( surface );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
|
|
|
|
{
|
|
|
|
|
if ( changedField == &m_collectionName )
|
|
|
|
|
{
|
|
|
|
|
// Keep the name unique among the folders in the same parent folder
|
|
|
|
|
m_collectionName = RiaNameUniquenessTools::resolveRenameConflict( this, newValue.toString() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
caf::PdmNestedCollection<RimSurfaceCollection, RimSurface>::fieldChangedByUi( changedField, oldValue, newValue );
|
2020-01-03 13:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-17 13:38:12 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::addEnsembleSurface( RimEnsembleSurface* ensembleSurface )
|
|
|
|
|
{
|
2021-09-13 10:16:09 +02:00
|
|
|
addSubCollection( ensembleSurface );
|
2021-08-17 13:38:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-23 09:59:29 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<RimEnsembleSurface*> RimSurfaceCollection::ensembleSurfaces() const
|
|
|
|
|
{
|
2023-05-12 21:41:34 +02:00
|
|
|
return descendantsIncludingThisOfType<RimEnsembleSurface>();
|
2021-09-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-05 15:29:23 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimSurface* RimSurfaceCollection::createSurfaceFromFile( const QString& fileName )
|
|
|
|
|
{
|
|
|
|
|
RimSurface* newSurface = nullptr;
|
|
|
|
|
|
|
|
|
|
auto extension = QFileInfo( fileName ).suffix().toLower();
|
|
|
|
|
|
|
|
|
|
if ( extension == "pvd" )
|
|
|
|
|
{
|
|
|
|
|
RimFractureSurface* fractureSurface = new RimFractureSurface;
|
|
|
|
|
fractureSurface->setSurfaceFilePath( fileName );
|
|
|
|
|
newSurface = fractureSurface;
|
|
|
|
|
}
|
|
|
|
|
else if ( extension == "irap" || extension == "gri" )
|
|
|
|
|
{
|
|
|
|
|
auto regularFileSurface = new RimRegularFileSurface;
|
|
|
|
|
regularFileSurface->setFilePath( fileName );
|
2026-01-20 15:42:27 +01:00
|
|
|
regularFileSurface->setPropertyAsDepth( RimRegularFileSurface::propertyName() );
|
2025-12-05 15:29:23 +01:00
|
|
|
newSurface = regularFileSurface;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RimFileSurface* fileSurface = new RimFileSurface;
|
2025-12-10 08:43:51 +01:00
|
|
|
fileSurface->setFilePath( fileName );
|
2025-12-05 15:29:23 +01:00
|
|
|
newSurface = fileSurface;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newSurface;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 13:49:12 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-09-30 17:25:24 +02:00
|
|
|
std::expected<RimSurface*, QString> RimSurfaceCollection::importSurfacesFromFiles( const QStringList& fileNames, bool showLegend /* = true */ )
|
2020-01-03 13:49:12 +01:00
|
|
|
{
|
2026-09-30 17:25:24 +02:00
|
|
|
if ( fileNames.isEmpty() ) return std::unexpected( "No surface files to import." );
|
|
|
|
|
|
|
|
|
|
size_t newSurfCount = 0;
|
|
|
|
|
size_t existingSurfCount = m_items().size();
|
|
|
|
|
QStringList errorMessages;
|
2020-01-03 13:49:12 +01:00
|
|
|
|
2020-08-11 11:34:34 +02:00
|
|
|
std::vector<RimSurface*> surfacesToLoad;
|
|
|
|
|
|
|
|
|
|
for ( const QString& newFileName : fileNames )
|
2020-01-03 13:49:12 +01:00
|
|
|
{
|
2026-09-30 17:25:24 +02:00
|
|
|
if ( !QFileInfo::exists( newFileName ) )
|
|
|
|
|
{
|
|
|
|
|
errorMessages << QString( "Could not import surface from file '%1'. File does not exist." ).arg( newFileName );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-05 15:29:23 +01:00
|
|
|
RimSurface* newSurface = createSurfaceFromFile( newFileName );
|
2021-09-23 09:59:29 +02:00
|
|
|
|
2025-01-17 14:45:42 +01:00
|
|
|
auto newColor = RiaColorTables::categoryPaletteColors().cycledColor3f( existingSurfCount + newSurfCount );
|
2020-01-03 13:49:12 +01:00
|
|
|
newSurface->setColor( newColor );
|
2025-01-17 14:45:42 +01:00
|
|
|
newSurface->setUserDescription( QFileInfo( newFileName ).fileName() );
|
2020-01-03 13:49:12 +01:00
|
|
|
|
2020-05-03 11:35:06 +02:00
|
|
|
if ( !newSurface->onLoadData() )
|
2020-01-03 13:49:12 +01:00
|
|
|
{
|
|
|
|
|
delete newSurface;
|
2026-09-30 17:25:24 +02:00
|
|
|
errorMessages << QString( "Could not import surface from file '%1'." ).arg( newFileName );
|
2020-01-03 13:49:12 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-08-04 09:04:14 +02:00
|
|
|
addSurface( newSurface );
|
2020-08-11 11:34:34 +02:00
|
|
|
surfacesToLoad.push_back( newSurface );
|
2020-01-03 13:49:12 +01:00
|
|
|
++newSurfCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !errorMessages.isEmpty() )
|
|
|
|
|
{
|
2026-09-30 17:25:24 +02:00
|
|
|
RiaLogging::warning( "Import Surfaces : " + errorMessages.join( "\n" ).toStdString() );
|
2020-01-03 13:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-04 09:04:14 +02:00
|
|
|
updateConnectedEditors();
|
2020-01-03 13:49:12 +01:00
|
|
|
|
2021-05-18 14:28:54 +02:00
|
|
|
updateViews( surfacesToLoad, showLegend );
|
2020-01-03 13:49:12 +01:00
|
|
|
|
2026-09-30 17:25:24 +02:00
|
|
|
if ( surfacesToLoad.empty() ) return std::unexpected( errorMessages.join( "\n" ) );
|
|
|
|
|
|
|
|
|
|
return surfacesToLoad.back();
|
2020-01-03 13:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 11:34:34 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-05-28 00:55:54 +02:00
|
|
|
void RimSurfaceCollection::reloadSurfaces( std::vector<RimSurface*> surfaces, bool showLegend /*=true*/ )
|
2020-08-11 11:34:34 +02:00
|
|
|
{
|
|
|
|
|
// ask the surfaces given to reload its data
|
|
|
|
|
for ( RimSurface* surface : surfaces )
|
|
|
|
|
{
|
|
|
|
|
surface->reloadData();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 09:04:14 +02:00
|
|
|
updateConnectedEditors();
|
2020-08-11 11:34:34 +02:00
|
|
|
|
2021-05-28 00:55:54 +02:00
|
|
|
updateViews( surfaces, showLegend );
|
2020-08-11 11:34:34 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-24 11:09:22 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimSurface* RimSurfaceCollection::copySurfaces( std::vector<RimSurface*> surfaces )
|
|
|
|
|
{
|
|
|
|
|
std::vector<RimSurface*> newsurfaces;
|
|
|
|
|
|
|
|
|
|
// create a copy of each surface given
|
|
|
|
|
for ( RimSurface* surface : surfaces )
|
|
|
|
|
{
|
|
|
|
|
RimSurface* copy = surface->createCopy();
|
|
|
|
|
if ( copy )
|
|
|
|
|
{
|
|
|
|
|
newsurfaces.push_back( copy );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::warning( "Create Surface Copy: Could not create a copy of the surface " + surface->fullName().toStdString() );
|
2020-08-24 11:09:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RimSurface* retsurf = nullptr;
|
|
|
|
|
for ( RimSurface* surface : newsurfaces )
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
m_items.push_back( surface );
|
2026-08-07 08:34:58 +02:00
|
|
|
ensureUniqueSurfaceName( surface );
|
2020-08-24 11:09:22 +02:00
|
|
|
retsurf = surface;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 09:04:14 +02:00
|
|
|
updateConnectedEditors();
|
2020-08-24 11:09:22 +02:00
|
|
|
|
|
|
|
|
return retsurf;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 11:29:33 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-08-17 13:38:12 +02:00
|
|
|
RimSurface* RimSurfaceCollection::addGridCaseSurface( RimCase* sourceCase, int oneBasedSliceIndex )
|
2020-05-03 11:29:33 +02:00
|
|
|
{
|
|
|
|
|
auto s = new RimGridCaseSurface;
|
|
|
|
|
s->setCase( sourceCase );
|
|
|
|
|
|
2020-08-24 11:09:22 +02:00
|
|
|
s->setOneBasedIndex( oneBasedSliceIndex );
|
2020-08-11 11:34:34 +02:00
|
|
|
|
|
|
|
|
if ( !s->onLoadData() )
|
|
|
|
|
{
|
2020-08-24 11:09:22 +02:00
|
|
|
RiaLogging::warning( "Add Grid Case Surface : Could not create the grid case surface." );
|
2020-08-11 11:34:34 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2020-04-30 20:51:25 +02:00
|
|
|
|
2026-05-12 14:24:43 +02:00
|
|
|
m_items.push_back( s );
|
2026-08-07 08:34:58 +02:00
|
|
|
ensureUniqueSurfaceName( s );
|
2020-05-03 11:29:33 +02:00
|
|
|
|
2023-08-04 09:04:14 +02:00
|
|
|
updateConnectedEditors();
|
2020-05-03 11:29:33 +02:00
|
|
|
|
2020-08-11 11:34:34 +02:00
|
|
|
std::vector<RimSurface*> surfacesToRefresh;
|
|
|
|
|
surfacesToRefresh.push_back( s );
|
|
|
|
|
updateViews( surfacesToRefresh );
|
|
|
|
|
|
2020-05-03 11:29:33 +02:00
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 11:30:06 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<RimSurface*> RimSurfaceCollection::surfaces() const
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
return m_items.childrenByType();
|
2020-08-24 11:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-24 10:25:42 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
|
|
|
|
|
{
|
|
|
|
|
menuBuilder << "RicImportSurfacesFeature";
|
|
|
|
|
menuBuilder << "RicNewGridSurfaceFeature";
|
|
|
|
|
menuBuilder << "RicNewDepthSurfaceFeature";
|
2025-05-12 13:12:31 +02:00
|
|
|
menuBuilder << "RicNewRegularSurfaceFeature";
|
2024-07-24 10:25:42 +02:00
|
|
|
menuBuilder << "RicImportEnsembleSurfaceFeature";
|
|
|
|
|
menuBuilder << "RicCreateEnsembleSurfaceFeature";
|
|
|
|
|
menuBuilder.addSeparator();
|
2026-05-12 14:24:43 +02:00
|
|
|
menuBuilder << "RicNewNestedCollectionFeature";
|
2026-09-25 15:39:45 +02:00
|
|
|
menuBuilder.addSeparator();
|
|
|
|
|
menuBuilder << "RicNewGenericDataViewFeature";
|
2024-07-24 10:25:42 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-08 11:56:48 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::loadData()
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
for ( auto surf : m_items )
|
2020-01-08 11:56:48 +01:00
|
|
|
{
|
2020-05-03 11:35:06 +02:00
|
|
|
surf->loadDataIfRequired();
|
2020-01-08 11:56:48 +01:00
|
|
|
}
|
2021-08-17 13:38:12 +02:00
|
|
|
|
2021-09-13 10:16:09 +02:00
|
|
|
for ( auto subColl : m_subCollections )
|
2021-08-17 13:38:12 +02:00
|
|
|
{
|
2021-09-13 10:16:09 +02:00
|
|
|
subColl->loadData();
|
2021-08-17 13:38:12 +02:00
|
|
|
}
|
2020-01-08 11:56:48 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-03 13:49:12 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-05-18 14:28:54 +02:00
|
|
|
void RimSurfaceCollection::updateViews( const std::vector<RimSurface*>& surfsToReload, bool showLegend /* = true */ )
|
2020-01-03 13:49:12 +01:00
|
|
|
{
|
2020-05-12 09:50:38 +02:00
|
|
|
RimProject* proj = RimProject::current();
|
2020-01-08 11:56:48 +01:00
|
|
|
|
2023-08-07 16:35:59 +02:00
|
|
|
// Make sure the tree items are synchronized
|
2024-04-04 08:50:28 +02:00
|
|
|
for ( auto view : proj->allViews() )
|
2020-01-06 11:30:06 +01:00
|
|
|
{
|
2024-02-12 10:19:52 +01:00
|
|
|
view->updateViewTreeItems( RiaDefines::ItemIn3dView::SURFACE );
|
2023-10-03 09:04:46 +02:00
|
|
|
|
|
|
|
|
if ( auto gridView = dynamic_cast<RimGridView*>( view ) )
|
|
|
|
|
{
|
|
|
|
|
auto seismicCollection = gridView->seismicSectionCollection();
|
|
|
|
|
seismicCollection->setSurfacesVisible( surfsToReload );
|
|
|
|
|
}
|
2020-01-06 11:30:06 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-07 16:35:59 +02:00
|
|
|
std::set<Rim3dView*> viewsNeedingUpdate;
|
2020-01-06 11:30:06 +01:00
|
|
|
|
|
|
|
|
for ( auto surf : surfsToReload )
|
|
|
|
|
{
|
2023-05-12 21:41:34 +02:00
|
|
|
std::vector<RimSurfaceInView*> surfsInView = surf->objectsWithReferringPtrFieldsOfType<RimSurfaceInView>();
|
2020-01-06 11:30:06 +01:00
|
|
|
for ( auto surfInView : surfsInView )
|
|
|
|
|
{
|
2020-05-03 11:29:33 +02:00
|
|
|
surfInView->clearGeometry();
|
2021-05-18 14:28:54 +02:00
|
|
|
surfInView->surfaceResultDefinition()->legendConfig()->setShowLegend( showLegend );
|
2020-05-03 11:29:33 +02:00
|
|
|
|
2023-08-07 16:35:59 +02:00
|
|
|
auto gridView = surfInView->firstAncestorOrThisOfType<Rim3dView>();
|
2020-01-06 11:30:06 +01:00
|
|
|
if ( gridView ) viewsNeedingUpdate.insert( gridView );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the views:
|
|
|
|
|
for ( auto view : viewsNeedingUpdate )
|
|
|
|
|
{
|
|
|
|
|
view->scheduleCreateDisplayModelAndRedraw();
|
2021-09-24 12:21:16 +02:00
|
|
|
|
|
|
|
|
if ( view->ownerCase() )
|
|
|
|
|
{
|
|
|
|
|
auto views = view->ownerCase()->intersectionViewCollection()->views();
|
|
|
|
|
for ( Rim2dIntersectionView* view : views )
|
|
|
|
|
{
|
|
|
|
|
view->scheduleCreateDisplayModelAndRedraw();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-06 11:30:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::updateViews()
|
|
|
|
|
{
|
2024-04-03 14:53:20 +02:00
|
|
|
RimProject* proj = RimProject::current();
|
|
|
|
|
std::vector<Rim3dView*> views = proj->allViews();
|
2020-01-06 11:30:06 +01:00
|
|
|
|
2020-05-03 11:29:33 +02:00
|
|
|
// Make sure the tree items are synchronized
|
2020-01-06 11:30:06 +01:00
|
|
|
|
|
|
|
|
for ( auto view : views )
|
|
|
|
|
{
|
2024-02-12 10:19:52 +01:00
|
|
|
view->updateViewTreeItems( RiaDefines::ItemIn3dView::SURFACE );
|
2020-01-06 11:30:06 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-03 13:49:12 +01:00
|
|
|
for ( auto view : views )
|
|
|
|
|
{
|
2020-01-06 11:30:06 +01:00
|
|
|
view->scheduleCreateDisplayModelAndRedraw();
|
2020-01-03 13:49:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-18 16:02:27 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 10:48:40 +01:00
|
|
|
void RimSurfaceCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& referringObjects )
|
2020-05-18 16:02:27 +02:00
|
|
|
{
|
|
|
|
|
updateViews();
|
|
|
|
|
}
|
2020-08-24 11:09:22 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::orderChanged( const caf::SignalEmitter* emitter )
|
|
|
|
|
{
|
|
|
|
|
updateViews();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::removeSurface( RimSurface* surface )
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
m_items.removeChild( surface );
|
2020-08-24 11:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-18 14:28:54 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimSurfaceCollection::removeMissingFileSurfaces()
|
|
|
|
|
{
|
|
|
|
|
// get the existing surfaces
|
|
|
|
|
std::list<RimFileSurface*> missingSurfaces;
|
|
|
|
|
|
|
|
|
|
// check if a filesurface references a file no longer present
|
|
|
|
|
for ( auto& surface : surfaces() )
|
|
|
|
|
{
|
|
|
|
|
RimFileSurface* fileSurface = dynamic_cast<RimFileSurface*>( surface );
|
|
|
|
|
if ( fileSurface == nullptr ) continue;
|
|
|
|
|
|
2025-12-10 08:43:51 +01:00
|
|
|
QString filename = fileSurface->filePath();
|
2021-05-18 14:28:54 +02:00
|
|
|
if ( !QFile::exists( filename ) )
|
|
|
|
|
{
|
|
|
|
|
missingSurfaces.push_back( fileSurface );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove all surfaces with a missing input file
|
|
|
|
|
for ( auto& surface : missingSurfaces )
|
|
|
|
|
{
|
|
|
|
|
removeSurface( surface );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 11:09:22 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimSurface* RimSurfaceCollection::addSurfacesAtIndex( int position, std::vector<RimSurface*> surfaces )
|
|
|
|
|
{
|
|
|
|
|
// adjust index for number of folders we have
|
2020-08-26 12:31:23 +02:00
|
|
|
position = position - static_cast<int>( m_subCollections.size() );
|
2020-08-24 11:09:22 +02:00
|
|
|
|
|
|
|
|
RimSurface* returnSurface = nullptr;
|
|
|
|
|
if ( !surfaces.empty() ) returnSurface = surfaces[0];
|
|
|
|
|
|
|
|
|
|
// insert position at end?
|
2026-05-12 14:24:43 +02:00
|
|
|
if ( ( position >= static_cast<int>( m_items.size() ) ) || ( position < 0 ) )
|
2020-08-24 11:09:22 +02:00
|
|
|
{
|
|
|
|
|
for ( auto surf : surfaces )
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
m_items.push_back( surf );
|
2020-08-24 11:09:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// build the new surface order
|
|
|
|
|
std::vector<RimSurface*> orderedSurfs;
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
while ( i < position )
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
orderedSurfs.push_back( m_items[i++] );
|
2020-08-24 11:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( auto surf : surfaces )
|
|
|
|
|
{
|
|
|
|
|
orderedSurfs.push_back( surf );
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 14:24:43 +02:00
|
|
|
int surfcount = static_cast<int>( m_items.size() );
|
2020-08-24 11:09:22 +02:00
|
|
|
while ( i < surfcount )
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
orderedSurfs.push_back( m_items[i++] );
|
2020-08-24 11:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// reset the surface collection and use the new order
|
2026-05-12 14:24:43 +02:00
|
|
|
m_items.clearWithoutDelete();
|
2020-08-24 11:09:22 +02:00
|
|
|
for ( auto surf : orderedSurfs )
|
|
|
|
|
{
|
2026-05-12 14:24:43 +02:00
|
|
|
m_items.push_back( surf );
|
2020-08-24 11:09:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-07 08:34:58 +02:00
|
|
|
// Surfaces moved in from another folder may collide with the names already present here
|
|
|
|
|
for ( auto surf : surfaces )
|
|
|
|
|
{
|
|
|
|
|
ensureUniqueSurfaceName( surf );
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 11:09:22 +02:00
|
|
|
// make sure the views are in sync with the collection order
|
|
|
|
|
updateViews();
|
|
|
|
|
|
|
|
|
|
return returnSurface;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 14:43:15 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimSurfaceCollection::containsSurface()
|
|
|
|
|
{
|
2023-09-27 08:07:49 +02:00
|
|
|
bool containsSurface = ( !surfaces().empty() );
|
2020-09-18 14:43:15 +02:00
|
|
|
|
|
|
|
|
for ( auto coll : m_subCollections )
|
|
|
|
|
{
|
|
|
|
|
containsSurface |= coll->containsSurface();
|
|
|
|
|
}
|
2021-08-17 13:38:12 +02:00
|
|
|
|
2020-09-18 14:43:15 +02:00
|
|
|
return containsSurface;
|
|
|
|
|
}
|
2021-05-18 14:28:54 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimSurfaceCollection::containsFileSurface( QString filename )
|
|
|
|
|
{
|
|
|
|
|
for ( auto& surface : surfaces() )
|
|
|
|
|
{
|
|
|
|
|
RimFileSurface* fileSurface = dynamic_cast<RimFileSurface*>( surface );
|
|
|
|
|
if ( fileSurface == nullptr ) continue;
|
2025-12-10 08:43:51 +01:00
|
|
|
if ( fileSurface->filePath() == filename ) return true;
|
2021-05-18 14:28:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|