ResInsight/ApplicationCode/Commands/RicNewContourMapViewFeature.cpp

328 lines
14 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- Equinor ASA
2019-01-09 05:48:56 -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.
2019-01-09 05:48:56 -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.
2019-01-09 05:48:56 -06:00
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicNewContourMapViewFeature.h"
#include "Rim3dView.h"
#include "RimCellEdgeColors.h"
#include "RimEclipseContourMapView.h"
#include "RimEclipseContourMapViewCollection.h"
#include "RimEclipseCase.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseView.h"
#include "RimGeoMechContourMapView.h"
#include "RimGeoMechContourMapViewCollection.h"
#include "RimGeoMechCase.h"
#include "RimGeoMechCellColors.h"
#include "RimGeoMechView.h"
#include "RimFaultInViewCollection.h"
#include "RimSimWellInViewCollection.h"
#include "Riu3DMainWindowTools.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RiaPreferences.h"
#include "cafPdmDocument.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicNewContourMapViewFeature, "RicNewContourMapViewFeature");
//--------------------------------------------------------------------------------------------------
2019-01-09 05:48:56 -06:00
///
//--------------------------------------------------------------------------------------------------
bool RicNewContourMapViewFeature::isCommandEnabled()
{
bool selectedView = caf::SelectionManager::instance()->selectedItemOfType<RimGridView>() != nullptr;
bool selectedCase = caf::SelectionManager::instance()->selectedItemOfType<RimCase>() != nullptr;
bool selectedEclipseContourMapCollection = caf::SelectionManager::instance()->selectedItemOfType<RimEclipseContourMapViewCollection>();
bool selectedGeoMechContourMapCollection = caf::SelectionManager::instance()->selectedItemOfType<RimGeoMechContourMapViewCollection>();
return selectedView || selectedCase || selectedEclipseContourMapCollection || selectedGeoMechContourMapCollection;
}
//--------------------------------------------------------------------------------------------------
2019-01-09 05:48:56 -06:00
///
//--------------------------------------------------------------------------------------------------
void RicNewContourMapViewFeature::onActionTriggered(bool isChecked)
{
RimEclipseView* reservoirView = caf::SelectionManager::instance()->selectedItemOfType<RimEclipseView>();
RimEclipseContourMapView* existingEclipseContourMap =
caf::SelectionManager::instance()->selectedItemOfType<RimEclipseContourMapView>();
RimEclipseCase* eclipseCase = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimEclipseCase>();
RimEclipseContourMapView* eclipseContourMap = nullptr;
RimGeoMechView* geoMechView = caf::SelectionManager::instance()->selectedItemOfType<RimGeoMechView>();
RimGeoMechContourMapView* existingGeoMechContourMap =
caf::SelectionManager::instance()->selectedItemOfType<RimGeoMechContourMapView>();
RimGeoMechCase* geoMechCase = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimGeoMechCase>();
RimGeoMechContourMapView* geoMechContourMap = nullptr;
// Find case to insert into
if (existingEclipseContourMap)
{
eclipseContourMap = createEclipseContourMapFromExistingContourMap(eclipseCase, existingEclipseContourMap);
}
else if (reservoirView)
{
eclipseContourMap = createEclipseContourMapFrom3dView(eclipseCase, reservoirView);
}
else if (eclipseCase)
{
eclipseContourMap = createEclipseContourMap(eclipseCase);
}
else if (existingGeoMechContourMap)
{
geoMechContourMap = createGeoMechContourMapFromExistingContourMap(geoMechCase, existingGeoMechContourMap);
}
else if (geoMechView)
{
geoMechContourMap = createGeoMechContourMapFrom3dView(geoMechCase, geoMechView);
}
else if (geoMechCase)
{
geoMechContourMap = createGeoMechContourMap(geoMechCase);
}
if (eclipseContourMap)
{
// Must be run before buildViewItems, as wells are created in this function
eclipseContourMap->loadDataAndUpdate();
if (eclipseCase)
{
eclipseCase->updateConnectedEditors();
}
caf::SelectionManager::instance()->setSelectedItem(eclipseContourMap);
eclipseContourMap->createDisplayModelAndRedraw();
eclipseContourMap->zoomAll();
Riu3DMainWindowTools::setExpanded(eclipseContourMap);
}
else if (geoMechContourMap)
{
geoMechContourMap->loadDataAndUpdate();
if (geoMechCase)
{
geoMechCase->updateConnectedEditors();
caf::SelectionManager::instance()->setSelectedItem(geoMechContourMap);
geoMechContourMap->createDisplayModelAndRedraw();
geoMechContourMap->zoomAll();
Riu3DMainWindowTools::setExpanded(geoMechContourMap);
}
}
}
//--------------------------------------------------------------------------------------------------
2019-01-09 05:48:56 -06:00
///
//--------------------------------------------------------------------------------------------------
void RicNewContourMapViewFeature::setupActionLook(QAction* actionToSetup)
{
bool contourMapSelected = caf::SelectionManager::instance()->selectedItemOfType<RimEclipseContourMapView>() != nullptr ||
caf::SelectionManager::instance()->selectedItemOfType<RimGeoMechContourMapView>() != nullptr;
bool viewSelected = caf::SelectionManager::instance()->selectedItemOfType<RimEclipseView>() != nullptr ||
caf::SelectionManager::instance()->selectedItemOfType<RimGeoMechView>() != nullptr;
if (contourMapSelected)
{
actionToSetup->setText("Duplicate Contour Map");
}
else if (viewSelected)
{
actionToSetup->setText("New Contour Map From 3d View");
}
else
{
actionToSetup->setText("New Contour Map");
}
actionToSetup->setIcon(QIcon(":/2DMap16x16.png"));
2019-01-09 05:48:56 -06:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseContourMapView* RicNewContourMapViewFeature::createEclipseContourMapFromExistingContourMap(RimEclipseCase* eclipseCase,
RimEclipseContourMapView* existingContourMap)
{
RimEclipseContourMapView* contourMap = dynamic_cast<RimEclipseContourMapView*>(
2019-01-09 05:48:56 -06:00
existingContourMap->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
CVF_ASSERT(contourMap);
contourMap->setEclipseCase(eclipseCase);
contourMap->setBackgroundColor(cvf::Color3f(1.0f, 1.0f, 0.98f)); // Ignore original view background
caf::PdmDocument::updateUiIconStateRecursively(contourMap);
size_t i = eclipseCase->contourMapCollection()->views().size();
contourMap->setName(QString("Contour Map %1").arg(i + 1));
eclipseCase->contourMapCollection()->push_back(contourMap);
// Resolve references after contour map has been inserted into Rim structures
contourMap->resolveReferencesRecursively();
contourMap->initAfterReadRecursively();
return contourMap;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseContourMapView* RicNewContourMapViewFeature::createEclipseContourMapFrom3dView(RimEclipseCase* eclipseCase,
2019-01-09 05:48:56 -06:00
const RimEclipseView* sourceView)
{
RimEclipseContourMapView* contourMap = dynamic_cast<RimEclipseContourMapView*>(sourceView->xmlCapability()->copyAndCastByXmlSerialization(
RimEclipseContourMapView::classKeywordStatic(), sourceView->classKeyword(), caf::PdmDefaultObjectFactory::instance()));
CVF_ASSERT(contourMap);
contourMap->setEclipseCase(eclipseCase);
contourMap->setBackgroundColor(cvf::Color3f(1.0f, 1.0f, 0.98f)); // Ignore original view background
contourMap->setDefaultCustomName();
contourMap->faultCollection()->showFaultCollection = false;
2019-01-09 05:48:56 -06:00
contourMap->wellCollection()->isActive = false;
caf::PdmDocument::updateUiIconStateRecursively(contourMap);
eclipseCase->contourMapCollection()->push_back(contourMap);
contourMap->syncronizeLocalAnnotationsFromGlobal();
// Resolve references after contour map has been inserted into Rim structures
std::vector<caf::PdmFieldHandle*> fieldsWithFailingResolve;
contourMap->resolveReferencesRecursively(&fieldsWithFailingResolve);
// TODO: Introduce the assert when code is stable
// If we have intersections on well paths, the resolving is now failing
2019-01-09 05:48:56 -06:00
// CVF_ASSERT(fieldsWithFailingResolve.empty());
contourMap->initAfterReadRecursively();
return contourMap;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseContourMapView* RicNewContourMapViewFeature::createEclipseContourMap(RimEclipseCase* eclipseCase)
{
RimEclipseContourMapView* contourMap = new RimEclipseContourMapView();
contourMap->setEclipseCase(eclipseCase);
// Set default values
{
contourMap->cellResult()->setResultType(RiaDefines::DYNAMIC_NATIVE);
if (RiaApplication::instance()->preferences()->loadAndShowSoil)
{
contourMap->cellResult()->setResultVariable("SOIL");
2019-01-09 05:48:56 -06:00
}
}
caf::PdmDocument::updateUiIconStateRecursively(contourMap);
size_t i = eclipseCase->contourMapCollection()->views().size();
contourMap->setName(QString("Contour Map %1").arg(i + 1));
eclipseCase->contourMapCollection()->push_back(contourMap);
contourMap->hasUserRequestedAnimation = true;
contourMap->setBackgroundColor(cvf::Color3f(1.0f, 1.0f, 0.98f));
contourMap->initAfterReadRecursively();
return contourMap;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGeoMechContourMapView*
RicNewContourMapViewFeature::createGeoMechContourMapFromExistingContourMap(RimGeoMechCase* geoMechCase,
RimGeoMechContourMapView* existingContourMap)
{
RimGeoMechContourMapView* contourMap = dynamic_cast<RimGeoMechContourMapView*>(
existingContourMap->xmlCapability()->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
CVF_ASSERT(contourMap);
contourMap->setGeoMechCase(geoMechCase);
contourMap->setBackgroundColor(cvf::Color3f(1.0f, 1.0f, 0.98f)); // Ignore original view background
caf::PdmDocument::updateUiIconStateRecursively(contourMap);
size_t i = geoMechCase->contourMapCollection()->views().size();
contourMap->setName(QString("Contour Map %1").arg(i + 1));
geoMechCase->contourMapCollection()->push_back(contourMap);
// Resolve references after contour map has been inserted into Rim structures
contourMap->resolveReferencesRecursively();
contourMap->initAfterReadRecursively();
return contourMap;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGeoMechContourMapView* RicNewContourMapViewFeature::createGeoMechContourMapFrom3dView(RimGeoMechCase* geoMechCase,
const RimGeoMechView* sourceView)
{
RimGeoMechContourMapView* contourMap = dynamic_cast<RimGeoMechContourMapView*>(
sourceView->xmlCapability()->copyAndCastByXmlSerialization(RimGeoMechContourMapView::classKeywordStatic(),
sourceView->classKeyword(),
caf::PdmDefaultObjectFactory::instance()));
CVF_ASSERT(contourMap);
contourMap->setGeoMechCase(geoMechCase);
contourMap->setBackgroundColor(cvf::Color3f(1.0f, 1.0f, 0.98f)); // Ignore original view background
contourMap->setDefaultCustomName();
caf::PdmDocument::updateUiIconStateRecursively(contourMap);
geoMechCase->contourMapCollection()->push_back(contourMap);
// Resolve references after contour map has been inserted into Rim structures
std::vector<caf::PdmFieldHandle*> fieldsWithFailingResolve;
contourMap->resolveReferencesRecursively(&fieldsWithFailingResolve);
contourMap->initAfterReadRecursively();
return contourMap;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGeoMechContourMapView* RicNewContourMapViewFeature::createGeoMechContourMap(RimGeoMechCase* geoMechCase)
{
RimGeoMechContourMapView* contourMap = new RimGeoMechContourMapView();
contourMap->setGeoMechCase(geoMechCase);
caf::PdmDocument::updateUiIconStateRecursively(contourMap);
size_t i = geoMechCase->contourMapCollection()->views().size();
contourMap->setName(QString("Contour Map %1").arg(i + 1));
geoMechCase->contourMapCollection()->push_back(contourMap);
contourMap->hasUserRequestedAnimation = true;
contourMap->setBackgroundColor(cvf::Color3f(1.0f, 1.0f, 0.98f));
contourMap->initAfterReadRecursively();
return contourMap;
}