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:

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
}
}
}
}
}
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
const std::string pickMode()
Get the current Picking mode.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Viewer::ActionMode actionMode()
Get the current Action mode.

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)