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 "RimUiTreeModelPdm.h"
|
|
|
|
#include "RimCellRangeFilter.h"
|
|
|
|
#include "RimCellRangeFilterCollection.h"
|
|
|
|
|
|
|
|
#include "cafPdmObject.h"
|
|
|
|
#include "RimCellPropertyFilter.h"
|
|
|
|
#include "RimCellPropertyFilterCollection.h"
|
|
|
|
|
|
|
|
#include "RimReservoirView.h"
|
2013-03-22 11:30:50 -05:00
|
|
|
#include "RiuViewer.h"
|
2012-05-18 02:45:23 -05:00
|
|
|
#include "RimCalcScript.h"
|
2013-03-22 10:24:42 -05:00
|
|
|
#include "RiaApplication.h"
|
2013-03-22 11:30:50 -05:00
|
|
|
#include "RiuMainWindow.h"
|
2012-06-26 09:10:41 -05:00
|
|
|
#include "RimInputProperty.h"
|
|
|
|
#include "RimInputPropertyCollection.h"
|
|
|
|
#include "cafPdmField.h"
|
2013-03-22 10:40:41 -05:00
|
|
|
#include "RimInputCase.h"
|
2013-03-22 08:24:41 -05:00
|
|
|
#include "RimStatisticsCase.h"
|
2013-03-22 10:40:41 -05:00
|
|
|
#include "RimResultCase.h"
|
2013-04-07 10:27:45 -05:00
|
|
|
#include "RigGridManager.h"
|
2013-04-08 05:16:38 -05:00
|
|
|
#include "RimCase.h"
|
|
|
|
#include "RigCaseData.h"
|
2013-04-16 04:19:37 -05:00
|
|
|
#include "RimMimeData.h"
|
2013-05-06 03:55:00 -05:00
|
|
|
#include "RimCaseCollection.h"
|
|
|
|
#include "RimIdenticalGridCaseGroup.h"
|
|
|
|
#include "RimProject.h"
|
|
|
|
#include "RimScriptCollection.h"
|
|
|
|
#include "RimWellCollection.h"
|
|
|
|
#include "cafPdmFieldCvfMat4d.h"
|
|
|
|
#include "cafPdmFieldCvfColor.h"
|
|
|
|
#include "RimResultSlot.h"
|
|
|
|
#include "RimCellEdgeResultSlot.h"
|
|
|
|
#include "Rim3dOverlayInfoConfig.h"
|
|
|
|
#include "RimReservoirCellResultsCacher.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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-21 07:41:44 -05:00
|
|
|
/// TO BE DELETED
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-21 07:41:44 -05:00
|
|
|
bool RimUiTreeModelPdm::insertRows_special(int position, int rows, const QModelIndex &parent /*= QModelIndex()*/)
|
2012-05-18 02:45:23 -05:00
|
|
|
{
|
|
|
|
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
|
2013-03-21 07:41:44 -05:00
|
|
|
removeRows_special(itemIndex.row(), 1, itemIndex.parent());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
propertyFilterCollection->remove(propertyFilter);
|
|
|
|
delete propertyFilter;
|
|
|
|
|
|
|
|
if (wasFilterActive)
|
|
|
|
{
|
|
|
|
propertyFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::PROPERTY_FILTERED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wasSomeFilterActive)
|
|
|
|
{
|
|
|
|
propertyFilterCollection->reservoirView()->createDisplayModelAndRedraw();
|
|
|
|
}
|
2013-03-20 09:04:28 -05:00
|
|
|
|
|
|
|
clearClipboard();
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
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
|
2013-03-21 07:41:44 -05:00
|
|
|
removeRows_special(itemIndex.row(), 1, itemIndex.parent());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
rangeFilterCollection->remove(rangeFilter);
|
|
|
|
delete rangeFilter;
|
|
|
|
|
|
|
|
if (wasFilterActive)
|
|
|
|
{
|
|
|
|
rangeFilterCollection->reservoirView()->scheduleGeometryRegen(RivReservoirViewPartMgr::PROPERTY_FILTERED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wasSomeFilterActive)
|
|
|
|
{
|
|
|
|
rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw();
|
|
|
|
}
|
|
|
|
|
2013-03-20 09:04:28 -05:00
|
|
|
clearClipboard();
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
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
|
2013-03-21 07:41:44 -05:00
|
|
|
removeRows_special(itemIndex.row(), 1, itemIndex.parent());
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
reservoirView->eclipseCase()->removeReservoirView(reservoirView);
|
|
|
|
delete reservoirView;
|
|
|
|
|
2013-03-20 09:04:28 -05:00
|
|
|
clearClipboard();
|
|
|
|
|
2012-05-18 02:45:23 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-23 04:12:47 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 09:43:42 -05:00
|
|
|
void RimUiTreeModelPdm::deleteReservoir(RimCase* reservoir)
|
2012-10-23 04:12:47 -05:00
|
|
|
{
|
2013-04-05 07:18:34 -05:00
|
|
|
if (reservoir->parentCaseCollection())
|
2013-03-20 09:04:28 -05:00
|
|
|
{
|
2013-04-08 05:16:38 -05:00
|
|
|
RimCaseCollection* caseCollection = reservoir->parentCaseCollection();
|
|
|
|
QModelIndex caseCollectionModelIndex = getModelIndexFromPdmObject(caseCollection);
|
|
|
|
if (!caseCollectionModelIndex.isValid()) return;
|
2012-10-23 04:12:47 -05:00
|
|
|
|
2013-04-08 05:16:38 -05:00
|
|
|
QModelIndex mi = getModelIndexFromPdmObjectRecursive(caseCollectionModelIndex, reservoir);
|
|
|
|
if (mi.isValid())
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(mi);
|
|
|
|
CVF_ASSERT(uiItem);
|
2012-10-23 04:12:47 -05:00
|
|
|
|
2013-04-08 05:16:38 -05:00
|
|
|
// Remove Ui items pointing at the pdm object to delete
|
|
|
|
removeRows_special(mi.row(), 1, mi.parent());
|
|
|
|
}
|
2013-04-05 07:18:34 -05:00
|
|
|
|
2013-04-08 05:16:38 -05:00
|
|
|
if (RimIdenticalGridCaseGroup::isStatisticsCaseCollection(caseCollection))
|
|
|
|
{
|
|
|
|
RimIdenticalGridCaseGroup* caseGroup = caseCollection->parentCaseGroup();
|
|
|
|
CVF_ASSERT(caseGroup);
|
2013-03-22 05:47:46 -05:00
|
|
|
|
2013-04-08 05:16:38 -05:00
|
|
|
caseGroup->statisticsCaseCollection()->reservoirs.removeChildObject(reservoir);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
|
|
|
proj->removeCaseFromAllGroups(reservoir);
|
|
|
|
}
|
2013-03-22 05:47:46 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-22 09:50:44 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2013-04-05 07:18:34 -05:00
|
|
|
QModelIndex mi = getModelIndexFromPdmObject(reservoir);
|
|
|
|
if (mi.isValid())
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(mi);
|
|
|
|
CVF_ASSERT(uiItem);
|
|
|
|
|
|
|
|
// Remove Ui items pointing at the pdm object to delete
|
|
|
|
removeRows_special(mi.row(), 1, mi.parent());
|
|
|
|
}
|
|
|
|
|
2013-03-22 05:47:46 -05:00
|
|
|
proj->removeCaseFromAllGroups(reservoir);
|
|
|
|
}
|
2012-10-23 04:12:47 -05:00
|
|
|
|
|
|
|
delete reservoir;
|
2013-03-20 09:04:28 -05:00
|
|
|
|
|
|
|
clearClipboard();
|
2012-10-23 04:12:47 -05:00
|
|
|
}
|
|
|
|
|
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-04-22 03:04:37 -05:00
|
|
|
int position = 0;
|
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-04-22 03:04:37 -05:00
|
|
|
position = itemIndex.row();
|
2013-02-15 02:21:28 -06:00
|
|
|
}
|
2013-03-22 09:43:42 -05:00
|
|
|
else if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
|
2013-02-15 02:21:28 -06:00
|
|
|
{
|
|
|
|
collectionItem = currentItem;
|
2013-03-08 04:14:27 -06:00
|
|
|
collectionIndex = itemIndex;
|
2013-04-22 03:04:37 -05:00
|
|
|
position = collectionItem->childCount();
|
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)
|
|
|
|
{
|
2013-03-22 09:43:42 -05:00
|
|
|
RimCase* rimReservoir = dynamic_cast<RimCase*>(collectionItem->dataObject().p());
|
2013-04-12 05:03:04 -05:00
|
|
|
rimReservoir->openEclipseGridFile();
|
2013-04-08 05:16:38 -05:00
|
|
|
|
2013-02-15 02:21:28 -06:00
|
|
|
RimReservoirView* insertedView = rimReservoir->createAndAddReservoirView();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-04-11 03:35:33 -05:00
|
|
|
// Must be run before buildViewItems, as wells are created in this function
|
|
|
|
insertedView->loadDataAndUpdate();
|
|
|
|
|
2013-04-22 03:04:37 -05:00
|
|
|
beginInsertRows(collectionIndex, position, position);
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-03-20 01:14:27 -05:00
|
|
|
// NOTE: -1 as second argument indicates append
|
2013-04-22 03:04:37 -05:00
|
|
|
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(collectionItem, position, insertedView);
|
2013-03-20 01:14:27 -05:00
|
|
|
|
2013-02-15 02:21:28 -06:00
|
|
|
endInsertRows();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2013-04-22 03:04:37 -05:00
|
|
|
insertedModelIndex = index(position, 0, collectionIndex);
|
|
|
|
|
2013-02-15 02:21:28 -06:00
|
|
|
return insertedView;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimUiTreeModelPdm::updateScriptPaths()
|
|
|
|
{
|
2013-03-22 09:50:44 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-03-22 09:50:44 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
if (!proj || !proj->scriptCollection()) return;
|
|
|
|
|
|
|
|
RimScriptCollection* changedSColl = proj->scriptCollection()->findScriptCollection(path);
|
|
|
|
if (changedSColl)
|
|
|
|
{
|
|
|
|
changedSColl->readContentFromDisc();
|
2013-05-13 05:00:52 -05:00
|
|
|
this->updateUiSubTree(changedSColl);
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
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-22 09:43:42 -05:00
|
|
|
std::vector<RimInputCase*> parentObjects;
|
2013-03-13 07:51:26 -05:00
|
|
|
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-22 09:43:42 -05:00
|
|
|
RimInputCase* 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
|
|
|
}
|
|
|
|
|
2013-05-13 05:00:52 -05:00
|
|
|
this->updateUiSubTree(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
|
2013-03-21 07:41:44 -05:00
|
|
|
removeRows_special(itemIndex.row(), 1, 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-22 09:43:42 -05:00
|
|
|
std::vector<RimInputCase*> parentObjects2;
|
2013-03-13 07:51:26 -05:00
|
|
|
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-22 09:43:42 -05:00
|
|
|
RimInputCase* 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;
|
2013-03-20 09:04:28 -05:00
|
|
|
|
|
|
|
clearClipboard();
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
2012-10-23 04:12:47 -05:00
|
|
|
|
2013-02-15 01:44:45 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-03-22 04:03:51 -05:00
|
|
|
RimStatisticsCase* RimUiTreeModelPdm::addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex)
|
2013-02-15 01:44:45 -06:00
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
|
|
|
|
QModelIndex collectionIndex;
|
2013-03-21 04:31:58 -05:00
|
|
|
RimIdenticalGridCaseGroup* caseGroup = NULL;
|
2013-02-15 01:44:45 -06:00
|
|
|
caf::PdmUiTreeItem* parentCollectionItem = NULL;
|
|
|
|
int position = 0;
|
|
|
|
|
2013-03-22 04:03:51 -05:00
|
|
|
if (dynamic_cast<RimStatisticsCase*>(currentItem->dataObject().p()))
|
2013-02-15 01:44:45 -06:00
|
|
|
{
|
2013-03-22 04:03:51 -05:00
|
|
|
RimStatisticsCase* currentObject = dynamic_cast<RimStatisticsCase*>(currentItem->dataObject().p());
|
|
|
|
caseGroup = currentObject->parentStatisticsCaseCollection()->parentCaseGroup();
|
2013-02-15 01:44:45 -06:00
|
|
|
parentCollectionItem = currentItem->parent();
|
|
|
|
position = itemIndex.row();
|
|
|
|
collectionIndex = itemIndex.parent();
|
|
|
|
}
|
2013-03-22 05:47:46 -05:00
|
|
|
else if (dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
|
2013-02-15 01:44:45 -06:00
|
|
|
{
|
2013-03-22 05:47:46 -05:00
|
|
|
RimCaseCollection* statColl = dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p());
|
2013-03-21 04:31:58 -05:00
|
|
|
caseGroup = statColl->parentCaseGroup();
|
2013-02-15 01:44:45 -06:00
|
|
|
parentCollectionItem = currentItem;
|
|
|
|
position = parentCollectionItem->childCount();
|
|
|
|
collectionIndex = itemIndex;
|
|
|
|
}
|
|
|
|
|
2013-03-22 05:47:46 -05:00
|
|
|
if (parentCollectionItem && caseGroup)
|
|
|
|
{
|
|
|
|
beginInsertRows(collectionIndex, position, position);
|
2013-02-15 01:44:45 -06:00
|
|
|
|
2013-05-08 03:41:56 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2013-03-22 05:47:46 -05:00
|
|
|
RimStatisticsCase* createdObject = caseGroup->createAndAppendStatisticsCase();
|
2013-05-08 03:41:56 -05:00
|
|
|
proj->assignCaseIdToCase(createdObject);
|
|
|
|
|
2013-03-22 05:47:46 -05:00
|
|
|
caf::PdmUiTreeItem* childItem = new caf::PdmUiTreeItem(parentCollectionItem, position, createdObject);
|
2013-02-15 01:44:45 -06:00
|
|
|
|
2013-03-22 05:47:46 -05:00
|
|
|
endInsertRows();
|
2013-02-15 01:44:45 -06:00
|
|
|
|
2013-03-22 05:47:46 -05:00
|
|
|
insertedModelIndex = index(position, 0, collectionIndex);
|
2013-02-15 01:44:45 -06:00
|
|
|
|
2013-03-22 05:47:46 -05:00
|
|
|
return createdObject;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-02-15 01:44:45 -06:00
|
|
|
}
|
|
|
|
|
2013-03-14 03:50:40 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2013-04-11 04:03:52 -05:00
|
|
|
RimIdenticalGridCaseGroup* RimUiTreeModelPdm::addCaseGroup(QModelIndex& insertedModelIndex)
|
2013-03-14 03:50:40 -05:00
|
|
|
{
|
2013-03-22 09:50:44 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2013-03-14 03:50:40 -05:00
|
|
|
CVF_ASSERT(proj);
|
|
|
|
|
2013-04-11 04:03:52 -05:00
|
|
|
QModelIndex scriptModelIndex = getModelIndexFromPdmObject(proj->scriptCollection());
|
|
|
|
if (!scriptModelIndex.isValid()) return NULL;
|
2013-03-14 03:50:40 -05:00
|
|
|
|
2013-04-11 04:03:52 -05:00
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(scriptModelIndex);
|
|
|
|
if (!currentItem) return NULL;
|
2013-03-14 03:50:40 -05:00
|
|
|
|
2013-04-11 04:03:52 -05:00
|
|
|
QModelIndex rootIndex = scriptModelIndex.parent();
|
|
|
|
caf::PdmUiTreeItem* rootTreeItem = currentItem->parent();
|
2013-03-14 03:50:40 -05:00
|
|
|
|
2013-04-11 04:03:52 -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
|
|
|
|
2013-04-11 04:03:52 -05:00
|
|
|
beginInsertRows(rootIndex, position, position);
|
2013-03-14 03:50:40 -05:00
|
|
|
|
2013-04-11 04:03:52 -05:00
|
|
|
RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup;
|
2013-05-10 08:35:33 -05:00
|
|
|
proj->assignIdToCaseGroup(createdObject);
|
|
|
|
|
2013-05-08 03:41:56 -05:00
|
|
|
RimCase* createdReservoir = createdObject->createAndAppendStatisticsCase();
|
|
|
|
proj->assignCaseIdToCase(createdReservoir);
|
2013-04-11 07:08:06 -05:00
|
|
|
createdObject->name = QString("Grid Case Group %1").arg(position + 1);
|
2013-04-11 04:03:52 -05:00
|
|
|
proj->caseGroups().push_back(createdObject);
|
2013-03-14 03:50:40 -05:00
|
|
|
|
2013-04-11 04:03:52 -05:00
|
|
|
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(rootTreeItem, position, createdObject);
|
|
|
|
endInsertRows();
|
2013-03-14 03:50:40 -05:00
|
|
|
|
2013-04-11 04:03:52 -05:00
|
|
|
insertedModelIndex = index(position, 0, rootIndex);
|
|
|
|
|
|
|
|
return createdObject;
|
2013-03-14 03:50:40 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-03-22 09:50:44 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2013-03-19 06:47:38 -05:00
|
|
|
CVF_ASSERT(proj);
|
|
|
|
|
2013-04-05 06:22:36 -05:00
|
|
|
RimIdenticalGridCaseGroup* gridCaseGroup = gridCaseGroupFromItemIndex(itemIndex);
|
2013-03-19 06:47:38 -05:00
|
|
|
if (gridCaseGroup)
|
|
|
|
{
|
2013-03-22 09:43:42 -05:00
|
|
|
std::vector<caf::PdmPointer<RimResultCase> > typedObjects;
|
2013-03-20 01:42:26 -05:00
|
|
|
pdmObjects.createCopyByType(&typedObjects);
|
|
|
|
|
2013-04-07 10:27:45 -05:00
|
|
|
if (typedObjects.size() == 0)
|
2013-04-12 04:12:53 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-04-07 10:27:45 -05:00
|
|
|
|
|
|
|
RimResultCase* mainResultCase = NULL;
|
|
|
|
std::vector< std::vector<int> > mainCaseGridDimensions;
|
|
|
|
|
|
|
|
// Read out main grid and main grid dimensions if present in case group
|
|
|
|
if (gridCaseGroup->mainCase())
|
2013-04-12 04:12:53 -05:00
|
|
|
{
|
2013-04-07 10:27:45 -05:00
|
|
|
mainResultCase = dynamic_cast<RimResultCase*>(gridCaseGroup->mainCase());
|
|
|
|
CVF_ASSERT(mainResultCase);
|
|
|
|
|
|
|
|
mainResultCase->readGridDimensions(mainCaseGridDimensions);
|
2013-03-20 01:42:26 -05:00
|
|
|
}
|
|
|
|
|
2013-04-07 10:27:45 -05:00
|
|
|
// Add cases to case group
|
2013-03-20 01:42:26 -05:00
|
|
|
for (size_t i = 0; i < typedObjects.size(); i++)
|
|
|
|
{
|
2013-03-22 09:43:42 -05:00
|
|
|
RimResultCase* rimResultReservoir = typedObjects[i];
|
2013-03-20 01:42:26 -05:00
|
|
|
|
2013-05-08 03:41:56 -05:00
|
|
|
proj->assignCaseIdToCase(rimResultReservoir);
|
|
|
|
|
2013-03-21 07:56:50 -05:00
|
|
|
if (gridCaseGroup->contains(rimResultReservoir))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-04-07 10:27:45 -05:00
|
|
|
if (!mainResultCase)
|
2013-03-20 01:42:26 -05:00
|
|
|
{
|
|
|
|
rimResultReservoir->openEclipseGridFile();
|
2013-04-07 10:27:45 -05:00
|
|
|
rimResultReservoir->readGridDimensions(mainCaseGridDimensions);
|
|
|
|
|
|
|
|
mainResultCase = rimResultReservoir;
|
2013-03-20 01:42:26 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-07 10:27:45 -05:00
|
|
|
std::vector< std::vector<int> > caseGridDimensions;
|
|
|
|
rimResultReservoir->readGridDimensions(caseGridDimensions);
|
|
|
|
|
|
|
|
bool identicalGrid = RigGridManager::isGridDimensionsEqual(mainCaseGridDimensions, caseGridDimensions);
|
|
|
|
if (!identicalGrid)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rimResultReservoir->openAndReadActiveCellData(mainResultCase->reservoirData()))
|
2013-03-20 01:42:26 -05:00
|
|
|
{
|
|
|
|
CVF_ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proj->insertCaseInCaseGroup(gridCaseGroup, rimResultReservoir);
|
|
|
|
|
|
|
|
caf::PdmObjectGroup::initAfterReadTraversal(rimResultReservoir);
|
|
|
|
|
|
|
|
{
|
2013-04-05 06:22:36 -05:00
|
|
|
QModelIndex rootIndex = getModelIndexFromPdmObject(gridCaseGroup->caseCollection());
|
2013-03-20 01:42:26 -05:00
|
|
|
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-04-23 04:24:54 -05:00
|
|
|
else if (caseFromItemIndex(itemIndex))
|
|
|
|
{
|
|
|
|
std::vector<caf::PdmPointer<RimReservoirView> > typedObjects;
|
|
|
|
pdmObjects.createCopyByType(&typedObjects);
|
|
|
|
|
|
|
|
if (typedObjects.size() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RimCase* rimCase = caseFromItemIndex(itemIndex);
|
|
|
|
QModelIndex collectionIndex = getModelIndexFromPdmObject(rimCase);
|
|
|
|
caf::PdmUiTreeItem* collectionItem = getTreeItemFromIndex(collectionIndex);
|
|
|
|
|
|
|
|
// Add cases to case group
|
|
|
|
for (size_t i = 0; i < typedObjects.size(); i++)
|
|
|
|
{
|
|
|
|
RimReservoirView* rimReservoirView = typedObjects[i];
|
|
|
|
QString nameOfCopy = QString("Copy of ") + rimReservoirView->name;
|
|
|
|
rimReservoirView->name = nameOfCopy;
|
|
|
|
|
|
|
|
rimReservoirView->setEclipseCase(rimCase);
|
|
|
|
|
|
|
|
// Delete all wells to be able to copy/paste between cases, as the wells differ between cases
|
|
|
|
rimReservoirView->wellCollection()->wells().deleteAllChildObjects();
|
|
|
|
|
|
|
|
caf::PdmObjectGroup::initAfterReadTraversal(rimReservoirView);
|
|
|
|
|
|
|
|
rimReservoirView->loadDataAndUpdate();
|
|
|
|
rimCase->reservoirViews().push_back(rimReservoirView);
|
|
|
|
|
|
|
|
int position = static_cast<int>(rimCase->reservoirViews().size());
|
|
|
|
beginInsertRows(collectionIndex, position, position);
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(collectionItem, position, rimReservoirView);
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 06:47:38 -05:00
|
|
|
}
|
|
|
|
|
2013-04-05 06:22:36 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimUiTreeModelPdm::moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects)
|
|
|
|
{
|
|
|
|
addObjects(itemIndex, pdmObjects);
|
|
|
|
|
|
|
|
// Delete objects from original container
|
|
|
|
std::vector<caf::PdmPointer<RimResultCase> > typedObjects;
|
|
|
|
pdmObjects.objectsByType(&typedObjects);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < typedObjects.size(); i++)
|
|
|
|
{
|
|
|
|
RimCase* rimReservoir = typedObjects[i];
|
|
|
|
deleteReservoir(rimReservoir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 09:04:28 -05:00
|
|
|
clearClipboard();
|
|
|
|
|
2013-03-20 06:08:40 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-20 09:04:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimUiTreeModelPdm::clearClipboard()
|
|
|
|
{
|
|
|
|
// We use QModelIndex to identify a selection on the clipboard
|
|
|
|
// When we delete or move an entity, the clipboard data might be invalid
|
|
|
|
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
if (clipboard)
|
|
|
|
{
|
|
|
|
if (dynamic_cast<const MimeDataWithIndexes*>(clipboard->mimeData()))
|
|
|
|
{
|
|
|
|
clipboard->clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 07:41:44 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
Qt::DropActions RimUiTreeModelPdm::supportedDropActions() const
|
|
|
|
{
|
|
|
|
return Qt::CopyAction | Qt::MoveAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
Qt::ItemFlags RimUiTreeModelPdm::flags(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags defaultFlags = caf::UiTreeModelPdm::flags(index);
|
|
|
|
if (index.isValid())
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(index);
|
|
|
|
CVF_ASSERT(currentItem);
|
|
|
|
|
|
|
|
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()) ||
|
|
|
|
dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
return Qt::ItemIsDropEnabled | defaultFlags;
|
|
|
|
}
|
2013-03-22 09:43:42 -05:00
|
|
|
else if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
|
2013-03-21 07:41:44 -05:00
|
|
|
{
|
|
|
|
// TODO: Remember to handle reservoir holding the main grid
|
|
|
|
return Qt::ItemIsDragEnabled | defaultFlags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimUiTreeModelPdm::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
const MimeDataWithIndexes* myMimeData = qobject_cast<const MimeDataWithIndexes*>(data);
|
|
|
|
if (myMimeData && parent.isValid())
|
|
|
|
{
|
|
|
|
caf::PdmObjectGroup pog;
|
|
|
|
|
|
|
|
for (int i = 0; i < myMimeData->indexes().size(); i++)
|
|
|
|
{
|
|
|
|
QModelIndex mi = myMimeData->indexes().at(i);
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(mi);
|
|
|
|
caf::PdmObject* pdmObj = currentItem->dataObject().p();
|
|
|
|
|
|
|
|
pog.objects().push_back(pdmObj);
|
|
|
|
}
|
|
|
|
|
2013-04-05 06:22:36 -05:00
|
|
|
if (action == Qt::CopyAction)
|
2013-03-21 07:41:44 -05:00
|
|
|
{
|
2013-04-08 05:16:38 -05:00
|
|
|
addObjects(parent, pog);
|
2013-04-05 06:22:36 -05:00
|
|
|
}
|
|
|
|
else if (action == Qt::MoveAction)
|
|
|
|
{
|
|
|
|
moveObjects(parent, pog);
|
2013-03-21 07:41:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QMimeData* RimUiTreeModelPdm::mimeData(const QModelIndexList &indexes) const
|
|
|
|
{
|
|
|
|
MimeDataWithIndexes* myObj = new MimeDataWithIndexes();
|
|
|
|
myObj->setIndexes(indexes);
|
|
|
|
return myObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QStringList RimUiTreeModelPdm::mimeTypes() const
|
|
|
|
{
|
|
|
|
QStringList types;
|
|
|
|
types << MimeDataWithIndexes::formatName();
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
2013-04-05 06:22:36 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Return grid case group when QModelIndex points to grid case group, case collection or case in a grid case group
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimIdenticalGridCaseGroup* RimUiTreeModelPdm::gridCaseGroupFromItemIndex(const QModelIndex& itemIndex)
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
|
|
|
|
RimIdenticalGridCaseGroup* gridCaseGroup = NULL;
|
|
|
|
|
|
|
|
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
gridCaseGroup = dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p());
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimCaseCollection* caseCollection = dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p());
|
|
|
|
CVF_ASSERT(caseCollection);
|
|
|
|
|
|
|
|
gridCaseGroup = caseCollection->parentCaseGroup();
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimCase* rimReservoir = dynamic_cast<RimCase*>(currentItem->dataObject().p());
|
|
|
|
CVF_ASSERT(rimReservoir);
|
|
|
|
|
|
|
|
RimCaseCollection* caseCollection = rimReservoir->parentCaseCollection();
|
|
|
|
if (caseCollection)
|
|
|
|
{
|
|
|
|
gridCaseGroup = caseCollection->parentCaseGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gridCaseGroup;
|
|
|
|
}
|
|
|
|
|
2013-04-22 04:54:41 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimUiTreeModelPdm::addToParentAndBuildUiItems(caf::PdmUiTreeItem* parentTreeItem, int position, caf::PdmObject* pdmObject)
|
|
|
|
{
|
|
|
|
QModelIndex parentModelIndex;
|
|
|
|
|
|
|
|
if (parentTreeItem && parentTreeItem->dataObject())
|
|
|
|
{
|
|
|
|
parentModelIndex = getModelIndexFromPdmObject(parentTreeItem->dataObject());
|
|
|
|
}
|
|
|
|
|
|
|
|
beginInsertRows(parentModelIndex, position, position);
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(parentTreeItem, position, pdmObject);
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
2013-04-23 04:24:54 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimCase* RimUiTreeModelPdm::caseFromItemIndex(const QModelIndex& itemIndex)
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
|
|
|
|
|
|
|
RimCase* rimCase = NULL;
|
|
|
|
|
|
|
|
if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
rimCase = dynamic_cast<RimCase*>(currentItem->dataObject().p());
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<RimReservoirView*>(currentItem->dataObject().p()))
|
|
|
|
{
|
|
|
|
RimReservoirView* reservoirView = dynamic_cast<RimReservoirView*>(currentItem->dataObject().p());
|
|
|
|
CVF_ASSERT(reservoirView);
|
|
|
|
|
|
|
|
rimCase = reservoirView->eclipseCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rimCase;
|
|
|
|
}
|
|
|
|
|
2013-04-25 01:47:01 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Set toggle state for list of model indices.
|
|
|
|
///
|
|
|
|
/// NOTE: Set toggle state directly on object, does not use setValueFromUi()
|
|
|
|
/// The caller must make sure the relevant dependencies are updated
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimUiTreeModelPdm::setObjectToggleStateForSelection(QModelIndexList selectedIndexes, int state)
|
|
|
|
{
|
|
|
|
bool toggleOn = (state == Qt::Checked);
|
|
|
|
|
|
|
|
foreach (QModelIndex index, selectedIndexes)
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
caf::PdmUiTreeItem* treeItem = UiTreeModelPdm::getTreeItemFromIndex(index);
|
|
|
|
assert(treeItem);
|
|
|
|
|
|
|
|
caf::PdmObject* obj = treeItem->dataObject();
|
|
|
|
assert(obj);
|
|
|
|
|
|
|
|
if (obj && obj->objectToggleField())
|
|
|
|
{
|
|
|
|
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>* >(obj->objectToggleField());
|
|
|
|
if (field)
|
|
|
|
{
|
|
|
|
// Does not use setValueFromUi(), so the caller must make sure dependencies are updated
|
|
|
|
field->v() = toggleOn;
|
|
|
|
|
|
|
|
emitDataChanged(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|