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-03-22 10:12:00 -05:00
|
|
|
#include "RiaStdInclude.h"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
#include "RimProject.h"
|
2013-03-22 10:24:42 -05:00
|
|
|
#include "RiaApplication.h"
|
2013-03-22 10:12:00 -05:00
|
|
|
#include "RiaVersionInfo.h"
|
2013-02-14 07:30:01 -06:00
|
|
|
|
2013-02-14 06:16:56 -06:00
|
|
|
#include "RigGridCollection.h"
|
|
|
|
#include "RigEclipseCase.h"
|
2013-03-19 03:55:17 -05:00
|
|
|
#include "RimResultReservoir.h"
|
2013-02-14 06:16:56 -06:00
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT(RimProject, "ResInsightProject");
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimProject::RimProject(void)
|
|
|
|
{
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_projectFileVersionString, "ProjectFileVersionString", "", "", "", "");
|
2012-06-26 09:10:41 -05:00
|
|
|
m_projectFileVersionString.setUiHidden(true);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&reservoirs, "Reservoirs", "", "", "", "");
|
2013-02-14 07:30:01 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault(&caseGroups, "CaseGroups", "", "", "", "");
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
CAF_PDM_InitFieldNoDefault(&scriptCollection, "ScriptCollection", "Scripts", ":/Default.png", "", "");
|
|
|
|
|
|
|
|
scriptCollection = new RimScriptCollection();
|
2012-06-26 09:10:41 -05:00
|
|
|
scriptCollection->directory.setUiHidden(true);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-22 09:43:42 -05:00
|
|
|
m_gridCollection = new RigGridManager;
|
2013-02-14 06:16:56 -06:00
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
initAfterRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimProject::~RimProject(void)
|
|
|
|
{
|
2013-02-14 06:16:56 -06:00
|
|
|
close();
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
if (scriptCollection()) delete scriptCollection();
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
reservoirs.deleteAllChildObjects();
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimProject::close()
|
|
|
|
{
|
2013-03-08 01:36:30 -06:00
|
|
|
m_gridCollection->clear();
|
2013-02-14 06:16:56 -06:00
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
reservoirs.deleteAllChildObjects();
|
2013-02-14 07:30:01 -06:00
|
|
|
caseGroups.deleteAllChildObjects();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
fileName = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimProject::initAfterRead()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// TODO : Must store content of scripts in project file and notify user if stored content is different from disk on execute and edit
|
|
|
|
//
|
2013-03-22 09:50:44 -05:00
|
|
|
RiaApplication* app = RiaApplication::instance();
|
2012-05-18 02:45:23 -05:00
|
|
|
QString scriptDirectory = app->scriptDirectory();
|
|
|
|
|
|
|
|
this->setUserScriptPath(scriptDirectory);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimProject::setupBeforeSave()
|
|
|
|
{
|
|
|
|
m_projectFileVersionString = STRPRODUCTVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimProject::setUserScriptPath(const QString& scriptDirectory)
|
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
scriptCollection->calcScripts().deleteAllChildObjects();
|
|
|
|
scriptCollection->subDirectories().deleteAllChildObjects();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
QDir dir(scriptDirectory);
|
|
|
|
if (!scriptDirectory.isEmpty() && dir.exists())
|
|
|
|
{
|
|
|
|
RimScriptCollection* sharedScriptLocation = new RimScriptCollection;
|
|
|
|
sharedScriptLocation->directory = scriptDirectory;
|
|
|
|
sharedScriptLocation->setUiName(dir.dirName());
|
|
|
|
|
|
|
|
sharedScriptLocation->readContentFromDisc();
|
|
|
|
|
|
|
|
scriptCollection->subDirectories.push_back(sharedScriptLocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimProject::projectFileVersionString() const
|
|
|
|
{
|
|
|
|
return m_projectFileVersionString;
|
|
|
|
}
|
2013-02-14 06:16:56 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimProject::moveEclipseCaseIntoCaseGroup(RimCase* rimReservoir)
|
2013-02-14 06:16:56 -06:00
|
|
|
{
|
2013-02-14 07:30:01 -06:00
|
|
|
CVF_ASSERT(rimReservoir);
|
2013-02-14 06:16:56 -06:00
|
|
|
|
2013-03-22 09:43:42 -05:00
|
|
|
RigCaseData* rigEclipseCase = rimReservoir->reservoirData();
|
2013-03-19 03:55:17 -05:00
|
|
|
RigMainGrid* equalGrid = registerCaseInGridCollection(rigEclipseCase);
|
|
|
|
CVF_ASSERT(equalGrid);
|
2013-02-14 07:30:01 -06:00
|
|
|
|
|
|
|
// Insert in identical grid group
|
|
|
|
bool foundGroup = false;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < caseGroups.size(); i++)
|
|
|
|
{
|
|
|
|
RimIdenticalGridCaseGroup* cg = caseGroups()[i];
|
|
|
|
|
|
|
|
if (cg->mainGrid() == equalGrid)
|
|
|
|
{
|
|
|
|
cg->addCase(rimReservoir);
|
|
|
|
foundGroup = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundGroup)
|
|
|
|
{
|
|
|
|
RimIdenticalGridCaseGroup* group = new RimIdenticalGridCaseGroup;
|
|
|
|
group->addCase(rimReservoir);
|
|
|
|
|
|
|
|
caseGroups().push_back(group);
|
|
|
|
}
|
2013-02-15 03:01:41 -06:00
|
|
|
|
|
|
|
// Remove reservoir from main container
|
|
|
|
reservoirs().removeChildObject(rimReservoir);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimProject::removeCaseFromAllGroups(RimCase* reservoir)
|
2013-02-15 03:01:41 -06:00
|
|
|
{
|
|
|
|
m_gridCollection->removeCase(reservoir->reservoirData());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < caseGroups.size(); i++)
|
|
|
|
{
|
|
|
|
RimIdenticalGridCaseGroup* cg = caseGroups()[i];
|
|
|
|
|
2013-03-20 05:35:27 -05:00
|
|
|
cg->removeCase(reservoir);
|
2013-02-15 03:01:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
reservoirs().removeChildObject(reservoir);
|
2013-02-14 06:16:56 -06:00
|
|
|
}
|
2013-03-19 03:55:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
RigMainGrid* RimProject::registerCaseInGridCollection(RigCaseData* rigEclipseCase)
|
2013-03-19 03:55:17 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(rigEclipseCase);
|
|
|
|
|
|
|
|
RigMainGrid* equalGrid = m_gridCollection->findEqualGrid(rigEclipseCase->mainGrid());
|
|
|
|
|
|
|
|
if (equalGrid)
|
|
|
|
{
|
|
|
|
// Replace the grid with an already registered grid
|
|
|
|
rigEclipseCase->setMainGrid(equalGrid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This is the first insertion of this grid, compute cached data
|
|
|
|
rigEclipseCase->mainGrid()->computeCachedData();
|
|
|
|
|
|
|
|
std::vector<RigGridBase*> grids;
|
|
|
|
rigEclipseCase->allGrids(&grids);
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < grids.size(); i++)
|
|
|
|
{
|
|
|
|
grids[i]->computeFaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
equalGrid = rigEclipseCase->mainGrid();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_gridCollection->addCase(rigEclipseCase);
|
|
|
|
|
|
|
|
return equalGrid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimProject::insertCaseInCaseGroup(RimIdenticalGridCaseGroup* caseGroup, RimCase* rimReservoir)
|
2013-03-19 03:55:17 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(rimReservoir);
|
|
|
|
|
2013-03-22 09:43:42 -05:00
|
|
|
RigCaseData* rigEclipseCase = rimReservoir->reservoirData();
|
2013-03-19 03:55:17 -05:00
|
|
|
registerCaseInGridCollection(rigEclipseCase);
|
|
|
|
|
|
|
|
caseGroup->addCase(rimReservoir);
|
|
|
|
}
|
|
|
|
|