05.11., 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Revised event handling system: Got rid of campvis::AbstractEventHandler and...

Revised event handling system: Got rid of campvis::AbstractEventHandler and replaced with functionality of tgt::EventListener and tgt::EventHandler
parent 9da15771
......@@ -170,7 +170,7 @@ namespace campvis {
if (_pipeline != 0) {
_pipeline->s_renderTargetChanged.disconnect(this);
if (getCanvas()->getEventHandler() != 0)
getCanvas()->getEventHandler()->removeListener(_pipeline);
getCanvas()->getEventHandler()->removeEventListener(_pipeline);
_pipeline = 0;
}
}
......@@ -180,14 +180,14 @@ namespace campvis {
if (_pipeline != 0) {
_pipeline->s_renderTargetChanged.disconnect(this);
if (getCanvas()->getEventHandler() != 0)
getCanvas()->getEventHandler()->removeListener(_pipeline);
getCanvas()->getEventHandler()->removeEventListener(_pipeline);
}
_pipeline = pipeline;
_pipeline->s_renderTargetChanged.connect(this, &TumVisPainter::onRenderTargetChanged);
_pipeline->setRenderTargetSize(getCanvas()->getSize());
if (getCanvas()->getEventHandler() != 0)
getCanvas()->getEventHandler()->addListenerToFront(_pipeline);
getCanvas()->getEventHandler()->addEventListenerToFront(_pipeline);
}
void TumVisPainter::onRenderTargetChanged() {
......
......@@ -90,7 +90,7 @@ namespace campvis {
// set this as painter to get notified when window size changes
setPainter(this, false);
getEventHandler()->addListenerToFront(this);
getEventHandler()->addEventListenerToFront(this);
}
void DataContainerInspectorCanvas::deinit() {
......
......@@ -72,7 +72,7 @@ namespace campvis {
Geometry1DTransferFunctionEditor::~Geometry1DTransferFunctionEditor() {
tbb::mutex::scoped_lock lock(_localMutex);
// clear and delete former stuff
// clearEventListeners and delete former stuff
_selectedGeometry = 0;
for (std::vector<AbstractTFGeometryManipulator*>::iterator it = _manipulators.begin(); it != _manipulators.end(); ++it) {
if (WholeTFGeometryManipulator* tester = dynamic_cast<WholeTFGeometryManipulator*>(*it)) {
......@@ -274,9 +274,9 @@ namespace campvis {
void Geometry1DTransferFunctionEditor::updateManipulators() {
tbb::mutex::scoped_lock lock(_localMutex);
// clear and delete former stuff
// clearEventListeners and delete former stuff
_selectedGeometry = 0;
_canvas->getEventHandler()->clear();
_canvas->getEventHandler()->clearEventListeners();
for (std::vector<AbstractTFGeometryManipulator*>::iterator it = _manipulators.begin(); it != _manipulators.end(); ++it) {
if (WholeTFGeometryManipulator* tester = dynamic_cast<WholeTFGeometryManipulator*>(*it)) {
tester->s_selected.disconnect(this);
......@@ -291,17 +291,17 @@ namespace campvis {
// Add manipulator for the whole geometry and register it as event handler:
WholeTFGeometryManipulator* wtf = new WholeTFGeometryManipulator(_canvas->getSize(), *git);
_manipulators.push_back(wtf);
_canvas->getEventHandler()->addListenerToFront(wtf);
_canvas->getEventHandler()->addEventListenerToFront(wtf);
wtf->s_selected.connect(this, &Geometry1DTransferFunctionEditor::onWholeTFGeometryManipulatorSelected);
// Add a manipulator for each KeyPoint and register it as event handler:
for (std::vector<TFGeometry1D::KeyPoint>::iterator kpit = (*git)->getKeyPoints().begin(); kpit != (*git)->getKeyPoints().end(); ++kpit) {
_manipulators.push_back(new KeyPointManipulator(_canvas->getSize(), *git, kpit));
_canvas->getEventHandler()->addListenerToFront(_manipulators.back());
_canvas->getEventHandler()->addEventListenerToFront(_manipulators.back());
}
}
_canvas->getEventHandler()->addListenerToFront(this);
_canvas->getEventHandler()->addEventListenerToFront(this);
}
void Geometry1DTransferFunctionEditor::onGeometryCollectionChanged() {
......
......@@ -257,7 +257,7 @@ namespace campvis {
void Geometry2DTransferFunctionEditor::updateManipulators() {
tbb::mutex::scoped_lock lock(_localMutex);
_canvas->getEventHandler()->addListenerToFront(this);
_canvas->getEventHandler()->addEventListenerToFront(this);
}
void Geometry2DTransferFunctionEditor::onGeometryCollectionChanged() {
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef ABSTRACTEVENTHANDLER_H__
#define ABSTRACTEVENTHANDLER_H__
#include "tgt/logmanager.h"
#include "tgt/event/event.h"
namespace campvis {
/**
* Abstract base class for CAMPVis EventHandlers.
*
*/
class AbstractEventHandler {
public:
/**
* Creates a AbstractEventHandler.
*/
AbstractEventHandler();
/**
* Virtual Destructor
**/
virtual ~AbstractEventHandler();
/**
* Checks, whether the given event \a e is handled by this EventHandler.
* \param e The event to check
* \return True, if the given event is handled by this EventHandler.
*/
virtual bool accept(tgt::Event* e) = 0;
/**
* Performs the event handling.
* \param e The event to handle
*/
virtual void execute(tgt::Event* e) = 0;
protected:
static const std::string loggerCat_;
};
}
#endif // ABSTRACTEVENTHANDLER_H__
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#include "mwheeltonumericpropertyeventhandler.h"
#include "tgt/assert.h"
#include "tgt/event/mouseevent.h"
#include "core/properties/numericproperty.h"
namespace campvis {
const std::string MWheelToNumericPropertyEventHandler::loggerCat_ = "CAMPVis.core.eventhandler.MWheelToNumericPropertyEventHandler";
MWheelToNumericPropertyEventHandler::MWheelToNumericPropertyEventHandler(INumericProperty* property)
: AbstractEventHandler()
, _prop(property)
{
tgtAssert(_prop != 0, "Assigned property must not be 0.");
}
MWheelToNumericPropertyEventHandler::~MWheelToNumericPropertyEventHandler() {
}
bool MWheelToNumericPropertyEventHandler::accept(tgt::Event* e) {
if (tgt::MouseEvent* me = dynamic_cast<tgt::MouseEvent*>(e)) {
return me->action() == tgt::MouseEvent::WHEEL;
}
return false;
}
void MWheelToNumericPropertyEventHandler::execute(tgt::Event* e) {
if (tgt::MouseEvent* me = dynamic_cast<tgt::MouseEvent*>(e)) {
if (me->action() == tgt::MouseEvent::WHEEL) {
switch (me->button()) {
case tgt::MouseEvent::MOUSE_WHEEL_UP:
_prop->increment();
e->ignore();
break;
case tgt::MouseEvent::MOUSE_WHEEL_DOWN:
_prop->decrement();
e->ignore();
break;
}
}
}
}
}
......@@ -27,16 +27,38 @@
//
// ================================================================================================
#include "abstracteventhandler.h"
#include "mwheeltonumericpropertyeventlistener.h"
namespace campvis {
const std::string AbstractEventHandler::loggerCat_ = "CAMPVis.core.eventhandler.AbstractEventhandler";
#include "tgt/assert.h"
#include "tgt/event/mouseevent.h"
#include "core/properties/numericproperty.h"
AbstractEventHandler::AbstractEventHandler() {
namespace campvis {
const std::string MWheelToNumericPropertyEventListener::loggerCat_ = "CAMPVis.core.eventhandler.MWheelToNumericPropertyEventListener";
MWheelToNumericPropertyEventListener::MWheelToNumericPropertyEventListener(INumericProperty* property)
: tgt::EventListener()
, _prop(property)
{
tgtAssert(_prop != 0, "Assigned property must not be 0.");
setEventTypes(tgt::Event::WHEELEVENT);
}
AbstractEventHandler::~AbstractEventHandler() {
MWheelToNumericPropertyEventListener::~MWheelToNumericPropertyEventListener() {
}
void MWheelToNumericPropertyEventListener::wheelEvent(tgt::MouseEvent* e) {
switch (e->button()) {
case tgt::MouseEvent::MOUSE_WHEEL_UP:
_prop->increment();
e->ignore();
break;
case tgt::MouseEvent::MOUSE_WHEEL_DOWN:
_prop->decrement();
e->ignore();
break;
}
}
}
......@@ -31,43 +31,31 @@
#define MWHEELTONUMERICPROPERTYEVENTHANDLER_H__
#include "tgt/logmanager.h"
#include "core/eventhandlers/abstracteventhandler.h"
#include "tgt/event/eventlistener.h"
namespace campvis {
class INumericProperty;
/**
* Event handler that maps mouse wheel events to a numeric property.
*
*/
class MWheelToNumericPropertyEventHandler : public AbstractEventHandler {
class MWheelToNumericPropertyEventListener : public tgt::EventListener {
public:
/**
* Creates a MWheelToNumericPropertyEventHandler.
* Creates a MWheelToNumericPropertyEventListener.
*/
MWheelToNumericPropertyEventHandler(INumericProperty* property);
MWheelToNumericPropertyEventListener(INumericProperty* property);
/**
* Virtual Destructor
**/
virtual ~MWheelToNumericPropertyEventHandler();
virtual ~MWheelToNumericPropertyEventListener();
/**
* Checks, whether the given event \a e is handled by this EventHandler.
* \param e The event to check
* \return True, if the given event is handled by this EventHandler.
*/
virtual bool accept(tgt::Event* e);
/**
* Performs the event handling.
* \param e The event to handle
*/
virtual void execute(tgt::Event* e);
/// \see tgt::EventListener::wheelEvent()
virtual void wheelEvent(tgt::MouseEvent* e);
protected:
INumericProperty* _prop;
INumericProperty* _prop; ///< The Property to map the event to
static const std::string loggerCat_;
};
......
......@@ -27,7 +27,7 @@
//
// ================================================================================================
#include "trackballnavigationeventhandler.h"
#include "trackballnavigationeventlistener.h"
#include "tgt/assert.h"
#include "tgt/event/mouseevent.h"
#include "core/properties/cameraproperty.h"
......@@ -60,12 +60,12 @@ namespace campvis {
_dirty = false;
}
// = TrackballNavigationEventHandler ==============================================================
// = TrackballNavigationEventListener ==============================================================
const std::string TrackballNavigationEventHandler::loggerCat_ = "CAMPVis.core.eventhandler.TrackballNavigationEventHandler";
const std::string TrackballNavigationEventListener::loggerCat_ = "CAMPVis.core.eventhandler.TrackballNavigationEventListener";
TrackballNavigationEventHandler::TrackballNavigationEventHandler(VisualizationPipeline* parentPipeline, CameraProperty* cameraProperty, const tgt::ivec2& viewportSize)
: AbstractEventHandler()
TrackballNavigationEventListener::TrackballNavigationEventListener(VisualizationPipeline* parentPipeline, CameraProperty* cameraProperty, const tgt::ivec2& viewportSize)
: tgt::EventListener()
, _parentPipeline(parentPipeline)
, _cameraProperty(cameraProperty)
, _cpnw(cameraProperty)
......@@ -75,29 +75,11 @@ namespace campvis {
_trackball = new tgt::Trackball(&_cpnw, viewportSize);
}
TrackballNavigationEventHandler::~TrackballNavigationEventHandler() {
TrackballNavigationEventListener::~TrackballNavigationEventListener() {
delete _trackball;
}
bool TrackballNavigationEventHandler::accept(tgt::Event* e) {
if (typeid(*e) == typeid(tgt::MouseEvent)) {
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
if (me->action() == tgt::MouseEvent::PRESSED)
return true;
else if (me->action() == tgt::MouseEvent::RELEASED)
return true;
else if (me->action() == tgt::MouseEvent::MOTION)
return true;
else if (me->action() == tgt::MouseEvent::WHEEL)
return true;
}
else if (typeid(*e) == typeid(tgt::KeyEvent)) {
return true;
}
return false;
}
void TrackballNavigationEventHandler::execute(tgt::Event* e) {
void TrackballNavigationEventListener::onEvent(tgt::Event* e) {
if (typeid(*e) == typeid(tgt::MouseEvent)) {
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
if (me->action() == tgt::MouseEvent::PRESSED) {
......@@ -120,23 +102,23 @@ namespace campvis {
}
}
void TrackballNavigationEventHandler::reinitializeCamera(const tgt::vec3& position, const tgt::vec3& focus, const tgt::vec3& upVector) {
void TrackballNavigationEventListener::reinitializeCamera(const tgt::vec3& position, const tgt::vec3& focus, const tgt::vec3& upVector) {
_trackball->reinitializeCamera(position, focus, upVector);
}
void TrackballNavigationEventHandler::setCenter(const tgt::vec3& center) {
void TrackballNavigationEventListener::setCenter(const tgt::vec3& center) {
_trackball->setCenter(center);
}
void TrackballNavigationEventHandler::setViewportSize(const tgt::ivec2& viewportSize) {
void TrackballNavigationEventListener::setViewportSize(const tgt::ivec2& viewportSize) {
_trackball->setViewprtSize(viewportSize);
}
void TrackballNavigationEventHandler::setSceneBounds(const tgt::Bounds& bounds) {
void TrackballNavigationEventListener::setSceneBounds(const tgt::Bounds& bounds) {
_trackball->setSceneBounds(bounds);
}
const tgt::Bounds& TrackballNavigationEventHandler::getSceneBounds() const {
const tgt::Bounds& TrackballNavigationEventListener::getSceneBounds() const {
return _trackball->getSceneBounds();
}
......
......@@ -32,8 +32,8 @@
#include "tgt/bounds.h"
#include "tgt/logmanager.h"
#include "tgt/event/eventlistener.h"
#include "tgt/navigation/trackball.h"
#include "core/eventhandlers/abstracteventhandler.h"
namespace campvis {
class CameraProperty;
......@@ -64,34 +64,24 @@ namespace campvis {
* EventHandler implementing a trackball navigation for a CameraProperty.
* Implementation inspired by http://www.opengl.org/wiki/Trackball
*/
class TrackballNavigationEventHandler : public AbstractEventHandler {
class TrackballNavigationEventListener : public tgt::EventListener {
public:
/**
* Creates a TrackballNavigationEventHandler.
* Creates a TrackballNavigationEventListener.
* \param parentPipeline Parent pipeline of this event handler, must not be 0.
* \param cameraProperty The CameraProperty to apply the navigation to.
* \param viewportSize Initial viewport size
*/
TrackballNavigationEventHandler(VisualizationPipeline* parentPipeline, CameraProperty* cameraProperty, const tgt::ivec2& viewportSize);
TrackballNavigationEventListener(VisualizationPipeline* parentPipeline, CameraProperty* cameraProperty, const tgt::ivec2& viewportSize);
/**
* Virtual Destructor
**/
virtual ~TrackballNavigationEventHandler();
virtual ~TrackballNavigationEventListener();
/**
* Checks, whether the given event \a e is handled by this EventHandler.
* \param e The event to check
* \return True, if the given event is handled by this EventHandler.
*/
virtual bool accept(tgt::Event* e);
/**
* Performs the event handling.
* \param e The event to handle
*/
virtual void execute(tgt::Event* e);
/// \see tgt::EventListener::onEvent()
virtual void onEvent(tgt::Event* e);
/**
* Sets the viewport size to \a viewportSize.
......
......@@ -27,7 +27,7 @@
//
// ================================================================================================
#include "transfuncwindowingeventhandler.h"
#include "transfuncwindowingeventlistener.h"
#include "tgt/assert.h"
#include "tgt/event/mouseevent.h"
......@@ -35,34 +35,22 @@
#include "core/properties/transferfunctionproperty.h"
namespace campvis {
const std::string TransFuncWindowingEventHandler::loggerCat_ = "CAMPVis.core.eventhandler.TransFuncWindowingEventHandler";
const std::string TransFuncWindowingEventListener::loggerCat_ = "CAMPVis.core.eventhandler.TransFuncWindowingEventListener";
TransFuncWindowingEventHandler::TransFuncWindowingEventHandler(TransferFunctionProperty* property)
: AbstractEventHandler()
TransFuncWindowingEventListener::TransFuncWindowingEventListener(TransferFunctionProperty* property)
: tgt::EventListener()
, _prop(property)
{
tgtAssert(_prop != 0, "Assigned property must not be 0.");
}
TransFuncWindowingEventHandler::~TransFuncWindowingEventHandler() {
TransFuncWindowingEventListener::~TransFuncWindowingEventListener() {
}
bool TransFuncWindowingEventHandler::accept(tgt::Event* e) {
if (typeid(*e) == typeid(tgt::MouseEvent)) {
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
if (me->action() == tgt::MouseEvent::PRESSED)
return true;
else if (_mousePressed && me->action() == tgt::MouseEvent::RELEASED)
return true;
else if (_mousePressed && me->action() == tgt::MouseEvent::MOTION)
return true;
}
return false;
}
void TransFuncWindowingEventHandler::execute(tgt::Event* e) {
tgtAssert(dynamic_cast<tgt::MouseEvent*>(e) != 0, "Given event has wrong type. Check if the event is accepted by this event handler before executing it!");
void TransFuncWindowingEventListener::onEvent(tgt::Event* e) {
if (typeid(*e) != typeid(tgt::MouseEvent))
return;
// this is only to be executed when the event was accepted, so the static cast is safe.
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
......
......@@ -32,7 +32,7 @@
#include "tgt/logmanager.h"
#include "tgt/vector.h"
#include "core/eventhandlers/abstracteventhandler.h"
#include "tgt/event/eventlistener.h"
namespace campvis {
class TransferFunctionProperty;
......@@ -41,31 +41,20 @@ namespace campvis {
* Event handler that maps mouse click-and-drag events to the windowing of a transfer function.
*
*/
class TransFuncWindowingEventHandler : public AbstractEventHandler {
class TransFuncWindowingEventListener : public tgt::EventListener {
public:
/**
* Creates a TransFuncWindowingEventHandler.
* Creates a TransFuncWindowingEventListener.
*/
TransFuncWindowingEventHandler(TransferFunctionProperty* property);
TransFuncWindowingEventListener(TransferFunctionProperty* property);
/**
* Virtual Destructor
**/
virtual ~TransFuncWindowingEventHandler();
virtual ~TransFuncWindowingEventListener();
/**
* Checks, whether the given event \a e is handled by this EventHandler.
* \param e The event to check
* \return True, if the given event is handled by this EventHandler.
*/
virtual bool accept(tgt::Event* e);
/**
* Performs the event handling.
* \param e The event to handle
*/
virtual void execute(tgt::Event* e);
/// \see tgt::EventListener::onEvent()
virtual void onEvent(tgt::Event* e);
protected:
TransferFunctionProperty* _prop;
......
......@@ -33,7 +33,6 @@
#include "sigslot/sigslot.h"
#include "tgt/vector.h"
#include "tgt/event/eventlistener.h"
#include "core/eventhandlers/abstracteventhandler.h"
#include "core/pipeline/visualizationpipeline.h"
#include "core/properties/genericproperty.h"
......
......@@ -61,6 +61,7 @@ namespace campvis {
VisualizationPipeline::VisualizationPipeline()
: AbstractPipeline()
, tgt::EventHandler()
, tgt::EventListener()
, _lqMode(false)
, _ignoreCanvasSizeUpdate(false)
......@@ -79,16 +80,15 @@ namespace campvis {
}
void VisualizationPipeline::onEvent(tgt::Event* e) {
// cycle through event handlers, ask each one if it handles the event and if so, execute it.
for (std::vector<AbstractEventHandler*>::iterator it = _eventHandlers.begin(); it != _eventHandlers.end() && e->isAccepted(); ++it) {
if ((*it)->accept(e)) {
(*it)->execute(e);
// copy and paste from tgt::EventHandler::onEvent() but without deleting e
for (size_t i = 0 ; i < listeners_.size() ; ++i) {
// check if current listener listens to the eventType of e
if(listeners_[i]->getEventTypes() & e->getEventType() ){
listeners_[i]->onEvent(e);
if (e->isAccepted())
break;
}
}
if (e->isAccepted()) {
EventListener::onEvent(e);
}
}