diff --git a/Applications/AppList.cmake b/Applications/AppList.cmake index 704f1ec375..c965a86005 100644 --- a/Applications/AppList.cmake +++ b/Applications/AppList.cmake @@ -1,21 +1,22 @@ # This file is included in the top-level MITK CMakeLists.txt file to # allow early dependency checking option(MITK_BUILD_APP_CoreApp "Build the MITK CoreApp" OFF) option(MITK_BUILD_APP_ExtApp "Build the MITK ExtApp" ON) option(MITK_BUILD_APP_mitkDiffusion "Build MITK Diffusion executable" OFF) # This variable is fed to ctkFunctionSetupPlugins() macro in the # top-level MITK CMakeLists.txt file. This allows to automatically # enable required plug-in runtime dependencies for applications using # the CTK DGraph executable and the ctkMacroValidateBuildOptions macro. # For this to work, directories containing executables must contain # a CMakeLists.txt file containing a "project(...)" command and a # target_libraries.cmake file setting a list named "target_libraries" # with required plug-in target names. set(MITK_APPS CoreApp^^MITK_BUILD_APP_CoreApp ExtApp^^MITK_BUILD_APP_ExtApp + mitkDiffusion^^MITK_BUILD_APP_mitkDiffusion ) diff --git a/Applications/CMakeLists.txt b/Applications/CMakeLists.txt index 366f008ddb..8e4124be00 100644 --- a/Applications/CMakeLists.txt +++ b/Applications/CMakeLists.txt @@ -1,27 +1,27 @@ set(MITK_CPACK_PACKAGE_EXECUTABLES "" CACHE INTERNAL "Collecting windows shortcuts to executables" FORCE) set(MITK_DIR ${PROJECT_BINARY_DIR}) set(MITK_EXPORTS_FILE_INCLUDED 1) if(MITK_USE_QT AND QT4_FOUND) if(MITK_USE_CTK) add_subdirectory(PluginGenerator) endif() if(MITK_BUILD_APP_CoreApp OR MITK_BUILD_ALL_APPS) add_subdirectory(CoreApp) endif() if(MITK_BUILD_APP_ExtApp OR MITK_BUILD_ALL_APPS) add_subdirectory(ExtApp) endif() if(MITK_BUILD_TUTORIAL) add_subdirectory(Tutorial) endif() - if(MITK_BUILD_APP_mitkDiffusion) + if(MITK_BUILD_APP_mitkDiffusion OR MITK_BUILD_ALL_APPS) add_subdirectory(mitkDiffusion) endif() endif() diff --git a/Applications/mitkDiffusion/CMakeLists.txt b/Applications/mitkDiffusion/CMakeLists.txt index d7cf0e0f25..09d8021344 100644 --- a/Applications/mitkDiffusion/CMakeLists.txt +++ b/Applications/mitkDiffusion/CMakeLists.txt @@ -1,130 +1,52 @@ -#----------------------------------------------------------------------------- -# Prerequesites -#----------------------------------------------------------------------------- - -find_package(Qt REQUIRED) - -#----------------------------------------------------------------------------- -# Include and linker directories -#----------------------------------------------------------------------------- - -INCLUDE(${QT_USE_FILE}) - -INCLUDE_DIRECTORIES( - ${org_blueberry_osgi_INCLUDE_DIRS} - ${Poco_INCLUDE_DIRS} - ${mbilog_INCLUDE_DIRS} - ${ALL_INCLUDE_DIRECTORIES} -) - -LINK_DIRECTORIES(${MITK_LIBRARY_DIRS}) - -#----------------------------------------------------------------------------- -# Executable -#----------------------------------------------------------------------------- +project(mitkDiffusion) set(DIFFUSIONAPP_NAME mitkDiffusion) -IF(MITK_SHOW_CONSOLE_WINDOW) - ADD_EXECUTABLE(${DIFFUSIONAPP_NAME} MACOSX_BUNDLE ${DIFFUSIONAPP_NAME}.cpp) -ELSE() - ADD_EXECUTABLE(${DIFFUSIONAPP_NAME} MACOSX_BUNDLE WIN32 ${DIFFUSIONAPP_NAME}.cpp) -ENDIF() - -TARGET_LINK_LIBRARIES(${DIFFUSIONAPP_NAME} org_blueberry_osgi ${ALL_LIBRARIES}) -IF(WIN32) - TARGET_LINK_LIBRARIES(${DIFFUSIONAPP_NAME} ${QT_QTCORE_LIBRARY} ${QT_QTMAIN_LIBRARY}) -ENDIF() - -# Make sure all enabled plug-ins are up to date when building the application -ctkFunctionExtractPluginTargets("${MITKDIFFUSION_PLUGINS}" ON _plugin_deps) - -IF(_plugin_deps) - # Make sure all enabled plug-ins are up to date - add_dependencies(${DIFFUSIONAPP_NAME} ${_plugin_deps}) -ENDIF() - -#----------------------------------------------------------------------------- -# Additional files needed for the executable -#----------------------------------------------------------------------------- - -# Create a provisioning file, listing all enabled plug-ins - -set(DIFFUSIONIMAGINGAPP_PROVISIONING_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${DIFFUSIONAPP_NAME}.provisioning") -FunctionCreateProvisioningFile( - FILE ${DIFFUSIONIMAGINGAPP_PROVISIONING_FILE} - INCLUDE "${MITK_PLUGIN_PROVISIONING_FILE}" +set(_app_options) +if(MITK_SHOW_CONSOLE_WINDOW) + list(APPEND _app_options SHOW_CONSOLE) +endif() + +MITK_USE_MODULE(qtsingleapplication) +include_directories(${ALL_INCLUDE_DIRECTORIES}) + +# Create a cache entry for the provisioning file which is used to export +# the file name in the MITKConfig.cmake file. This will keep external projects +# which rely on this file happy. +set(DIFFUSIONIMAGINGAPP_PROVISIONING_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${DIFFUSIONAPP_NAME}.provisioning" CACHE INTERNAL "${DIFFUSIONAPP_NAME} provisioning file" FORCE) + +set(_plugins + org.mitk.diffusionimaging + org.mitk.gui.qt.diffusionimagingapp + org.mitk.gui.qt.common.legacy + org.mitk.gui.qt.ext + org.mitk.gui.qt.datamanager + org.mitk.gui.qt.measurementtoolbox + org.mitk.gui.qt.segmentation + org.mitk.gui.qt.volumevisualization + org.mitk.gui.qt.diffusionimaging + org.mitk.gui.qt.imagenavigator + org.mitk.gui.qt.moviemaker + org.mitk.planarfigure ) -# Create a .ini file for initial parameters -CONFIGURE_FILE(${DIFFUSIONAPP_NAME}.ini - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${DIFFUSIONAPP_NAME}.ini) - -# Create batch files for Windows platforms -IF(WIN32) - FOREACH(DIFFUSIONIMAGINGAPP_BUILD_TYPE debug release) - mitkFunctionCreateWindowsBatchScript(start${DIFFUSIONAPP_NAME}.bat.in - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/start${DIFFUSIONAPP_NAME}_${DIFFUSIONIMAGINGAPP_BUILD_TYPE}.bat - ${DIFFUSIONIMAGINGAPP_BUILD_TYPE}) - ENDFOREACH() -ENDIF() - +# Plug-ins listed below will not be +# - added as a build-time dependency to the executable +# - listed in the provisioning file for the executable +# - installed if they are external plug-ins -#----------------------------------------------------------------------------- -# Source Files -#----------------------------------------------------------------------------- - -SET(CPP_FILES - mitkDiffusion.cpp - #mitkDiffusionImagingSafeQApplication.cpp - QDiffusionImagingSplashScreen.cpp +set(_exclude_plugins + org.blueberry.test + org.blueberry.uitest + org.mitk.gui.qt.coreapplication + org.mitk.gui.qt.extapplication ) -QT4_WRAP_CPP(CPP_FILES QDiffusionImagingSplashScreen.h) -QT4_ADD_RESOURCES(CPP_FILES splashscreen.qrc) - -#----------------------------------------------------------------------------- -# Bundle Activation -#----------------------------------------------------------------------------- - -SET(_mitk_dependencies -org_mitk_diffusionimaging -org_mitk_gui_qt_diffusionimagingapp -org_mitk_gui_qt_common_legacy -org_mitk_gui_qt_ext -org_mitk_gui_qt_datamanager -org_mitk_gui_qt_measurementtoolbox -org_mitk_gui_qt_segmentation -org_mitk_gui_qt_volumevisualization -org_mitk_gui_qt_diffusionimaging -org_mitk_gui_qt_imagenavigator -org_mitk_gui_qt_moviemaker -org_mitk_planarfigure +FunctionCreateBlueBerryApplication( + NAME ${DIFFUSIONAPP_NAME} + DESCRIPTION "MITK Diffusion" + PLUGINS ${_plugins} + EXCLUDE_PLUGINS ${_exclude_plugins} + LINK_LIBRARIES ${ALL_LIBRARIES} + ${_app_options} ) - -# check for missing mitk dependencies -FOREACH(_mitk_diffusion_dep ${_mitk_dependencies}) - IF(NOT TARGET ${_mitk_diffusion_dep}) - MESSAGE(FATAL_ERROR "missing dependency: ${_mitk_diffusion_dep}") - ENDIF() -ENDFOREACH() - -#----------------------------------------------------------------------------- -# Install support -#----------------------------------------------------------------------------- - -# This installs all enabled CTK plug-ins -FunctionInstallThirdPartyCTKPlugins(${CTK_PLUGIN_LIBRARIES}) - -# Install the executable and its provisioning file -MITK_INSTALL_TARGETS(EXECUTABLES ${DIFFUSIONAPP_NAME} GLOB_PLUGINS) -mitkFunctionInstallProvisioningFiles(${MITK_PROVISIONING_FILES} - ${DIFFUSIONIMAGINGAPP_PROVISIONING_FILE}) - -# On Linux, create a shell script to start a relocatable application -IF(UNIX AND NOT APPLE) - INSTALL(PROGRAMS "${MITK_SOURCE_DIR}/CMake/RunInstalledApp.sh" DESTINATION "." RENAME ${DIFFUSIONAPP_NAME}.sh) -ENDIF() - -# tell cpack the executables that you also want mitkDiffusion in the start menu as links -# mitkDiffusionSET(MITK_CPACK_PACKAGE_EXECUTABLES "${MITK_CPACK_PACKAGE_EXECUTABLES}" "${DIFFUSIONAPP_NAME}; MITK Diffusion" CACHE INTERNAL "Collecting windows shortcuts to executables") diff --git a/Applications/mitkDiffusion/mitkDiffusion.cpp b/Applications/mitkDiffusion/mitkDiffusion.cpp index 85210e7d6e..549db57ec2 100644 --- a/Applications/mitkDiffusion/mitkDiffusion.cpp +++ b/Applications/mitkDiffusion/mitkDiffusion.cpp @@ -1,118 +1,141 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date$ Version: $Revision: 13820 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/ 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 #include +#include +#include +#include + +#include #include #include -#include #include -#include - -#include -#include -#include -class mitkDiffusionImagingSafeQApplication : public QApplication +class QtSafeApplication : public QtSingleApplication { public: - mitkDiffusionImagingSafeQApplication(int& argc, char** argv); + QtSafeApplication(int& argc, char** argv) : QtSingleApplication(argc, argv) + {} /** * Reimplement notify to catch unhandled exceptions and open an error message. * * @param receiver * @param event * @return */ - bool notify(QObject* receiver, QEvent* event); - -}; - -mitkDiffusionImagingSafeQApplication::mitkDiffusionImagingSafeQApplication(int& argc, char** argv) -: QApplication(argc, argv) -{ - -} - -bool mitkDiffusionImagingSafeQApplication::notify(QObject* receiver, QEvent* event) -{ - QString msg; - try - { - return QApplication::notify(receiver, event); - } catch (Poco::Exception& e) + bool notify(QObject* receiver, QEvent* event) { - msg = QString::fromStdString(e.displayText()); - } catch (std::exception& e) - { - msg = e.what(); - } catch (...) - { - msg = "Unknown exception"; + QString msg; + try + { + return QApplication::notify(receiver, event); + } + catch (Poco::Exception& e) + { + msg = QString::fromStdString(e.displayText()); + } + catch (std::exception& e) + { + msg = e.what(); + } + catch (...) + { + msg = "Unknown exception"; + } + + QString text("An error occurred. You should save all data and quit the program to " + "prevent possible data loss.\nSee the error log for details.\n\n"); + text += msg; + + QMessageBox::critical(0, "Error", text); + return false; } - QString - text( - "An error occurred. You should save all data and quit the program to prevent possible data loss.\nSee the error log for details.\n\n"); - text += msg; - QMessageBox::critical(0, "Error", text); -} +}; + int main(int argc, char** argv) { + // Create a QApplication instance first + QtSafeApplication qSafeApp(argc, argv); + qSafeApp.setApplicationName("mitkDiffusion"); + qSafeApp.setOrganizationName("DKFZ"); - mitkDiffusionImagingSafeQApplication app(argc, argv); - app.setApplicationName("mitkDiffusion"); - app.setOrganizationName("DKFZ"); bool showSplashScreen(true); QPixmap pixmap( ":/splash/splashscreen.png" ); QSplashScreen splash( pixmap ); splash.setMask( pixmap.mask() ); splash.setWindowFlags( Qt::SplashScreen | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint ); if (showSplashScreen) { splash.show(); - app.sendPostedEvents(); - app.processEvents(); - app.flush(); + qSafeApp.sendPostedEvents(); + qSafeApp.processEvents(); + qSafeApp.flush(); QTimer::singleShot(4000, &splash, SLOT(close()) ); } + // This function checks if an instance is already running + // and either sends a message to it (containing the command + // line arguments) or checks if a new instance was forced by + // providing the BlueBerry.newInstance command line argument. + // In the latter case, a path to a temporary directory for + // the new application's storage directory is returned. + QString storageDir = handleNewAppInstance(&qSafeApp, argc, argv, "BlueBerry.newInstance"); + // These paths replace the .ini file and are tailored for installation // packages created with CPack. If a .ini file is presented, it will // overwrite the settings in MapConfiguration Poco::Path basePath(argv[0]); basePath.setFileName(""); - + Poco::Path provFile(basePath); provFile.setFileName("mitkDiffusion.provisioning"); - Poco::Util::MapConfiguration* sbConfig(new Poco::Util::MapConfiguration()); - sbConfig->setString(berry::Platform::ARG_PROVISIONING, provFile.toString()); - sbConfig->setString(berry::Platform::ARG_APPLICATION, "org.mitk.qt.diffusionimagingapp"); - return berry::Starter::Run(argc, argv, sbConfig); + Poco::Path extPath(basePath); + extPath.pushDirectory("ExtBundles"); + std::string pluginDirs = extPath.toString(); + + Poco::Util::MapConfiguration* extConfig(new Poco::Util::MapConfiguration()); + if (!storageDir.isEmpty()) + { + extConfig->setString(berry::Platform::ARG_STORAGE_DIR, storageDir.toStdString()); + } + extConfig->setString(berry::Platform::ARG_PLUGIN_DIRS, pluginDirs); + extConfig->setString(berry::Platform::ARG_PROVISIONING, provFile.toString()); + extConfig->setString(berry::Platform::ARG_APPLICATION, "org.mitk.qt.diffusionimagingapp"); + + // Preload the org.mitk.gui.qt.ext plug-in (and hence also QmitkExt) to speed + // up a clean-cache start. This also works around bugs in older gcc and glibc implementations, + // which have difficulties with multiple dynamic opening and closing of shared libraries with + // many global static initializers. It also helps if dependent libraries have weird static + // initialization methods and/or missing de-initialization code. + extConfig->setString(berry::Platform::ARG_PRELOAD_LIBRARY, "liborg_mitk_gui_qt_ext"); + + return berry::Starter::Run(argc, argv, extConfig); } diff --git a/Applications/mitkDiffusion/startmitkDiffusion.bat.in b/Applications/mitkDiffusion/startmitkDiffusion.bat.in index a4bf812c33..22d1f9f605 100644 --- a/Applications/mitkDiffusion/startmitkDiffusion.bat.in +++ b/Applications/mitkDiffusion/startmitkDiffusion.bat.in @@ -1,2 +1,2 @@ -PATH=@MITK_RUNTIME_PATH@;@CMAKE_RUNTIME_OUTPUT_DIRECTORY@/@VS_BUILD_TYPE@;@VTK_LIBRARY_DIRS@\@MITKDIFFUSIONIMAGING_BUILD_TYPE@;@ITK_LIBRARY_DIRS@\@MITKDIFFUSIONIMAGING_BUILD_TYPE@;@GDCM_BIN_DIR@;@MITK_BIN_DIRS@;@QT_LIBRARY_DIR@\..\bin;@BLUEBERRY_PLUGINS_OUTPUT_DIR@\org.blueberry.osgi\bin\@MITKDIFFUSIONIMAGING_BUILD_TYPE@ -@MITKDIFFUSIONIMAGING_BUILD_TYPE@\mitkDiffusion.exe +PATH=@MITK_RUNTIME_PATH@;%PATH% +@VS_BUILD_TYPE@\mitkDiffusion.exe diff --git a/Applications/mitkDiffusion/target_libraries.cmake b/Applications/mitkDiffusion/target_libraries.cmake new file mode 100644 index 0000000000..93c17932c5 --- /dev/null +++ b/Applications/mitkDiffusion/target_libraries.cmake @@ -0,0 +1,10 @@ + +# A list of plug-in targets which should be automatically enabled +# (or be available in external projects) for this application. + +set(target_libraries + org_blueberry_compat + org_blueberry_ui_qt + org_blueberry_ui_qt_help + org_mitk_gui_qt_diffusionimagingapp +)