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 #if QT_VERSION >= 0x050000
102  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SelectionBase")
103 #endif
104 
105  public:
106 
109 
110  // BaseInterface
111  QString name() { return (QString(tr("SelectionBase"))); };
112  QString description( ) { return (QString(tr("Provides basic selection functions"))); };
113 
114  signals:
115 
116  // BaseInterface
117  void updateView();
118 
119  // LoggingInterface
120  void log(Logtype _type, QString _message);
121  void log(QString _message);
122 
123  // ToolbarInterface
124  void addToolbar(QToolBar* _toolbar);
125 
126  // SelectionInterface
127  void toggleSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
128  void lassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
129  void volumeLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
130  void surfaceLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
131  void sphereSelection(QMouseEvent* _event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect);
132  void closestBoundarySelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
133  void floodFillSelection(QMouseEvent* _event, double _maxAngle, SelectionInterface::PrimitiveType _currentType, bool _deselect);
134  void componentsSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
135  void customSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, QString _customIdentifier, bool _deselect);
136 
137  void selectionOperation(QString _operation);
138  void loadSelection(const INIFile& _file);
139  void saveSelection(INIFile& _file);
140 
141  void keyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier);
142 
143  // PickingInterface
144  void addPickMode(const std::string& _mode);
145  void setPickModeMouseTracking(const std::string& _mode, bool _mouseTracking);
146  void setPickModeCursor(const std::string& _mode, QCursor _cursor);
147  void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
148 
149  // KeyInterface
150  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
151 
152  // ToolboxInterface
153  void addToolbox(QString _name, QWidget* _widget, QIcon* _icon);
154 
155  private slots:
156 
157  // BaseInterface
158  void initializePlugin();
159  void pluginsInitialized();
160 
161  //MouseInterface
162  void slotMouseWheelEvent(QWheelEvent* _event, const std::string& _mode);
163  void slotMouseEvent(QMouseEvent* _event);
164 
165  // SelectionInterface
166  void slotAddSelectionEnvironment(QString _modeName, QString _description, QString _icon, QString& _handleName);
167  void slotRegisterType(QString _handleName, DataType _type);
168  void slotAddPrimitiveType(QString _handleName, QString _name, QString _icon, SelectionInterface::PrimitiveType& _typeHandle);
169  void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QString _icon,
170  SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
171  void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QString _icon,
172  SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier,
173  DataType _objectTypeRestriction);
174 
175  void slotAddSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u);
176 
177  void slotShowToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
178  void slotShowLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
179  void slotShowVolumeLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
180  void slotShowSurfaceLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
181  void slotShowSphereSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
182  void slotShowClosestBoundarySelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
183  void slotShowFloodFillSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
184  void slotShowComponentsSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
185 
186  void slotGetActiveDataTypes(SelectionInterface::TypeList& _types);
187  void slotGetActivePrimitiveType(SelectionInterface::PrimitiveType& _type);
188 
189  void slotTargetObjectsOnly(bool& _targetsOnly);
190  void slotRegisterKeyShortcut(int _key, Qt::KeyboardModifiers _modifiers);
191 
192  // LoadSaveInterface
193  void addedEmptyObject (int _id);
194  void objectDeleted (int _id);
195 
196  // PickingInterface
197  void slotPickModeChanged (const std::string& _pickmode);
198 
199  // KeyInterface
200  void slotKeyEvent(QKeyEvent* _event);
201  void slotKeyReleaseEvent(QKeyEvent* _event);
202 
203  // ============== Selection Actions ===============
204 
205  void slotMouseToggleSelection(QMouseEvent* _event);
206  void slotMouseLassoSelection(QMouseEvent* _event);
207  void slotMouseVolumeLassoSelection(QMouseEvent* _event);
208  void slotMouseSurfaceLassoSelection(QMouseEvent* _event);
209  void slotMouseSphereSelection(QMouseEvent* _event);
210  void slotMouseBoundarySelection(QMouseEvent* _event);
211  void slotMouseFloodFillSelection(QMouseEvent* _event);
212  void slotMouseComponentsSelection(QMouseEvent* _event);
213  void slotMouseCustomSelection(QMouseEvent* _event);
214 
215  void slotLoadSelectionButton();
216  void slotSaveSelectionButton();
217 
218  void slotOperationRequested();
219  void slotShowAndHideOperations();
220 
221  // ==================== GUI =======================
222 
223  void slotSelectionEnvironmentRequested(bool _checked);
224 
225  void slotEnterSelectionMode(bool _checked);
226 
227  void updateActivePrimitiveTypes(bool _checked);
228 
229  public slots:
230  QString version() { return QString("1.0"); };
231 
245  void setSelectionMetaphor(QString _metaphor);
246 
263  void setSelectionPrimitiveType(QString _primitive);
264 
265  private:
266 
268  // Name of the environment
269  QString name;
270  // List of supported types
271  std::vector<DataType> types;
272  // List of all default selection modes
273  std::set<HandleAction*> defaultSelectionModes;
274  // List of all default selection modes
275  std::set<HandleAction*> customSelectionModes;
276  // Selection environments handle
277  QString handle;
278  // Handle to tab widget's primitive's bar
279  QHBoxLayout* primitivesBar;
280  // Handle to tab widget's operations widget
281  QVBoxLayout* operationsBar;
282  // Keep track of operation categories
283  std::map<QString,std::pair<FillingLayout*,QGroupBox*> > categories;
284  // Action group for primitives
285  QActionGroup* primitiveActions;
286  // Store the supported primitive types (bitmask)
287  unsigned int primitiveTypes;
288  // Map that stores for each primitive type a set of
289  // operations that are supported on it
290  std::multimap<PrimitiveType, QPushButton*> operations;
291  // Keep name of tab for selection environment
292  QWidget* tabWidget;
293  };
294 
296  QString getUniqueIdentifierName(QString _name, int _num = 0);
297 
299  QString getUniqueHandleName(QString _name, int _num = 0);
300 
302  bool typeExists(DataType _type, int _excludeId = -1);
303 
305  QMap<DataType,int> typeCounter_;
306 
309  void showSelectionMode(QString _mode, QString _icon, QString _desc,
310  QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes,
311  QString& _customIdentifier, bool _custom = false, DataType _objectTypeRestriction = DATA_ALL);
312 
315 
317  void updatePickModeToolBar();
318 
319  // Update the tabs widgets' order
320  void updateTabsOrder();
321 
322  // Map of registered selection environments (handle, environment)
323  std::map<QString,SelectionEnvironment> selectionEnvironments_;
324 
325  //================== GUI ======================
326 
327  // List of primitive type buttons (primitivetype, button)
328  std::map<PrimitiveType,QAction*> primitiveTypeButtons_;
329 
330  // Toolbar in OpenFlipper that contains the selection button
331  QToolBar* toolBar_;
332 
333  // Widget for Toolbox
335 
336  // Toolbar that displays ALL primitive types of all selection environments
337  QActionGroup* primitivesBarGroup_;
338  QToolBar* pickModeToolBar_;
339 
340  QActionGroup* selectionModesGroup_;
341 
342  // Actions for default selection modes
343  HandleAction* toggleSelectionAction_;
344  HandleAction* lassoSelectionAction_;
345  HandleAction* volumeLassoSelectionAction_;
346  HandleAction* surfaceLassoSelectionAction_;
347  HandleAction* sphereSelectionAction_;
348  HandleAction* boundarySelectionAction_;
349  HandleAction* floodFillSelectionAction_;
350  HandleAction* componentsSelectionAction_;
351 
352  std::set<std::pair<int,Qt::KeyboardModifiers> > registeredKeys_;
353 
354  //================== Status ===================
355 
356  // Keep the current pick mode
357  QString currentPickMode_;
358 
359  // Keep the last used pick mode
360  QString lastPickMode_;
361 
362  // Keep the current selection mode
363  QString currentSelectionMode_;
364 
365  // Bitmask for currently selected primitive types
366  SelectionInterface::PrimitiveType currentPrimitiveType_;
367 
368  // Next free primitive handle
369  unsigned int nextFreePrimitiveType_;
370 
371  // Indicates whether we want to deselect primitives
372  bool deselection_;
373 
374  //=============== Rendering ====================
375 
376  // Sphere Nodes material
377  ACG::SceneGraph::MaterialNode* sphere_mat_node_;
378 
379  // Sphere Node
381 
382  // Sphere radius
383  double sphere_radius_;
384 
385  // Line Node
386  ACG::SceneGraph::LineNode* line_node_;
387 
388  // Indicates if lasso selection is currently active
389  bool lassoSelection_;
390 
391  // List of points for line node
392  std::vector<ACG::Vec3d> linePoints_;
393 
394  QIcon* toolIcon_;
395 
396  // Keep track of all data types in the scene
397  DataType availableObjectTypes_;
398 };
399 
400 #endif // SELECTIONBASEPLUGIN_HH
Interface class for creating custom context menus.
Interface class for receiving mouse events.
Predefined datatypes.
Definition: DataTypes.hh:96
bool typeExists(DataType _type, int _excludeId=-1)
Test if at least one object of type _type is in the scene graph.
Logtype
Log types for Message Window.
QString getUniqueHandleName(QString _name, int _num=0)
Get a unique handle name.
Keyboard Event Interface.
Definition: KeyInterface.hh:76
void updatePickModeToolBar()
Update the pickmode toolbar.
SelectionTypeFrameWidget * createNewTypeFrame(SelectionEnvironment &_env)
Create new type frame for tabs widget.
Interface for all Plugins which provide scriptable Functions.
Interface class for Plugins which have to store information in ini files.
Definition: INIInterface.hh:81
Interface class from which all plugins have to be created.
Plugins can add its own toolbox to the main widget&#39;s toolbox area by using this interface.
QString description()
Return a description of what the plugin is doing.
Interface for all Plugins which do logging to the logging window of the framework.
QMap< DataType, int > typeCounter_
Caches the number of available elements of a certain data type for the typeExists function...
void setSelectionMetaphor(QString _metaphor)
Enables setting the selection metaphor via scripting The default selection metaphors are: ...
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
Class for the handling of simple configuration files.
Definition: INIFile.hh:105
SelectionBasePlugin()
Default constructor.
Interface for all plugins which want to use selection functions.
void setSelectionPrimitiveType(QString _primitive)
Enables setting the selection primitive via scripting The default primitives for OpenMesh are: ...
void showSelectionMode(QString _mode, QString _icon, QString _desc, QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes, QString &_customIdentifier, bool _custom=false, DataType _objectTypeRestriction=DATA_ALL)
Interface for all plugins which want to Load or Save files and create Objects.
QString name()
Return a name for the plugin.
QString getUniqueIdentifierName(QString _name, int _num=0)
Get a unique pickmode name.
Add a toolbox to OpenFlipper.
Allow access to picking functions.