Developer Documentation
SelectionBasePlugin.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 #ifndef SELECTIONBASEPLUGIN_HH
51 #define SELECTIONBASEPLUGIN_HH
52 
53 #include <QObject>
54 #include <QGroupBox>
55 #include <QMenuBar>
56 
57 #include <set>
58 
67 #include <OpenFlipper/BasePlugin/INIInterface.hh>
71 
72 #include <ACG/Scenegraph/GlutPrimitiveNode.hh>
73 #include <ACG/Scenegraph/LineNode.hh>
74 
77 
78 #include "widgets/SelectionBaseToolbox.hh"
79 #include "widgets/SelectionTypeFrame.hh"
80 
81 #include <OpenFlipper/INIFile/INIFile.hh>
82 
83 #include "HelperClasses.hh"
84 
87 Q_OBJECT
88 Q_INTERFACES(BaseInterface)
89 Q_INTERFACES(MouseInterface)
90 Q_INTERFACES(KeyInterface)
91 Q_INTERFACES(PickingInterface)
92 Q_INTERFACES(ToolboxInterface)
93 Q_INTERFACES(INIInterface)
94 Q_INTERFACES(LoggingInterface)
95 Q_INTERFACES(ScriptInterface)
96 Q_INTERFACES(ContextMenuInterface)
97 Q_INTERFACES(ToolbarInterface)
98 Q_INTERFACES(LoadSaveInterface)
99 Q_INTERFACES(SelectionInterface)
100 
101  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SelectionBase")
102 
103  public:
104 
107 
108  // BaseInterface
109  QString name() { return (QString(tr("SelectionBase"))); };
110  QString description( ) { return (QString(tr("Provides basic selection functions"))); };
111 
112  signals:
113 
114  // BaseInterface
115  void updateView();
116 
117  // LoggingInterface
118  void log(Logtype _type, QString _message);
119  void log(QString _message);
120 
121  // ToolbarInterface
122  void addToolbar(QToolBar* _toolbar);
123 
124  // SelectionInterface
125  void toggleSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
126  void lassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
127  void volumeLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
128  void surfaceLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
129  void sphereSelection(QMouseEvent* _event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect);
130  void closestBoundarySelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
131  void floodFillSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
132  void componentsSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
133  void customSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, QString _customIdentifier, bool _deselect);
134 
135  void selectionOperation(QString _operation);
136  void loadSelection(const INIFile& _file);
137  void saveSelection(INIFile& _file);
138 
139  void keyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier);
140 
141  // PickingInterface
142  void addPickMode(const std::string& _mode);
143  void setPickModeMouseTracking(const std::string& _mode, bool _mouseTracking);
144  void setPickModeCursor(const std::string& _mode, QCursor _cursor);
145  void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
146 
147  // KeyInterface
148  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
149 
150  // ToolboxInterface
151  void addToolbox(QString _name, QWidget* _widget, QIcon* _icon);
152 
153  private slots:
154 
155  // BaseInterface
156  void initializePlugin();
157  void pluginsInitialized();
158 
159  //MouseInterface
160  void slotMouseWheelEvent(QWheelEvent* _event, const std::string& _mode);
161  void slotMouseEvent(QMouseEvent* _event);
162 
163  // SelectionInterface
164  void slotAddSelectionEnvironment(QString _modeName, QString _description, QString _icon, QString& _handleName);
165  void slotRegisterType(QString _handleName, DataType _type);
166  void slotAddPrimitiveType(QString _handleName, QString _name, QString _icon, SelectionInterface::PrimitiveType& _typeHandle);
167  void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QString _icon,
168  SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
169  void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QString _icon,
170  SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier,
171  DataType _objectTypeRestriction);
172 
173  void slotAddSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u);
174  void slotAddSelectionParameters(QString _handleName, QWidget* _widget, QString _category, SelectionInterface::PrimitiveType _type = 0u);
175 
176  void slotShowToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
177  void slotShowLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
178  void slotShowVolumeLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
179  void slotShowSurfaceLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
180  void slotShowSphereSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
181  void slotShowClosestBoundarySelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
182  void slotShowFloodFillSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
183  void slotShowComponentsSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
184 
185  void slotGetActiveDataTypes(SelectionInterface::TypeList& _types);
186  void slotGetActivePrimitiveType(SelectionInterface::PrimitiveType& _type);
187 
188  void slotTargetObjectsOnly(bool& _targetsOnly);
189  void slotRegisterKeyShortcut(int _key, Qt::KeyboardModifiers _modifiers);
190 
191  // LoadSaveInterface
192  void addedEmptyObject (int _id);
193  void objectDeleted (int _id);
194 
195  // PickingInterface
196  void slotPickModeChanged (const std::string& _pickmode);
197 
198  // KeyInterface
199  void slotKeyEvent(QKeyEvent* _event);
200  void slotKeyReleaseEvent(QKeyEvent* _event);
201 
202  // INIInterface
203  void loadIniFileOptionsLast(INIFile& _ini);
204 
205 
206  // ============== Selection Actions ===============
207 
208  void slotMouseToggleSelection(QMouseEvent* _event);
209  void slotMouseLassoSelection(QMouseEvent* _event);
210  void slotMouseVolumeLassoSelection(QMouseEvent* _event);
211  void slotMouseSurfaceLassoSelection(QMouseEvent* _event);
212  void slotMouseSphereSelection(QMouseEvent* _event);
213  void slotMouseBoundarySelection(QMouseEvent* _event);
214  void slotMouseFloodFillSelection(QMouseEvent* _event);
215  void slotMouseComponentsSelection(QMouseEvent* _event);
216  void slotMouseCustomSelection(QMouseEvent* _event);
217 
218  void slotLoadSelectionButton();
219  void slotSaveSelectionButton();
220 
221  void slotOperationRequested();
222  void slotShowAndHideOperations();
223  void slotShowAndHideParameters();
224 
225  // ==================== GUI =======================
226 
227  void slotSelectionEnvironmentRequested(bool _checked);
228 
229  void slotEnterSelectionMode(bool _checked);
230 
231  void updateActivePrimitiveTypes(bool _checked);
232 
233  public slots:
234  QString version() { return QString("1.0"); };
235 
249  void setSelectionMetaphor(QString _metaphor);
250 
267  void setSelectionPrimitiveType(QString _primitive);
268 
269  private:
270 
272  // Name of the environment
273  QString name;
274  // List of supported types
275  std::vector<DataType> types;
276  // List of all default selection modes
277  std::set<HandleAction*> defaultSelectionModes;
278  // List of all default selection modes
279  std::set<HandleAction*> customSelectionModes;
280  // Selection environments handle
281  QString handle;
282  // Handle to tab widget's primitive's bar
283  QHBoxLayout* primitivesBar;
284  // Handle to tab widget's operations widget
285  QVBoxLayout* operationsBar;
286  // Keep track of operation categories
287  std::map<QString,std::pair<FillingLayout*,QGroupBox*> > categories;
288  // Action group for primitives
289  QActionGroup* primitiveActions;
290  // Store the supported primitive types (bitmask)
291  unsigned int primitiveTypes;
292  // Map that stores for each primitive type a set of
293  // operations that are supported on it
294  std::multimap<PrimitiveType, QPushButton*> operations;
295  // Map that stores for each primitive type a widget
296  // that provides parameters
297  std::multimap<PrimitiveType, QWidget*> parameters;
298  // Keep name of tab for selection environment
299  QWidget* tabWidget;
300  };
301 
303  QString getUniqueIdentifierName(QString _name, int _num = 0);
304 
306  QString getUniqueHandleName(QString _name, int _num = 0);
307 
309  bool getSelectionEnvironment(SelectionEnvironment*& env, const QString& _handleName);
310 
312  bool typeExists(DataType _type, int _excludeId = -1);
313 
315  QMap<DataType,int> typeCounter_;
316 
319  void showSelectionMode(QString _mode, QString _icon, QString _desc,
320  QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes,
321  QString& _customIdentifier, bool _custom = false, DataType _objectTypeRestriction = DATA_ALL);
322 
324  void selectionModeShowSwitch(bool _show, SelectionEnvironment*& env, HandleAction* toggleSelectionAction_,
325  SelectionInterface::PrimitiveType& _associatedTypes);
326 
328  bool findObjectType(BaseObjectData*& obj, bool& found, SelectionEnvironment*& env, int _id);
329 
332 
334  void updatePickModeToolBar();
335 
336  // Update the tabs widgets' order
337  void updateTabsOrder();
338 
339  // Map of registered selection environments (handle, environment)
340  std::map<QString,SelectionEnvironment> selectionEnvironments_;
341 
342  //================== GUI ======================
343 
344  // List of primitive type buttons (primitivetype, button)
345  std::map<PrimitiveType,QAction*> primitiveTypeButtons_;
346 
347  // Toolbar in OpenFlipper that contains the selection button
348  QToolBar* toolBar_;
349 
350  // Widget for Toolbox
352 
353  // Toolbar that displays ALL primitive types of all selection environments
354  QActionGroup* primitivesBarGroup_;
355  QToolBar* pickModeToolBar_;
356 
357  QActionGroup* selectionModesGroup_;
358 
359  // Actions for default selection modes
360  HandleAction* toggleSelectionAction_;
361  HandleAction* lassoSelectionAction_;
362  HandleAction* volumeLassoSelectionAction_;
363  HandleAction* surfaceLassoSelectionAction_;
364  HandleAction* sphereSelectionAction_;
365  HandleAction* boundarySelectionAction_;
366  HandleAction* floodFillSelectionAction_;
367  HandleAction* componentsSelectionAction_;
368 
369  std::set<std::pair<int,Qt::KeyboardModifiers> > registeredKeys_;
370 
371  //================== Status ===================
372 
373  // Keep the current pick mode
374  QString currentPickMode_;
375 
376  // Keep the last used pick mode
377  QString lastPickMode_;
378 
379  // Keep the current selection mode
380  QString currentSelectionMode_;
381 
382  // Bitmask for currently selected primitive types
383  SelectionInterface::PrimitiveType currentPrimitiveType_;
384 
385  // Next free primitive handle
386  unsigned int nextFreePrimitiveType_;
387 
388  // Indicates whether we want to deselect primitives
389  bool deselection_;
390 
391  //=============== Rendering ====================
392 
393  // Sphere Nodes material
394  ACG::SceneGraph::MaterialNode* sphere_mat_node_;
395 
396  // Sphere Node
398 
399  // Sphere radius
400  double sphere_radius_;
401 
402  // Line Node
403  ACG::SceneGraph::LineNode* line_node_;
404 
405  // Indicates if lasso selection is currently active
406  bool lassoSelection_;
407 
408  // List of points for line node
409  std::vector<ACG::Vec3d> linePoints_;
410 
411  QIcon* toolIcon_;
412 
413  // Keep track of all data types in the scene
414  DataType availableObjectTypes_;
415 };
416 
417 #endif // SELECTIONBASEPLUGIN_HH
Interface class for Plugins which have to store information in ini files.
Definition: INIInterface.hh:60
Interface class for creating custom context menus.
SelectionBasePlugin()
Default constructor.
Logtype
Log types for Message Window.
QMap< DataType, int > typeCounter_
Caches the number of available elements of a certain data type for the typeExists function...
Interface for all plugins which want to Load or Save files and create Objects.
Interface for all Plugins which provide scriptable Functions.
bool getSelectionEnvironment(SelectionEnvironment *&env, const QString &_handleName)
Get a selectionEnvironment by a given name.
QString description()
Return a description of what the plugin is doing.
QString getUniqueHandleName(QString _name, int _num=0)
Get a unique handle name.
void updatePickModeToolBar()
Update the pickmode toolbar.
Interface class for receiving mouse events.
Interface for all Plugins which do logging to the logging window of the framework.
QString getUniqueIdentifierName(QString _name, int _num=0)
Get a unique pickmode name.
void setSelectionPrimitiveType(QString _primitive)
Enables setting the selection primitive via scripting The default primitives for OpenMesh are: ...
Allow access to picking functions.
bool findObjectType(BaseObjectData *&obj, bool &found, SelectionEnvironment *&env, int _id)
helper function to find a baseObjectData and selection environment given a specific id ...
void setSelectionMetaphor(QString _metaphor)
Enables setting the selection metaphor via scripting The default selection metaphors are: ...
Plugins can add its own toolbox to the main widget&#39;s toolbox area by using this interface.
void selectionModeShowSwitch(bool _show, SelectionEnvironment *&env, HandleAction *toggleSelectionAction_, SelectionInterface::PrimitiveType &_associatedTypes)
helper function for showSelectionMode
Interface class from which all plugins have to be created.
Add a toolbox to OpenFlipper.
Keyboard Event Interface.
Definition: KeyInterface.hh:59
Interface for all plugins which want to use selection functions.
Predefined datatypes.
Definition: DataTypes.hh:83
bool typeExists(DataType _type, int _excludeId=-1)
Test if at least one object of type _type is in the scene graph.
SelectionTypeFrameWidget * createNewTypeFrame(SelectionEnvironment &_env)
Create new type frame for tabs widget.
void showSelectionMode(QString _mode, QString _icon, QString _desc, QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes, QString &_customIdentifier, bool _custom=false, DataType _objectTypeRestriction=DATA_ALL)
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
QString name()
Return a name for the plugin.
Class for the handling of simple configuration files.
Definition: INIFile.hh:99