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
87Q_OBJECT
88Q_INTERFACES(BaseInterface)
89Q_INTERFACES(MouseInterface)
90Q_INTERFACES(KeyInterface)
91Q_INTERFACES(PickingInterface)
92Q_INTERFACES(ToolboxInterface)
93Q_INTERFACES(INIInterface)
94Q_INTERFACES(LoggingInterface)
95Q_INTERFACES(ScriptInterface)
96Q_INTERFACES(ContextMenuInterface)
97Q_INTERFACES(ToolbarInterface)
98Q_INTERFACES(LoadSaveInterface)
99Q_INTERFACES(SelectionInterface)
100
101 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SelectionBase")
102
103 public:
104
107
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, 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, const QString &_description, const QString &_icon, QString& _handleName);
167 void slotRegisterType(const QString &_handleName, DataType _type);
168 void slotAddPrimitiveType(QString _handleName, QString _name, QString _icon, SelectionInterface::PrimitiveType& _typeHandle);
169 void slotAddCustomSelectionMode(const QString& _handleName, const QString& _modeName, const QString& _description, const QString& _icon,
170 SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
171 void slotAddCustomSelectionMode(const QString &_handleName, const QString &_modeName, const QString &_description, const 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 void slotAddSelectionParameters(QString _handleName, QWidget* _widget, QString _category, SelectionInterface::PrimitiveType _type = 0u);
177
178 void slotShowToggleSelectionMode(const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
179 void slotShowLassoSelectionMode(const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
180 void slotShowVolumeLassoSelectionMode(const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
181 void slotShowSurfaceLassoSelectionMode(const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
182 void slotShowSphereSelectionMode(const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
183 void slotShowClosestBoundarySelectionMode(const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
184 void slotShowFloodFillSelectionMode(const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
185 void slotShowComponentsSelectionMode(const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
186
187 void slotGetActiveDataTypes(SelectionInterface::TypeList& _types);
188 void slotGetActivePrimitiveType(SelectionInterface::PrimitiveType& _type);
189
190 void slotTargetObjectsOnly(bool& _targetsOnly);
191 void slotRegisterKeyShortcut(int _key, Qt::KeyboardModifiers _modifiers);
192
193 // LoadSaveInterface
194 void addedEmptyObject (int _id);
195 void objectDeleted (int _id);
196
197 // PickingInterface
198 void slotPickModeChanged (const std::string& _pickmode);
199
200 // KeyInterface
201 void slotKeyEvent(QKeyEvent* _event);
202 void slotKeyReleaseEvent(QKeyEvent* _event);
203
204 // INIInterface
205 void loadIniFileOptionsLast(INIFile& _ini);
206
207
208 // ============== Selection Actions ===============
209
210 void slotMouseToggleSelection(QMouseEvent* _event);
211 void slotMouseLassoSelection(QMouseEvent* _event);
212 void slotMouseVolumeLassoSelection(QMouseEvent* _event);
213 void slotMouseSurfaceLassoSelection(QMouseEvent* _event);
214 void slotMouseSphereSelection(QMouseEvent* _event);
215 void slotMouseBoundarySelection(QMouseEvent* _event);
216 void slotMouseFloodFillSelection(QMouseEvent* _event);
217 void slotMouseComponentsSelection(QMouseEvent* _event);
218 void slotMouseCustomSelection(QMouseEvent* _event);
219
220 void slotLoadSelectionButton();
221 void slotSaveSelectionButton();
222
223 void slotOperationRequested();
224 void slotShowAndHideOperations();
225 void slotShowAndHideParameters();
226
227 // ==================== GUI =======================
228
229 void slotSelectionEnvironmentRequested(bool _checked);
230
231 void slotEnterSelectionMode(bool _checked);
232
233 void updateActivePrimitiveTypes(bool _checked);
234
235 public slots:
236 QString version() { return QString("1.0"); };
237
251 void setSelectionMetaphor(const QString& _metaphor);
252
269 void setSelectionPrimitiveType(const QString &_primitive);
270
271 private:
272
274 // Name of the environment
275 QString name;
276 // List of supported types
277 std::vector<DataType> types;
278 // List of all default selection modes
279 std::set<HandleAction*> defaultSelectionModes;
280 // List of all default selection modes
281 std::set<HandleAction*> customSelectionModes;
282 // Selection environments handle
283 QString handle;
284 // Handle to tab widget's primitive's bar
285 QHBoxLayout* primitivesBar;
286 // Handle to tab widget's operations widget
287 QVBoxLayout* operationsBar;
288 // Keep track of operation categories
289 std::map<QString,std::pair<FillingLayout*,QGroupBox*> > categories;
290 // Action group for primitives
291 QActionGroup* primitiveActions;
292 // Store the supported primitive types (bitmask)
293 unsigned int primitiveTypes;
294 // Map that stores for each primitive type a set of
295 // operations that are supported on it
296 std::multimap<PrimitiveType, QPushButton*> operations;
297 // Map that stores for each primitive type a widget
298 // that provides parameters
299 std::multimap<PrimitiveType, QWidget*> parameters;
300 // Keep name of tab for selection environment
301 QWidget* tabWidget;
302 };
303
305 QString getUniqueIdentifierName(const QString &_name, int _num = 0);
306
308 QString getUniqueHandleName(const QString &_name, int _num = 0);
309
311 bool getSelectionEnvironment(SelectionEnvironment*& env, const QString& _handleName);
312
314 bool typeExists(DataType _type, int _excludeId = -1);
315
317 QMap<DataType,int> typeCounter_;
318
321 void showSelectionMode(const QString &_mode, const QString &_icon, const QString &_desc,
322 const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes,
323 QString& _customIdentifier, bool _custom = false, DataType _objectTypeRestriction = DATA_ALL);
324
326 void selectionModeShowSwitch(bool _show, SelectionEnvironment*& env, HandleAction* toggleSelectionAction_,
327 SelectionInterface::PrimitiveType& _associatedTypes);
328
330 bool findObjectType(BaseObjectData*& obj, bool& found, SelectionEnvironment*& env, int _id);
331
334
337
338 // Update the tabs widgets' order
339 void updateTabsOrder();
340
341 // Map of registered selection environments (handle, environment)
342 std::map<QString,SelectionEnvironment> selectionEnvironments_;
343
344 //================== GUI ======================
345
346 // List of primitive type buttons (primitivetype, button)
347 std::map<PrimitiveType,QAction*> primitiveTypeButtons_;
348
349 // Toolbar in OpenFlipper that contains the selection button
350 QToolBar* toolBar_;
351
352 // Widget for Toolbox
354
355 // Toolbar that displays ALL primitive types of all selection environments
356 QActionGroup* primitivesBarGroup_;
357 QToolBar* pickModeToolBar_;
358
359 QActionGroup* selectionModesGroup_;
360
361 // Actions for default selection modes
362 HandleAction* toggleSelectionAction_;
363 HandleAction* lassoSelectionAction_;
364 HandleAction* volumeLassoSelectionAction_;
365 HandleAction* surfaceLassoSelectionAction_;
366 HandleAction* sphereSelectionAction_;
367 HandleAction* boundarySelectionAction_;
368 HandleAction* floodFillSelectionAction_;
369 HandleAction* componentsSelectionAction_;
370
371 std::set<std::pair<int,Qt::KeyboardModifiers> > registeredKeys_;
372
373 //================== Status ===================
374
375 // Keep the current pick mode
376 QString currentPickMode_;
377
378 // Keep the last used pick mode
379 QString lastPickMode_;
380
381 // Keep the current selection mode
382 QString currentSelectionMode_;
383
384 // Bitmask for currently selected primitive types
385 SelectionInterface::PrimitiveType currentPrimitiveType_;
386
387 // Next free primitive handle
388 unsigned int nextFreePrimitiveType_;
389
390 // Indicates whether we want to deselect primitives
391 bool deselection_;
392
393 //=============== Rendering ====================
394
395 // Sphere Nodes material
396 ACG::SceneGraph::MaterialNode* sphere_mat_node_;
397
398 // Sphere Node
400
401 // Sphere radius
402 double sphere_radius_;
403
404 // Line Node
405 ACG::SceneGraph::LineNode* line_node_;
406
407 // Indicates if lasso selection is currently active
408 bool lassoSelection_;
409
410 // List of points for line node
411 std::vector<ACG::Vec3d> linePoints_;
412
413 QIcon* toolIcon_;
414
415 // Keep track of all data types in the scene
416 DataType availableObjectTypes_;
417};
418
419#endif // SELECTIONBASEPLUGIN_HH
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
Logtype
Log types for Message Window.
Interface class from which all plugins have to be created.
Interface class for creating custom context menus.
Predefined datatypes.
Definition: DataTypes.hh:83
Class for the handling of simple configuration files.
Definition: INIFile.hh:100
Interface class for Plugins which have to store information in ini files.
Definition: INIInterface.hh:60
Keyboard Event Interface.
Definition: KeyInterface.hh:59
Interface for all plugins which want to Load or Save files and create Objects.
Interface for all Plugins which do logging to the logging window of the framework.
Interface class for receiving mouse events.
Allow access to picking functions.
Interface for all Plugins which provide scriptable Functions.
bool typeExists(DataType _type, int _excludeId=-1)
Test if at least one object of type _type is in the scene graph.
QMap< DataType, int > typeCounter_
Caches the number of available elements of a certain data type for the typeExists function.
void setSelectionPrimitiveType(const QString &_primitive)
Enables setting the selection primitive via scripting The default primitives for OpenMesh are:
QString name()
Return a name for the plugin.
void updatePickModeToolBar()
Update the pickmode toolbar.
void showSelectionMode(const QString &_mode, const QString &_icon, const QString &_desc, const QString &_handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes, QString &_customIdentifier, bool _custom=false, DataType _objectTypeRestriction=DATA_ALL)
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(const QString &_metaphor)
Enables setting the selection metaphor via scripting The default selection metaphors are:
QString getUniqueHandleName(const QString &_name, int _num=0)
Get a unique handle name.
SelectionBasePlugin()
Default constructor.
SelectionTypeFrameWidget * createNewTypeFrame(SelectionEnvironment &_env)
Create new type frame for tabs widget.
QString description()
Return a description of what the plugin is doing.
bool getSelectionEnvironment(SelectionEnvironment *&env, const QString &_handleName)
Get a selectionEnvironment by a given name.
QString getUniqueIdentifierName(const QString &_name, int _num=0)
Get a unique pickmode name.
void selectionModeShowSwitch(bool _show, SelectionEnvironment *&env, HandleAction *toggleSelectionAction_, SelectionInterface::PrimitiveType &_associatedTypes)
helper function for showSelectionMode
Interface for all plugins which want to use selection functions.
Add a toolbox to OpenFlipper.
Plugins can add its own toolbox to the main widget's toolbox area by using this interface.