MouseInterface.hh 7.49 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
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42 43


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

Jan Möbius's avatar
Jan Möbius committed
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
 *
 */
Jan Möbius's avatar
 
Jan Möbius committed
63
class MouseInterface {
Jan Möbius's avatar
Jan Möbius committed
64

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

Jan Möbius's avatar
 
Jan Möbius committed
67
    /**  \brief Wheel Event from Main App
Jan Möbius's avatar
Jan Möbius committed
68
      *
Jan Möbius's avatar
 
Jan Möbius committed
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.
Jan Möbius's avatar
 
Jan Möbius committed
72 73 74 75
      *  This slot will only get called in pickingMode.
      *  @param _event Mousevent
      *  @param _mode Name of the current Picking Mode.
    */
Dirk Wilden's avatar
Dirk Wilden committed
76
    virtual void slotMouseWheelEvent(QWheelEvent * /*_event*/, const std::string & /*_mode*/) {};
Jan Möbius's avatar
Jan Möbius committed
77

Jan Möbius's avatar
 
Jan Möbius committed
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.
Jan Möbius's avatar
 
Jan Möbius committed
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.
      *
Jan Möbius's avatar
 
Jan Möbius committed
85 86
      *  @param _event Mousevent
    */
Dirk Wilden's avatar
Dirk Wilden committed
87
    virtual void slotMouseEvent( QMouseEvent* /*_event*/ ) {};
Jan Möbius's avatar
Jan Möbius committed
88

Jan Möbius's avatar
 
Jan Möbius committed
89
    /**  \brief Mouse Event from Main App ( Identify Mode )
Jan Möbius's avatar
Jan Möbius committed
90 91 92
      *
      *  This slot is called if a mouse event occured in the Viewer
      *  This slot will only get called in identifyMode.
Jan Möbius's avatar
 
Jan Möbius committed
93
      *  Right button clicks will not be passed to the plugins as this is reserved for
Jan Möbius's avatar
Jan Möbius committed
94 95
      *  the context Menu.
      *
Jan Möbius's avatar
 
Jan Möbius committed
96
      *  @param _event Mousevent
Jan Möbius's avatar
Jan Möbius committed
97
    */
Jan Möbius's avatar
Mike:  
Jan Möbius committed
98 99 100 101 102 103 104 105 106 107 108 109
    virtual void slotMouseEventIdentify( QMouseEvent* /*_event */) {};
    
    /**  \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
    */
    virtual void slotMouseEventLight( QMouseEvent* /* _event */) {};
Jan Möbius's avatar
Jan Möbius committed
110 111 112

  public :

Jan Möbius's avatar
 
Jan Möbius committed
113 114
    /// Destructor
    virtual ~MouseInterface() {};
Jan Möbius's avatar
Jan Möbius committed
115

Jan Möbius's avatar
 
Jan Möbius committed
116 117
};

Jan Möbius's avatar
Jan Möbius committed
118 119 120 121 122 123 124 125 126 127 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 172 173 174 175 176 177 178 179 180 181 182 183
/** \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()
<li> <b>Identify Mode</b> events where passed through the MouseInterface::slotMouseEventIdentify()
</ul>

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

The picking mode is only a global mode which is devided into several other picking modes that can be managed
through the PickingInterface. If you react on mouse events from picking mode, you should check if the current
picking mode is yours.
\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>


*/

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

Jan Möbius's avatar
 
Jan Möbius committed
186
#endif // MOUSEINTERFACE_HH