diff --git a/Plugins/org.mitk.gui.common/src/mitkIRenderWindowPartListener.h b/Plugins/org.mitk.gui.common/src/mitkIRenderWindowPartListener.h index afd7f19561..8f72eb2cb5 100644 --- a/Plugins/org.mitk.gui.common/src/mitkIRenderWindowPartListener.h +++ b/Plugins/org.mitk.gui.common/src/mitkIRenderWindowPartListener.h @@ -1,60 +1,65 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ - #ifndef MITKIRENDERWINDOWPARTLISTENER_H #define MITKIRENDERWINDOWPARTLISTENER_H #include namespace mitk { -struct IRenderWindowPart; - -/** - * \ingroup org_mitk_gui_common - * - * \brief Interface for berry::IViewPart implementations to be notified about mitk::IRenderWindowPart lifecycle changes. - * - * This interface is intended to be implemented by subclasses of berry::IWorkbenchPart. If implemented, - * the interface methods are called automatically if a Workbench part which implementes mitk::IRenderWindowPart - * is activated or deactivated. - * - * The notion of activated and deactivated is slightly different from the usual Workbench part lifecycle. - */ -struct MITK_GUI_COMMON_PLUGIN IRenderWindowPartListener -{ - virtual ~IRenderWindowPartListener(); + struct IRenderWindowPart; /** - * Called when a IRenderWindowPart is activated or if it becomes visible and no - * other IRenderWindowPart was activated before. + * \ingroup org_mitk_gui_common * - * \param renderWindowPart The newly activated IRenderWindowPart. - */ - virtual void RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) = 0; - - /** - * Called when a IRenderWindowPart becomes invisible and if it was active before. + * \brief Interface for berry::IViewPart implementations to be notified about mitk::IRenderWindowPart lifecycle changes. * - * \param renderWindowPart The deactivated IRenderWindowPart. + * This interface is intended to be implemented by subclasses of berry::IWorkbenchPart. If implemented, + * the interface methods are called automatically if a Workbench part which implementes mitk::IRenderWindowPart + * is activated or deactivated. + * + * The notion of activated and deactivated is slightly different from the usual Workbench part lifecycle. */ - virtual void RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderWindowPart) = 0; -}; + struct MITK_GUI_COMMON_PLUGIN IRenderWindowPartListener + { + virtual ~IRenderWindowPartListener(); + + /** + * Called when an IRenderWindowPart is activated or if it becomes visible and no + * other IRenderWindowPart was activated before. + * + * \param renderWindowPart The newly activated IRenderWindowPart. + */ + virtual void RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) = 0; + + /** + * Called when an IRenderWindowPart becomes invisible and if it was active before. + * + * \param renderWindowPart The deactivated IRenderWindowPart. + */ + virtual void RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderWindowPart) = 0; + /** + * Called when an IRenderWindowPart changes and if it was active before. + * + * \param renderWindowPart The modified IRenderWindowPart. + */ + virtual void RenderWindowPartInputChanged(mitk::IRenderWindowPart* /*renderWindowPart*/) {}; + }; } #endif // MITKIRENDERWINDOWPARTLISTENER_H diff --git a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkViewCoordinator.cpp b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkViewCoordinator.cpp index 0d152a43b5..035ac62b15 100644 --- a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkViewCoordinator.cpp +++ b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkViewCoordinator.cpp @@ -1,205 +1,226 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkViewCoordinator.h" #include "QmitkAbstractView.h" #include #include #include #include #include QmitkViewCoordinator::QmitkViewCoordinator() : m_ActiveZombieView(nullptr) , m_ActiveRenderWindowPart(nullptr) , m_VisibleRenderWindowPart(nullptr) { } QmitkViewCoordinator::~QmitkViewCoordinator() { } void QmitkViewCoordinator::Start() { berry::PlatformUI::GetWorkbench()->AddWindowListener(this); QList wnds(berry::PlatformUI::GetWorkbench()->GetWorkbenchWindows()); - for (QList::iterator i = wnds.begin(); - i != wnds.end(); ++i) + for (QList::iterator i = wnds.begin(); i != wnds.end(); ++i) { (*i)->GetPartService()->AddPartListener(this); } } void QmitkViewCoordinator::Stop() { if (!berry::PlatformUI::IsWorkbenchRunning()) return; berry::PlatformUI::GetWorkbench()->RemoveWindowListener(this); QList wnds(berry::PlatformUI::GetWorkbench()->GetWorkbenchWindows()); - for (QList::iterator i = wnds.begin(); - i != wnds.end(); ++i) + for (QList::iterator i = wnds.begin(); i != wnds.end(); ++i) { (*i)->GetPartService()->RemovePartListener(this); } } berry::IPartListener::Events::Types QmitkViewCoordinator::GetPartEventTypes() const { return berry::IPartListener::Events::ACTIVATED | berry::IPartListener::Events::DEACTIVATED | berry::IPartListener::Events::CLOSED | berry::IPartListener::Events::HIDDEN - | berry::IPartListener::Events::VISIBLE | berry::IPartListener::Events::OPENED; + | berry::IPartListener::Events::VISIBLE | berry::IPartListener::Events::OPENED + | berry::IPartListener::Events::INPUT_CHANGED; } -void QmitkViewCoordinator::PartActivated(const berry::IWorkbenchPartReference::Pointer& partRef ) +void QmitkViewCoordinator::PartActivated(const berry::IWorkbenchPartReference::Pointer& partRef) { //MITK_INFO << "*** PartActivated (" << partRef->GetPart(false)->GetPartName() << ")"; berry::IWorkbenchPart* part = partRef->GetPart(false).GetPointer(); // Check for a render window part and inform IRenderWindowPartListener views // that it was activated - if ( mitk::IRenderWindowPart* renderPart = dynamic_cast(part) ) + if (mitk::IRenderWindowPart* renderPart = dynamic_cast(part)) { if (m_VisibleRenderWindowPart != renderPart) { RenderWindowPartActivated(renderPart); m_ActiveRenderWindowPart = renderPart; m_VisibleRenderWindowPart = renderPart; } } // Check if the activated part wants to be notified if (mitk::ILifecycleAwarePart* lifecycleAwarePart = dynamic_cast(part)) { lifecycleAwarePart->Activated(); } // Check if a zombie view has been activated. if (mitk::IZombieViewPart* zombieView = dynamic_cast(part)) { if (m_ActiveZombieView && (m_ActiveZombieView != zombieView)) { // Another zombie view has been activated. Tell the old one about it. m_ActiveZombieView->ActivatedZombieView(partRef); m_ActiveZombieView = zombieView; } } } -void QmitkViewCoordinator::PartDeactivated(const berry::IWorkbenchPartReference::Pointer& partRef ) +void QmitkViewCoordinator::PartDeactivated(const berry::IWorkbenchPartReference::Pointer& partRef) { //MITK_INFO << "*** PartDeactivated (" << partRef->GetPart(false)->GetPartName() << ")"; berry::IWorkbenchPart* part = partRef->GetPart(false).GetPointer(); if (mitk::ILifecycleAwarePart* lifecycleAwarePart = dynamic_cast(part)) { lifecycleAwarePart->Deactivated(); } } -void QmitkViewCoordinator::PartOpened(const berry::IWorkbenchPartReference::Pointer& partRef ) +void QmitkViewCoordinator::PartOpened(const berry::IWorkbenchPartReference::Pointer& partRef) { //MITK_INFO << "*** PartOpened (" << partRef->GetPart(false)->GetPartName() << ")"; berry::IWorkbenchPart* part = partRef->GetPart(false).GetPointer(); if (mitk::IRenderWindowPartListener* renderWindowListener = dynamic_cast(part)) { m_RenderWindowListeners.insert(renderWindowListener); } } -void QmitkViewCoordinator::PartClosed(const berry::IWorkbenchPartReference::Pointer& partRef ) +void QmitkViewCoordinator::PartClosed(const berry::IWorkbenchPartReference::Pointer& partRef) { //MITK_INFO << "*** PartClosed (" << partRef->GetPart(false)->GetPartName() << ")"; berry::IWorkbenchPart* part = partRef->GetPart(false).GetPointer(); if (mitk::IRenderWindowPartListener* renderWindowListener = dynamic_cast(part)) { m_RenderWindowListeners.remove(renderWindowListener); } } -void QmitkViewCoordinator::PartHidden(const berry::IWorkbenchPartReference::Pointer& partRef ) +void QmitkViewCoordinator::PartHidden(const berry::IWorkbenchPartReference::Pointer& partRef) { //MITK_INFO << "*** PartHidden (" << partRef->GetPart(false)->GetPartName() << ")"; berry::IWorkbenchPart* part = partRef->GetPart(false).GetPointer(); // Check for a render window part and if it is the currently active on. // Inform IRenderWindowPartListener views that it has been hidden. - if ( mitk::IRenderWindowPart* renderPart = dynamic_cast(part) ) + if (mitk::IRenderWindowPart* renderPart = dynamic_cast(part)) { if (!m_ActiveRenderWindowPart && m_VisibleRenderWindowPart == renderPart) { RenderWindowPartDeactivated(renderPart); m_VisibleRenderWindowPart = nullptr; } } if (mitk::ILifecycleAwarePart* lifecycleAwarePart = dynamic_cast(part)) { lifecycleAwarePart->Hidden(); } } -void QmitkViewCoordinator::PartVisible(const berry::IWorkbenchPartReference::Pointer& partRef ) +void QmitkViewCoordinator::PartVisible(const berry::IWorkbenchPartReference::Pointer& partRef) { //MITK_INFO << "*** PartVisible (" << partRef->GetPart(false)->GetPartName() << ")"; berry::IWorkbenchPart* part = partRef->GetPart(false).GetPointer(); // Check for a render window part and inform IRenderWindowPartListener views // that it was activated - if ( mitk::IRenderWindowPart* renderPart = dynamic_cast(part) ) + if (mitk::IRenderWindowPart* renderPart = dynamic_cast(part)) { if (!m_ActiveRenderWindowPart) { RenderWindowPartActivated(renderPart); m_VisibleRenderWindowPart = renderPart; } } if (mitk::ILifecycleAwarePart* lifecycleAwarePart = dynamic_cast(part)) { lifecycleAwarePart->Visible(); } } -void QmitkViewCoordinator::RenderWindowPartActivated(mitk::IRenderWindowPart* renderPart) +void QmitkViewCoordinator::PartInputChanged(const berry::IWorkbenchPartReference::Pointer& partRef) { - foreach (mitk::IRenderWindowPartListener* l, m_RenderWindowListeners) + berry::IWorkbenchPart* part = partRef->GetPart(false).GetPointer(); + + // Check for a render window part and inform IRenderWindowPartListener views + // that it was changed + if (mitk::IRenderWindowPart* renderPart = dynamic_cast(part)) { - l->RenderWindowPartActivated(renderPart); + if (!m_ActiveRenderWindowPart) + { + RenderWindowPartInputChanged(renderPart); + } } } -void QmitkViewCoordinator::RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderPart) +void QmitkViewCoordinator::WindowOpened(const berry::IWorkbenchWindow::Pointer& window) +{ + window->GetPartService()->AddPartListener(this); +} + +void QmitkViewCoordinator::WindowClosed(const berry::IWorkbenchWindow::Pointer& /*window*/) { - foreach (mitk::IRenderWindowPartListener* l, m_RenderWindowListeners) +} + +void QmitkViewCoordinator::RenderWindowPartActivated(mitk::IRenderWindowPart* renderPart) +{ + for (auto& listener : m_RenderWindowListeners) { - l->RenderWindowPartDeactivated(renderPart); + listener->RenderWindowPartActivated(renderPart); } } -void QmitkViewCoordinator::WindowClosed(const berry::IWorkbenchWindow::Pointer& /*window*/ ) +void QmitkViewCoordinator::RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderPart) { + for (auto& listener : m_RenderWindowListeners) + { + listener->RenderWindowPartDeactivated(renderPart); + } } -void QmitkViewCoordinator::WindowOpened(const berry::IWorkbenchWindow::Pointer& window ) +void QmitkViewCoordinator::RenderWindowPartInputChanged(mitk::IRenderWindowPart* renderPart) { - window->GetPartService()->AddPartListener(this); + for (auto& listener : m_RenderWindowListeners) + { + listener->RenderWindowPartInputChanged(renderPart); + } } - diff --git a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkViewCoordinator.h b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkViewCoordinator.h index 3f876f974d..be64ddb163 100644 --- a/Plugins/org.mitk.gui.qt.common/src/internal/QmitkViewCoordinator.h +++ b/Plugins/org.mitk.gui.qt.common/src/internal/QmitkViewCoordinator.h @@ -1,122 +1,128 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QmitkViewCoordinator_h #define QmitkViewCoordinator_h #include #include #include #include #include namespace mitk { struct IRenderWindowPart; struct IRenderWindowPartListener; struct IZombieViewPart; } class QmitkAbstractView; /** * A class which coordinates active QmitkAbstractView s, e.g. calling activated and hidden on them. */ class QmitkViewCoordinator : private berry::IPartListener, private berry::IWindowListener { public: /** * Add listener */ QmitkViewCoordinator(); /** * Remove listener */ virtual ~QmitkViewCoordinator(); void Start(); void Stop(); //#IPartListener methods (these methods internally call Activated() or other similar methods) /** * \see IPartListener::GetPartEventTypes() */ berry::IPartListener::Events::Types GetPartEventTypes() const override; /** * \see IPartListener::PartActivated() */ virtual void PartActivated (const berry::IWorkbenchPartReference::Pointer& partRef) override; /** * \see IPartListener::PartDeactivated() */ virtual void PartDeactivated(const berry::IWorkbenchPartReference::Pointer& /*partRef*/) override; /** * \see IPartListener::PartOpened() */ virtual void PartOpened(const berry::IWorkbenchPartReference::Pointer& partRef) override; /** * \see IPartListener::PartClosed() */ virtual void PartClosed (const berry::IWorkbenchPartReference::Pointer& partRef) override; /** * \see IPartListener::PartHidden() */ virtual void PartHidden(const berry::IWorkbenchPartReference::Pointer& partRef) override; /** * \see IPartListener::PartVisible() */ virtual void PartVisible(const berry::IWorkbenchPartReference::Pointer& partRef) override; + /** + * \see IPartListener::PartInputChanged() + */ + virtual void PartInputChanged(const berry::IWorkbenchPartReference::Pointer& partRef) override; + /** * Notifies this listener that the given window has been closed. */ virtual void WindowClosed(const berry::IWorkbenchWindow::Pointer& window) override; /** * Notifies this listener that the given window has been opened. */ - virtual void WindowOpened(const berry::IWorkbenchWindow::Pointer& /*window*/) override; + virtual void WindowOpened(const berry::IWorkbenchWindow::Pointer& window) override; private: void RenderWindowPartActivated(mitk::IRenderWindowPart* renderPart); void RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderPart); + void RenderWindowPartInputChanged(mitk::IRenderWindowPart* renderPart); private: mitk::IZombieViewPart* m_ActiveZombieView; mitk::IRenderWindowPart* m_ActiveRenderWindowPart; mitk::IRenderWindowPart* m_VisibleRenderWindowPart; QSet m_RenderWindowListeners; }; #endif // QmitkViewCoordinator_h diff --git a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.cpp b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.cpp index cff2554e4a..dd8ae78e06 100644 --- a/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.cpp +++ b/Plugins/org.mitk.gui.qt.custommultiwidgeteditor/src/QmitkCustomMultiWidgetEditor.cpp @@ -1,267 +1,269 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical Image Computing. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkCustomMultiWidgetEditor.h" -#include -#include #include #include +#include +#include +#include #include // mitk core #include #include const QString QmitkCustomMultiWidgetEditor::EDITOR_ID = "org.mitk.editors.custommultiwidget"; QmitkCustomMultiWidgetEditor::QmitkCustomMultiWidgetEditor() : m_CustomMultiWidget(nullptr) , m_InteractionSchemeToolBar(nullptr) , m_ConfigurationToolBar(nullptr) { // nothing here } QmitkCustomMultiWidgetEditor::~QmitkCustomMultiWidgetEditor() { // nothing here } void QmitkCustomMultiWidgetEditor::Activated() { // nothing here } void QmitkCustomMultiWidgetEditor::Deactivated() { // nothing here } void QmitkCustomMultiWidgetEditor::Visible() { // nothing here } void QmitkCustomMultiWidgetEditor::Hidden() { // nothing here } QmitkRenderWindow* QmitkCustomMultiWidgetEditor::GetActiveQmitkRenderWindow() const { if (nullptr != m_CustomMultiWidget) { auto activeRenderWindowWidget = m_CustomMultiWidget->GetActiveRenderWindowWidget(); if (nullptr != activeRenderWindowWidget) { return activeRenderWindowWidget->GetRenderWindow(); } } return nullptr; } QHash QmitkCustomMultiWidgetEditor::GetQmitkRenderWindows() const { QHash result; if (nullptr == m_CustomMultiWidget) { return result; } // create QHash on demand QmitkCustomMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); for (const auto& renderWindowWidget : renderWindowWidgets) { result.insert(renderWindowWidget.first, renderWindowWidget.second->GetRenderWindow()); } return result; } QmitkRenderWindow* QmitkCustomMultiWidgetEditor::GetQmitkRenderWindow(const QString& id) const { if (nullptr == m_CustomMultiWidget) { return nullptr; } return m_CustomMultiWidget->GetRenderWindow(id); } mitk::Point3D QmitkCustomMultiWidgetEditor::GetSelectedPosition(const QString& id) const { if (nullptr == m_CustomMultiWidget) { return mitk::Point3D(); } return m_CustomMultiWidget->GetCrossPosition(id); } void QmitkCustomMultiWidgetEditor::SetSelectedPosition(const mitk::Point3D& pos, const QString& id) { if (nullptr != m_CustomMultiWidget) { m_CustomMultiWidget->MoveCrossToPosition(id, pos); } } void QmitkCustomMultiWidgetEditor::EnableDecorations(bool enable, const QStringList& decorations) { m_MultiWidgetDecorationManager->ShowDecorations(enable, decorations); } bool QmitkCustomMultiWidgetEditor::IsDecorationEnabled(const QString& decoration) const { return m_MultiWidgetDecorationManager->IsDecorationVisible(decoration); } QStringList QmitkCustomMultiWidgetEditor::GetDecorations() const { return m_MultiWidgetDecorationManager->GetDecorations(); } void QmitkCustomMultiWidgetEditor::EnableSlicingPlanes(bool enable) { // #TODO: nothing here } bool QmitkCustomMultiWidgetEditor::IsSlicingPlanesEnabled() const { // #TODO: nothing here return false; } QmitkCustomMultiWidget* QmitkCustomMultiWidgetEditor::GetCustomMultiWidget() { return m_CustomMultiWidget; } void QmitkCustomMultiWidgetEditor::OnLayoutSet(int row, int column) { m_CustomMultiWidget->ResetLayout(row, column); SetControlledRenderer(); + FirePropertyChange(berry::IWorkbenchPartConstants::PROP_INPUT); } void QmitkCustomMultiWidgetEditor::OnSynchronize(bool synchronized) { m_CustomMultiWidget->Synchronize(synchronized); } void QmitkCustomMultiWidgetEditor::OnViewDirectionChanged(mitk::SliceNavigationController::ViewDirection viewDirection) { m_RenderWindowViewDirectionController->SetViewDirectionOfRenderer(viewDirection); } ////////////////////////////////////////////////////////////////////////// // PRIVATE ////////////////////////////////////////////////////////////////////////// void QmitkCustomMultiWidgetEditor::SetFocus() { if (nullptr != m_CustomMultiWidget) { m_CustomMultiWidget->setFocus(); } } void QmitkCustomMultiWidgetEditor::CreateQtPartControl(QWidget* parent) { if (nullptr == m_CustomMultiWidget) { QHBoxLayout* layout = new QHBoxLayout(parent); layout->setContentsMargins(0, 0, 0, 0); berry::IBerryPreferences* preferences = dynamic_cast(GetPreferences().GetPointer()); mitk::BaseRenderer::RenderingMode::Type renderingMode = static_cast(preferences->GetInt("Rendering Mode", 0)); m_CustomMultiWidget = new QmitkCustomMultiWidget(parent, 0, 0, renderingMode); // create left toolbar: interaction scheme toolbar to switch how the render window navigation behaves if (nullptr == m_InteractionSchemeToolBar) { m_InteractionSchemeToolBar = new QmitkInteractionSchemeToolBar(parent); layout->addWidget(m_InteractionSchemeToolBar); } m_InteractionSchemeToolBar->SetInteractionEventHandler(m_CustomMultiWidget->GetInteractionEventHandler()); // add center widget: the custom multi widget layout->addWidget(m_CustomMultiWidget); m_CustomMultiWidget->SetDataStorage(GetDataStorage()); m_CustomMultiWidget->InitializeRenderWindowWidgets(); // create right toolbar: configuration toolbar to change the render window widget layout if (nullptr == m_ConfigurationToolBar) { m_ConfigurationToolBar = new QmitkMultiWidgetConfigurationToolBar(m_CustomMultiWidget); layout->addWidget(m_ConfigurationToolBar); } connect(m_ConfigurationToolBar, SIGNAL(LayoutSet(int, int)), SLOT(OnLayoutSet(int, int))); connect(m_ConfigurationToolBar, SIGNAL(Synchronized(bool)), SLOT(OnSynchronize(bool))); connect(m_ConfigurationToolBar, SIGNAL(ViewDirectionChanged(mitk::SliceNavigationController::ViewDirection)), SLOT(OnViewDirectionChanged(mitk::SliceNavigationController::ViewDirection))); m_MultiWidgetDecorationManager = std::make_unique(m_CustomMultiWidget); m_RenderWindowViewDirectionController = std::make_unique(); m_RenderWindowViewDirectionController->SetDataStorage(GetDataStorage()); SetControlledRenderer(); OnPreferencesChanged(preferences); } } void QmitkCustomMultiWidgetEditor::OnPreferencesChanged(const berry::IBerryPreferences* preferences) { if (m_CustomMultiWidget->GetRenderWindowWidgets().empty()) { return; } // update decoration preferences m_MultiWidgetDecorationManager->DecorationPreferencesChanged(preferences); // zooming and panning preferences bool constrainedZooming = preferences->GetBool("Use constrained zooming and panning", true); mitk::RenderingManager::GetInstance()->SetConstrainedPanningZooming(constrainedZooming); mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(GetDataStorage()); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkCustomMultiWidgetEditor::SetControlledRenderer() { if (nullptr == m_RenderWindowViewDirectionController || nullptr == m_CustomMultiWidget) { return; } RenderWindowLayerUtilities::RendererVector controlledRenderer; auto renderWindowWidgets = m_CustomMultiWidget->GetRenderWindowWidgets(); for (const auto& renderWindowWidget : renderWindowWidgets) { auto renderWindow = renderWindowWidget.second->GetRenderWindow(); auto vtkRenderWindow = renderWindow->GetRenderWindow(); mitk::BaseRenderer* baseRenderer = mitk::BaseRenderer::GetInstance(vtkRenderWindow); if (nullptr != baseRenderer) { controlledRenderer.push_back(baseRenderer); } } m_RenderWindowViewDirectionController->SetControlledRenderer(controlledRenderer); } diff --git a/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.cpp b/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.cpp index 1307b4045e..42ee4ebd91 100644 --- a/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.cpp +++ b/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.cpp @@ -1,114 +1,135 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // render window manager plugin #include "QmitkRenderWindowManagerView.h" // blueberry #include #include // mitk core #include #include const std::string QmitkRenderWindowManagerView::VIEW_ID = "org.mitk.views.renderwindowmanager"; +void QmitkRenderWindowManagerView::RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) +{ + if (m_RenderWindowPart != renderWindowPart) + { + m_RenderWindowPart = renderWindowPart; + } + + SetControlledRenderer(); +} + +void QmitkRenderWindowManagerView::RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderWindowPart) +{ + m_RenderWindowPart = nullptr; +} + +void QmitkRenderWindowManagerView::RenderWindowPartInputChanged(mitk::IRenderWindowPart* renderWindowPart) +{ + if (m_RenderWindowPart == renderWindowPart) + { + SetControlledRenderer(); + } +} + void QmitkRenderWindowManagerView::SetFocus() { // nothing here } void QmitkRenderWindowManagerView::CreateQtPartControl(QWidget* parent) { // create GUI widgets m_Controls.setupUi(parent); // add custom render window manager UI widget to the 'renderWindowManagerTab' m_RenderWindowManipulatorWidget = new QmitkRenderWindowManipulatorWidget(GetDataStorage(), parent); m_RenderWindowManipulatorWidget->setObjectName(QStringLiteral("m_RenderWindowManipulatorWidget")); m_Controls.verticalLayout->addWidget(m_RenderWindowManipulatorWidget); SetControlledRenderer(); - for (const auto& renderer : m_ControlledRenderer) - { - m_Controls.comboBoxRenderWindowSelection->addItem(renderer->GetName()); - } - - OnRenderWindowSelectionChanged(m_Controls.comboBoxRenderWindowSelection->itemText(0)); - connect(m_Controls.comboBoxRenderWindowSelection, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(OnRenderWindowSelectionChanged(const QString&))); connect(m_RenderWindowManipulatorWidget, SIGNAL(AddLayerButtonClicked()), this, SLOT(OnAddLayerButtonClicked())); } void QmitkRenderWindowManagerView::SetControlledRenderer() { + m_Controls.comboBoxRenderWindowSelection->clear(); + const mitk::RenderingManager::RenderWindowVector allRegisteredRenderWindows = mitk::RenderingManager::GetInstance()->GetAllRegisteredRenderWindows(); mitk::BaseRenderer* baseRenderer = nullptr; for (const auto &renderWindow : allRegisteredRenderWindows) { baseRenderer = mitk::BaseRenderer::GetInstance(renderWindow); if (nullptr != baseRenderer) { m_ControlledRenderer.push_back(baseRenderer); + m_Controls.comboBoxRenderWindowSelection->addItem(baseRenderer->GetName()); } } m_RenderWindowManipulatorWidget->SetControlledRenderer(m_ControlledRenderer); + + OnRenderWindowSelectionChanged(m_Controls.comboBoxRenderWindowSelection->itemText(0)); } void QmitkRenderWindowManagerView::OnRenderWindowSelectionChanged(const QString &renderWindowId) { m_RenderWindowManipulatorWidget->SetActiveRenderWindow(renderWindowId); } void QmitkRenderWindowManagerView::OnAddLayerButtonClicked() { QList nodes = GetDataManagerSelection(); for (mitk::DataNode* dataNode : nodes) { if (nullptr != dataNode) { m_RenderWindowManipulatorWidget->AddLayer(dataNode); // get child nodes of the current node mitk::DataStorage::SetOfObjects::ConstPointer derivedNodes = GetDataStorage()->GetDerivations(dataNode, nullptr, false); for (mitk::DataStorage::SetOfObjects::ConstIterator it = derivedNodes->Begin(); it != derivedNodes->End(); ++it) { m_RenderWindowManipulatorWidget->AddLayer(it->Value()); } } } } void QmitkRenderWindowManagerView::NodeAdded(const mitk::DataNode* node) { bool global = false; node->GetBoolProperty("globalObject_RWM", global); if (global) { // initially insert new point set node into the node list of all render windows // the node object of a new point set won't be visible due to its "helper object" property set to true m_RenderWindowManipulatorWidget->AddLayerToAllRenderer(const_cast(node)); } else { // initially set new node as invisible in all render windows // this way, each single renderer overwrites the common renderer and the node is invisible // until it is inserted into the node list of a render windows m_RenderWindowManipulatorWidget->HideDataNodeInAllRenderer(node); } } diff --git a/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.h b/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.h index ba9743fb77..a99325f429 100644 --- a/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.h +++ b/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.h @@ -1,82 +1,90 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKRENDERWINDOWMANAGERVIEW_H #define QMITKRENDERWINDOWMANAGERVIEW_H // render window manager plugin #include "ui_QmitkRenderWindowManagerControls.h" // render window manager UI module #include // blueberry #include +#include + // qt #include /** * @brief RenderWindowManager */ -class QmitkRenderWindowManagerView : public QmitkAbstractView +class QmitkRenderWindowManagerView : public QmitkAbstractView, public mitk::IRenderWindowPartListener { Q_OBJECT public: static const std::string VIEW_ID; + virtual void RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) override; + virtual void RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderWindowPart) override; + virtual void RenderWindowPartInputChanged(mitk::IRenderWindowPart* renderWindowPart) override; + protected: virtual void SetFocus() override; virtual void CreateQtPartControl(QWidget* parent) override; private Q_SLOTS: /** * @brief Called when the user changes the render window selection in the combo box. * * @param renderWindowId The text inside the combo box. */ void OnRenderWindowSelectionChanged(const QString &renderWindowId); /** * @brief Called when the 'AddLayer'-button of he render window manipulator widget has been pushed. */ void OnAddLayerButtonClicked(); private: void SetControlledRenderer(); /** * @brief Reacts to a node that has been added to the data storage. * 1. Insert new node into the node list of all render windows, if it is an "globalObject_RWM"-node. * or else * 2. Set data node invisible in all render windows, as soon as the node is added to the data storage. */ void NodeAdded(const mitk::DataNode* node) override; // the Qt parent of our GUI QWidget* m_Parent; Ui::QmitkRenderWindowManagerControls m_Controls; + mitk::IRenderWindowPart* m_RenderWindowPart; + QmitkRenderWindowManipulatorWidget* m_RenderWindowManipulatorWidget; RenderWindowLayerUtilities::RendererVector m_ControlledRenderer; }; #endif // QMITKRENDERWINDOWMANAGERVIEW_H