35 #include <QMessageBox> 36 #include <QApplication> 39 #include "internal/org_mitk_gui_common_Activator.h" 43 struct WorkbenchUtilPrivate {
63 return defaultDescriptor;
83 throw berry::PartInitException(
"No editor found");
91 ctkPluginContext* context = mitk::PluginActivator::GetContext();
101 QString msg =
"IDataStorageService service not available. Unable to open files.";
103 QMessageBox::warning(QApplication::activeWindow(),
"Unable to open files", msg);
109 context->ungetService(dsRef);
111 return dataStorageRef;
118 if (fileNames.empty())
124 if (
nullptr == dataStorageReference)
131 #if defined(_MSC_VER) && !defined(NDEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) 132 int lastCrtReportType = _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
136 DataStorage::SetOfObjects::Pointer data;
146 const bool dsmodified = !data->empty();
149 #if defined(_MSC_VER) && !defined(NDEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) 150 if (lastCrtReportType)
151 _CrtSetReportMode(_CRT_ASSERT, lastCrtReportType);
155 if (window->GetActivePage().
IsNull())
157 QString defaultPerspId = window->GetWorkbench()->GetPerspectiveRegistry()->GetDefaultPerspective();
158 window->GetWorkbench()->ShowPerspective(defaultPerspId, window);
161 bool globalReinitOnNodeAdded =
true;
163 if (prefService !=
nullptr)
169 globalReinitOnNodeAdded = prefs->GetBool(
"Call global reinit if node is added",
true);
173 if (openEditor && globalReinitOnNodeAdded)
181 mitk::IRenderingManager* renderingManager = renderEditor ==
nullptr ? nullptr : renderEditor->GetRenderingManager();
183 if (dsmodified && renderingManager)
188 catch (
const berry::PartInitException& e)
190 QString msg =
"An error occurred when displaying the file(s): %1";
191 QMessageBox::warning(QApplication::activeWindow(),
"Error displaying file",
192 msg.arg(e.message()));
202 throw std::invalid_argument(
"page argument must not be nullptr");
206 return page->OpenEditor(input, editorId, activate);
214 throw std::invalid_argument(
"page argument must not be nullptr");
218 QString name = input->GetName() +
".mitk";
221 GetDefaultEditor(name, determineContentType));
223 return page->OpenEditor(input, editorDesc->GetId(), activate);
230 throw std::invalid_argument(
"name argument must not be empty");
239 return WorkbenchUtilPrivate::GetEditorDescriptor(name, editorReg, editorReg->
GetDefaultEditor(name ));
249 if (!editorID.isEmpty())
277 if (renderWindowPart)
279 return renderWindowPart;
283 QList<berry::IEditorReference::Pointer> editors = page->GetEditorReferences();
284 for (QList<berry::IEditorReference::Pointer>::iterator i = editors.begin(); i != editors.end(); ++i)
287 if (page->IsPartVisible(part))
290 if (renderWindowPart)
292 return renderWindowPart;
298 QList<berry::IViewReference::Pointer> views = page->GetViewReferences();
299 for (QList<berry::IViewReference::Pointer>::iterator i = views.begin(); i != views.end(); ++i)
302 if (page->IsPartVisible(part))
305 if (renderWindowPart)
307 return renderWindowPart;
313 if (strategies == NONE)
319 if (
nullptr == dataStorageReference)
326 bool activate =
false;
327 if (strategies & ACTIVATE)
333 if (strategies & OPEN)
341 catch (
const berry::PartInitException&)
346 else if (activate || (strategies & BRING_TO_FRONT))
349 editorPart = page->FindEditor(input);
354 page->Activate(editorPart);
358 page->BringToTop(editorPart);
370 return GetRenderWindowPart(page, ACTIVATE | OPEN);
374 return GetRenderWindowPart(page, BRING_TO_FRONT | OPEN);
380 if (context ==
nullptr)
382 BERRY_WARN <<
"Plugin context invalid, unable to set custom logo.";
389 const QString logoFileName = logoResource.mid(logoResource.lastIndexOf(
'/') + 1);
391 if (logoFileName.isEmpty())
393 BERRY_WARN <<
"Logo file name empty, unable to set custom logo.";
397 const QString logoPath = context->getDataFile(
"").absoluteFilePath();
399 bool extractLogo =
true;
400 QFileInfo logoFileInfo(logoPath +
"/" + logoFileName);
402 if (logoFileInfo.exists())
406 QString pluginLocation = QUrl(context->getPlugin()->getLocation()).toLocalFile();
407 if (!pluginLocation.isEmpty())
409 QFileInfo pluginFileInfo(pluginLocation);
410 if (logoFileInfo.lastModified() > pluginFileInfo.lastModified())
420 QFile logo(logoResource);
424 BERRY_WARN <<
"Custom logo '" << logoResource <<
"' does not exist.";
428 if (logo.open(QIODevice::ReadOnly))
430 QFile localLogo(logoPath +
"/" + logoFileName);
432 if (localLogo.open(QIODevice::WriteOnly))
434 localLogo.write(logo.readAll());
440 logoFileInfo.refresh();
442 if (logoFileInfo.exists())
454 prefService->
GetSystemPreferences()->Put(
"DepartmentLogo", qPrintable(logoFileInfo.absoluteFilePath()));
458 BERRY_WARN <<
"Preferences service not available, unable to set custom logo.";
464 BERRY_WARN <<
"Custom logo at '" << logoFileInfo.absoluteFilePath().toStdString() <<
"' does not exist.";
static const QString SYSTEM_INPLACE_EDITOR_ID
static berry::IEditorDescriptor::Pointer GetDefaultEditor(const QString &file, bool determineContentType)
virtual IEditorDescriptor::Pointer FindEditor(const QString &editorId)=0
static berry::IEditorDescriptor::Pointer GetEditorDescriptor(const QString &name, bool inferContentType=true)
virtual IDataStorageReference::Pointer GetDataStorage() const =0
Interface for a MITK Workbench Part providing a render window.
static IRenderWindowPart * GetRenderWindowPart(berry::IWorkbenchPage::Pointer page, IRenderWindowPartStrategies strategies)
Returns the currently active mitk::IRenderWindowPart.
DataCollection - Class to facilitate loading/accessing structured data.
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
static IRenderWindowPart * OpenRenderWindowPart(berry::IWorkbenchPage::Pointer page, bool activatedEditor=true)
Uses 'GetRenderWindowPart' to open the a render window part with a certain strategy: Calls 'GetRender...
static bool SetDepartmentLogoPreference(const QString &logoResource, ctkPluginContext *context)
static void LoadFiles(const QStringList &fileNames, berry::IWorkbenchWindow::Pointer wnd, bool openEditor=true)
berry::SmartPointer< Self > Pointer
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
static RenderingManager * GetInstance()
virtual IEditorDescriptor::Pointer GetDefaultEditor()=0
virtual bool IsSystemInPlaceEditorAvailable(const QString &filename)=0
virtual bool IsSystemExternalEditorAvailable(const QString &filename)=0
static berry::IEditorPart::Pointer OpenEditor(berry::IWorkbenchPage::Pointer page, berry::IEditorInput::Pointer input, const QString &editorId, bool activate=false)
static QList< mitk::BaseData::Pointer > Load(const QStringList &paths, QWidget *parent=nullptr)
Loads the specified files.
static const QString SYSTEM_EXTERNAL_EDITOR_ID
virtual void InitializeViewsByBoundingObjects(const DataStorage *)
Initializes the renderwindows by the aggregated geometry of all objects that are held in the data sto...
An interface for accessing a mitk::RenderingManager instance.
virtual IEditorRegistry * GetEditorRegistry() const =0
ObjectType * GetPointer() const