SelectionPlugin.hh 19.1 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
37
38
39
40
41
42
43
44
45
46
47
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
//
//  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 Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




#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>
48
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
49
50
51
52
53
#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
54
#include <ACG/Scenegraph/LineNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
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
#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
80
#define VOLUME_LASSO_SELECTION "Select (Volume Lasso)"
Jan Möbius's avatar
 
Jan Möbius committed
81
82
83
84
85
86
87
88
89
90
#define SURFACE_LASSO_SELECTION "Select (Surface Lasso)"
#define CONNECTED_COMPONENT_SELECTION "Select (Connected Component)"

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

91
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
92
93
94
95
96
97
98
99
100
101
102
103
104
{
  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)
105
  Q_INTERFACES(LoadSaveInterface)
Jan Möbius's avatar
 
Jan Möbius committed
106
107
108
109
110

  signals:
    //BaseInterface
    void updateView();
    void updatedObject(int);
Dirk Wilden's avatar
Dirk Wilden committed
111
    void objectSelectionChanged(int);
Jan Möbius's avatar
 
Jan Möbius committed
112
113
114
115
116
117
118
119
120
121
122
    //PickingInterface
    void addHiddenPickMode( const std::string _mode );
    void setPickModeMouseTracking( const std::string _mode, bool _mouseTracking);
    void setPickModeCursor( const std::string _mode, QCursor _cursor);
    //BackupInterface
    void createBackup( int _id , QString _name );
    //LoggingInterface
    void log(Logtype _type, QString _message);
    void log(QString _message);
    //ScriptInterface
    void scriptInfo( QString _functionName );
123

Jan Möbius's avatar
   
Jan Möbius committed
124
125
126
    // ContextMenuInterface
    void addContextMenuItem(QAction* _action , ContextMenuType _type);
    void addContextMenuItem(QAction* _action , DataType _objectType , ContextMenuType _type );
127

Jan Möbius's avatar
 
Jan Möbius committed
128
129
130
131
132
133
    //KeyInterface
    void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
    //ToolbarInterface
    void addToolbar(QToolBar* _toolbar);
    void getToolBar(QString _name, QToolBar*& _toolbar);

134
135
136
    //LoadSaveInterface
    void deleteObject( int _id );

Jan Möbius's avatar
 
Jan Möbius committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  private slots:
    //MouseInterface
    void slotMouseWheelEvent(QWheelEvent * _event, const std::string & _mode);
    void slotMouseEvent( QMouseEvent* _event );
    //KeyInterface
    void slotKeyEvent( QKeyEvent* _event );
    void slotKeyReleaseEvent( QKeyEvent* _event );
    //PickingInterface
    void slotPickModeChanged( const std::string& _mode);
    //INIInterface
    void loadIniFile( INIFile& _ini , int _id);
    void saveIniFile( INIFile& _ini , int _id);
    //BaseInterface
    void initializePlugin();
    void pluginsInitialized();
    void slotObjectUpdated(int _id);
    void noguiSupported( ) {} ;

  public :

    SelectionPlugin();
    ~SelectionPlugin() {};
    //Toolbox Interface
    bool initializeToolbox(QWidget*& _widget);
    //BaseInterface
    QString name() { return (QString("Selections")); };
    QString description( ) { return (QString("Allows to select parts of Objects")); };

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
165
166
    friend class SelectVolumeAction;

Jan Möbius's avatar
 
Jan Möbius committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  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
184
    QAction* volumeLassoAction_;
Jan Möbius's avatar
 
Jan Möbius committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    QAction* surfaceLassoAction_;
    QAction* connectedAction_;

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

  private :
    /// 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
205
206
207
208
    /// convert current selection to features
    template< typename MeshType >
    void set_features(MeshType* _mesh);

Jan Möbius's avatar
 
Jan Möbius committed
209
210
211
212
213
214
215
216
    /// 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
217
218
219
220
    /// Clear Features
    template< typename MeshType >
    void clear_features(MeshType* _mesh);

Jan Möbius's avatar
 
Jan Möbius committed
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
    /// Delete all selected elements of a mesh
    template< typename MeshT >
    bool deleteSelection(MeshT* _mesh);

    /// 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);

    /// Select all primitves of connected component
    template< class MeshT >
    void componentSelection(MeshT* _mesh, uint _fh);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
270
    /// Handle Mouse move event for lasso selection
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
271
272
273
274
275
    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
276

Jan Möbius's avatar
 
Jan Möbius committed
277
278
279
280
281
282
283
284
285
    /** @} */
  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
286
287
288
    /// convert current selection to feature
    void slotSetFeatures();

Jan Möbius's avatar
 
Jan Möbius committed
289
290
291
292
293
294
    /// Clear Handle Bits
    void slotClearHandle();

    /// Clear Area Bits
    void slotClearArea();

Dirk Wilden's avatar
Dirk Wilden committed
295
296
297
    /// Clear Features
    void slotClearFeatures();

Jan Möbius's avatar
 
Jan Möbius committed
298
299
300
    /// Delete all selected elements of the target meshes
    void slotDeleteSelection();

Dirk Wilden's avatar
Dirk Wilden committed
301
302
303
    /// Toggle the selection Restriction
    void slotToggleSelectionRestriction();

Jan Möbius's avatar
 
Jan Möbius committed
304
  private:
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
305
306
307

    /// 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
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

  //===========================================================================
  /** @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
333
334
    /// load a selection
    void slotLoadSelection();
Jan Möbius's avatar
 
Jan Möbius committed
335

Dirk Wilden's avatar
Dirk Wilden committed
336
337
    /// Save the current selection
    void slotSaveSelection();
Jan Möbius's avatar
 
Jan Möbius committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469


  /** @} */

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

    /// select given vertices
    void selectVertices( int objectId , idList _vertexList );

    /// unselect given vertices
    void unselectVertices( int objectId , idList _vertexList );

    /// 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
    idList getVertexSelection( int objectId );

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

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

    /// Set vertices to be part of the handle area
    void selectHandleVertices( int objectId , idList _vertexList );

    /// Remove vertices from handle area
    void unselectHandleVertices( int objectId , idList _vertexList );

    /// 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
    idList getHandleVertices( int objectId );

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

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

    /// Set vertices to be part of the modeling area
    void selectModelingVertices( int objectId , idList _vertexList );

    /// Remove vertices from modeling area
    void unselectModelingVertices( int objectId , idList _vertexList );

    /// 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
    idList getModelingVertices( int objectId );

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

    /// Select given Edges
    void selectEdges( int objectId , idList _vertexList );

    /// Unselect given Edges
    void unselectEdges( int objectId , idList _vertexList );

    /// 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
    idList getEdgeSelection( int objectId );

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

    /// Select given faces
    void selectFaces( int objectId , idList _facesList );

    /// Unselect given faces
    void unselectFaces( int objectId , idList _facesList );

    /// 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
    idList getFaceSelection( int objectId );

470
471
472
473
474
475
476
477
478
479
    /// save Selections into File
    void saveSelections();

    /// save Selection of one object
    void saveSelection( int _objectId  , QString _filename);
    void saveSelection( TriMesh&  _mesh, QString _filename);
    void saveSelection( PolyMesh& _mesh, QString _filename);



Jan Möbius's avatar
 
Jan Möbius committed
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
  /** @} */

  //===========================================================================
  /** @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
495
496
497
    /// Line Node
    ACG::SceneGraph::LineNode* line_node_;

Jan Möbius's avatar
 
Jan Möbius committed
498
499
500
501
502
503
504
505
506
    /// 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
507
508
    /// vector containing all projected lasso points
    std::vector< ACG::Vec3f > lasso_points_;
Jan Möbius's avatar
 
Jan Möbius committed
509

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
510
511
    /// vector containing all lasso points
    QPolygon lasso_2Dpoints_;
Jan Möbius's avatar
 
Jan Möbius committed
512

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
513
514
    /// true if currently selecting with lasso
    bool lasso_selection_;
Jan Möbius's avatar
 
Jan Möbius committed
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600

  /** @} */


  //===========================================================================
  /** @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);

  /** @} */

  //===========================================================================
  /** @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 );

  /** @} */

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

};

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/// Traverse the scenegraph and call the selection function for mesh nodes
class SelectVolumeAction
{
public:

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

  bool operator()(BaseNode* _node, ACG::GLState& _state);

private:

  QRegion         *region_;
  SelectionPlugin *plugin_;
};


Jan Möbius's avatar
 
Jan Möbius committed
618
619
620
621
622
623
624
625
626
627
628
629
630
//=============================================================================
#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
//=============================================================================