diff --git a/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp b/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp index 5098ae1877..9bf06b927a 100644 --- a/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp +++ b/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.cpp @@ -37,6 +37,8 @@ #include #include +#include + 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( i ) ); - formatter.add( static_cast( j ) ); - formatter.add( contourMapProjection->valueAtVertex( i, j ) ); - formatter.rowCompleted(); + double value = contourMapProjection->valueAtVertex( i, j ); + if ( !( std::isinf( value ) && excludeUndefinedValues ) ) + { + formatter.add( static_cast( i ) ); + formatter.add( static_cast( 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 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 ) diff --git a/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.h b/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.h index 35b20ebce1..21fb79886c 100644 --- a/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.h +++ b/ApplicationCode/Commands/RicExportContourMapToAsciiFeature.h @@ -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 m_exportFileName; caf::PdmField m_exportLocalCoordinates; caf::PdmField m_undefinedValueLabel; + caf::PdmField m_excludeUndefinedValues; caf::PdmField m_viewId; }; diff --git a/ApplicationCode/Commands/RicExportContourMapToAsciiUi.cpp b/ApplicationCode/Commands/RicExportContourMapToAsciiUi.cpp index f528d0ce94..4d0a393381 100644 --- a/ApplicationCode/Commands/RicExportContourMapToAsciiUi.cpp +++ b/ApplicationCode/Commands/RicExportContourMapToAsciiUi.cpp @@ -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; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/RicExportContourMapToAsciiUi.h b/ApplicationCode/Commands/RicExportContourMapToAsciiUi.h index 8975d336f2..3715a98ad0 100644 --- a/ApplicationCode/Commands/RicExportContourMapToAsciiUi.h +++ b/ApplicationCode/Commands/RicExportContourMapToAsciiUi.h @@ -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 m_exportFileName; caf::PdmField m_exportLocalCoordinates; caf::PdmField m_undefinedValueLabel; + caf::PdmField m_excludeUndefinedValues; }; diff --git a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto index 2a5d703243..f986749a4e 100644 --- a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto +++ b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto @@ -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. diff --git a/ApplicationCode/GrpcInterface/Python/rips/contour_map.py b/ApplicationCode/GrpcInterface/Python/rips/contour_map.py index 696dd483b6..901b0de290 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/contour_map.py +++ b/ApplicationCode/GrpcInterface/Python/rips/contour_map.py @@ -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))