MouseInterface.hh 7.97 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 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 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * 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.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49 50


Jan Möbius's avatar
Jan Möbius committed
51 52
#ifndef MOUSEINTERFACE_HH
#define MOUSEINTERFACE_HH
Jan Möbius's avatar
 
Jan Möbius committed
53

Matthias Möller's avatar
Matthias Möller committed
54 55 56 57 58 59

#if QT_VERSION >= 0x050000 
  #include <QtWidgets>
#else
  #include <QtGui>
#endif
Jan Möbius's avatar
Jan Möbius committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74


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

Jan Möbius's avatar
 
Jan Möbius committed
77
  private slots :
Jan Möbius's avatar
Jan Möbius committed
78

79
    /**  \brief Wheel Event from main application
Jan Möbius's avatar
Jan Möbius committed
80
      *
81
      *  This slot is called if a wheel event occurred in the Viewer and is extended by
Jan Möbius's avatar
 
Jan Möbius committed
82
      *  the current Mode set in the Viewer. You can add additional Picking Modes to
Jan Möbius's avatar
Jan Möbius committed
83
      *  the Viewer by using the picking interface.
Jan Möbius's avatar
 
Jan Möbius committed
84
      *  This slot will only get called in pickingMode.
85
      *  @param _event Mouse event
Jan Möbius's avatar
 
Jan Möbius committed
86 87
      *  @param _mode Name of the current Picking Mode.
    */
88
    virtual void slotMouseWheelEvent(QWheelEvent * _event, const std::string & _mode) {};
Jan Möbius's avatar
Jan Möbius committed
89

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

  public :

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

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

Jan Möbius's avatar
Jan Möbius committed
119 120 121 122 123 124 125 126 127 128 129
/** \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
130 131 132 133
inside the viewers.</li>
<li> <b>Picking Mode</b> 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.</li>
<li> <b>Light Mode</b> events where passed through the MouseInterface::slotMouseEventLight(). Plugins modifying light sources use that mode to get mouse events. </li>
<li> <b>Info Mode</b> events are passed through the Information interface \ref informationInterfacePage. This mode is used to provide information about clicked objects only.</li>
Jan Möbius's avatar
Jan Möbius committed
134 135 136 137
</ul>

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

Jan Möbius's avatar
Jan Möbius committed
138 139 140
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.
Jan Möbius's avatar
Jan Möbius committed
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 184
\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
185
Q_DECLARE_INTERFACE(MouseInterface,"OpenFlipper.MouseInterface/1.0")
Jan Möbius's avatar
Jan Möbius committed
186

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