NA-MIC/Projects/Collaboration/Slicer3 Theme

From NAMIC Wiki
Revision as of 16:03, 30 June 2008 by Vmagnotta (talk | contribs)
Jump to: navigation, search
Home < NA-MIC < Projects < Collaboration < Slicer3 Theme
Building Block shown with number of mesh seeds color coded.
Mesh quality visualization.



Key Investigators

  • Iowa: Vincent Magnotta, Nicole Grosland, Hans Johnson


Objective

This page describes how to incorporate the Slicer3 Theme into any KWWidgets based application. Hopefully this will develop into a Slicer3 Theme library that one can link against.


Getting the Slicer3 Theme Files

The Slicer3 theme is a clean and nice looking user interface. This page describes how to incroporate the theme into any KWWidgets application.

  • The following source code files are needed from the Slicer3 code base. These are located in Slicer3/Base/GUI
    • vtkSlicerCheckRadioButtonIcons.cxx vtkSlicerCheckRadioButtonIcons.h
    • vtkSlicerFont.cxx vtkSlicerFont.h
    • vtkSlicerTheme.cxx vtkSlicerTheme.h
    • vtkSlicerColor.cxx vtkSlicerColor.h
    • vtkSlicerIcons.cxx vtkSlicerIcons.h
  • The following icons are needed. These are located in Slicer3/Base/GUI/Resources. This file needs to be put in a directory called Resources that is in the same directory as vtkSlicerCheckRadioButtonIcons.h
    • vtkSlicerCheckRadioButton_ImageData.h

Slicer3 Theme Modifications

Modify vtkSlicerTheme.cxx

  • Change line 5 from
#include vtkSlicerApplication.h 

to

#include vtkMyApplication.h
  • Change line 61 and 108 from
vtkSlicerApplication *app = vtkSlicerApplication::SafeDownCast(this->GetApplication() );

to

vtkKWMyApplication *app = vtkKWMyApplication::SafeDownCast(this->GetApplication() );


Your Application Modifications

Application class header file

#ifndef __vtkKWMyApplication_h
#define __vtkKWMyApplication_h
 
#include "vtkKWApplication.h"
#include "vtkKWRegistryHelper.h"


class vtkSlicerTheme;

class vtkKWMyApplication : public vtkKWApplication
{
public:
 static vtkKWMyApplication* New();
 vtkTypeRevisionMacro(vtkKWMyApplication,vtkKWApplication);

 virtual void InstallTheme ( vtkKWTheme *theme );
 virtual void InstallDefaultTheme ( );
 vtkSlicerTheme *GetSlicerTheme ( );

 // Description:
 // Set/Get the application font family
 void SetApplicationFontFamily ( const char *family);
 const char *GetApplicationFontFamily ( ) const;

 // Description:
 // Set/Get the application font size
 void SetApplicationFontSize ( const char *size );
 const char *GetApplicationFontSize ( ) const;
 .
 .
 .
protected:
 vtkKWMyApplication();
 ~vtkKWMyApplication();
 
 vtkSlicerTheme *SlicerTheme;
 char ApplicationFontSize [vtkKWRegistryHelper::RegistryKeyValueSizeMax];
 char ApplicationFontFamily [vtkKWRegistryHelper::RegistryKeyValueSizeMax];    
 .
 .
 .
};

Application class source file

vtkKWMyApplication::vtkKWMimxApplication()
{
 vtkKWFrameWithLabel::SetDefaultLabelFontWeightToNormal( );
 this->SlicerTheme = vtkSlicerTheme::New ( );
 
 strcpy ( this->ApplicationFontSize,   "small" );
 strcpy ( this->ApplicationFontFamily, "Arial" );
 .
 .
 .
}

//---------------------------------------------------------------------------
void vtkKWMimxApplication::InstallDefaultTheme ( )
{
 InstallTheme( this->SlicerTheme );
}

//---------------------------------------------------------------------------
void vtkKWMimxApplication::InstallTheme ( vtkKWTheme *theme )
{
 if ( theme != NULL ) 
 {
   if ( vtkSlicerTheme::SafeDownCast (theme) == this->SlicerTheme ) {
       this->SetTheme (this->SlicerTheme );
   } else {
       this->SetTheme ( theme );
   }
 }
}

//---------------------------------------------------------------------------
vtkSlicerTheme *vtkKWMimxApplication::GetSlicerTheme ( )
{
 return this->SlicerTheme;
}

//----------------------------------------------------------------------------
void vtkKWMimxApplication::SetApplicationFontFamily ( const char *font)
{
 char localFont[32];
 strcpy(localFont, font);
   
 if ( this->SlicerTheme )
   {
   this->SlicerTheme->SetFontFamily ( localFont );
   this->Script ( "font configure %s -family %s", this->SlicerTheme->GetApplicationFont2(), localFont );
   this->Script ( "font configure %s -family %s", this->SlicerTheme->GetApplicationFont1(), localFont );
   this->Script ( "font configure %s -family %s", this->SlicerTheme->GetApplicationFont0(), localFont );
   strcpy ( this->ApplicationFontFamily, localFont );
   this->SetRegistryValue(1, "Font", "Family", localFont);
   }

}

//----------------------------------------------------------------------------
const char *vtkKWMimxApplication::GetApplicationFontFamily () const
{
 return this->ApplicationFontFamily;
}

//----------------------------------------------------------------------------
void vtkKWMimxApplication::SetApplicationFontSize ( const char *size)
{
 char localSize[32];
 strcpy(localSize, size);
 
 if (this->SlicerTheme)
   {
   vtkSlicerFont *font = this->SlicerTheme->GetSlicerFonts();
   if ( font )
     {
     // check to see if m has a valid value:
     if ( font->IsValidFontSize ( localSize ) )
       {
       int f2 = font->GetFontSize2( localSize );
       int f1 = font->GetFontSize1( localSize );
       int f0 = font->GetFontSize0( localSize );
       
       this->Script ( "font configure %s -size %d", this->SlicerTheme->GetApplicationFont2(), f2);
       this->Script ( "font configure %s -size %d", this->SlicerTheme->GetApplicationFont1(), f1);
       this->Script ( "font configure %s -size %d", this->SlicerTheme->GetApplicationFont0(), f0);
       
       strcpy (this->ApplicationFontSize, localSize );
       this->SetRegistryValue(1, "Font", "Size", localSize);
       }
     }
   }    
}

//----------------------------------------------------------------------------
const char *vtkKWMimxApplication::GetApplicationFontSize () const
{
 return this->ApplicationFontSize;
}

Main Program

In your main program will need the following lines. You probably already have the first line to create the application. The second line will install the Slicer3 theme for you.

vtkKWMyApplication *app = vtkKWMyApplication::New();
app->InstallDefaultTheme( );      

CMakeLists.txt File

The following files will now need to be added to your CMakeLists.txt file and built either as part of a library or your application

  • vtkSlicerTheme.cxx
  • vtkSlicerColor.cxx
  • vtkSlicerFont.cxx
  • vtkSlicerCheckRadioButtonIcons.cxx
  • vtkSlicerIcons.cxx

Results

  • The Slicer3 Theme has now been installed in both the IA-FEMesh and BRAINSTracer applications using these changes.