2015-09-15 16:28:17 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-09-15 16:28:17 +02: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-09-06 10:40:57 +02:00
|
|
|
//
|
2015-09-15 16:28:17 +02: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-09-06 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-09-15 16:28:17 +02:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RicLinkViewFeature.h"
|
|
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
|
|
|
|
|
|
#include "RicLinkVisibleViewsFeature.h"
|
|
|
|
|
|
2018-01-09 10:11:28 +01:00
|
|
|
#include "Rim3dView.h"
|
2019-01-11 13:56:35 +01:00
|
|
|
#include "RimEclipseContourMapView.h"
|
2018-10-24 13:45:46 +02:00
|
|
|
#include "RimGridView.h"
|
2018-11-22 08:46:01 +01:00
|
|
|
#include "RimProject.h"
|
2015-09-22 14:23:51 +02:00
|
|
|
#include "RimViewLinker.h"
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "RimViewLinkerCollection.h"
|
2015-09-15 16:28:17 +02:00
|
|
|
|
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
CAF_CMD_SOURCE_INIT( RicLinkViewFeature, "RicLinkViewFeature" );
|
2015-09-15 16:28:17 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-09-15 16:28:17 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RicLinkViewFeature::isCommandEnabled()
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
std::vector<caf::PdmUiItem*> allSelectedItems;
|
|
|
|
|
std::vector<RimGridView*> selectedGridViews;
|
2019-01-11 13:56:35 +01:00
|
|
|
std::vector<RimEclipseContourMapView*> selectedContourMaps;
|
2018-11-22 08:46:01 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
caf::SelectionManager::instance()->selectedItems( allSelectedItems );
|
|
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedGridViews );
|
|
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedContourMaps );
|
2018-11-22 08:46:01 +01:00
|
|
|
size_t selectedRegularGridViews = selectedGridViews.size() - selectedContourMaps.size();
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( selectedGridViews.size() > 1u && selectedRegularGridViews >= 1u &&
|
|
|
|
|
allSelectedItems.size() == selectedGridViews.size() )
|
2015-09-15 16:28:17 +02:00
|
|
|
{
|
2018-10-24 13:45:46 +02:00
|
|
|
return true;
|
2015-09-24 14:29:13 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-24 13:45:46 +02:00
|
|
|
// Link only the active view to an existing view link collection.
|
|
|
|
|
Rim3dView* activeView = RiaApplication::instance()->activeReservoirView();
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( !activeView ) return false;
|
2018-10-24 13:45:46 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
2018-10-24 13:45:46 +02:00
|
|
|
RimViewLinker* viewLinker = proj->viewLinkerCollection->viewLinker();
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( !viewLinker ) return false;
|
2018-10-24 13:45:46 +02:00
|
|
|
|
|
|
|
|
RimViewController* viewController = activeView->viewController();
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( viewController )
|
2015-09-22 14:23:51 +02:00
|
|
|
{
|
2018-10-24 13:45:46 +02:00
|
|
|
return false;
|
2015-09-24 14:29:13 +02:00
|
|
|
}
|
2019-09-06 10:40:57 +02:00
|
|
|
else if ( !activeView->isMasterView() )
|
2015-09-24 14:29:13 +02:00
|
|
|
{
|
2018-10-24 13:45:46 +02:00
|
|
|
return true;
|
2015-09-22 14:23:51 +02:00
|
|
|
}
|
2015-09-15 16:28:17 +02:00
|
|
|
}
|
2018-10-24 13:45:46 +02:00
|
|
|
return false;
|
2015-09-15 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-09-15 16:28:17 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicLinkViewFeature::onActionTriggered( bool isChecked )
|
2015-09-15 16:28:17 +02:00
|
|
|
{
|
2018-10-24 13:45:46 +02:00
|
|
|
std::vector<caf::PdmUiItem*> allSelectedItems;
|
2019-09-06 10:40:57 +02:00
|
|
|
std::vector<RimGridView*> selectedGridViews;
|
2018-11-22 08:46:01 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
caf::SelectionManager::instance()->selectedItems( allSelectedItems );
|
|
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedGridViews );
|
2018-11-22 08:46:01 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( selectedGridViews.size() > 1u && allSelectedItems.size() == selectedGridViews.size() )
|
2018-10-24 13:45:46 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
RicLinkVisibleViewsFeature::linkViews( selectedGridViews );
|
2018-10-24 13:45:46 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
Rim3dView* activeView = RiaApplication::instance()->activeReservoirView();
|
|
|
|
|
RimGridView* gridView = dynamic_cast<RimGridView*>( activeView );
|
|
|
|
|
if ( gridView )
|
2018-10-24 13:45:46 +02:00
|
|
|
{
|
|
|
|
|
std::vector<RimGridView*> views;
|
2019-09-06 10:40:57 +02:00
|
|
|
views.push_back( gridView );
|
|
|
|
|
RicLinkVisibleViewsFeature::linkViews( views );
|
2018-10-24 13:45:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-09-15 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-09-15 16:28:17 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicLinkViewFeature::setupActionLook( QAction* actionToSetup )
|
2015-09-15 16:28:17 +02:00
|
|
|
{
|
2018-10-24 13:45:46 +02:00
|
|
|
std::vector<RimGridView*> selectedGridViews;
|
2019-09-06 10:40:57 +02:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedGridViews );
|
|
|
|
|
if ( selectedGridViews.size() > 1u )
|
2018-10-24 13:45:46 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
actionToSetup->setText( "Link Selected Views" );
|
2018-10-24 13:45:46 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
actionToSetup->setText( "Link View" );
|
2018-10-24 13:45:46 +02:00
|
|
|
}
|
2019-09-06 10:40:57 +02:00
|
|
|
actionToSetup->setIcon( QIcon( ":/chain.png" ) );
|
2015-09-15 16:28:17 +02:00
|
|
|
}
|