[Ctk-developers] CTK plugin framework tutorial/example

Sergio Vera sergio.vera at alma3d.com
Mon May 27 11:48:18 EDT 2013


Hi all
I tried to do a plugin test some time ago but unfortunately I could not
develop it much becasue I had more urgent and important work to do :(

I managed to create a minium skeleton of plugin enabled app and test
plugin. I home might help someone advance a bit. Here is my recipe:

TOP LEVEL SOURCE DIRECTORY (
A CmakeLists.txt file with the project general infor and the plugin
enabling commands with something like this:
-----------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8)
PROJECT(MyViewer)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})  # include UseQt4.cmake
FIND_PACKAGE(CTK REQUIRED)
INCLUDE(${CTK_USE_FILE}) # include UseCTK.cmake

# Extract all library names starting with org_mydomain_ this regular domain
defines your plugins
macro(GetMyTargetLibraries all_target_libraries varname)
  set(re_ctkplugin "^com_alma_[a-zA-Z0-9_]+$")
  set(_tmp_list)
  list(APPEND _tmp_list ${all_target_libraries})
  ctkMacroListFilter(_tmp_list re_ctkplugin OUTPUT_VARIABLE ${varname})
endmacro()

#> Create a list of available plug-ins and make them known to the build
system
set(plugins
  Plugins/com.alma.rd.tracker:ON
)
ctkMacroSetupPlugins(${plugins})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/CoreApp)  # This is the main
App, that should load
------------------------------------------------------------------------------------------------------------
Now, I Have a Root\Plugins\com.alma.rd.tracker directory with another
CMakelistst.txt for the plugin itself:
-------------------------------------------------------------------------------
PROJECT(com_alma_rd_tracker) #IIRC this projectname is important

set(PLUGIN_export_directive "com_alma_rd_tracker_EXPORT")

set(PLUGIN_SRCS
  TrackerListenerActivator.cpp
  TrackerListenerLogic.cpp
  TrackerListenerLogic.h
)

# Files which should be processed by Qts moc
set(PLUGIN_MOC_SRCS
TrackerListenerActivator.h
)

# Qt Designer files which should be processed by Qts uic
set(PLUGIN_UI_FORMS
)

# QRC Files which should be compiled into the plugin
set(PLUGIN_resources
)

#Compute the plugin dependencies
ctkFunctionGetTargetLibraries(PLUGIN_target_libraries)

ctkMacroBuildPlugin(
  NAME ${PROJECT_NAME}
  EXPORT_DIRECTIVE ${PLUGIN_export_directive}
  SRCS ${PLUGIN_SRCS}
  MOC_SRCS ${PLUGIN_MOC_SRCS}
  UI_FORMS ${PLUGIN_UI_FORMS}
  RESOURCES ${PLUGIN_resources}
  TARGET_LIBRARIES ${PLUGIN_target_libraries}
)
---------------------------------------------------------------------------------------------------

The TrackerListenerActivator class is the interface with the CTK's plugin
system while the logic class should do whatever work the plugin is supposed
to do.

The CoreApp folders is there the main APP that can list and use plugins
lies... The CMakeLists.txt in this folder does no have any plugin specific
command at all.
Inside CoreApp\MainWindow.cxx I have a initplugin function: You'll see that
I was testing the exact way to init the plugins when I had to put the
project away.* I cannot guarantee that this code really works 100% but I
think it will be a good starting point for anyone willing to try CTK
plugins:*

________________________________________________________________________________________________
void
MainWindow::InitPluginSystem() {

//ctkPluginFrameworkLauncher::addSearchPath("C:\\work\\pruebas-bin\\CTKTest\\Plugins\\com.alma.rd.tracker");
//ctkPluginFrameworkLauncher::addSearchPath("C:\\work\\pruebas-bin\\CTKTest\\Plugins\\com.alma.rd.tracker\\Release");
ctkPluginFrameworkLauncher::addSearchPath("C:/work/pruebas-bin/CTKTest/Plugins/com.alma.rd.tracker/Release");
 bool succeeded = false;
try {
succeeded = ctkPluginFrameworkLauncher::start("com.alma.rd.tracker");
}catch(ctkPluginException &e) {
std::cout << e.message().toStdString() << std::endl;
const ctkException* e2 = e.cause();
if(e2)
std::cout << e2->message().toStdString() << std::endl;
 }catch(ctkRuntimeException &e) {
std::cout << e.what() << std::endl;
const ctkException* e2 = e.cause();
if(e2)
std::cout << e2->message().toStdString() << std::endl;
}

/*
succeeded = ctkPluginFrameworkLauncher::start("org.commontk.eventadmin");
if (succeeded) {
std::cout << "org.commontk.eventadmin started succesfully" << std::endl;
ctkPluginContext* pluginContext =
ctkPluginFrameworkLauncher::getPluginContext();
ctkServiceReference eventAdminRef =
pluginContext->getServiceReference<ctkEventAdmin>();
ctkEventAdmin* eventAdmin =
pluginContext->getService<ctkEventAdmin>(eventAdminRef);
eventAdmin->sendEvent(ctkEvent("mydomain/tutorial/CustomEvent"));
} else
std::cout << "org.commontk.eventadmin not started" << std::endl;
 succeeded =
ctkPluginFrameworkLauncher::start("com.alma.rd.trackerlistener");
if (succeeded) {
std::cout << "com.alma.rd.trackerlistenerservice started succesfully" <<
std::endl;
} else
std::cout << "com.alma.rd.trackerlistenerservice not started" << std::endl;
*/
}
________________________________________________________________________________________________
I've stripped the code from unnecesary files and I've attached the relevant
code bits in this email.

I hope it helps to some degree.

Best Regards


On Fri, May 24, 2013 at 10:57 PM, Zelzer, Sascha <
s.zelzer at dkfz-heidelberg.de> wrote:

> Hi,
>
> There is an application in CTK called PluginGenerator helping you with
> generating a plugin.
>
> I am traveling right now but will send you more information soon.
>
> Thanks,
>
> Sascha
>
>
> Von Samsung Mobile gesendet
>
>
>
> -------- Ursprüngliche Nachricht --------
> Von: Florian Ganglberger <Florian.Ganglberger at student.i-med.ac.at>
> Datum:
> An: ctk-developers at commontk.org
> Betreff: Re: [Ctk-developers] CTK plugin framework tutorial/example
>
>
> Hi Jean-Christophe,
> I have already had a look at the wiki. Unfortunately the "Create a new
> CTK Plugin" [1] page is empty which would help us a lot...
>
> [1]
> http://www.commontk.org/index.php/Documentation/CTK_Plugin_Framework:_Creating_a_new_CTK_Plugin
>
> 2013/5/24 Jean-Christophe Fillion-Robin <jchris.fillionr at kitware.com>:
> > Hi Florian,
> >
> > Seem the following page could be helpful:
> >
> http://www.commontk.org/index.php/Documentation/Plugin_Framework#Documentation
> >
> > And more particularly:
> >
> http://www.commontk.org/index.php/Documentation/CTK_Plugin_Framework:_Embedding_the_CTK_Plugin_Framework
> >
> > Hth
> > Jc
> >
> >
> >
> >
> > On Fri, May 24, 2013 at 9:07 AM, Florian Ganglberger
> > <Florian.Ganglberger at student.i-med.ac.at> wrote:
> >>
> >> Hi all,
> >> I'm new to CTK. Me and my colleges want to develop a CTK application
> >> that involves IGSTK for tracking. Unfortunately we can not find any
> >> suitable example application / tutorial to learn how to use the plugin
> >> framework. Do you have any suggestions for us? Or maybe a nice person
> >> can send us a minimal example application ;-)
> >> _______________________________________________
> >> Ctk-developers mailing list
> >> Ctk-developers at commontk.org
> >> http://public.kitware.com/cgi-bin/mailman/listinfo/ctk-developers
> >
> >
> >
> >
> > --
> > +1 919 869 8849
> _______________________________________________
> Ctk-developers mailing list
> Ctk-developers at commontk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/ctk-developers
> _______________________________________________
> Ctk-developers mailing list
> Ctk-developers at commontk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/ctk-developers
>



-- 
Sergio Vera

 Alma IT Systems
 C/ Vilana, 4B, 4º 1ª
 08022 Barcelona
 T. (+34) 932 380 592
 www.alma3d.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/ctk-developers/attachments/20130527/d8e4bb5f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PluginExample.zip
Type: application/zip
Size: 9047 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/ctk-developers/attachments/20130527/d8e4bb5f/attachment-0002.zip>


More information about the Ctk-developers mailing list