2015-11-27 05:17:50 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) Statoil ASA
|
|
|
|
// Copyright (C) Ceetron Solutions AS
|
2018-10-26 08:38:09 -05:00
|
|
|
//
|
2015-11-27 05:17:50 -06:00
|
|
|
// 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.
|
2018-10-26 08:38:09 -05:00
|
|
|
//
|
2015-11-27 05:17:50 -06:00
|
|
|
// 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.
|
2018-10-26 08:38:09 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-11-27 05:17:50 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RimGridCollection.h"
|
2018-10-24 06:01:17 -05:00
|
|
|
#include "RimEclipseCase.h"
|
2018-10-26 08:38:09 -05:00
|
|
|
#include "RimGridView.h"
|
2015-11-27 05:17:50 -06:00
|
|
|
|
2018-10-24 06:01:17 -05:00
|
|
|
#include "RigMainGrid.h"
|
|
|
|
|
|
|
|
#include <cafPdmUiTreeOrdering.h>
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void removeGridInfo(const QString& gridName, std::vector<RimGridInfo*>& collection)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < collection.size(); i++)
|
|
|
|
{
|
|
|
|
if (collection[i]->name() == gridName)
|
|
|
|
{
|
|
|
|
collection.erase(collection.begin() + i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT(RimGridInfo, "GridInfo");
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimGridInfo::RimGridInfo()
|
|
|
|
{
|
|
|
|
CAF_PDM_InitObject("GridInfo", ":/draw_style_meshlines_24x24.png", "", "");
|
|
|
|
|
|
|
|
CAF_PDM_InitField(&m_isActive, "IsActive", true, "Show Grid Cells", "", "", "");
|
|
|
|
CAF_PDM_InitField(&m_gridName, "GridName", QString(), "Grid Name", "", "", "");
|
|
|
|
CAF_PDM_InitField(&m_gridIndex, "GridIndex", 0, "Grid Index", "", "", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
caf::PdmFieldHandle* RimGridInfo::objectToggleField()
|
|
|
|
{
|
|
|
|
return nullptr; // &m_isActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridInfo::setActive(bool active)
|
|
|
|
{
|
|
|
|
m_isActive = active;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridInfo::setName(const QString& name)
|
|
|
|
{
|
|
|
|
m_gridName = name;
|
|
|
|
setUiName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridInfo::setIndex(int index)
|
|
|
|
{
|
|
|
|
m_gridIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimGridInfo::name() const
|
|
|
|
{
|
|
|
|
return m_gridName();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
int RimGridInfo::index() const
|
|
|
|
{
|
|
|
|
return m_gridIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
caf::PdmFieldHandle* RimGridInfo::userDescriptionField()
|
|
|
|
{
|
|
|
|
return &m_gridName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-26 08:38:09 -05:00
|
|
|
void RimGridInfo::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) {}
|
2018-10-24 06:01:17 -05:00
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT(RimGridInfoCollection, "GridInfoCollection");
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimGridInfoCollection::RimGridInfoCollection()
|
|
|
|
{
|
|
|
|
CAF_PDM_InitObject("GridInfoCollection", ":/draw_style_meshlines_24x24.png", "", "");
|
|
|
|
|
|
|
|
CAF_PDM_InitField(&m_isActive, "IsActive", true, "Show Grid Cells", "", "", "");
|
|
|
|
m_isActive.uiCapability()->setUiHidden(true);
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_gridInfos, "GridInfos", "Grid Infos", "", "", "");
|
|
|
|
|
|
|
|
m_gridInfos.uiCapability()->setUiTreeHidden(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridInfoCollection::addGridInfo(const QString& name, size_t gridIndex)
|
|
|
|
{
|
|
|
|
auto gridInfo = new RimGridInfo();
|
|
|
|
gridInfo->setActive(true);
|
|
|
|
gridInfo->setName(name);
|
|
|
|
gridInfo->setIndex((int)gridIndex);
|
|
|
|
m_gridInfos.push_back(gridInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridInfoCollection::clear()
|
|
|
|
{
|
|
|
|
m_gridInfos.deleteAllChildObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimGridInfoCollection::containsGrid(const QString& gridName) const
|
|
|
|
{
|
|
|
|
for (auto gridInfo : m_gridInfos)
|
|
|
|
{
|
|
|
|
if (gridInfo->name() == gridName) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridInfoCollection::deleteGridInfo(const QString& gridName)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_gridInfos.size(); i++)
|
|
|
|
{
|
|
|
|
auto gridInfo = m_gridInfos[i];
|
|
|
|
if (gridInfo->name() == gridName)
|
|
|
|
{
|
|
|
|
m_gridInfos.erase(i);
|
|
|
|
delete gridInfo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RimGridInfo*> RimGridInfoCollection::gridInfos() const
|
|
|
|
{
|
2018-10-26 08:31:32 -05:00
|
|
|
return m_gridInfos.childObjects();
|
2018-10-24 06:01:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
caf::PdmFieldHandle* RimGridInfoCollection::objectToggleField()
|
|
|
|
{
|
2018-10-26 08:38:09 -05:00
|
|
|
return nullptr; // &m_isActive;
|
2018-10-24 06:01:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridInfoCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
|
|
|
|
const QVariant& oldValue,
|
|
|
|
const QVariant& newValue)
|
|
|
|
{
|
|
|
|
}
|
2015-11-27 05:17:50 -06:00
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT(RimGridCollection, "GridCollection");
|
|
|
|
|
2018-10-24 06:01:17 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-11-27 05:17:50 -06:00
|
|
|
RimGridCollection::RimGridCollection()
|
|
|
|
{
|
2017-11-08 08:08:01 -06:00
|
|
|
CAF_PDM_InitObject("Grids", ":/draw_style_meshlines_24x24.png", "", "");
|
2015-11-27 05:17:50 -06:00
|
|
|
|
2018-10-24 06:01:17 -05:00
|
|
|
CAF_PDM_InitField(&m_isActive, "IsActive", true, "Show Grid Cells", "", "", "");
|
|
|
|
m_isActive.uiCapability()->setUiHidden(true);
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_mainGrid, "MainGrid", "Main Grid", "", "", "");
|
|
|
|
m_mainGrid = new RimGridInfo();
|
|
|
|
m_mainGrid->setUiName("Main Grid");
|
|
|
|
m_mainGrid->uiCapability()->setUiTreeHidden(true);
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_persistentLgrs, "PersistentLgrs", "Persistent LGRs", "", "", "");
|
|
|
|
m_persistentLgrs = new RimGridInfoCollection();
|
2018-10-26 08:38:09 -05:00
|
|
|
m_persistentLgrs->setUiName(persistentGridUiName());
|
2018-10-24 06:01:17 -05:00
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_temporaryLgrs, "TemporaryLgrs", "Temporary LGRs", "", "", "");
|
2018-10-25 04:22:18 -05:00
|
|
|
m_temporaryLgrs.xmlCapability()->disableIO();
|
2018-10-24 06:01:17 -05:00
|
|
|
m_temporaryLgrs = new RimGridInfoCollection();
|
2018-10-26 08:38:09 -05:00
|
|
|
m_temporaryLgrs->setUiName(temporaryGridUiName());
|
2015-11-27 05:17:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-26 08:38:09 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimGridCollection::~RimGridCollection() {}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
2015-11-27 05:17:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-26 08:38:09 -05:00
|
|
|
const QString RimGridCollection::persistentGridUiName()
|
2015-11-27 05:17:50 -06:00
|
|
|
{
|
2018-10-26 08:38:09 -05:00
|
|
|
return "LGRs";
|
|
|
|
}
|
2015-11-27 05:17:50 -06:00
|
|
|
|
2018-10-26 08:38:09 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const QString RimGridCollection::temporaryGridUiName()
|
|
|
|
{
|
|
|
|
return "Temporary LGRs";
|
2015-11-27 05:17:50 -06:00
|
|
|
}
|
|
|
|
|
2018-10-24 06:01:17 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridCollection::setActive(bool active)
|
|
|
|
{
|
|
|
|
m_isActive = active;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimGridCollection::isActive() const
|
|
|
|
{
|
|
|
|
return m_isActive;
|
|
|
|
}
|
|
|
|
|
2015-11-27 05:17:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-26 08:38:09 -05:00
|
|
|
///
|
2015-11-27 05:17:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
caf::PdmFieldHandle* RimGridCollection::objectToggleField()
|
|
|
|
{
|
2018-10-24 06:01:17 -05:00
|
|
|
return &m_isActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridCollection::syncFromMainGrid()
|
|
|
|
{
|
|
|
|
auto mainGrid = this->mainGrid();
|
|
|
|
if (mainGrid)
|
|
|
|
{
|
|
|
|
m_mainGrid->setName("Main Grid");
|
|
|
|
m_mainGrid->setIndex(0);
|
|
|
|
|
2018-10-26 08:38:09 -05:00
|
|
|
auto allTemporaryGrids = m_temporaryLgrs->gridInfos();
|
2018-10-24 06:01:17 -05:00
|
|
|
auto allPersistentGrids = m_persistentLgrs->gridInfos();
|
|
|
|
|
|
|
|
size_t gridCount = mainGrid->gridCount();
|
|
|
|
for (size_t i = 1; i < gridCount; i++)
|
|
|
|
{
|
2018-10-26 08:38:09 -05:00
|
|
|
auto grid = mainGrid->gridByIndex(i);
|
|
|
|
QString gridName = QString::fromStdString(grid->gridName());
|
|
|
|
size_t gridIndex = grid->gridIndex();
|
2018-10-24 06:01:17 -05:00
|
|
|
|
|
|
|
if (grid->isTempGrid())
|
|
|
|
{
|
|
|
|
if (m_temporaryLgrs->containsGrid(gridName))
|
|
|
|
{
|
|
|
|
removeGridInfo(gridName, allTemporaryGrids);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_temporaryLgrs->addGridInfo(gridName, gridIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_persistentLgrs->containsGrid(gridName))
|
|
|
|
{
|
|
|
|
removeGridInfo(gridName, allPersistentGrids);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_persistentLgrs->addGridInfo(gridName, gridIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!allPersistentGrids.empty())
|
|
|
|
{
|
|
|
|
auto gridName = allPersistentGrids.front()->name();
|
|
|
|
m_persistentLgrs->deleteGridInfo(gridName);
|
|
|
|
removeGridInfo(gridName, allPersistentGrids);
|
|
|
|
}
|
|
|
|
while (!allTemporaryGrids.empty())
|
|
|
|
{
|
|
|
|
auto gridName = allTemporaryGrids.front()->name();
|
|
|
|
m_temporaryLgrs->deleteGridInfo(allTemporaryGrids.front()->name());
|
|
|
|
removeGridInfo(gridName, allTemporaryGrids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateConnectedEditors();
|
2015-11-27 05:17:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-26 08:38:09 -05:00
|
|
|
///
|
2015-11-27 05:17:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-26 08:38:09 -05:00
|
|
|
void RimGridCollection::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
|
|
|
|
const QVariant& oldValue,
|
|
|
|
const QVariant& newValue)
|
2015-11-27 05:17:50 -06:00
|
|
|
{
|
2018-10-24 06:01:17 -05:00
|
|
|
if (changedField == &m_isActive)
|
2015-11-27 05:17:50 -06:00
|
|
|
{
|
2018-02-18 11:56:43 -06:00
|
|
|
RimGridView* rimView = nullptr;
|
2016-09-21 06:59:41 -05:00
|
|
|
this->firstAncestorOrThisOfType(rimView);
|
2015-11-27 05:17:50 -06:00
|
|
|
CVF_ASSERT(rimView);
|
|
|
|
|
2018-10-24 06:01:17 -05:00
|
|
|
if (rimView) rimView->showGridCells(m_isActive);
|
2015-11-27 05:17:50 -06:00
|
|
|
|
2018-10-24 06:01:17 -05:00
|
|
|
updateUiIconFromState(m_isActive);
|
2015-11-27 05:17:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-26 08:38:09 -05:00
|
|
|
///
|
2015-11-27 05:17:50 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridCollection::initAfterRead()
|
|
|
|
{
|
2018-10-24 06:01:17 -05:00
|
|
|
updateUiIconFromState(m_isActive);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridCollection::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/)
|
|
|
|
{
|
|
|
|
uiTreeOrdering.add(m_mainGrid());
|
|
|
|
uiTreeOrdering.add(m_persistentLgrs());
|
|
|
|
uiTreeOrdering.add(m_temporaryLgrs());
|
|
|
|
uiTreeOrdering.skipRemainingChildren(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const RigMainGrid* RimGridCollection::mainGrid() const
|
|
|
|
{
|
|
|
|
RimEclipseCase* eclipseCase;
|
|
|
|
firstAncestorOrThisOfType(eclipseCase);
|
|
|
|
return eclipseCase ? eclipseCase->mainGrid() : nullptr;
|
2015-11-27 05:17:50 -06:00
|
|
|
}
|