mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Surface python interface (#6370)
* Add python interface for importing surfaces with example.
This commit is contained in:
parent
6f7534b2a9
commit
cfe64f5706
@ -0,0 +1,40 @@
|
||||
# Load ResInsight Processing Server Client Library
|
||||
import rips
|
||||
# Connect to ResInsight instance
|
||||
resinsight = rips.Instance.find()
|
||||
print("ResInsight version: " + resinsight.version_string())
|
||||
|
||||
# Example code
|
||||
|
||||
# get the project
|
||||
project = resinsight.project
|
||||
|
||||
# get the topmost surface folder from the project
|
||||
surfacefolder = project.surface_folder()
|
||||
|
||||
# list of surface files to load
|
||||
filenames = ["surface1.ts", "surface2.ts", "surface3.ts"]
|
||||
|
||||
# Load the files into the top level
|
||||
for surffile in filenames:
|
||||
surface = surfacefolder.import_surface(surffile)
|
||||
if surface is None:
|
||||
print("Could not import the surface " + surffile)
|
||||
|
||||
# add a subfolder
|
||||
subfolder = surfacefolder.add_folder("ExampleFolder")
|
||||
|
||||
# load the same surface multiple times using increasing depth offsets
|
||||
# store them in the new subfolder we just created
|
||||
for offset in range(0, 200, 20):
|
||||
surface = subfolder.import_surface("mysurface.ts")
|
||||
if surface:
|
||||
surface.depth_offset = offset
|
||||
surface.update()
|
||||
else:
|
||||
print("Could not import surface.")
|
||||
|
||||
# get an existing subfolder
|
||||
existingfolder = project.surface_folder("ExistingFolder")
|
||||
if existingfolder is None:
|
||||
print("Could not find the specified folder.")
|
@ -23,6 +23,9 @@
|
||||
#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
|
||||
@ -35,7 +38,7 @@ CAF_PDM_SOURCE_INIT( RimFileSurface, "Surface" );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimFileSurface::RimFileSurface()
|
||||
{
|
||||
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
|
||||
CAF_PDM_InitScriptableObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_surfaceDefinitionFilePath, "SurfaceFilePath", "File", "", "", "" );
|
||||
}
|
||||
|
@ -24,6 +24,9 @@
|
||||
|
||||
#include "RifSurfaceImporter.h"
|
||||
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
#include "cafPdmObjectScriptingCapability.h"
|
||||
|
||||
#include "cafPdmUiDoubleSliderEditor.h"
|
||||
|
||||
#include <cmath>
|
||||
@ -35,13 +38,14 @@ CAF_PDM_ABSTRACT_SOURCE_INIT( RimSurface, "SurfaceInterface" );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSurface::RimSurface()
|
||||
{
|
||||
CAF_PDM_InitObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
|
||||
CAF_PDM_InitScriptableObject( "Surface", ":/ReservoirSurface16x16.png", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_userDescription, "SurfaceUserDecription", "Name", "", "", "" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &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_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 );
|
||||
|
@ -30,6 +30,9 @@
|
||||
|
||||
#include "cafPdmFieldReorderCapability.h"
|
||||
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
#include "cafPdmObjectScriptingCapability.h"
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimSurfaceCollection, "SurfaceCollection" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -37,17 +40,17 @@ CAF_PDM_SOURCE_INIT( RimSurfaceCollection, "SurfaceCollection" );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSurfaceCollection::RimSurfaceCollection()
|
||||
{
|
||||
CAF_PDM_InitObject( "Surfaces", ":/ReservoirSurfaces16x16.png", "", "" );
|
||||
CAF_PDM_InitScriptableObject( "Surfaces", ":/ReservoirSurfaces16x16.png", "", "" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_collectionname, "SurfaceUserDecription", "Name", "", "", "" );
|
||||
m_collectionname = "Surfaces";
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_collectionName, "SurfaceUserDecription", "Name", "", "", "" );
|
||||
m_collectionName = "Surfaces";
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_subcollections, "SubCollections", "Surfaces", "", "", "" );
|
||||
m_subcollections.uiCapability()->setUiTreeHidden( true );
|
||||
auto reorderability = caf::PdmFieldReorderCapability::addToField( &m_subcollections );
|
||||
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_InitFieldNoDefault( &m_surfaces, "SurfacesField", "Surfaces", "", "", "" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_surfaces, "SurfacesField", "Surfaces", "", "", "" );
|
||||
m_surfaces.uiCapability()->setUiTreeHidden( true );
|
||||
|
||||
setDeletable( true );
|
||||
@ -65,16 +68,24 @@ RimSurfaceCollection::~RimSurfaceCollection()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSurfaceCollection::setAsTopmostFolder()
|
||||
{
|
||||
m_collectionname.uiCapability()->setUiHidden( true );
|
||||
m_collectionName.uiCapability()->setUiHidden( true );
|
||||
setDeletable( false );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimSurfaceCollection::collectionname() const
|
||||
QString RimSurfaceCollection::collectionName() const
|
||||
{
|
||||
return m_collectionname.value();
|
||||
return m_collectionName.value();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSurfaceCollection::setCollectionName( const QString name )
|
||||
{
|
||||
return m_collectionName.setValue( name );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -82,7 +93,7 @@ QString RimSurfaceCollection::collectionname() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* RimSurfaceCollection::userDescriptionField()
|
||||
{
|
||||
return &m_collectionname;
|
||||
return &m_collectionName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -235,9 +246,9 @@ std::vector<RimSurface*> RimSurfaceCollection::surfaces() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimSurfaceCollection*> RimSurfaceCollection::subcollections() const
|
||||
std::vector<RimSurfaceCollection*> RimSurfaceCollection::subCollections() const
|
||||
{
|
||||
return m_subcollections.childObjects();
|
||||
return m_subCollections.childObjects();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -346,7 +357,7 @@ void RimSurfaceCollection::removeSurface( RimSurface* 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() );
|
||||
position = position - static_cast<int>( m_subCollections.size() );
|
||||
|
||||
RimSurface* returnSurface = nullptr;
|
||||
if ( !surfaces.empty() ) returnSurface = surfaces[0];
|
||||
@ -401,10 +412,23 @@ RimSurface* RimSurfaceCollection::addSurfacesAtIndex( int position, std::vector<
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSurfaceCollection::addSubCollection( RimSurfaceCollection* subcoll )
|
||||
{
|
||||
m_subcollections.push_back( 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;
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ public:
|
||||
RimSurface* copySurfaces( std::vector<RimSurface*> surfaces );
|
||||
RimSurface* addSurfacesAtIndex( int index, std::vector<RimSurface*> surfaces );
|
||||
|
||||
void addSubCollection( RimSurfaceCollection* collection );
|
||||
void addSubCollection( RimSurfaceCollection* collection );
|
||||
RimSurfaceCollection* getSubCollection( const QString name );
|
||||
|
||||
void reloadSurfaces( std::vector<RimSurface*> surfaces );
|
||||
void removeSurface( RimSurface* surface );
|
||||
@ -54,10 +55,11 @@ public:
|
||||
void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
|
||||
std::vector<caf::PdmObjectHandle*>& referringObjects ) override;
|
||||
|
||||
QString collectionname() const;
|
||||
QString collectionName() const;
|
||||
void setCollectionName( const QString name );
|
||||
|
||||
std::vector<RimSurface*> surfaces() const;
|
||||
std::vector<RimSurfaceCollection*> subcollections() const;
|
||||
std::vector<RimSurfaceCollection*> subCollections() const;
|
||||
|
||||
protected:
|
||||
caf::PdmFieldHandle* userDescriptionField() override;
|
||||
@ -65,7 +67,7 @@ protected:
|
||||
private:
|
||||
void orderChanged( const caf::SignalEmitter* emitter );
|
||||
|
||||
caf::PdmField<QString> m_collectionname;
|
||||
caf::PdmField<QString> m_collectionName;
|
||||
caf::PdmChildArrayField<RimSurface*> m_surfaces;
|
||||
caf::PdmChildArrayField<RimSurfaceCollection*> m_subcollections;
|
||||
caf::PdmChildArrayField<RimSurfaceCollection*> m_subCollections;
|
||||
};
|
||||
|
@ -40,10 +40,10 @@ 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_collectionName, "CollectionName", "Name", "", "", "" );
|
||||
m_collectionName.registerGetMethod( this, &RimSurfaceInViewCollection::name );
|
||||
m_collectionName.uiCapability()->setUiReadOnly( true );
|
||||
m_collectionName.xmlCapability()->disableIO();
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_collectionsInView,
|
||||
"SurfacesInViewFieldCollections",
|
||||
@ -56,8 +56,8 @@ RimSurfaceInViewCollection::RimSurfaceInViewCollection()
|
||||
CAF_PDM_InitFieldNoDefault( &m_surfacesInView, "SurfacesInViewField", "SurfacesInViewField", "", "", "" );
|
||||
m_surfacesInView.uiCapability()->setUiTreeHidden( true );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_surfacecollection, "SurfaceCollectionRef", "SurfaceCollection", "", "", "" );
|
||||
m_surfacecollection.uiCapability()->setUiHidden( true );
|
||||
CAF_PDM_InitFieldNoDefault( &m_surfaceCollection, "SurfaceCollectionRef", "SurfaceCollection", "", "", "" );
|
||||
m_surfaceCollection.uiCapability()->setUiHidden( true );
|
||||
|
||||
nameField()->uiCapability()->setUiHidden( true );
|
||||
}
|
||||
@ -74,7 +74,7 @@ RimSurfaceInViewCollection::~RimSurfaceInViewCollection()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* RimSurfaceInViewCollection::userDescriptionField()
|
||||
{
|
||||
return &m_collectionname;
|
||||
return &m_collectionName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -82,7 +82,7 @@ caf::PdmFieldHandle* RimSurfaceInViewCollection::userDescriptionField()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimSurfaceInViewCollection::name() const
|
||||
{
|
||||
if ( m_surfacecollection ) return m_surfacecollection->collectionname();
|
||||
if ( m_surfaceCollection ) return m_surfaceCollection->collectionName();
|
||||
|
||||
return "";
|
||||
}
|
||||
@ -92,7 +92,7 @@ QString RimSurfaceInViewCollection::name() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSurfaceCollection* RimSurfaceInViewCollection::surfaceCollection() const
|
||||
{
|
||||
return m_surfacecollection;
|
||||
return m_surfaceCollection;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -100,7 +100,7 @@ RimSurfaceCollection* RimSurfaceInViewCollection::surfaceCollection() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSurfaceInViewCollection::setSurfaceCollection( RimSurfaceCollection* surfcoll )
|
||||
{
|
||||
m_surfacecollection = surfcoll;
|
||||
m_surfaceCollection = surfcoll;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -132,10 +132,10 @@ void RimSurfaceInViewCollection::syncCollectionsWithView()
|
||||
|
||||
// Create new collection entries and reorder
|
||||
std::vector<RimSurfaceInViewCollection*> orderedColls;
|
||||
if ( m_surfacecollection )
|
||||
if ( m_surfaceCollection )
|
||||
{
|
||||
// pick up the collections and the order from the surface collection
|
||||
std::vector<RimSurfaceCollection*> surfcolls = m_surfacecollection->subcollections();
|
||||
std::vector<RimSurfaceCollection*> surfcolls = m_surfaceCollection->subCollections();
|
||||
for ( auto surfcoll : surfcolls )
|
||||
{
|
||||
// check if this is a collection we need to create
|
||||
@ -184,10 +184,10 @@ void RimSurfaceInViewCollection::syncSurfacesWithView()
|
||||
// Create new surfade entries and reorder
|
||||
std::vector<RimSurfaceInView*> orderedSurfs;
|
||||
|
||||
if ( m_surfacecollection )
|
||||
if ( m_surfaceCollection )
|
||||
{
|
||||
// pick up the surfaces and the order from the surface collection
|
||||
std::vector<RimSurface*> surfs = m_surfacecollection->surfaces();
|
||||
std::vector<RimSurface*> surfs = m_surfaceCollection->surfaces();
|
||||
for ( auto surf : surfs )
|
||||
{
|
||||
// check if this is a surface we need to create
|
||||
|
@ -78,8 +78,8 @@ private:
|
||||
void syncCollectionsWithView();
|
||||
void syncSurfacesWithView();
|
||||
|
||||
caf::PdmProxyValueField<QString> m_collectionname;
|
||||
caf::PdmProxyValueField<QString> m_collectionName;
|
||||
caf::PdmChildArrayField<RimSurfaceInViewCollection*> m_collectionsInView;
|
||||
caf::PdmChildArrayField<RimSurfaceInView*> m_surfacesInView;
|
||||
caf::PdmPtrField<RimSurfaceCollection*> m_surfacecollection;
|
||||
caf::PdmPtrField<RimSurfaceCollection*> m_surfaceCollection;
|
||||
};
|
||||
|
@ -7,7 +7,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimcProject.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcFractureModelCollection.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcFractureModelPlotCollection.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcFractureModelPlot.h
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcSurfaceCollection.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerDouble.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerString.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerTime.h
|
||||
@ -21,7 +21,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimcProject.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcFractureModelCollection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcFractureModelPlotCollection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcFractureModelPlot.cpp
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcSurfaceCollection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerDouble.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerString.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcDataContainerTime.cpp
|
||||
|
@ -21,8 +21,10 @@
|
||||
#include "RicImportSummaryCasesFeature.h"
|
||||
|
||||
#include "RimFileSummaryCase.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSurfaceCollection.h"
|
||||
#include "RiuPlotMainWindow.h"
|
||||
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
@ -138,3 +140,58 @@ bool RimProject_summaryCase::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimProject, RimProject_surfaceFolder, "surfaceFolder" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimProject_surfaceFolder::RimProject_surfaceFolder( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Get Surface Folder", "", "", "Get Surface Folder" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_folderName, "FolderName", "", "", "", "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObjectHandle* RimProject_surfaceFolder::execute()
|
||||
{
|
||||
auto proj = RimProject::current();
|
||||
RimSurfaceCollection* surfcoll = proj->activeOilField()->surfaceCollection();
|
||||
|
||||
// Blank foldername parameter should return the topmost folder
|
||||
if ( m_folderName().isEmpty() ) return surfcoll;
|
||||
|
||||
for ( auto s : surfcoll->subCollections() )
|
||||
{
|
||||
if ( s->collectionName() == m_folderName() ) return s;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimProject_surfaceFolder::resultIsPersistent() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<caf::PdmObjectHandle> RimProject_surfaceFolder::defaultResult() const
|
||||
{
|
||||
return std::unique_ptr<caf::PdmObjectHandle>( new RimSurfaceCollection );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimProject_surfaceFolder::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -62,3 +62,22 @@ public:
|
||||
private:
|
||||
caf::PdmField<int> m_caseId;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimProject_surfaceFolder : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimProject_surfaceFolder( caf::PdmObjectHandle* self );
|
||||
|
||||
caf::PdmObjectHandle* execute();
|
||||
bool resultIsPersistent() const override;
|
||||
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
|
||||
bool isNullptrValidResult() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_folderName;
|
||||
};
|
||||
|
@ -0,0 +1,132 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RimcSurfaceCollection.h"
|
||||
|
||||
#include "SurfaceCommands/RicImportSurfacesFeature.h"
|
||||
|
||||
#include "RimFileSurface.h"
|
||||
#include "RimSurface.h"
|
||||
#include "RimSurfaceCollection.h"
|
||||
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
#include "cafPdmObjectScriptingCapability.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSurfaceCollection, RimcSurfaceCollection_importSurface, "ImportSurface" );
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSurfaceCollection, RimcSurfaceCollection_addFolder, "AddFolder" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcSurfaceCollection_importSurface::RimcSurfaceCollection_importSurface( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Import Surface", "", "", "Import a new surface from file" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_fileName, "FileName", "", "", "", "Filename to import surface from" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObjectHandle* RimcSurfaceCollection_importSurface::execute()
|
||||
{
|
||||
RimSurfaceCollection* coll = self<RimSurfaceCollection>();
|
||||
if ( coll )
|
||||
{
|
||||
QStringList filelist;
|
||||
filelist << m_fileName();
|
||||
return coll->importSurfacesFromFiles( filelist );
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcSurfaceCollection_importSurface::resultIsPersistent() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<caf::PdmObjectHandle> RimcSurfaceCollection_importSurface::defaultResult() const
|
||||
{
|
||||
return std::unique_ptr<caf::PdmObjectHandle>( new RimFileSurface );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcSurfaceCollection_importSurface::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcSurfaceCollection_addFolder::RimcSurfaceCollection_addFolder( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Add Folder", "", "", "Add a new surface folder" );
|
||||
CAF_PDM_InitScriptableField( &m_folderName, "FolderName", QString( "Surfaces" ), "", "", "", "New surface folder name" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObjectHandle* RimcSurfaceCollection_addFolder::execute()
|
||||
{
|
||||
RimSurfaceCollection* coll = self<RimSurfaceCollection>();
|
||||
if ( coll )
|
||||
{
|
||||
RimSurfaceCollection* newcoll = new RimSurfaceCollection();
|
||||
newcoll->setCollectionName( m_folderName() );
|
||||
|
||||
coll->addSubCollection( newcoll );
|
||||
return newcoll;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcSurfaceCollection_addFolder::resultIsPersistent() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<caf::PdmObjectHandle> RimcSurfaceCollection_addFolder::defaultResult() const
|
||||
{
|
||||
return std::unique_ptr<caf::PdmObjectHandle>( new RimSurfaceCollection );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcSurfaceCollection_addFolder::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RimSurfaceCollection.h"
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include "cafPdmObjectMethod.h"
|
||||
#include "cafPdmPtrArrayField.h"
|
||||
#include "cafPdmPtrField.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class RimSurface;
|
||||
class RimSurfaceCollection;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimcSurfaceCollection_importSurface : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimcSurfaceCollection_importSurface( caf::PdmObjectHandle* self );
|
||||
|
||||
caf::PdmObjectHandle* execute();
|
||||
bool resultIsPersistent() const override;
|
||||
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
|
||||
bool isNullptrValidResult() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_fileName;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimcSurfaceCollection_addFolder : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimcSurfaceCollection_addFolder( caf::PdmObjectHandle* self );
|
||||
|
||||
caf::PdmObjectHandle* execute();
|
||||
bool resultIsPersistent() const override;
|
||||
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
|
||||
bool isNullptrValidResult() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_folderName;
|
||||
};
|
Loading…
Reference in New Issue
Block a user