[osg-users] mouse event handling

2014-10-24 Thread Gianni Ambrosio
Hi All,
I implemented a PointPicker derived from osgGA::GUIEventHandler and overloading:

virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& 
aa, osg::Object*, osg::NodeVisitor*);

in which I handle both osgGA::GUIEventAdapter::PUSH and 
osgGA::GUIEventAdapter::RELEASE cases and always return false.

In my Qt application I have a ViewerWidget that inherits from osgQt::GLWidget 
and osgViewer::CompositeViewer. All key events ara handled in ViewerWidget by 
overloading keyPressEvent(QKeyEvent*).
Now, I thought to activate the PointPicker by pressing 'C' key. So for 
"Qt::Key_C" key I call:

getView(0)->addEventHandler(pointPicker);

Since the point picker must be deactivated after the first pick, then I thought 
to handle the mouse release event on the ViewerWidget side also, overloading 
the method mouseReleaseEvent:

ViewerWidget::mouseReleaseEvent(QMouseEvent* event)

where I call:

superclass::mouseReleaseEvent(event);
getView(0)->removeEventHandler(pointPicker);

The problem is that when removeEventHandler is called the event has not been 
already processed by PointPiker::handle(...). So 
osgGA::GUIEventAdapter::RELEASE case never happens. I tryed to call 
eventTraversal() as follows:

superclass::mouseReleaseEvent(event);
eventTraversal();
getView(0)->removeEventHandler(pointPicker);

but unfortunately it does not solve the problem.

I found a workaround but I will appreciate if someone could explain how to 
solve this case.

Regards,
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61405#61405





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] mouse event handling

2014-10-24 Thread Robert Osfield
Hi Gianni,

Rather than adding/removing the event handler I would add a flag to the
event handle to say whether it's active or not and then enable/disable as
required.

Robert.

On 24 October 2014 08:57, Gianni Ambrosio  wrote:

> Hi All,
> I implemented a PointPicker derived from osgGA::GUIEventHandler and
> overloading:
>
> virtual bool handle(const osgGA::GUIEventAdapter&
> ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*);
>
> in which I handle both osgGA::GUIEventAdapter::PUSH and
> osgGA::GUIEventAdapter::RELEASE cases and always return false.
>
> In my Qt application I have a ViewerWidget that inherits from
> osgQt::GLWidget and osgViewer::CompositeViewer. All key events ara handled
> in ViewerWidget by overloading keyPressEvent(QKeyEvent*).
> Now, I thought to activate the PointPicker by pressing 'C' key. So for
> "Qt::Key_C" key I call:
>
> getView(0)->addEventHandler(pointPicker);
>
> Since the point picker must be deactivated after the first pick, then I
> thought to handle the mouse release event on the ViewerWidget side also,
> overloading the method mouseReleaseEvent:
>
> ViewerWidget::mouseReleaseEvent(QMouseEvent* event)
>
> where I call:
>
> superclass::mouseReleaseEvent(event);
> getView(0)->removeEventHandler(pointPicker);
>
> The problem is that when removeEventHandler is called the event has not
> been already processed by PointPiker::handle(...). So
> osgGA::GUIEventAdapter::RELEASE case never happens. I tryed to call
> eventTraversal() as follows:
>
> superclass::mouseReleaseEvent(event);
> eventTraversal();
> getView(0)->removeEventHandler(pointPicker);
>
> but unfortunately it does not solve the problem.
>
> I found a workaround but I will appreciate if someone could explain how to
> solve this case.
>
> Regards,
> Gianni
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=61405#61405
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] mouse event handling

2014-10-24 Thread Gianni Ambrosio
Hi Robert,
thanks for the fast reply. That's exactly the "workaroud" I found.
Just out of curiosity, is there any way to force the event handling on the OSG 
part in Qt event handling method?

Best regards,
Gianni


robertosfield wrote:
> Hi Gianni,
> Rather than adding/removing the event handler I would add a flag to the event 
> handle to say whether it's active or not and then enable/disable as required.
> 


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61407#61407





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] mouse event handling

2014-10-24 Thread Robert Osfield
On 24 October 2014 09:09, Gianni Ambrosio  wrote:

> Hi Robert,
> thanks for the fast reply. That's exactly the "workaroud" I found.
> Just out of curiosity, is there any way to force the event handling on the
> OSG part in Qt event handling method?
>

I not a Qt coder so can't comment on the Qt side.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] mouse event handling

2014-10-24 Thread Gianni Ambrosio

robertosfield wrote:
> 
> I not a Qt coder so can't comment on the Qt side.
> 

Honestrly I'm not sure this is just a matter of Qt code. I can get the mouse 
event on the Qt side and let OSG code handlling it later. I debugged that code 
and the mouse event seems correctly added to the osg event queue but calling 
eventTraversal() the event is not processed. I guess the event is processed in 
a frame() call, but removing the event handler too early (in 
mouseReleaseEvent()) it causes the behaviour I experienced. That's why I asked 
if there is a way to force event processing in pure OSG code.

Best regards,
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61411#61411





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] mouse event handling

2014-10-24 Thread Robert Osfield
Hi Gianni,

On 24 October 2014 10:48, Gianni Ambrosio  wrote:

> Honestrly I'm not sure this is just a matter of Qt code. I can get the
> mouse event on the Qt side and let OSG code handlling it later. I debugged
> that code and the mouse event seems correctly added to the osg event queue
> but calling eventTraversal() the event is not processed. I guess the event
> is processed in a frame() call, but removing the event handler too early
> (in mouseReleaseEvent()) it causes the behaviour I experienced. That's why
> I asked if there is a way to force event processing in pure OSG code.
>

There really is too little to go on for a 3rd party to know what might be
going on, what is correct and what might not be.  You have all the code in
front of you, I and others don't, there are really limits to our ability to
onimpotent.

As for forcing event processing in pure OSG code. Well you can create an
event and pass it directly to the event handling/callback.

Robert
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org