///////////////////////////////////////////////////////////////////////////////// // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RicLinkVisibleViewsFeature.h" #include "RicLinkVisibleViewsFeatureUi.h" #include "RimEclipseContourMapView.h" #include "RimGeoMechContourMapView.h" #include "RimGridView.h" #include "RimProject.h" #include "RimViewController.h" #include "RimViewLinker.h" #include "RimViewLinkerCollection.h" #include "Riu3DMainWindowTools.h" #include "cafPdmUiPropertyViewDialog.h" #include #include CAF_CMD_SOURCE_INIT( RicLinkVisibleViewsFeature, "RicLinkVisibleViewsFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicLinkVisibleViewsFeature::isCommandEnabled() { RimProject* proj = RimProject::current(); if ( !proj ) return false; std::vector visibleViews; std::vector linkedviews; std::vector visibleGridViews; proj->allVisibleViews( visibleViews ); for ( Rim3dView* view : visibleViews ) { RimGridView* gridView = dynamic_cast( view ); if ( gridView ) visibleGridViews.push_back( gridView ); } if ( proj->viewLinkerCollection() && proj->viewLinkerCollection()->viewLinker() ) { proj->viewLinkerCollection()->viewLinker()->allViews( linkedviews ); } if ( visibleGridViews.size() >= 2 && ( linkedviews.size() < visibleGridViews.size() ) ) { std::vector views; findLinkableVisibleViews( views ); RicLinkVisibleViewsFeatureUi testUi; testUi.setViews( views ); return !testUi.masterViewCandidates().empty(); } return false; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicLinkVisibleViewsFeature::onActionTriggered( bool isChecked ) { std::vector linkableViews; findLinkableVisibleViews( linkableViews ); linkViews( linkableViews ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicLinkVisibleViewsFeature::setupActionLook( QAction* actionToSetup ) { actionToSetup->setText( "Link Visible Views" ); actionToSetup->setIcon( QIcon( ":/LinkView.svg" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicLinkVisibleViewsFeature::allLinkedViews( std::vector& views ) { RimProject* proj = RimProject::current(); if ( proj->viewLinkerCollection()->viewLinker() ) { proj->viewLinkerCollection()->viewLinker()->allViews( views ); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicLinkVisibleViewsFeature::findLinkableVisibleViews( std::vector& views ) { RimProject* proj = RimProject::current(); std::vector alreadyLinkedViews; allLinkedViews( alreadyLinkedViews ); std::vector visibleGridViews; proj->allVisibleGridViews( visibleGridViews ); for ( auto gridView : visibleGridViews ) { if ( !gridView ) continue; if ( dynamic_cast( gridView ) ) continue; if ( dynamic_cast( gridView ) ) continue; if ( gridView->assosiatedViewLinker() ) continue; views.push_back( gridView ); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicLinkVisibleViewsFeature::linkViews( std::vector& linkableViews ) { RimProject* proj = RimProject::current(); RimViewLinker* viewLinker = proj->viewLinkerCollection->viewLinker(); std::vector masterCandidates = linkableViews; if ( !viewLinker ) { // Create a new view linker RimGridView* masterView = masterCandidates.front(); viewLinker = new RimViewLinker; proj->viewLinkerCollection()->viewLinker = viewLinker; viewLinker->setMasterView( masterView ); } for ( RimGridView* rimView : linkableViews ) { if ( rimView == viewLinker->masterView() ) continue; viewLinker->addDependentView( rimView ); } viewLinker->updateDependentViews(); viewLinker->updateUiNameAndIcon(); proj->viewLinkerCollection.uiCapability()->updateConnectedEditors(); proj->updateConnectedEditors(); Riu3DMainWindowTools::setExpanded( proj->viewLinkerCollection() ); }