diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/files.cmake b/CoreUI/Bundles/org.mitk.gui.qt.common/files.cmake index b7938ef751..2a76572546 100755 --- a/CoreUI/Bundles/org.mitk.gui.qt.common/files.cmake +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/files.cmake @@ -1,49 +1,52 @@ SET(SRC_CPP_FILES QmitkCloseProjectAction.cpp QmitkDnDFrameWidget.cpp QmitkDataNodeSelectionProvider.cpp QmitkFileOpenAction.cpp QmitkFileExitAction.cpp QmitkFunctionality.cpp QmitkFunctionality2.cpp QmitkStatusBar.cpp QmitkStdMultiWidgetEditor.cpp QmitkPreferencesDialog.cpp QmitkFunctionalityCoordinator.cpp + QmitkStdMultiWidgetEditorPreferencePage.cpp ) SET(INTERNAL_CPP_FILES QmitkDataNodeSelection.cpp QmitkCommonActivator.cpp QmitkFunctionalityUtil.cpp ) SET(MOC_H_FILES src/QmitkCloseProjectAction.h src/QmitkFileOpenAction.h src/QmitkFileExitAction.h src/QmitkPreferencesDialog.h src/QmitkStdMultiWidgetEditor.h src/QmitkDnDFrameWidget.h src/internal/QmitkCommonActivator.h + + src/QmitkStdMultiWidgetEditorPreferencePage.h ) SET(CACHED_RESOURCE_FILES plugin.xml ) # todo: add some qt style sheet resources SET(QRC_FILES resources/resources.qrc ) SET(CPP_FILES ) foreach(file ${SRC_CPP_FILES}) SET(CPP_FILES ${CPP_FILES} src/${file}) endforeach(file ${SRC_CPP_FILES}) foreach(file ${INTERNAL_CPP_FILES}) SET(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/plugin.xml b/CoreUI/Bundles/org.mitk.gui.qt.common/plugin.xml index c1e2d793cb..c1b4b2e2f1 100644 --- a/CoreUI/Bundles/org.mitk.gui.qt.common/plugin.xml +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/plugin.xml @@ -1,11 +1,16 @@ + + + + + diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditor.cpp b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditor.cpp index 9731a2679f..9e844fe683 100644 --- a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditor.cpp +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditor.cpp @@ -1,173 +1,235 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkStdMultiWidgetEditor.h" #include #include #include #include #include #include +#include + +#include "mitkNodePredicateNot.h" +#include "mitkNodePredicateProperty.h" const std::string QmitkStdMultiWidgetEditor::EDITOR_ID = "org.mitk.editors.stdmultiwidget"; QmitkStdMultiWidgetEditor::QmitkStdMultiWidgetEditor() : m_StdMultiWidget(0) { } QmitkStdMultiWidgetEditor::QmitkStdMultiWidgetEditor(const QmitkStdMultiWidgetEditor& other) { Q_UNUSED(other) throw std::runtime_error("Copy constructor not implemented"); } QmitkStdMultiWidgetEditor::~QmitkStdMultiWidgetEditor() { // we need to wrap the RemovePartListener call inside a // register/unregister block to prevent infinite recursion // due to the destruction of temporary smartpointer to this this->Register(); this->GetSite()->GetPage()->RemovePartListener(berry::IPartListener::Pointer(this)); this->UnRegister(false); } QmitkStdMultiWidget* QmitkStdMultiWidgetEditor::GetStdMultiWidget() { return m_StdMultiWidget; } void QmitkStdMultiWidgetEditor::Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input) { if (input.Cast().IsNull()) throw berry::PartInitException("Invalid Input: Must be IFileEditorInput"); this->SetSite(site); this->SetInput(input); } void QmitkStdMultiWidgetEditor::CreateQtPartControl(QWidget* parent) { if (m_StdMultiWidget == 0) { m_DndFrameWidget = new QmitkDnDFrameWidget(parent); QVBoxLayout* layout = new QVBoxLayout(parent); layout->addWidget(m_DndFrameWidget); layout->setContentsMargins(0,0,0,0); m_StdMultiWidget = new QmitkStdMultiWidget(m_DndFrameWidget); QVBoxLayout* layout2 = new QVBoxLayout(m_DndFrameWidget); layout2->addWidget(m_StdMultiWidget); layout2->setContentsMargins(0,0,0,0); mitk::DataStorage::Pointer ds = this->GetEditorInput().Cast() ->GetDataStorageReference()->GetDataStorage(); // Tell the multiWidget which (part of) the tree to render m_StdMultiWidget->SetDataStorage(ds); // Initialize views as transversal, sagittal, coronar to all data objects in DataStorage // (from top-left to bottom) mitk::TimeSlicedGeometry::Pointer geo = ds->ComputeBoundingGeometry3D(ds->GetAll()); mitk::RenderingManager::GetInstance()->InitializeViews(geo); // Initialize bottom-right view as 3D view m_StdMultiWidget->GetRenderWindow4()->GetRenderer()->SetMapperID( mitk::BaseRenderer::Standard3D ); // Enable standard handler for levelwindow-slider m_StdMultiWidget->EnableStandardLevelWindow(); // Add the displayed views to the tree to see their positions // in 2D and 3D m_StdMultiWidget->AddDisplayPlaneSubTree(); m_StdMultiWidget->EnableNavigationControllerEventListening(); mitk::GlobalInteraction::GetInstance()->AddListener( m_StdMultiWidget->GetMoveAndZoomInteractor() ); this->GetSite()->GetPage()->AddPartListener(berry::IPartListener::Pointer(this)); // enable change of logo berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry() .GetServiceById(berry::IPreferencesService::ID); berry::IPreferences::Pointer logoPref = prefService->GetSystemPreferences()->Node("DepartmentLogo"); std::string departmentLogoLocation = logoPref->Get("DepartmentLogo",""); + + //# Preferences + + berry::IBerryPreferences::Pointer prefs + = (prefService->GetSystemPreferences()->Node(EDITOR_ID)) + .Cast(); + assert( prefs ); + + prefs->OnChanged.AddListener( berry::MessageDelegate1( this + , &QmitkStdMultiWidgetEditor::OnPreferencesChanged ) ); + + bool constrainedZooming = prefs->GetBool("Use constrained zooming and padding", false); + + mitk::RenderingManager::GetInstance()->SetConstrainedPaddingZooming(constrainedZooming); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + m_StdMultiWidget->SetDepartmentLogoPath(departmentLogoLocation.c_str()); m_StdMultiWidget->DisableDepartmentLogo(); m_StdMultiWidget->EnableDepartmentLogo(); } } +void QmitkStdMultiWidgetEditor::OnPreferencesChanged(const berry::IBerryPreferences* prefs) +{ + + // Set preferences respecting zooming and padding + bool constrainedZooming = prefs->GetBool("Use constrained zooming and padding", false); + + mitk::RenderingManager::GetInstance()->SetConstrainedPaddingZooming(constrainedZooming); + + mitk::NodePredicateNot::Pointer pred + = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox" + , mitk::BoolProperty::New(false))); + + mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred); + // calculate bounding geometry of these nodes + + mitk::TimeSlicedGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); + + + // initialize the views to the bounding geometry + mitk::RenderingManager::GetInstance()->InitializeViews(bounds); + + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + +} + + +mitk::DataStorage::Pointer QmitkStdMultiWidgetEditor::GetDataStorage() const +{ + mitk::IDataStorageService::Pointer service = + berry::Platform::GetServiceRegistry().GetServiceById(mitk::IDataStorageService::ID); + + if (service.IsNotNull()) + { + return service->GetDefaultDataStorage()->GetDataStorage(); + } + + return 0; +} + + berry::IPartListener::Events::Types QmitkStdMultiWidgetEditor::GetPartEventTypes() const { return Events::CLOSED | Events::HIDDEN | Events::VISIBLE; } void QmitkStdMultiWidgetEditor::PartClosed( berry::IWorkbenchPartReference::Pointer partRef ) { if (partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID) { QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast(); if (m_StdMultiWidget == stdMultiWidgetEditor->GetStdMultiWidget()) { m_StdMultiWidget->RemovePlanesFromDataStorage(); } } } void QmitkStdMultiWidgetEditor::PartVisible( berry::IWorkbenchPartReference::Pointer partRef ) { if (partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID) { QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast(); if (m_StdMultiWidget == stdMultiWidgetEditor->GetStdMultiWidget()) { m_StdMultiWidget->AddPlanesToDataStorage(); } } } void QmitkStdMultiWidgetEditor::PartHidden( berry::IWorkbenchPartReference::Pointer partRef ) { if (partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID) { QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast(); if (m_StdMultiWidget == stdMultiWidgetEditor->GetStdMultiWidget()) { m_StdMultiWidget->RemovePlanesFromDataStorage(); } } } void QmitkStdMultiWidgetEditor::SetFocus() { if (m_StdMultiWidget != 0) m_StdMultiWidget->setFocus(); } diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditor.h b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditor.h index b6767e37ed..e1e975fae7 100644 --- a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditor.h +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditor.h @@ -1,69 +1,78 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QMITKSTDMULTIWIDGETEDITOR_H_ #define QMITKSTDMULTIWIDGETEDITOR_H_ #include #include +#include +#include #include #include #include class MITK_QT_COMMON QmitkStdMultiWidgetEditor : public berry::QtEditorPart, virtual public berry::IPartListener { Q_OBJECT public: - berryObjectMacro(QmitkStdMultiWidgetEditor); + berryObjectMacro(QmitkStdMultiWidgetEditor) static const std::string EDITOR_ID; QmitkStdMultiWidgetEditor(); QmitkStdMultiWidgetEditor(const QmitkStdMultiWidgetEditor& other); ~QmitkStdMultiWidgetEditor(); QmitkStdMultiWidget* GetStdMultiWidget(); void Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input); void SetFocus(); void DoSave() {} void DoSaveAs() {} bool IsDirty() const { return false; } bool IsSaveAsAllowed() const { return false; } +public slots: + void OnPreferencesChanged(const berry::IBerryPreferences*); + protected: void CreateQtPartControl(QWidget* parent); // IPartListener Events::Types GetPartEventTypes() const; virtual void PartClosed (berry::IWorkbenchPartReference::Pointer partRef); virtual void PartHidden (berry::IWorkbenchPartReference::Pointer partRef); virtual void PartVisible (berry::IWorkbenchPartReference::Pointer partRef); + + mitk::DataStorage::Pointer GetDataStorage() const; + + private: QmitkStdMultiWidget* m_StdMultiWidget; QmitkDnDFrameWidget* m_DndFrameWidget; }; #endif /*QMITKSTDMULTIWIDGETEDITOR_H_*/ diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditorPreferencePage.cpp b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditorPreferencePage.cpp new file mode 100644 index 0000000000..2560e3a406 --- /dev/null +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditorPreferencePage.cpp @@ -0,0 +1,87 @@ +/*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date: 2009-07-07 16:57:15 +0200 (Di, 07 Jul 2009) $ + Version: $Revision: 18019 $ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ + +#include "QmitkStdMultiWidgetEditorPreferencePage.h" +#include "QmitkStdMultiWidgetEditor.h" + +#include +#include +#include +#include + +#include +#include + +QmitkStdMultiWidgetEditorPreferencePage::QmitkStdMultiWidgetEditorPreferencePage() +: m_MainControl(0) +{ + +} + +QmitkStdMultiWidgetEditorPreferencePage::QmitkStdMultiWidgetEditorPreferencePage(const QmitkStdMultiWidgetEditorPreferencePage& other) +{ + Q_UNUSED(other) + throw std::runtime_error("Copy constructor not implemented"); +} + +void QmitkStdMultiWidgetEditorPreferencePage::Init(berry::IWorkbench::Pointer ) +{ + +} + +void QmitkStdMultiWidgetEditorPreferencePage::CreateQtControl(QWidget* parent) +{ + berry::IPreferencesService::Pointer prefService + = berry::Platform::GetServiceRegistry() + .GetServiceById(berry::IPreferencesService::ID); + + m_StdMultiWidgetEditorPreferencesNode = prefService->GetSystemPreferences()->Node(QmitkStdMultiWidgetEditor::EDITOR_ID); + + m_MainControl = new QWidget(parent); + m_EnableFlexibleZooming = new QCheckBox; + + QFormLayout *formLayout = new QFormLayout; + formLayout->addRow("&Use constrained zooming and padding", m_EnableFlexibleZooming); + + + m_MainControl->setLayout(formLayout); + this->Update(); +} + +QWidget* QmitkStdMultiWidgetEditorPreferencePage::GetQtControl() const +{ + return m_MainControl; +} + +bool QmitkStdMultiWidgetEditorPreferencePage::PerformOk() +{ + m_StdMultiWidgetEditorPreferencesNode->PutBool("Use constrained zooming and padding" + , m_EnableFlexibleZooming->isChecked()); + + return true; +} + +void QmitkStdMultiWidgetEditorPreferencePage::PerformCancel() +{ + +} + +void QmitkStdMultiWidgetEditorPreferencePage::Update() +{ + m_EnableFlexibleZooming->setChecked(m_StdMultiWidgetEditorPreferencesNode->GetBool("Use constrained zooming and padding", true)); + +} diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.h b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditorPreferencePage.h similarity index 69% copy from Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.h copy to CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditorPreferencePage.h index 4f2c233cdc..ecd24b66bc 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.h +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/QmitkStdMultiWidgetEditorPreferencePage.h @@ -1,69 +1,65 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-02-10 14:14:32 +0100 (Di, 10 Feb 2009) $ Version: $Revision: 16224 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef QMITKDATAMANAGERPREFERENCEPAGE_H_ -#define QMITKDATAMANAGERPREFERENCEPAGE_H_ +#ifndef QMITKSTDMULTIWIDGETEDITORPREFERENCEPAGE_H_ +#define QMITKSTDMULTIWIDGETEDITORPREFERENCEPAGE_H_ #include "berryIQtPreferencePage.h" -#include +#include #include class QWidget; class QCheckBox; -struct MITK_QT_DATAMANAGER QmitkDataManagerPreferencePage : public QObject, public berry::IQtPreferencePage +struct MITK_QT_COMMON QmitkStdMultiWidgetEditorPreferencePage : public QObject, public berry::IQtPreferencePage { Q_OBJECT Q_INTERFACES(berry::IPreferencePage) public: - QmitkDataManagerPreferencePage(); - QmitkDataManagerPreferencePage(const QmitkDataManagerPreferencePage& other); + QmitkStdMultiWidgetEditorPreferencePage(); + QmitkStdMultiWidgetEditorPreferencePage(const QmitkStdMultiWidgetEditorPreferencePage& other); void Init(berry::IWorkbench::Pointer workbench); void CreateQtControl(QWidget* widget); QWidget* GetQtControl() const; /// /// \see IPreferencePage::PerformOk() /// virtual bool PerformOk(); /// /// \see IPreferencePage::PerformCancel() /// virtual void PerformCancel(); /// /// \see IPreferencePage::Update() /// virtual void Update(); protected: QWidget* m_MainControl; - QCheckBox* m_EnableFlexibleZooming; - QCheckBox* m_EnableSingleEditing; - QCheckBox* m_PlaceNewNodesOnTop; - QCheckBox* m_ShowHelperObjects; - QCheckBox* m_UseSurfaceDecimation; - berry::IPreferences::Pointer m_DataManagerPreferencesNode; + QCheckBox* m_EnableFlexibleZooming; + berry::IPreferences::Pointer m_StdMultiWidgetEditorPreferencesNode; }; #endif /* QMITKDATAMANAGERPREFERENCEPAGE_H_ */ diff --git a/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkCommonActivator.cpp b/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkCommonActivator.cpp index 8b37065ba0..b41457f871 100644 --- a/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkCommonActivator.cpp +++ b/CoreUI/Bundles/org.mitk.gui.qt.common/src/internal/QmitkCommonActivator.cpp @@ -1,55 +1,57 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkCommonActivator.h" #include "../QmitkStdMultiWidgetEditor.h" +#include "../QmitkStdMultiWidgetEditorPreferencePage.h" #include #include #include void QmitkCommonActivator::start(ctkPluginContext* context) { Q_UNUSED(context) BERRY_REGISTER_EXTENSION_CLASS(QmitkStdMultiWidgetEditor, context) + BERRY_REGISTER_EXTENSION_CLASS(QmitkStdMultiWidgetEditorPreferencePage, context) QFile file(":/org.mitk.gui.qt.common/StateMachine.xml"); if(file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text) ) { QByteArray contents = file.readAll(); QString string(contents); file.close(); mitk::GlobalInteraction::GetInstance()->Initialize("global", string.toStdString()); } else throw std::exception(); QmitkRegisterClasses(); } void QmitkCommonActivator::stop(ctkPluginContext* context) { Q_UNUSED(context) } Q_EXPORT_PLUGIN2(org_mitk_gui_qt_common, QmitkCommonActivator) diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.cpp b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.cpp index 30785357a9..f1a7e739b6 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.cpp @@ -1,104 +1,99 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-07 16:57:15 +0200 (Di, 07 Jul 2009) $ Version: $Revision: 18019 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkDataManagerPreferencePage.h" #include "QmitkDataManagerView.h" #include #include #include #include #include #include QmitkDataManagerPreferencePage::QmitkDataManagerPreferencePage() : m_MainControl(0) { } QmitkDataManagerPreferencePage::QmitkDataManagerPreferencePage(const QmitkDataManagerPreferencePage& other) { Q_UNUSED(other) throw std::runtime_error("Copy constructor not implemented"); } void QmitkDataManagerPreferencePage::Init(berry::IWorkbench::Pointer ) { } void QmitkDataManagerPreferencePage::CreateQtControl(QWidget* parent) { berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry() .GetServiceById(berry::IPreferencesService::ID); m_DataManagerPreferencesNode = prefService->GetSystemPreferences()->Node(QmitkDataManagerView::VIEW_ID); - m_MainControl = new QWidget(parent); - m_EnableFlexibleZooming = new QCheckBox; + m_MainControl = new QWidget(parent); m_EnableSingleEditing = new QCheckBox; m_PlaceNewNodesOnTop = new QCheckBox; m_ShowHelperObjects = new QCheckBox; m_UseSurfaceDecimation = new QCheckBox; - QFormLayout *formLayout = new QFormLayout; - formLayout->addRow("&Use constrained zooming and padding", m_EnableFlexibleZooming); + QFormLayout *formLayout = new QFormLayout; formLayout->addRow("&Single click property editing:", m_EnableSingleEditing); formLayout->addRow("&Place new nodes on top:", m_PlaceNewNodesOnTop); formLayout->addRow("&Show helper objects:", m_ShowHelperObjects); formLayout->addRow("&Use surface decimation:", m_UseSurfaceDecimation); m_MainControl->setLayout(formLayout); this->Update(); } QWidget* QmitkDataManagerPreferencePage::GetQtControl() const { return m_MainControl; } bool QmitkDataManagerPreferencePage::PerformOk() -{ - m_DataManagerPreferencesNode->PutBool("Use constrained zooming and padding" - , m_EnableFlexibleZooming->isChecked()); +{ m_DataManagerPreferencesNode->PutBool("Single click property editing" , m_EnableSingleEditing->isChecked()); m_DataManagerPreferencesNode->PutBool("Place new nodes on top" , m_PlaceNewNodesOnTop->isChecked()); m_DataManagerPreferencesNode->PutBool("Show helper objects" , m_ShowHelperObjects->isChecked()); m_DataManagerPreferencesNode->PutBool("Use surface decimation" , m_UseSurfaceDecimation->isChecked()); return true; } void QmitkDataManagerPreferencePage::PerformCancel() { } void QmitkDataManagerPreferencePage::Update() -{ - m_EnableFlexibleZooming->setChecked(m_DataManagerPreferencesNode->GetBool("Use constrained zooming and padding", true)); +{ m_EnableSingleEditing->setChecked(m_DataManagerPreferencesNode->GetBool("Single click property editing", true)); m_PlaceNewNodesOnTop->setChecked(m_DataManagerPreferencesNode->GetBool("Place new nodes on top", true)); m_ShowHelperObjects->setChecked(m_DataManagerPreferencesNode->GetBool("Show helper objects", false)); m_UseSurfaceDecimation->setChecked(m_DataManagerPreferencesNode->GetBool("Use surface decimation", true)); } diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.h b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.h index 4f2c233cdc..3f0e9781f7 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.h +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerPreferencePage.h @@ -1,69 +1,68 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-02-10 14:14:32 +0100 (Di, 10 Feb 2009) $ Version: $Revision: 16224 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QMITKDATAMANAGERPREFERENCEPAGE_H_ #define QMITKDATAMANAGERPREFERENCEPAGE_H_ #include "berryIQtPreferencePage.h" #include #include class QWidget; class QCheckBox; struct MITK_QT_DATAMANAGER QmitkDataManagerPreferencePage : public QObject, public berry::IQtPreferencePage { Q_OBJECT Q_INTERFACES(berry::IPreferencePage) public: QmitkDataManagerPreferencePage(); QmitkDataManagerPreferencePage(const QmitkDataManagerPreferencePage& other); void Init(berry::IWorkbench::Pointer workbench); void CreateQtControl(QWidget* widget); QWidget* GetQtControl() const; /// /// \see IPreferencePage::PerformOk() /// virtual bool PerformOk(); /// /// \see IPreferencePage::PerformCancel() /// virtual void PerformCancel(); /// /// \see IPreferencePage::Update() /// virtual void Update(); protected: - QWidget* m_MainControl; - QCheckBox* m_EnableFlexibleZooming; + QWidget* m_MainControl; QCheckBox* m_EnableSingleEditing; QCheckBox* m_PlaceNewNodesOnTop; QCheckBox* m_ShowHelperObjects; QCheckBox* m_UseSurfaceDecimation; berry::IPreferences::Pointer m_DataManagerPreferencesNode; }; #endif /* QMITKDATAMANAGERPREFERENCEPAGE_H_ */ diff --git a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp index 7fef4f07fd..51234927ad 100644 --- a/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.datamanager/src/QmitkDataManagerView.cpp @@ -1,1019 +1,1014 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkDataManagerView.h" #include //# Own Includes //## mitk #include "mitkDataStorageEditorInput.h" #include "mitkIDataStorageReference.h" #include "mitkNodePredicateDataType.h" #include "mitkCoreObjectFactory.h" #include "mitkPACSPlugin.h" #include "mitkDataNodeFactory.h" #include "mitkColorProperty.h" #include "mitkCommon.h" #include "mitkDelegateManager.h" #include "mitkNodePredicateData.h" #include "mitkNodePredicateNot.h" #include "mitkNodePredicateProperty.h" #include "mitkEnumerationProperty.h" #include "mitkProperties.h" #include #include #include //## Qmitk #include #include #include #include #include #include #include #include #include "src/internal/QmitkNodeTableViewKeyFilter.h" #include "src/internal/QmitkInfoDialog.h" //## Berry #include #include #include #include //# Toolkit Includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mitkDataNodeObject.h" #include "mitkIContextMenuAction.h" #include "berryIExtensionPointService.h" const std::string QmitkDataManagerView::VIEW_ID = "org.mitk.views.datamanager"; QmitkDataManagerView::QmitkDataManagerView() { } QmitkDataManagerView::QmitkDataManagerView(const QmitkDataManagerView& other) { Q_UNUSED(other) throw std::runtime_error("Copy constructor not implemented"); } QmitkDataManagerView::~QmitkDataManagerView() { berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) s->RemoveSelectionListener(m_SelectionListener); berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry() .GetServiceById(berry::IPreferencesService::ID); berry::IBerryPreferences::Pointer prefs = (prefService->GetSystemPreferences()->Node(VIEW_ID)) .Cast(); prefs->OnChanged.RemoveListener( berry::MessageDelegate1( this , &QmitkDataManagerView::OnPreferencesChanged ) ); } void QmitkDataManagerView::CreateQtPartControl(QWidget* parent) { m_CurrentRowCount = 0; m_Parent = parent; //# Preferences berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry() .GetServiceById(berry::IPreferencesService::ID); berry::IBerryPreferences::Pointer prefs = (prefService->GetSystemPreferences()->Node(VIEW_ID)) .Cast(); assert( prefs ); prefs->OnChanged.AddListener( berry::MessageDelegate1( this , &QmitkDataManagerView::OnPreferencesChanged ) ); //# GUI m_NodeTreeModel = new QmitkDataStorageTreeModel(this->GetDataStorage()); m_NodeTreeModel->setParent( parent ); m_NodeTreeModel->SetPlaceNewNodesOnTop( prefs->GetBool("Place new nodes on top", true) ); m_NodeTreeModel->SetShowHelperObjects( prefs->GetBool("Show helper objects", false) ); m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false); //# Tree View (experimental) m_NodeTreeView = new QTreeView; m_NodeTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection ); m_NodeTreeView->setSelectionBehavior( QAbstractItemView::SelectRows ); m_NodeTreeView->setAlternatingRowColors(true); m_NodeTreeView->setDragEnabled(true); m_NodeTreeView->setDropIndicatorShown(true); m_NodeTreeView->setAcceptDrops(true); m_NodeTreeView->setContextMenuPolicy(Qt::CustomContextMenu); m_NodeTreeView->setModel(m_NodeTreeModel); m_NodeTreeView->installEventFilter(new QmitkNodeTableViewKeyFilter(this)); QObject::connect( m_NodeTreeView, SIGNAL(customContextMenuRequested(const QPoint&)) , this, SLOT(NodeTableViewContextMenuRequested(const QPoint&)) ); QObject::connect( m_NodeTreeModel, SIGNAL(rowsInserted (const QModelIndex&, int, int)) , this, SLOT(NodeTreeViewRowsInserted ( const QModelIndex&, int, int )) ); QObject::connect( m_NodeTreeModel, SIGNAL(rowsRemoved (const QModelIndex&, int, int)) , this, SLOT(NodeTreeViewRowsRemoved( const QModelIndex&, int, int )) ); QObject::connect( m_NodeTreeView->selectionModel() , SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection & ) ) , this , SLOT( NodeSelectionChanged ( const QItemSelection &, const QItemSelection & ) ) ); //# m_NodeMenu m_NodeMenu = new QMenu(m_NodeTreeView); //# m_SelectionProvider m_SelectionProvider = new QmitkDataNodeSelectionProvider(); m_SelectionProvider->SetItemSelectionModel(m_NodeTreeView->selectionModel()); this->GetSite()->SetSelectionProvider(m_SelectionProvider); // # Actions QmitkNodeDescriptor* unknownDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetUnknownDataNodeDescriptor(); QmitkNodeDescriptor* imageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Image"); QmitkNodeDescriptor* surfaceDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Surface"); m_GlobalReinitAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png"), "Global Reinit", this); QObject::connect( m_GlobalReinitAction, SIGNAL( triggered(bool) ) , this, SLOT( GlobalReinit(bool) ) ); unknownDataNodeDescriptor->AddAction(m_GlobalReinitAction); m_SaveAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Save_48.png"), "Save...", this); QObject::connect( m_SaveAction, SIGNAL( triggered(bool) ) , this, SLOT( SaveSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_SaveAction); m_RemoveAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Remove_48.png"), "Remove", this); QObject::connect( m_RemoveAction, SIGNAL( triggered(bool) ) , this, SLOT( RemoveSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_RemoveAction); m_ReinitAction = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png"), "Reinit", this); QObject::connect( m_ReinitAction, SIGNAL( triggered(bool) ) , this, SLOT( ReinitSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_ReinitAction); // find contextMenuAction extension points and add them to the node descriptor berry::IExtensionPointService::Pointer extensionPointService = berry::Platform::GetExtensionPointService(); berry::IConfigurationElement::vector cmActions( extensionPointService->GetConfigurationElementsFor("org.mitk.gui.qt.datamanager.contextMenuActions") ); berry::IConfigurationElement::vector::iterator cmActionsIt; std::string cmNodeDescriptorName; std::string cmLabel; std::string cmIcon; std::string cmClass; QmitkNodeDescriptor* tmpDescriptor; QAction* contextMenuAction; QVariant cmActionDataIt; m_ConfElements.clear(); int i=1; for (cmActionsIt = cmActions.begin() ; cmActionsIt != cmActions.end() ; ++cmActionsIt) { cmIcon.erase(); if((*cmActionsIt)->GetAttribute("nodeDescriptorName", cmNodeDescriptorName) && (*cmActionsIt)->GetAttribute("label", cmLabel) && (*cmActionsIt)->GetAttribute("class", cmClass)) { (*cmActionsIt)->GetAttribute("icon", cmIcon); // create context menu entry here tmpDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(QString::fromStdString(cmNodeDescriptorName)); if(!tmpDescriptor) { MITK_WARN << "cannot add action \"" << cmLabel << "\" because descriptor " << cmNodeDescriptorName << " does not exist"; continue; } contextMenuAction = new QAction( QString::fromStdString(cmLabel), parent); tmpDescriptor->AddAction(contextMenuAction); m_ConfElements[contextMenuAction] = *cmActionsIt; cmActionDataIt.setValue(i); contextMenuAction->setData( cmActionDataIt ); connect( contextMenuAction, SIGNAL( triggered(bool) ) , this, SLOT( ContextMenuActionTriggered(bool) ) ); ++i; } } m_OpacitySlider = new QSlider; m_OpacitySlider->setMinimum(0); m_OpacitySlider->setMaximum(100); m_OpacitySlider->setOrientation(Qt::Horizontal); QObject::connect( m_OpacitySlider, SIGNAL( valueChanged(int) ) , this, SLOT( OpacityChanged(int) ) ); QLabel* _OpacityLabel = new QLabel("Opacity: "); QHBoxLayout* _OpacityWidgetLayout = new QHBoxLayout; _OpacityWidgetLayout->setContentsMargins(4,4,4,4); _OpacityWidgetLayout->addWidget(_OpacityLabel); _OpacityWidgetLayout->addWidget(m_OpacitySlider); QWidget* _OpacityWidget = new QWidget; _OpacityWidget->setLayout(_OpacityWidgetLayout); m_OpacityAction = new QWidgetAction(this); m_OpacityAction->setDefaultWidget(_OpacityWidget); QObject::connect( m_OpacityAction, SIGNAL( changed() ) , this, SLOT( OpacityActionChanged() ) ); unknownDataNodeDescriptor->AddAction(m_OpacityAction, false); m_ColorButton = new QPushButton; m_ColorButton->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum); //m_ColorButton->setText("Change color"); QObject::connect( m_ColorButton, SIGNAL( clicked() ) , this, SLOT( ColorChanged() ) ); QLabel* _ColorLabel = new QLabel("Color: "); _ColorLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); QHBoxLayout* _ColorWidgetLayout = new QHBoxLayout; _ColorWidgetLayout->setContentsMargins(4,4,4,4); _ColorWidgetLayout->addWidget(_ColorLabel); _ColorWidgetLayout->addWidget(m_ColorButton); QWidget* _ColorWidget = new QWidget; _ColorWidget->setLayout(_ColorWidgetLayout); m_ColorAction = new QWidgetAction(this); m_ColorAction->setDefaultWidget(_ColorWidget); QObject::connect( m_ColorAction, SIGNAL( changed() ) , this, SLOT( ColorActionChanged() ) ); unknownDataNodeDescriptor->AddAction(m_ColorAction, false); m_TextureInterpolation = new QAction("Texture Interpolation", this); m_TextureInterpolation->setCheckable ( true ); QObject::connect( m_TextureInterpolation, SIGNAL( changed() ) , this, SLOT( TextureInterpolationChanged() ) ); QObject::connect( m_TextureInterpolation, SIGNAL( toggled(bool) ) , this, SLOT( TextureInterpolationToggled(bool) ) ); imageDataNodeDescriptor->AddAction(m_TextureInterpolation, false); m_SurfaceRepresentation = new QAction("Surface Representation", this); m_SurfaceRepresentation->setMenu(new QMenu); QObject::connect( m_SurfaceRepresentation->menu(), SIGNAL( aboutToShow() ) , this, SLOT( SurfaceRepresentationMenuAboutToShow() ) ); surfaceDataNodeDescriptor->AddAction(m_SurfaceRepresentation, false); m_ShowOnlySelectedNodes = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/ShowSelectedNode_48.png") , "Show only selected nodes", this); QObject::connect( m_ShowOnlySelectedNodes, SIGNAL( triggered(bool) ) , this, SLOT( ShowOnlySelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_ShowOnlySelectedNodes); m_ToggleSelectedVisibility = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/InvertShowSelectedNode_48.png") , "Toggle visibility", this); QObject::connect( m_ToggleSelectedVisibility, SIGNAL( triggered(bool) ) , this, SLOT( ToggleVisibilityOfSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_ToggleSelectedVisibility); m_ActionShowInfoDialog = new QAction(QIcon(":/org.mitk.gui.qt.datamanager/ShowDataInfo_48.png") , "Details...", this); QObject::connect( m_ActionShowInfoDialog, SIGNAL( triggered(bool) ) , this, SLOT( ShowInfoDialogForSelectedNodes(bool) ) ); unknownDataNodeDescriptor->AddAction(m_ActionShowInfoDialog); m_OtsuFilterAction = new QAction("Apply Otsu Filter", this); QObject::connect( m_OtsuFilterAction, SIGNAL( triggered(bool) ) , this, SLOT( OtsuFilter(bool) ) ); // Otsu filter does not work properly, remove it temporarily // imageDataNodeDescriptor->AddAction(m_OtsuFilterAction); QGridLayout* _DndFrameWidgetLayout = new QGridLayout; _DndFrameWidgetLayout->addWidget(m_NodeTreeView, 0, 0); _DndFrameWidgetLayout->setContentsMargins(0,0,0,0); m_DndFrameWidget = new QmitkDnDFrameWidget(m_Parent); m_DndFrameWidget->setLayout(_DndFrameWidgetLayout); QVBoxLayout* layout = new QVBoxLayout(parent); layout->addWidget(m_DndFrameWidget); layout->setContentsMargins(0,0,0,0); m_Parent->setLayout(layout); m_SelectionListener = new berry::SelectionChangedAdapter (this, &QmitkDataManagerView::SelectionChanged); berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); s->AddSelectionListener(m_SelectionListener); } void QmitkDataManagerView::SetFocus() { } void QmitkDataManagerView::ContextMenuActionTriggered( bool ) { QAction* action = qobject_cast ( sender() ); std::map::iterator it = m_ConfElements.find( action ); if( it == m_ConfElements.end() ) { MITK_WARN << "associated conf element for action " << action->text().toStdString() << " not found"; return; } berry::IConfigurationElement::Pointer confElem = it->second; mitk::IContextMenuAction* contextMenuAction = confElem->CreateExecutableExtension("class"); if (contextMenuAction == 0) { // support legacy BlueBerry extensions contextMenuAction = confElem->CreateExecutableExtension("class", mitk::IContextMenuAction::GetManifestName()); } std::string className; std::string smoothed; confElem->GetAttribute("class", className); confElem->GetAttribute("smoothed", smoothed); if(className == "QmitkThresholdAction") { contextMenuAction->SetDataStorage(this->GetDataStorage()); } if(className == "QmitkCreatePolygonModelAction") { contextMenuAction->SetDataStorage(this->GetDataStorage()); if(smoothed == "false") { contextMenuAction->SetSmoothed(false); } else { contextMenuAction->SetSmoothed(true); } contextMenuAction->SetDecimated(m_SurfaceDecimation); } if(className == "QmitkStatisticsAction") { contextMenuAction->SetFunctionality(this); } contextMenuAction->Run( this->GetSelectedNodes() ); // run the action } mitk::DataStorage::Pointer QmitkDataManagerView::GetDataStorage() const { mitk::IDataStorageService::Pointer service = berry::Platform::GetServiceRegistry().GetServiceById(mitk::IDataStorageService::ID); if (service.IsNotNull()) { return service->GetDefaultDataStorage()->GetDataStorage(); } return 0; } void QmitkDataManagerView::OnPreferencesChanged(const berry::IBerryPreferences* prefs) { if( m_NodeTreeModel->GetPlaceNewNodesOnTopFlag() != prefs->GetBool("Place new nodes on top", true) ) m_NodeTreeModel->SetPlaceNewNodesOnTop( !m_NodeTreeModel->GetPlaceNewNodesOnTopFlag() ); if( m_NodeTreeModel->GetShowHelperObjectsFlag()!= prefs->GetBool("Show helper objects", false) ) m_NodeTreeModel->SetShowHelperObjects( !m_NodeTreeModel->GetShowHelperObjectsFlag() ); m_NodeTreeView->expandAll(); m_SurfaceDecimation = prefs->GetBool("Use surface decimation", false); - // Set preferences respecting zooming and padding - bool constrainedZooming = prefs->GetBool("Use constrained zooming and padding", false); - - mitk::RenderingManager::GetInstance()->SetConstrainedPaddingZooming(constrainedZooming); - this->GlobalReinit(); } void QmitkDataManagerView::NodeTableViewContextMenuRequested( const QPoint & pos ) { QModelIndex selected = m_NodeTreeView->indexAt ( pos ); mitk::DataNode::Pointer node = m_NodeTreeModel->GetNode(selected); std::vector selectedNodes = this->GetSelectedNodes(); if(!selectedNodes.empty()) { m_NodeMenu->clear(); QList actions; if(selectedNodes.size() == 1 ) { actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(node); for(QList::iterator it = actions.begin(); it != actions.end(); ++it) { (*it)->setData(QVariant::fromValue(node.GetPointer())); } } else actions = QmitkNodeDescriptorManager::GetInstance()->GetActions(selectedNodes); m_NodeMenu->addActions(actions); m_NodeMenu->popup(QCursor::pos()); } } void QmitkDataManagerView::OpacityChanged(int value) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { float opacity = static_cast(value)/100.0f; node->SetFloatProperty("opacity", opacity); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } MITK_INFO << "slider changed"; } void QmitkDataManagerView::OpacityActionChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { float opacity = 0.0; if(node->GetFloatProperty("opacity", opacity)) { m_OpacitySlider->setValue(static_cast(opacity*100)); } } MITK_INFO << "changed"; } void QmitkDataManagerView::ColorChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { QColor color = QColorDialog::getColor(); m_ColorButton->setAutoFillBackground(true); node->SetProperty("color",mitk::ColorProperty::New(color.red()/255.0,color.green()/255.0,color.blue()/255.0)); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } MITK_INFO << "slider changed"; } void QmitkDataManagerView::ColorActionChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { mitk::Color color; mitk::ColorProperty::Pointer colorProp; node->GetProperty(colorProp,"color"); if(colorProp.IsNull()) return; color = colorProp->GetValue(); QString styleSheet = "background-color:rgb("; styleSheet.append(QString::number(color[0]*255)); styleSheet.append(","); styleSheet.append(QString::number(color[1]*255)); styleSheet.append(","); styleSheet.append(QString::number(color[2]*255)); styleSheet.append(")"); m_ColorButton->setStyleSheet(styleSheet); } MITK_INFO << "changed"; } void QmitkDataManagerView::TextureInterpolationChanged() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { bool textureInterpolation = false; node->GetBoolProperty("texture interpolation", textureInterpolation); m_TextureInterpolation->setChecked(textureInterpolation); } } void QmitkDataManagerView::TextureInterpolationToggled( bool checked ) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(node) { node->SetBoolProperty("texture interpolation", checked); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkDataManagerView::SurfaceRepresentationMenuAboutToShow() { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(!node) return; mitk::EnumerationProperty* representationProp = dynamic_cast (node->GetProperty("material.representation")); if(!representationProp) return; // clear menu m_SurfaceRepresentation->menu()->clear(); QAction* tmp; // create menu entries for(mitk::EnumerationProperty::EnumConstIterator it=representationProp->Begin(); it!=representationProp->End() ; it++) { tmp = m_SurfaceRepresentation->menu()->addAction(QString::fromStdString(it->second)); tmp->setCheckable(true); if(it->second == representationProp->GetValueAsString()) { tmp->setChecked(true); } QObject::connect( tmp, SIGNAL( triggered(bool) ) , this, SLOT( SurfaceRepresentationActionToggled(bool) ) ); } } void QmitkDataManagerView::SurfaceRepresentationActionToggled( bool /*checked*/ ) { mitk::DataNode* node = m_NodeTreeModel->GetNode(m_NodeTreeView->selectionModel()->currentIndex()); if(!node) return; mitk::EnumerationProperty* representationProp = dynamic_cast (node->GetProperty("material.representation")); if(!representationProp) return; QAction* senderAction = qobject_cast ( QObject::sender() ); if(!senderAction) return; std::string activatedItem = senderAction->text().toStdString(); if ( activatedItem != representationProp->GetValueAsString() ) { if ( representationProp->IsValidEnumerationValue( activatedItem ) ) { representationProp->SetValue( activatedItem ); representationProp->InvokeEvent( itk::ModifiedEvent() ); representationProp->Modified(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } } void QmitkDataManagerView::SaveSelectedNodes( bool ) { QModelIndexList indexesOfSelectedRows = m_NodeTreeView->selectionModel()->selectedRows(); mitk::DataNode* node = 0; unsigned int indexesOfSelectedRowsSize = indexesOfSelectedRows.size(); for (unsigned int i = 0; iGetNode(indexesOfSelectedRows.at(i)); // if node is not defined or if the node contains geometry data do not remove it if ( node != 0 ) { mitk::BaseData::Pointer data = node->GetData(); if (data.IsNotNull()) { QString error; try { CommonFunctionality::SaveBaseData( data.GetPointer(), node->GetName().c_str() ); } catch(std::exception& e) { error = e.what(); } catch(...) { error = "Unknown error occured"; } if( !error.isEmpty() ) QMessageBox::critical( m_Parent, "Error saving...", error ); } } } } void QmitkDataManagerView::ReinitSelectedNodes( bool ) { this->ReinitMultiWidgetEditor(); std::vector selectedNodes = this->GetSelectedNodes(); mitk::DataNode* node = 0; for (std::vector::iterator it = selectedNodes.begin() ; it != selectedNodes.end(); it++) { node = *it; mitk::BaseData::Pointer basedata = node->GetData(); if (basedata.IsNotNull()) { mitk::RenderingManager::GetInstance()->InitializeViews( basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } } void QmitkDataManagerView::RemoveSelectedNodes( bool ) { QModelIndexList indexesOfSelectedRows = m_NodeTreeView->selectionModel()->selectedRows(); if(indexesOfSelectedRows.size() < 1) { return; } std::vector selectedNodes; mitk::DataNode* node = 0; QString question = tr("Do you really want to remove "); for (QModelIndexList::iterator it = indexesOfSelectedRows.begin() ; it != indexesOfSelectedRows.end(); it++) { node = m_NodeTreeModel->GetNode(*it); // if node is not defined or if the node contains geometry data do not remove it if ( node != 0 /*& strcmp(node->GetData()->GetNameOfClass(), "Geometry2DData") != 0*/ ) { selectedNodes.push_back(node); question.append(QString::fromStdString(node->GetName())); question.append(", "); } } // remove the last two characters = ", " question = question.remove(question.size()-2, 2); question.append(" from data storage?"); QMessageBox::StandardButton answerButton = QMessageBox::question( m_Parent , tr("DataManager") , question , QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(answerButton == QMessageBox::Yes) { for (std::vector::iterator it = selectedNodes.begin() ; it != selectedNodes.end(); it++) { node = *it; this->GetDataStorage()->Remove(node); this->GlobalReinit(false); } } } void QmitkDataManagerView::MakeAllNodesInvisible( bool ) { std::vector nodes = m_NodeTreeModel->GetNodeSet(); for (std::vector::iterator it = nodes.begin() ; it != nodes.end(); it++) { (*it)->SetVisibility(false); } //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ShowOnlySelectedNodes( bool ) { std::vector selectedNodes = this->GetSelectedNodes(); std::vector allNodes = m_NodeTreeModel->GetNodeSet(); mitk::DataNode* node = 0; for (std::vector::iterator it = allNodes.begin() ; it != allNodes.end(); it++) { node = *it; if(std::find(selectedNodes.begin(), selectedNodes.end(), node) == selectedNodes.end()) node->SetVisibility(false); else node->SetVisibility(true); } //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ToggleVisibilityOfSelectedNodes( bool ) { std::vector selectedNodes = this->GetSelectedNodes(); bool isVisible = false; mitk::DataNode* node = 0; for (std::vector::iterator it = selectedNodes.begin() ; it != selectedNodes.end(); it++) { isVisible = false; node = *it; node->GetBoolProperty("visible", isVisible); node->SetVisibility(!isVisible); } //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ShowInfoDialogForSelectedNodes( bool ) { std::vector selectedNodes = this->GetSelectedNodes(); QmitkInfoDialog _QmitkInfoDialog(selectedNodes, this->m_Parent); _QmitkInfoDialog.exec(); } void QmitkDataManagerView::Load( bool ) { QStringList fileNames = QFileDialog::getOpenFileNames(NULL, "Load data", "", mitk::CoreObjectFactory::GetInstance()->GetFileExtensions()); for ( QStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it ) { FileOpen((*it).toAscii(), 0); } } void QmitkDataManagerView::FileOpen( const char * fileName, mitk::DataNode* parentNode ) { mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New(); try { factory->SetFileName( fileName ); QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); factory->Update(); for ( unsigned int i = 0 ; i < factory->GetNumberOfOutputs( ); ++i ) { mitk::DataNode::Pointer node = factory->GetOutput( i ); if ( ( node.IsNotNull() ) && ( node->GetData() != NULL ) ) { this->GetDataStorage()->Add(node, parentNode); mitk::BaseData::Pointer basedata = node->GetData(); mitk::RenderingManager::GetInstance()->InitializeViews( basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } } catch ( itk::ExceptionObject & ex ) { itkGenericOutputMacro( << "Exception during file open: " << ex ); } QApplication::restoreOverrideCursor(); } void QmitkDataManagerView::GlobalReinit( bool ) { this->ReinitMultiWidgetEditor(); // get all nodes that have not set "includeInBoundingBox" to false mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox" , mitk::BoolProperty::New(false))); mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred); // calculate bounding geometry of these nodes mitk::TimeSlicedGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry mitk::RenderingManager::GetInstance()->InitializeViews(bounds); } std::vector QmitkDataManagerView::GetSelectedNodes() const { QModelIndexList indexesOfSelectedRows = m_NodeTreeView->selectionModel()->selectedRows(); std::vector selectedNodes; mitk::DataNode* node = 0; for (QModelIndexList::iterator it = indexesOfSelectedRows.begin() ; it != indexesOfSelectedRows.end(); it++) { node = 0; node = m_NodeTreeModel->GetNode(*it); // if node is not defined or if the node contains geometry data do not remove it if ( node != 0 ) selectedNodes.push_back(node); } return selectedNodes; } void QmitkDataManagerView::SelectionChanged( berry::IWorkbenchPart::Pointer part , berry::ISelection::ConstPointer selection ) { if(part.GetPointer() == this) return; mitk::DataNodeSelection::ConstPointer _DataNodeSelection = selection.Cast(); if(_DataNodeSelection.IsNull()) return; std::vector selectedNodes; mitk::DataNodeObject* _DataNodeObject = 0; mitk::DataNode* _DataNode = 0; QItemSelection newSelection; m_NodeTreeView->selectionModel()->reset(); for(mitk::DataNodeSelection::iterator it = _DataNodeSelection->Begin(); it != _DataNodeSelection->End(); ++it) { _DataNodeObject = dynamic_cast((*it).GetPointer()); if(_DataNodeObject) _DataNode = _DataNodeObject->GetDataNode(); QModelIndex treeIndex = m_NodeTreeModel->GetIndex(_DataNode); if(treeIndex.isValid()) newSelection.select(treeIndex, treeIndex); } m_NodeTreeView->selectionModel()->select(newSelection, QItemSelectionModel::SelectCurrent); } void QmitkDataManagerView::OtsuFilter( bool ) { std::vector selectedNodes = this->GetSelectedNodes(); mitk::DataNode* _DataNode = 0; mitk::Image::Pointer mitkImage = 0; for (std::vector::iterator it = selectedNodes.begin() ; it != selectedNodes.end(); it++) { _DataNode = *it; mitkImage = dynamic_cast( _DataNode->GetData() ); if(mitkImage.IsNull()) continue; try { // get selected mitk image const unsigned short dim = 3; typedef short InputPixelType; typedef unsigned char OutputPixelType; typedef itk::Image< InputPixelType, dim > InputImageType; typedef itk::Image< OutputPixelType, dim > OutputImageType; typedef itk::OtsuThresholdImageFilter< InputImageType, OutputImageType > FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetOutsideValue( 1 ); filter->SetInsideValue( 0 ); InputImageType::Pointer itkImage; mitk::CastToItkImage(mitkImage, itkImage); filter->SetInput( itkImage ); filter->Update(); mitk::DataNode::Pointer resultNode = mitk::DataNode::New(); std::string nameOfResultImage = _DataNode->GetName(); nameOfResultImage.append("Otsu"); resultNode->SetProperty("name", mitk::StringProperty::New(nameOfResultImage) ); resultNode->SetProperty("binary", mitk::BoolProperty::New(true) ); resultNode->SetData( mitk::ImportItkImage ( filter->GetOutput() ) ); this->GetDataStorage()->Add(resultNode, _DataNode); } catch( std::exception& err ) { MITK_ERROR(this->GetClassName()) << err.what(); } } } void QmitkDataManagerView::NodeTreeViewRowsRemoved ( const QModelIndex & parent, int start, int end ) { m_CurrentRowCount = m_NodeTreeModel->rowCount(); } void QmitkDataManagerView::NodeTreeViewRowsInserted( const QModelIndex & parent, int, int ) { m_NodeTreeView->setExpanded(parent, true); // a new row was inserted if( m_CurrentRowCount == 0 && m_NodeTreeModel->rowCount() == 1 ) { this->ReinitMultiWidgetEditor(); m_CurrentRowCount = m_NodeTreeModel->rowCount(); /* std::vector nodes = m_NodeTreeModel->GetNodeSet(); if(nodes.size() == 1) { QModelIndex treeIndex = m_NodeTreeModel->GetIndex(nodes.front()); m_NodeTreeView->selectionModel()->setCurrentIndex( treeIndex, QItemSelectionModel::ClearAndSelect ); } */ } } void QmitkDataManagerView::NodeSelectionChanged( const QItemSelection & /*selected*/, const QItemSelection & /*deselected*/ ) { std::vector nodes = m_NodeTreeModel->GetNodeSet(); mitk::DataNode* node = 0; for (std::vector::iterator it = nodes.begin() ; it != nodes.end(); it++) { node = *it; if ( node ) node->SetBoolProperty("selected", false); } nodes.clear(); nodes = this->GetSelectedNodes(); for (std::vector::iterator it = nodes.begin() ; it != nodes.end(); it++) { node = *it; if ( node ) node->SetBoolProperty("selected", true); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDataManagerView::ReinitMultiWidgetEditor() { berry::IEditorPart::Pointer editor; std::vector editors = this->GetSite()->GetPage()->GetEditors(); for (size_t i=0; i().IsNotNull() ) { editor = editors.at(i); break; } } if ( editor.IsNull() ) { mitk::IDataStorageService::Pointer service = berry::Platform::GetServiceRegistry().GetServiceById(mitk::IDataStorageService::ID); mitk::IDataStorageReference::Pointer DataStorageReference; if (service.IsNotNull()) { DataStorageReference = service->GetDefaultDataStorage(); } mitk::DataStorageEditorInput::Pointer editorInput; editorInput = new mitk::DataStorageEditorInput(DataStorageReference); // open a new multi-widget editor, but do not give it the focus berry::IEditorPart::Pointer editor = this->GetSite()->GetPage()->OpenEditor(editorInput, QmitkStdMultiWidgetEditor::EDITOR_ID, false); } else this->GetSite()->GetPage()->OpenEditor(editor->GetEditorInput() , QmitkStdMultiWidgetEditor::EDITOR_ID, true); }