mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4819 Add option to exclude undefined values from contour map export.
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
RICF_SOURCE_INIT( RicExportContourMapToAsciiFeature, "RicExportContourMapToAsciiFeature", "exportContourMapToText" );
|
||||
|
||||
RicExportContourMapToAsciiFeature::RicExportContourMapToAsciiFeature()
|
||||
@@ -44,6 +46,7 @@ RicExportContourMapToAsciiFeature::RicExportContourMapToAsciiFeature()
|
||||
RICF_InitFieldNoDefault( &m_exportFileName, "exportFileName", "", "", "", "" );
|
||||
RICF_InitFieldNoDefault( &m_exportLocalCoordinates, "exportLocalCoordinates", "", "", "", "" );
|
||||
RICF_InitFieldNoDefault( &m_undefinedValueLabel, "undefinedValueLabel", "", "", "", "" );
|
||||
RICF_InitFieldNoDefault( &m_excludeUndefinedValues, "excludeUndefinedValues", "", "", "", "" );
|
||||
RICF_InitField( &m_viewId, "viewId", -1, "View Id", "", "", "" );
|
||||
}
|
||||
|
||||
@@ -111,8 +114,9 @@ void RicExportContourMapToAsciiFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
app->setLastUsedDialogDirectory( "CONTOUR_EXPORT", fileName );
|
||||
m_exportFileName = fileName;
|
||||
m_exportLocalCoordinates = true;
|
||||
m_undefinedValueLabel = "fæskslo";
|
||||
m_exportLocalCoordinates = featureUi.exportLocalCoordinates();
|
||||
m_undefinedValueLabel = featureUi.undefinedValueLabel();
|
||||
m_excludeUndefinedValues = featureUi.excludeUndefinedValues();
|
||||
|
||||
RicfCommandResponse response = execute();
|
||||
QStringList messages = response.messages();
|
||||
@@ -136,7 +140,10 @@ void RicExportContourMapToAsciiFeature::onActionTriggered( bool isChecked )
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportContourMapToAsciiFeature::writeContourMapToStream( QTextStream& stream,
|
||||
const RimContourMapProjection* contourMapProjection )
|
||||
const RimContourMapProjection* contourMapProjection,
|
||||
bool exportLocalCoordinates,
|
||||
const QString& undefinedValueLabel,
|
||||
bool excludeUndefinedValues )
|
||||
{
|
||||
RifTextDataTableFormatter formatter( stream );
|
||||
formatter.setTableRowLineAppendText( "" );
|
||||
@@ -157,10 +164,14 @@ void RicExportContourMapToAsciiFeature::writeContourMapToStream( QTextStream&
|
||||
{
|
||||
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();
|
||||
double value = contourMapProjection->valueAtVertex( i, j );
|
||||
if ( !( std::isinf( value ) && excludeUndefinedValues ) )
|
||||
{
|
||||
formatter.add( static_cast<int>( i ) );
|
||||
formatter.add( static_cast<int>( j ) );
|
||||
formatter.add( value );
|
||||
formatter.rowCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,13 +194,7 @@ RicfCommandResponse RicExportContourMapToAsciiFeature::execute()
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
|
||||
RimProject* proj = app->project();
|
||||
|
||||
// TODO: Add error message
|
||||
if ( !proj )
|
||||
{
|
||||
response.updateStatus( RicfCommandResponse::COMMAND_ERROR, "No project found!" );
|
||||
return response;
|
||||
}
|
||||
CAF_ASSERT( proj );
|
||||
|
||||
std::vector<Rim3dView*> allViews;
|
||||
proj->allViews( allViews );
|
||||
@@ -229,7 +234,11 @@ RicfCommandResponse RicExportContourMapToAsciiFeature::execute()
|
||||
{
|
||||
QString tableText;
|
||||
QTextStream stream( &exportFile );
|
||||
writeContourMapToStream( stream, contourMapProjection );
|
||||
writeContourMapToStream( stream,
|
||||
contourMapProjection,
|
||||
m_exportLocalCoordinates.value(),
|
||||
m_undefinedValueLabel.value(),
|
||||
m_excludeUndefinedValues.value() );
|
||||
}
|
||||
|
||||
for ( QString errorMessage : errorMessages )
|
||||
|
||||
@@ -41,7 +41,11 @@ protected:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
|
||||
static void writeContourMapToStream( QTextStream& stream, const RimContourMapProjection* contourMapProjection );
|
||||
static void writeContourMapToStream( QTextStream& stream,
|
||||
const RimContourMapProjection* contourMapProjection,
|
||||
bool exportLocalCoordinates,
|
||||
const QString& undefinedValueLabel,
|
||||
bool excludeUndefinedValues );
|
||||
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
@@ -49,5 +53,6 @@ private:
|
||||
caf::PdmField<QString> m_exportFileName;
|
||||
caf::PdmField<bool> m_exportLocalCoordinates;
|
||||
caf::PdmField<QString> m_undefinedValueLabel;
|
||||
caf::PdmField<bool> m_excludeUndefinedValues;
|
||||
caf::PdmField<int> m_viewId;
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ RicExportContourMapToAsciiUi::RicExportContourMapToAsciiUi()
|
||||
|
||||
CAF_PDM_InitField( &m_exportLocalCoordinates, "ExportLocalCoordinates", false, "Export Local Coordinates", "", "", "" );
|
||||
CAF_PDM_InitField( &m_undefinedValueLabel, "UndefinedValueLabel", QString( "NaN" ), "Undefined Value Label", "", "", "" );
|
||||
CAF_PDM_InitField( &m_excludeUndefinedValues, "ExcludeUndefinedValues", false, "Exclude Undefined Values", "", "", "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -49,6 +50,14 @@ QString RicExportContourMapToAsciiUi::undefinedValueLabel() const
|
||||
return m_undefinedValueLabel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicExportContourMapToAsciiUi::excludeUndefinedValues() const
|
||||
{
|
||||
return m_excludeUndefinedValues;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
void setExportFileName( const QString& exportFileName );
|
||||
bool exportLocalCoordinates() const;
|
||||
QString undefinedValueLabel() const;
|
||||
bool excludeUndefinedValues() const;
|
||||
|
||||
protected:
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
@@ -45,4 +46,5 @@ private:
|
||||
caf::PdmField<QString> m_exportFileName;
|
||||
caf::PdmField<bool> m_exportLocalCoordinates;
|
||||
caf::PdmField<QString> m_undefinedValueLabel;
|
||||
caf::PdmField<bool> m_excludeUndefinedValues;
|
||||
};
|
||||
|
||||
@@ -319,7 +319,8 @@ message ExportContourMapToTextRequest
|
||||
string exportFileName = 1;
|
||||
bool exportLocalCoordinates = 2;
|
||||
string undefinedValueLabel = 3;
|
||||
int32 viewId = 4;
|
||||
bool excludeUndefinedValues = 4;
|
||||
int32 viewId = 5;
|
||||
}
|
||||
|
||||
/* CommandParams handles both command name and parameters in one.
|
||||
|
||||
@@ -33,16 +33,18 @@ class ContourMap(View):
|
||||
self.map_type = map_type
|
||||
|
||||
|
||||
def export_to_text(self, export_file_name='', export_local_coordinates=False, undefined_value_label="NaN"):
|
||||
def export_to_text(self, export_file_name='', export_local_coordinates=False, undefined_value_label="NaN", exclude_undefined_values=False):
|
||||
""" Export snapshot for the current view
|
||||
Arguments:
|
||||
export_file_name(str): The file location to store results in.
|
||||
export_local_coordinates(bool): Should we export local coordinates, or UTM.
|
||||
undefined_value_label(str): Replace undefined values with this label.
|
||||
exclude_undefined_values(bool): Skip undefined values.
|
||||
"""
|
||||
return self._execute_command(
|
||||
exportContourMapToText=Cmd.ExportContourMapToTextRequest(
|
||||
exportFileName=export_file_name,
|
||||
exportLocalCoordinates=export_local_coordinates,
|
||||
undefinedValueLabel=undefined_value_label,
|
||||
excludeUndefinedValues=exclude_undefined_values,
|
||||
viewId=self.view_id))
|
||||
|
||||
Reference in New Issue
Block a user