SCM

Migration Guide 2.0 to 3.x

From Forge Wiki

Jump to: navigation, search

This page explains how to migrate your code from CamiTK 2.0 to CamiTK 3.x See also the ChangeLog for detailed information.

Contents

Action API

Action in CamiTK 3.0 is simplified but can take more use cases into account.

In CamiTK 2.0 Action::apply() was a private method, it is now a public slot and return an application status depending on how the action was carried out:

    public slots:
	 virtual ApplyStatus apply();

You need to update your Action subclass consequently.

In CamiTK 2.0 an action could access to the list of targeted components (i.e., selected and valid for the currently triggered action) by using the inherited protected targetComponents. This was violating the encapsulation principle. In CamiTK 3.0, you need to use the inherited protected getTargets() method.

Therefore wherever your had something like:

Component *last = targetComponents.last();

you need to replace it by

Component *last = getTargets().last();

New application actions

CamiTK 3.0 has a whole new list of actions to help you develop an application and its main window. They are called "Application Actions". Here is the list of these actions:


List of Application Action in CamiTK 3.0
Action Name Description

"Open"

shows a dialog to open a new file

"Clear Selection"

clears the list of selected item

"Save"

Save all the top-level of the selected components

"Save As"

Save the currently selected data under a different filename or format

"Save All"

Saves all the currently loaded data

"Close"

Close the currently selected components

"Close All"

Close all components, prompting for additional information if needed

"Quit"

Exit the application, prompting for additional information if needed

"Select Last Instanciated Top Level Component"

select the last top level component that was instanciated

"Remove Last Instanciated Top Level Component"

Remove the last top level component that was instanciated without saving it

"Show Console"

Show the redirection console window (view debugging information, cout, cerr,...)

"About..."

Show a little dialog about the application

Medical image viewer manipulation

"Show Axial Viewer"

Show the Axial Viewer Only

"Show Coronal Viewer"

Show the Coronal Viewer Only

"Show Sagittal Viewer"

Show the Sagittal Viewer Only

"Show 3D Viewer"

Show the 3D Viewer Only

"Show All Viewers"

Show Classical Medical Image Viewer (Axial, Coronal, Sagittal and 3D in a 4 panels)

"Show Arbitrary Viewer"

Show the Arbitrary Slice Viewer Only

If you were directly using slots from the MainWindow class, you need now to replace them by a trigger to the corresponding action.

For example, if you had:

    MainWindow::slotFileOpen();
    ...
   ImageComponent *myImage;
   ...
   Application::getMainWindow()->save(myImage);

You need to use the "Open" action like this:

    Application::getAction("Open")->trigger();
    ...
   ImageComponent *myImage;
   ...
   Application::save(myImage);

Note: the application actions have to be compiled and loaded, otherwise you will have an application crash.

ExtensionsManager, ComponentExtension and ActionManager

All the extensions (plugins, i.e, dll, so or dylib) are now managed by one class, called ExtensionManager. Therefore if you need to load a specific action or component extension, use the following code:

    // load a specific component extension
    ExtensionManager::loadComponentExtension(QStringContainingPathToYourComponentPluginFile);
 
    // load a specific action extension
    ExtensionManager::loadActionExtension(QStringContainingPathToYourActionPluginFile);

If you had something like:

    Action *myAction= ActionManager::getAction("The Action I Like");

You need to rewrite it to:

    Action *myAction= Application::getAction("The Action I Like");

ComponentManager and ActionManager

Both ComponentManager and ActionManager class were removed. All live instance of components (instanciated when the user open a component) and actions (instanciated at launch time but activated only when triggered) are now managed by the Application class static methods.

The following static methods are available to manage component instances:

// load the filename and returns the corresponding Component (return NULL if an error occurs)
Component* open(const QString &)
 
// load a directory and returns the corresponding Component (return NULL if an error occurs)
Component* openDirectory (const QString &dirName, const QString &pluginName)
 
// Close a Component: if it has been changed, ask the user for more information, then if everything is ok, delete it.
bool close (Component *component) 
 
// save a component to its file (as given by component->getFileName()).
bool save (Component *component) 
 
// get the current application wide list of instanciated top-level Components.
const ComponentList & getTopLevelComponents ()
 
// get the current application wide list of all Components.
const ComponentList & getAllComponents () 
 
// does this Component still exist?
bool isAlive (Component *) 
 
// Return true if at least one of the opened components has been modified, false otherwise. 
bool hasModified ()

The following static methods are available to manage actions:

// get a registered action given its name
Action* getAction (QString)
 
// 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 const ActionList getActions ()
 
// 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 getActions(Component *)
 
// 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 getActions(ComponentList)
 
// get all the actions that of a given tag (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates)
static ActionList getActions(ComponentList, QString)
 
// register all actions from the given ActionExtension  	
static int registerAllActions(ActionExtension *)

Application constructor

If you had this line in Camitk 2.0:

   Application a(argc,argv);

The first parameter is now a string. It is the name of your application. CamiTK 3.0 save application settings (geometry, colors, etc...) depending on this name. The application instanciation should look like this:

   Application a("Your Application Name",argc,argv);

DefaultActionWidget

If you had a DefaultActionWidget instance in your action header file (.h) simply remove it. It is now natively handled by the action viewer that will create one if you don't have any customized widget for your action.

getWidget method

If you had a getWidget( ) method simply remove it. It is now natively handled by the action viewer that will create one if you don't have any customized widget for your action.

apply method

You must add at the end of the apply method (in the (.cpp) source file), the following return value :

Action::ApplyStatus myAction::apply() {
    foreach (Component *comp, getTargets()) {
        myComponent  * input = dynamic_cast<myComponent*> ( comp );
            process(input);
    }
	return SUCCESS;
}
Powered By FusionForge