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.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RIStdInclude.h"
|
|
|
|
|
|
|
|
#include "RimUiTreeModelPdm.h"
|
|
|
|
#include "RimCellRangeFilter.h"
|
|
|
|
#include "RimCellRangeFilterCollection.h"
|
|
|
|
|
|
|
|
#include "cafPdmObject.h"
|
|
|
|
#include "RimCellPropertyFilter.h"
|
|
|
|
#include "RimCellPropertyFilterCollection.h"
|
|
|
|
|
|
|
|
#include "RimReservoirView.h"
|
|
|
|
#include "RIViewer.h"
|
|
|
|
#include "RimCalcScript.h"
|
|
|
|
#include "RIApplication.h"
|
|
|
|
#include "RIMainWindow.h"
|
2012-06-26 09:10:41 -05:00
|
|
|
#include "RimInputProperty.h"
|
|
|
|
#include "RimInputPropertyCollection.h"
|
|
|
|
#include "cafPdmField.h"
|
|
|
|
#include "RimInputReservoir.h"
|
2013-02-15 01:44:45 -06:00
|
|
|
#include "RimStatisticalCalculation.h"
|
2013-03-20 01:42:26 -05:00
|
|
|
#include "RimResultReservoir.h"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimUiTreeModelPdm::RimUiTreeModelPdm(QObject* parent)
|
|
|
|
: caf::UiTreeModelPdm(parent)
|
|
|
|
{
|
|
|
|
m_scriptChangeDetector = new QFileSystemWatcher(this);
|
|
|
|
this->updateScriptPaths();
|
|
|
|
connect(m_scriptChangeDetector, SIGNAL(directoryChanged(QString)), this, SLOT(slotRefreshScriptTree(QString)));
|
|
|
|
connect(m_scriptChangeDetector, SIGNAL(fileChanged(QString)), this, SLOT(slotRefreshScriptTree(QString)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimUiTreeModelPdm::insertRows(int position, int rows, const QModelIndex &parent /*= QModelIndex()*/)
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* parentItem = getTreeItemFromIndex(parent);
|
|
|
|
|
|
|
|
bool canCreateChildren = false;
|
|
|
|
QModelIndex parentIndex = parent;
|
|
|
|
|
|
|
|
if (dynamic_cast<RimCellRangeFilterCollection*>(parentItem->dataObject().p()) ||
|
|
|
|
dynamic_cast<RimCellPropertyFilterCollection*>(parentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
canCreateChildren = true;
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimCellFilter*>(parentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
parentItem = parentItem->parent();
|
|
|
|
parentIndex = parent.parent();
|
|
|
|
|
|
|
|
canCreateChildren = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canCreateChildren)
|
|
|
|
{
|
|
|
|
beginInsertRows(parent, position, position + rows - 1);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < rows; i++)
|
|
|
|
{
|
|
|
|
if (dynamic_cast<RimCellRangeFilterCollection*>(parentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimCellRangeFilterCollection* rangeFilterCollection = dynamic_cast<RimCellRangeFilterCollection*>(parentItem->dataObject().p());
|
|
|
|
|
|
|
|
RimCellRangeFilter* rangeFilter = rangeFilterCollection->createAndAppendRangeFilter();
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentItem, position + i, rangeFilter);
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimCellPropertyFilterCollection*>(parentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimCellPropertyFilterCollection* propertyFilterCollection = dynamic_cast<RimCellPropertyFilterCollection*>(parentItem->dataObject().p());
|
|
|
|
|
|
|
|
RimCellPropertyFilter* propertyFilter = propertyFilterCollection->createAndAppendPropertyFilter();
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentItem, position + i, propertyFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
return canCreateChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
bool RimUiTreeModelPdm::deletePropertyFilter(const QModelIndex& itemIndex)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(itemIndex.isValid());
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
CVF_ASSERT(uiItem);
|
|
|
|
|
|
|
|
RimCellPropertyFilter* propertyFilter = dynamic_cast<RimCellPropertyFilter*>(uiItem->dataObject().p());
|
|
|
|
CVF_ASSERT(propertyFilter);
|
|
|
|
|
|
|
|
RimCellPropertyFilterCollection* propertyFilterCollection = propertyFilter->parentContainer();
|
|
|
|
CVF_ASSERT(propertyFilterCollection);
|
|
|
|
|
|
|
|
bool wasFilterActive = propertyFilter->active();
|
|
|
|
bool wasSomeFilterActive = propertyFilterCollection->hasActiveFilters();
|
|
|
|
|
|
|
|
// Remove Ui items pointing at the pdm object to delete
|
|
|
|
removeRow(itemIndex.row(), itemIndex.parent());
|
|
|
|
|
|
|
|
propertyFilterCollection->remove(propertyFilter);
|
|
|
|
delete propertyFilter;
|
|
|
|
|
|
|
|
if (wasFilterActive)
|
|
|
|
{
|
|
|
|
propertyFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::PROPERTY_FILTERED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wasSomeFilterActive)
|
|
|
|
{
|
|
|
|
propertyFilterCollection->reservoirView()->createDisplayModelAndRedraw();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
bool RimUiTreeModelPdm::deleteRangeFilter(const QModelIndex& itemIndex)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(itemIndex.isValid());
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
CVF_ASSERT(uiItem);
|
|
|
|
|
|
|
|
RimCellRangeFilter* rangeFilter = dynamic_cast<RimCellRangeFilter*>(uiItem->dataObject().p());
|
|
|
|
CVF_ASSERT(rangeFilter);
|
|
|
|
|
|
|
|
RimCellRangeFilterCollection* rangeFilterCollection = rangeFilter->parentContainer();
|
|
|
|
CVF_ASSERT(rangeFilterCollection);
|
|
|
|
|
|
|
|
bool wasFilterActive = rangeFilter->active();
|
|
|
|
bool wasSomeFilterActive = rangeFilterCollection->hasActiveFilters();
|
|
|
|
|
|
|
|
// Remove Ui items pointing at the pdm object to delete
|
|
|
|
removeRow(itemIndex.row(), itemIndex.parent());
|
|
|
|
|
|
|
|
rangeFilterCollection->remove(rangeFilter);
|
|
|
|
delete rangeFilter;
|
|
|
|
|
|
|
|
if (wasFilterActive)
|
|
|
|
{
|
|
|
|
rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::PROPERTY_FILTERED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wasSomeFilterActive)
|
|
|
|
{
|
|
|
|
rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
bool RimUiTreeModelPdm::deleteReservoirView(const QModelIndex& itemIndex)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(itemIndex.isValid());
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
CVF_ASSERT(uiItem);
|
|
|
|
|
|
|
|
RimReservoirView* reservoirView = dynamic_cast<RimReservoirView*>(uiItem->dataObject().p());
|
|
|
|
CVF_ASSERT(reservoirView);
|
|
|
|
|
|
|
|
// Remove Ui items pointing at the pdm object to delete
|
|
|
|
removeRow(itemIndex.row(), itemIndex.parent());
|
|
|
|
|
|
|
|
reservoirView->eclipseCase()->removeReservoirView(reservoirView);
|
|
|
|
delete reservoirView;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-23 04:12:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimUiTreeModelPdm::deleteReservoir(const QModelIndex& itemIndex)
|
|
|
|
{
|
|
|
|
CVF_ASSERT(itemIndex.isValid());
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
CVF_ASSERT(uiItem);
|
|
|
|
|
|
|
|
RimReservoir* reservoir = dynamic_cast<RimReservoir*>(uiItem->dataObject().p());
|
|
|
|
CVF_ASSERT(reservoir);
|
|
|
|
|
|
|
|
// Remove Ui items pointing at the pdm object to delete
|
|
|
|
removeRow(itemIndex.row(), itemIndex.parent());
|
|
|
|
|
|
|
|
RimProject* proj = RIApplication::instance()->project();
|
2013-03-20 05:35:27 -05:00
|
|
|
proj->removeCaseFromAllGroups(reservoir);
|
2012-10-23 04:12:47 -05:00
|
|
|
|
|
|
|
delete reservoir;
|
|
|
|
}
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimCellPropertyFilter* RimUiTreeModelPdm::addPropertyFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex)
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
|
|
|
|
QModelIndex collectionIndex;
|
|
|
|
RimCellPropertyFilterCollection* propertyFilterCollection = NULL;
|
|
|
|
caf::PdmUiTreeItem* propertyFilterCollectionItem = NULL;
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
if (dynamic_cast<RimCellPropertyFilter*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimCellPropertyFilter* propertyFilter = dynamic_cast<RimCellPropertyFilter*>(currentItem->dataObject().p());
|
|
|
|
propertyFilterCollection = propertyFilter->parentContainer();
|
|
|
|
propertyFilterCollectionItem = currentItem->parent();
|
|
|
|
position = itemIndex.row();
|
|
|
|
collectionIndex = itemIndex.parent();
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimCellPropertyFilterCollection*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
propertyFilterCollection = dynamic_cast<RimCellPropertyFilterCollection*>(currentItem->dataObject().p());
|
|
|
|
propertyFilterCollectionItem = currentItem;
|
|
|
|
position = propertyFilterCollectionItem->childCount();
|
|
|
|
collectionIndex = itemIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
beginInsertRows(collectionIndex, position, position);
|
|
|
|
|
|
|
|
RimCellPropertyFilter* propertyFilter = propertyFilterCollection->createAndAppendPropertyFilter();
|
|
|
|
caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(propertyFilterCollectionItem, position, propertyFilter);
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
insertedModelIndex = index(position, 0, collectionIndex);
|
|
|
|
|
|
|
|
if (propertyFilterCollection)
|
|
|
|
{
|
|
|
|
propertyFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::PROPERTY_FILTERED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return propertyFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimCellRangeFilter* RimUiTreeModelPdm::addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex)
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
|
|
|
|
QModelIndex collectionIndex;
|
|
|
|
RimCellRangeFilterCollection* rangeFilterCollection = NULL;
|
|
|
|
caf::PdmUiTreeItem* rangeFilterCollectionItem = NULL;
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
if (dynamic_cast<RimCellRangeFilter*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimCellRangeFilter* rangeFilter = dynamic_cast<RimCellRangeFilter*>(currentItem->dataObject().p());
|
|
|
|
rangeFilterCollection = rangeFilter->parentContainer();
|
|
|
|
rangeFilterCollectionItem = currentItem->parent();
|
|
|
|
position = itemIndex.row();
|
|
|
|
collectionIndex = itemIndex.parent();
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimCellRangeFilterCollection*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
rangeFilterCollection = dynamic_cast<RimCellRangeFilterCollection*>(currentItem->dataObject().p());
|
|
|
|
rangeFilterCollectionItem = currentItem;
|
|
|
|
position = rangeFilterCollectionItem->childCount();
|
|
|
|
collectionIndex = itemIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
beginInsertRows(collectionIndex, position, position);
|
|
|
|
|
|
|
|
RimCellRangeFilter* rangeFilter = rangeFilterCollection->createAndAppendRangeFilter();
|
|
|
|
caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(rangeFilterCollectionItem, position, rangeFilter);
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
insertedModelIndex = index(position, 0, collectionIndex);
|
|
|
|
if (rangeFilterCollection)
|
|
|
|
{
|
|
|
|
rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED);
|
|
|
|
rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::RANGE_FILTERED_INACTIVE);
|
|
|
|
|
|
|
|
}
|
|
|
|
return rangeFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimReservoirView* RimUiTreeModelPdm::addReservoirView(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex)
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
if (!currentItem) return NULL;
|
|
|
|
|
2013-02-15 02:21:28 -06:00
|
|
|
caf::PdmUiTreeItem* collectionItem = NULL;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-08 04:14:27 -06:00
|
|
|
bool itemIndexIsCollection = false;
|
|
|
|
QModelIndex collectionIndex;
|
2013-02-15 02:21:28 -06:00
|
|
|
if (dynamic_cast<RimReservoirView*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
collectionItem = currentItem->parent();
|
2013-03-08 04:14:27 -06:00
|
|
|
collectionIndex = itemIndex.parent();
|
2013-02-15 02:21:28 -06:00
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimReservoir*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
collectionItem = currentItem;
|
2013-03-08 04:14:27 -06:00
|
|
|
collectionIndex = itemIndex;
|
2013-02-15 02:21:28 -06:00
|
|
|
}
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-02-15 02:21:28 -06:00
|
|
|
if (collectionItem)
|
|
|
|
{
|
|
|
|
RimReservoir* rimReservoir = dynamic_cast<RimReservoir*>(collectionItem->dataObject().p());
|
|
|
|
RimReservoirView* insertedView = rimReservoir->createAndAddReservoirView();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-11 02:24:45 -05:00
|
|
|
int viewCount = rowCount(collectionIndex);
|
|
|
|
beginInsertRows(collectionIndex, viewCount, viewCount);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-20 01:14:27 -05:00
|
|
|
// NOTE: -1 as second argument indicates append
|
|
|
|
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(collectionItem, -1, insertedView);
|
|
|
|
|
2013-02-15 02:21:28 -06:00
|
|
|
endInsertRows();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-02-15 02:21:28 -06:00
|
|
|
insertedView->loadDataAndUpdate();
|
|
|
|
|
|
|
|
return insertedView;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimUiTreeModelPdm::updateScriptPaths()
|
|
|
|
{
|
|
|
|
RimProject* proj = RIApplication::instance()->project();
|
|
|
|
|
|
|
|
if (!proj || !proj->scriptCollection()) return;
|
|
|
|
|
|
|
|
QStringList paths;
|
|
|
|
|
|
|
|
proj->scriptCollection()->pathsAndSubPaths(paths);
|
|
|
|
|
|
|
|
if (m_scriptChangeDetector->directories().size()) m_scriptChangeDetector->removePaths( m_scriptChangeDetector->directories());
|
|
|
|
if (m_scriptChangeDetector->files().size()) m_scriptChangeDetector->removePaths( m_scriptChangeDetector->files());
|
|
|
|
|
|
|
|
if (paths.size()) m_scriptChangeDetector->addPaths(paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimUiTreeModelPdm::slotRefreshScriptTree(QString path)
|
|
|
|
{
|
|
|
|
RimProject* proj = RIApplication::instance()->project();
|
|
|
|
|
|
|
|
if (!proj || !proj->scriptCollection()) return;
|
|
|
|
|
|
|
|
RimScriptCollection* changedSColl = proj->scriptCollection()->findScriptCollection(path);
|
|
|
|
if (changedSColl)
|
|
|
|
{
|
|
|
|
changedSColl->readContentFromDisc();
|
|
|
|
this->rebuildUiSubTree(changedSColl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
void RimUiTreeModelPdm::addInputProperty(const QModelIndex& itemIndex, const QStringList& fileNames)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
RimInputPropertyCollection* inputPropertyCollection = dynamic_cast<RimInputPropertyCollection*>(currentItem->dataObject().p());
|
|
|
|
CVF_ASSERT(inputPropertyCollection);
|
|
|
|
|
2013-03-13 07:51:26 -05:00
|
|
|
std::vector<RimInputReservoir*> parentObjects;
|
|
|
|
inputPropertyCollection->parentObjectsOfType(parentObjects);
|
2012-06-26 09:10:41 -05:00
|
|
|
CVF_ASSERT(parentObjects.size() == 1);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-13 07:51:26 -05:00
|
|
|
RimInputReservoir* inputReservoir = parentObjects[0];
|
2012-06-26 09:10:41 -05:00
|
|
|
CVF_ASSERT(inputReservoir);
|
|
|
|
if (inputReservoir)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
inputReservoir->openDataFileSet(fileNames);
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
this->rebuildUiSubTree(inputPropertyCollection);
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-06-26 09:10:41 -05:00
|
|
|
void RimUiTreeModelPdm::deleteInputProperty(const QModelIndex& itemIndex)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
if (!itemIndex.isValid()) return;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
if (!uiItem) return;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
caf::PdmObject* object = uiItem->dataObject().p();
|
|
|
|
RimInputProperty* inputProperty = dynamic_cast<RimInputProperty*>(object);
|
|
|
|
if (!inputProperty) return;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
// Remove item from UI tree model before delete of project data structure
|
|
|
|
removeRow(itemIndex.row(), itemIndex.parent());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-13 07:51:26 -05:00
|
|
|
std::vector<RimInputPropertyCollection*> parentObjects;
|
|
|
|
object->parentObjectsOfType(parentObjects);
|
2012-06-26 09:10:41 -05:00
|
|
|
CVF_ASSERT(parentObjects.size() == 1);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-13 07:51:26 -05:00
|
|
|
RimInputPropertyCollection* inputPropertyCollection = parentObjects[0];
|
2012-06-26 09:10:41 -05:00
|
|
|
if (!inputPropertyCollection) return;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-13 07:51:26 -05:00
|
|
|
std::vector<RimInputReservoir*> parentObjects2;
|
|
|
|
inputPropertyCollection->parentObjectsOfType(parentObjects2);
|
2012-06-26 09:10:41 -05:00
|
|
|
CVF_ASSERT(parentObjects2.size() == 1);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-13 07:51:26 -05:00
|
|
|
RimInputReservoir* inputReservoir = parentObjects2[0];
|
2012-06-26 09:10:41 -05:00
|
|
|
if (!inputReservoir) return;
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
inputReservoir->removeProperty(inputProperty);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
delete inputProperty;
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
2012-10-23 04:12:47 -05:00
|
|
|
|
2013-02-15 01:44:45 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimStatisticalCalculation* RimUiTreeModelPdm::addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex)
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
|
|
|
|
QModelIndex collectionIndex;
|
2013-02-21 05:00:49 -06:00
|
|
|
RimStatisticalCollection* caseGroup = NULL;
|
2013-02-15 01:44:45 -06:00
|
|
|
caf::PdmUiTreeItem* parentCollectionItem = NULL;
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
if (dynamic_cast<RimStatisticalCalculation*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimStatisticalCalculation* currentObject = dynamic_cast<RimStatisticalCalculation*>(currentItem->dataObject().p());
|
2013-03-13 07:51:26 -05:00
|
|
|
caseGroup = currentObject->parentStatisticalCollection();
|
2013-02-15 01:44:45 -06:00
|
|
|
parentCollectionItem = currentItem->parent();
|
|
|
|
position = itemIndex.row();
|
|
|
|
collectionIndex = itemIndex.parent();
|
|
|
|
}
|
2013-02-21 05:00:49 -06:00
|
|
|
else if (dynamic_cast<RimStatisticalCollection*>(currentItem->dataObject().p()))
|
2013-02-15 01:44:45 -06:00
|
|
|
{
|
2013-02-21 05:00:49 -06:00
|
|
|
caseGroup = dynamic_cast<RimStatisticalCollection*>(currentItem->dataObject().p());
|
2013-02-15 01:44:45 -06:00
|
|
|
parentCollectionItem = currentItem;
|
|
|
|
position = parentCollectionItem->childCount();
|
|
|
|
collectionIndex = itemIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
beginInsertRows(collectionIndex, position, position);
|
|
|
|
|
|
|
|
RimStatisticalCalculation* createdObject = caseGroup->createAndAppendStatisticalCalculation();
|
|
|
|
caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentCollectionItem, position, createdObject);
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
insertedModelIndex = index(position, 0, collectionIndex);
|
|
|
|
|
|
|
|
return createdObject;
|
|
|
|
}
|
|
|
|
|
2013-03-14 03:50:40 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimIdenticalGridCaseGroup* RimUiTreeModelPdm::addCaseGroup(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex)
|
|
|
|
{
|
|
|
|
RimProject* proj = RIApplication::instance()->project();
|
|
|
|
CVF_ASSERT(proj);
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
|
|
|
|
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
QModelIndex rootIndex = itemIndex.parent();
|
|
|
|
caf::PdmUiTreeItem* rootTreeItem = currentItem->parent();
|
|
|
|
|
2013-03-19 05:14:32 -05:00
|
|
|
// New case group is inserted before the last item, the script item
|
|
|
|
int position = rootTreeItem->childCount() - 1;
|
2013-03-14 03:50:40 -05:00
|
|
|
|
|
|
|
beginInsertRows(rootIndex, position, position);
|
|
|
|
|
|
|
|
RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup;
|
|
|
|
proj->caseGroups().push_back(createdObject);
|
|
|
|
|
2013-03-20 01:14:27 -05:00
|
|
|
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(rootTreeItem, position, createdObject);
|
2013-03-14 03:50:40 -05:00
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
insertedModelIndex = index(position, 0, rootIndex);
|
|
|
|
|
|
|
|
return createdObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-19 06:47:38 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-20 01:42:26 -05:00
|
|
|
void RimUiTreeModelPdm::addObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects)
|
2013-03-19 06:47:38 -05:00
|
|
|
{
|
|
|
|
RimProject* proj = RIApplication::instance()->project();
|
|
|
|
CVF_ASSERT(proj);
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
|
|
|
|
RimIdenticalGridCaseGroup* gridCaseGroup = NULL;
|
|
|
|
RimCaseCollection* caseCollection = NULL;
|
|
|
|
|
|
|
|
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
gridCaseGroup = dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p());
|
|
|
|
caseCollection = gridCaseGroup->caseCollection();
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
caseCollection = dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p());
|
|
|
|
gridCaseGroup = caseCollection->parentCaseGroup();
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimReservoir*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimReservoir* rimReservoir = dynamic_cast<RimReservoir*>(currentItem->dataObject().p());
|
|
|
|
caseCollection = rimReservoir->parentCaseCollection();
|
|
|
|
gridCaseGroup = caseCollection->parentCaseGroup();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVF_ASSERT(caseCollection);
|
|
|
|
CVF_ASSERT(gridCaseGroup);
|
|
|
|
|
|
|
|
if (gridCaseGroup)
|
|
|
|
{
|
2013-03-20 01:42:26 -05:00
|
|
|
std::vector<caf::PdmPointer<RimResultReservoir> > typedObjects;
|
|
|
|
pdmObjects.createCopyByType(&typedObjects);
|
|
|
|
|
|
|
|
RigEclipseCase* mainEclipseCase = NULL;
|
|
|
|
if (gridCaseGroup->caseCollection()->reservoirs().size() > 0)
|
|
|
|
{
|
|
|
|
RimReservoir* mainReservoir = gridCaseGroup->caseCollection()->reservoirs()[0];;
|
|
|
|
mainEclipseCase = mainReservoir->reservoirData();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < typedObjects.size(); i++)
|
|
|
|
{
|
|
|
|
RimResultReservoir* rimResultReservoir = typedObjects[i];
|
|
|
|
|
|
|
|
if (gridCaseGroup->mainGrid() == NULL)
|
|
|
|
{
|
|
|
|
rimResultReservoir->openEclipseGridFile();
|
|
|
|
mainEclipseCase = rimResultReservoir->reservoirData();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!rimResultReservoir->openAndReadActiveCellData(mainEclipseCase))
|
|
|
|
{
|
|
|
|
CVF_ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proj->insertCaseInCaseGroup(gridCaseGroup, rimResultReservoir);
|
|
|
|
|
|
|
|
caf::PdmObjectGroup::initAfterReadTraversal(rimResultReservoir);
|
|
|
|
|
|
|
|
{
|
|
|
|
QModelIndex rootIndex = getModelIndexFromPdmObject(caseCollection);
|
|
|
|
caf::PdmUiTreeItem* caseCollectionUiItem = getTreeItemFromIndex(rootIndex);
|
|
|
|
|
|
|
|
int position = rowCount(rootIndex);
|
|
|
|
beginInsertRows(rootIndex, position, position);
|
|
|
|
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(caseCollectionUiItem, -1, rimResultReservoir);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
2013-03-20 07:49:32 -05:00
|
|
|
|
|
|
|
for (size_t i = 0; i < rimResultReservoir->reservoirViews.size(); i++)
|
|
|
|
{
|
|
|
|
RimReservoirView* riv = rimResultReservoir->reservoirViews()[i];
|
|
|
|
riv->loadDataAndUpdate();
|
|
|
|
}
|
2013-03-20 01:42:26 -05:00
|
|
|
}
|
2013-03-19 06:47:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 06:08:40 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimUiTreeModelPdm::deleteObjectFromPdmPointersField(const QModelIndex& itemIndex)
|
|
|
|
{
|
|
|
|
if (!itemIndex.isValid())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
CVF_ASSERT(currentItem);
|
|
|
|
|
|
|
|
caf::PdmObject* currentPdmObject = currentItem->dataObject().p();
|
|
|
|
CVF_ASSERT(currentPdmObject);
|
|
|
|
|
|
|
|
std::vector<caf::PdmFieldHandle*> parentFields;
|
|
|
|
currentPdmObject->parentFields(parentFields);
|
|
|
|
|
|
|
|
if (parentFields.size() == 1)
|
|
|
|
{
|
|
|
|
beginRemoveRows(itemIndex.parent(), itemIndex.row(), itemIndex.row());
|
|
|
|
if (currentItem->parent())
|
|
|
|
{
|
|
|
|
currentItem->parent()->removeChildren(itemIndex.row(), 1);
|
|
|
|
}
|
|
|
|
endRemoveRows();
|
|
|
|
|
|
|
|
caf::PdmPointersField<RimIdenticalGridCaseGroup*>* caseGroup = dynamic_cast<caf::PdmPointersField<RimIdenticalGridCaseGroup*> *>(parentFields[0]);
|
|
|
|
if (caseGroup)
|
|
|
|
{
|
|
|
|
caseGroup->removeChildObject(currentPdmObject);
|
|
|
|
|
|
|
|
delete currentPdmObject;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|