MouseInterface.hh 6.99 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33 34 35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
42 43


Jan Möbius's avatar
Jan Möbius committed
44 45
#ifndef MOUSEINTERFACE_HH
#define MOUSEINTERFACE_HH
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include <QtGui>


/** \file MouseInterface.hh
*
* Interface for registering types in OpenFlipper. \ref mouseInterfacePage
*/


 /** \brief Interface class for receiving mouse events
 *
 * \n
 * \ref mouseInterfacePage "Detailed description"
 * \n
 *
 */
63
class MouseInterface {
Jan Möbius's avatar
Jan Möbius committed
64

65
  private slots :
Jan Möbius's avatar
Jan Möbius committed
66

67
    /**  \brief Wheel Event from Main App
Jan Möbius's avatar
Jan Möbius committed
68
      *
69 70
      *  This slot is called if a wheel event occured in the Viewer and is extended by
      *  the current Mode set in the Viewer. You can add additional Picking Modes to
Jan Möbius's avatar
Jan Möbius committed
71
      *  the Viewer by using the picking interface.
72 73 74 75
      *  This slot will only get called in pickingMode.
      *  @param _event Mousevent
      *  @param _mode Name of the current Picking Mode.
    */
76
    virtual void slotMouseWheelEvent(QWheelEvent * _event, const std::string & _mode) {};
Jan Möbius's avatar
Jan Möbius committed
77

78
    /**  \brief Mouse Event from Main App ( Picking Mode )
Jan Möbius's avatar
Jan Möbius committed
79 80 81
      *
      *  This slot is called if a mouse event occured in the Viewer
      *  This slot will only get called in pickingMode.
82
      *  Right button clicks will not be passed to the plugins as this is reserved for
Jan Möbius's avatar
Jan Möbius committed
83 84
      *  the context Menu.
      *
85 86
      *  @param _event Mousevent
    */
87
    virtual void slotMouseEvent( QMouseEvent* _event ) {};
Jan Möbius's avatar
Jan Möbius committed
88 89 90 91 92 93 94 95 96 97
    
    /**  \brief Mouse Event from Main App ( Light Mode )
      *
      *  This slot is called if a mouse event occured in the Viewer
      *  This slot will only get called in LightMode.
      *  Right button clicks will not be passed to the plugins as this is reserved for
      *  the context Menu.
      *
      *  @param _event Mousevent
    */
98
    virtual void slotMouseEventLight( QMouseEvent*  _event ) {};
Jan Möbius's avatar
Jan Möbius committed
99 100 101

  public :

102 103
    /// Destructor
    virtual ~MouseInterface() {};
Jan Möbius's avatar
Jan Möbius committed
104

105 106
};

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
/** \page mouseInterfacePage Mouse Interface
\n
\image html mouseInterface.png
\n


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

There are 4 main viewer modes:
<ul>
<li> <b>Move Mode</b> events are never passed to one of the plugins and is only used for scene navigation
inside the viewers.
<li> <b>Picking Mode</b> events where passed through the MouseInterface::slotMouseEvent() and MouseInterface::slotMouseWheelEvent().
<li> <b>Light Mode</b> events where passed through the MouseInterface::slotMouseEventLight()
</ul>

You can add handlers for these mouse events in your plugin. Remember that all plugins receive these signals.\n

125 126 127
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.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
\code
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

        }
      }
    }
  }


}
\endcode

See our tutorial \ref ex3 for an example of how to use mouse and keyboard events
within a plugin.

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


*/

172
Q_DECLARE_INTERFACE(MouseInterface,"OpenFlipper.MouseInterface/1.0")
Jan Möbius's avatar
Jan Möbius committed
173

174
#endif // MOUSEINTERFACE_HH