PickingInterface.hh 10.2 KB
 Jan Möbius committed Aug 05, 2009 1 /*===========================================================================*\  Jan Möbius committed Nov 25, 2010 2 3 * * * OpenFlipper *  Jan Möbius committed Feb 05, 2014 4 * Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *  Jan Möbius committed Nov 25, 2010 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 . * * *  Jan Möbius committed Aug 05, 2009 33 34 35 \*===========================================================================*/ /*===========================================================================*\  Jan Möbius committed Nov 25, 2010 36 37 38 39 40 * * * $Revision$ * * $LastChangedBy$ * * $Date$ * * *  Jan Möbius committed Aug 05, 2009 41 \*===========================================================================*/  Jan Möbius committed Aug 29, 2008 42   Jan Möbius committed Jan 27, 2009 43 44 #ifndef PICKINGINTERFACE_HH #define PICKINGINTERFACE_HH  Jan Möbius committed Aug 29, 2008 45   Matthias Möller committed Aug 25, 2014 46 47  #include  Matthias Möller committed Jul 19, 2013 48 49 50 51 52 53 #if QT_VERSION >= 0x050000 #include #else #include #endif  Jan Möbius committed Aug 29, 2008 54  #include  Matthias Möller committed Aug 25, 2014 55   Jan Möbius committed Jan 27, 2009 56   Jan Möbius committed Mar 16, 2011 57 58 59 60 61 62 63 64  /** \file PickingInterface.hh * * Interface Class which allows access to picking functions. \ref pickingInterfacePage */ /** \brief Allow access to picking functions.  Mike Kremer committed Feb 04, 2009 65  *  Jan Möbius committed Mar 16, 2011 66 67 68 69 70  * \ref pickingInterfacePage "Detailed description" * \n * * Using this interface you can add different pick modes to OpenFlipper and * separate different mouse Interactions depending on the current mode.  Mike Kremer committed Mar 26, 2009 71 72  * * Read tutorial \ref ex3 for an example of how to use mouse picking.  Jan Möbius committed Aug 29, 2008 73 74 75  */ class PickingInterface { signals :  Jan Möbius committed Jan 27, 2009 76 77  /** \brief Add a new picking mode to the examiner *  Jan Möbius committed Aug 29, 2008 78 79  * @param _mode Identifier of Picking mode or "Separator" to add a Separator */  Jan Möbius committed Jan 12, 2012 80  virtual void addPickMode( const std::string& _mode) {};  Jan Möbius committed Jan 27, 2009 81   Jan Möbius committed Aug 29, 2008 82  /** \brief Add a new picking mode to the examiner which will be invisible  Jan Möbius committed Jan 27, 2009 83  *  Jan Möbius committed Aug 29, 2008 84  * The added PickMode will not appear in the context menus Picking menu.  Jan Möbius committed Mar 16, 2011 85  * You have to provide a button or menu entry yourself if you want to switch to  Jan Möbius committed Aug 29, 2008 86  * the picking mode provided here.  Jan Möbius committed Jan 27, 2009 87  *  Jan Möbius committed Aug 29, 2008 88 89  * @param _mode Identifier of Picking mode or "Separator" to add a Separator */  Jan Möbius committed Jan 12, 2012 90  virtual void addHiddenPickMode( const std::string& _mode ) {};  Jan Möbius committed Jan 27, 2009 91   Dirk Wilden committed Dec 09, 2008 92  /** \brief Set the cursor of the given PickMode  Jan Möbius committed Jan 27, 2009 93  *  Dirk Wilden committed Dec 09, 2008 94  * Set the cursor that should be used inside the pickMode  Jan Möbius committed Jan 27, 2009 95  *  Dirk Wilden committed Dec 09, 2008 96 97  * @param _mode Identifier of Picking mode * @param _cursor the new cursor  Jan Möbius committed Aug 29, 2008 98  */  Jan Möbius committed Jan 12, 2012 99  virtual void setPickModeCursor( const std::string& _mode , QCursor _cursor ) {};  Dirk Wilden committed Dec 09, 2008 100 101  /** \brief Set mouse tracking for the given PickMode  Jan Möbius committed Jan 27, 2009 102  *  Dirk Wilden committed Dec 09, 2008 103 104  * Enable mouseTracking for the given PickMode. When MouseTracking is enabled * you receive mouseMove events also when no button is pressed (via MouseInterface)  Jan Möbius committed Jan 27, 2009 105  *  Dirk Wilden committed Dec 09, 2008 106 107  * @param _mode Identifier of Picking mode * @param _mouseTracking new state of mouseTracking  Jan Möbius committed Aug 29, 2008 108  */  Jan Möbius committed Jan 12, 2012 109  virtual void setPickModeMouseTracking( const std::string& _mode , bool _mouseTracking ) {};  Dirk Wilden committed Dec 09, 2008 110   Jan Möbius committed Mar 16, 2011 111  /** \brief Set the additional toolbar of the given PickMode  Jan Möbius committed May 07, 2009 112 113 114 115 116 117  * * Set the additional toolbar that should be shown in the pickMode * * @param _mode Identifier of Picking mode * @param _toolbar the toolbar */  Jan Möbius committed Jan 12, 2012 118  virtual void setPickModeToolbar( const std::string& _mode , QToolBar * _toolbar ) {};  Jan Möbius committed May 07, 2009 119   Jan Möbius committed Mar 16, 2011 120  /** \brief Removes the additional toolbar of the given PickMode  Jan Möbius committed May 07, 2009 121 122 123 124 125  * * Set the additional toolbar that should be shown in the pickMode * * @param _mode Identifier of Picking mode */  Jan Möbius committed Jan 12, 2012 126  virtual void removePickModeToolbar( const std::string& _mode ) {};  Jan Möbius committed May 07, 2009 127   Jan Möbius committed Oct 12, 2009 128 129  private slots:  Jan Möbius committed Aug 29, 2008 130  /** \brief The pickingMode has changed  Jan Möbius committed Jan 27, 2009 131  *  Jan Möbius committed Aug 29, 2008 132 133 134  * This slot is called if the user changes the current picking mode * @param _mode Identifier of Picking mode */  Jan Möbius committed Mar 16, 2011 135  virtual void slotPickModeChanged( const std::string& _mode) {};  Jan Möbius committed Jan 27, 2009 136 137 138  public :  Jan Möbius committed Aug 29, 2008 139 140  /// Destructor virtual ~PickingInterface() {};  Jan Möbius committed Jan 27, 2009 141   Jan Möbius committed Aug 29, 2008 142 143 };  Jan Möbius committed Mar 16, 2011 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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 /** \page pickingInterfacePage Picking Interface/Mouse Picking/Pick Mode Toolbars \n \image html PickingInterface.png \n \section pickingInterface_functionality Functionality OpenFlipper uses several different ActionModes. These include, Light interaction (Changing lights), Move interaction (navigating through the scene) and the picking interaction. The picking interaction is separated into different pick modes. These modes are usually defined by plugins and are used to restrict the mouse interaction to one plugin. E.g. if the current picking mode is "vertex selection", all other plugins that react on mouse events, but are not responsible for the "vertex selection" will ignore these events. \section pickingInterface_managing Managing Pick Modes Pick modes can be created in your plugin initialization. You can add them as visible pick modes (visible in the context menus of objects) or as hidden pick modes PickingInterface::addHiddenPickMode() ( This should be preferred! ). You can also set a special cursor that will be used when your pick mode is active via PickingInterface::setPickModeCursor(). If you need to enable mouse tracking in your mode, you can use PickingInterface::setPickModeMouseTracking(). This will result in mouse events even if no button is pressed. \code // When the plugin gets initialized void ExamplePlugin::pluginsInitialized() { // Add pick mode emit addPickMode("ExamplePlugin Pick Mode"); } // Triggered when the pick mode got changed. void ExamplePlugin::slotPickModeChanged(const std::string& _mode) { // Enable a button depending on the current pick mode button_->setEnabled(_mode == "ExamplePlugin Pick Mode"); } // From MouseInterface void ExamplePlugin::slotMouseEvent(QMouseEvent* _event) { // Check if your pick mode is currently active if ( PluginFunctions::pickMode() == "ExamplePlugin Pick Mode" && PluginFunctions::actionMode() == Viewer::PickingMode ) { // Do something } } \endcode A change of the current pick mode can be detected by the PickingInterface::slotPickModeChanged() function. \section pickingInterface_toolbars PickMode Toolbars \n \image html PickModeToolbar.png \n Additionally it is possible to show a special toolbar in OpenFlippers viewer when your pick mode is active. This is especially Useful, when you can change the interaction type by buttons in the bar, e.g. select vertices or faces. Every time your pick mode is activated, your toolbar will be visible at the top of the viewer. Use the functions PickingInterface::setPickModeToolbar() and PickingInterface::removePickModeToolbar() for controlling these toolbars. The embedding is fully transparent so that you can manage your toolbar and connect signals and slots as usual. \code // When the plugin gets initialized void ExamplePlugin::pluginsInitialized() { // Global variable QToolBar* pickToolbar_ pickToolbar_ = new QToolBar(tr("Example Pickmode Toolbar")); pickToolbar_->setAttribute(Qt::WA_AlwaysShowToolTips, true); QActionGroup* pickToolBarActions = new QActionGroup(pickToolbar_); QAction* action = new QAction(tr("Action"),pickToolBarActions); action->setStatusTip(tr("Action description")); action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"icon.png") ); action->setCheckable(true); pickToolbar_->addAction(action); // Connect to a local slot. The embedding is transparent, so you can connect all your actions and toolbars as usual. connect(pickToolBarActions, SIGNAL(triggered(QAction*)), this, SLOT(slotPickToolbarAction(QAction*)) ); emit setPickModeToolbar ("ExamplePlugin Pick Mode", pickToolbar_); } \endcode \section pickingInterface_usage Usage To use the PickingInterface:
*/  Dirk Wilden committed Dec 09, 2008 246 Q_DECLARE_INTERFACE(PickingInterface,"OpenFlipper.PickingInterface/1.1")  Jan Möbius committed Jan 27, 2009 247   Jan Möbius committed Aug 29, 2008 248 #endif // PICKINGINTERFACE_HH