Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,39 @@ std::vector<RimPolygonInView*> RimPolygonInViewCollection::allPolygonsInView() c
return polys;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPolygonInViewCollection::setPolygonVisible( RimPolygon* polygon, bool visible )
{
updateFromPolygonCollection();

auto* polygonInView = findPolygonInView( polygon );
if ( !polygonInView ) return false;

polygonInView->setCheckState( visible );
polygonInView->updateConnectedEditors();
return true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPolygonInView* RimPolygonInViewCollection::findPolygonInView( const RimPolygon* polygon ) const
{
for ( auto polygonInView : m_itemsInView )
{
if ( polygonInView && polygonInView->polygon() == polygon ) return polygonInView;
}

for ( auto collection : m_collectionsInView )
{
if ( auto* polygonInView = collection->findPolygonInView( polygon ) ) return polygonInView;
}

return nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ class RimPolygonInViewCollection : public RimNestedMirrorCollectionInView<RimPol
std::vector<RimPolygonInView*> visiblePolygonsInView() const;
std::vector<RimPolygonInView*> allPolygonsInView() const;

bool setPolygonVisible( RimPolygon* polygon, bool visible );

protected:
std::vector<RimPolygonContainer*> sourceSubCollections() const override;
std::vector<RimPolygon*> sourceItems() const override;
RimPolygonInView* createItemInView( RimPolygon* source ) override;

private:
RimPolygonInView* findPolygonInView( const RimPolygon* polygon ) const;

void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "RimSurfaceInViewCollection.h"

#include "Surface/RigSurface.h"

#include "Rim3dView.h"
#include "RimEnsembleSurface.h"
#include "RimGridView.h"
Expand All @@ -36,6 +38,8 @@

#include "cvfModelBasicList.h"

#include <algorithm>

CAF_PDM_SOURCE_INIT( RimSurfaceInViewCollection, "SurfaceInViewCollection" );

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -254,6 +258,71 @@ void RimSurfaceInViewCollection::updateFromSurfaceCollection()
updateAllViewItems();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSurfaceInViewCollection::setSurfaceVisible( RimSurface* surface, bool visible )
{
updateFromSurfaceCollection();

auto* surfaceInView = findSurfaceInView( surface );
if ( !surfaceInView ) return false;

surfaceInView->setActive( visible );
surfaceInView->updateConnectedEditors();
return true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<void, QString> RimSurfaceInViewCollection::setSurfaceProperty( RimSurface* surface, const QString& propertyName )
{
updateFromSurfaceCollection();

auto* surfaceInView = findSurfaceInView( surface );
if ( !surfaceInView )
{
return std::unexpected( QString( "Surface is not available in this view." ) );
}

surface->loadDataIfRequired();
auto* surfaceData = surface->surfaceData();
if ( !surfaceData )
{
return std::unexpected( QString( "Surface '%1' has no surface data." ).arg( surface->fullName() ) );
}

const auto propertyNames = surfaceData->propertyNames();
if ( std::find( propertyNames.begin(), propertyNames.end(), propertyName ) == propertyNames.end() )
{
return std::unexpected( QString( "Property '%1' is not available for surface '%2'." ).arg( propertyName, surface->fullName() ) );
}

surfaceInView->surfaceResultDefinition()->setPropertyName( propertyName );
return {};
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSurfaceInViewCollection::isSurfaceVisible( const RimSurface* surface ) const
{
auto* surfaceInView = findSurfaceInView( surface );
return surfaceInView && surfaceInView->isActive();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSurfaceInViewCollection::surfaceProperty( const RimSurface* surface ) const
{
auto* surfaceInView = findSurfaceInView( surface );
if ( !surfaceInView ) return {};

return surfaceInView->surfaceResultDefinition()->propertyName();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -360,6 +429,21 @@ RimSurfaceInView* RimSurfaceInViewCollection::getSurfaceInViewForSurface( const
return nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSurfaceInView* RimSurfaceInViewCollection::findSurfaceInView( const RimSurface* surface ) const
{
if ( auto* surfaceInView = getSurfaceInViewForSurface( surface ) ) return surfaceInView;

for ( auto collection : m_collectionsInView )
{
if ( auto* surfaceInView = collection->findSurfaceInView( surface ) ) return surfaceInView;
}

return nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "cafPdmProxyValueField.h"
#include "cafPdmPtrField.h"

#include <expected>

namespace cvf
{
class ModelBasicList;
Expand Down Expand Up @@ -58,6 +60,12 @@ class RimSurfaceInViewCollection : public RimCheckableNamedObject
void setSurfaceCollection( RimSurfaceCollection* surfcoll );

void updateFromSurfaceCollection();

bool setSurfaceVisible( RimSurface* surface, bool visible );
std::expected<void, QString> setSurfaceProperty( RimSurface* surface, const QString& propertyName );
bool isSurfaceVisible( const RimSurface* surface ) const;
QString surfaceProperty( const RimSurface* surface ) const;

void loadData( int timeStep );
void clearGeometry();

Expand All @@ -82,6 +90,7 @@ class RimSurfaceInViewCollection : public RimCheckableNamedObject
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;

RimSurfaceInView* getSurfaceInViewForSurface( const RimSurface* surf ) const;
RimSurfaceInView* findSurfaceInView( const RimSurface* surface ) const;
RimSurfaceInViewCollection* getCollectionInViewForCollection( const RimSurfaceCollection* coll ) const;

void updateAllViewItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ void RimSurfaceResultDefinition::setSurfaceInView( RimSurfaceInView* surfaceInVi
assignDefaultProperty();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSurfaceResultDefinition::setPropertyName( const QString& propertyName )
{
m_propertyName = propertyName;
setCheckState( true );
updateMinMaxValues( -1 );
updateConnectedEditors();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RimSurfaceResultDefinition : public RimCheckableNamedObject
~RimSurfaceResultDefinition() override;

void setSurfaceInView( RimSurfaceInView* surfaceInView );
void setPropertyName( const QString& propertyName );
QString propertyName() const;

RimRegularLegendConfig* legendConfig();
Expand Down
124 changes: 124 additions & 0 deletions ApplicationLibCode/ProjectDataModelCommands/RimcGridView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@
#include "RiaApplication.h"
#include "RiaKeyValueStoreUtil.h"

#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonInViewCollection.h"
#include "Rim3dView.h"
#include "RimEclipseView.h"
#include "RimGridView.h"
#include "Surfaces/RimSurface.h"
#include "Surfaces/RimSurfaceInViewCollection.h"

#include "cafPdmFieldScriptingCapability.h"

#include "cvfArray.h"

CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseView, RimcGridView_visibleCellsInternal, "visible_cells_internal" );
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, RimcGridView_setPolygonVisible, "set_polygon_visible" );
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, RimcGridView_setSurfaceVisible, "set_surface_visible" );
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, RimcGridView_setSurfaceProperty, "set_surface_property" );

//--------------------------------------------------------------------------------------------------
///
Expand Down Expand Up @@ -80,3 +88,119 @@ std::expected<caf::PdmObjectHandle*, QString> RimcGridView_visibleCellsInternal:

return nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcGridView_setPolygonVisible::RimcGridView_setPolygonVisible( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Set Polygon Visible", "", "", "Set polygon visibility in this view" );

CAF_PDM_InitScriptableFieldNoDefault( &m_polygon, "Polygon", "Polygon" );
CAF_PDM_InitScriptableField( &m_visible, "Visible", true, "Visible" );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<caf::PdmObjectHandle*, QString> RimcGridView_setPolygonVisible::execute()
{
auto* gridView = self<RimGridView>();
if ( !gridView )
{
return std::unexpected( QString( "Polygon visibility is only supported for grid views." ) );
}

if ( !m_polygon() )
{
return std::unexpected( QString( "Polygon is null." ) );
}

if ( !gridView->polygonInViewCollection()->setPolygonVisible( m_polygon(), m_visible() ) )
{
return std::unexpected( QString( "Polygon '%1' is not available in this view." ).arg( m_polygon()->name() ) );
}

gridView->scheduleCreateDisplayModelAndRedraw();
return nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcGridView_setSurfaceVisible::RimcGridView_setSurfaceVisible( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Set Surface Visible", "", "", "Set surface visibility in this view" );

CAF_PDM_InitScriptableFieldNoDefault( &m_surface, "Surface", "Surface" );
CAF_PDM_InitScriptableField( &m_visible, "Visible", true, "Visible" );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<caf::PdmObjectHandle*, QString> RimcGridView_setSurfaceVisible::execute()
{
auto* gridView = self<RimGridView>();
if ( !gridView )
{
return std::unexpected( QString( "Surface visibility is only supported for grid views." ) );
}

if ( !m_surface() )
{
return std::unexpected( QString( "Surface is null." ) );
}

auto* collection = gridView->surfaceInViewCollection();
if ( !collection || !collection->setSurfaceVisible( m_surface(), m_visible() ) )
{
return std::unexpected( QString( "Surface '%1' is not available in this view." ).arg( m_surface()->fullName() ) );
}

gridView->scheduleCreateDisplayModelAndRedraw();
return nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcGridView_setSurfaceProperty::RimcGridView_setSurfaceProperty( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Set Surface Property", "", "", "Set the surface property shown in this view" );

CAF_PDM_InitScriptableFieldNoDefault( &m_surface, "Surface", "Surface" );
CAF_PDM_InitScriptableFieldNoDefault( &m_propertyName, "PropertyName", "Property Name" );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<caf::PdmObjectHandle*, QString> RimcGridView_setSurfaceProperty::execute()
{
auto* gridView = self<RimGridView>();
if ( !gridView )
{
return std::unexpected( QString( "Surface properties are only supported for grid views." ) );
}

if ( !m_surface() )
{
return std::unexpected( QString( "Surface is null." ) );
}

auto* collection = gridView->surfaceInViewCollection();
if ( !collection )
{
return std::unexpected( QString( "Surface '%1' is not available in this view." ).arg( m_surface()->fullName() ) );
}

auto result = collection->setSurfaceProperty( m_surface(), m_propertyName() );
if ( !result ) return std::unexpected( result.error() );

gridView->scheduleCreateDisplayModelAndRedraw();
return nullptr;
}
Loading