Hi Roman,
If you don't want your classes to derive from itk::Object (which is necessary
if you want to use the ITK command framework) you can also use mitkMessage.h .
This header file declares templated message objects on which listeners can be
registered and notified. This approach does not require you to derive your
classes from a special class and is more declarative. Your clients can discover
the supported events/messages more easily since they commonly are "published"
as public member variables. Here is a code snippet (I did not compile this
one..):
#include <mitkMessage.h>
class MyClass
{
public:
// declare a message object with 2 parameters
mitk::Message2<SomeType, const std::string&> m_MessageWith2Parameters;
void FireMessage() {
SomeType someType;
std::string str = "some message";
// use operator() of the mitk::Message2 class to notify listeners
// this is a shorthand for m_MessageWith2Parameters->Send(someType, str)
m_MessageWith2Parameters(someType, str);
}
};
// some class which is interested in a message
// from MyClass
class MyListener
{
private:
MyClass* m_MyClass;
public:
MyListener(MyClass* myClass)
: m_MyClass(myClass) {
// register a listener to the message/event
// ALWAYS remove the listener before your
// object is destroyed
myClass->m_MessageWith2Parameters.AddListener(this,
&MyListener::ListenToMessage);
}
~MyListener() {
// remove the listener
M_MyClass->m_MessageWith2Parameters.RemoveListener(this,
&MyListener::ListenToMessage);
}
// the function which gets called
void ListenToMessage(SomeType someType, const std::string& str) {
// do something
}
};
If you just want "signals", i.e. messages without parameters, use mitk::Message
(not templated). Otherwise, use mitk::Message1<A> or
Mitk::Message2<A,B>.
Regards,
Sascha
-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Wegner Ingmar
Gesendet: Sonntag, 24. August 2008 16:42
An: Roman Tulchiner; [email protected]
Betreff: Re: [mitk-users] emitting events from interactor
Hi Roman,
short answer: rather use the ITK Command.
see e.g. www.na-mic.org/Wiki/images/3/3d/Insight-Architecture.ppt
<http://www.na-mic.org/Wiki/images/3/3d/Insight-Architecture.ppt> last few
slides
http://www.itk.org/pipermail/insight-users/2007-October/023836.html
long answer:
MITK has a non-gui dependent mitk-core and then depenting on this core a layer
on top of it which is GUI-related (mostly QT (Qmitk)). Within the mitk, no GUI
related classes should be included or used.
If you are creating a class derived from QObject, you woul call it
QmitkNameOfNewClass and put it somewhere in the Qmitk folder such as the
Functionalities-folder.
Now for the signal-slot feature, which you are looking for, I would suggest the
itk::Command feature. It is GUI independent and thus can be used within mitk.
Within your functionality you can connect your interactor to your gui class and
send an event whenever it is needed. An example is implemented in mitkPointSet
line 522
(http://www.mitk.org/documentation/doxygen/classmitk_1_1PointSet.html).
Snipet with some docu:
//create the event
mitk::OperationEndEvent
<http://www.mitk.org/documentation/doxygen/classmitk_1_1OperationEndEvent.html>
endevent(operation);
//send it to connected objects
((const itk::Object*)this)->InvokeEvent(endevent);
Your Gui-object then can listen for the event.
Best Regards,
Ingmar
________________________________
Von: [EMAIL PROTECTED] im Auftrag von Roman Tulchiner
Gesendet: So 08/24/08 13:49
An: [email protected]
Betreff: Re: [mitk-users] emitting events from interactor
Hi,
I can suggest the following solution for using Qt's "signal-slot" with
an mitk interactor. It's maybe not the coolest solution, but it is the
one that works.
First of all, the interactor should be placed locally in the directory
where your functionality is. Otherwise "#include <qobject.h>" will fail
(why? Maybe you know?).
Than the interactor shouldn't have "MITK_CORE_EXPORT" makro, cause it's
not a part of CORE any more.
The interactor has to be derived from QObject and have "Q_OBJECT" in its
declaration - just a usual procedure for using "signal-slot".
Now you have to make sure, the corresponding meta object compiler file
(moc) will be also created. To do so, just insert the line
"your_ineractor_name".h into the "files.cmake" file of your
functionality in the "SET( MOC_H_FILES" section.
Now you can declare signals and slots and connect them e.g. with signals
and slots of your functionality.
If someone knows the solution, that fits better to the mitk environment,
I would be glad to learn it.
My regards,
Roman
Roman Tulchiner wrote:
> Hallo everybody,
>
> is there a possibility to emit events (or signals or similar) from out
> of mitk interactor?
>
> The following is a little sketch of what I'm trying to do:
>
> I have an interactor, which reads some parameters of a surface point
> near the mouse click location. Reading is not a problem - so I have the
> information I need within my interactor. Now I wish this information be
> shown in the UI of my mitk functionality.
>
> I could certainly do it per "call-back". Like giving my interactor a
> pointer to my functionality. So the interactor can directly notify the
> functionality of new information.
> But I would rather appreciate an "event-driven" approach with interactor
> emitting an event if data is changed.
>
> I have tried it with Qt's "signal-slot". As I understand, if I want the
> interactor to emit signals, I should derive it from QObject. But
> "#include <qobject.h>" in my interactor breaks with a following compiler
> error message:
> 6>f:\mitk\src\core\interactions\PointNeighborhoodSelectInteractor.h(12)
> : fatal error C1083: Cannot open include file: 'qobject.h': No such file
> or directory
>
> So finally my question is :-) :
> Isn't it possible to use Qt "signal-slots" from within mitk interactor?
> Are there maybe some other "event-driven" approach provided, referenced
> to my problem above?
>
>
> Kind regards,
> Roman
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> mitk-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mitk-users
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users