Developer Documentation

Mouse Interface

The mouse interface can be used to receive mouse events which occur in the glViewer.

There are 4 main viewer modes:

- Move Mode events are never passed to one of the plugins and is only used for scene navigation inside the viewers.
- Picking Mode events where passed through the MouseInterface::slotMouseEvent() and MouseInterface::slotMouseWheelEvent() to the plugins. This is usually the mode, that plugins use to implement mouse interaction.
- Light Mode events where passed through the MouseInterface::slotMouseEventLight(). Plugins modifying light sources use that mode to get mouse events.
- Info Mode events are passed through the Information interface Information Interface. This mode is used to provide information about clicked objects only.

You can add handlers for these mouse events in your plugin. Remember that all plugins receive these signals.
The picking action is only a global mode which is divided into several other picking modes that can be managed through the PickingInterface. If you react on mouse events, you should check if the current picking mode is yours and of course define such a mode for your plugin.

void MousePlugin::slotMouseEvent(QMouseEvent* _event) {
// Check if your pick mode is currently active
if ( PluginFunctions::pickMode() == "YourPickMode" && PluginFunctions::actionMode() == Viewer::PickingMode ) {
// If double click has been performed
if (_event->type() == QEvent::MouseButtonDblClick) {
unsigned int node_idx, target_idx;
OpenMesh::Vec3d hitPoint;
// Get picked object's identifier by picking in scenegraph
if ( PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING,_event->pos(), node_idx, target_idx, &hitPoint) ) {
BaseObjectData* object;
// Get picked object
if ( PluginFunctions::getPickedObject(node_idx, object) ) {
// Do something with the object
}
}
}
}
}

See our tutorial Implementing mouse and keyboard interaction for an example of how to use mouse and keyboard events within a plugin.

To use the MouseInterface:

- include MouseInterface.hh in your plugins header file
- derive your plugin from the class MouseInterface
- add Q_INTERFACES(MouseInterface) to your plugin class
- And add the signals or slots you want to use to your plugin class (You don't need to implement all of them)