ResInsight/ApplicationCode/ProjectDataModel/Surfaces/RimFileSurface.cpp

193 lines
6.5 KiB
C++
Raw Normal View History

2020-05-03 04:29:33 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimFileSurface.h"
#include "RifSurfaceImporter.h"
#include "RigGocadData.h"
2020-05-03 04:29:33 -05:00
#include "RigSurface.h"
#include "RimSurfaceCollection.h"
#include <QFileInfo>
2020-04-30 13:20:46 -05:00
// 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" );
2020-05-03 04:29:33 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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() );
}
Surfaces: Improve UI and usability for surfaces (#6290) * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Fixes by clang-format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2020-08-11 04:34:34 -05:00
clearCachedNativeData();
2020-05-03 04:29:33 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimFileSurface::surfaceFilePath()
{
return m_surfaceDefinitionFilePath().path();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::onLoadData()
2020-05-03 04:29:33 -05:00
{
Surfaces: Improve UI and usability for surfaces (#6290) * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Fixes by clang-format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2020-08-11 04:34:34 -05:00
return updateSurfaceData();
2020-05-03 04:29:33 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface* RimFileSurface::createCopy()
{
RimFileSurface* newSurface = dynamic_cast<RimFileSurface*>(
xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
if ( !newSurface->onLoadData() )
{
delete newSurface;
return nullptr;
}
return newSurface;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2020-05-03 04:29:33 -05:00
void RimFileSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
RimSurface::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_surfaceDefinitionFilePath )
{
Surfaces: Improve UI and usability for surfaces (#6290) * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Fixes by clang-format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2020-08-11 04:34:34 -05:00
clearCachedNativeData();
updateSurfaceData();
2020-05-03 04:29:33 -05:00
RimSurfaceCollection* surfColl;
this->firstAncestorOrThisOfTypeAsserted( surfColl );
2020-06-04 02:27:20 -05:00
surfColl->updateViews( {this} );
2020-05-03 04:29:33 -05:00
}
}
//--------------------------------------------------------------------------------------------------
Surfaces: Improve UI and usability for surfaces (#6290) * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Fixes by clang-format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2020-08-11 04:34:34 -05:00
/// Regenerate the surface geometry, using the offset specified.
/// If the surface data hasn't been loaded from file yet, load it.
2020-05-03 04:29:33 -05:00
/// Returns false for fatal failure
//--------------------------------------------------------------------------------------------------
Surfaces: Improve UI and usability for surfaces (#6290) * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Fixes by clang-format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2020-08-11 04:34:34 -05:00
bool RimFileSurface::updateSurfaceData()
2020-05-03 04:29:33 -05:00
{
bool result = true;
if ( m_vertices.empty() )
{
result = loadDataFromFile();
}
2020-05-03 04:29:33 -05:00
2020-06-04 02:27:20 -05:00
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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Surfaces: Improve UI and usability for surfaces (#6290) * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Add reload command to surface context menus. Still missing the part that actually reloads the data. * Add additional check for null ptr to avoid crash * Surfaces: implements reload command in context menu to reload surface data from its source (i.e. a file). Rename function names to better show what they are actually doing Refactor a bit to give all RimSurface subclasses the same interface for reloading data. Also makes sure new RimGridCaseSurface instances are shown by default in the view(s) * Fixes by clang-format * Include offset and slice index in surface name shown in project explorer * Allow importing the same file multiple times * Disable lighting for surfaces, as it doesn't look good for now. Fixes #6084 * Surfaces: Remove depth offset setting from view. Add slider to depth offset edit for surface * Create new surfaces only on collection context menu * Make sure tree view icon is enabled/disabled when the check box is clicked * Fix depth offset for grid case surfaces, missing base function call. * Make public method .. public. * Fixes by clang-format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2020-08-11 04:34:34 -05:00
void RimFileSurface::clearCachedNativeData()
{
m_vertices.clear();
m_tringleIndices.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::loadDataFromFile()
{
std::pair<std::vector<cvf::Vec3d>, std::vector<unsigned>> surface;
2020-05-03 04:29:33 -05:00
QString filePath = this->surfaceFilePath();
2020-05-03 04:29:33 -05:00
if ( filePath.endsWith( "ptl", Qt::CaseInsensitive ) )
{
surface = RifSurfaceImporter::readPetrelFile( filePath );
2020-05-03 04:29:33 -05:00
}
else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) )
{
2020-06-04 02:27:20 -05:00
m_gocadData.reset( new RigGocadData );
RifSurfaceImporter::readGocadFile( filePath, m_gocadData.get() );
2020-05-03 04:29:33 -05:00
surface = m_gocadData->gocadGeometry();
2020-05-03 04:29:33 -05:00
}
m_vertices = surface.first;
m_tringleIndices = surface.second;
2020-05-03 04:29:33 -05:00
if ( m_vertices.empty() || m_tringleIndices.empty() ) return false;
2020-05-03 04:29:33 -05:00
return true;
2020-05-03 04:29:33 -05:00
}