00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "QmitkStdMultiWidgetEditor.h" 00019 00020 #include <berryUIException.h> 00021 #include <berryIWorkbenchPage.h> 00022 #include <berryIPreferencesService.h> 00023 00024 #include <QWidget> 00025 00026 #include <mitkGlobalInteraction.h> 00027 00028 #include <mitkDataStorageEditorInput.h> 00029 00030 const std::string QmitkStdMultiWidgetEditor::EDITOR_ID = "org.mitk.editors.stdmultiwidget"; 00031 00032 QmitkStdMultiWidgetEditor::QmitkStdMultiWidgetEditor() 00033 : m_StdMultiWidget(0) 00034 { 00035 00036 } 00037 00038 QmitkStdMultiWidgetEditor::~QmitkStdMultiWidgetEditor() 00039 { 00040 // we need to wrap the RemovePartListener call inside a 00041 // register/unregister block to prevent infinite recursion 00042 // due to the destruction of temporary smartpointer to this 00043 this->Register(); 00044 this->GetSite()->GetPage()->RemovePartListener(berry::IPartListener::Pointer(this)); 00045 this->UnRegister(false); 00046 } 00047 00048 QmitkStdMultiWidget* QmitkStdMultiWidgetEditor::GetStdMultiWidget() 00049 { 00050 return m_StdMultiWidget; 00051 } 00052 00053 void QmitkStdMultiWidgetEditor::Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input) 00054 { 00055 if (input.Cast<mitk::DataStorageEditorInput>().IsNull()) 00056 throw berry::PartInitException("Invalid Input: Must be IFileEditorInput"); 00057 00058 this->SetSite(site); 00059 this->SetInput(input); 00060 } 00061 00062 void QmitkStdMultiWidgetEditor::CreateQtPartControl(QWidget* parent) 00063 { 00064 if (m_StdMultiWidget == 0) 00065 { 00066 m_DndFrameWidget = new QmitkDnDFrameWidget(parent); 00067 QVBoxLayout* layout = new QVBoxLayout(parent); 00068 layout->addWidget(m_DndFrameWidget); 00069 layout->setContentsMargins(0,0,0,0); 00070 00071 m_StdMultiWidget = new QmitkStdMultiWidget(m_DndFrameWidget); 00072 QVBoxLayout* layout2 = new QVBoxLayout(m_DndFrameWidget); 00073 layout2->addWidget(m_StdMultiWidget); 00074 layout2->setContentsMargins(0,0,0,0); 00075 00076 mitk::DataStorage::Pointer ds = this->GetEditorInput().Cast<mitk::DataStorageEditorInput>() 00077 ->GetDataStorageReference()->GetDataStorage(); 00078 00079 // Tell the multiWidget which (part of) the tree to render 00080 m_StdMultiWidget->SetDataStorage(ds); 00081 00082 // Initialize views as transversal, sagittal, coronar to all data objects in DataStorage 00083 // (from top-left to bottom) 00084 mitk::TimeSlicedGeometry::Pointer geo = ds->ComputeBoundingGeometry3D(ds->GetAll()); 00085 mitk::RenderingManager::GetInstance()->InitializeViews(geo); 00086 00087 // Initialize bottom-right view as 3D view 00088 m_StdMultiWidget->GetRenderWindow4()->GetRenderer()->SetMapperID( 00089 mitk::BaseRenderer::Standard3D ); 00090 00091 // Enable standard handler for levelwindow-slider 00092 m_StdMultiWidget->EnableStandardLevelWindow(); 00093 00094 // Add the displayed views to the tree to see their positions 00095 // in 2D and 3D 00096 m_StdMultiWidget->AddDisplayPlaneSubTree(); 00097 00098 m_StdMultiWidget->EnableNavigationControllerEventListening(); 00099 00100 mitk::GlobalInteraction::GetInstance()->AddListener( 00101 m_StdMultiWidget->GetMoveAndZoomInteractor() 00102 ); 00103 this->GetSite()->GetPage()->AddPartListener(berry::IPartListener::Pointer(this)); 00104 00105 // enable change of logo 00106 berry::IPreferencesService::Pointer prefService 00107 = berry::Platform::GetServiceRegistry() 00108 .GetServiceById<berry::IPreferencesService>(berry::IPreferencesService::ID); 00109 00110 berry::IPreferences::Pointer logoPref = prefService->GetSystemPreferences()->Node("DepartmentLogo"); 00111 std::string departmentLogoLocation = logoPref->Get("DepartmentLogo",""); 00112 00113 m_StdMultiWidget->SetDepartmentLogoPath(departmentLogoLocation.c_str()); 00114 m_StdMultiWidget->DisableDepartmentLogo(); 00115 m_StdMultiWidget->EnableDepartmentLogo(); 00116 } 00117 } 00118 00119 berry::IPartListener::Events::Types QmitkStdMultiWidgetEditor::GetPartEventTypes() const 00120 { 00121 return Events::CLOSED | Events::HIDDEN | Events::VISIBLE; 00122 } 00123 00124 void QmitkStdMultiWidgetEditor::PartClosed( berry::IWorkbenchPartReference::Pointer partRef ) 00125 { 00126 if (partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID) 00127 { 00128 QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast<QmitkStdMultiWidgetEditor>(); 00129 00130 if (m_StdMultiWidget == stdMultiWidgetEditor->GetStdMultiWidget()) 00131 { 00132 m_StdMultiWidget->RemovePlanesFromDataStorage(); 00133 } 00134 } 00135 } 00136 00137 void QmitkStdMultiWidgetEditor::PartVisible( berry::IWorkbenchPartReference::Pointer partRef ) 00138 { 00139 if (partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID) 00140 { 00141 QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast<QmitkStdMultiWidgetEditor>(); 00142 00143 if (m_StdMultiWidget == stdMultiWidgetEditor->GetStdMultiWidget()) 00144 { 00145 m_StdMultiWidget->AddPlanesToDataStorage(); 00146 } 00147 } 00148 } 00149 00150 void QmitkStdMultiWidgetEditor::PartHidden( berry::IWorkbenchPartReference::Pointer partRef ) 00151 { 00152 if (partRef->GetId() == QmitkStdMultiWidgetEditor::EDITOR_ID) 00153 { 00154 QmitkStdMultiWidgetEditor::Pointer stdMultiWidgetEditor = partRef->GetPart(false).Cast<QmitkStdMultiWidgetEditor>(); 00155 00156 if (m_StdMultiWidget == stdMultiWidgetEditor->GetStdMultiWidget()) 00157 { 00158 m_StdMultiWidget->RemovePlanesFromDataStorage(); 00159 } 00160 } 00161 } 00162 00163 void QmitkStdMultiWidgetEditor::SetFocus() 00164 { 00165 if (m_StdMultiWidget != 0) 00166 m_StdMultiWidget->setFocus(); 00167 }