2015-08-30 06:30:46 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2015-08-30 06:30:46 -05: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 03:40:57 -05:00
|
|
|
//
|
2015-08-30 06:30:46 -05: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 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-08-30 06:30:46 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicLinkVisibleViewsFeature.h"
|
|
|
|
|
2015-09-02 07:22:36 -05:00
|
|
|
#include "RicLinkVisibleViewsFeatureUi.h"
|
|
|
|
|
2019-01-11 06:56:35 -06:00
|
|
|
#include "RimEclipseContourMapView.h"
|
2021-04-05 11:18:34 -05:00
|
|
|
#include "RimGeoMechContourMapView.h"
|
2018-01-16 02:37:08 -06:00
|
|
|
#include "RimGridView.h"
|
2018-11-22 01:46:01 -06:00
|
|
|
#include "RimProject.h"
|
|
|
|
#include "RimViewController.h"
|
2015-09-07 07:29:46 -05:00
|
|
|
#include "RimViewLinker.h"
|
2015-09-08 03:17:35 -05:00
|
|
|
#include "RimViewLinkerCollection.h"
|
2015-08-30 06:30:46 -05:00
|
|
|
|
2018-02-27 09:00:55 -06:00
|
|
|
#include "Riu3DMainWindowTools.h"
|
2015-08-30 06:30:46 -05:00
|
|
|
|
2015-09-02 07:22:36 -05:00
|
|
|
#include "cafPdmUiPropertyViewDialog.h"
|
2015-08-30 06:30:46 -05:00
|
|
|
|
|
|
|
#include <QAction>
|
2019-09-06 03:40:57 -05:00
|
|
|
#include <QTreeView>
|
2015-09-02 07:22:36 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicLinkVisibleViewsFeature, "RicLinkVisibleViewsFeature" );
|
2015-08-30 06:30:46 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-08-30 06:30:46 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicLinkVisibleViewsFeature::isCommandEnabled()
|
|
|
|
{
|
2020-12-14 08:02:27 -06:00
|
|
|
RimProject* proj = RimProject::current();
|
|
|
|
if ( !proj ) return false;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<Rim3dView*> visibleViews;
|
2018-01-15 07:52:22 -06:00
|
|
|
std::vector<RimGridView*> linkedviews;
|
|
|
|
std::vector<RimGridView*> visibleGridViews;
|
2015-09-25 08:22:55 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
proj->allVisibleViews( visibleViews );
|
|
|
|
for ( Rim3dView* view : visibleViews )
|
2018-01-15 07:52:22 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RimGridView* gridView = dynamic_cast<RimGridView*>( view );
|
|
|
|
if ( gridView ) visibleGridViews.push_back( gridView );
|
2018-01-15 07:52:22 -06:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( proj->viewLinkerCollection() && proj->viewLinkerCollection()->viewLinker() )
|
2015-09-25 08:22:55 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
proj->viewLinkerCollection()->viewLinker()->allViews( linkedviews );
|
2015-09-25 08:22:55 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( visibleGridViews.size() >= 2 && ( linkedviews.size() < visibleGridViews.size() ) )
|
2018-10-23 09:32:40 -05:00
|
|
|
{
|
|
|
|
std::vector<RimGridView*> views;
|
2019-10-28 09:39:01 -05:00
|
|
|
findLinkableVisibleViews( views );
|
2018-10-23 09:32:40 -05:00
|
|
|
RicLinkVisibleViewsFeatureUi testUi;
|
2019-09-06 03:40:57 -05:00
|
|
|
testUi.setViews( views );
|
2018-10-23 09:32:40 -05:00
|
|
|
return !testUi.masterViewCandidates().empty();
|
|
|
|
}
|
2015-08-30 06:30:46 -05:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-08-30 06:30:46 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicLinkVisibleViewsFeature::onActionTriggered( bool isChecked )
|
2015-08-30 06:30:46 -05:00
|
|
|
{
|
2019-10-28 09:39:01 -05:00
|
|
|
std::vector<RimGridView*> linkableViews;
|
|
|
|
findLinkableVisibleViews( linkableViews );
|
2015-09-15 05:16:51 -05:00
|
|
|
|
2019-10-28 09:39:01 -05:00
|
|
|
linkViews( linkableViews );
|
2015-09-15 09:28:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-09-15 09:28:17 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicLinkVisibleViewsFeature::setupActionLook( QAction* actionToSetup )
|
2015-09-15 09:28:17 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Link Visible Views" );
|
2020-10-01 10:25:19 -05:00
|
|
|
actionToSetup->setIcon( QIcon( ":/LinkView.svg" ) );
|
2015-09-15 09:28:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-09-15 09:28:17 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicLinkVisibleViewsFeature::allLinkedViews( std::vector<RimGridView*>& views )
|
2015-09-15 09:28:17 -05:00
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* proj = RimProject::current();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( proj->viewLinkerCollection()->viewLinker() )
|
2015-09-15 09:28:17 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
proj->viewLinkerCollection()->viewLinker()->allViews( views );
|
2015-09-15 09:28:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-09-15 09:28:17 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-10-28 09:39:01 -05:00
|
|
|
void RicLinkVisibleViewsFeature::findLinkableVisibleViews( std::vector<RimGridView*>& views )
|
2015-09-15 09:28:17 -05:00
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* proj = RimProject::current();
|
2015-09-15 09:28:17 -05:00
|
|
|
|
2018-01-15 07:52:22 -06:00
|
|
|
std::vector<RimGridView*> alreadyLinkedViews;
|
2019-09-06 03:40:57 -05:00
|
|
|
allLinkedViews( alreadyLinkedViews );
|
2015-09-15 09:28:17 -05:00
|
|
|
|
2019-10-28 09:39:01 -05:00
|
|
|
std::vector<RimGridView*> visibleGridViews;
|
|
|
|
proj->allVisibleGridViews( visibleGridViews );
|
2015-09-15 09:28:17 -05:00
|
|
|
|
2019-10-28 09:39:01 -05:00
|
|
|
for ( auto gridView : visibleGridViews )
|
2015-09-15 09:28:17 -05:00
|
|
|
{
|
2021-04-05 11:18:34 -05:00
|
|
|
if ( !gridView ) continue;
|
2019-10-28 09:39:01 -05:00
|
|
|
if ( dynamic_cast<RimEclipseContourMapView*>( gridView ) ) continue;
|
|
|
|
if ( dynamic_cast<RimGeoMechContourMapView*>( gridView ) ) continue;
|
|
|
|
if ( gridView->assosiatedViewLinker() ) continue;
|
|
|
|
|
|
|
|
views.push_back( gridView );
|
2015-09-15 09:28:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-09-15 09:28:17 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-10-28 09:39:01 -05:00
|
|
|
void RicLinkVisibleViewsFeature::linkViews( std::vector<RimGridView*>& linkableViews )
|
2015-09-15 09:28:17 -05:00
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* proj = RimProject::current();
|
2015-09-24 07:29:13 -05:00
|
|
|
RimViewLinker* viewLinker = proj->viewLinkerCollection->viewLinker();
|
2015-09-15 05:16:51 -05:00
|
|
|
|
2019-10-28 09:39:01 -05:00
|
|
|
std::vector<RimGridView*> masterCandidates = linkableViews;
|
2018-11-22 01:46:01 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !viewLinker )
|
2015-09-15 05:16:51 -05:00
|
|
|
{
|
|
|
|
// Create a new view linker
|
|
|
|
|
2018-11-22 01:46:01 -06:00
|
|
|
RimGridView* masterView = masterCandidates.front();
|
2019-10-28 09:39:01 -05:00
|
|
|
|
|
|
|
viewLinker = new RimViewLinker;
|
|
|
|
|
2015-09-16 07:26:25 -05:00
|
|
|
proj->viewLinkerCollection()->viewLinker = viewLinker;
|
2019-09-06 03:40:57 -05:00
|
|
|
viewLinker->setMasterView( masterView );
|
2015-09-24 07:29:13 -05:00
|
|
|
}
|
2015-09-01 10:14:22 -05:00
|
|
|
|
2021-04-05 11:18:34 -05:00
|
|
|
for ( RimGridView* rimView : linkableViews )
|
2015-09-24 07:29:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( rimView == viewLinker->masterView() ) continue;
|
2015-08-30 06:30:46 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
viewLinker->addDependentView( rimView );
|
2015-08-30 06:30:46 -05:00
|
|
|
}
|
|
|
|
|
2015-09-25 07:48:16 -05:00
|
|
|
viewLinker->updateDependentViews();
|
|
|
|
|
2015-09-24 07:29:13 -05:00
|
|
|
viewLinker->updateUiNameAndIcon();
|
|
|
|
|
2015-09-08 03:17:35 -05:00
|
|
|
proj->viewLinkerCollection.uiCapability()->updateConnectedEditors();
|
2015-09-07 07:01:19 -05:00
|
|
|
proj->updateConnectedEditors();
|
2015-08-30 06:30:46 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
Riu3DMainWindowTools::setExpanded( proj->viewLinkerCollection() );
|
2015-08-30 06:30:46 -05:00
|
|
|
}
|