#5379 Surface : Add grid case surface

This commit is contained in:
Magne Sjaastad
2020-05-03 11:29:33 +02:00
parent 4d114e36f8
commit 77734b8b57
15 changed files with 641 additions and 85 deletions

View File

@@ -1,10 +1,12 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicImportSurfacesFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewGridCaseSurfaceFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicImportSurfacesFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewGridCaseSurfaceFeature.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,76 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicNewGridCaseSurfaceFeature.h"
#include "RiaApplication.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimSurface.h"
#include "RimSurfaceCollection.h"
#include "Riu3DMainWindowTools.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicNewGridSurfaceFeature, "RicNewGridSurfaceFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewGridSurfaceFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewGridSurfaceFeature::onActionTriggered( bool isChecked )
{
RiaApplication* app = RiaApplication::instance();
// Find or create the SurfaceCollection
RimProject* proj = RiaApplication::instance()->project();
RimSurfaceCollection* surfColl = proj->activeOilField()->surfaceCollection();
if ( !surfColl )
{
surfColl = new RimSurfaceCollection();
proj->activeOilField()->surfaceCollection = surfColl;
proj->updateConnectedEditors();
}
RimSurface* lastCreatedOrUpdated = surfColl->addGridCaseSurface( nullptr );
if ( lastCreatedOrUpdated )
{
Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewGridSurfaceFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/ReservoirSurfaces16x16.png" ) );
actionToSetup->setText( "Create Grid Case Surfaces" );
}

View File

@@ -0,0 +1,35 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicNewGridSurfaceFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -141,6 +141,7 @@ void RivSurfaceIntersectionGeometryGenerator::calculateArrays()
{
if ( m_triangleVxes->size() ) return;
if ( m_hexGrid.isNull() ) return;
if ( !m_surfaceInView->surface()->surfaceData() ) return;
std::vector<cvf::Vec3f> outputTriangleVertices;
@@ -323,8 +324,6 @@ cvf::ref<cvf::DrawableGeo> RivSurfaceIntersectionGeometryGenerator::generateSurf
{
calculateArrays();
CVF_ASSERT( m_triangleVxes.notNull() );
if ( m_triangleVxes->size() == 0 ) return nullptr;
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;

View File

@@ -377,7 +377,9 @@ void RivSurfacePartMgr::generateNativePartGeometry()
m_surfaceInView->firstAncestorOrThisOfTypeAsserted( ownerCase );
cvf::Vec3d displayModOffsett = ownerCase->displayModelOffset();
m_usedSurfaceData = m_surfaceInView->surface()->surfaceData();
m_usedSurfaceData = m_surfaceInView->surface()->surfaceData();
if ( m_usedSurfaceData.isNull() ) return;
double depthOffset = m_surfaceInView->depthOffset();
displayModOffsett.z() = displayModOffsett.z() + depthOffset;
@@ -413,6 +415,8 @@ void RivSurfacePartMgr::generateNativePartGeometry()
//--------------------------------------------------------------------------------------------------
void RivSurfacePartMgr::generateNativeVertexToCellIndexMap()
{
if ( m_usedSurfaceData.isNull() ) return;
cvf::ref<RivIntersectionHexGridInterface> hexGrid = m_surfaceInView->createHexGridInterface();
const std::vector<cvf::Vec3d>& vertices = m_usedSurfaceData->vertices();

View File

@@ -863,6 +863,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
else if ( dynamic_cast<RimSurfaceCollection*>( firstUiItem ) || dynamic_cast<RimSurface*>( firstUiItem ) )
{
menuBuilder << "RicImportSurfacesFeature";
menuBuilder << "RicNewGridSurfaceFeature";
}
else if ( dynamic_cast<RimAnnotationCollection*>( firstUiItem ) ||
dynamic_cast<RimAnnotationGroupCollection*>( firstUiItem ) )

View File

@@ -1,6 +1,8 @@
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
@@ -8,6 +10,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RimSurfaceInViewCollection.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

View File

@@ -0,0 +1,129 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RifSurfaceReader.h"
#include "RigSurface.h"
#include "RimSurfaceCollection.h"
#include <QFileInfo>
CAF_PDM_SOURCE_INIT( RimFileSurface, "FileSurface" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFileSurface::RimFileSurface()
{
CAF_PDM_InitObject( "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() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimFileSurface::surfaceFilePath()
{
return m_surfaceDefinitionFilePath().path();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::loadData()
{
return updateSurfaceDataFromFile();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFileSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
RimSurface::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_surfaceDefinitionFilePath )
{
updateSurfaceDataFromFile();
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( {this} );
}
}
//--------------------------------------------------------------------------------------------------
/// Returns false for fatal failure
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::updateSurfaceDataFromFile()
{
QString filePath = this->surfaceFilePath();
std::vector<unsigned> tringleIndices;
std::vector<cvf::Vec3d> vertices;
if ( filePath.endsWith( "ptl", Qt::CaseInsensitive ) )
{
auto surface = RifSurfaceReader::readPetrelFile( filePath );
vertices = surface.first;
tringleIndices = surface.second;
}
else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) )
{
auto surface = RifSurfaceReader::readGocadFile( filePath );
vertices = surface.first;
tringleIndices = surface.second;
}
if ( !vertices.empty() && !tringleIndices.empty() )
{
auto surface = new RigSurface();
surface->setTriangleData( tringleIndices, vertices );
setSurfaceData( surface );
return true;
}
return false;
}

View File

@@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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"
class RimFileSurface : public RimSurface
{
CAF_PDM_HEADER_INIT;
public:
RimFileSurface();
~RimFileSurface() override;
void setSurfaceFilePath( const QString& filePath );
QString surfaceFilePath();
bool loadData() override;
private:
bool updateSurfaceDataFromFile();
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
caf::PdmField<caf::FilePath> m_surfaceDefinitionFilePath;
};

View File

@@ -0,0 +1,221 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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_sliceDirection,
"SnapShotDirection",
caf::AppEnum<RiaDefines::GridCaseAxis>( RiaDefines::GridCaseAxis::UNDEFINED_AXIS ),
"Range Filter Slice",
"",
"",
"" );
CAF_PDM_InitField( &m_sliceIndex, "SliceIndex", 0, "Slice Index", "", "", "" );
m_sliceIndex.uiCapability()->setUiEditorTypeName( caf::PdmUiSliderEditor::uiEditorTypeName() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridCaseSurface::~RimGridCaseSurface()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCaseSurface::setCase( RimCase* sourceCase )
{
m_case = sourceCase;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimGridCaseSurface::loadData()
{
return updateSurfaceDataFromGridCase();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 )
{
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;
if ( m_sliceDirection() == RiaDefines::GridCaseAxis::AXIS_I )
{
myAttr->m_maximum = static_cast<int>( grid->cellCountI() );
}
else if ( m_sliceDirection() == RiaDefines::GridCaseAxis::AXIS_J )
{
myAttr->m_maximum = static_cast<int>( grid->cellCountJ() );
}
else if ( m_sliceDirection() == RiaDefines::GridCaseAxis::AXIS_K )
{
myAttr->m_maximum = static_cast<int>( grid->cellCountK() );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCaseSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
if ( changedField == &m_case || changedField == &m_sliceDirection || changedField == &m_sliceIndex )
{
updateSurfaceDataFromGridCase();
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( {this} );
}
}
//--------------------------------------------------------------------------------------------------
/// Returns false for fatal failure
//--------------------------------------------------------------------------------------------------
bool RimGridCaseSurface::updateSurfaceDataFromGridCase()
{
RigSurface* surfaceData = nullptr;
std::vector<unsigned> tringleIndices;
std::vector<cvf::Vec3d> vertices;
cvf::StructGridInterface::FaceType faceType = cvf::StructGridInterface::NO_FACE;
{
if ( m_sliceDirection() == RiaDefines::GridCaseAxis::AXIS_K )
{
faceType = cvf::StructGridInterface::NEG_K;
}
else if ( m_sliceDirection() == RiaDefines::GridCaseAxis::AXIS_J )
{
faceType = cvf::StructGridInterface::NEG_J;
}
else if ( m_sliceDirection() == RiaDefines::GridCaseAxis::AXIS_I )
{
faceType = cvf::StructGridInterface::NEG_I;
}
}
if ( m_case && faceType != cvf::StructGridInterface::NO_FACE )
{
RimEclipseCase* eclCase = dynamic_cast<RimEclipseCase*>( m_case() );
if ( eclCase && eclCase->mainGrid() )
{
{
const RigMainGrid* grid = eclCase->mainGrid();
size_t k = m_sliceIndex;
for ( size_t i = 0; i < grid->cellCountI(); i++ )
{
for ( size_t j = 0; j < grid->cellCountJ(); j++ )
{
size_t cellIndex = grid->cellIndexFromIJK( i, j, k );
if ( grid->cell( cellIndex ).isInvalid() ) continue;
cvf::Vec3d cornerVerts[8];
grid->cellCornerVertices( cellIndex, cornerVerts );
cvf::ubyte faceConn[4];
grid->cellFaceVertexIndices( faceType, faceConn );
cvf::uint triangleIndex = static_cast<cvf::uint>( vertices.size() );
for ( int n = 0; n < 4; n++ )
{
vertices.push_back( cornerVerts[faceConn[n]] );
}
tringleIndices.push_back( triangleIndex + 0 );
tringleIndices.push_back( triangleIndex + 1 );
tringleIndices.push_back( triangleIndex + 2 );
tringleIndices.push_back( triangleIndex + 0 );
tringleIndices.push_back( triangleIndex + 2 );
tringleIndices.push_back( triangleIndex + 3 );
}
}
}
}
}
if ( !tringleIndices.empty() )
{
surfaceData = new RigSurface;
surfaceData->setTriangleData( tringleIndices, vertices );
}
setSurfaceData( surfaceData );
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 "RiaDefines.h"
#include "cafPdmPtrField.h"
class RimCase;
class RimGridCaseSurface : public RimSurface
{
CAF_PDM_HEADER_INIT;
public:
RimGridCaseSurface();
~RimGridCaseSurface() override;
void setCase( RimCase* sourceCase );
bool loadData() override;
protected:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
bool* useOptionsOnly ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute ) override;
private:
bool updateSurfaceDataFromGridCase();
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
private:
caf::PdmPtrField<RimCase*> m_case;
caf::PdmField<caf::AppEnum<RiaDefines::GridCaseAxis>> m_sliceDirection;
caf::PdmField<int> m_sliceIndex;
};

View File

@@ -36,7 +36,6 @@ RimSurface::RimSurface()
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_userDescription, "SurfaceUserDecription", "Name", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_surfaceDefinitionFilePath, "SurfaceFilePath", "File", "", "", "" );
CAF_PDM_InitField( &m_color, "SurfaceColor", cvf::Color3f( 0.5f, 0.3f, 0.2f ), "Color", "", "", "" );
}
@@ -47,26 +46,6 @@ RimSurface::~RimSurface()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::setSurfaceFilePath( const QString& filePath )
{
m_surfaceDefinitionFilePath = filePath;
if ( m_userDescription().isEmpty() )
{
m_userDescription = QFileInfo( filePath ).fileName();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSurface::surfaceFilePath()
{
return m_surfaceDefinitionFilePath().path();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -91,6 +70,30 @@ QString RimSurface::userDescription()
return m_userDescription();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSurface::loadData()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::setUserDescription( const QString& description )
{
m_userDescription = description;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurface::setSurfaceData( RigSurface* surface )
{
m_surfaceData = surface;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -112,54 +115,10 @@ caf::PdmFieldHandle* RimSurface::userDescriptionField()
//--------------------------------------------------------------------------------------------------
void RimSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
if ( changedField == &m_surfaceDefinitionFilePath )
{
updateSurfaceDataFromFile();
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( {this} );
}
else if ( changedField == &m_color )
if ( changedField == &m_color )
{
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
surfColl->updateViews( {this} );
}
}
//--------------------------------------------------------------------------------------------------
/// Returns false for fatal failure
//--------------------------------------------------------------------------------------------------
bool RimSurface::updateSurfaceDataFromFile()
{
QString filePath = this->surfaceFilePath();
std::vector<unsigned> tringleIndices;
std::vector<cvf::Vec3d> vertices;
if ( filePath.endsWith( "ptl", Qt::CaseInsensitive ) )
{
auto surface = RifSurfaceReader::readPetrelFile( filePath );
vertices = surface.first;
tringleIndices = surface.second;
}
else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) )
{
auto surface = RifSurfaceReader::readGocadFile( filePath );
vertices = surface.first;
tringleIndices = surface.second;
}
if ( !vertices.empty() && !tringleIndices.empty() )
{
m_surfaceData = new RigSurface();
m_surfaceData->setTriangleData( tringleIndices, vertices );
return true;
}
return false;
}

View File

@@ -34,24 +34,26 @@ public:
RimSurface();
~RimSurface() override;
void setSurfaceFilePath( const QString& filePath );
QString surfaceFilePath();
void setColor( const cvf::Color3f& color );
cvf::Color3f color() const;
bool updateSurfaceDataFromFile();
RigSurface* surfaceData();
QString userDescription();
virtual bool loadData();
protected:
void setUserDescription( const QString& description );
void setSurfaceData( RigSurface* surface );
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
private:
caf::PdmFieldHandle* userDescriptionField() override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
caf::PdmField<caf::FilePath> m_surfaceDefinitionFilePath;
caf::PdmField<QString> m_userDescription;
caf::PdmField<cvf::Color3f> m_color;
caf::PdmField<QString> m_userDescription;
caf::PdmField<cvf::Color3f> m_color;
cvf::ref<RigSurface> m_surfaceData;
};

View File

@@ -17,9 +17,13 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RimSurfaceCollection.h"
#include "QMessageBox"
#include "RiaApplication.h"
#include "RiaColorTables.h"
#include "RiaLogging.h"
#include "RimFileSurface.h"
#include "RimGridCaseSurface.h"
#include "RimGridView.h"
#include "RimProject.h"
#include "RimSurface.h"
@@ -66,7 +70,8 @@ RimSurface* RimSurfaceCollection::importSurfacesFromFiles( const QStringList& fi
bool isFound = false;
for ( RimSurface* surface : m_surfaces() )
{
if ( surface->surfaceFilePath() == newFileName )
RimFileSurface* fileSurface = dynamic_cast<RimFileSurface*>( surface );
if ( fileSurface && fileSurface->surfaceFilePath() == newFileName )
{
surfacesToReload.push_back( surface );
isFound = true;
@@ -86,14 +91,14 @@ RimSurface* RimSurfaceCollection::importSurfacesFromFiles( const QStringList& fi
for ( const QString& newFileName : newFileNames )
{
RimSurface* newSurface = new RimSurface;
RimFileSurface* newSurface = new RimFileSurface;
auto newColor = RiaColorTables::categoryPaletteColors().cycledColor3f( existingSurfCount + newSurfCount );
newSurface->setSurfaceFilePath( newFileName );
newSurface->setColor( newColor );
if ( !newSurface->updateSurfaceDataFromFile() )
if ( !newSurface->loadData() )
{
delete newSurface;
errorMessages += newFileName + "\n";
@@ -109,7 +114,7 @@ RimSurface* RimSurfaceCollection::importSurfacesFromFiles( const QStringList& fi
if ( !errorMessages.isEmpty() )
{
QMessageBox::warning( nullptr, "Import Surfaces:", "Could not import the following files:\n" + errorMessages );
RiaLogging::warning( "Import Surfaces : Could not import the following files:\n" + errorMessages );
}
this->updateConnectedEditors();
@@ -126,6 +131,21 @@ RimSurface* RimSurfaceCollection::importSurfacesFromFiles( const QStringList& fi
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimSurfaceCollection::addGridCaseSurface( RimCase* sourceCase )
{
auto s = new RimGridCaseSurface;
s->setCase( sourceCase );
m_surfaces.push_back( s );
this->updateConnectedEditors();
return s;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -141,7 +161,7 @@ void RimSurfaceCollection::loadData()
{
for ( auto surf : m_surfaces )
{
if ( !surf->updateSurfaceDataFromFile() )
if ( !surf->loadData() )
{
// Error: could not open the surface file surf->surfaceFilePath();
}
@@ -158,7 +178,7 @@ void RimSurfaceCollection::updateViews( const std::vector<RimSurface*>& surfsToR
std::vector<Rim3dView*> views;
proj->allViews( views );
// Make sure the tree items are syncronized
// Make sure the tree items are synchronized
for ( auto view : views )
{
@@ -174,6 +194,8 @@ void RimSurfaceCollection::updateViews( const std::vector<RimSurface*>& surfsToR
surf->objectsWithReferringPtrFieldsOfType( surfsInView );
for ( auto surfInView : surfsInView )
{
surfInView->clearGeometry();
RimGridView* gridView;
surfInView->firstAncestorOrThisOfType( gridView );
@@ -197,7 +219,7 @@ void RimSurfaceCollection::updateViews()
std::vector<RimGridView*> views;
proj->allVisibleGridViews( views );
// Make sure the tree items are syncronized
// Make sure the tree items are synchronized
for ( auto view : views )
{

View File

@@ -21,6 +21,7 @@
#include "cafPdmObject.h"
class RimSurface;
class RimCase;
class RimSurfaceCollection : public caf::PdmObject
{
@@ -33,6 +34,7 @@ public:
void addSurface( RimSurface* surface );
RimSurface* importSurfacesFromFiles( const QStringList& fileNames );
RimSurface* addGridCaseSurface( RimCase* sourceCase );
std::vector<RimSurface*> surfaces() const;