ResInsight/ApplicationCode/ProjectDataModel/Surfaces/RimSurface.cpp
jonjenssen bbc659799e
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 11:34:34 +02:00

239 lines
8.3 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimSurfaceCollection.h"
#include "RigSurface.h"
#include "RifSurfaceReader.h"
#include "cafPdmUiDoubleSliderEditor.h"
#include <cmath>
CAF_PDM_ABSTRACT_SOURCE_INIT( RimSurface, "SurfaceInterface" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurface::RimSurface()
{
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_userDescription, "SurfaceUserDecription", "Name", "", "", "" );
CAF_PDM_InitField( &m_color, "SurfaceColor", cvf::Color3f( 0.5f, 0.3f, 0.2f ), "Color", "", "", "" );
// CAF_PDM_InitField( &m_depthOffset, "DepthOffset", 0.0, "Depth Offset", "", "", "" );
CAF_PDM_InitField( &m_depthOffset, "DepthOffset", 0.0, "Depth Offset", "", "", "" );
m_depthOffset.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() );
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::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 )
{
doubleSliderAttrib->m_minimum = -2000;
doubleSliderAttrib->m_maximum = 2000;
}
}
}