mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-16 18:34:54 -06:00
#4819 Export contour map to ascii.
This commit is contained in:
parent
3cbbf1fd6e
commit
7f3240fd70
@ -81,6 +81,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicConvertGroupToEnsembleFeature.h
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RicResampleDialog.h
|
${CMAKE_CURRENT_LIST_DIR}/RicResampleDialog.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicCreateTemporaryLgrFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicCreateTemporaryLgrFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicDeleteTemporaryLgrsFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicDeleteTemporaryLgrsFeature.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RicExportContourMapToAsciiFeature.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -160,6 +161,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicConvertGroupToEnsembleFeature.cpp
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RicResampleDialog.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicResampleDialog.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicCreateTemporaryLgrFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicCreateTemporaryLgrFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicDeleteTemporaryLgrsFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicDeleteTemporaryLgrsFeature.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RicExportContourMapToAsciiFeature.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
138
ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp
Normal file
138
ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2019- 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 "RicExportContourMapToAsciiFeature.h"
|
||||||
|
|
||||||
|
#include "RiaGuiApplication.h"
|
||||||
|
#include "RiaLogging.h"
|
||||||
|
#include "RifTextDataTableFormatter.h"
|
||||||
|
#include "RimContourMapProjection.h"
|
||||||
|
#include "RimEclipseContourMapProjection.h"
|
||||||
|
#include "RimEclipseContourMapView.h"
|
||||||
|
#include "RimGeoMechContourMapProjection.h"
|
||||||
|
#include "RimGeoMechContourMapView.h"
|
||||||
|
|
||||||
|
#include "cafSelectionManager.h"
|
||||||
|
#include "cafUtils.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
CAF_CMD_SOURCE_INIT( RicExportContourMapToAsciiFeature, "RicExportContourMapToAsciiFeature" );
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RicExportContourMapToAsciiFeature::isCommandEnabled()
|
||||||
|
{
|
||||||
|
RimEclipseContourMapView* existingEclipseContourMap = caf::SelectionManager::instance()
|
||||||
|
->selectedItemOfType<RimEclipseContourMapView>();
|
||||||
|
RimGeoMechContourMapView* existingGeoMechContourMap = caf::SelectionManager::instance()
|
||||||
|
->selectedItemOfType<RimGeoMechContourMapView>();
|
||||||
|
return existingEclipseContourMap || existingGeoMechContourMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicExportContourMapToAsciiFeature::onActionTriggered( bool isChecked )
|
||||||
|
{
|
||||||
|
RimContourMapProjection* contourMapProjection = nullptr;
|
||||||
|
RimEclipseContourMapView* existingEclipseContourMap = caf::SelectionManager::instance()
|
||||||
|
->selectedItemOfType<RimEclipseContourMapView>();
|
||||||
|
RimGeoMechContourMapView* existingGeoMechContourMap = caf::SelectionManager::instance()
|
||||||
|
->selectedItemOfType<RimGeoMechContourMapView>();
|
||||||
|
CAF_ASSERT( existingEclipseContourMap || existingGeoMechContourMap );
|
||||||
|
|
||||||
|
QString contourMapName;
|
||||||
|
if ( existingEclipseContourMap )
|
||||||
|
{
|
||||||
|
contourMapProjection = existingEclipseContourMap->contourMapProjection();
|
||||||
|
contourMapName = existingEclipseContourMap->createAutoName();
|
||||||
|
}
|
||||||
|
else if ( existingGeoMechContourMap )
|
||||||
|
{
|
||||||
|
contourMapProjection = existingGeoMechContourMap->contourMapProjection();
|
||||||
|
contourMapName = existingGeoMechContourMap->createAutoName();
|
||||||
|
}
|
||||||
|
|
||||||
|
CAF_ASSERT( contourMapProjection );
|
||||||
|
|
||||||
|
RiaGuiApplication* app = RiaGuiApplication::instance();
|
||||||
|
CAF_ASSERT( app && "Must be gui mode" );
|
||||||
|
QString startPath = app->lastUsedDialogDirectoryWithFallbackToProjectFolder( "CONTOUR_EXPORT" );
|
||||||
|
|
||||||
|
QString fileBaseName = caf::Utils::makeValidFileBasename( contourMapName );
|
||||||
|
|
||||||
|
startPath = startPath + "/" + fileBaseName + ".txt";
|
||||||
|
|
||||||
|
QString fileName = QFileDialog::getSaveFileName( nullptr,
|
||||||
|
tr( "Export Contour Map To Text File" ),
|
||||||
|
startPath,
|
||||||
|
tr( "Text file (*.txt);;All files(*.*)" ) );
|
||||||
|
|
||||||
|
if ( fileName.isEmpty() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile exportFile( fileName );
|
||||||
|
if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
|
||||||
|
{
|
||||||
|
RiaLogging::error( QString( "Export Contour Map as Text : Could not open the file: %1" ).arg( fileName ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cvf::Vec2ui numVerticesIJ = contourMapProjection->numberOfVerticesIJ();
|
||||||
|
|
||||||
|
QString tableText;
|
||||||
|
QTextStream stream( &exportFile );
|
||||||
|
RifTextDataTableFormatter formatter( stream );
|
||||||
|
formatter.setTableRowLineAppendText( "" );
|
||||||
|
formatter.setTableRowPrependText( "" );
|
||||||
|
formatter.setCommentPrefix( "#" );
|
||||||
|
|
||||||
|
std::vector<RifTextDataTableColumn> header = {
|
||||||
|
RifTextDataTableColumn( "x" ),
|
||||||
|
RifTextDataTableColumn( "y" ),
|
||||||
|
RifTextDataTableColumn( "value" ),
|
||||||
|
};
|
||||||
|
|
||||||
|
formatter.header( header );
|
||||||
|
|
||||||
|
for ( unsigned int j = 0; j < numVerticesIJ.y(); j++ )
|
||||||
|
{
|
||||||
|
for ( unsigned int i = 0; i < numVerticesIJ.x(); i++ )
|
||||||
|
{
|
||||||
|
formatter.add( static_cast<int>( i ) );
|
||||||
|
formatter.add( static_cast<int>( j ) );
|
||||||
|
formatter.add( contourMapProjection->valueAtVertex( i, j ) );
|
||||||
|
formatter.rowCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter.tableCompleted();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RicExportContourMapToAsciiFeature::setupActionLook( QAction* actionToSetup )
|
||||||
|
{
|
||||||
|
actionToSetup->setText( "Export Contour Map to Ascii" );
|
||||||
|
}
|
34
ApplicationCode/Commands/RicExportContourMapToAsciiFeature.h
Normal file
34
ApplicationCode/Commands/RicExportContourMapToAsciiFeature.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (C) 2019- 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 "cafCmdFeature.h"
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
///
|
||||||
|
//==================================================================================================
|
||||||
|
class RicExportContourMapToAsciiFeature : public caf::CmdFeature
|
||||||
|
{
|
||||||
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Overrides
|
||||||
|
bool isCommandEnabled() override;
|
||||||
|
void onActionTriggered( bool isChecked ) override;
|
||||||
|
void setupActionLook( QAction* actionToSetup ) override;
|
||||||
|
};
|
@ -38,6 +38,7 @@
|
|||||||
#include "RimEclipseCase.h"
|
#include "RimEclipseCase.h"
|
||||||
#include "RimEclipseCaseCollection.h"
|
#include "RimEclipseCaseCollection.h"
|
||||||
#include "RimEclipseCellColors.h"
|
#include "RimEclipseCellColors.h"
|
||||||
|
#include "RimEclipseContourMapView.h"
|
||||||
#include "RimEclipseContourMapViewCollection.h"
|
#include "RimEclipseContourMapViewCollection.h"
|
||||||
#include "RimEclipseInputProperty.h"
|
#include "RimEclipseInputProperty.h"
|
||||||
#include "RimEclipseInputPropertyCollection.h"
|
#include "RimEclipseInputPropertyCollection.h"
|
||||||
@ -61,6 +62,7 @@
|
|||||||
#include "RimFractureTemplate.h"
|
#include "RimFractureTemplate.h"
|
||||||
#include "RimFractureTemplateCollection.h"
|
#include "RimFractureTemplateCollection.h"
|
||||||
#include "RimGeoMechCase.h"
|
#include "RimGeoMechCase.h"
|
||||||
|
#include "RimGeoMechContourMapView.h"
|
||||||
#include "RimGeoMechContourMapViewCollection.h"
|
#include "RimGeoMechContourMapViewCollection.h"
|
||||||
#include "RimGeoMechPropertyFilter.h"
|
#include "RimGeoMechPropertyFilter.h"
|
||||||
#include "RimGeoMechPropertyFilterCollection.h"
|
#include "RimGeoMechPropertyFilterCollection.h"
|
||||||
@ -174,6 +176,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
|||||||
|
|
||||||
menuBuilder << "Separator";
|
menuBuilder << "Separator";
|
||||||
menuBuilder << "RicCopyReferencesToClipboardFeature";
|
menuBuilder << "RicCopyReferencesToClipboardFeature";
|
||||||
|
menuBuilder << "RicExportContourMapToAsciiFeature";
|
||||||
}
|
}
|
||||||
else if ( dynamic_cast<RimEclipseView*>( uiItem ) )
|
else if ( dynamic_cast<RimEclipseView*>( uiItem ) )
|
||||||
{
|
{
|
||||||
@ -186,6 +189,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
|||||||
menuBuilder << "Separator";
|
menuBuilder << "Separator";
|
||||||
menuBuilder << "RicCopyReferencesToClipboardFeature";
|
menuBuilder << "RicCopyReferencesToClipboardFeature";
|
||||||
menuBuilder << "RicExportEclipseInputGridFeature";
|
menuBuilder << "RicExportEclipseInputGridFeature";
|
||||||
|
menuBuilder << "RicExportContourMapToAsciiFeature";
|
||||||
menuBuilder << "RicSaveEclipseInputVisibleCellsFeature";
|
menuBuilder << "RicSaveEclipseInputVisibleCellsFeature";
|
||||||
}
|
}
|
||||||
else if ( dynamic_cast<RimEclipseContourMapViewCollection*>( uiItem ) )
|
else if ( dynamic_cast<RimEclipseContourMapViewCollection*>( uiItem ) )
|
||||||
|
Loading…
Reference in New Issue
Block a user