Commit 553df44b authored by jcfr's avatar jcfr
Browse files

ENH: Initial commit of the QtSlicer port. Added subdirs Base/GUI2,...

ENH: Initial commit of the QtSlicer port. Added subdirs Base/GUI2, Libs/QCTKWidgets and Libs/QMRMLWidgets. Updated Application/GUI/Slicer3 and Base/GUI/vtkSlicerApplication to be able to initialize and start QtModule. CMakeLists.txt also updated to consider the script CMake/Slicer3FindQT.cmake

git-svn-id: http://svn.slicer.org/Slicer4/trunk@10581 3bd1e089-480b-0410-8dfb-8563597acbee
parent 802c0072
......@@ -11,6 +11,15 @@
See License.txt or http://www.slicer.org/copyright/copyright.txt for details.
==========================================================================*/
//---------------------------------------------------------------------------
// Slicer3_USE_QT
//
#ifdef Slicer3_USE_QT
#include "qSlicerModuleTransform.h"
#include "qSlicerApplication.h"
#endif
#include "vtkOpenGLRenderWindow.h"
#include "vtkRenderWindow.h"
......@@ -60,6 +69,9 @@
#include "vtkSlicerROILogic.h"
#include "vtkSlicerROIGUI.h"
//---------------------------------------------------------------------------
// Slicer3_USE_PYTHON
//
#ifdef Slicer3_USE_PYTHON
#include "slicerPython.h"
......@@ -71,8 +83,6 @@ extern "C" {
#endif
//#define Slicer3_USE_QT
#include <vtksys/SystemTools.hxx>
#include <vtksys/Directory.hxx>
#include <vtksys/stl/string>
......@@ -831,6 +841,10 @@ int Slicer3_main(int argc, char *argv[])
vtksys_stl::string root = vtksys::SystemTools::GetCurrentWorkingDirectory();
scene->SetRootDirectory(root.c_str());
vtkMRMLScene::SetActiveScene( scene );
slicerApp->SetMRMLScene( scene );
#ifdef Slicer3_USE_QT
qSlicerApplication::application()->setMRMLScene( scene );
#endif
// Create the application Logic object,
// Create the application GUI object
......@@ -1414,6 +1428,12 @@ int Slicer3_main(int argc, char *argv[])
appGUI->InitializeSlicesControlGUI();
appGUI->InitializeViewControlGUI();
// appGUI->InitializeNavigationWidget();
#ifdef Slicer3_USE_QT
// --- Transforms2 module
slicerApp->SplashMessage("Initializing Transforms2 Module...");
slicerApp->AddAndShowModule(new qSlicerModuleTransform());
#endif
// --- First scene needs a crosshair to be added manually
vtkMRMLCrosshairNode *crosshair = vtkMRMLCrosshairNode::New();
......@@ -1538,7 +1558,7 @@ int Slicer3_main(int argc, char *argv[])
// get the Tcl name so the vtk class will be registered in the interpreter
// as a byproduct
// - set some handy variables so it will be easy to access these classes
/// from the tkcon
// from the tkcon
// - all the variables are put in the slicer3 tcl namespace for easy access
// - note, slicerApp is loaded as $::slicer3::Application above, so it
// can be used from scripts that run without the GUI
......
......@@ -6,6 +6,13 @@ endif(Slicer3_BUILD_TESTING)
subdirs(
Logic
)
IF(Slicer3_USE_QT)
subdirs(GUI2)
ENDIF(Slicer3_USE_QT)
subdirs(
GUI
CLI
)
......@@ -13,6 +13,10 @@ set(include_dirs
${CMAKE_CURRENT_BINARY_DIR}
${SlicerBaseLogic_SOURCE_DIR}
${SlicerBaseLogic_BINARY_DIR}
${SlicerBaseGUI2_SOURCE_DIR}
${SlicerBaseGUI2_BINARY_DIR}
${QMRMLWidgets_SOURCE_DIR}
${QMRMLWidgets_BINARY_DIR}
${MRML_SOURCE_DIR}
${MRML_BINARY_DIR}
${ModuleDescriptionParser_SOURCE_DIR}
......
......@@ -22,13 +22,13 @@
#include <vtkSlicerBaseGUIQtConfigure.h>
#if defined(WIN32) && !defined(VTKSLICER_STATIC)
#if defined(SlicerBaseGUIQt_EXPORTS)
#define VTK_SLICER_BASE_GUI_QT_EXPORT __declspec( dllexport )
#if defined(SlicerBaseGUIQt_EXPORTS)
#define VTK_SLICER_BASE_GUI_QT_EXPORT __declspec( dllexport )
#else
#define VTK_SLICER_BASE_GUI_QT_EXPORT __declspec( dllimport )
#endif
#else
#define VTK_SLICER_BASE_GUI_QT_EXPORT __declspec( dllimport )
#endif
#else
#define VTK_SLICER_BASE_GUI_QT_EXPORT
#define VTK_SLICER_BASE_GUI_QT_EXPORT
#endif
#endif
......@@ -4,8 +4,12 @@
# include "PythonQt.h"
# include "PythonQt_QtAll.h"
# endif
#include <QApplication>
#include "qSlicerApplication.h"
#include "qSlicerAbstractModule.h"
#include "QtSlicerWebKit.h"
#include <QHash>
#endif
#include <sstream>
......@@ -32,6 +36,7 @@
#include "vtkSlicerBaseGUIWin32Header.h"
#include "vtkKWRegistryHelper.h"
#include "vtkSlicerGUILayout.h"
#include "vtkMRMLScene.h"
#include "vtkMRMLLayoutNode.h"
#include "vtkSlicerGUICollection.h"
#include "vtkSlicerTheme.h"
......@@ -213,10 +218,36 @@ private:
//
// vtkStandardNewMacro(vtkSlicerOutputWindow);
//----------------------------------------------------------------------------
class vtkSlicerApplication::vtkInternal
{
public:
#ifdef Slicer3_USE_QT
typedef QHash<QString, qSlicerAbstractModule*>::const_iterator ModuleListConstIterator;
typedef QHash<QString, qSlicerAbstractModule*>::iterator ModuleListIterator;
#endif
vtkInternal()
{
#ifdef Slicer3_USE_QT
this->qApplication = 0;
#endif
this->MRMLScene = 0;
}
vtkMRMLScene* MRMLScene;
#ifdef Slicer3_USE_QT
qSlicerApplication* qApplication;
QHash<QString, qSlicerAbstractModule*> ModuleList;
#endif
};
//---------------------------------------------------------------------------
vtkSlicerApplication::vtkSlicerApplication ( ) {
this->ApplicationGUI = NULL;
this->Internal = new vtkInternal;
// note: these are fixed size arrays, not pointers,
// so initializing them to null string is correct
......@@ -334,12 +365,12 @@ vtkSlicerApplication::vtkSlicerApplication ( ) {
#ifdef Slicer3_USE_QT
char *argv = NULL;
int argc = 0;
this->qapp = new QApplication(argc, &argv);
this->Internal->qApplication = new qSlicerApplication(argc, &argv);
#ifdef Slicer3_USE_PYTHONQT
#ifdef Slicer3_USE_PYTHONQT
PythonQt::init(PythonQt::DoNotInitializePython);
PythonQt_QtAll::init();
#endif
#endif
#endif
}
......@@ -347,6 +378,11 @@ vtkSlicerApplication::vtkSlicerApplication ( ) {
//---------------------------------------------------------------------------
vtkSlicerApplication::~vtkSlicerApplication ( ) {
#ifdef Slicer3_USE_QT
this->Internal->qApplication->quit();
#endif
delete this->Internal;
if ( this->DefaultGeometry )
{
this->DefaultGeometry->Delete ( );
......@@ -625,6 +661,82 @@ vtkSlicerModuleGUI* vtkSlicerApplication::GetModuleGUIByName ( const char *name
return ( NULL );
}
//---------------------------------------------------------------------------
void vtkSlicerApplication::SetMRMLScene( vtkMRMLScene* scene)
{
this->Internal->MRMLScene = scene;
}
//---------------------------------------------------------------------------
vtkMRMLScene* vtkSlicerApplication::GetMRMLScene()
{
return this->Internal->MRMLScene;
}
#ifdef Slicer3_USE_QT
//---------------------------------------------------------------------------
void vtkSlicerApplication::AddAndShowModule(qSlicerAbstractModule * module)
{
this->AddModule( module );
module->setMRMLScene( this->GetMRMLScene() );
module->show();
}
//---------------------------------------------------------------------------
void vtkSlicerApplication::AddModule(qSlicerAbstractModule * module)
{
if (!module)
{
return;
}
QString name = module->moduleName();
if (this->Internal->ModuleList.contains(name))
{
return;
}
this->Internal->ModuleList[name] = module;
}
//---------------------------------------------------------------------------
void vtkSlicerApplication::RemoveModule(qSlicerAbstractModule * module)
{
if (!module)
{
return;
}
QString name = module->moduleName();
vtkInternal::ModuleListConstIterator iter = this->Internal->ModuleList.find( name );
if ( iter == this->Internal->ModuleList.constEnd())
{
return;
}
}
//---------------------------------------------------------------------------
qSlicerAbstractModule* vtkSlicerApplication::GetModule ( const char *name )
{
vtkInternal::ModuleListConstIterator iter = this->Internal->ModuleList.find( name );
if ( iter == this->Internal->ModuleList.constEnd())
{
return 0;
}
return *iter;
}
//---------------------------------------------------------------------------
void vtkSlicerApplication::ShowModule ( const char *name )
{
qSlicerAbstractModule * module = this->GetModule(name);
if (!name)
{
return;
}
module->show();
}
#endif
//---------------------------------------------------------------------------
void vtkSlicerApplication::ConfigureApplication ( ) {
......@@ -694,7 +806,7 @@ void vtkSlicerApplication::DoOneTclEvent ( )
broker->ProcessEventQueue();
}
#ifdef Slicer3_USE_QT
this->qapp->processEvents();
this->Internal->qApplication->processEvents();
#endif
}
......@@ -2327,7 +2439,6 @@ vtkKWColorPickerDialog* vtkSlicerApplication::GetColorPickerDialog()
return Superclass::GetColorPickerDialog();
}
//----------------------------------------------------------------------------
// Temporary test method
void vtkSlicerApplication::TestQtSlicerWebKit(const char *url)
......
......@@ -9,6 +9,13 @@
#include "vtkSlicerApplicationGUI.h"
#ifdef Slicer3_USE_QT
//BTX
class qSlicerApplication;
class qSlicerAbstractModule;
//ETX
#endif
class vtkSlicerModuleGUI;
class vtkSlicerGUILayout;
class vtkSlicerTheme;
......@@ -17,11 +24,6 @@ class vtkSlicerGUICollection;
class DisplayMessageQueue;
//ETX
//BTX
#ifdef Slicer3_USE_QT
class QApplication;
#endif
//ETX
// Description:
// Contains slicer's style, application and collection of associated guis.
......@@ -62,6 +64,22 @@ class VTK_SLICER_BASE_GUI_EXPORT vtkSlicerApplication : public vtkKWApplication
virtual void AddModuleGUI ( vtkSlicerModuleGUI *gui );
virtual void RemoveModuleGUI ( vtkSlicerModuleGUI *gui );
virtual vtkSlicerModuleGUI* GetModuleGUIByName ( const char *name );
// Description:
// Set/Get MRML scene
void SetMRMLScene( vtkMRMLScene* scene);
vtkMRMLScene* GetMRMLScene();
#ifdef Slicer3_USE_QT
// Description:
//BTX
virtual void AddModule(qSlicerAbstractModule * module);
virtual void AddAndShowModule(qSlicerAbstractModule * module);
virtual void RemoveModule(qSlicerAbstractModule * module);
virtual qSlicerAbstractModule* GetModule( const char *name );
virtual void ShowModule ( const char *name );
//ETX
#endif
// Description:
// These methods manage windows associated with the application
......@@ -395,12 +413,6 @@ class VTK_SLICER_BASE_GUI_EXPORT vtkSlicerApplication : public vtkKWApplication
const char* GetSvnUrl();
const char* GetSvnRevision();
#ifdef Slicer3_USE_QT
//BTX
QApplication* GetQApplication()
{return this->qapp;};
//ETX
#endif
void TestQtSlicerWebKit(const char *url);
protected:
......@@ -504,11 +516,12 @@ private:
// have we added the mrml color table nodes to the color picker dialog yet?
int ColorSwatchesAdded;
//BTX
#ifdef Slicer3_USE_QT
QApplication *qapp;
#endif
class vtkInternal;
vtkInternal* Internal;
//ETX
};
#endif
project(SlicerBaseGUI2)
cmake_minimum_required(VERSION 2.4)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
#-----------------------------------------------------------------------------
# Sources
#
SET(qSlicerGUI2_SRCS
qSlicerAbstractModule.h
qSlicerAbstractModule.cxx
qSlicerModuleTransform.h
qSlicerModuleTransform.cxx
qSlicerApplication.h
qSlicerApplication.cxx
qSlicerIOManager.h
qSlicerIOManager.cxx
)
# Headers that should run through moc
SET(qSlicerGUI2_MOC_SRCS
qSlicerAbstractModule.h
qSlicerModuleTransform.h
qSlicerApplication.h
)
# UI files
SET(qSlicerGUI2_UI_SRCS
Resources/UI/qSlicerModuleTransform.ui
)
QT4_WRAP_CPP(qSlicerGUI2_SRCS ${qSlicerGUI2_MOC_SRCS})
QT4_WRAP_UI(qSlicerGUI2_UI_CXX ${qSlicerGUI2_UI_SRCS})
QT4_ADD_RESOURCES(qSlicerGUI2_QRC_SRCS Resources/qSlicerGUI2.qrc)
SET_SOURCE_FILES_PROPERTIES(
${qSlicerGUI2_UI_CXX}
${qSlicerGUI2_SRCS}
WRAP_EXCLUDE
)
# --------------------------------------------------------------------------
# Include dirs
set(include_dirs
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${SlicerBaseLogic_SOURCE_DIR}
${SlicerBaseLogic_BINARY_DIR}
${QCTKWidgets_SOURCE_DIR}
${QCTKWidgets_BINARY_DIR}
${QMRMLWidgets_SOURCE_DIR}
${QMRMLWidgets_BINARY_DIR}
${MRML_SOURCE_DIR}
${MRML_BINARY_DIR}
)
set(QT_INCLUDE_DIRS
${QT_INCLUDE_DIR}
${QT_QTWEBKIT_INCLUDE_DIR}
${QT_QTGUI_INCLUDE_DIR}
${QT_QTCORE_INCLUDE_DIR}
)
SET(QT_LIBRARIES
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTWEBKIT_LIBRARY}
QVTK
)
set(include_dirs ${include_dirs} ${QT_INCLUDE_DIRS})
include_directories(${include_dirs})
slicer3_get_persistent_property(Slicer3_Base_LIBRARIES tmp)
slicer3_set_persistent_property(Slicer3_Base_LIBRARIES ${tmp} ${include_dirs})
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/qSlicerBaseGUI2Configure.h.in
${CMAKE_CURRENT_BINARY_DIR}/qSlicerBaseGUI2Configure.h
)
# --------------------------------------------------------------------------
# Build the library
set(lib_name "SlicerBaseGUI2")
add_library(${lib_name}
${qSlicerGUI2_SRCS}
${qSlicerGUI2_UI_CXX}
${qSlicerGUI2_QRC_SRCS}
)
target_link_libraries(${lib_name}
${QT_LIBRARIES}
SlicerBaseLogic
QCTKWidgets
QMRMLWidgets
)
slicer3_get_persistent_property(Slicer3_Base_LIBRARIES tmp)
slicer3_set_persistent_property(Slicer3_Base_LIBRARIES ${tmp} ${lib_name})
# Apply user-defined properties to the library target.
IF(Slicer3_LIBRARY_PROPERTIES)
SET_TARGET_PROPERTIES(${lib_name} PROPERTIES
${Slicer3_LIBRARY_PROPERTIES}
)
ENDIF(Slicer3_LIBRARY_PROPERTIES)
# --------------------------------------------------------------------------
# Install the library
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
install(FILES
${files}
${CMAKE_CURRENT_BINARY_DIR}/qSlicerBaseGUI2Configure.h
DESTINATION ${Slicer3_INSTALL_INCLUDE_DIR}/${PROJECT_NAME} COMPONENT Development
)
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/Resources/*.h")
install(FILES
${files}
DESTINATION ${Slicer3_INSTALL_INCLUDE_DIR}/${PROJECT_NAME}/Resources COMPONENT Development
)
install(TARGETS ${lib_name}
RUNTIME DESTINATION ${Slicer3_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${Slicer3_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${Slicer3_INSTALL_LIB_DIR} COMPONENT Development
)
file(GLOB PNGFILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "Resources/*.png")
foreach(pngfile ${PNGFILES})
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/${pngfile}
${CMAKE_BINARY_DIR}/${Slicer3_INSTALL_SHARE_DIR}/${PROJECT_NAME}/${pngfile}
COPYONLY
)
endforeach(pngfile)
install(
FILES ${PNGFILES}
DESTINATION ${Slicer3_INSTALL_SHARE_DIR}/${PROJECT_NAME}/Resources
)
# --------------------------------------------------------------------------
# Testing
if(BUILD_TESTING)
# no tests yet...
# add_test(Slicer3GUITest1 ${Slicer3_BINARY_DIR}/Slicer3 --test-mode --script ${Slicer3_SOURCE_DIR}/Base/GUI/Testing/TestSliceController.tcl)
endif(BUILD_TESTING)
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>qSlicerModuleTransform</class>
<widget class="QWidget" name="qSlicerModuleTransform">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>485</width>
<height>468</height>
</rect>
</property>
<property name="windowTitle">
<string>Transform Module</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="qMRMLNodeSelector" name="TransformNodeSelector" native="true"/>
</item>
<item>
<widget class="QGroupBox" name="MatrixViewGroupBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Transform Matrix view</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>2</number>
</property>
<item>
<widget class="qMRMLMatrixWidget" name="MatrixWidget" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="qMRMLTransformSliders" name="TranslationSliders" native="true"/>
</item>
<item>
<widget class="qMRMLTransformSliders" name="RotationSliders" native="true"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QGroupBox" name="CoordinateReferenceGroupBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>Coordinate Reference</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="GlobalRadioButton">
<property name="text">
<string>Global</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="LocalRadioButton">
<property name="text">
<string>Local</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>