diff --git a/ApplicationLibCode/Application/Tools/RiaProjectFileTools.cpp b/ApplicationLibCode/Application/Tools/RiaProjectFileTools.cpp index 962d8b1ba9..dff3d4e86e 100644 --- a/ApplicationLibCode/Application/Tools/RiaProjectFileTools.cpp +++ b/ApplicationLibCode/Application/Tools/RiaProjectFileTools.cpp @@ -17,89 +17,28 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaProjectFileTools.h" +#include "Tools/RiaVariableMapper.h" + +#include "RimCase.h" +#include "RimCaseDisplayNameTools.h" +#include "RimProject.h" +#include "RimSummaryCase.h" #include -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RiaProjectFileTools::isCandidateVersionNewerThanOther( const QString& candidateProjectFileVersion, const QString& projectFileVersion ) +namespace internal { - int candidateMajorVersion = 0; - int candidateMinorVersion = 0; - int candidatePatchNumber = -1; - int candidateDevelopmentId = -1; - - RiaProjectFileTools::decodeVersionString( candidateProjectFileVersion, - &candidateMajorVersion, - &candidateMinorVersion, - &candidatePatchNumber, - &candidateDevelopmentId ); - - int majorVersion = 0; - int minorVersion = 0; - int patchNumber = -1; - int developmentId = -1; - - RiaProjectFileTools::decodeVersionString( projectFileVersion, &majorVersion, &minorVersion, &patchNumber, &developmentId ); - - return RiaProjectFileTools::isCandidateNewerThanOther( candidateMajorVersion, - candidateMinorVersion, - candidatePatchNumber, - candidateDevelopmentId, - majorVersion, - minorVersion, - patchNumber, - developmentId ); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiaProjectFileTools::decodeVersionString( const QString& projectFileVersion, int* majorVersion, int* minorVersion, int* patch, int* developmentId ) -{ - if ( projectFileVersion.isEmpty() ) return; - - QStringList subStrings = projectFileVersion.split( "." ); - - if ( !subStrings.empty() ) - { - *majorVersion = subStrings[0].toInt(); - } - - if ( subStrings.size() > 1 ) - { - *minorVersion = subStrings[1].toInt(); - } - - if ( subStrings.size() > 2 ) - { - QString candidate = subStrings[2]; - QString candidateDigitsOnly = RiaProjectFileTools::stringOfDigits( candidate ); - - *patch = candidateDigitsOnly.toInt(); - } - - if ( subStrings.size() > 3 ) - { - QString candidate = subStrings.back(); - QString candidateDigitsOnly = RiaProjectFileTools::stringOfDigits( candidate ); - - *developmentId = candidateDigitsOnly.toInt(); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RiaProjectFileTools::isCandidateNewerThanOther( int candidateMajorVersion, - int candidateMinorVersion, - int candidatePatchNumber, - int candidateDevelopmentId, - int otherMajorVersion, - int otherMinorVersion, - int otherPatchNumber, - int otherDevelopmentId ) +bool isCandidateNewerThanOther( int candidateMajorVersion, + int candidateMinorVersion, + int candidatePatchNumber, + int candidateDevelopmentId, + int otherMajorVersion, + int otherMinorVersion, + int otherPatchNumber, + int otherDevelopmentId ) { if ( candidateMajorVersion != otherMajorVersion ) { @@ -133,7 +72,7 @@ bool RiaProjectFileTools::isCandidateNewerThanOther( int candidateMajorVersion, //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RiaProjectFileTools::stringOfDigits( const QString& string ) +QString stringOfDigits( const QString& string ) { QString digitsOnly; @@ -154,3 +93,220 @@ QString RiaProjectFileTools::stringOfDigits( const QString& string ) return digitsOnly; } + +} // namespace internal + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiaProjectFileTools::isCandidateVersionNewerThanOther( const QString& candidateProjectFileVersion, const QString& projectFileVersion ) +{ + int candidateMajorVersion = 0; + int candidateMinorVersion = 0; + int candidatePatchNumber = -1; + int candidateDevelopmentId = -1; + + RiaProjectFileTools::decodeVersionString( candidateProjectFileVersion, + &candidateMajorVersion, + &candidateMinorVersion, + &candidatePatchNumber, + &candidateDevelopmentId ); + + int majorVersion = 0; + int minorVersion = 0; + int patchNumber = -1; + int developmentId = -1; + + RiaProjectFileTools::decodeVersionString( projectFileVersion, &majorVersion, &minorVersion, &patchNumber, &developmentId ); + + return internal::isCandidateNewerThanOther( candidateMajorVersion, + candidateMinorVersion, + candidatePatchNumber, + candidateDevelopmentId, + majorVersion, + minorVersion, + patchNumber, + developmentId ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiaProjectFileTools::transferPathsToGlobalPathList( RimProject* project ) +{ + RiaVariableMapper variableMapper( "" ); + + for ( caf::FilePath* filePath : project->allFilePaths() ) + { + QString path = filePath->path(); + if ( !path.isEmpty() ) + { + QString pathId = variableMapper.addPathAndGetId( path ); + filePath->setPath( pathId ); + } + } + + for ( auto summaryCase : project->allSummaryCases() ) + { + if ( summaryCase->displayNameType() == RimCaseDisplayNameTools::DisplayName::CUSTOM ) + { + // At this point, after the replace of variables into caf::FilePath objects, the variable name is + // stored in the summary case object. Read out the variable name and append "_name" for custom + // summary variables. + + QString variableName = summaryCase->summaryHeaderFilename(); + variableName = variableName.remove( RiaVariableMapper::variableToken() ); + + variableName = RiaVariableMapper::variableToken() + variableName + RiaVariableMapper::postfixName() + + RiaVariableMapper::variableToken(); + + QString variableValue = summaryCase->displayCaseName(); + variableMapper.addVariable( variableName, variableValue ); + + summaryCase->setCustomCaseName( variableName ); + } + } + + for ( auto gridCase : project->allGridCases() ) + { + if ( gridCase->displayNameType() == RimCaseDisplayNameTools::DisplayName::CUSTOM ) + { + // At this point, after the replace of variables into caf::FilePath objects, the variable name is + // stored in the summary case object. Read out the variable name and append "_name" for custom + // summary variables. + + QString variableName = gridCase->gridFileName(); + variableName = variableName.remove( RiaVariableMapper::variableToken() ); + + variableName = RiaVariableMapper::variableToken() + variableName + RiaVariableMapper::postfixName() + + RiaVariableMapper::variableToken(); + + QString variableValue = gridCase->caseUserDescription(); + variableMapper.addVariable( variableName, variableValue ); + + gridCase->setCustomCaseName( variableName ); + } + } + + variableMapper.replaceVariablesInValues(); + + return variableMapper.variableTableAsText(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaProjectFileTools::distributePathsFromGlobalPathList( RimProject* project, const QString& pathList ) +{ + if ( !project ) return; + + RiaVariableMapper pathListMapper( pathList ); + + for ( auto filePath : project->allFilePaths() ) + { + filePath->setPath( updatedFilePathFromPathId( filePath->path(), &pathListMapper ) ); + } + + for ( auto summaryCase : project->allSummaryCases() ) + { + if ( summaryCase->displayNameType() == RimCaseDisplayNameTools::DisplayName::CUSTOM ) + { + auto variableName = summaryCase->displayCaseName(); + + bool isFound = false; + QString variableValue = pathListMapper.valueForVariable( variableName, &isFound ); + if ( isFound ) + { + summaryCase->setCustomCaseName( variableValue ); + } + else if ( variableName.contains( RiaVariableMapper::postfixName() + RiaVariableMapper::variableToken() ) ) + { + // The variable name is not found in the variable list, but the name indicates a variable. Reset + // to full case name. + summaryCase->setDisplayNameOption( RimCaseDisplayNameTools::DisplayName::FULL_CASE_NAME ); + } + } + } + + for ( auto gridCase : project->allGridCases() ) + { + if ( gridCase->displayNameType() == RimCaseDisplayNameTools::DisplayName::CUSTOM ) + { + auto variableName = gridCase->caseUserDescription(); + + bool isFound = false; + QString variableValue = pathListMapper.valueForVariable( variableName, &isFound ); + if ( isFound ) + { + gridCase->setCustomCaseName( variableValue ); + } + else if ( variableName.contains( RiaVariableMapper::postfixName() + RiaVariableMapper::variableToken() ) ) + { + // The variable name is not found in the variable list, but the name indicates a variable. Reset + // to full case name. + gridCase->setDisplayNameType( RimCaseDisplayNameTools::DisplayName::FULL_CASE_NAME ); + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiaProjectFileTools::updatedFilePathFromPathId( QString filePath, RiaVariableMapper* pathListMapper ) +{ + if ( pathListMapper ) + { + QString pathIdCandidate = filePath.trimmed(); + QStringList pathIdComponents = pathIdCandidate.split( RiaVariableMapper::variableToken() ); + + if ( pathIdComponents.size() == 3 && pathIdComponents[0].size() == 0 && pathIdComponents[1].size() > 0 && + pathIdComponents[2].size() == 0 ) + { + bool isFound = false; + QString path = pathListMapper->valueForVariable( pathIdCandidate, &isFound ); + if ( isFound ) + { + return path; + } + } + } + + return filePath; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaProjectFileTools::decodeVersionString( const QString& projectFileVersion, int* majorVersion, int* minorVersion, int* patch, int* developmentId ) +{ + if ( projectFileVersion.isEmpty() ) return; + + QStringList subStrings = projectFileVersion.split( "." ); + + if ( !subStrings.empty() ) + { + *majorVersion = subStrings[0].toInt(); + } + + if ( subStrings.size() > 1 ) + { + *minorVersion = subStrings[1].toInt(); + } + + if ( subStrings.size() > 2 ) + { + QString candidate = subStrings[2]; + QString candidateDigitsOnly = internal::stringOfDigits( candidate ); + + *patch = candidateDigitsOnly.toInt(); + } + + if ( subStrings.size() > 3 ) + { + QString candidate = subStrings.back(); + QString candidateDigitsOnly = internal::stringOfDigits( candidate ); + + *developmentId = candidateDigitsOnly.toInt(); + } +} diff --git a/ApplicationLibCode/Application/Tools/RiaProjectFileTools.h b/ApplicationLibCode/Application/Tools/RiaProjectFileTools.h index c38b9f2203..4c7b1ed1da 100644 --- a/ApplicationLibCode/Application/Tools/RiaProjectFileTools.h +++ b/ApplicationLibCode/Application/Tools/RiaProjectFileTools.h @@ -26,65 +26,59 @@ #include +class RiaVariableMapper; +class RimProject; + //================================================================================================== // //================================================================================================== -class RiaProjectFileTools +namespace RiaProjectFileTools { -public: - static bool isCandidateVersionNewerThanOther( const QString& candidateProjectFileVersion, const QString& otherProjectFileVersion ); +bool isCandidateVersionNewerThanOther( const QString& candidateProjectFileVersion, const QString& otherProjectFileVersion ); - // Public to be able to unit test function, not intended to be used - static void decodeVersionString( const QString& projectFileVersion, int* majorVersion, int* minorVersion, int* patch, int* developmentId ); +template +std::vector writableFieldContent( const caf::PdmObjectHandle* object ) +{ + if ( !object ) return {}; - template - static std::vector writableFieldContent( const caf::PdmObjectHandle* object ) + std::vector fieldContents; + + std::vector children; + for ( const auto& field : object->fields() ) { - if ( !object ) return {}; + if ( !field ) continue; - std::vector fieldContents; + if ( field->xmlCapability() && !field->xmlCapability()->isIOWritable() ) continue; - std::vector children; - for ( const auto& field : object->fields() ) + caf::PdmField* typedField = dynamic_cast*>( field ); + if ( typedField ) fieldContents.push_back( &typedField->v() ); + + caf::PdmField>* typedFieldInVector = dynamic_cast>*>( field ); + if ( typedFieldInVector ) { - if ( !field ) continue; - - if ( field->xmlCapability() && !field->xmlCapability()->isIOWritable() ) continue; - - caf::PdmField* typedField = dynamic_cast*>( field ); - if ( typedField ) fieldContents.push_back( &typedField->v() ); - - caf::PdmField>* typedFieldInVector = dynamic_cast>*>( field ); - if ( typedFieldInVector ) + for ( T& typedFieldFromVector : typedFieldInVector->v() ) { - for ( T& typedFieldFromVector : typedFieldInVector->v() ) - { - fieldContents.push_back( &typedFieldFromVector ); - } + fieldContents.push_back( &typedFieldFromVector ); } - - auto other = field->children(); - children.insert( children.end(), other.begin(), other.end() ); } - for ( const auto& child : children ) - { - auto childObjects = writableFieldContent( child ); - fieldContents.insert( fieldContents.end(), childObjects.begin(), childObjects.end() ); - } - - return fieldContents; + auto other = field->children(); + children.insert( children.end(), other.begin(), other.end() ); } -private: - static bool isCandidateNewerThanOther( int candidateMajorVersion, - int candidateMinorVersion, - int candidatePatchNumber, - int candidateDevelopmentId, - int otherMajorVersion, - int otherMinorVersion, - int otherPatchNumber, - int otherDevelopmentId ); + for ( const auto& child : children ) + { + auto childObjects = writableFieldContent( child ); + fieldContents.insert( fieldContents.end(), childObjects.begin(), childObjects.end() ); + } - static QString stringOfDigits( const QString& string ); -}; + return fieldContents; +} + +QString transferPathsToGlobalPathList( RimProject* project ); +void distributePathsFromGlobalPathList( RimProject* project, const QString& pathList ); +QString updatedFilePathFromPathId( QString filePath, RiaVariableMapper* pathListMapper ); + +// Public to be able to unit test function +void decodeVersionString( const QString& projectFileVersion, int* majorVersion, int* minorVersion, int* patch, int* developmentId ); +}; // namespace RiaProjectFileTools diff --git a/ApplicationLibCode/Commands/RicImportEnsembleFeature.cpp b/ApplicationLibCode/Commands/RicImportEnsembleFeature.cpp index 9e70097e70..302ea04c71 100644 --- a/ApplicationLibCode/Commands/RicImportEnsembleFeature.cpp +++ b/ApplicationLibCode/Commands/RicImportEnsembleFeature.cpp @@ -120,6 +120,8 @@ void RicImportEnsembleFeature::onActionTriggered( bool isChecked ) RiaSummaryTools::summaryCaseMainCollection()->updateConnectedEditors(); } } + + RiuPlotMainWindowTools::showPlotMainWindow(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp index 84e0a4971a..af1422b1fa 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp @@ -76,6 +76,9 @@ void RicReplaceSummaryEnsembleFeature::onActionTriggered( bool isChecked ) collection->updateFileSetNames(); collection->updateAllRequiredEditors(); + + RiaLogging::info( QString( "Completed replace ensemble, new name is '" ) + summaryEnsemble->name() + "'" ); + return; } diff --git a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp index 922ced8625..2422500197 100644 --- a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp +++ b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp @@ -540,12 +540,6 @@ void RifEclipseInputFileTools::saveFault( QTextStream& RiaLogging::error( QString( "Fault name '%1' contains spaces" ).arg( faultName ) ); return; } - else if ( faultName.length() > 8 ) - { - // Keep going anyway, eclipse files sometimes have longer than - // the specified 8 characters in the name without Eclipse complaining - RiaLogging::warning( QString( "Fault name '%1' is longer than 8 characters" ).arg( faultName ) ); - } std::vector faultCellAndFaces; @@ -1633,12 +1627,6 @@ void RifEclipseInputFileTools::readFaults( QFile& data, qint64 filePos, cvf::Col errorMessages.insert( QString( "Fault name '%1' contains spaces" ).arg( faultName ) ); continue; } - else if ( faultName.length() > 8 ) - { - // Keep going anyway, eclipse files sometimes have longer than - // the specified 8 characters in the name without Eclipse complaining - warningMessages.insert( QString( "Fault name '%1' is longer than 8 characters" ).arg( faultName ) ); - } int i1, i2, j1, j2, k1, k2; i1 = entries[1].toInt(); diff --git a/ApplicationLibCode/FileInterface/RifReaderFmuRft.cpp b/ApplicationLibCode/FileInterface/RifReaderFmuRft.cpp index 65a969077b..9107b36112 100644 --- a/ApplicationLibCode/FileInterface/RifReaderFmuRft.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderFmuRft.cpp @@ -259,13 +259,15 @@ void RifReaderFmuRft::importData() }; // The text file name can be either _.txt or .txt - QString txtFile = findFileName( wellName, "txt", measurementId, dir ); - auto locations = importLocations( dir.absoluteFilePath( txtFile ) ); + QString txtFile = findFileName( wellName, "txt", measurementId, dir ); + if ( !QFile::exists( txtFile ) ) continue; + + auto locations = importLocations( dir.absoluteFilePath( txtFile ) ); if ( locations.empty() ) continue; // The observation file name can be either _.obs or .obs QString observationFileName = findFileName( wellName, "obs", measurementId, dir ); - if ( observationFileName.isEmpty() ) continue; + if ( !QFile::exists( observationFileName ) ) continue; for ( const auto& wellDate : wellDates ) { diff --git a/ApplicationLibCode/ProjectDataModel/RimObservedFmuRftData.cpp b/ApplicationLibCode/ProjectDataModel/RimObservedFmuRftData.cpp index d317d099a6..a66fd906ff 100644 --- a/ApplicationLibCode/ProjectDataModel/RimObservedFmuRftData.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimObservedFmuRftData.cpp @@ -30,9 +30,14 @@ CAF_PDM_SOURCE_INIT( RimObservedFmuRftData, "ObservedFmuRftData" ); RimObservedFmuRftData::RimObservedFmuRftData() { CAF_PDM_InitObject( "Observed FMU Data", ":/ObservedRFTDataFile16x16.png" ); - CAF_PDM_InitFieldNoDefault( &m_directoryPath, "Directory", "Directory" ); + + CAF_PDM_InitFieldNoDefault( &m_directoryPath, "ObservedFolder", "Directory" ); m_directoryPath.uiCapability()->setUiReadOnly( true ); + CAF_PDM_InitFieldNoDefault( &m_directoryPath_OBSOLETE, "Directory", "Directory" ); + m_directoryPath_OBSOLETE.uiCapability()->setUiReadOnly( true ); + m_directoryPath_OBSOLETE.xmlCapability()->setIOWritable( false ); + CAF_PDM_InitFieldNoDefault( &m_wells, "Wells", "Wells" ); m_wells.xmlCapability()->disableIO(); m_wells.uiCapability()->setUiReadOnly( true ); @@ -52,7 +57,7 @@ void RimObservedFmuRftData::setDirectoryPath( const QString& path ) //-------------------------------------------------------------------------------------------------- void RimObservedFmuRftData::createRftReaderInterface() { - m_fmuRftReader = new RifReaderFmuRft( m_directoryPath ); + m_fmuRftReader = new RifReaderFmuRft( m_directoryPath().path() ); m_fmuRftReader->importData(); } @@ -109,3 +114,14 @@ std::vector RimObservedFmuRftData::labels( const RifEclipseRftAddress& } return {}; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimObservedFmuRftData::initAfterRead() +{ + if ( m_directoryPath().path().isEmpty() ) + { + m_directoryPath = m_directoryPath_OBSOLETE(); + } +} diff --git a/ApplicationLibCode/ProjectDataModel/RimObservedFmuRftData.h b/ApplicationLibCode/ProjectDataModel/RimObservedFmuRftData.h index 987e31db5b..3704811573 100644 --- a/ApplicationLibCode/ProjectDataModel/RimObservedFmuRftData.h +++ b/ApplicationLibCode/ProjectDataModel/RimObservedFmuRftData.h @@ -40,9 +40,13 @@ public: std::vector wells() const; std::vector labels( const RifEclipseRftAddress& rftAddress ); +protected: + void initAfterRead() override; + private: cvf::ref m_fmuRftReader; - caf::PdmField m_directoryPath; + caf::PdmField m_directoryPath; + caf::PdmField m_directoryPath_OBSOLETE; caf::PdmProxyValueField> m_wells; }; diff --git a/ApplicationLibCode/ProjectDataModel/RimProject.cpp b/ApplicationLibCode/ProjectDataModel/RimProject.cpp index 37e8aeb323..0ee4f28541 100644 --- a/ApplicationLibCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimProject.cpp @@ -27,12 +27,9 @@ #include "RiaPreferences.h" #include "RiaProjectBackupTools.h" #include "RiaProjectFileTools.h" -#include "RiaTextStringTools.h" #include "RiaVersionInfo.h" -#include "RicfCommandObject.h" #include "RigEclipseCaseData.h" -#include "RigGridBase.h" #include "Cloud/RimCloudDataSourceCollection.h" #include "ContourMap/RimEclipseContourMapViewCollection.h" @@ -45,7 +42,6 @@ #include "RimAnalysisPlotCollection.h" #include "RimAnnotationCollection.h" #include "RimAnnotationInViewCollection.h" -#include "RimCalcScript.h" #include "RimCase.h" #include "RimCaseCollection.h" #include "RimColorLegendCollection.h" @@ -85,21 +81,18 @@ #include "RimSeismicView.h" #include "RimSeismicViewCollection.h" #include "RimStimPlanModelPlotCollection.h" -#include "RimSummaryCalculation.h" #include "RimSummaryCalculationCollection.h" +#include "RimSummaryCase.h" #include "RimSummaryCaseMainCollection.h" #include "RimSummaryEnsemble.h" #include "RimSummaryMultiPlotCollection.h" #include "RimSummaryTableCollection.h" #include "RimSurfaceCollection.h" #include "RimTools.h" -#include "RimUserDefinedPolylinesAnnotation.h" #include "RimValveTemplate.h" #include "RimValveTemplateCollection.h" #include "RimViewLinker.h" #include "RimViewLinkerCollection.h" -#include "RimViewWindow.h" -#include "RimWellLogLasFile.h" #include "RimWellLogPlotCollection.h" #include "RimWellPath.h" #include "RimWellPathCollection.h" @@ -108,32 +101,22 @@ #include "VerticalFlowPerformance/RimVfpDataCollection.h" #include "VerticalFlowPerformance/RimVfpPlotCollection.h" -#include "Tools/RiaVariableMapper.h" - #ifdef USE_QTCHARTS -#include "RimEnsembleFractureStatisticsPlot.h" #include "RimEnsembleFractureStatisticsPlotCollection.h" #include "RimGridStatisticsPlot.h" #include "RimGridStatisticsPlotCollection.h" #endif -#include "RiuMainWindow.h" #include "RiuPlotMainWindow.h" -#include "OctaveScriptCommands/RicExecuteScriptForCasesFeature.h" - -#include "cafCmdFeature.h" -#include "cafCmdFeatureManager.h" #include "cafCmdFeatureMenuBuilder.h" +#include "cafPdmObjectScriptingCapability.h" #include "cafPdmUiTreeOrdering.h" -#include "cvfBoundingBox.h" -#include #include -#include +#include #include -#include CAF_PDM_SOURCE_INIT( RimProject, "ResInsightProject" ); //-------------------------------------------------------------------------------------------------- @@ -310,7 +293,7 @@ void RimProject::close() //-------------------------------------------------------------------------------------------------- void RimProject::updatesAfterProjectFileIsRead() { - distributePathsFromGlobalPathList(); + RiaProjectFileTools::distributePathsFromGlobalPathList( this, m_globalPathList() ); // Create an empty oil field in case the project did not contain one if ( oilFields.empty() ) @@ -473,7 +456,7 @@ RimMainPlotCollection* RimProject::mainPlotCollection() const //-------------------------------------------------------------------------------------------------- bool RimProject::writeProjectFile() { - transferPathsToGlobalPathList(); + m_globalPathList = RiaProjectFileTools::transferPathsToGlobalPathList( this ); QFile xmlFile( fileName() ); if ( !xmlFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) return false; @@ -488,7 +471,7 @@ bool RimProject::writeProjectFile() RiaProjectBackupTools::appendTextToDatabase( backupFilename, maximumRecordCount, content ); } - distributePathsFromGlobalPathList(); + RiaProjectFileTools::distributePathsFromGlobalPathList( this, m_globalPathList() ); return true; } @@ -1562,152 +1545,3 @@ void RimProject::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, Q uiTreeOrdering.skipRemainingChildren( true ); } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimProject::transferPathsToGlobalPathList() -{ - RiaVariableMapper variableMapper( m_globalPathList() ); - - for ( caf::FilePath* filePath : allFilePaths() ) - { - QString path = filePath->path(); - if ( !path.isEmpty() ) - { - QString pathId = variableMapper.addPathAndGetId( path ); - filePath->setPath( pathId ); - } - } - - for ( auto summaryCase : allSummaryCases() ) - { - if ( summaryCase->displayNameType() == RimCaseDisplayNameTools::DisplayName::CUSTOM ) - { - // At this point, after the replace of variables into caf::FilePath objects, the variable name is - // stored in the summary case object. Read out the variable name and append "_name" for custom - // summary variables. - - QString variableName = summaryCase->summaryHeaderFilename(); - variableName = variableName.remove( RiaVariableMapper::variableToken() ); - - variableName = RiaVariableMapper::variableToken() + variableName + RiaVariableMapper::postfixName() + - RiaVariableMapper::variableToken(); - - QString variableValue = summaryCase->displayCaseName(); - variableMapper.addVariable( variableName, variableValue ); - - summaryCase->setCustomCaseName( variableName ); - } - } - - for ( auto gridCase : allGridCases() ) - { - if ( gridCase->displayNameType() == RimCaseDisplayNameTools::DisplayName::CUSTOM ) - { - // At this point, after the replace of variables into caf::FilePath objects, the variable name is - // stored in the summary case object. Read out the variable name and append "_name" for custom - // summary variables. - - QString variableName = gridCase->gridFileName(); - variableName = variableName.remove( RiaVariableMapper::variableToken() ); - - variableName = RiaVariableMapper::variableToken() + variableName + RiaVariableMapper::postfixName() + - RiaVariableMapper::variableToken(); - - QString variableValue = gridCase->caseUserDescription(); - variableMapper.addVariable( variableName, variableValue ); - - gridCase->setCustomCaseName( variableName ); - } - } - - variableMapper.replaceVariablesInValues(); - - m_globalPathList = variableMapper.variableTableAsText(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString RimProject::updatedFilePathFromPathId( QString filePath, RiaVariableMapper* pathListMapper /*=nullptr*/ ) const -{ - std::unique_ptr internalMapper; - - if ( pathListMapper == nullptr ) - { - internalMapper = std::make_unique( m_globalPathList ); - pathListMapper = internalMapper.get(); - } - - QString returnValue = filePath; - QString pathIdCandidate = filePath.trimmed(); - QStringList pathIdComponents = pathIdCandidate.split( RiaVariableMapper::variableToken() ); - - if ( pathIdComponents.size() == 3 && pathIdComponents[0].size() == 0 && pathIdComponents[1].size() > 0 && pathIdComponents[2].size() == 0 ) - { - bool isFound = false; - QString path = pathListMapper->valueForVariable( pathIdCandidate, &isFound ); - if ( isFound ) - { - returnValue = path; - } - } - - return returnValue; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimProject::distributePathsFromGlobalPathList() -{ - RiaVariableMapper pathListMapper( m_globalPathList() ); - - for ( caf::FilePath* filePath : allFilePaths() ) - { - filePath->setPath( updatedFilePathFromPathId( filePath->path(), &pathListMapper ) ); - } - - for ( auto summaryCase : allSummaryCases() ) - { - if ( summaryCase->displayNameType() == RimCaseDisplayNameTools::DisplayName::CUSTOM ) - { - auto variableName = summaryCase->displayCaseName(); - - bool isFound = false; - QString variableValue = pathListMapper.valueForVariable( variableName, &isFound ); - if ( isFound ) - { - summaryCase->setCustomCaseName( variableValue ); - } - else if ( variableName.contains( RiaVariableMapper::postfixName() + RiaVariableMapper::variableToken() ) ) - { - // The variable name is not found in the variable list, but the name indicates a variable. Reset - // to full case name. - summaryCase->setDisplayNameOption( RimCaseDisplayNameTools::DisplayName::FULL_CASE_NAME ); - } - } - } - - for ( auto gridCase : allGridCases() ) - { - if ( gridCase->displayNameType() == RimCaseDisplayNameTools::DisplayName::CUSTOM ) - { - auto variableName = gridCase->caseUserDescription(); - - bool isFound = false; - QString variableValue = pathListMapper.valueForVariable( variableName, &isFound ); - if ( isFound ) - { - gridCase->setCustomCaseName( variableValue ); - } - else if ( variableName.contains( RiaVariableMapper::postfixName() + RiaVariableMapper::variableToken() ) ) - { - // The variable name is not found in the variable list, but the name indicates a variable. Reset - // to full case name. - gridCase->setDisplayNameType( RimCaseDisplayNameTools::DisplayName::FULL_CASE_NAME ); - } - } - } -} diff --git a/ApplicationLibCode/ProjectDataModel/RimProject.h b/ApplicationLibCode/ProjectDataModel/RimProject.h index bd4a314c8f..09575b8b12 100644 --- a/ApplicationLibCode/ProjectDataModel/RimProject.h +++ b/ApplicationLibCode/ProjectDataModel/RimProject.h @@ -30,8 +30,6 @@ #include -class RiaVariableMapper; - class RigEclipseCaseData; class RigGridManager; class RigMainGrid; @@ -204,11 +202,6 @@ protected: void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override; -private: - void transferPathsToGlobalPathList(); - void distributePathsFromGlobalPathList(); - QString updatedFilePathFromPathId( QString filePath, RiaVariableMapper* pathListMapper = nullptr ) const; - private: caf::PdmChildField m_mainPlotCollection; caf::PdmChildField m_pinnedFieldCollection;