From cfe64f57062cbf072b94b0ccb40c9f28a1be5e27 Mon Sep 17 00:00:00 2001 From: jonjenssen <69144954+jonjenssen@users.noreply.github.com> Date: Wed, 26 Aug 2020 12:31:23 +0200 Subject: [PATCH] Surface python interface (#6370) * Add python interface for importing surfaces with example. --- .../rips/PythonExamples/surface_import.py | 40 ++++++ .../Surfaces/RimFileSurface.cpp | 5 +- .../ProjectDataModel/Surfaces/RimSurface.cpp | 10 +- .../Surfaces/RimSurfaceCollection.cpp | 54 +++++-- .../Surfaces/RimSurfaceCollection.h | 12 +- .../Surfaces/RimSurfaceInViewCollection.cpp | 28 ++-- .../Surfaces/RimSurfaceInViewCollection.h | 4 +- .../CMakeLists_files.cmake | 4 +- .../ProjectDataModelCommands/RimcProject.cpp | 57 ++++++++ .../ProjectDataModelCommands/RimcProject.h | 19 +++ .../RimcSurfaceCollection.cpp | 132 ++++++++++++++++++ .../RimcSurfaceCollection.h | 72 ++++++++++ 12 files changed, 395 insertions(+), 42 deletions(-) create mode 100644 ApplicationCode/GrpcInterface/Python/rips/PythonExamples/surface_import.py create mode 100644 ApplicationCode/ProjectDataModelCommands/RimcSurfaceCollection.cpp create mode 100644 ApplicationCode/ProjectDataModelCommands/RimcSurfaceCollection.h diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/surface_import.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/surface_import.py new file mode 100644 index 0000000000..ded1efbee5 --- /dev/null +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/surface_import.py @@ -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.") diff --git a/ApplicationCode/ProjectDataModel/Surfaces/RimFileSurface.cpp b/ApplicationCode/ProjectDataModel/Surfaces/RimFileSurface.cpp index d04dcebb8b..67bb222974 100644 --- a/ApplicationCode/ProjectDataModel/Surfaces/RimFileSurface.cpp +++ b/ApplicationCode/ProjectDataModel/Surfaces/RimFileSurface.cpp @@ -23,6 +23,9 @@ #include "RigSurface.h" #include "RimSurfaceCollection.h" +#include "cafPdmFieldScriptingCapability.h" +#include "cafPdmObjectScriptingCapability.h" + #include // 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", "", "", "" ); } diff --git a/ApplicationCode/ProjectDataModel/Surfaces/RimSurface.cpp b/ApplicationCode/ProjectDataModel/Surfaces/RimSurface.cpp index 9a9e5385e8..62ce1aafed 100644 --- a/ApplicationCode/ProjectDataModel/Surfaces/RimSurface.cpp +++ b/ApplicationCode/ProjectDataModel/Surfaces/RimSurface.cpp @@ -24,6 +24,9 @@ #include "RifSurfaceImporter.h" +#include "cafPdmFieldScriptingCapability.h" +#include "cafPdmObjectScriptingCapability.h" + #include "cafPdmUiDoubleSliderEditor.h" #include @@ -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()->setIOWriteable( true ); CAF_PDM_InitFieldNoDefault( &m_nameProxy, "NameProxy", "Name Proxy", "", "", "" ); m_nameProxy.registerGetMethod( this, &RimSurface::fullName ); diff --git a/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceCollection.cpp b/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceCollection.cpp index e4afd70790..e76d960db0 100644 --- a/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceCollection.cpp @@ -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 RimSurfaceCollection::surfaces() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimSurfaceCollection::subcollections() const +std::vector 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 surfaces ) { // adjust index for number of folders we have - position = position - static_cast( m_subcollections.size() ); + position = position - static_cast( 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; +} diff --git a/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceCollection.h b/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceCollection.h index 6e157ff6a3..f33d6fe91d 100644 --- a/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceCollection.h +++ b/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceCollection.h @@ -41,7 +41,8 @@ public: RimSurface* copySurfaces( std::vector surfaces ); RimSurface* addSurfacesAtIndex( int index, std::vector surfaces ); - void addSubCollection( RimSurfaceCollection* collection ); + void addSubCollection( RimSurfaceCollection* collection ); + RimSurfaceCollection* getSubCollection( const QString name ); void reloadSurfaces( std::vector surfaces ); void removeSurface( RimSurface* surface ); @@ -54,10 +55,11 @@ public: void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector& referringObjects ) override; - QString collectionname() const; + QString collectionName() const; + void setCollectionName( const QString name ); std::vector surfaces() const; - std::vector subcollections() const; + std::vector subCollections() const; protected: caf::PdmFieldHandle* userDescriptionField() override; @@ -65,7 +67,7 @@ protected: private: void orderChanged( const caf::SignalEmitter* emitter ); - caf::PdmField m_collectionname; + caf::PdmField m_collectionName; caf::PdmChildArrayField m_surfaces; - caf::PdmChildArrayField m_subcollections; + caf::PdmChildArrayField m_subCollections; }; diff --git a/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp b/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp index a9c5868718..b9c83925e3 100644 --- a/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.cpp @@ -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 orderedColls; - if ( m_surfacecollection ) + if ( m_surfaceCollection ) { // pick up the collections and the order from the surface collection - std::vector surfcolls = m_surfacecollection->subcollections(); + std::vector 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 orderedSurfs; - if ( m_surfacecollection ) + if ( m_surfaceCollection ) { // pick up the surfaces and the order from the surface collection - std::vector surfs = m_surfacecollection->surfaces(); + std::vector surfs = m_surfaceCollection->surfaces(); for ( auto surf : surfs ) { // check if this is a surface we need to create diff --git a/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h b/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h index 378107a8a9..72d61edfd1 100644 --- a/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h +++ b/ApplicationCode/ProjectDataModel/Surfaces/RimSurfaceInViewCollection.h @@ -78,8 +78,8 @@ private: void syncCollectionsWithView(); void syncSurfacesWithView(); - caf::PdmProxyValueField m_collectionname; + caf::PdmProxyValueField m_collectionName; caf::PdmChildArrayField m_collectionsInView; caf::PdmChildArrayField m_surfacesInView; - caf::PdmPtrField m_surfacecollection; + caf::PdmPtrField m_surfaceCollection; }; diff --git a/ApplicationCode/ProjectDataModelCommands/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModelCommands/CMakeLists_files.cmake index 519f7433c3..262840b42d 100644 --- a/ApplicationCode/ProjectDataModelCommands/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModelCommands/CMakeLists_files.cmake @@ -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 diff --git a/ApplicationCode/ProjectDataModelCommands/RimcProject.cpp b/ApplicationCode/ProjectDataModelCommands/RimcProject.cpp index 0aa903c123..67ee93f775 100644 --- a/ApplicationCode/ProjectDataModelCommands/RimcProject.cpp +++ b/ApplicationCode/ProjectDataModelCommands/RimcProject.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 RimProject_surfaceFolder::defaultResult() const +{ + return std::unique_ptr( new RimSurfaceCollection ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimProject_surfaceFolder::isNullptrValidResult() const +{ + return true; +} diff --git a/ApplicationCode/ProjectDataModelCommands/RimcProject.h b/ApplicationCode/ProjectDataModelCommands/RimcProject.h index 75a7a8c38e..90420c3122 100644 --- a/ApplicationCode/ProjectDataModelCommands/RimcProject.h +++ b/ApplicationCode/ProjectDataModelCommands/RimcProject.h @@ -62,3 +62,22 @@ public: private: caf::PdmField 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 defaultResult() const override; + bool isNullptrValidResult() const override; + +private: + caf::PdmField m_folderName; +}; diff --git a/ApplicationCode/ProjectDataModelCommands/RimcSurfaceCollection.cpp b/ApplicationCode/ProjectDataModelCommands/RimcSurfaceCollection.cpp new file mode 100644 index 0000000000..1913e4a010 --- /dev/null +++ b/ApplicationCode/ProjectDataModelCommands/RimcSurfaceCollection.cpp @@ -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 +// 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 + +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(); + if ( coll ) + { + QStringList filelist; + filelist << m_fileName(); + return coll->importSurfacesFromFiles( filelist ); + } + return nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimcSurfaceCollection_importSurface::resultIsPersistent() const +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::unique_ptr RimcSurfaceCollection_importSurface::defaultResult() const +{ + return std::unique_ptr( 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(); + 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 RimcSurfaceCollection_addFolder::defaultResult() const +{ + return std::unique_ptr( new RimSurfaceCollection ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimcSurfaceCollection_addFolder::isNullptrValidResult() const +{ + return true; +} diff --git a/ApplicationCode/ProjectDataModelCommands/RimcSurfaceCollection.h b/ApplicationCode/ProjectDataModelCommands/RimcSurfaceCollection.h new file mode 100644 index 0000000000..c5d0842de4 --- /dev/null +++ b/ApplicationCode/ProjectDataModelCommands/RimcSurfaceCollection.h @@ -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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RimSurfaceCollection.h" + +#include "cafPdmField.h" +#include "cafPdmObjectHandle.h" +#include "cafPdmObjectMethod.h" +#include "cafPdmPtrArrayField.h" +#include "cafPdmPtrField.h" + +#include + +#include + +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 defaultResult() const override; + bool isNullptrValidResult() const override; + +private: + caf::PdmField 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 defaultResult() const override; + bool isNullptrValidResult() const override; + +private: + caf::PdmField m_folderName; +};