Skip to content

Commit

Permalink
Fault reactivation export: improve error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Sep 27, 2023
1 parent 1b1984e commit 74a656f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <QAction>
#include <QFile>
#include <QMessageBox>
#include <QString>

CAF_CMD_SOURCE_INIT( RicExportInpFileFeature, "RicExportInpFileFeature" );
Expand All @@ -47,8 +48,16 @@ void RicExportInpFileFeature::onActionTriggered( bool isChecked )
auto faultReactivationModel = caf::SelectionManager::instance()->selectedItemOfType<RimFaultReactivationModel>();
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 );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,25 @@ std::pair<bool, std::string> 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<std::function<std::pair<bool, std::string>()>> 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, "" };
}

Expand Down Expand Up @@ -184,6 +192,8 @@ std::pair<bool, std::string> 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, "" };
Expand Down

0 comments on commit 74a656f

Please sign in to comment.