From 5ba506584847956a5a037858be0e52160b0142ce Mon Sep 17 00:00:00 2001 From: jonjenssen Date: Wed, 3 Jan 2024 00:59:09 +0100 Subject: [PATCH] Work in progress --- .../RicExportInpFileFeature.cpp | 9 ++-- .../RifFaultReactivationModelExporter.cpp | 2 +- .../Faults/RimFaultReactivationModel.cpp | 51 ++++++++++++++----- .../Faults/RimFaultReactivationModel.h | 11 ++-- 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp b/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp index 962938992d..c5aa024bc4 100644 --- a/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp +++ b/ApplicationLibCode/Commands/ExportCommands/RicExportInpFileFeature.cpp @@ -48,13 +48,14 @@ void RicExportInpFileFeature::onActionTriggered( bool isChecked ) auto faultReactivationModel = caf::SelectionManager::instance()->selectedItemOfType(); if ( faultReactivationModel ) { - QString exportFile = faultReactivationModel->baseDir() + "/faultreactivation.inp"; - auto [isOk, errorMessage] = RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *faultReactivationModel ); + std::string exportFile = faultReactivationModel->inputFilename(); + auto [isOk, errorMessage] = RifFaultReactivationModelExporter::exportToFile( exportFile, *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 ) ); + QString outErrorText = QString( "Failed to export INP model to file %1.\n\n%2" ) + .arg( QString::fromStdString( exportFile ) ) + .arg( QString::fromStdString( errorMessage ) ); QMessageBox::critical( nullptr, frmTitle, outErrorText ); } } diff --git a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp index 5e4ee7a474..7a190cf378 100644 --- a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp +++ b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp @@ -838,7 +838,7 @@ bool RifFaultReactivationModelExporter::exportModelSettings( const RimFaultReact faultNormal = faultNormal ^ cvf::Vec3d::Z_AXIS; RimFaultReactivationTools::addSettingsToMap( settings, faultNormal, topPosition, bottomPosition ); - return ResInsightInternalJson::JsonWriter::encodeFile( rimModel.settingsFilename(), settings ); + return ResInsightInternalJson::JsonWriter::encodeFile( QString::fromStdString( rimModel.settingsFilename() ), settings ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp index aa43dcffdd..0832e529f4 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.cpp @@ -625,8 +625,8 @@ QStringList RimFaultReactivationModel::commandParameters() const QStringList retlist; retlist << baseDir(); - retlist << inputFilename(); - retlist << outputOdbFilename(); + retlist << QString::fromStdString( inputFilename() ); + retlist << QString::fromStdString( outputOdbFilename() ); return retlist; } @@ -634,45 +634,72 @@ QStringList RimFaultReactivationModel::commandParameters() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RimFaultReactivationModel::outputOdbFilename() const +std::string RimFaultReactivationModel::outputOdbFilename() const { QDir directory( baseDir() ); - return directory.absoluteFilePath( baseFilename() + ".odb" ); + return directory.absoluteFilePath( QString::fromStdString( baseFilename() + ".odb" ) ).toStdString(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RimFaultReactivationModel::inputFilename() const +std::string RimFaultReactivationModel::inputFilename() const { QDir directory( baseDir() ); - return directory.absoluteFilePath( baseFilename() + ".inp" ); + return directory.absoluteFilePath( QString::fromStdString( baseFilename() + ".inp" ) ).toStdString(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RimFaultReactivationModel::settingsFilename() const +std::string RimFaultReactivationModel::includeFilename( const std::string propertyName, const std::string timeStep ) const +{ + QDir directory( baseDir() ); + std::string name = baseFilename(); + if ( !propertyName.empty() ) + { + name += "_" + cleanUpName( propertyName ); + } + if ( !timeStep.empty() ) + { + name += "_" + cleanUpName( timeStep ); + } + + return directory.absoluteFilePath( QString::fromStdString( name + ".inp" ) ).toStdString(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::string RimFaultReactivationModel::settingsFilename() const { QDir directory( baseDir() ); - return directory.absoluteFilePath( baseFilename() + ".settings.json" ); + return directory.absoluteFilePath( QString::fromStdString( baseFilename() + ".settings.json" ) ).toStdString(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RimFaultReactivationModel::baseFilename() const +std::string RimFaultReactivationModel::cleanUpName( const std::string candidate ) { - QString tmp = m_userDescription(); + QString tmp = QString::fromStdString( candidate ); - if ( tmp.isEmpty() ) return "faultReactivation"; + if ( tmp.isEmpty() ) return "unknown"; tmp.replace( ' ', '_' ); tmp.replace( '/', '_' ); tmp.replace( '\\', '_' ); tmp.replace( ':', '_' ); - return tmp; + return tmp.toStdString(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::string RimFaultReactivationModel::baseFilename() const +{ + return cleanUpName( m_userDescription().toStdString() ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h index b7fc93c0ef..6b53cf7ba5 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationModel.h @@ -110,9 +110,10 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly QStringList commandParameters() const; - QString outputOdbFilename() const; - QString inputFilename() const; - QString settingsFilename() const; + std::string outputOdbFilename() const; + std::string inputFilename() const; + std::string includeFilename( const std::string propertyName, const std::string timeStep = "" ) const; + std::string settingsFilename() const; void updateTimeSteps(); @@ -137,7 +138,9 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; - QString baseFilename() const; + std::string baseFilename() const; + + static std::string cleanUpName( const std::string candidate ); private: std::shared_ptr m_pickTargetsEventHandler;