Rename ApplicationCode to ApplicationLibCode

This commit is contained in:
Gaute Lindkvist
2021-01-06 14:55:29 +01:00
parent 751df1a421
commit 81699db187
3242 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimSurface.h
${CMAKE_CURRENT_LIST_DIR}/RimFileSurface.h
${CMAKE_CURRENT_LIST_DIR}/RimGridCaseSurface.h
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceInView.h
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceInViewCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceResultDefinition.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimSurface.cpp
${CMAKE_CURRENT_LIST_DIR}/RimFileSurface.cpp
${CMAKE_CURRENT_LIST_DIR}/RimGridCaseSurface.cpp
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceInView.cpp
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceInViewCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimSurfaceResultDefinition.cpp
)
list(APPEND CODE_HEADER_FILES
${SOURCE_GROUP_HEADER_FILES}
)
list(APPEND CODE_SOURCE_FILES
${SOURCE_GROUP_SOURCE_FILES}
)
source_group( "ProjectDataModel\\Surface" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )

View File

@@ -0,0 +1,203 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimFileSurface.h"
#include "RiaPreferences.h"
#include "RifSurfaceImporter.h"
#include "RigGocadData.h"
#include "RigSurface.h"
#include "RimSurfaceCollection.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
#include <QFileInfo>
// TODO: Use the alias concept prototyped below when the alias concept for class is ready
// CAF_PDM_SOURCE_INIT( RimFileSurface, "FileSurface", "Surface" );
// CAF_PDM_SOURCE_INIT( <class> , <keyword> , <alias>);
CAF_PDM_SOURCE_INIT( RimFileSurface, "Surface" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFileSurface::RimFileSurface()
{
CAF_PDM_InitScriptableObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_surfaceDefinitionFilePath, "SurfaceFilePath", "File", "", "", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFileSurface::~RimFileSurface()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFileSurface::setSurfaceFilePath( const QString& filePath )
{
m_surfaceDefinitionFilePath = filePath;
if ( userDescription().isEmpty() )
{
setUserDescription( QFileInfo( filePath ).fileName() );
}
clearCachedNativeData();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimFileSurface::surfaceFilePath()
{
return m_surfaceDefinitionFilePath().path();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::onLoadData()
{
return updateSurfaceData();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimFileSurface::createCopy()
{
RimFileSurface* newSurface = dynamic_cast<RimFileSurface*>(
xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
if ( !newSurface->onLoadData() )
{
delete newSurface;
return nullptr;
}
return newSurface;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFileSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
RimSurface::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_surfaceDefinitionFilePath )
{
clearCachedNativeData();
updateSurfaceData();
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( { this } );
}
}
//--------------------------------------------------------------------------------------------------
/// Regenerate the surface geometry, using the offset specified.
/// If the surface data hasn't been loaded from file yet, load it.
/// Returns false for fatal failure
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::updateSurfaceData()
{
bool result = true;
if ( m_vertices.empty() )
{
result = loadDataFromFile();
}
std::vector<cvf::Vec3d> vertices{ m_vertices };
std::vector<unsigned> tringleIndices{ m_tringleIndices };
auto surface = new RigSurface;
if ( !vertices.empty() && !tringleIndices.empty() )
{
RimSurface::applyDepthOffsetIfNeeded( &vertices );
surface->setTriangleData( tringleIndices, vertices );
}
if ( m_gocadData )
{
auto propertyNames = m_gocadData->propertyNames();
for ( const auto& name : propertyNames )
{
auto values = m_gocadData->propertyValues( name );
surface->addVerticeResult( name, values );
}
}
setSurfaceData( surface );
return result;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFileSurface::clearCachedNativeData()
{
m_vertices.clear();
m_tringleIndices.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::loadDataFromFile()
{
std::pair<std::vector<cvf::Vec3d>, std::vector<unsigned>> surface;
QString filePath = this->surfaceFilePath();
if ( filePath.endsWith( "ptl", Qt::CaseInsensitive ) )
{
surface = RifSurfaceImporter::readPetrelFile( filePath );
}
else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) )
{
m_gocadData.reset( new RigGocadData );
RifSurfaceImporter::readGocadFile( filePath, m_gocadData.get() );
surface = m_gocadData->gocadGeometry();
}
else if ( filePath.endsWith( "dat", Qt::CaseInsensitive ) )
{
double resamplingDistance = RiaPreferences::current()->surfaceImportResamplingDistance();
surface = RifSurfaceImporter::readOpenWorksXyzFile( filePath, resamplingDistance );
}
m_vertices = surface.first;
m_tringleIndices = surface.second;
if ( m_vertices.empty() || m_tringleIndices.empty() ) return false;
return true;
}

View File

@@ -0,0 +1,57 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RimSurface.h"
#include <memory>
class RigGocadData;
class RimFileSurface : public RimSurface
{
CAF_PDM_HEADER_INIT;
public:
RimFileSurface();
~RimFileSurface() override;
void setSurfaceFilePath( const QString& filePath );
QString surfaceFilePath();
bool onLoadData() override;
RimSurface* createCopy() override;
protected:
bool updateSurfaceData() override;
void clearCachedNativeData() override;
private:
bool loadDataFromFile();
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
caf::PdmField<caf::FilePath> m_surfaceDefinitionFilePath;
std::vector<unsigned> m_tringleIndices;
std::vector<cvf::Vec3d> m_vertices;
std::unique_ptr<RigGocadData> m_gocadData;
};

View File

@@ -0,0 +1,463 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimGridCaseSurface.h"
#include "RigSurface.h"
#include "RigMainGrid.h"
#include "RimCase.h"
#include "RimEclipseCase.h"
#include "RimSurfaceCollection.h"
#include "RimTools.h"
#include "cafPdmUiSliderEditor.h"
#include "RigReservoirGridTools.h"
#include "cvfVector3.h"
CAF_PDM_SOURCE_INIT( RimGridCaseSurface, "GridCaseSurface" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridCaseSurface::RimGridCaseSurface()
{
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_case, "SourceCase", "Source Case", "", "", "" );
CAF_PDM_InitField( &m_oneBasedSliceIndex, "SliceIndex", 1, "Slice Index (K)", "", "", "" );
m_oneBasedSliceIndex.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridCaseSurface::~RimGridCaseSurface()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCaseSurface::setCase( RimCase* sourceCase )
{
m_case = sourceCase;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCaseSurface::setOneBasedIndex( int oneBasedSliceIndex )
{
m_oneBasedSliceIndex = oneBasedSliceIndex;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimGridCaseSurface::onLoadData()
{
return updateSurfaceData();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimGridCaseSurface::createCopy()
{
RimGridCaseSurface* newSurface = dynamic_cast<RimGridCaseSurface*>(
xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
newSurface->setCase( m_case.value() ); // TODO: case seems to get lost in the xml copy, investigate later
if ( !newSurface->onLoadData() )
{
delete newSurface;
return nullptr;
}
return newSurface;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimGridCaseSurface::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
bool* useOptionsOnly )
{
QList<caf::PdmOptionItemInfo> options;
if ( fieldNeedingOptions == &m_case )
{
RimTools::caseOptionItems( &options );
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCaseSurface::defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute )
{
RimSurface::defineEditorAttribute( field, uiConfigName, attribute );
caf::PdmUiSliderEditorAttribute* myAttr = dynamic_cast<caf::PdmUiSliderEditorAttribute*>( attribute );
if ( myAttr && m_case )
{
const cvf::StructGridInterface* grid = RigReservoirGridTools::mainGrid( m_case );
if ( !grid ) return;
myAttr->m_minimum = 1;
myAttr->m_maximum = static_cast<int>( grid->cellCountK() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCaseSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
RimSurface::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_case || changedField == &m_oneBasedSliceIndex )
{
clearCachedNativeData();
updateSurfaceData();
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( { this } );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCaseSurface::extractDataFromGrid()
{
clearCachedNativeData();
if ( m_case )
{
RimEclipseCase* eclCase = dynamic_cast<RimEclipseCase*>( m_case() );
if ( eclCase && eclCase->mainGrid() )
{
const RigMainGrid* grid = eclCase->mainGrid();
size_t minI = 0;
size_t minJ = 0;
size_t minK = 0;
size_t maxI = grid->cellCountI();
size_t maxJ = grid->cellCountJ();
size_t maxK = grid->cellCountK();
size_t row = 0;
size_t maxRow = 0;
size_t column = 0;
size_t maxColumn = 0;
size_t zeroBasedLayerIndex = static_cast<size_t>( m_oneBasedSliceIndex ) - 1;
cvf::StructGridInterface::FaceType faceType = cvf::StructGridInterface::NO_FACE;
{
auto sliceDirection = RiaDefines::GridCaseAxis::AXIS_K;
if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_K )
{
faceType = cvf::StructGridInterface::NEG_K;
minK = zeroBasedLayerIndex;
maxK = zeroBasedLayerIndex;
maxRow = maxJ;
maxColumn = maxI;
}
else if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_J )
{
faceType = cvf::StructGridInterface::NEG_J;
minJ = zeroBasedLayerIndex;
maxJ = zeroBasedLayerIndex;
maxRow = maxK;
maxColumn = maxI;
}
else if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_I )
{
faceType = cvf::StructGridInterface::NEG_I;
minI = zeroBasedLayerIndex;
maxI = zeroBasedLayerIndex;
maxRow = maxK;
maxColumn = maxJ;
}
}
std::vector<unsigned> triangleIndices;
std::vector<cvf::Vec3d> vertices;
std::vector<std::pair<unsigned, unsigned>> structGridVertexIndices;
for ( size_t i = minI; i <= maxI; i++ )
{
for ( size_t j = minJ; j <= maxJ; j++ )
{
for ( size_t k = minK; k <= maxK; k++ )
{
switch ( faceType )
{
case cvf::StructGridInterface::NEG_I:
row = k;
column = j;
break;
case cvf::StructGridInterface::NEG_J:
row = k;
column = i;
break;
case cvf::StructGridInterface::NEG_K:
row = j;
column = i;
break;
}
size_t cellIndex = 0;
size_t cellFaceIndex = 0;
if ( !findValidCellIndex( grid, faceType, cellIndex, row, column, zeroBasedLayerIndex, cellFaceIndex ) )
return;
cvf::Vec3d cornerVerts[8];
grid->cellCornerVertices( cellIndex, cornerVerts );
cvf::ubyte faceConn[4];
grid->cellFaceVertexIndices( faceType, faceConn );
structGridVertexIndices.push_back(
std::make_pair( static_cast<cvf::uint>( column + 1 ), static_cast<cvf::uint>( row + 1 ) ) );
vertices.push_back( cornerVerts[faceConn[cellFaceIndex]] );
if ( row < maxRow && column < maxColumn )
{
cvf::uint triangleIndexLeft = static_cast<cvf::uint>( column * ( maxRow + 1 ) + row );
cvf::uint triangleIndexRight = static_cast<cvf::uint>( ( column + 1 ) * ( maxRow + 1 ) + row );
triangleIndices.push_back( triangleIndexLeft );
triangleIndices.push_back( triangleIndexLeft + 1 );
triangleIndices.push_back( triangleIndexRight + 1 );
triangleIndices.push_back( triangleIndexLeft );
triangleIndices.push_back( triangleIndexRight + 1 );
triangleIndices.push_back( triangleIndexRight );
}
}
}
}
m_vertices = vertices;
m_triangleIndices = triangleIndices;
m_structGridIndices = structGridVertexIndices;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimGridCaseSurface::findValidCellIndex( const RigMainGrid* grid,
const cvf::StructGridInterface::FaceType faceType,
size_t& cellIndex,
const size_t row,
const size_t column,
const size_t layer,
size_t& cellFaceIndex )
{
auto getCellFromRowColumnLayer = [grid, faceType]( size_t row, size_t column, size_t layer ) -> size_t {
if ( faceType == cvf::StructGridInterface::NEG_I ) return grid->cellIndexFromIJK( layer, column, row );
if ( faceType == cvf::StructGridInterface::NEG_J ) return grid->cellIndexFromIJK( column, layer, row );
return grid->cellIndexFromIJK( column, row, layer );
};
auto isCellValid = [grid, faceType]( size_t row, size_t column, size_t layer ) -> bool {
if ( faceType == cvf::StructGridInterface::NEG_I )
{
return column < grid->cellCountJ() && row < grid->cellCountK() &&
!grid->cell( grid->cellIndexFromIJK( layer, column, row ) ).isInvalid();
}
if ( faceType == cvf::StructGridInterface::NEG_J )
{
return column < grid->cellCountI() && row < grid->cellCountK() &&
!grid->cell( grid->cellIndexFromIJK( column, layer, row ) ).isInvalid();
}
return column < grid->cellCountI() && row < grid->cellCountJ() &&
!grid->cell( grid->cellIndexFromIJK( column, row, layer ) ).isInvalid();
};
if ( isCellValid( row, column, layer ) )
{
cellIndex = getCellFromRowColumnLayer( row, column, layer );
cellFaceIndex = 0;
return true;
}
if ( isCellValid( row - 1, column, layer ) )
{
cellIndex = getCellFromRowColumnLayer( row - 1, column, layer );
cellFaceIndex = 1;
return true;
}
if ( isCellValid( row, column - 1, layer ) )
{
cellIndex = getCellFromRowColumnLayer( row, column - 1, layer );
cellFaceIndex = 3;
return true;
}
if ( isCellValid( row - 1, column - 1, layer ) )
{
cellIndex = getCellFromRowColumnLayer( row - 1, column - 1, layer );
cellFaceIndex = 2;
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCaseSurface::clearCachedNativeData()
{
m_vertices.clear();
m_triangleIndices.clear();
m_structGridIndices.clear();
}
//--------------------------------------------------------------------------------------------------
/// Returns false for fatal failure
//--------------------------------------------------------------------------------------------------
bool RimGridCaseSurface::updateSurfaceData()
{
if ( m_vertices.empty() || m_triangleIndices.empty() || m_structGridIndices.empty() )
{
extractDataFromGrid();
}
RigSurface* surfaceData = nullptr;
std::vector<unsigned> tringleIndices{ m_triangleIndices };
std::vector<cvf::Vec3d> vertices{ m_vertices };
RiaDefines::GridCaseAxis sliceDirection = RiaDefines::GridCaseAxis::AXIS_K;
if ( !tringleIndices.empty() )
{
{
// Modify the z-value slightly to avoid geometrical numerical issues when the surface intersects
// exactly at the cell face
double delta = 1.0e-5;
cvf::Vec3d offset = cvf::Vec3d::ZERO;
if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_I )
{
offset.x() += delta;
}
else if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_J )
{
offset.y() += delta;
}
if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_K )
{
offset.z() += delta;
}
// Include the potential depth offset in the base class
offset.z() += depthOffset();
RimSurface::applyDepthOffset( offset, &vertices );
}
surfaceData = new RigSurface;
surfaceData->setTriangleData( tringleIndices, vertices );
}
setSurfaceData( surfaceData );
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimGridCaseSurface::exportStructSurfaceFromGridCase( std::vector<cvf::Vec3d>* vertices,
std::vector<std::pair<uint, uint>>* structGridVertexIndices )
{
if ( m_vertices.empty() || m_triangleIndices.empty() || m_structGridIndices.empty() )
{
extractDataFromGrid();
}
if ( m_vertices.empty() ) return false;
*vertices = m_vertices;
*structGridVertexIndices = m_structGridIndices;
RiaDefines::GridCaseAxis sliceDirection = RiaDefines::GridCaseAxis::AXIS_K;
if ( !vertices->empty() )
{
// Permute z-value to avoid numerical issues when surface intersects exactly at cell face
double delta = 1.0e-5;
cvf::Vec3d offset = cvf::Vec3d::ZERO;
if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_I )
{
offset.x() += delta;
}
else if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_J )
{
offset.y() += delta;
}
else if ( sliceDirection == RiaDefines::GridCaseAxis::AXIS_K )
{
offset.z() += delta;
}
// Include the potential depth offset in the base class
offset.z() += depthOffset();
RimSurface::applyDepthOffset( offset, vertices );
}
return true;
}
//--------------------------------------------------------------------------------------------------
/// Return the name to show in the tree selector, including the slice index
//--------------------------------------------------------------------------------------------------
QString RimGridCaseSurface::fullName() const
{
QString retval = RimSurface::fullName();
retval += " - K:";
retval += QString::number( m_oneBasedSliceIndex );
return retval;
}

View File

@@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RimSurface.h"
#include "RiaDefines.h"
#include "cafPdmPtrField.h"
#include "cvfStructGrid.h"
class RigMainGrid;
class RimCase;
class RimGridCaseSurface : public RimSurface
{
CAF_PDM_HEADER_INIT;
public:
RimGridCaseSurface();
~RimGridCaseSurface() override;
void setCase( RimCase* sourceCase );
void setOneBasedIndex( int oneBasedSliceIndex );
bool onLoadData() override;
RimSurface* createCopy() override;
bool exportStructSurfaceFromGridCase( std::vector<cvf::Vec3d>* vertices,
std::vector<std::pair<uint, uint>>* structGridVertexIndices );
protected:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
bool* useOptionsOnly ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute ) override;
bool updateSurfaceData() override;
void clearCachedNativeData() override;
QString fullName() const override;
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void extractDataFromGrid();
bool findValidCellIndex( const RigMainGrid* grid,
const cvf::StructGridInterface::FaceType faceType,
size_t& cellIndex,
const size_t row,
const size_t column,
const size_t layer,
size_t& cellFaceIndex );
private:
caf::PdmPtrField<RimCase*> m_case;
caf::PdmField<int> m_oneBasedSliceIndex;
std::vector<unsigned> m_triangleIndices;
std::vector<cvf::Vec3d> m_vertices;
std::vector<std::pair<unsigned, unsigned>> m_structGridIndices;
};

View File

@@ -0,0 +1,266 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimSurface.h"
#include "RiaApplication.h"
#include "RimCase.h"
#include "RimProject.h"
#include "RimSurfaceCollection.h"
#include "RigSurface.h"
#include "RifSurfaceImporter.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
#include "cafPdmUiDoubleSliderEditor.h"
#include "cvfBoundingBox.h"
#include <algorithm>
#include <cmath>
CAF_PDM_ABSTRACT_SOURCE_INIT( RimSurface, "SurfaceInterface" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface::RimSurface()
{
CAF_PDM_InitScriptableObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_userDescription, "SurfaceUserDecription", "Name", "", "", "" );
CAF_PDM_InitField( &m_color, "SurfaceColor", cvf::Color3f( 0.5f, 0.3f, 0.2f ), "Color", "", "", "" );
CAF_PDM_InitScriptableField( &m_depthOffset, "DepthOffset", 0.0, "Depth Offset", "", "", "" );
m_depthOffset.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() );
m_depthOffset.capability<caf::PdmAbstractFieldScriptingCapability>()->setIOWriteable( true );
CAF_PDM_InitFieldNoDefault( &m_nameProxy, "NameProxy", "Name Proxy", "", "", "" );
m_nameProxy.registerGetMethod( this, &RimSurface::fullName );
m_nameProxy.uiCapability()->setUiReadOnly( true );
m_nameProxy.uiCapability()->setUiHidden( true );
m_nameProxy.xmlCapability()->disableIO();
setDeletable( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface::~RimSurface()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::setColor( const cvf::Color3f& color )
{
m_color = color;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Color3f RimSurface::color() const
{
return m_color();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSurface::userDescription()
{
return m_userDescription();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimSurface::userDescriptionField()
{
return &m_nameProxy;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::loadDataIfRequired()
{
if ( m_surfaceData.isNull() )
{
onLoadData();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::setUserDescription( const QString& description )
{
m_userDescription = description;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::setSurfaceData( RigSurface* surface )
{
m_surfaceData = surface;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::applyDepthOffsetIfNeeded( std::vector<cvf::Vec3d>* vertices ) const
{
double epsilon = 1.0e-10;
if ( std::fabs( m_depthOffset ) > epsilon )
{
cvf::Vec3d offset = cvf::Vec3d::ZERO;
offset.z() += m_depthOffset;
RimSurface::applyDepthOffset( offset, vertices );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimSurface::depthOffset() const
{
return m_depthOffset;
}
void RimSurface::setDepthOffset( double depthoffset )
{
m_depthOffset.setValue( depthoffset );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::applyDepthOffset( const cvf::Vec3d& offset, std::vector<cvf::Vec3d>* vertices )
{
if ( vertices )
{
for ( auto& v : *vertices )
{
v += offset;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigSurface* RimSurface::surfaceData()
{
return m_surfaceData.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
bool updateViews = false;
if ( changedField == &m_color )
{
updateViews = true;
}
else if ( changedField == &m_userDescription )
{
this->updateConnectedEditors();
}
else if ( changedField == &m_depthOffset )
{
this->onLoadData();
updateViews = true;
}
if ( updateViews )
{
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( { this } );
}
}
//--------------------------------------------------------------------------------------------------
/// Make the surface clear its internal data and reload them from the source data (i.e. file or grid)
//--------------------------------------------------------------------------------------------------
void RimSurface::reloadData()
{
clearCachedNativeData();
updateSurfaceData();
}
//--------------------------------------------------------------------------------------------------
/// Return the name to show in the tree selector, including the depth offset if not 0
//--------------------------------------------------------------------------------------------------
QString RimSurface::fullName() const
{
if ( depthOffset() != 0.0 )
{
return QString( "%1 - Offset:%2" ).arg( m_userDescription, QString::number( depthOffset() ) );
}
return QString( "%1" ).arg( m_userDescription );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute )
{
auto doubleSliderAttrib = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>( attribute );
if ( doubleSliderAttrib )
{
if ( field == &m_depthOffset )
{
RiaApplication* app = RiaApplication::instance();
std::vector<RimCase*> cases;
app->project()->allCases( cases );
cvf::BoundingBox bb;
for ( auto c : cases )
{
bb.add( c->allCellsBoundingBox() );
}
double extentFromCase = std::fabs( bb.extent().z() ) * 2.0;
extentFromCase = std::floor( extentFromCase / 1000.0 ) * 1000.0;
double minimumExtent = std::max( 1000.0, extentFromCase );
doubleSliderAttrib->m_minimum = -minimumExtent;
doubleSliderAttrib->m_maximum = minimumExtent;
}
}
}

View File

@@ -0,0 +1,81 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmFieldCvfColor.h"
#include "cafPdmProxyValueField.h"
#include "cvfObject.h"
#include "cvfVector3.h"
#include <vector>
class RigSurface;
class RimSurface : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimSurface();
~RimSurface() override;
void setColor( const cvf::Color3f& color );
cvf::Color3f color() const;
RigSurface* surfaceData();
QString userDescription();
void setUserDescription( const QString& description );
virtual QString fullName() const;
virtual bool onLoadData() = 0;
virtual RimSurface* createCopy() = 0;
void loadDataIfRequired();
void reloadData();
protected:
void setSurfaceData( RigSurface* surface );
void applyDepthOffsetIfNeeded( std::vector<cvf::Vec3d>* vertices ) const;
double depthOffset() const;
void setDepthOffset( double depthoffset );
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute ) override;
static void applyDepthOffset( const cvf::Vec3d& offset, std::vector<cvf::Vec3d>* vertices );
caf::PdmFieldHandle* userDescriptionField() override;
virtual bool updateSurfaceData() = 0;
virtual void clearCachedNativeData() = 0;
private:
caf::PdmField<QString> m_userDescription;
caf::PdmField<cvf::Color3f> m_color;
caf::PdmField<double> m_depthOffset;
caf::PdmProxyValueField<QString> m_nameProxy;
cvf::ref<RigSurface> m_surfaceData;
};

View File

@@ -0,0 +1,448 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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"
#include "RiaColorTables.h"
#include "RiaLogging.h"
#include "RimFileSurface.h"
#include "RimGridCaseSurface.h"
#include "RimGridView.h"
#include "RimProject.h"
#include "RimSurface.h"
#include "RimSurfaceInView.h"
#include "cafPdmFieldReorderCapability.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
CAF_PDM_SOURCE_INIT( RimSurfaceCollection, "SurfaceCollection" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceCollection::RimSurfaceCollection()
{
CAF_PDM_InitScriptableObject( "Surfaces", ":/ReservoirSurfaces16x16.png", "", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_collectionName, "SurfaceUserDecription", "Name", "", "", "" );
m_collectionName = "Surfaces";
CAF_PDM_InitScriptableFieldNoDefault( &m_subCollections, "SubCollections", "Surfaces", "", "", "" );
m_subCollections.uiCapability()->setUiTreeHidden( true );
auto reorderability = caf::PdmFieldReorderCapability::addToField( &m_subCollections );
reorderability->orderChanged.connect( this, &RimSurfaceCollection::orderChanged );
CAF_PDM_InitScriptableFieldNoDefault( &m_surfaces, "SurfacesField", "Surfaces", "", "", "" );
m_surfaces.uiCapability()->setUiTreeHidden( true );
setDeletable( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceCollection::~RimSurfaceCollection()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::setAsTopmostFolder()
{
m_collectionName.uiCapability()->setUiHidden( true );
setDeletable( false );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSurfaceCollection::collectionName() const
{
return m_collectionName.value();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::setCollectionName( const QString name )
{
return m_collectionName.setValue( name );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimSurfaceCollection::userDescriptionField()
{
return &m_collectionName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::addSurface( RimSurface* surface )
{
m_surfaces.push_back( surface );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimSurfaceCollection::importSurfacesFromFiles( const QStringList& fileNames )
{
size_t newSurfCount = 0;
size_t existingSurfCount = m_surfaces().size();
QString errorMessages;
std::vector<RimSurface*> surfacesToLoad;
for ( const QString& newFileName : fileNames )
{
RimFileSurface* newSurface = new RimFileSurface;
auto newColor = RiaColorTables::categoryPaletteColors().cycledColor3f( existingSurfCount + newSurfCount );
newSurface->setSurfaceFilePath( newFileName );
newSurface->setColor( newColor );
if ( !newSurface->onLoadData() )
{
delete newSurface;
errorMessages += newFileName + "\n";
}
else
{
this->addSurface( newSurface );
surfacesToLoad.push_back( newSurface );
++newSurfCount;
}
}
if ( !errorMessages.isEmpty() )
{
RiaLogging::warning( "Import Surfaces : Could not import the following files:\n" + errorMessages );
}
this->updateConnectedEditors();
updateViews( surfacesToLoad );
if ( newSurfCount > 0 && !m_surfaces.empty() )
{
return m_surfaces[m_surfaces.size() - 1];
}
else
{
return nullptr;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::reloadSurfaces( std::vector<RimSurface*> surfaces )
{
// ask the surfaces given to reload its data
for ( RimSurface* surface : surfaces )
{
surface->reloadData();
}
this->updateConnectedEditors();
updateViews( surfaces );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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
{
RiaLogging::warning( "Create Surface Copy: Could not create a copy of the surface " + surface->fullName() );
}
}
RimSurface* retsurf = nullptr;
for ( RimSurface* surface : newsurfaces )
{
m_surfaces.push_back( surface );
retsurf = surface;
}
this->updateConnectedEditors();
return retsurf;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimSurfaceCollection::addGridCaseSurface( RimCase* sourceCase )
{
auto s = new RimGridCaseSurface;
s->setCase( sourceCase );
int oneBasedSliceIndex = 1;
s->setOneBasedIndex( oneBasedSliceIndex );
s->setUserDescription( "Surface" );
if ( !s->onLoadData() )
{
RiaLogging::warning( "Add Grid Case Surface : Could not create the grid case surface." );
return nullptr;
}
m_surfaces.push_back( s );
this->updateConnectedEditors();
std::vector<RimSurface*> surfacesToRefresh;
surfacesToRefresh.push_back( s );
updateViews( surfacesToRefresh );
return s;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSurface*> RimSurfaceCollection::surfaces() const
{
return m_surfaces.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSurfaceCollection*> RimSurfaceCollection::subCollections() const
{
return m_subCollections.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::loadData()
{
for ( auto surf : m_surfaces )
{
surf->loadDataIfRequired();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::updateViews( const std::vector<RimSurface*>& surfsToReload )
{
RimProject* proj = RimProject::current();
std::vector<Rim3dView*> views;
proj->allViews( views );
// Make sure the tree items are synchronized
for ( auto view : views )
{
auto gridView = dynamic_cast<RimGridView*>( view );
if ( gridView ) gridView->updateSurfacesInViewTreeItems();
}
std::set<RimGridView*> viewsNeedingUpdate;
for ( auto surf : surfsToReload )
{
std::vector<RimSurfaceInView*> surfsInView;
surf->objectsWithReferringPtrFieldsOfType( surfsInView );
for ( auto surfInView : surfsInView )
{
surfInView->clearGeometry();
RimGridView* gridView;
surfInView->firstAncestorOrThisOfType( gridView );
if ( gridView ) viewsNeedingUpdate.insert( gridView );
}
}
// Update the views:
for ( auto view : viewsNeedingUpdate )
{
view->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::updateViews()
{
RimProject* proj = RimProject::current();
std::vector<RimGridView*> views;
proj->allVisibleGridViews( views );
// Make sure the tree items are synchronized
for ( auto view : views )
{
view->updateSurfacesInViewTreeItems();
}
for ( auto view : views )
{
view->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects )
{
updateViews();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::orderChanged( const caf::SignalEmitter* emitter )
{
updateViews();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::removeSurface( RimSurface* surface )
{
m_surfaces.removeChildObject( surface );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimSurfaceCollection::addSurfacesAtIndex( int position, std::vector<RimSurface*> surfaces )
{
// adjust index for number of folders we have
position = position - static_cast<int>( m_subCollections.size() );
RimSurface* returnSurface = nullptr;
if ( !surfaces.empty() ) returnSurface = surfaces[0];
// insert position at end?
if ( ( position >= static_cast<int>( m_surfaces.size() ) ) || ( position < 0 ) )
{
for ( auto surf : surfaces )
{
m_surfaces.push_back( surf );
}
}
else
{
// build the new surface order
std::vector<RimSurface*> orderedSurfs;
int i = 0;
while ( i < position )
{
orderedSurfs.push_back( m_surfaces[i++] );
}
for ( auto surf : surfaces )
{
orderedSurfs.push_back( surf );
}
int surfcount = static_cast<int>( m_surfaces.size() );
while ( i < surfcount )
{
orderedSurfs.push_back( m_surfaces[i++] );
}
// reset the surface collection and use the new order
m_surfaces.clear();
for ( auto surf : orderedSurfs )
{
m_surfaces.push_back( surf );
}
}
// make sure the views are in sync with the collection order
updateViews();
return returnSurface;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceCollection::addSubCollection( RimSurfaceCollection* subcoll )
{
m_subCollections.push_back( subcoll );
this->updateConnectedEditors();
updateViews();
return;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceCollection* RimSurfaceCollection::getSubCollection( const QString name )
{
for ( auto coll : m_subCollections )
{
if ( coll->collectionName() == name ) return coll;
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSurfaceCollection::containsSurface()
{
bool containsSurface = ( surfaces().size() > 0 );
for ( auto coll : m_subCollections )
{
containsSurface |= coll->containsSurface();
}
return containsSurface;
}

View File

@@ -0,0 +1,75 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmField.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmObject.h"
class RimSurface;
class RimCase;
class RimSurfaceCollection : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimSurfaceCollection();
~RimSurfaceCollection() override;
void addSurface( RimSurface* surface );
void setAsTopmostFolder();
RimSurface* importSurfacesFromFiles( const QStringList& fileNames );
RimSurface* addGridCaseSurface( RimCase* sourceCase );
RimSurface* copySurfaces( std::vector<RimSurface*> surfaces );
RimSurface* addSurfacesAtIndex( int index, std::vector<RimSurface*> surfaces );
void addSubCollection( RimSurfaceCollection* collection );
RimSurfaceCollection* getSubCollection( const QString name );
bool containsSurface();
void reloadSurfaces( std::vector<RimSurface*> surfaces );
void removeSurface( RimSurface* surface );
void loadData();
void updateViews();
void updateViews( const std::vector<RimSurface*>& surfsToReload );
void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects ) override;
QString collectionName() const;
void setCollectionName( const QString name );
std::vector<RimSurface*> surfaces() const;
std::vector<RimSurfaceCollection*> subCollections() const;
protected:
caf::PdmFieldHandle* userDescriptionField() override;
private:
void orderChanged( const caf::SignalEmitter* emitter );
caf::PdmField<QString> m_collectionName;
caf::PdmChildArrayField<RimSurface*> m_surfaces;
caf::PdmChildArrayField<RimSurfaceCollection*> m_subCollections;
};

View File

@@ -0,0 +1,252 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimSurfaceInView.h"
#include "RigFemPartCollection.h"
#include "RigSurface.h"
#include "RimEclipseView.h"
#include "RimGeoMechView.h"
#include "RimGridView.h"
#include "RimRegularLegendConfig.h"
#include "RimSurface.h"
#include "RimSurfaceResultDefinition.h"
#include "RiuViewer.h"
#include "RivHexGridIntersectionTools.h"
#include "RivSurfacePartMgr.h"
#include "cafPdmUiDoubleSliderEditor.h"
CAF_PDM_SOURCE_INIT( RimSurfaceInView, "SurfaceInView" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceInView::RimSurfaceInView()
{
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_name, "Name", "Name", "", "", "" );
m_name.registerGetMethod( this, &RimSurfaceInView::name );
m_name.uiCapability()->setUiReadOnly( true );
CAF_PDM_InitFieldNoDefault( &m_surface, "SurfaceRef", "Surface", "", "", "" );
m_surface.uiCapability()->setUiHidden( true );
CAF_PDM_InitFieldNoDefault( &m_resultDefinition, "ResultDefinition", "Result Definition", "", "", "" );
m_resultDefinition.uiCapability()->setUiHidden( true );
m_resultDefinition.uiCapability()->setUiTreeChildrenHidden( true );
m_resultDefinition = new RimSurfaceResultDefinition;
m_resultDefinition->setCheckState( false );
m_resultDefinition->setSurfaceInView( this );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceInView::~RimSurfaceInView()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSurfaceInView::name() const
{
if ( m_surface ) return m_surface->fullName();
return "";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimSurfaceInView::surface() const
{
return m_surface();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::setSurface( RimSurface* surf )
{
m_surface = surf;
if ( surface()->surfaceData() && surface()->surfaceData()->propertyNames().empty() )
{
m_resultDefinition.uiCapability()->setUiTreeChildrenHidden( true );
m_resultDefinition->setCheckState( false );
}
else
{
m_resultDefinition.uiCapability()->setUiTreeChildrenHidden( false );
m_resultDefinition->setCheckState( true );
m_resultDefinition->assignDefaultProperty();
}
m_resultDefinition->updateMinMaxValues();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSurfaceInView::isNativeSurfaceResultsActive() const
{
return m_resultDefinition->isChecked();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceResultDefinition* RimSurfaceInView::surfaceResultDefinition()
{
return m_resultDefinition();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::clearGeometry()
{
m_surfacePartMgr = nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivSurfacePartMgr* RimSurfaceInView::surfacePartMgr()
{
if ( m_surfacePartMgr.isNull() ) m_surfacePartMgr = new RivSurfacePartMgr( this );
return m_surfacePartMgr.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::loadDataAndUpdate()
{
if ( surface() )
{
surface()->loadDataIfRequired();
if ( surface()->surfaceData() && surface()->surfaceData()->propertyNames().empty() )
{
m_resultDefinition.uiCapability()->setUiTreeChildrenHidden( true );
m_resultDefinition->setCheckState( false );
}
else
{
m_resultDefinition.uiCapability()->setUiTreeChildrenHidden( false );
m_resultDefinition->setCheckState( true );
}
m_resultDefinition->updateMinMaxValues();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, bool isUsingOverrideViewer )
{
if ( m_resultDefinition->legendConfig() )
{
RimRegularLegendConfig* legendConfig = m_resultDefinition->legendConfig();
legendConfig->setTitle(
QString( "Surface : \n%1\n%2" ).arg( this->name() ).arg( m_resultDefinition->propertyName() ) );
if ( this->isActive() && m_resultDefinition->isChecked() && legendConfig->showLegend() )
{
nativeOrOverrideViewer->addColorLegendToBottomLeftCorner( legendConfig->titledOverlayFrame(),
isUsingOverrideViewer );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
this->updateUiIconFromToggleField();
bool scheduleRedraw = false;
if ( changedField == &m_isActive || changedField == &m_useSeparateDataSource || changedField == &m_separateDataSource )
{
scheduleRedraw = true;
}
else if ( changedField == &m_showInactiveCells )
{
clearGeometry();
scheduleRedraw = true;
}
if ( scheduleRedraw )
{
RimGridView* ownerView;
this->firstAncestorOrThisOfTypeAsserted( ownerView );
ownerView->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( &m_name );
uiOrdering.add( &m_showInactiveCells );
this->defineSeparateDataSourceUi( uiConfigName, uiOrdering );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIntersectionResultsDefinitionCollection* RimSurfaceInView::findSeparateResultsCollection()
{
RimGridView* view;
this->firstAncestorOrThisOfTypeAsserted( view );
return view->separateSurfaceResultsCollection();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimSurfaceInView::userDescriptionField()
{
return &m_name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInView::initAfterRead()
{
this->updateUiIconFromToggleField();
}

View File

@@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmChildField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmPtrField.h"
#include "cvfObject.h"
#include "RimIntersection.h"
class RimSurface;
class RimSurfaceResultDefinition;
class RivSurfacePartMgr;
class RivIntersectionHexGridInterface;
class RiuViewer;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RimSurfaceInView : public RimIntersection
{
CAF_PDM_HEADER_INIT;
public:
RimSurfaceInView();
~RimSurfaceInView() override;
QString name() const override;
RimSurface* surface() const;
void setSurface( RimSurface* surf );
bool isNativeSurfaceResultsActive() const;
RimSurfaceResultDefinition* surfaceResultDefinition();
void clearGeometry();
RivSurfacePartMgr* surfacePartMgr();
void loadDataAndUpdate();
void updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, bool isUsingOverrideViewer );
protected:
virtual void initAfterRead() override;
private:
virtual RimIntersectionResultsDefinitionCollection* findSeparateResultsCollection() override;
caf::PdmFieldHandle* userDescriptionField() override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
caf::PdmProxyValueField<QString> m_name;
caf::PdmPtrField<RimSurface*> m_surface;
caf::PdmChildField<RimSurfaceResultDefinition*> m_resultDefinition;
cvf::ref<RivSurfacePartMgr> m_surfacePartMgr;
};

View File

@@ -0,0 +1,485 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimSurfaceInViewCollection.h"
#include "RimGridView.h"
#include "RimIntersectionResultDefinition.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimSurface.h"
#include "RimSurfaceCollection.h"
#include "RimSurfaceInView.h"
#include "RimSurfaceResultDefinition.h"
#include "RivSurfacePartMgr.h"
#include "cvfModelBasicList.h"
CAF_PDM_SOURCE_INIT( RimSurfaceInViewCollection, "SurfaceInViewCollection" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceInViewCollection::RimSurfaceInViewCollection()
{
CAF_PDM_InitObject( "Surfaces", ":/ReservoirSurfaces16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_collectionName, "CollectionName", "Name", "", "", "" );
m_collectionName.registerGetMethod( this, &RimSurfaceInViewCollection::name );
m_collectionName.uiCapability()->setUiReadOnly( true );
m_collectionName.xmlCapability()->disableIO();
CAF_PDM_InitFieldNoDefault( &m_collectionsInView,
"SurfacesInViewFieldCollections",
"SurfacesInViewFieldCollections",
"",
"",
"" );
m_collectionsInView.uiCapability()->setUiTreeHidden( true );
CAF_PDM_InitFieldNoDefault( &m_surfacesInView, "SurfacesInViewField", "SurfacesInViewField", "", "", "" );
m_surfacesInView.uiCapability()->setUiTreeHidden( true );
CAF_PDM_InitFieldNoDefault( &m_surfaceCollection, "SurfaceCollectionRef", "SurfaceCollection", "", "", "" );
m_surfaceCollection.uiCapability()->setUiHidden( true );
nameField()->uiCapability()->setUiHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceInViewCollection::~RimSurfaceInViewCollection()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimSurfaceInViewCollection::userDescriptionField()
{
return &m_collectionName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSurfaceInViewCollection::name() const
{
if ( m_surfaceCollection ) return m_surfaceCollection->collectionName();
return "";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceCollection* RimSurfaceInViewCollection::surfaceCollection() const
{
return m_surfaceCollection;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::setSurfaceCollection( RimSurfaceCollection* surfcoll )
{
m_surfaceCollection = surfcoll;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::updateAllViewItems()
{
syncCollectionsWithView();
syncSurfacesWithView();
updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::syncCollectionsWithView()
{
// check that we have surface in view collections for all sub-collections
std::vector<RimSurfaceInViewCollection*> colls = m_collectionsInView.childObjects();
for ( auto surfcoll : colls )
{
if ( !surfcoll->surfaceCollection() )
{
m_collectionsInView.removeChildObject( surfcoll );
delete surfcoll;
}
}
// Create new collection entries and reorder
std::vector<RimSurfaceInViewCollection*> orderedColls;
if ( m_surfaceCollection )
{
// pick up the collections and the order from the surface collection
std::vector<RimSurfaceCollection*> surfcolls = m_surfaceCollection->subCollections();
for ( auto surfcoll : surfcolls )
{
// check if this is a collection we need to create
RimSurfaceInViewCollection* viewSurfColl = this->getCollectionInViewForCollection( surfcoll );
if ( viewSurfColl == nullptr )
{
RimSurfaceInViewCollection* newColl = new RimSurfaceInViewCollection();
newColl->setSurfaceCollection( surfcoll );
orderedColls.push_back( newColl );
}
else
{
orderedColls.push_back( viewSurfColl );
}
}
// make sure our view surfaces have the same order as the source surface collection
m_collectionsInView.clear();
for ( auto viewColl : orderedColls )
{
m_collectionsInView.push_back( viewColl );
viewColl->updateAllViewItems();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::syncSurfacesWithView()
{
// Delete surfaceInView without any real Surface connection
std::vector<RimSurfaceInView*> surfsInView = m_surfacesInView.childObjects();
for ( auto surf : surfsInView )
{
if ( !surf->surface() )
{
m_surfacesInView.removeChildObject( surf );
delete surf;
}
}
// Create new surfade entries and reorder
std::vector<RimSurfaceInView*> orderedSurfs;
if ( m_surfaceCollection )
{
// pick up the surfaces and the order from the surface collection
std::vector<RimSurface*> surfs = m_surfaceCollection->surfaces();
for ( auto surf : surfs )
{
// check if this is a surface we need to create
RimSurfaceInView* viewSurf = this->getSurfaceInViewForSurface( surf );
if ( viewSurf == nullptr )
{
RimSurfaceInView* newSurfInView = new RimSurfaceInView();
newSurfInView->setSurface( surf );
orderedSurfs.push_back( newSurfInView );
}
else
{
orderedSurfs.push_back( viewSurf );
}
}
// make sure our view surfaces have the same order as the source surface collection
m_surfacesInView.clear();
for ( auto viewSurf : orderedSurfs )
{
m_surfacesInView.push_back( viewSurf );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::updateFromSurfaceCollection()
{
updateAllViewItems();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::loadData()
{
for ( RimSurfaceInViewCollection* coll : m_collectionsInView )
{
coll->loadData();
}
for ( RimSurfaceInView* surf : m_surfacesInView )
{
if ( surf->isActive() )
{
surf->loadDataAndUpdate();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::clearGeometry()
{
for ( RimSurfaceInViewCollection* coll : m_collectionsInView )
{
coll->clearGeometry();
}
for ( RimSurfaceInView* surf : m_surfacesInView )
{
surf->clearGeometry();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::appendPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform )
{
if ( !isChecked() ) return;
for ( RimSurfaceInViewCollection* coll : m_collectionsInView )
{
if ( coll->isChecked() )
{
coll->appendPartsToModel( model, scaleTransform );
}
}
for ( RimSurfaceInView* surf : m_surfacesInView )
{
if ( surf->isActive() )
{
surf->surfacePartMgr()->appendIntersectionGeometryPartsToModel( model, scaleTransform );
}
}
model->updateBoundingBoxesRecursive();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
this->updateUiIconFromToggleField();
if ( changedField == &m_isChecked )
{
RimGridView* ownerView;
this->firstAncestorOrThisOfTypeAsserted( ownerView );
ownerView->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::initAfterRead()
{
this->updateUiIconFromToggleField();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceInView* RimSurfaceInViewCollection::getSurfaceInViewForSurface( const RimSurface* surf ) const
{
for ( auto surfInView : m_surfacesInView )
{
if ( surfInView->surface() == surf )
{
return surfInView;
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceInViewCollection*
RimSurfaceInViewCollection::getCollectionInViewForCollection( const RimSurfaceCollection* coll ) const
{
for ( auto collInView : m_collectionsInView )
{
if ( collInView->surfaceCollection() == coll )
{
return collInView;
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::updateCellResultColor( bool hasGeneralCellResult, size_t timeStepIndex )
{
if ( !this->isChecked() ) return;
for ( RimSurfaceInViewCollection* coll : m_collectionsInView )
{
if ( coll->isChecked() )
{
coll->updateCellResultColor( hasGeneralCellResult, timeStepIndex );
}
}
for ( RimSurfaceInView* surf : m_surfacesInView )
{
if ( surf->isActive() )
{
bool useNativeSurfaceColors = false;
if ( surf->isNativeSurfaceResultsActive() ) useNativeSurfaceColors = true;
if ( !useNativeSurfaceColors )
{
bool showResults = surf->activeSeparateResultDefinition()
? surf->activeSeparateResultDefinition()->hasResult()
: hasGeneralCellResult;
if ( showResults )
{
surf->surfacePartMgr()->updateCellResultColor( timeStepIndex );
}
else
{
useNativeSurfaceColors = true;
}
}
if ( useNativeSurfaceColors )
{
surf->surfacePartMgr()->updateNativeSurfaceColors();
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::applySingleColorEffect()
{
if ( !this->isChecked() ) return;
for ( RimSurfaceInViewCollection* coll : m_collectionsInView )
{
if ( coll->isChecked() )
{
coll->applySingleColorEffect();
}
}
for ( RimSurfaceInView* surf : m_surfacesInView )
{
if ( surf->isActive() )
{
surf->surfacePartMgr()->updateNativeSurfaceColors();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSurfaceInViewCollection::hasAnyActiveSeparateResults()
{
if ( !this->isChecked() ) return false;
for ( RimSurfaceInViewCollection* coll : m_collectionsInView )
{
if ( coll->isChecked() )
{
bool found = coll->hasAnyActiveSeparateResults();
if ( found ) return true;
}
}
for ( RimSurfaceInView* surf : m_surfacesInView )
{
if ( surf->isActive() && surf->activeSeparateResultDefinition() &&
surf->activeSeparateResultDefinition()->hasResult() )
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceInViewCollection::updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer,
bool isUsingOverrideViewer )
{
for ( RimSurfaceInViewCollection* coll : m_collectionsInView )
{
if ( coll->isChecked() )
coll->updateLegendRangesTextAndVisibility( nativeOrOverrideViewer, isUsingOverrideViewer );
}
for ( RimSurfaceInView* surf : m_surfacesInView )
{
surf->updateLegendRangesTextAndVisibility( nativeOrOverrideViewer, isUsingOverrideViewer );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimRegularLegendConfig*> RimSurfaceInViewCollection::legendConfigs()
{
std::vector<RimRegularLegendConfig*> configs;
for ( RimSurfaceInViewCollection* coll : m_collectionsInView )
{
if ( coll->isChecked() )
{
std::vector<RimRegularLegendConfig*> collconfigs = coll->legendConfigs();
configs.insert( configs.end(), collconfigs.begin(), collconfigs.end() );
}
}
for ( RimSurfaceInView* surf : m_surfacesInView )
{
if ( surf->isActive() && surf->surfaceResultDefinition() )
{
configs.push_back( surf->surfaceResultDefinition()->legendConfig() );
}
}
return configs;
}

View File

@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RimCheckableNamedObject.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmPtrField.h"
namespace cvf
{
class ModelBasicList;
class Transform;
class ScalarMapper;
} // namespace cvf
class RimSurfaceInView;
class RimSurface;
class RimSurfaceCollection;
class RimRegularLegendConfig;
class RiuViewer;
class RimSurfaceInViewCollection : public RimCheckableNamedObject
{
CAF_PDM_HEADER_INIT;
public:
RimSurfaceInViewCollection();
~RimSurfaceInViewCollection() override;
QString name() const override;
RimSurfaceCollection* surfaceCollection() const;
void setSurfaceCollection( RimSurfaceCollection* surfcoll );
void updateFromSurfaceCollection();
void loadData();
void clearGeometry();
void appendPartsToModel( cvf::ModelBasicList* surfaceVizModel, cvf::Transform* scaleTransform );
void updateCellResultColor( bool hasGeneralCellResult, size_t timeStepIndex );
void applySingleColorEffect();
bool hasAnyActiveSeparateResults();
void updateLegendRangesTextAndVisibility( RiuViewer* nativeOrOverrideViewer, bool isUsingOverrideViewer );
std::vector<RimRegularLegendConfig*> legendConfigs();
protected:
virtual void initAfterRead() override;
caf::PdmFieldHandle* userDescriptionField() override;
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
RimSurfaceInView* getSurfaceInViewForSurface( const RimSurface* surf ) const;
RimSurfaceInViewCollection* getCollectionInViewForCollection( const RimSurfaceCollection* coll ) const;
void updateAllViewItems();
void syncCollectionsWithView();
void syncSurfacesWithView();
caf::PdmProxyValueField<QString> m_collectionName;
caf::PdmChildArrayField<RimSurfaceInViewCollection*> m_collectionsInView;
caf::PdmChildArrayField<RimSurfaceInView*> m_surfacesInView;
caf::PdmPtrField<RimSurfaceCollection*> m_surfaceCollection;
};

View File

@@ -0,0 +1,206 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimSurfaceResultDefinition.h"
#include "RiaDefines.h"
#include "RigStatisticsMath.h"
#include "RigSurface.h"
#include "Rim3dView.h"
#include "RimRegularLegendConfig.h"
#include "RimSurface.h"
#include "RimSurfaceInView.h"
CAF_PDM_SOURCE_INIT( RimSurfaceResultDefinition, "SurfaceResultDefinition" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceResultDefinition::RimSurfaceResultDefinition()
{
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_propertyName, "PropertyName", "Property Name", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_legendConfig, "LegendConfig", "Legend", "", "", "" );
m_legendConfig.uiCapability()->setUiHidden( true );
m_legendConfig.uiCapability()->setUiTreeChildrenHidden( false );
m_legendConfig = new RimRegularLegendConfig;
setName( "Surface Result" );
CAF_PDM_InitFieldNoDefault( &m_surfaceInView, "SurfaceInView", "Surface In View", "", "", "" );
m_surfaceInView.uiCapability()->setUiHidden( true );
m_surfaceInView.uiCapability()->setUiTreeChildrenHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceResultDefinition::~RimSurfaceResultDefinition()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceResultDefinition::setSurfaceInView( RimSurfaceInView* surfaceInView )
{
m_surfaceInView = surfaceInView;
assignDefaultProperty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSurfaceResultDefinition::propertyName() const
{
return m_propertyName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimRegularLegendConfig* RimSurfaceResultDefinition::legendConfig()
{
return m_legendConfig();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceResultDefinition::updateMinMaxValues()
{
RigSurface* surfData = surfaceData();
if ( surfData )
{
double globalMin = 0.0;
double globalMax = 0.0;
double globalPosClosestToZero = 0.0;
double globalNegClosestToZero = 0.0;
{
MinMaxAccumulator minMaxAccumulator;
PosNegAccumulator posNegAccumulator;
auto values = surfData->propertyValues( m_propertyName );
minMaxAccumulator.addData( values );
posNegAccumulator.addData( values );
globalPosClosestToZero = posNegAccumulator.pos;
globalNegClosestToZero = posNegAccumulator.neg;
globalMin = minMaxAccumulator.min;
globalMax = minMaxAccumulator.max;
}
m_legendConfig->setClosestToZeroValues( globalPosClosestToZero,
globalNegClosestToZero,
globalPosClosestToZero,
globalNegClosestToZero );
m_legendConfig->setAutomaticRanges( globalMin, globalMax, globalMin, globalMax );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceResultDefinition::assignDefaultProperty()
{
if ( m_surfaceInView->surface() && m_surfaceInView->surface()->surfaceData() )
{
auto propNames = m_surfaceInView->surface()->surfaceData()->propertyNames();
if ( !propNames.empty() )
{
m_propertyName = m_surfaceInView->surface()->surfaceData()->propertyNames().front();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceResultDefinition::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
if ( changedField == &m_propertyName )
{
updateMinMaxValues();
}
Rim3dView* view = nullptr;
this->firstAncestorOrThisOfType( view );
if ( view )
{
view->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceResultDefinition::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( &m_propertyName );
uiOrdering.skipRemainingFields();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo>
RimSurfaceResultDefinition::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly )
{
QList<caf::PdmOptionItemInfo> options;
if ( fieldNeedingOptions == &m_propertyName )
{
options.push_back( caf::PdmOptionItemInfo( RiaDefines::undefinedResultName(), RiaDefines::undefinedResultName() ) );
RigSurface* surfData = surfaceData();
if ( surfData )
{
auto propertyNames = surfData->propertyNames();
for ( auto name : propertyNames )
{
options.push_back( caf::PdmOptionItemInfo( name, name ) );
}
}
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigSurface* RimSurfaceResultDefinition::surfaceData()
{
if ( m_surfaceInView && m_surfaceInView->surface() && m_surfaceInView->surface()->surfaceData() )
{
return m_surfaceInView->surface()->surfaceData();
}
return nullptr;
}

View File

@@ -0,0 +1,65 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RimCheckableNamedObject.h"
#include "cafPdmChildField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
#include "cvfObject.h"
class RimRegularLegendConfig;
class RimSurfaceInView;
class RigSurface;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RimSurfaceResultDefinition : public RimCheckableNamedObject
{
CAF_PDM_HEADER_INIT;
public:
RimSurfaceResultDefinition();
~RimSurfaceResultDefinition() override;
void setSurfaceInView( RimSurfaceInView* surfaceInView );
QString propertyName() const;
RimRegularLegendConfig* legendConfig();
void updateMinMaxValues();
void assignDefaultProperty();
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
bool* useOptionsOnly ) override;
RigSurface* surfaceData();
private:
caf::PdmField<QString> m_propertyName;
caf::PdmChildField<RimRegularLegendConfig*> m_legendConfig;
caf::PdmPtrField<RimSurfaceInView*> m_surfaceInView;
};