Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Private Slots | Private Attributes | Static Private Attributes | List of all members
camitk::Application Class Reference

The generic/default application. More...

#include <Application.h>

+ Inheritance diagram for camitk::Application:

Public Member Functions

 Application (QString name, int &argc, char **argv, bool autoloadExtension=true, bool registerFileExtension=false)
 Initializes the window system and constructs a CamiTK application object with argc command line arguments in argv. More...
 
virtual ~Application ()
 destructor More...
 

Static Public Member Functions

Application specific
static QString getName ()
 get the application name More...
 
static QSettings & getSettings ()
 Get the Core wide settings. More...
 
static int exec ()
 Overriden from QApplication: Enters the main event loop and waits until exit() is called, then returns the value that was set to exit() (which is 0 if exit() is called via quit()). More...
 
static const QDir getLastUsedDirectory ()
 Get the last used directory (e.g. More...
 
static void setLastUsedDirectory (QDir)
 set (force) the last used directory More...
 
static void addRecentDocument (QFileInfo)
 Add a document to the list of recent documents (e.g. More...
 
static const QList< QFileInfo > getRecentDocuments ()
 Get the list of recent documents. More...
 
static const int getMaxRecentDocuments ()
 get the maximal number of recent documents stored More...
 
Selection management
static const ComponentListgetSelectedComponents ()
 get the currently selected Components. More...
 
static void clearSelectedComponents ()
 clear all the selection, i.e call setSelected(false) for all the previously selected components and clear the list. More...
 
Action instances management
static ActiongetAction (QString)
 get a registered action given its name More...
 
static const ActionList getActions ()
 get all the actions registered in the application (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates) More...
 
static ActionList getActions (Component *)
 get all the actions that can be applied on a given component (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates) More...
 
static ActionList getActions (ComponentList)
 Get all the actions that can be applied on any components of the given list of components (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates) More...
 
static ActionList getActions (ComponentList, QString)
 get all the actions that of a given tag (note: the returned ActionList is guaranteed to be sorted by action name and to contain no duplicates) More...
 
static int registerAllActions (ActionExtension *)
 register all actions from the given ActionExtension More...
 

Private Slots

void quitting ()
 

Static Private Member Functions

Components management
static ComponentListgetTopLevelComponentList ()
 get the current application wide list of instanciated top-level Components. More...
 
static ComponentListgetAllComponentList ()
 get the current application wide list of all Components. More...
 
static ComponentListgetSelectedComponentList ()
 get the currently selected Components. More...
 
static void setSelected (Component *component, bool isSelected)
 insert/remove one specific Component to the selection (at the end). More...
 
static void addComponent (Component *)
 register a new component either in the full component list, or in the full list and in the top-level list. More...
 
static void removeComponent (Component *)
 unregister a Component. More...
 
Actions management
static QMap< QString, Action * > & getActionMap ()
 all the registered actions, this is a QMap as actions are mainly sort/compared/process by name (key). More...
 
static ActionList sort (ActionSet)
 sort an ActionSet by action's name More...
 

Private Attributes

int argc
 argc given from command line More...
 
char ** argv
 argv given from command line More...
 

Static Private Attributes

static MainWindowmainWindow
 the main window of the CamiTK application More...
 
static QString name
 name of the CamiTK application (used to differentiate settings between CamiTK applications) More...
 
static QSettings settings
 global settings for CamiTK application More...
 
Recent document management

list of all the remembered recent documents (last opened is last inserted!)

static QList< QFileInfo > recentDocuments
 
static QDir lastUsedDirectory
 last used directory More...
 
static int maxRecentDocuments
 max number of recent document (default 10) More...
 

Component instances management

class Component
 Only the class Component can access to the private members addComponent(..) and removeComponent(..) More...
 
static Componentopen (const QString &)
 load the filename and returns the corresponding Component (return NULL if an error occurs) More...
 
static ComponentopenDirectory (const QString &dirName, const QString &pluginName)
 load a directory and returns the corresponding Component (return NULL if an error occurs) More...
 
static bool close (Component *component)
 Close a Component: if it has been changed, ask the user for more information, then if everything is ok, delete it. More...
 
static bool save (Component *component)
 save a component to its file (as given by component->getFileName()). More...
 
static const ComponentListgetTopLevelComponents ()
 get the current application wide list of instanciated top-level Components. More...
 
static const ComponentListgetAllComponents ()
 get the current application wide list of all Components. More...
 
static bool isAlive (Component *)
 does this Component still exists? More...
 
static bool hasModified ()
 Return true if at least one of the opened components has been modified, false otherwise. More...
 

Main Window management

void setMainWindow (MainWindow *mw)
 set the main window. More...
 
static MainWindowgetMainWindow ()
 get the main window More...
 
static void refresh ()
 refresh the main window (this will call the refresh method of all viewers) More...
 
static void showStatusBarMessage (QString msg, int timeout=0)
 Set a message to the status bar. More...
 
static void resetProgressBar ()
 Resets the progress bar if it exists. More...
 
static void setProgressBarValue (int)
 set the progress bar value, value should be in [0..100]. More...
 
static void vtkProgressFunction (vtkObject *caller, long unsigned int eventId, void *clientData, void *callData)
 Observer function to be called by vtkFilters and to update progress bar Example of use: More...
 

Actions pipeline history

get the history of actions stored.

  • This method follows the "construct on first use" idiom/design-pattern.
static void addHistoryItem (HistoryItem item)
 Add the history item to the application history. More...
 
static HistoryItem removeLastHistoryItem ()
 Remove the last pushed actions in the history of the current pipeline. More...
 
static void saveHistoryAsSXML ()
 Save the history as an SCXML file, stored using. More...
 
static QStack< HistoryItem > & getHistory ()
 get the singleton stack of actions stored in a pipeline This is the private (intern) method. More...
 

Detailed Description

The generic/default application.

Once this class is intanciated in the main, everything is setup. The constructor can take the command line arguments. It can also be asked not to load the extensions automatically,see Application().

If you do not have a specific MainWindow extension, then the default CamiTK MainWindow is used, see setMainWindow()

Constructor & Destructor Documentation

camitk::Application::Application ( QString  name,
int &  argc,
char **  argv,
bool  autoloadExtension = true,
bool  registerFileExtension = false 
)

Initializes the window system and constructs a CamiTK application object with argc command line arguments in argv.

The first parameter is the name of the application (used as a identifier in the settings, for example)

The second and third parameters comes from the command line (see QApplication API documentation). This constructor inits all the CamiTK context:

  • log file
  • application wide settings
  • autoload (or not, depending on the last parameter) of the extension
Note
that you have to call init before doing anything!
Parameters
namethe name of the application, it will be used to save specific configuration for example.
argcthe number of command line arguments
argvthe values of the command line arguments
autoloadExtensionif true, all the plugins are loaded
registerFileExtensionif true, the application will prompt the user at first run if he wants to register file formats handled by loaded components with this application for opening. Works only (at the moment) on Windows platform.
virtual camitk::Application::~Application ( )
virtual

destructor

Member Function Documentation

static void camitk::Application::addComponent ( Component )
staticprivate

register a new component either in the full component list, or in the full list and in the top-level list.

Note
do not call this method from anywhere BUT the Component class destructor; Component is a friend class.
static void camitk::Application::addHistoryItem ( HistoryItem  item)
static

Add the history item to the application history.

The item is added to the history stack of actions used in a pipeline

See also
removeLastHistoryItem() To pop back an action from the history use
Parameters
itemthe item to add to the history
static void camitk::Application::addRecentDocument ( QFileInfo  )
static

Add a document to the list of recent documents (e.g.

when a document was opened) and update lastUsedDirectory

static void camitk::Application::clearSelectedComponents ( )
static

clear all the selection, i.e call setSelected(false) for all the previously selected components and clear the list.

static bool camitk::Application::close ( Component component)
static

Close a Component: if it has been changed, ask the user for more information, then if everything is ok, delete it.

Parameters
componentthe Component to close.
Returns
true if the closing was made, false if the user cancelled the operation or a saving problem occurs
static int camitk::Application::exec ( )
static

Overriden from QApplication: Enters the main event loop and waits until exit() is called, then returns the value that was set to exit() (which is 0 if exit() is called via quit()).

It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.

Generally, no user interaction can take place before calling exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.

To make your application perform idle processing, i.e., executing a special function whenever there are no pending events, use a QTimer with 0 timeout. More advanced idle processing schemes can be achieved using processEvents().

static Action* camitk::Application::getAction ( QString  )
static

get a registered action given its name

static QMap<QString,Action*>& camitk::Application::getActionMap ( )
staticprivate

all the registered actions, this is a QMap as actions are mainly sort/compared/process by name (key).

This is the private (intern) method. The component extension map is updated by loadExtension, unloadExtension and autoloadExtensions. This method follows the "construct on first use" idiom/design-pattern. It therefore avoids the infamous "static initialization order fiasco", see http://www.parashift.com/c++-faq/ctors.html

static const ActionList camitk::Application::getActions ( )
static

get all the actions registered in the application (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates)

static ActionList camitk::Application::getActions ( Component )
static

get all the actions that can be applied on a given component (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates)

static ActionList camitk::Application::getActions ( ComponentList  )
static

Get all the actions that can be applied on any components of the given list of components (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates)

static ActionList camitk::Application::getActions ( ComponentList  ,
QString   
)
static

get all the actions that of a given tag (note: the returned ActionList is guaranteed to be sorted by action name and to contain no duplicates)

static ComponentList& camitk::Application::getAllComponentList ( )
staticprivate

get the current application wide list of all Components.

This is the private (intern) method. This holds all the components at any level (full component list), top-level or under. This method follows the "construct on first use" idiom/design-pattern. It therefore avoids the infamous "static initialization order fiasco", see http://www.parashift.com/c++-faq/ctors.html

static const ComponentList& camitk::Application::getAllComponents ( )
static

get the current application wide list of all Components.

This is the public method (return a const, the component list is private and cannot be modified externally).

static QStack<HistoryItem>& camitk::Application::getHistory ( )
staticprivate

get the singleton stack of actions stored in a pipeline This is the private (intern) method.

This history is updated (push(), pop()) by addHistoryItem() and removeHistoryItem() This method follows the "construct on first use" idiom/design-pattern. It therefore avoids the infamous "static initialization order fiasco", see http://www.parashift.com/c++-faq/ctors.html

static const QDir camitk::Application::getLastUsedDirectory ( )
static

Get the last used directory (e.g.

the directory of the last opened document)

static MainWindow* camitk::Application::getMainWindow ( )
static

get the main window

static const int camitk::Application::getMaxRecentDocuments ( )
static

get the maximal number of recent documents stored

static QString camitk::Application::getName ( )
static

get the application name

static const QList<QFileInfo> camitk::Application::getRecentDocuments ( )
static

Get the list of recent documents.

static ComponentList& camitk::Application::getSelectedComponentList ( )
staticprivate

get the currently selected Components.

This is the private (intern) method. the current selection (selected Components can at any level). This method follows the "construct on first use" idiom/design-pattern. It therefore avoids the infamous "static initialization order fiasco", see http://www.parashift.com/c++-faq/ctors.html

static const ComponentList& camitk::Application::getSelectedComponents ( )
static

get the currently selected Components.

This is the public method (return a const, the selected component list is private and cannot be modified externally).

static QSettings& camitk::Application::getSettings ( )
static

Get the Core wide settings.

This is the preferred methods for accessing and writing the settings for your specific needs, although you can use any kind of settings you like, using this allow you to store all settings in one place for all Core needs. This settings are stored in the user scope, using the INI format (i.e. no registers !), the organisation name is TIMC-IMAG and the application name is equal to Core::version. Check the QSettings API documentation to know exactly where is the settings file or call Application::getSettings().fileName()

The recommanded method is to use one section for each Core area. Use the beginGroup("my area")/endGroup() to define specific settings area.

Note
for each beginGroup you use, you HAVE TO use an endGroup(), otherwise the settings state integrity is not guaranteed!
static ComponentList& camitk::Application::getTopLevelComponentList ( )
staticprivate

get the current application wide list of instanciated top-level Components.

This is the private (intern) method. The top-level component list is updated by the Component class top-level constructor. This method follows the "construct on first use" idiom/design-pattern. It therefore avoids the infamous "static initialization order fiasco", see http://www.parashift.com/c++-faq/ctors.html

static const ComponentList& camitk::Application::getTopLevelComponents ( )
static

get the current application wide list of instanciated top-level Components.

This is the public method (return a const, the top-level component list is private and cannot be modified externally).

static bool camitk::Application::hasModified ( )
static

Return true if at least one of the opened components has been modified, false otherwise.

static bool camitk::Application::isAlive ( Component )
static

does this Component still exists?

static Component* camitk::Application::open ( const QString &  )
static

load the filename and returns the corresponding Component (return NULL if an error occurs)

static Component* camitk::Application::openDirectory ( const QString &  dirName,
const QString &  pluginName 
)
static

load a directory and returns the corresponding Component (return NULL if an error occurs)

Parameters
dirNamethe name of the directory to open
pluginNamethe name of the plugin to use
void camitk::Application::quitting ( )
privateslot
static void camitk::Application::refresh ( )
static

refresh the main window (this will call the refresh method of all viewers)

static int camitk::Application::registerAllActions ( ActionExtension )
static

register all actions from the given ActionExtension

Returns
the number of actions effectively registered (in case an action's name is already registered it won't be a second time)
static void camitk::Application::removeComponent ( Component )
staticprivate

unregister a Component.

This method remove top-level component and other level component

Note
do not call this method from anywhere BUT the Component class destructor Component is a friend class.
static HistoryItem camitk::Application::removeLastHistoryItem ( )
static

Remove the last pushed actions in the history of the current pipeline.

See also
addHistoryItem() To push back the item use
static void camitk::Application::resetProgressBar ( )
static

Resets the progress bar if it exists.

See example of use for ProgressFunction for more detailed explanation.

static bool camitk::Application::save ( Component component)
static

save a component to its file (as given by component->getFileName()).

Note
the component's file name has to be set prior to call this method.

This method look for the proper loaded ComponentExtension, and call its save(Component*) method

static void camitk::Application::saveHistoryAsSXML ( )
static

Save the history as an SCXML file, stored using.

See also
addHistoryItem() method. This file can be interpreted by the camitk actionstatemachine executable
static void camitk::Application::setLastUsedDirectory ( QDir  )
static

set (force) the last used directory

void camitk::Application::setMainWindow ( MainWindow mw)

set the main window.

You need to call this method in order to use a customized CamiTK MainWindow instead of the default one. This method has to be called after init().

It allows you to set the main window using your application extension instance.

Note
Application takes ownership of the MainWindow pointer and deletes it at the appropriate time.
Parameters
mwThe instance of main window you want to use for your application (if NULL a new instance of the MainWindow class is created)
static void camitk::Application::setProgressBarValue ( int  )
static

set the progress bar value, value should be in [0..100].

Attempting to change the current value to one outside the minimum-maximum range has no effect on the current value.

Consider using vtkProgressFunction()

Referenced by camitk::ItkProgressObserver::Execute(), camitk::ItkProgressObserver::ItkProgressObserver(), and camitk::ItkProgressObserver::Reset().

static void camitk::Application::setSelected ( Component component,
bool  isSelected 
)
staticprivate

insert/remove one specific Component to the selection (at the end).

The selected component list is a QList, because the selection order is important (QList is order, QSet is not). But it does not make any sense to have two times the same Component instance so if isSelected is true we have to "manually" check that it is not already in the list

Note
do not call this method from anywhere BUT the Component setSelected method; Component is a friend class.
Parameters
componentthe component to insert/remove from the selection
isSelectedif true then insert if not already in the selection, otherwise remove
static void camitk::Application::showStatusBarMessage ( QString  msg,
int  timeout = 0 
)
static

Set a message to the status bar.

By default there is no timeout (default), i.e. the given message remains displayed until this method is called again (or the status bar is cleared otherwise).

Parameters
msgthe message to display in the status bar.
timeoutnumber of milli-seconds (timeout) before the status bar is cleared (default = 0, i.e. until next call)
static ActionList camitk::Application::sort ( ActionSet  )
staticprivate

sort an ActionSet by action's name

static void camitk::Application::vtkProgressFunction ( vtkObject *  caller,
long unsigned int  eventId,
void *  clientData,
void *  callData 
)
static

Observer function to be called by vtkFilters and to update progress bar Example of use:

Application::showStatusBarMessage("Applying my vtk filter");
vtkSmartPointer<vtkCallbackCommand> progressCallback = vtkSmartPointer<vtkCallbackCommand>::New();
progressCallback->SetCallback(&Application::vtkProgressFunction);
myVtkFilter->AddObserver(vtkCommand::ProgressEvent, progressCallback);

Friends And Related Function Documentation

friend class Component
friend

Only the class Component can access to the private members addComponent(..) and removeComponent(..)

Member Data Documentation

int camitk::Application::argc
private

argc given from command line

char** camitk::Application::argv
private

argv given from command line

QDir camitk::Application::lastUsedDirectory
staticprivate

last used directory

MainWindow* camitk::Application::mainWindow
staticprivate

the main window of the CamiTK application

int camitk::Application::maxRecentDocuments
staticprivate

max number of recent document (default 10)

QString camitk::Application::name
staticprivate

name of the CamiTK application (used to differentiate settings between CamiTK applications)

QList<QFileInfo> camitk::Application::recentDocuments
staticprivate
QSettings camitk::Application::settings
staticprivate

global settings for CamiTK application


The documentation for this class was generated from the following file: