///////////////////////////////////////////////////////////////////////////////// // // 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 "RicExportKLayerToPtlFeature.h" #include "RiaApplication.h" #include "RifSurfaceExporter.h" #include "RigSurface.h" #include "RimGridCaseSurface.h" #include "Riu3DMainWindowTools.h" #include "RiuFileDialogTools.h" #include "cafSelectionManagerTools.h" #include "cafUtils.h" #include #include CAF_CMD_SOURCE_INIT( RicExportKLayerToPtlFeature, "RicExportKLayerToPtlFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicExportKLayerToPtlFeature::isCommandEnabled() const { // std::vector surfaces = caf::selectedObjectsByTypeStrict(); std::vector surfaces = caf::selectedObjectsByTypeStrict(); return !surfaces.empty(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicExportKLayerToPtlFeature::onActionTriggered( bool isChecked ) { RiaApplication* app = RiaApplication::instance(); QString defaultDir = app->lastUsedDialogDirectoryWithFallbackToProjectFolder( "EXPORT_SURFACE" ); QStringList imageFileExtensions; imageFileExtensions << "*.ptl"; QString fileExtensionFilter = QString( "Surface (%1)" ).arg( imageFileExtensions.join( " " ) ); QString defaultExtension = "ptl"; QString defaultFileBaseName = "surface"; QString defaultAbsFileName = caf::Utils::constructFullFileName( defaultDir, defaultFileBaseName, "." + defaultExtension ); QString selectedExtension; std::vector surfaces = caf::selectedObjectsByTypeStrict(); for ( RimGridCaseSurface* surf : surfaces ) { QString fileName = RiuFileDialogTools::getSaveFileName( nullptr, tr( "Export to File" ), defaultAbsFileName, fileExtensionFilter, &selectedExtension ); if ( fileName.isEmpty() ) return; app->setLastUsedDialogDirectory( "EXPORT_SURFACE", QFileInfo( fileName ).absolutePath() ); std::vector vertices; std::vector> structGridVertexIndices; if ( surf->exportStructSurfaceFromGridCase( &vertices, &structGridVertexIndices ) ) { RifSurfaceExporter::writePetrelPtlFile( fileName, vertices, structGridVertexIndices ); } } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicExportKLayerToPtlFeature::setupActionLook( QAction* actionToSetup ) { actionToSetup->setIcon( QIcon( ":/ReservoirSurfaces16x16.png" ) ); actionToSetup->setText( "Export Grid Case Surface to Petrel ptl-file" ); }