Difference between revisions of "Documentation/4.0/Developers/Tutorials/ModuleWriting"

From Slicer Wiki
Jump to: navigation, search
m (Move instructions in an array)
Line 2: Line 2:
  
 
= Initialization =
 
= Initialization =
* Create the Module directory
+
=== 1) Create the module directory ===
 +
Use the ModuleWizard.py script to generate files and directory based on a template.
 +
{|
 +
! style="border-bottom: 1px solid darkgrey;"| Linux
 +
! style="border-bottom: 1px solid darkgrey;"| Mac
 +
! style="border-bottom: 1px solid darkgrey;"| Windows
 +
|-
 +
| colspan=2; valign="top" |
 
  $ cd Slicer4
 
  $ cd Slicer4
 
  $ python Utilities/Scripts/ModuleWizard.py MY_MODULE_NAME
 
  $ python Utilities/Scripts/ModuleWizard.py MY_MODULE_NAME
Where you replace MY_MODULE_NAME with the name of the module you want (e.g. HelloWorld)
+
| valign="top" |
 
+
You need to open a terminal and go to the Slicer4 source directory.<br>
Note: on Windows 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<br>
Start -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt
+
Then type in the terminal:<br>
 
  $ cd here\is\the\path\of\Slicer4\source\directory
 
  $ cd here\is\the\path\of\Slicer4\source\directory
  $ ..\Slicer4-Superbuild\python-build\PCBuild\python.exe UtilitiesScripts\ModuleWizard.py MY_MODULE_NAME
+
  $ ..\Slicer4-Superbuild\python-build\PCBuild\python.exe Utilities\Scripts\ModuleWizard.py MY_MODULE_NAME
* Edit the file Slicer4/Modules/Loadable/CMakeLists.txt
+
|}
Add the name of your module at the end of the qtmodules variable assignment:
+
Replace MY_MODULE_NAME with the name of the module you want (e.g. HelloWorld)
 +
<br><br>
 +
=== 2) Add the module in CMake ===
 +
Edit the file [http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Modules/Loadable/CMakeLists.txt?view=markup Slicer4/Modules/Loadable/CMakeLists.txt]:
 +
Add the name of your module at the end of the qtmodules variable assignment:
 
  ...
 
  ...
 
  set(qtmodules
 
  set(qtmodules
Line 19: Line 30:
 
   )
 
   )
 
  ...
 
  ...
* Compile
+
<br><br>
 +
=== 3) Compile ===
 +
{|
 +
! style="border-bottom: 1px solid darkgrey;"| Linux
 +
! style="border-bottom: 1px solid darkgrey;"| Mac
 +
! style="border-bottom: 1px solid darkgrey;"| Windows
 +
|-
 +
| colspan=2; valign="top" |
 
  $ cd ../Slicer4-Superbuild/Slicer-build;
 
  $ cd ../Slicer4-Superbuild/Slicer-build;
 
  $ make -j4
 
  $ make -j4
On Windows, it would be:
+
| valign="top" |
  $ cd ../Slicer4-Superbuild/Slicer-build;
+
  $ cd ..\Slicer4-Superbuild\Slicer-build;
 
  $ .\Slicer.exe --VisualStudio Slicer.sln
 
  $ .\Slicer.exe --VisualStudio Slicer.sln
On the opened Visual Studio, go to Build -> Build Solution
+
In Visual Studio, go to Build -> Build Solution
* Start Slicer and verify the module is present (listed under "Module Template")
+
|}
 +
<br><br>
 +
=== 4) Check the module ===
 +
Start Slicer and make sure the module is present (listed under "Module Template")
 
  $ ./Slicer
 
  $ ./Slicer
* Open the designer via the launcher
+
<br><br>
 +
=== 5) Open the designer using the launcher ===
 +
The launcher ensures all the environment variables are correctly set for Qt Designer
 
  $./Slicer --designer
 
  $./Slicer --designer
*Edit the module UI file: QTModules/MY_MODULE_NAME/Resources/UI/qSlicerMY_MODULE_NAMEModule.ui
+
<br><br>
 +
=== 6) Change the UI ===
 +
Using Qt Designer, edit the module UI file: '''QTModules/MY_MODULE_NAME/Resources/UI/qSlicerMY_MODULE_NAMEModule.ui'''<br>
 
[[Slicer4:Developers:Projects:QtSlicer/Tutorials/QtDesigner|More info on how to use the designer]]
 
[[Slicer4:Developers:Projects:QtSlicer/Tutorials/QtDesigner|More info on how to use the designer]]
*Edit the module files
+
<br><br>
 +
=== 7) Edit the module files ===
 
  Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAME.[h|cxx]
 
  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/qSlicerMY_MODULE_NAMEWidget.[h|cxx]
 
  Slicer4/Modules/Loadable/MY_MODULE_NAME/Logic/vtkSlicerMY_MODULE_NAMELogic.[h|cxx]
 
  Slicer4/Modules/Loadable/MY_MODULE_NAME/Logic/vtkSlicerMY_MODULE_NAMELogic.[h|cxx]
 
  ...
 
  ...
 
+
<br><br>
 
= Qt Designer =
 
= Qt Designer =
 
* How to set icons to widgets
 
* How to set icons to widgets

Revision as of 15:44, 22 December 2011

Home < Documentation < 4.0 < Developers < Tutorials < ModuleWriting

Back to Developers Information

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)

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



5) Open the designer using the launcher

The launcher ensures all the environment variables are correctly set for Qt Designer

$./Slicer --designer



6) Change the UI

Using Qt Designer, edit the module UI file: QTModules/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>"