Files
ResInsight/ApplicationLibCode/Commands/ViewLink/RicLinkVisibleViewsFeature.cpp
T

164 lines
5.6 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicLinkVisibleViewsFeature.h"
#include "RicLinkVisibleViewsFeatureUi.h"
2018-01-16 09:37:08 +01:00
#include "RimGridView.h"
#include "RimProject.h"
#include "RimViewController.h"
#include "RimViewLinker.h"
#include "RimViewLinkerCollection.h"
#include "Riu3DMainWindowTools.h"
#include "cafPdmUiPropertyViewDialog.h"
#include <QAction>
#include <QTreeView>
CAF_CMD_SOURCE_INIT( RicLinkVisibleViewsFeature, "RicLinkVisibleViewsFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-06-26 14:28:46 +02:00
bool RicLinkVisibleViewsFeature::isCommandEnabled() const
{
RimProject* proj = RimProject::current();
if ( !proj ) return false;
2022-11-24 10:46:54 +01:00
std::vector<Rim3dView*> visibleViews;
proj->allVisibleViews( visibleViews );
2022-11-24 10:46:54 +01:00
std::vector<Rim3dView*> linkedviews;
if ( proj->viewLinkerCollection() && proj->viewLinkerCollection()->viewLinker() )
{
2022-11-04 15:48:25 +01:00
linkedviews = proj->viewLinkerCollection()->viewLinker()->allViews();
}
2022-11-24 10:46:54 +01:00
if ( visibleViews.size() >= 2 && ( linkedviews.size() < visibleViews.size() ) )
{
2022-11-24 10:46:54 +01:00
return !findLinkableVisibleViews().empty();
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicLinkVisibleViewsFeature::onActionTriggered( bool isChecked )
{
2022-11-24 10:46:54 +01:00
auto linkableViews = findLinkableVisibleViews();
RicLinkVisibleViewsFeature::linkViews( linkableViews );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicLinkVisibleViewsFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Link Visible Views" );
2020-10-01 17:25:19 +02:00
actionToSetup->setIcon( QIcon( ":/LinkView.svg" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2022-11-24 10:46:54 +01:00
std::vector<Rim3dView*> RicLinkVisibleViewsFeature::findLinkableVisibleViews()
{
RimProject* proj = RimProject::current();
2022-11-24 10:46:54 +01:00
std::vector<Rim3dView*> views;
2022-11-24 10:46:54 +01:00
std::vector<Rim3dView*> candidates;
proj->allVisibleViews( candidates );
2022-11-24 10:46:54 +01:00
for ( auto gridView : candidates )
{
if ( gridView && !gridView->assosiatedViewLinker() ) views.push_back( gridView );
}
2022-11-24 10:46:54 +01:00
return views;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2022-11-24 10:46:54 +01:00
void RicLinkVisibleViewsFeature::linkViews( std::vector<Rim3dView*>& linkableViews )
{
2022-11-24 10:46:54 +01:00
if ( linkableViews.empty() ) return;
RimProject* proj = RimProject::current();
RimViewLinker* viewLinker = proj->viewLinkerCollection->viewLinker();
if ( !viewLinker )
{
viewLinker = new RimViewLinker;
proj->viewLinkerCollection()->viewLinker = viewLinker;
2022-11-24 10:46:54 +01:00
viewLinker->setMasterView( linkableViews.front() );
}
2022-11-24 10:46:54 +01:00
Rim3dView* primaryView = viewLinker->masterView();
2022-11-24 10:46:54 +01:00
auto matchingViews = RicLinkVisibleViewsFeature::matchingViews( primaryView, linkableViews );
for ( auto v : matchingViews )
{
viewLinker->addDependentView( v );
}
viewLinker->updateDependentViews();
viewLinker->updateUiNameAndIcon();
proj->viewLinkerCollection.uiCapability()->updateConnectedEditors();
proj->viewLinkerCollection->updateConnectedEditors();
Riu3DMainWindowTools::setExpanded( proj->viewLinkerCollection() );
}
2022-11-24 10:46:54 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-02-26 10:48:40 +01:00
std::vector<Rim3dView*> RicLinkVisibleViewsFeature::matchingViews( Rim3dView* primaryView, std::vector<Rim3dView*>& candidates )
2022-11-24 10:46:54 +01:00
{
if ( !primaryView ) return {};
std::vector<Rim3dView*> matchingViews;
RiaDefines::View3dContent primaryContent = primaryView->viewContent();
if ( primaryContent == RiaDefines::View3dContent::FLAT_INTERSECTION )
{
for ( auto v : candidates )
{
2023-02-26 10:48:40 +01:00
if ( v != primaryView && v->viewContent() == RiaDefines::View3dContent::FLAT_INTERSECTION ) matchingViews.emplace_back( v );
2022-11-24 10:46:54 +01:00
}
return matchingViews;
}
// We have a 3D view or contour map as primary view, include all views except flat intersection views
for ( auto v : candidates )
{
2023-02-26 10:48:40 +01:00
if ( v != primaryView && v->viewContent() != RiaDefines::View3dContent::FLAT_INTERSECTION ) matchingViews.emplace_back( v );
2022-11-24 10:46:54 +01:00
}
return matchingViews;
}