2012-05-18 02:45:23 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-05-06 03:55:00 -05:00
|
|
|
//#include "RiaStdInclude.h"
|
|
|
|
#include "RimCase.h"
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
2013-10-07 04:45:54 -05:00
|
|
|
#include <QDebug>
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
#include "RifReaderEclipseOutput.h"
|
2012-08-31 12:12:47 -05:00
|
|
|
#include "RifReaderMockModel.h"
|
|
|
|
|
|
|
|
#include "RimReservoirView.h"
|
2013-05-06 03:55:00 -05:00
|
|
|
#include "cafPdmFieldCvfMat4d.h"
|
|
|
|
#include "cafPdmFieldCvfColor.h"
|
|
|
|
#include "RimCellRangeFilter.h"
|
|
|
|
#include "RimCellRangeFilterCollection.h"
|
|
|
|
#include "RimCellPropertyFilter.h"
|
|
|
|
#include "RimCellPropertyFilterCollection.h"
|
|
|
|
#include "Rim3dOverlayInfoConfig.h"
|
|
|
|
#include "RimIdenticalGridCaseGroup.h"
|
|
|
|
#include "RimWellCollection.h"
|
2013-05-16 07:02:59 -05:00
|
|
|
#include "RimWellPathCollection.h"
|
2013-05-06 03:55:00 -05:00
|
|
|
|
|
|
|
#include "RimScriptCollection.h"
|
2012-08-31 12:12:47 -05:00
|
|
|
|
2013-03-22 10:58:44 -05:00
|
|
|
#include "RigCaseData.h"
|
2012-05-18 02:45:23 -05:00
|
|
|
#include "RigMainGrid.h"
|
2013-03-22 10:58:44 -05:00
|
|
|
#include "RigCaseCellResultsData.h"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
#include "cvfAssert.h"
|
|
|
|
|
2013-05-06 03:55:00 -05:00
|
|
|
#include "cafPdmFieldCvfColor.h"
|
|
|
|
|
2012-08-31 12:12:47 -05:00
|
|
|
#include "cafPdmUiPushButtonEditor.h"
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
#include <QString>
|
2013-02-14 06:16:56 -06:00
|
|
|
#include "RimProject.h"
|
2013-03-18 08:34:29 -05:00
|
|
|
#include "RimReservoirCellResultsCacher.h"
|
2013-05-06 03:55:00 -05:00
|
|
|
#include "RimResultSlot.h"
|
|
|
|
#include "RimCellPropertyFilterCollection.h"
|
|
|
|
#include "RimCellEdgeResultSlot.h"
|
|
|
|
#include "RimCaseCollection.h"
|
2013-06-06 08:02:35 -05:00
|
|
|
#include "RimOilField.h"
|
|
|
|
#include "RimAnalysisModels.h"
|
2013-12-16 08:57:15 -06:00
|
|
|
#include "cafProgressInfo.h"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-22 09:43:42 -05:00
|
|
|
CAF_PDM_SOURCE_INIT(RimCase, "RimReservoir");
|
2013-03-18 05:40:39 -05:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2012-05-18 02:45:23 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
RimCase::RimCase()
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2013-04-11 05:06:38 -05:00
|
|
|
CAF_PDM_InitField(&caseUserDescription, "CaseUserDescription", QString(), "Case name", "", "" ,"");
|
2013-05-08 03:41:56 -05:00
|
|
|
|
|
|
|
CAF_PDM_InitField(&caseId, "CaseId", -1, "Case ID", "", "" ,"");
|
|
|
|
caseId.setUiReadOnly(true);
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
CAF_PDM_InitFieldNoDefault(&reservoirViews, "ReservoirViews", "", "", "", "");
|
2013-03-18 08:34:29 -05:00
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_matrixModelResults, "MatrixModelResults", "", "", "", "");
|
2013-03-19 04:29:34 -05:00
|
|
|
m_matrixModelResults.setUiHidden(true);
|
2013-03-18 08:34:29 -05:00
|
|
|
CAF_PDM_InitFieldNoDefault(&m_fractureModelResults, "FractureModelResults", "", "", "", "");
|
2013-03-19 04:29:34 -05:00
|
|
|
m_fractureModelResults.setUiHidden(true);
|
2013-03-18 08:34:29 -05:00
|
|
|
|
2013-04-26 06:19:34 -05:00
|
|
|
CAF_PDM_InitField(&flipXAxis, "FlipXAxis", false, "Flip X Axis", "", "", "");
|
|
|
|
CAF_PDM_InitField(&flipYAxis, "FlipYAxis", false, "Flip Y Axis", "", "", "");
|
|
|
|
|
|
|
|
|
2013-04-11 05:06:38 -05:00
|
|
|
// Obsolete field
|
|
|
|
CAF_PDM_InitField(&caseName, "CaseName", QString(), "Obsolete", "", "" ,"");
|
|
|
|
caseName.setIOWritable(false);
|
|
|
|
caseName.setUiHidden(true);
|
|
|
|
|
2013-03-19 04:29:34 -05:00
|
|
|
m_matrixModelResults = new RimReservoirCellResultsStorage;
|
|
|
|
m_fractureModelResults = new RimReservoirCellResultsStorage;
|
2013-03-18 08:34:29 -05:00
|
|
|
|
|
|
|
this->setReservoirData( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
RimCase::~RimCase()
|
2013-03-18 08:34:29 -05:00
|
|
|
{
|
|
|
|
reservoirViews.deleteAllChildObjects();
|
|
|
|
|
|
|
|
delete m_matrixModelResults();
|
|
|
|
delete m_fractureModelResults();
|
|
|
|
|
|
|
|
if (this->reservoirData())
|
|
|
|
{
|
|
|
|
// At this point, we assume that memory should be released
|
|
|
|
CVF_ASSERT(this->reservoirData()->refCount() == 1);
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
RigCaseData* RimCase::reservoirData()
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2013-02-14 03:19:27 -06:00
|
|
|
return m_rigEclipseCase.p();
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
const RigCaseData* RimCase::reservoirData() const
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2013-02-14 03:19:27 -06:00
|
|
|
return m_rigEclipseCase.p();
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
2013-04-08 05:16:38 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimCase::initAfterRead()
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
size_t j;
|
|
|
|
for (j = 0; j < reservoirViews().size(); j++)
|
|
|
|
{
|
|
|
|
RimReservoirView* riv = reservoirViews()[j];
|
|
|
|
CVF_ASSERT(riv);
|
|
|
|
|
|
|
|
riv->setEclipseCase(this);
|
|
|
|
}
|
2013-04-11 05:06:38 -05:00
|
|
|
|
|
|
|
if (caseUserDescription().isEmpty() && !caseName().isEmpty())
|
|
|
|
{
|
|
|
|
caseUserDescription = caseName;
|
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
RimReservoirView* RimCase::createAndAddReservoirView()
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
RimReservoirView* riv = new RimReservoirView();
|
|
|
|
riv->setEclipseCase(this);
|
|
|
|
|
|
|
|
size_t i = reservoirViews().size();
|
|
|
|
riv->name = QString("View %1").arg(i + 1);
|
|
|
|
|
|
|
|
reservoirViews().push_back(riv);
|
|
|
|
|
|
|
|
return riv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// TODO: Move this functionality to PdmPointersField
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimCase::removeReservoirView(RimReservoirView* reservoirView)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
std::vector<size_t> indices;
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < reservoirViews().size(); i++)
|
|
|
|
{
|
|
|
|
if (reservoirViews()[i] == reservoirView)
|
|
|
|
{
|
|
|
|
indices.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB! Make sure the ordering goes from large to low index
|
|
|
|
while (!indices.empty())
|
|
|
|
{
|
|
|
|
reservoirViews().erase(indices.back());
|
|
|
|
indices.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimCase::removeResult(const QString& resultName)
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < reservoirViews().size(); i++)
|
|
|
|
{
|
|
|
|
RimReservoirView* reservoirView = reservoirViews()[i];
|
|
|
|
CVF_ASSERT(reservoirView);
|
|
|
|
|
|
|
|
RimResultSlot* result = reservoirView->cellResult;
|
|
|
|
CVF_ASSERT(result);
|
|
|
|
|
|
|
|
bool rebuildDisplayModel = false;
|
|
|
|
|
|
|
|
// Set cell result variable to none if displaying
|
|
|
|
if (result->resultVariable() == resultName)
|
|
|
|
{
|
2013-04-30 06:41:53 -05:00
|
|
|
result->setResultVariable(RimDefines::undefinedResultName());
|
2012-06-26 09:10:41 -05:00
|
|
|
result->loadResult();
|
|
|
|
|
|
|
|
rebuildDisplayModel = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list< caf::PdmPointer< RimCellPropertyFilter > >::iterator it;
|
|
|
|
RimCellPropertyFilterCollection* propFilterCollection = reservoirView->propertyFilterCollection();
|
|
|
|
for (it = propFilterCollection->propertyFilters.v().begin(); it != propFilterCollection->propertyFilters.v().end(); ++it)
|
|
|
|
{
|
|
|
|
RimCellPropertyFilter* propertyFilter = *it;
|
2013-04-30 06:41:53 -05:00
|
|
|
if (propertyFilter->resultDefinition->resultVariable() == resultName)
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
2013-04-30 06:41:53 -05:00
|
|
|
propertyFilter->resultDefinition->setResultVariable(RimDefines::undefinedResultName());
|
2012-06-26 09:10:41 -05:00
|
|
|
propertyFilter->resultDefinition->loadResult();
|
|
|
|
propertyFilter->setDefaultValues();
|
|
|
|
|
|
|
|
rebuildDisplayModel = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rebuildDisplayModel)
|
|
|
|
{
|
|
|
|
reservoirViews()[i]->createDisplayModelAndRedraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// CellEdgeResults are not considered, as they do not support display of input properties yet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-31 12:12:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimCase::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
|
2012-08-31 12:12:47 -05:00
|
|
|
{
|
|
|
|
if (changedField == &releaseResultMemory)
|
|
|
|
{
|
2013-03-18 08:34:29 -05:00
|
|
|
if (this->reservoirData())
|
2012-08-31 12:12:47 -05:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < reservoirViews().size(); i++)
|
|
|
|
{
|
|
|
|
RimReservoirView* reservoirView = reservoirViews()[i];
|
|
|
|
CVF_ASSERT(reservoirView);
|
|
|
|
|
|
|
|
RimResultSlot* result = reservoirView->cellResult;
|
|
|
|
CVF_ASSERT(result);
|
|
|
|
|
2013-04-30 06:41:53 -05:00
|
|
|
result->setResultVariable(RimDefines::undefinedResultName());
|
2012-08-31 12:12:47 -05:00
|
|
|
result->loadResult();
|
|
|
|
|
|
|
|
RimCellEdgeResultSlot* cellEdgeResult = reservoirView->cellEdgeResult;
|
|
|
|
CVF_ASSERT(cellEdgeResult);
|
|
|
|
|
|
|
|
cellEdgeResult->resultVariable.v() = RimDefines::undefinedResultName();
|
|
|
|
cellEdgeResult->loadResult();
|
|
|
|
|
|
|
|
reservoirView->createDisplayModelAndRedraw();
|
|
|
|
}
|
|
|
|
|
2013-03-22 09:43:42 -05:00
|
|
|
RigCaseCellResultsData* matrixModelResults = reservoirData()->results(RifReaderInterface::MATRIX_RESULTS);
|
2013-02-01 07:39:32 -06:00
|
|
|
if (matrixModelResults)
|
2012-08-31 12:12:47 -05:00
|
|
|
{
|
2013-02-01 07:39:32 -06:00
|
|
|
matrixModelResults->clearAllResults();
|
|
|
|
}
|
|
|
|
|
2013-03-22 09:43:42 -05:00
|
|
|
RigCaseCellResultsData* fractureModelResults = reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS);
|
2013-02-01 07:39:32 -06:00
|
|
|
if (fractureModelResults)
|
|
|
|
{
|
|
|
|
fractureModelResults->clearAllResults();
|
2012-08-31 12:12:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseResultMemory = oldValue.toBool();
|
|
|
|
}
|
2013-04-26 06:19:34 -05:00
|
|
|
else if (changedField == &flipXAxis || changedField == &flipYAxis)
|
|
|
|
{
|
|
|
|
RigCaseData* rigEclipseCase = reservoirData();
|
|
|
|
if (rigEclipseCase)
|
|
|
|
{
|
|
|
|
rigEclipseCase->mainGrid()->setFlipAxis(flipXAxis, flipYAxis);
|
|
|
|
|
|
|
|
computeCachedData();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < reservoirViews().size(); i++)
|
|
|
|
{
|
|
|
|
RimReservoirView* reservoirView = reservoirViews()[i];
|
|
|
|
|
|
|
|
reservoirView->scheduleReservoirGridGeometryRegen();
|
|
|
|
reservoirView->schedulePipeGeometryRegen();
|
|
|
|
reservoirView->createDisplayModelAndRedraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-31 12:12:47 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 06:16:56 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimCase::computeCachedData()
|
2013-02-14 06:16:56 -06:00
|
|
|
{
|
2013-03-22 09:43:42 -05:00
|
|
|
RigCaseData* rigEclipseCase = reservoirData();
|
2013-02-22 03:12:06 -06:00
|
|
|
if (rigEclipseCase)
|
2013-02-14 06:16:56 -06:00
|
|
|
{
|
2013-12-16 08:57:15 -06:00
|
|
|
caf::ProgressInfo pInf(30, "");
|
|
|
|
pInf.setNextProgressIncrement(1);
|
2013-03-21 09:31:47 -05:00
|
|
|
rigEclipseCase->computeActiveCellBoundingBoxes();
|
2013-12-16 08:57:15 -06:00
|
|
|
pInf.incrementProgress();
|
2013-02-14 06:16:56 -06:00
|
|
|
|
2013-12-16 08:57:15 -06:00
|
|
|
pInf.setNextProgressIncrement(10);
|
2013-02-22 03:12:06 -06:00
|
|
|
rigEclipseCase->mainGrid()->computeCachedData();
|
2013-12-16 08:57:15 -06:00
|
|
|
pInf.incrementProgress();
|
|
|
|
|
|
|
|
pInf.setProgressDescription("Calculating faults");
|
2013-12-12 15:15:14 -06:00
|
|
|
rigEclipseCase->mainGrid()->calculateFaults();
|
2013-12-16 08:57:15 -06:00
|
|
|
pInf.incrementProgress();
|
2013-02-14 06:16:56 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 05:42:26 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
RimCaseCollection* RimCase::parentCaseCollection()
|
2013-03-13 05:42:26 -05:00
|
|
|
{
|
|
|
|
std::vector<RimCaseCollection*> parentObjects;
|
|
|
|
this->parentObjectsOfType(parentObjects);
|
|
|
|
|
|
|
|
if (parentObjects.size() > 0)
|
|
|
|
{
|
|
|
|
return parentObjects[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-08 05:16:38 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimIdenticalGridCaseGroup* RimCase::parentGridCaseGroup()
|
|
|
|
{
|
|
|
|
RimCaseCollection* caseColl = parentCaseCollection();
|
|
|
|
if (caseColl)
|
|
|
|
{
|
|
|
|
return caseColl->parentCaseGroup();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-18 08:34:29 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimCase::setReservoirData(RigCaseData* eclipseCase)
|
2013-03-18 08:34:29 -05:00
|
|
|
{
|
|
|
|
m_rigEclipseCase = eclipseCase;
|
|
|
|
if (this->reservoirData())
|
|
|
|
{
|
|
|
|
m_fractureModelResults()->setCellResults(reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS));
|
|
|
|
m_matrixModelResults()->setCellResults(reservoirData()->results(RifReaderInterface::MATRIX_RESULTS));
|
|
|
|
m_fractureModelResults()->setMainGrid(this->reservoirData()->mainGrid());
|
|
|
|
m_matrixModelResults()->setMainGrid(this->reservoirData()->mainGrid());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fractureModelResults()->setCellResults(NULL);
|
|
|
|
m_matrixModelResults()->setCellResults(NULL);
|
|
|
|
m_fractureModelResults()->setMainGrid(NULL);
|
|
|
|
m_matrixModelResults()->setMainGrid(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
RimReservoirCellResultsStorage* RimCase::results(RifReaderInterface::PorosityModelResultType porosityModel)
|
2013-03-18 08:34:29 -05:00
|
|
|
{
|
|
|
|
if (porosityModel == RifReaderInterface::MATRIX_RESULTS)
|
|
|
|
{
|
|
|
|
return m_matrixModelResults();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_fractureModelResults();
|
|
|
|
}
|
2013-04-12 01:31:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Relocate the supplied file name, based on the search path as follows:
|
|
|
|
/// fileName, newProjectPath/fileNameWoPath, relocatedPath/fileNameWoPath
|
2013-10-07 04:45:54 -05:00
|
|
|
/// If the file is not found in any of the positions, the fileName is returned but converted to Qt Style path separators: "/"
|
2013-04-12 01:31:59 -05:00
|
|
|
///
|
|
|
|
/// The relocatedPath is found in this way:
|
|
|
|
/// use the start of newProjectPath
|
|
|
|
/// plus the end of the path to m_gridFileName
|
|
|
|
/// such that the common start of oldProjectPath and m_gridFileName is removed from m_gridFileName
|
|
|
|
/// and replaced with the start of newProjectPath up to where newProjectPath starts to be equal to oldProjectPath
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-10-07 04:45:54 -05:00
|
|
|
QString RimCase::relocateFile(const QString& orgFileName, const QString& orgNewProjectPath, const QString& orgOldProjectPath,
|
2013-04-12 01:31:59 -05:00
|
|
|
bool* foundFile, std::vector<QString>* searchedPaths)
|
|
|
|
{
|
|
|
|
if (foundFile) *foundFile = true;
|
2013-10-07 04:45:54 -05:00
|
|
|
|
|
|
|
// Make sure we have a Qt formatted path ( using "/" not "\")
|
|
|
|
QString fileName = QDir::fromNativeSeparators(orgFileName);
|
|
|
|
QString newProjectPath = QDir::fromNativeSeparators(orgNewProjectPath);
|
|
|
|
QString oldProjectPath = QDir::fromNativeSeparators(orgOldProjectPath);
|
|
|
|
|
|
|
|
// If we from a file or whatever gets a real windows path on linux, we need to manually convert it
|
|
|
|
// because Qt will not. QDir::fromNativeSeparators does nothing on linux.
|
|
|
|
|
|
|
|
bool isWindowsPath = false;
|
|
|
|
if (orgFileName.count("/")) isWindowsPath = false; // "/" are not allowed in a windows path
|
|
|
|
else if (orgFileName.count("\\")
|
|
|
|
&& !QFile::exists(orgFileName)) // To make sure we do not convert single linux files containing "\"
|
|
|
|
{
|
|
|
|
isWindowsPath = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isWindowsPath)
|
|
|
|
{
|
|
|
|
// Windows absolute path detected. transform.
|
|
|
|
fileName.replace(QString("\\"), QString("/"));
|
|
|
|
}
|
|
|
|
|
2013-04-12 01:31:59 -05:00
|
|
|
if (searchedPaths) searchedPaths->push_back(fileName);
|
|
|
|
if (QFile::exists(fileName))
|
|
|
|
{
|
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First check in the new project file directory
|
|
|
|
{
|
|
|
|
QString fileNameWithoutPath = QFileInfo(fileName).fileName();
|
|
|
|
QString candidate = QDir::fromNativeSeparators(newProjectPath + QDir::separator() + fileNameWithoutPath);
|
|
|
|
if (searchedPaths) searchedPaths->push_back(candidate);
|
|
|
|
|
|
|
|
if (QFile::exists(candidate))
|
|
|
|
{
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 02:43:40 -05:00
|
|
|
// Then find the possible move of a directory structure where projects and files referenced are moved in "paralell"
|
2013-04-12 01:31:59 -05:00
|
|
|
|
2013-04-12 02:43:40 -05:00
|
|
|
QFileInfo gridFileInfo(QDir::fromNativeSeparators(fileName));
|
|
|
|
QString gridFilePath = gridFileInfo.path();
|
|
|
|
QString gridFileNameWoPath = gridFileInfo.fileName();
|
2013-04-12 01:31:59 -05:00
|
|
|
QStringList gridPathElements = gridFilePath.split("/", QString::KeepEmptyParts);
|
2013-04-12 02:43:40 -05:00
|
|
|
|
|
|
|
QString oldProjPath = QDir::fromNativeSeparators(oldProjectPath);
|
2013-04-12 01:31:59 -05:00
|
|
|
QStringList oldProjPathElements = oldProjPath.split("/", QString::KeepEmptyParts);
|
2013-04-12 02:43:40 -05:00
|
|
|
|
|
|
|
QString newProjPath = QDir::fromNativeSeparators(newProjectPath);
|
2013-04-12 01:31:59 -05:00
|
|
|
QStringList newProjPathElements = newProjPath.split("/", QString::KeepEmptyParts);
|
|
|
|
|
2013-04-12 02:43:40 -05:00
|
|
|
// Find the possible equal start of the old project path, and the referenced file
|
|
|
|
|
2013-04-12 01:31:59 -05:00
|
|
|
bool pathStartsAreEqual = false;
|
|
|
|
bool pathEndsDiffer = false;
|
|
|
|
int firstDiffIdx = 0;
|
|
|
|
for ( firstDiffIdx = 0; firstDiffIdx < gridPathElements.size() && firstDiffIdx < oldProjPathElements.size(); ++firstDiffIdx)
|
|
|
|
{
|
|
|
|
if (gridPathElements[firstDiffIdx] == oldProjPathElements[firstDiffIdx])
|
|
|
|
{
|
|
|
|
pathStartsAreEqual = pathStartsAreEqual || !gridPathElements[firstDiffIdx].isEmpty();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pathEndsDiffer = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pathEndsDiffer && firstDiffIdx < gridPathElements.size() || firstDiffIdx < oldProjPathElements.size())
|
|
|
|
{
|
|
|
|
pathEndsDiffer = true;
|
|
|
|
}
|
|
|
|
|
2013-04-12 02:43:40 -05:00
|
|
|
// If the path starts are equal, try to substitute it in the referenced file, with the corresponding new project path start
|
|
|
|
|
2013-04-12 01:31:59 -05:00
|
|
|
if (pathStartsAreEqual)
|
|
|
|
{
|
|
|
|
if (pathEndsDiffer)
|
|
|
|
{
|
|
|
|
QString oldGridFilePathEnd;
|
|
|
|
for (int i = firstDiffIdx; i < gridPathElements.size(); ++i)
|
|
|
|
{
|
|
|
|
oldGridFilePathEnd += gridPathElements[i];
|
|
|
|
oldGridFilePathEnd += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the new Project File Start Path
|
|
|
|
|
|
|
|
QStringList oldProjectFilePathEndElements;
|
|
|
|
for (int i = firstDiffIdx; i < oldProjPathElements.size(); ++i)
|
|
|
|
{
|
|
|
|
oldProjectFilePathEndElements.push_back(oldProjPathElements[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ppIdx = oldProjectFilePathEndElements.size() -1;
|
|
|
|
int lastDiffIdx = newProjPathElements.size() -1;
|
|
|
|
|
|
|
|
for (; lastDiffIdx >= 0 && ppIdx >= 0; --lastDiffIdx, --ppIdx)
|
|
|
|
{
|
|
|
|
if (oldProjectFilePathEndElements[ppIdx] != newProjPathElements[lastDiffIdx])
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString newProjecetFileStartPath;
|
|
|
|
for (int i = 0; i <= lastDiffIdx; ++i)
|
|
|
|
{
|
|
|
|
newProjecetFileStartPath += newProjPathElements[i];
|
|
|
|
newProjecetFileStartPath += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString relocationPath = newProjecetFileStartPath + oldGridFilePathEnd;
|
|
|
|
|
2013-04-12 02:43:40 -05:00
|
|
|
QString relocatedFileName = relocationPath + gridFileNameWoPath;
|
2013-04-12 01:31:59 -05:00
|
|
|
|
|
|
|
if (searchedPaths) searchedPaths->push_back(relocatedFileName);
|
|
|
|
|
|
|
|
if (QFile::exists(relocatedFileName))
|
|
|
|
{
|
|
|
|
return relocatedFileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The Grid file was located in the same dir as the Project file. This is supposed to be handled above.
|
2013-04-12 02:43:40 -05:00
|
|
|
// So we did not find it
|
2013-04-12 01:31:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the unchanged filename, if we could not find a valid relocation file
|
|
|
|
if (foundFile) *foundFile = false;
|
|
|
|
|
|
|
|
return fileName;
|
|
|
|
}
|