SelectionPlugin.hh 25.4 KB
Newer Older
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
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 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
34

35
36
37
38
39
40
41
/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57



#ifndef SELECTIONPLUGIN_HH
#define SELECTIONPLUGIN_HH

#include <QObject>
#include <QMenuBar>

#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>
58
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
59
60
61
62
63
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/INIInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <ACG/Scenegraph/GlutPrimitiveNode.hh>
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
64
#include <ACG/Scenegraph/LineNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>

#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>

#ifdef ENABLE_POLYLINE_SUPPORT
#include <ObjectTypes/PolyLine/PolyLine.hh>
#endif

#ifdef ENABLE_BSPLINECURVE_SUPPORT
#include <ObjectTypes/BSplineCurve/BSplineCurve.hh>
#endif

#include "selectionToolbar.hh"

#include <OpenFlipper/INIFile/INIFile.hh>

#include <QGroupBox>

#define TOGGLE_SELECTION "Select (Toggle)"
#define PAINT_SPHERE_SELECTION "Select (Paint Sphere)"
#define CLOSEST_BOUNDARY_SELECTION "Select (Closest Boundary)"
#define LASSO_SELECTION "Select (Lasso)"
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
89
#define VOLUME_LASSO_SELECTION "Select (Volume Lasso)"
Jan Möbius's avatar
 
Jan Möbius committed
90
91
#define SURFACE_LASSO_SELECTION "Select (Surface Lasso)"
#define CONNECTED_COMPONENT_SELECTION "Select (Connected Component)"
Dirk Wilden's avatar
Dirk Wilden committed
92
#define FLOOD_FILL_SELECTION "Select (Flood Fill)"
93
#define CREATEMESH "Create Mesh from Selection"
Jan Möbius's avatar
 
Jan Möbius committed
94
95
96
97
98
99
100
101

enum SelectionPrimitive {
  VERTEX = 0x01,
  EDGE   = 0x02,
  FACE   = 0x04,
  OBJECT = 0x08
};

102
class SelectionPlugin : public QObject, BaseInterface , MouseInterface, KeyInterface, PickingInterface, ToolboxInterface, INIInterface, BackupInterface, LoggingInterface, ScriptInterface, ContextMenuInterface, ToolbarInterface, LoadSaveInterface
Jan Möbius's avatar
 
Jan Möbius committed
103
104
105
106
107
108
109
110
111
112
113
114
115
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(MouseInterface)
  Q_INTERFACES(KeyInterface)
  Q_INTERFACES(PickingInterface)
  Q_INTERFACES(ToolboxInterface)
  Q_INTERFACES(INIInterface)
  Q_INTERFACES(BackupInterface)
  Q_INTERFACES(LoggingInterface)
  Q_INTERFACES(ScriptInterface)
  Q_INTERFACES(ContextMenuInterface)
  Q_INTERFACES(ToolbarInterface)
116
  Q_INTERFACES(LoadSaveInterface)
Jan Möbius's avatar
 
Jan Möbius committed
117
118
119
120
121

  signals:
    //BaseInterface
    void updateView();
    void updatedObject(int);
122
    
Jan Möbius's avatar
 
Jan Möbius committed
123
124
    //PickingInterface
    void addHiddenPickMode( const std::string _mode );
125
    void addPickMode( const std::string _mode );
Jan Möbius's avatar
 
Jan Möbius committed
126
127
    void setPickModeMouseTracking( const std::string _mode, bool _mouseTracking);
    void setPickModeCursor( const std::string _mode, QCursor _cursor);
128
    
Jan Möbius's avatar
 
Jan Möbius committed
129
130
    //BackupInterface
    void createBackup( int _id , QString _name );
131
    
Jan Möbius's avatar
 
Jan Möbius committed
132
133
134
    //LoggingInterface
    void log(Logtype _type, QString _message);
    void log(QString _message);
135
    
Jan Möbius's avatar
 
Jan Möbius committed
136
137
    //ScriptInterface
    void scriptInfo( QString _functionName );
138

Jan Möbius's avatar
   
Jan Möbius committed
139
140
141
    // ContextMenuInterface
    void addContextMenuItem(QAction* _action , ContextMenuType _type);
    void addContextMenuItem(QAction* _action , DataType _objectType , ContextMenuType _type );
142

Jan Möbius's avatar
 
Jan Möbius committed
143
144
    //KeyInterface
    void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
145
146
147
148

    // ToolboxInterface
    void addToolbox( QString _name  , QWidget* _widget ); 
    
Jan Möbius's avatar
 
Jan Möbius committed
149
150
151
152
    //ToolbarInterface
    void addToolbar(QToolBar* _toolbar);
    void getToolBar(QString _name, QToolBar*& _toolbar);

153
154
    //LoadSaveInterface
    void deleteObject( int _id );
155
    void addEmptyObject( DataType _type, int& _id);
156

Jan Möbius's avatar
 
Jan Möbius committed
157
  private slots:
158
    
Jan Möbius's avatar
 
Jan Möbius committed
159
160
161
    //MouseInterface
    void slotMouseWheelEvent(QWheelEvent * _event, const std::string & _mode);
    void slotMouseEvent( QMouseEvent* _event );
162
    
Jan Möbius's avatar
 
Jan Möbius committed
163
164
165
    //KeyInterface
    void slotKeyEvent( QKeyEvent* _event );
    void slotKeyReleaseEvent( QKeyEvent* _event );
166
    
Jan Möbius's avatar
 
Jan Möbius committed
167
168
    //PickingInterface
    void slotPickModeChanged( const std::string& _mode);
169
    
Jan Möbius's avatar
 
Jan Möbius committed
170
171
172
    //INIInterface
    void loadIniFile( INIFile& _ini , int _id);
    void saveIniFile( INIFile& _ini , int _id);
173
    
Jan Möbius's avatar
 
Jan Möbius committed
174
175
176
177
178
179
180
181
182
183
    //BaseInterface
    void initializePlugin();
    void pluginsInitialized();
    void slotObjectUpdated(int _id);
    void noguiSupported( ) {} ;

  public :

    SelectionPlugin();
    ~SelectionPlugin() {};
Jan Möbius's avatar
Jan Möbius committed
184

Jan Möbius's avatar
 
Jan Möbius committed
185
    //BaseInterface
Dirk Wilden's avatar
Dirk Wilden committed
186
187
    QString name() { return (QString(tr("Selections"))); };
    QString description( ) { return (QString(tr("Allows to select parts of Objects"))); };
Jan Möbius's avatar
 
Jan Möbius committed
188

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
189
190
    friend class SelectVolumeAction;

Jan Möbius's avatar
 
Jan Möbius committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  private :
  //GUI objects
    /// Widget for Toolbox
    selectionToolbarWidget* tool_;

    /// Selection Toolbar
    QToolBar* toolBar_;
    QActionGroup* toolBarActions_;
    QActionGroup* toolBarTypes_;
    QAction* objectAction_;
    QAction* vertexAction_;
    QAction* edgeAction_;
    QAction* faceAction_;
    QAction* toggleAction_;
    QAction* paintSphereAction_;
    QAction* boundaryAction_;
    QAction* lassoAction_;
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
208
    QAction* volumeLassoAction_;
Jan Möbius's avatar
 
Jan Möbius committed
209
210
    QAction* surfaceLassoAction_;
    QAction* connectedAction_;
Dirk Wilden's avatar
Dirk Wilden committed
211
    QAction* floodFillAction_;
212
    QAction* createMeshFromSelAction_;
Jan Möbius's avatar
 
Jan Möbius committed
213
214
215
216
217
218

  private slots:
    /// Switch selection mode dependent which buttons are pressed in the toolbar
    void toolBarActionClicked(QAction* _action);

  private :
219
220
221
222
223
224
      
//===========================================================================
/** @name Template Functions
* @{ */
//===========================================================================
      
Jan Möbius's avatar
 
Jan Möbius committed
225
226
227
228
229
230
231
232
233
234
235
236
    /// Update face selection to correspond to the vertex selection
    template< typename MeshType >
    void update_regions(MeshType* _mesh);

    /// Use current selection to mark Vertices as Modifyable area vertices
    template< typename MeshType >
    void set_area(  MeshType* _mesh);

    /// Use current selection to mark Vertices as Handle vertices
    template< typename MeshType >
    void set_handle(MeshType* _mesh);

Dirk Wilden's avatar
Dirk Wilden committed
237
238
239
240
    /// convert current selection to features
    template< typename MeshType >
    void set_features(MeshType* _mesh);

Jan Möbius's avatar
 
Jan Möbius committed
241
242
243
244
245
246
247
248
    /// Clear Handle vertices
    template< typename MeshType >
    void clear_handle(MeshType* _mesh);

    /// Clear Area
    template< typename MeshType >
    void clear_area(MeshType* _mesh);

Dirk Wilden's avatar
Dirk Wilden committed
249
250
251
252
    /// Clear Features
    template< typename MeshType >
    void clear_features(MeshType* _mesh);

Jan Möbius's avatar
 
Jan Möbius committed
253
254
255
256
    /// Delete all selected elements of a mesh
    template< typename MeshT >
    bool deleteSelection(MeshT* _mesh);

Dirk Wilden's avatar
Dirk Wilden committed
257
258
259
    /// Colorize a selection
    template< typename MeshT >
    void colorizeSelection(MeshT* _mesh, SelectionPrimitive _type, int _red, int _green, int _blue);
260
261
262
263
264
265
266
267
    
    //=================================================================
    
    /// Create a new mesh from the selection
    template< class MeshT >
    void createMeshFromSelection( MeshT& _mesh, MeshT& _newMesh);
    
/** @} */
Dirk Wilden's avatar
Dirk Wilden committed
268

Jan Möbius's avatar
 
Jan Möbius committed
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    /// when SHIFT key is pressed do source-selection instead of target selection in object-mode
    bool sourceSelection_;

    /// when CONTROL key is pressed: deselect instead of select
    bool deselection_;

    //===========================================================================
    /** @name Selection functions
    * @{ */
    //===========================================================================

    ///SelectionFlags (VERTEX, EDGE, FACE, OBJECT)
    unsigned char selectionType_;

    /// Toggle the selection state
    void toggleSelection(QMouseEvent* _event);

    /// Toggle the selection state in meshes
    template< class MeshT >
    void toggleMeshSelection(MeshT* _mesh, uint _fh, ACG::Vec3d& _hit_point);

    #ifdef ENABLE_POLYLINE_SUPPORT
      /// Toggle the selection state in PolyLines
      void togglePolyLineSelection(QMouseEvent* _event);
    #endif

    #ifdef ENABLE_BSPLINECURVE_SUPPORT
      /// Toggle the selection state in BSplineCurves
      void toggleBSplineCurveSelection(QMouseEvent* _event);
    #endif

    /// Handle Mouse move event for sphere painting selection
    void paintSphereSelection(QMouseEvent* _event);

    /// Use the event to paint selection with a sphere
    template< typename MeshT>
    void paintSphereSelection( MeshT* _mesh , int _target_idx, typename MeshT::Point _hitpoint );

    /// Select all primitves of connected component
    void componentSelection(QMouseEvent* _event);

Dirk Wilden's avatar
Dirk Wilden committed
310
311
312
    /// Select all primitves on a (approx) planar region
    void floodFillSelection(QMouseEvent* _event);

Jan Möbius's avatar
 
Jan Möbius committed
313
314
315
316
    /// Select all primitves of connected component
    template< class MeshT >
    void componentSelection(MeshT* _mesh, uint _fh);

Dirk Wilden's avatar
Dirk Wilden committed
317
318
319
320
    /// Select all primitves of a planar region surrounding the faceHandle
    template< class MeshT >
    void floodFillSelection(MeshT* _mesh, uint _fh);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
321
    /// Handle Mouse move event for lasso selection
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
322
323
324
325
326
    void handleLassoSelection(QMouseEvent* _event, bool _volume);

    /// Select all primitves that are projected to the given region
    template< class MeshT >
    bool volumeSelection(MeshT* _mesh, ACG::GLState& _state, QRegion *_region);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
327

Jan Möbius's avatar
 
Jan Möbius committed
328
329
330
331
332
333
334
335
336
    /** @} */
  private slots:

    /// Use current selection to set Area bits
    void slotSetArea();

    /// Use current selection to set Handle bits
    void slotSetHandle();

Dirk Wilden's avatar
Dirk Wilden committed
337
338
339
    /// convert current selection to feature
    void slotSetFeatures();

Jan Möbius's avatar
 
Jan Möbius committed
340
341
342
343
344
345
    /// Clear Handle Bits
    void slotClearHandle();

    /// Clear Area Bits
    void slotClearArea();

Dirk Wilden's avatar
Dirk Wilden committed
346
347
348
    /// Clear Features
    void slotClearFeatures();

Jan Möbius's avatar
 
Jan Möbius committed
349
350
351
    /// Delete all selected elements of the target meshes
    void slotDeleteSelection();

Dirk Wilden's avatar
Dirk Wilden committed
352
353
354
    /// Toggle the selection Restriction
    void slotToggleSelectionRestriction();

Jan Möbius's avatar
 
Jan Möbius committed
355
  private:
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
356
357
358

    /// Select mesh elements for each object in the list
    void forEachObject(QList<QPair<unsigned int, unsigned int> > &_list, SelectionPrimitive _type);
Jan Möbius's avatar
 
Jan Möbius committed
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383

  //===========================================================================
  /** @name Button slots
  * @{ */
  //===========================================================================
  private slots:

    /// Select everything of the active object
    void slotSelectAll();

    /// Clear selection of current objects
    void slotClearSelection();

    /// Invert the current selection
    void slotInvertSelection();

    /// Select the boundary of the object
    void slotSelectBoundary();

    /// Shrink the current selection
    void slotShrinkSelection();

    /// Grow the current selection
    void slotGrowSelection();

Dirk Wilden's avatar
Dirk Wilden committed
384
385
    /// load a selection
    void slotLoadSelection();
Jan Möbius's avatar
 
Jan Möbius committed
386

Dirk Wilden's avatar
Dirk Wilden committed
387
388
    /// Save the current selection
    void slotSaveSelection();
Jan Möbius's avatar
 
Jan Möbius committed
389

390
    /// Convert selection types (modeling area, handle region or feature)
391
392
    void slotConvertSelectionType();

Dirk Wilden's avatar
Dirk Wilden committed
393
394
395
    /// Colorize given selection
    void slotColorizeSelection();

Mike Kremer's avatar
Mike Kremer committed
396
397
398
399
400
401
402
403
404
405
406
    //==========================================

    /// clear all vertex selections of every object
    void slotClearAllVertexSelections();

    /// clear all edge selections of every object
    void slotClearAllEdgeSelections();

    /// clear all face selections of every object
    void slotClearAllFaceSelections();

Jan Möbius's avatar
 
Jan Möbius committed
407
408
409
410
411
412
413
414
415
416

  /** @} */

  //===========================================================================
  /** @name Scriptable slots
  * @{ */
  //===========================================================================
  public slots:

    /// select given vertices
Jan Möbius's avatar
Jan Möbius committed
417
    void selectVertices( int objectId , IdList _vertexList );
Jan Möbius's avatar
 
Jan Möbius committed
418
419

    /// unselect given vertices
Jan Möbius's avatar
Jan Möbius committed
420
    void unselectVertices( int objectId , IdList _vertexList );
Jan Möbius's avatar
 
Jan Möbius committed
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

    /// Select all Vertices
    void selectAllVertices( int objectId );

    /// Unselect all vertices
    void clearVertexSelection( int objectId );

    /// Invert the current vertex selection
    void invertVertexSelection( int objectId );

    /// Select all boundary vertices of the given object
    void selectBoundaryVertices( int objectId );

    /// Select all vertices of the boundary close to the given vertex
    void selectClosestBoundaryVertices( int objectId, int VertexId );

    /// Shrink the current vertex selection
    void shrinkVertexSelection( int objectId );

    /// Grow the current vertex selection
    void growVertexSelection( int objectId );

    /// return a list of all selected vertices
Jan Möbius's avatar
Jan Möbius committed
444
    IdList getVertexSelection( int objectId );
Jan Möbius's avatar
 
Jan Möbius committed
445
446
447
448

    /// delete vertices and faces that are currently selected
    void deleteSelection( int objectId );

Dirk Wilden's avatar
Dirk Wilden committed
449
450
451
    /// colorize the vertex selection
    void colorizeVertexSelection(int objectId, int r, int g, int b );

Jan Möbius's avatar
 
Jan Möbius committed
452
453
454
    //==========================================

    /// Set vertices to be part of the handle area
Jan Möbius's avatar
Jan Möbius committed
455
    void selectHandleVertices( int objectId , IdList _vertexList );
Jan Möbius's avatar
 
Jan Möbius committed
456
457

    /// Remove vertices from handle area
Jan Möbius's avatar
Jan Möbius committed
458
    void unselectHandleVertices( int objectId , IdList _vertexList );
Jan Möbius's avatar
 
Jan Möbius committed
459
460
461
462
463
464
465
466

    /// Clear handle Area
    void clearHandleVertices( int objectId  );

    /// Set all vertices to be part of the handle area
    void setAllHandleVertices( int objectId );

    /// Get a list of all handle vertices
Jan Möbius's avatar
Jan Möbius committed
467
    IdList getHandleVertices( int objectId );
Jan Möbius's avatar
 
Jan Möbius committed
468
469
470
471

    /// Load a selection from an Flipper selection file for the given object
    void loadFlipperModelingSelection( int _objectId , QString _filename );

Dirk Wilden's avatar
Dirk Wilden committed
472
473
474
    /// Save a selection in Flipper Selection Format
    void saveFlipperModelingSelection( int _objectId , QString _filename );

Jan Möbius's avatar
 
Jan Möbius committed
475
476
477
    //==========================================

    /// Set vertices to be part of the modeling area
Jan Möbius's avatar
Jan Möbius committed
478
    void selectModelingVertices( int objectId , IdList _vertexList );
Jan Möbius's avatar
 
Jan Möbius committed
479
480

    /// Remove vertices from modeling area
Jan Möbius's avatar
Jan Möbius committed
481
    void unselectModelingVertices( int objectId , IdList _vertexList );
Jan Möbius's avatar
 
Jan Möbius committed
482
483
484
485
486
487
488
489

    /// Clear Modeling Area
    void clearModelingVertices( int objectId  );

    /// Set all vertices to be part of the modeling area
    void setAllModelingVertices( int objectId );

    /// Get a list of all modeling vertices
Jan Möbius's avatar
Jan Möbius committed
490
    IdList getModelingVertices( int objectId );
Jan Möbius's avatar
 
Jan Möbius committed
491
492
493
494

    //==========================================

    /// Select given Edges
Jan Möbius's avatar
Jan Möbius committed
495
    void selectEdges( int objectId , IdList _vertexList );
Jan Möbius's avatar
 
Jan Möbius committed
496
497

    /// Unselect given Edges
Jan Möbius's avatar
Jan Möbius committed
498
    void unselectEdges( int objectId , IdList _vertexList );
Jan Möbius's avatar
 
Jan Möbius committed
499
500
501
502
503
504
505
506
507
508
509
510
511
512

    /// Select all Edges
    void selectAllEdges( int objectId );

    /// Unselect all Edges
    void invertEdgeSelection( int objectId );

    /// Invert the current edge selection
    void clearEdgeSelection( int objectId );

    /// select boundary edges
    void selectBoundaryEdges( int objectId );

    /// return a list of all selected edges
Jan Möbius's avatar
Jan Möbius committed
513
    IdList getEdgeSelection( int objectId );
Mike Kremer's avatar
Mike Kremer committed
514
515
516
    
    /// colorize the edge selection
    void colorizeEdgeSelection(int objectId, int r, int g, int b );
Jan Möbius's avatar
 
Jan Möbius committed
517
518
519
520

    //==========================================

    /// Select given faces
Jan Möbius's avatar
Jan Möbius committed
521
    void selectFaces( int objectId , IdList _facesList );
Jan Möbius's avatar
 
Jan Möbius committed
522
523

    /// Unselect given faces
Jan Möbius's avatar
Jan Möbius committed
524
    void unselectFaces( int objectId , IdList _facesList );
Jan Möbius's avatar
 
Jan Möbius committed
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

    /// Select all faces
    void selectAllFaces( int objectId );

    /// Unselect all faces
    void clearFaceSelection( int objectId );

    /// Invert the current face selection
    void invertFaceSelection( int objectId );

    /// Select all boundary faces of the given object
    void selectBoundaryFaces( int objectId );

    /// Shrink the current face selection
    void shrinkFaceSelection( int objectId );

    /// Grow the current face selection
    void growFaceSelection( int objectId );

    /// return a list of all selected faces
Jan Möbius's avatar
Jan Möbius committed
545
    IdList getFaceSelection( int objectId );
Jan Möbius's avatar
 
Jan Möbius committed
546

Dirk Wilden's avatar
Dirk Wilden committed
547
548
549
    /// colorize the face selection
    void colorizeFaceSelection(int objectId, int r, int g, int b );

550
551
552
553
554
    /// save Selections into File
    void saveSelections();

    /// save Selection of one object
    void saveSelection( int _objectId  , QString _filename);
Dirk Wilden's avatar
Dirk Wilden committed
555
556
557

    /// load Selection of one object
    void loadSelection( int _objectId  , QString _filename);
558
559
560
561
562
    
    //=====================================================
    
    /// Create a mesh containing the selection of the given mesh
    int createMeshFromSelection( int _objectId );
Dirk Wilden's avatar
Dirk Wilden committed
563

Mike Kremer's avatar
Mike Kremer committed
564
565
    private slots:

566
567
568
    void saveSelection( TriMesh&  _mesh, QString _filename);
    void saveSelection( PolyMesh& _mesh, QString _filename);

569
    //======================================================
570

571
    /// Convert selection types (modeling area, handle region or feature)
Mike Kremer's avatar
Mike Kremer committed
572
    void convertSelectionType(StatusBits _from, StatusBits _to, bool _clearAfter);
573

574
    /// Convert selections (vertex, edge, face)
575
//    void convertSelection();
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599

    /// Select for each selected vertex the incident edges and
    /// unselect vertices after (if _unselectAfter = true)
    void convertVtoESelection(bool _unselectAfter = true);

    /// Select for each selected vertex the adjacent faces and
    /// unselect vertices after (if _unselectAfter = true)
    void convertVtoFSelection(bool _unselectAfter = true);

    /// Select for each selected edge the adjacent vertices and
    /// unselect the edges after (if _unselectAfter = true)
    void convertEtoVSelection(bool _unselectAfter = true);

    /// Select for each selected edge the two adjacent faces and
    /// unselect the edges after (if _unselectAfter = true)
    void convertEtoFSelection(bool _unselectAfter = true);

    /// Select for each selected face the adjacent vertices and
    /// unselect the face after (if _unselectAfter = true)
    void convertFtoVSelection(bool _unselectAfter = true);

    /// Select for each selected face the adjacent edges and
    /// unselect the face after (if _unselectAfter = true)
    void convertFtoESelection(bool _unselectAfter = true);
600
601
602
603
604
605
606
607
    
    //==========================================================
    
    /// Create Mesh from Selection Button
    void slotCreateMeshFromSelection();
    
    /// Create mesh from selection of picked object
    void createMeshFromSelection(QMouseEvent* _event);
608

Jan Möbius's avatar
 
Jan Möbius committed
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
  /** @} */

  //===========================================================================
  /** @name Variables for sphere painting selection
  * @{ */
  //===========================================================================

  private:

    /// Sphere Nodes material
    ACG::SceneGraph::MaterialNode*      sphere_mat_node_;

    /// Sphere Node
    ACG::SceneGraph::GlutPrimitiveNode* sphere_node_;

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
624
625
626
    /// Line Node
    ACG::SceneGraph::LineNode* line_node_;

Jan Möbius's avatar
 
Jan Möbius committed
627
628
629
630
631
632
633
634
635
    /// Current radius of the sphere
    float sphere_radius_;

    /// true if currently selecting a sphere
    bool sphere_selection_;

    /// vector containing all object-id's whose selection has changed
    std::vector< int > selection_changes_;

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
636
637
    /// vector containing all projected lasso points
    std::vector< ACG::Vec3f > lasso_points_;
Jan Möbius's avatar
 
Jan Möbius committed
638

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
639
640
    /// vector containing all lasso points
    QPolygon lasso_2Dpoints_;
Jan Möbius's avatar
 
Jan Möbius committed
641

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
642
643
    /// true if currently selecting with lasso
    bool lasso_selection_;
Jan Möbius's avatar
 
Jan Möbius committed
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690

  /** @} */


  //===========================================================================
  /** @name Variables for Surface-Lasso Selection
  * @{ */
  //===========================================================================

  private:

    /// flag is active while waiting for the creation of a polyLine
    bool waitingForPolyLineSelection_;

    /// stores the id of the polyLine which is used for selection
    int polyLineID_;

    #ifdef ENABLE_POLYLINE_SUPPORT
      /// function determines if inside/outside of polyline should be selected and selects the part
      void surfaceLassoSelection(QMouseEvent* _event);

      /// selects everything inside/outside of the given polyline
      template< class MeshT , class SpatialSearchT>
      void surfaceLassoSelection( MeshT*                     _mesh ,
                                  PolyLine*                  _line ,
                                  typename MeshT::FaceHandle _fh,
                                  SpatialSearchT*            _search);

    #endif

  /** @} */

  //===========================================================================
  /** @name Variables for Closest-Boundary Selection
  * @{ */
  //===========================================================================

  private:
    /// selects the closest boundary to a vertex with given handle
    template< class MeshT >
    void closestBoundarySelection(MeshT* _mesh, int _vh, unsigned char _selectionType);

    /// closest boundary selection
    void closestBoundarySelection(QMouseEvent* _event);

  /** @} */

Dirk Wilden's avatar
Dirk Wilden committed
691
692
693
694
695
696
697
698
699
700
  //===========================================================================
  /** @name Variables for FloodFill Selection
  * @{ */
  //===========================================================================

  private:
    double maxFloodFillAngle_;

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
  //===========================================================================
  /** @name Context Menu
  * @{ */
  //===========================================================================

  private slots:

    /// called by the selection context Menu
    void selectionContextMenu(QAction* _action);

  private:
    ///Selection context menu
    QMenu* contextMenu_;

    /// Select all primitives of the given object
    void selectAll      ( int objectId );

    /// Clear the selection on the given object
    void clearSelection ( int objectId );

    /// invert the selection on the given object
    void invertSelection( int objectId );

    /// shrink the outer ring(s) of the selection
    void shrinkSelection( int objectId );

    /// grow the outer ring(s) of the selection
    void growSelection  ( int objectId );

    /// select the boundary of the giben object
    void selectBoundary ( int objectId );

Dirk Wilden's avatar
Dirk Wilden committed
733
734
735
    /// choose a color and colorize the selection
    void colorizeSelection(int objectId );

Jan Möbius's avatar
 
Jan Möbius committed
736
737
738
739
740
741
742
  /** @} */

  public slots:
    QString version() { return QString("1.0"); };

};

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
743
744
745
746
747
748
749
750
/// Traverse the scenegraph and call the selection function for mesh nodes
class SelectVolumeAction
{
public:

  SelectVolumeAction(QRegion *_region, SelectionPlugin *_plugin) :
    region_(_region), plugin_(_plugin) {}

751
752
753
754
  void enter (BaseNode* /*_node*/) {};
  
  void leave (BaseNode* /*_node*/) {};

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
755
756
757
758
759
760
761
762
763
  bool operator()(BaseNode* _node, ACG::GLState& _state);

private:

  QRegion         *region_;
  SelectionPlugin *plugin_;
};


Jan Möbius's avatar
 
Jan Möbius committed
764
765
766
767
768
769
770
771
772
773
774
775
776
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(SELECTIONPLUGINT_C)
#define SELECTIONPLUGINT_TEMPLATES
#include "SelectionPluginT.cc"
#endif

#if defined(INCLUDE_TEMPLATES) && !defined(SELECTIONFUNCTIONST_C)
#define SELECTIONFUNCTIONST_TEMPLATES
#include "SelectionFunctionsT.cc"
#endif
//=============================================================================
#endif // SELECTIONPLUGIN_HH defined
//=============================================================================