(#446) Added feature "Set master view" to context menu in 3D and in project tree

This commit is contained in:
Magne Sjaastad
2015-09-16 15:13:56 +02:00
parent 4c781b12be
commit f1e11780ce
5 changed files with 175 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ ${CEE_CURRENT_LIST_DIR}RicLinkViewFeature.h
${CEE_CURRENT_LIST_DIR}RicUnLinkViewFeature.h
${CEE_CURRENT_LIST_DIR}RicShowLinkOptionsFeature.h
${CEE_CURRENT_LIST_DIR}RicDeleteAllLinkedViewsFeature.h
${CEE_CURRENT_LIST_DIR}RicSetMasterViewFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -22,6 +23,7 @@ ${CEE_CURRENT_LIST_DIR}RicLinkViewFeature.cpp
${CEE_CURRENT_LIST_DIR}RicUnLinkViewFeature.cpp
${CEE_CURRENT_LIST_DIR}RicShowLinkOptionsFeature.cpp
${CEE_CURRENT_LIST_DIR}RicDeleteAllLinkedViewsFeature.cpp
${CEE_CURRENT_LIST_DIR}RicSetMasterViewFeature.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,127 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSetMasterViewFeature.h"
#include "RiaApplication.h"
#include "RimProject.h"
#include "RimView.h"
#include "RimViewLink.h"
#include "RimViewLinker.h"
#include "RimViewLinkerCollection.h"
#include "RiuMainWindow.h"
#include "cafPdmUiTreeView.h"
#include <QAction>
#include <QTreeView>
CAF_CMD_SOURCE_INIT(RicSetMasterViewFeature, "RicSetMasterViewFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSetMasterViewFeature::isCommandEnabled()
{
RimView* activeView = RiaApplication::instance()->activeReservoirView();
if (!activeView) return false;
RimProject* proj = RiaApplication::instance()->project();
RimViewLinker* viewLinker = proj->findViewLinkerFromView(activeView);
if (viewLinker && viewLinker->mainView() == activeView)
{
return false;
}
if (!proj->viewLinkerCollection()->viewLinker())
{
return false;
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSetMasterViewFeature::onActionTriggered(bool isChecked)
{
RimView* activeView = RiaApplication::instance()->activeReservoirView();
if (!activeView) return;
RimProject* proj = RiaApplication::instance()->project();
RimViewLinker* viewLinker = proj->viewLinkerCollection()->viewLinker();
RimView* previousMasterView = viewLinker->mainView();
RimViewLink* previousViewLink = viewLinker->viewLinkFromView(activeView);
if (previousViewLink)
{
size_t indexToErase = cvf::UNDEFINED_SIZE_T;
for (size_t i = 0; i < viewLinker->viewLinks.size(); i++)
{
if (viewLinker->viewLinks()[i] == previousViewLink)
{
indexToErase = i;
}
}
if (indexToErase != cvf::UNDEFINED_SIZE_T)
{
viewLinker->viewLinks().erase(indexToErase);
}
delete previousViewLink;
}
viewLinker->removeOverrides();
viewLinker->setMainView(activeView);
if (previousMasterView)
{
RimViewLink* viewLink = new RimViewLink;
viewLink->setManagedView(previousMasterView);
viewLinker->viewLinks.push_back(viewLink);
viewLink->initAfterReadRecursively();
viewLink->updateOptionSensitivity();
viewLink->updateUiIconFromActiveState();
}
viewLinker->applyAllOperations();
proj->viewLinkerCollection.uiCapability()->updateConnectedEditors();
proj->updateConnectedEditors();
// Set managed view collection to selected and expanded in project tree
caf::PdmUiTreeView* projTreeView = RiuMainWindow::instance()->projectTreeView();
QModelIndex modIndex = projTreeView->findModelIndex(viewLinker);
projTreeView->treeView()->setCurrentIndex(modIndex);
projTreeView->treeView()->setExpanded(modIndex, true);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSetMasterViewFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setText("Set As Master View");
}

View File

@@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
#include <vector>
//==================================================================================================
///
//==================================================================================================
class RicSetMasterViewFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled();
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook(QAction* actionToSetup);
};