Documentation/4.0/Developers/Tutorials/ModuleWriting

From Slicer Wiki
Jump to: navigation, search
Home < Documentation < 4.0 < Developers < Tutorials < ModuleWriting

Back to Developers Information

Consider also reading

Initialization

1) Create the module directory

Use the ModuleWizard.py script to generate files and directory based on a template.

Linux Mac Windows
$ cd Slicer4
$ python Utilities/Scripts/ModuleWizard.py MY_MODULE_NAME

You need to open a terminal and go to the Slicer4 source directory.
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt
Then type in the terminal:

$ cd here\is\the\path\of\Slicer4\source\directory
$ ..\Slicer4-Superbuild\python-build\PCBuild\python.exe Utilities\Scripts\ModuleWizard.py MY_MODULE_NAME

Replace MY_MODULE_NAME with the name of the module you want (e.g. HelloWorld)
After running the script, a new directory MY_MODULE_NAME should be created in Slicer4/Modules/Loadable

2) Add the module in CMake

Edit the file Slicer4/Modules/Loadable/CMakeLists.txt: Add the name of your module at the end of the qtmodules variable assignment:

...
set(qtmodules
  ...
  MY_MODULE_NAME
  )
...



3) Compile

Linux Mac Windows
$ cd ../Slicer4-Superbuild/Slicer-build;
$ make -j4
$ cd ..\Slicer4-Superbuild\Slicer-build;
$ .\Slicer.exe --VisualStudio Slicer.sln

In Visual Studio, go to Build -> Build Solution



4) Check the module

Start Slicer and make sure the module is present (listed under "Module Template")

$ ./Slicer

To change the module title that shows up in Slicer, edit the file Slicer4/Modules/Loadable/MY_MODULE_NAME/CMakeLists.txt

set(qt_module_title "Your title") 

Other properties for the module such as help and acknowledgment can be re-implemented directly in C++ by editing Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAME.cxx.

5) Open Qt Designer using the launcher

Slicer (the launcher) searches Qt Designer on your machine (using QT_QMAKE_EXECUTABLE set at configure time). It starts the designer after setting the correct environment variables (QT_PLUGIN_PATH for the widgets designer plugins and PATH/LD_LIBRARY_PATH for the libraries).

$ ./Slicer --designer



6) Change the UI

Using Qt Designer, edit the module UI file: Modules/Loadable/MY_MODULE_NAME/Resources/UI/qSlicerMY_MODULE_NAMEModule.ui
More info on how to use the designer

7) Edit the module files

Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAME.[h|cxx]
Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAMEWidget.[h|cxx]
Slicer4/Modules/Loadable/MY_MODULE_NAME/Logic/vtkSlicerMY_MODULE_NAMELogic.[h|cxx]
...



Qt Designer

  • How to set icons to widgets
    • In the icon property entry of the widget (Property Editor), select a resource file
      • Slicer4/Modules/Loadable/MY_MODULE_NAME/Resources/qSlicerMY_MODULE_NAMEModule.qrc
      • Slicer4/Libs/MRML/Widgets/Resources/qMRMLWidget.qrc
      • Slicer4/Base/QTGUI/Resources/qSlicerBaseQTGUI.qrc
  • How to add an icon in a resource file
    • Add the icon in Slicer4/Modules/Loadable/MY_MODULE_NAME/Resources/Icon
    • Edit the resource file by adding the line
      • "<file>Icons/MyIcon.png</file>"