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"
|
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
|
|
|
|
2019-10-28 12:51:55 +01:00
|
|
|
#include "RiuViewer.h"
|
|
|
|
|
#include "RiuViewerCommands.h"
|
|
|
|
|
|
|
|
|
|
#include "cafCmdFeatureManager.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-10-28 15:39:01 +01:00
|
|
|
class RicLinkViewFeatureImpl
|
2015-09-15 16:28:17 +02:00
|
|
|
{
|
2019-10-28 15:39:01 +01:00
|
|
|
public:
|
|
|
|
|
// 1. Selected views in the tree
|
|
|
|
|
// 2. Context menu on a viewer
|
2018-11-22 08:46:01 +01:00
|
|
|
|
2019-10-28 15:39:01 +01:00
|
|
|
bool prepareToExecute()
|
|
|
|
|
{
|
2023-02-26 10:48:40 +01:00
|
|
|
auto contextViewer = dynamic_cast<RiuViewer*>( caf::CmdFeatureManager::instance()->currentContextMenuTargetWidget() );
|
2018-11-22 08:46:01 +01:00
|
|
|
|
2019-10-28 15:39:01 +01:00
|
|
|
if ( contextViewer )
|
|
|
|
|
{
|
|
|
|
|
// Link only the active view to an existing view link collection.
|
2022-11-24 10:46:54 +01:00
|
|
|
auto* activeView = RiaApplication::instance()->activeReservoirView();
|
2019-10-28 15:39:01 +01:00
|
|
|
if ( !activeView ) return false;
|
2019-10-28 12:51:55 +01:00
|
|
|
|
2019-10-28 15:39:01 +01:00
|
|
|
if ( activeView->assosiatedViewLinker() ) return false;
|
|
|
|
|
|
|
|
|
|
m_viewsToLink.push_back( activeView );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 10:46:54 +01:00
|
|
|
std::vector<Rim3dView*> selectedGridViews;
|
2019-10-28 15:39:01 +01:00
|
|
|
|
|
|
|
|
caf::SelectionManager::instance()->objectsByTypeStrict( &selectedGridViews );
|
|
|
|
|
for ( auto gridView : selectedGridViews )
|
|
|
|
|
{
|
2021-04-05 18:18:34 +02:00
|
|
|
if ( !gridView ) continue;
|
|
|
|
|
|
2019-10-28 15:39:01 +01:00
|
|
|
if ( !gridView->assosiatedViewLinker() )
|
|
|
|
|
{
|
|
|
|
|
m_viewsToLink.push_back( gridView );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-04 15:48:25 +01:00
|
|
|
if ( !m_viewsToLink.empty() )
|
2019-10-28 15:39:01 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2015-09-24 14:29:13 +02:00
|
|
|
}
|
2019-10-28 15:39:01 +01:00
|
|
|
|
2020-02-12 11:13:38 +01:00
|
|
|
void execute() { RicLinkVisibleViewsFeature::linkViews( m_viewsToLink ); }
|
2019-10-28 15:39:01 +01:00
|
|
|
|
2022-11-24 10:46:54 +01:00
|
|
|
const std::vector<Rim3dView*>& viewsToLink() { return m_viewsToLink; }
|
2019-10-28 15:39:01 +01:00
|
|
|
|
|
|
|
|
private:
|
2022-11-24 10:46:54 +01:00
|
|
|
std::vector<Rim3dView*> m_viewsToLink;
|
2019-10-28 15:39:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RicLinkViewFeature::isCommandEnabled()
|
|
|
|
|
{
|
|
|
|
|
RicLinkViewFeatureImpl cmdImpl;
|
|
|
|
|
return cmdImpl.prepareToExecute();
|
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
|
|
|
{
|
2019-10-28 15:39:01 +01:00
|
|
|
RicLinkViewFeatureImpl cmdImpl;
|
|
|
|
|
if ( cmdImpl.prepareToExecute() )
|
2018-10-24 13:45:46 +02:00
|
|
|
{
|
2019-10-28 15:39:01 +01:00
|
|
|
cmdImpl.execute();
|
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
|
|
|
{
|
2019-10-28 15:39:01 +01:00
|
|
|
RicLinkViewFeatureImpl cmdImpl;
|
|
|
|
|
cmdImpl.prepareToExecute();
|
2019-10-28 12:51:55 +01:00
|
|
|
|
2019-10-28 15:39:01 +01:00
|
|
|
if ( cmdImpl.viewsToLink().size() >= 2u )
|
2018-10-24 13:45:46 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
actionToSetup->setText( "Link Selected Views" );
|
2020-10-01 17:25:19 +02:00
|
|
|
actionToSetup->setIcon( QIcon( ":/LinkView.svg" ) );
|
2018-10-24 13:45:46 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
actionToSetup->setText( "Link View" );
|
2020-05-12 09:50:38 +02:00
|
|
|
if ( RimProject::current()->viewLinkerCollection()->viewLinker() )
|
2019-10-28 15:39:01 +01:00
|
|
|
{
|
2019-11-04 11:34:34 +01:00
|
|
|
actionToSetup->setIcon( QIcon( ":/ControlledView16x16.png" ) );
|
2019-10-28 15:39:01 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-11-04 11:34:34 +01:00
|
|
|
actionToSetup->setIcon( QIcon( ":/MasterView16x16.png" ) );
|
2019-10-28 15:39:01 +01:00
|
|
|
}
|
2018-10-24 13:45:46 +02:00
|
|
|
}
|
2015-09-15 16:28:17 +02:00
|
|
|
}
|