ResInsight/ApplicationCode/Commands/SurfaceCommands/RicExportSurfaceToTsurfFeature.cpp

96 lines
3.7 KiB
C++
Raw Normal View History

2020-04-29 03:19:38 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicExportSurfaceToTsurfFeature.h"
2020-04-29 03:19:38 -05:00
#include "RiaApplication.h"
#include "RifSurfaceExporter.h"
2020-04-29 03:19:38 -05:00
#include "RigSurface.h"
#include "RimSurface.h"
#include "Riu3DMainWindowTools.h"
#include "cafSelectionManagerTools.h"
#include "cafUtils.h"
#include <QAction>
#include <QFileDialog>
CAF_CMD_SOURCE_INIT( RicExportSurfaceToTsurfFeature, "RicExportSurfaceToTsurfFeature" );
2020-04-29 03:19:38 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicExportSurfaceToTsurfFeature::isCommandEnabled()
2020-04-29 03:19:38 -05:00
{
std::vector<RimSurface*> surfaces = caf::selectedObjectsByTypeStrict<RimSurface*>();
return !surfaces.empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportSurfaceToTsurfFeature::onActionTriggered( bool isChecked )
2020-04-29 03:19:38 -05:00
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectoryWithFallbackToProjectFolder( "EXPORT_SURFACE" );
QStringList imageFileExtensions;
imageFileExtensions << "*.ts";
QString fileExtensionFilter = QString( "Surface (%1)" ).arg( imageFileExtensions.join( " " ) );
QString defaultExtension = "ts";
QString defaultFileBaseName = "surface";
QString defaultAbsFileName =
caf::Utils::constructFullFileName( defaultDir, defaultFileBaseName, "." + defaultExtension );
QString selectedExtension;
std::vector<RimSurface*> surfaces = caf::selectedObjectsByTypeStrict<RimSurface*>();
for ( RimSurface* surf : surfaces )
{
QString fileName = QFileDialog::getSaveFileName( nullptr,
tr( "Export to File" ),
defaultAbsFileName,
fileExtensionFilter,
&selectedExtension );
if ( fileName.isEmpty() ) return;
app->setLastUsedDialogDirectory( "EXPORT_SURFACE", QFileInfo( fileName ).absolutePath() );
RigSurface* surface = surf->surfaceData();
RifSurfaceExporter::writeGocadTSurfFile( fileName,
surf->userDescription(),
surface->vertices(),
surface->triangleIndices() );
2020-04-29 03:19:38 -05:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportSurfaceToTsurfFeature::setupActionLook( QAction* actionToSetup )
2020-04-29 03:19:38 -05:00
{
actionToSetup->setIcon( QIcon( ":/ReservoirSurfaces16x16.png" ) );
actionToSetup->setText( "Export Surface to GOCAD TSurf file" );
2020-04-29 03:19:38 -05:00
}