mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-14 17:32:13 -05:00
Surface python interface (#6370)
* Add python interface for importing surfaces with example.
This commit is contained in:
1 parent
6f7534b2a9
commit
cfe64f5706
12 files changed
+395
-42
No files matched your search
@@ -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;
|
||||
};
|
||||
Reference in new issue
Block a user