diff --git a/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp b/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp index 378d678283..87de3e2f42 100644 --- a/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp +++ b/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp @@ -27,6 +27,7 @@ #include #include +#include #include CAF_CMD_SOURCE_INIT( RicExportInpFileFeature, "RicExportInpFileFeature" ); @@ -47,8 +48,16 @@ void RicExportInpFileFeature::onActionTriggered( bool isChecked ) auto faultReactivationModel = caf::SelectionManager::instance()->selectedItemOfType(); if ( faultReactivationModel ) { - QString exportFile = faultReactivationModel->baseDir() + "/faultreactivation.inp"; - RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *faultReactivationModel ); + QString exportFile = faultReactivationModel->baseDir() + "/faultreactivation.inp"; + auto [isOk, errorMessage] = RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *faultReactivationModel ); + if ( !isOk ) + { + const QString frmTitle( "Fault Reactivation Modeling" ); + + QString outErrorText = + QString( "Failed to export INP model to file %1.\n\n%2" ).arg( exportFile ).arg( QString::fromStdString( errorMessage ) ); + QMessageBox::critical( nullptr, frmTitle, outErrorText ); + } } } diff --git a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp index 4bcfc132db..e5ca9b025c 100644 --- a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp +++ b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp @@ -66,17 +66,25 @@ std::pair RifFaultReactivationModelExporter::exportToStream( auto model = rimModel.model(); CAF_ASSERT( !model.isNull() ); - printHeading( stream, applicationNameAndVersion ); - printParts( stream, *model, partNames, borders, faces, boundaries, rimModel.localCoordSysNormalsXY() ); - printAssembly( stream, *model, partNames ); - printMaterials( stream ); - printInteractionProperties( stream, faultFriction ); - printBoundaryConditions( stream, *model, partNames, boundaries ); - printPredefinedFields( stream, partNames ); - printInteractions( stream, partNames, borders ); - printSteps( stream, partNames ); - - // TODO: improve error handling + + std::vector()>> methods = { + [&]() { return printHeading( stream, applicationNameAndVersion ); }, + [&]() { return printParts( stream, *model, partNames, borders, faces, boundaries, rimModel.localCoordSysNormalsXY() ); }, + [&]() { return printAssembly( stream, *model, partNames ); }, + [&]() { return printMaterials( stream ); }, + [&]() { return printInteractionProperties( stream, faultFriction ); }, + [&]() { return printBoundaryConditions( stream, *model, partNames, boundaries ); }, + [&]() { return printPredefinedFields( stream, partNames ); }, + [&]() { return printInteractions( stream, partNames, borders ); }, + [&]() { return printSteps( stream, partNames ); }, + }; + + for ( auto method : methods ) + { + auto [isOk, errorMessage] = method(); + if ( !isOk ) return { false, errorMessage }; + } + return { true, "" }; } @@ -184,6 +192,8 @@ std::pair RifFaultReactivationModelExporter::printParts( RifInpExportTools::printLine( stream, "," ); RifInpExportTools::printHeading( stream, "End Part" ); + + if ( !stream.good() ) return { false, "Failed to write part " + partName + " to fault reactivation INP." }; } return { true, "" };