SelectionBasePlugin.hh 16.5 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
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
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
 *                           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 <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
38
39
 *   $Revision$                                                       *
 *   $Author$                                                       *
 *   $Date$                   *
Jan Möbius's avatar
 
Jan Möbius committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 *                                                                           *
\*===========================================================================*/

#ifndef SELECTIONBASEPLUGIN_HH
#define SELECTIONBASEPLUGIN_HH

#include <QObject>
#include <QGroupBox>
#include <QMenuBar>

#include <set>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/MouseInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/PickingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/INIInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/BasePlugin/SelectionInterface.hh>

#include <ACG/Scenegraph/GlutPrimitiveNode.hh>
#include <ACG/Scenegraph/LineNode.hh>

#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>

#include "widgets/SelectionBaseToolbox.hh"
#include "widgets/SelectionTypeFrame.hh"

#include <OpenFlipper/INIFile/INIFile.hh>

#include "HelperClasses.hh"

class SelectionBasePlugin : public QObject, BaseInterface , MouseInterface, KeyInterface, PickingInterface, ToolboxInterface, INIInterface,
    LoggingInterface, ScriptInterface, ContextMenuInterface, ToolbarInterface, LoadSaveInterface, SelectionInterface {
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(MouseInterface)
Q_INTERFACES(KeyInterface)
Q_INTERFACES(PickingInterface)
Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(INIInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(ScriptInterface)
Q_INTERFACES(ContextMenuInterface)
Q_INTERFACES(ToolbarInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(SelectionInterface)

    public:
        
        /// Default constructor
        SelectionBasePlugin();
     
        // BaseInterface
        QString name() { return (QString(tr("SelectionBase"))); };
        QString description( ) { return (QString(tr("Provides basic selection functions"))); };

    signals:
        
105
106
107
        // BaseInterface
        void updateView();

Jan Möbius's avatar
 
Jan Möbius committed
108
109
110
111
112
113
114
115
        // LoggingInterface
        void log(Logtype _type, QString _message);
        void log(QString _message);
        
        // ToolbarInterface
        void addToolbar(QToolBar* _toolbar);
        
        // SelectionInterface
Dirk Wilden's avatar
Dirk Wilden committed
116
        void toggleSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
Jan Möbius's avatar
 
Jan Möbius committed
117
118
119
        void lassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
        void volumeLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
        void surfaceLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
Dirk Wilden's avatar
Dirk Wilden committed
120
121
122
        void sphereSelection(QMouseEvent* _event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect);
        void closestBoundarySelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
        void floodFillSelection(QMouseEvent* _event, double _maxAngle, SelectionInterface::PrimitiveType _currentType, bool _deselect);
123
        void componentsSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
Jan Möbius's avatar
 
Jan Möbius committed
124
125
126
127
128
129
130
131
132
        void customSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, QString _customIdentifier, bool _deselect);
        
        void selectionOperation(QString _operation);
        void loadSelection(const INIFile& _file);
        void saveSelection(INIFile& _file);
        
        void keyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier);
        
        // PickingInterface
133
134
135
136
        void addPickMode(const std::string& _mode);
        void setPickModeMouseTracking(const std::string& _mode, bool _mouseTracking);
        void setPickModeCursor(const std::string& _mode, QCursor _cursor);
        void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
Jan Möbius's avatar
 
Jan Möbius committed
137
138
139
140
141
        
        // KeyInterface
        void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
        
        // ToolboxInterface
Dirk Wilden's avatar
Dirk Wilden committed
142
        void addToolbox(QString _name, QWidget* _widget, QIcon* _icon); 
Jan Möbius's avatar
 
Jan Möbius committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
      
    private slots:
        
        // BaseInterface
        void initializePlugin();
        void pluginsInitialized();
        
        //MouseInterface
        void slotMouseWheelEvent(QWheelEvent* _event, const std::string& _mode);
        void slotMouseEvent(QMouseEvent* _event);
        
        // SelectionInterface
        void slotAddSelectionEnvironment(QString _modeName, QString _description, QIcon _icon, QString& _handleName);
        void slotRegisterType(QString _handleName, DataType _type);
        void slotAddPrimitiveType(QString _handleName, QString _name, QIcon _icon, SelectionInterface::PrimitiveType& _typeHandle);
        void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
                                        SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
160
161
162
        void slotAddCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QIcon _icon,
                                        SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier,
                                        DataType _objectTypeRestriction);
Jan Möbius's avatar
 
Jan Möbius committed
163
164
165
166
167
168
169
170
171
172
        
        void slotAddSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u);
        
        void slotShowToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
        void slotShowLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
        void slotShowVolumeLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
        void slotShowSurfaceLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
        void slotShowSphereSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
        void slotShowClosestBoundarySelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
        void slotShowFloodFillSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
173
        void slotShowComponentsSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
Jan Möbius's avatar
 
Jan Möbius committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
        
        void slotGetActiveDataTypes(SelectionInterface::TypeList& _types);
        void slotGetActivePrimitiveType(SelectionInterface::PrimitiveType& _type);
        
        void slotTargetObjectsOnly(bool& _targetsOnly);
        void slotRegisterKeyShortcut(int _key, Qt::KeyboardModifiers _modifiers);
        
        // LoadSaveInterface
        void addedEmptyObject (int _id);
        void objectDeleted (int _id);
        
        // PickingInterface
        void slotPickModeChanged (const std::string& _pickmode);
        
        // KeyInterface
        void slotKeyEvent(QKeyEvent* _event);
        void slotKeyReleaseEvent(QKeyEvent* _event);
        
        // ============== Selection Actions ===============
        
Jan Möbius's avatar
Jan Möbius committed
194
195
196
197
198
199
200
201
202
203
204
205
        void slotMouseToggleSelection(QMouseEvent* _event);
        void slotMouseLassoSelection(QMouseEvent* _event);
        void slotMouseVolumeLassoSelection(QMouseEvent* _event);
        void slotMouseSurfaceLassoSelection(QMouseEvent* _event);
        void slotMouseSphereSelection(QMouseEvent* _event);
        void slotMouseBoundarySelection(QMouseEvent* _event);
        void slotMouseFloodFillSelection(QMouseEvent* _event);
        void slotMouseComponentsSelection(QMouseEvent* _event);
        void slotMouseCustomSelection(QMouseEvent* _event);
        
        void slotLoadSelectionButton();
        void slotSaveSelectionButton();
Jan Möbius's avatar
 
Jan Möbius committed
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
246
        
        void slotOperationRequested();
        void slotShowAndHideOperations();
        
        // ==================== GUI =======================
        
        void slotSelectionEnvironmentRequested(bool _checked);
        
        void slotEnterSelectionMode(bool _checked);
        
        void updateActivePrimitiveTypes(bool _checked);
        
    public slots:
        QString version() { return QString("1.0"); };
        
    private:
        
        struct SelectionEnvironment {
            // Name of the environment
            QString name;
            // List of supported types
            std::vector<DataType> types;
            // List of all default selection modes
            std::set<HandleAction*> defaultSelectionModes;
            // List of all default selection modes
            std::set<HandleAction*> customSelectionModes;
            // Selection environments handle
            QString handle;
            // Handle to tab widget's primitive's bar
            QHBoxLayout* primitivesBar;
            // Handle to tab widget's operations widget
            QVBoxLayout* operationsBar;
            // Keep track of operation categories
            std::map<QString,std::pair<FillingLayout*,QGroupBox*> > categories;
            // Action group for primitives
            QActionGroup* primitiveActions;
            // Store the supported primitive types (bitmask)
            unsigned int primitiveTypes;
            // Map that stores for each primitive type a set of
            // operations that are supported on it
            std::multimap<PrimitiveType, QPushButton*> operations;
247
248
            // Keep name of tab for selection environment
            QWidget* tabWidget;
Jan Möbius's avatar
 
Jan Möbius committed
249
250
251
252
253
254
255
256
257
258
259
        };
        
        /// Get a unique pickmode name
        QString getUniqueIdentifierName(QString _name, int _num = 0);
        
        /// Get a unique handle name
        QString getUniqueHandleName(QString _name, int _num = 0);
        
        /// Test if at least one object of type _type is in the scene graph
        bool typeExists(DataType _type, int _excludeId = -1);
        
260
261
262
        /// Caches the number of available elements of a certain data type for the typeExists function
        QMap<DataType,int> typeCounter_;

Jan Möbius's avatar
 
Jan Möbius committed
263
264
265
266
        /// Show standard selection mode
        /// Use this method to show/hide standard selection actions (lasso, floodfill, sphere, etc.)
        void showSelectionMode(QString _mode, QIcon _icon, QString _desc,
                               QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes,
267
                               QString& _customIdentifier, bool _custom = false, DataType _objectTypeRestriction = DATA_ALL);
Jan Möbius's avatar
 
Jan Möbius committed
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
         
        /// Create new type frame for tabs widget
        SelectionTypeFrameWidget* createNewTypeFrame(SelectionEnvironment& _env);        
        
        /// Update the pickmode toolbar
        void updatePickModeToolBar();
        
        // Update the tabs widgets' order
        void updateTabsOrder();

        // Map of registered selection environments (handle, environment)
        std::map<QString,SelectionEnvironment> selectionEnvironments_;
        
        //================== GUI ======================
        
        // List of primitive type buttons (primitivetype, button)
        std::map<PrimitiveType,QAction*> primitiveTypeButtons_;
        
        // Toolbar in OpenFlipper that contains the selection button
        QToolBar* toolBar_;
        
        // Widget for Toolbox
        SelectionBaseToolboxWidget* tool_;
        
        // Toolbar that displays ALL primitive types of all selection environments
        QActionGroup* primitivesBarGroup_;
294
        QToolBar* pickModeToolBar_;
Jan Möbius's avatar
 
Jan Möbius committed
295
        
296
297
        QActionGroup* selectionModesGroup_;

Jan Möbius's avatar
 
Jan Möbius committed
298
299
300
301
302
303
304
305
        // Actions for default selection modes
        HandleAction* toggleSelectionAction_;
        HandleAction* lassoSelectionAction_;
        HandleAction* volumeLassoSelectionAction_;
        HandleAction* surfaceLassoSelectionAction_;
        HandleAction* sphereSelectionAction_;
        HandleAction* boundarySelectionAction_;
        HandleAction* floodFillSelectionAction_;
306
        HandleAction* componentsSelectionAction_;
Jan Möbius's avatar
 
Jan Möbius committed
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
        
        std::set<std::pair<int,Qt::KeyboardModifiers> > registeredKeys_;
        
        //================== Status ===================
        
        // Keep the current pick mode
        QString currentPickMode_;
        
        // Keep the last used pick mode
        QString lastPickMode_;
        
        // Keep the current selection mode
        QString currentSelectionMode_;
        
        // Bitmask for currently selected primitive types
        SelectionInterface::PrimitiveType currentPrimitiveType_;
        
        // Next free primitive handle
        unsigned int nextFreePrimitiveType_;
        
        // Indicates whether we want to deselect primitives
        bool deselection_;
        
        //=============== Rendering ====================
        
        // Sphere Nodes material
        ACG::SceneGraph::MaterialNode* sphere_mat_node_;

        // Sphere Node
        ACG::SceneGraph::GlutPrimitiveNode* sphere_node_;
        
        // Sphere radius
        double sphere_radius_;
        
        // Line Node
        ACG::SceneGraph::LineNode* line_node_;
        
        // Indicates if lasso selection is currently active
        bool lassoSelection_;
        
        // List of points for line node
        std::vector<ACG::Vec3d> linePoints_;
Dirk Wilden's avatar
Dirk Wilden committed
349
350

        QIcon* toolIcon_;
351
352
353

        // Keep track of all data types in the scene
        DataType availableObjectTypes_;
Jan Möbius's avatar
 
Jan Möbius committed
354
355
356
};

#endif // SELECTIONBASEPLUGIN_HH