SelectionPlugin.cc 61.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




#include <QtGui>

#include "SelectionPlugin.hh"

#include <iostream>
51
#include <fstream>
Jan Möbius's avatar
 
Jan Möbius committed
52
53
54
55
56
57
58
59
#include <ACG/GL/GLState.hh>

#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/MeshNodeT.hh>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include "OpenFlipper/INIFile/INIFile.hh"
60
61
#include <OpenFlipper/common/Types.hh>

Jan Möbius's avatar
 
Jan Möbius committed
62
63
64
65
66
67
68
69
70
71
72
73
#include <QFileDialog>

/** \brief Default Constructor
 */
SelectionPlugin::SelectionPlugin() :
  waitingForPolyLineSelection_(false),
  polyLineID_(-1)
{
  selectionType_ = VERTEX;

  sourceSelection_ = false;
  deselection_ = false;
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
74
  lasso_selection_ = false;
Jan Möbius's avatar
 
Jan Möbius committed
75
76
77
78
79
80
81
82
83
84
85
86
87
}

/*******************************************************************************
        BaseInterface implementation
 *******************************************************************************/


/** \brief Initialization of the plugin when it is loaded by the core
 */
void SelectionPlugin::initializePlugin() {

  if ( OpenFlipper::Options::nogui() )
    return;
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  
  tool_ = new selectionToolbarWidget();
  QSize size(300, 300);
  tool_->resize(size);
  
  //Selection Mode
  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
  
  tool_->objectSelection->setIcon( QIcon(iconPath + "selection_object.png") );
  tool_->vertexSelection->setIcon( QIcon(iconPath + "selection_vertex.png") );
  tool_->edgeSelection->setIcon( QIcon(iconPath + "selection_edge.png") );
  tool_->faceSelection->setIcon( QIcon(iconPath + "selection_face.png") );
  
  // Set combo box entries for the different modes
  tool_->convertFrom->addItem(tr("Modeling Area"));
  tool_->convertFrom->addItem(tr("Handle Area"));
  tool_->convertFrom->addItem(tr("Feature Area"));
  
  tool_->convertTo->addItem(tr("Modeling Area"));
  tool_->convertTo->addItem(tr("Handle Area"));
  tool_->convertTo->addItem(tr("Feature Area"));
  
  // Set combo box entries for the different selection types
  tool_->convertFrom->addItem(tr("Vertex Selection"));
  tool_->convertFrom->addItem(tr("Edge Selection"));
  tool_->convertFrom->addItem(tr("Face Selection"));
  
  tool_->convertTo->addItem(tr("Vertex Selection"));
  tool_->convertTo->addItem(tr("Edge Selection"));
  tool_->convertTo->addItem(tr("Face Selection"));
  
  // Check checkboxes by default
  tool_->checkAddArea->setChecked(true);
  tool_->checkConvert->setChecked(true);
  tool_->checkSelectionConvert->setChecked(true);
  
  // Convert button
  connect(tool_->convertButton, SIGNAL(clicked()), this, SLOT(slotConvertSelectionType()));
  
  connect (tool_->restrictOnTargets, SIGNAL(clicked()), this, SLOT(slotToggleSelectionRestriction()) );
  
  //Selection Buttons
  connect( tool_->selectAll,       SIGNAL(clicked()), this,SLOT(slotSelectAll()) );
  connect( tool_->clearSelection,  SIGNAL(clicked()), this,SLOT(slotClearSelection()) );
  
  connect( tool_->growSelection,   SIGNAL(clicked()), this,SLOT(slotGrowSelection()) );
  connect( tool_->shrinkSelection, SIGNAL(clicked()), this,SLOT(slotShrinkSelection()) );
  
  connect( tool_->invertSelection, SIGNAL(clicked()), this,SLOT(slotInvertSelection()) );
  connect( tool_->selectBoundary,  SIGNAL(clicked()), this,SLOT(slotSelectBoundary()) );
  
  connect( tool_->deleteSelection,  SIGNAL(clicked()), this,SLOT(slotDeleteSelection()) );
  
  connect( tool_->colorizeSelection,SIGNAL(clicked()), this,SLOT(slotColorizeSelection()) );
  
  connect( tool_->loadSelection, SIGNAL(clicked()), this,SLOT(slotLoadSelection()) );
  connect( tool_->saveSelection, SIGNAL(clicked()), this,SLOT(slotSaveSelection()) );
  
  // Clear Properties and Selections
  connect( tool_->clearModelingArea, SIGNAL(clicked()), this,SLOT(slotClearArea()) );
  connect( tool_->clearHandleRegion, SIGNAL(clicked()), this,SLOT(slotClearHandle()));
  connect( tool_->clearFeatures,     SIGNAL(clicked()), this,SLOT(slotClearFeatures()));
  
  connect( tool_->clearVertexSelection, SIGNAL(clicked()), this,SLOT(slotClearAllVertexSelections()) );
  connect( tool_->clearEdgeSelection, SIGNAL(clicked()), this,SLOT(slotClearAllEdgeSelections()));
  connect( tool_->clearFaceSelection, SIGNAL(clicked()), this,SLOT(slotClearAllFaceSelections()));
  
  emit addToolbox("Selections",tool_);
Jan Möbius's avatar
 
Jan Möbius committed
156
157

  // create sphere for paint sphere selection
Jan Möbius's avatar
Jan Möbius committed
158
159
  sphere_mat_node_  = new ACG::SceneGraph::MaterialNode(0, tr("Selection Plugin: Selection Sphere Material").toStdString());
  PluginFunctions::addGlobalNode(sphere_mat_node_);
Jan Möbius's avatar
 
Jan Möbius committed
160
161
162
163
164
165
166
167
168
  sphere_mat_node_->applyProperties( MaterialNode::Blending  |
                                     MaterialNode::Material  |
                                     MaterialNode::AlphaTest |
                                     MaterialNode::BackFaceCulling );
  sphere_mat_node_->set_color(ACG::Vec4f(1.0, 0.0, 0.0, 0.3));
  sphere_mat_node_->enable_blending();
  sphere_mat_node_->disable_alpha_test();
  sphere_mat_node_->enable_backface_culling();

Jan Möbius's avatar
Jan Möbius committed
169
  sphere_node_ = new ACG::SceneGraph::GlutPrimitiveNode(ACG::SceneGraph::GlutPrimitiveNode::SPHERE, sphere_mat_node_, tr("Selection Plugin: Selection Sphere").toStdString());
Jan Möbius's avatar
 
Jan Möbius committed
170
171
172
173
174
175
176
  sphere_node_->drawMode(ACG::SceneGraph::DrawModes::SOLID_SMOOTH_SHADED);
  sphere_node_->hide();

  sphere_radius_ = 0.1 * PluginFunctions::sceneRadius();

  sphere_selection_ = false;

Jan Möbius's avatar
Jan Möbius committed
177
178
  line_node_ = new ACG::SceneGraph::LineNode (ACG::SceneGraph::LineNode::PolygonMode,0, tr("Selection Plugin: Lasso Selection Line").toStdString());
  PluginFunctions::addGlobalNode(line_node_);                                              
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
179
  line_node_->set_line_width (2.0);
180
181
  line_node_->depthFunc (GL_ALWAYS);
  line_node_->setTraverseMode (BaseNode::NodeFirst | BaseNode::SecondPass);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
182
  line_node_->hide();
Jan Möbius's avatar
 
Jan Möbius committed
183
184

  //register keys for the plugin
Dirk Wilden's avatar
Dirk Wilden committed
185
186
187
  emit registerKey(Qt::Key_C,      Qt::NoModifier, tr("Clear Selection"));
  emit registerKey(Qt::Key_I,      Qt::NoModifier, tr("Invert Selection"));
  emit registerKey(Qt::Key_Delete, Qt::NoModifier, tr("Delete Selection"));
Jan Möbius's avatar
 
Jan Möbius committed
188
189

  //the release event does not contain the modifier
Dirk Wilden's avatar
Dirk Wilden committed
190
191
  emit registerKey(Qt::Key_Control, Qt::NoModifier, tr("Deselect instead of Select"), true);
  emit registerKey(Qt::Key_Shift,   Qt::NoModifier,   tr("Switch between source/target Selection"), true);
Jan Möbius's avatar
 
Jan Möbius committed
192
  //the press event contains the modifier
Dirk Wilden's avatar
Dirk Wilden committed
193
194
  emit registerKey(Qt::Key_Control, Qt::ControlModifier, tr("Deselect instead of Select"), true);
  emit registerKey(Qt::Key_Shift,   Qt::ShiftModifier,   tr("Switch between source/target Selection"), true);
Jan Möbius's avatar
 
Jan Möbius committed
195
196

  //different combinations of keyPresses
Dirk Wilden's avatar
Dirk Wilden committed
197
198
  emit registerKey(Qt::Key_Shift,   Qt::ShiftModifier | Qt::ControlModifier, tr("Source Deselection"), true);
  emit registerKey(Qt::Key_Control, Qt::ShiftModifier | Qt::ControlModifier, tr("Source Deselection"), true);
199
200

  //register keys for the plugin
Dirk Wilden's avatar
Dirk Wilden committed
201
  emit registerKey(Qt::Key_F8,      Qt::NoModifier, tr("Save Selections"));
Jan Möbius's avatar
 
Jan Möbius committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
}

//***********************************************************************************


/** \brief Second initialization step after all plugins were loaded by the core
 */
void SelectionPlugin::pluginsInitialized() {

  if ( OpenFlipper::Options::nogui() )
    return;

  // PICKMODES
  emit addHiddenPickMode(TOGGLE_SELECTION);
  emit addHiddenPickMode(PAINT_SPHERE_SELECTION);
  emit addHiddenPickMode(CLOSEST_BOUNDARY_SELECTION);
  emit addHiddenPickMode(LASSO_SELECTION);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
219
  emit addHiddenPickMode(VOLUME_LASSO_SELECTION);
Jan Möbius's avatar
 
Jan Möbius committed
220
221
  emit addHiddenPickMode(SURFACE_LASSO_SELECTION);
  emit addHiddenPickMode(CONNECTED_COMPONENT_SELECTION);
Dirk Wilden's avatar
Dirk Wilden committed
222
  emit addHiddenPickMode(FLOOD_FILL_SELECTION);
223
224
  
  emit addPickMode(CREATEMESH);
Jan Möbius's avatar
 
Jan Möbius committed
225
226

  emit setPickModeMouseTracking(PAINT_SPHERE_SELECTION, true);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
227
  emit setPickModeMouseTracking(LASSO_SELECTION, true);
Jan Möbius's avatar
 
Jan Möbius committed
228
229
230
  emit setPickModeCursor(SURFACE_LASSO_SELECTION, Qt::CrossCursor);

  // CONTEXT MENU
Dirk Wilden's avatar
Dirk Wilden committed
231
  contextMenu_ = new QMenu(tr("Select"));
Jan Möbius's avatar
 
Jan Möbius committed
232
233
234

  QAction* lastAction;

Dirk Wilden's avatar
Dirk Wilden committed
235
236
  lastAction = contextMenu_->addAction( tr("All") );
  lastAction->setToolTip(tr("Select all"));
Jan Möbius's avatar
 
Jan Möbius committed
237
238
  lastAction->setStatusTip( lastAction->toolTip() );

Dirk Wilden's avatar
Dirk Wilden committed
239
240
  lastAction = contextMenu_->addAction( tr("Clear") );
  lastAction->setToolTip(tr("Clear selection"));
Jan Möbius's avatar
 
Jan Möbius committed
241
242
  lastAction->setStatusTip( lastAction->toolTip() );

Dirk Wilden's avatar
Dirk Wilden committed
243
244
  lastAction = contextMenu_->addAction( tr("Invert") );
  lastAction->setToolTip(tr("Invert selection"));
Jan Möbius's avatar
 
Jan Möbius committed
245
246
  lastAction->setStatusTip( lastAction->toolTip() );

Dirk Wilden's avatar
Dirk Wilden committed
247
248
  lastAction = contextMenu_->addAction( tr("Shrink") );
  lastAction->setToolTip(tr("Deselect the boundary of the current selection"));
Jan Möbius's avatar
 
Jan Möbius committed
249
250
  lastAction->setStatusTip( lastAction->toolTip() );

Dirk Wilden's avatar
Dirk Wilden committed
251
252
  lastAction = contextMenu_->addAction( tr("Grow") );
  lastAction->setToolTip(tr("Extend the selection at their boundary"));
Jan Möbius's avatar
 
Jan Möbius committed
253
254
  lastAction->setStatusTip( lastAction->toolTip() );

Dirk Wilden's avatar
Dirk Wilden committed
255
256
  lastAction = contextMenu_->addAction( tr("Boundary") );
  lastAction->setToolTip(tr("Select the boundary of the object"));
Jan Möbius's avatar
 
Jan Möbius committed
257
258
  lastAction->setStatusTip( lastAction->toolTip() );

Dirk Wilden's avatar
Dirk Wilden committed
259
260
261
  lastAction = contextMenu_->addAction( "Colorize" );
  lastAction->setToolTip("Change the color of selected elements.");
  lastAction->setStatusTip( lastAction->toolTip() );
Jan Möbius's avatar
 
Jan Möbius committed
262

Jan Möbius's avatar
   
Jan Möbius committed
263
264
  emit addContextMenuItem(contextMenu_->menuAction() , DATA_TRIANGLE_MESH , CONTEXTOBJECTMENU );
  emit addContextMenuItem(contextMenu_->menuAction() , DATA_POLY_MESH     , CONTEXTOBJECTMENU );
Henrik Zimmer's avatar
Henrik Zimmer committed
265
266
267
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  emit addContextMenuItem(contextMenu_->menuAction() , DATA_TSPLINE_MESH  , CONTEXTOBJECTMENU );
#endif
268
#ifdef ENABLE_POLYLINE_SUPPORT
Jan Möbius's avatar
   
Jan Möbius committed
269
  emit addContextMenuItem(contextMenu_->menuAction() , DATA_POLY_LINE     , CONTEXTOBJECTMENU );
270
#endif
271
  emit addContextMenuItem(contextMenu_->menuAction() , typeId("BSplineCurve") , CONTEXTOBJECTMENU );
Jan Möbius's avatar
 
Jan Möbius committed
272
273
274
275
276

  connect( contextMenu_ , SIGNAL( triggered(QAction*) ),
           this,          SLOT(selectionContextMenu(QAction*)) );


277

Jan Möbius's avatar
 
Jan Möbius committed
278
  // TOOLBAR
Dirk Wilden's avatar
Dirk Wilden committed
279
  toolBar_ = new QToolBar(tr("Selection"));
Jan Möbius's avatar
 
Jan Möbius committed
280
281
282
283
284
285
286
287
288
  emit addToolbar(toolBar_);

  // TOOLBAR - SELECTION TYPES
  toolBarActions_ = new QActionGroup(toolBar_);
  toolBarTypes_ = new QActionGroup(toolBar_);
  toolBarTypes_->setExclusive( true );

  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();

Dirk Wilden's avatar
Dirk Wilden committed
289
  objectAction_ = new QAction( QIcon(iconPath + "selection_object.png"), tr("Enable Object Selection"), toolBarTypes_ );
Jan Möbius's avatar
 
Jan Möbius committed
290
291
292
  objectAction_->setCheckable( true );
  objectAction_->setChecked( false );
  toolBar_->addAction( objectAction_ );
Dirk Wilden's avatar
Dirk Wilden committed
293
  vertexAction_ = new QAction( QIcon(iconPath + "selection_vertex.png"), tr("Enable Vertex Selection"), toolBarTypes_ );
Jan Möbius's avatar
 
Jan Möbius committed
294
295
296
  vertexAction_->setCheckable( true );
  vertexAction_->setChecked( true );
  toolBar_->addAction( vertexAction_ );
Dirk Wilden's avatar
Dirk Wilden committed
297
  edgeAction_ = new QAction( QIcon(iconPath + "selection_edge.png"), tr("Enable Edge Selection"), toolBarTypes_ );
Jan Möbius's avatar
 
Jan Möbius committed
298
299
  edgeAction_->setCheckable( true );
  toolBar_->addAction( edgeAction_ );
Dirk Wilden's avatar
Dirk Wilden committed
300
  faceAction_ = new QAction( QIcon(iconPath + "selection_face.png"), tr("Enable Face Selection"), toolBarTypes_ );
Jan Möbius's avatar
 
Jan Möbius committed
301
302
303
304
305
  faceAction_->setCheckable( true );
  toolBar_->addAction( faceAction_ );
  toolBar_->addSeparator();

  // TOOLBAR - SELECTION ACTIONS
Dirk Wilden's avatar
Dirk Wilden committed
306
  toggleAction_ = new QAction( QIcon(iconPath + "selection_toggle.png"),
Dirk Wilden's avatar
Dirk Wilden committed
307
                              tr("<B>Toggle Selection</B><br>Select or deselect clicked elements."), toolBarActions_ );
Jan Möbius's avatar
 
Jan Möbius committed
308
309
  toggleAction_->setCheckable( true );
  toolBar_->addAction( toggleAction_ );
Dirk Wilden's avatar
Dirk Wilden committed
310
  lassoAction_ = new QAction( QIcon(iconPath + "selection_lasso.png"),
Dirk Wilden's avatar
Dirk Wilden committed
311
                              tr("<B>Lasso Selection</B><br>Draw a Lasso to select elements on the surface."), toolBarActions_ );
Jan Möbius's avatar
 
Jan Möbius committed
312
313
  lassoAction_->setCheckable( true );
  toolBar_->addAction( lassoAction_ );
Dirk Wilden's avatar
Dirk Wilden committed
314
  volumeLassoAction_ = new QAction( QIcon(iconPath + "selection_lasso2.png"),
Dirk Wilden's avatar
Dirk Wilden committed
315
                              tr("<B>Volume Lasso Selection</B><br>Draw a Lasso to select elements in the drawn volume."), toolBarActions_ );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
316
317
  volumeLassoAction_->setCheckable( true );
  toolBar_->addAction( volumeLassoAction_ );
Dirk Wilden's avatar
Dirk Wilden committed
318
  paintSphereAction_ = new QAction( QIcon(iconPath + "selection_paintSphere.png"),
Dirk Wilden's avatar
Dirk Wilden committed
319
                              tr("<B>Sphere Selection</B><br>Select elements by painting with a sphere."), toolBarActions_ );
Jan Möbius's avatar
 
Jan Möbius committed
320
321
  paintSphereAction_->setCheckable( true );
  toolBar_->addAction( paintSphereAction_ );
322
  boundaryAction_ = new QAction( QIcon(iconPath + "selection_boundary.png"),
Dirk Wilden's avatar
Dirk Wilden committed
323
                              tr("<B>Closest Boundary</B><br>Select the closest boundary to a clicked point."), toolBarActions_ );
Jan Möbius's avatar
 
Jan Möbius committed
324
325
326
  boundaryAction_->setCheckable( true );
  toolBar_->addAction( boundaryAction_ );
  #ifdef ENABLE_POLYLINE_SUPPORT
Dirk Wilden's avatar
Dirk Wilden committed
327
  surfaceLassoAction_ = new QAction( QIcon(iconPath + "surface-lasso.png"),
Dirk Wilden's avatar
Dirk Wilden committed
328
                              tr("<B>Surface Lasso</B><br>Draw a Lasso on the surface."), toolBarActions_ );
Jan Möbius's avatar
 
Jan Möbius committed
329
330
331
  surfaceLassoAction_->setCheckable( true );
  toolBar_->addAction( surfaceLassoAction_ );
  #endif
Dirk Wilden's avatar
Dirk Wilden committed
332
  connectedAction_ = new QAction( QIcon(iconPath + "selection_connected.png"),
Dirk Wilden's avatar
Dirk Wilden committed
333
                               tr("<B>Connected Component</B><br>Select the connect component to a clicked element."), toolBarActions_ );
Jan Möbius's avatar
 
Jan Möbius committed
334
  connectedAction_->setCheckable( true );
Dirk Wilden's avatar
Dirk Wilden committed
335

Jan Möbius's avatar
 
Jan Möbius committed
336
  toolBar_->addAction( connectedAction_ );
Dirk Wilden's avatar
Dirk Wilden committed
337
338
339
340
  floodFillAction_ = new QAction( QIcon(iconPath + "selection_floodFill.png"),
                               tr("<B>Flood Fill</B><br>Select a planar region surrounding the clicked element."), toolBarActions_ );
  floodFillAction_->setCheckable( true );
  toolBar_->addAction( floodFillAction_ );
341
342
343
344
345
346
347
348
349
350
  
  //createMeshFromSelection
  createMeshFromSelAction_ = new QAction(tr("&Create Mesh from selection"), toolBarActions_);
  createMeshFromSelAction_->setCheckable( true );
  createMeshFromSelAction_->setStatusTip(tr("Create a mesh from the current selection of a target object"));
  createMeshFromSelAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scissor_createMeshSelection.png") );
  
  connect(createMeshFromSelAction_, SIGNAL(triggered()), this, SLOT(slotCreateMeshFromSelection()) );
  
  toolBar_->addAction( createMeshFromSelAction_ );
Jan Möbius's avatar
 
Jan Möbius committed
351
352

  connect( toolBarActions_, SIGNAL( triggered(QAction*) ), this, SLOT(toolBarActionClicked(QAction*)) );
Dirk Wilden's avatar
Dirk Wilden committed
353
  connect( toolBarTypes_,   SIGNAL( triggered(QAction*) ), this, SLOT(toolBarActionClicked(QAction*)) );
Dirk Wilden's avatar
Dirk Wilden committed
354
355
356


  //connect the toolbar Actions to the Toolbox Buttons
Dirk Wilden's avatar
Dirk Wilden committed
357
358
359
360
  connect( tool_->objectSelection, SIGNAL(clicked()), objectAction_, SLOT(trigger()) );
  connect( tool_->vertexSelection, SIGNAL(clicked()), vertexAction_, SLOT(trigger()) );
  connect( tool_->edgeSelection,   SIGNAL(clicked()), edgeAction_,   SLOT(trigger()) );
  connect( tool_->faceSelection,   SIGNAL(clicked()), faceAction_,   SLOT(trigger()) );
Dirk Wilden's avatar
Dirk Wilden committed
361
362
363
364
365
366

  connect( objectAction_, SIGNAL(toggled(bool)),tool_->objectSelection , SLOT(setChecked(bool)) );
  connect( vertexAction_, SIGNAL(toggled(bool)),tool_->vertexSelection , SLOT(setChecked(bool)) );
  connect( edgeAction_,   SIGNAL(toggled(bool)),tool_->edgeSelection ,   SLOT(setChecked(bool)) );
  connect( faceAction_,   SIGNAL(toggled(bool)),tool_->faceSelection ,   SLOT(setChecked(bool)) );

Jan Möbius's avatar
 
Jan Möbius committed
367
368
369
370
371
372
373
374
375
376
377
}

//***********************************************************************************

/** \brief Slot for receiving updates about changed objects
 *
 * this slot is needed for the surface selection, because the polyline for the selection is drawn
 * by the PolyLine Plugin and this function keeps track if drawing is completed.
 *
 * @param _id object-id of changed object
 */
Mike Kremer's avatar
Mike Kremer committed
378
void SelectionPlugin::slotObjectUpdated(int _id){
Jan Möbius's avatar
 
Jan Möbius committed
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#ifdef ENABLE_POLYLINE_SUPPORT

  if (waitingForPolyLineSelection_){

    //is object a polyLine?
    BaseObjectData *obj;
    PluginFunctions::getObject(_id, obj);
    // get polyline object
    PolyLineObject* pline  = PluginFunctions::polyLineObject(obj);
    if (pline){
      if (polyLineID_ == -1){
        polyLineID_ = _id;
      }else if (polyLineID_ != _id){
        //the user added a second polyline so delete the first
393
        emit deleteObject(polyLineID_);
Jan Möbius's avatar
 
Jan Möbius committed
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
        polyLineID_ = _id;
      }
      if (pline->line()->is_closed()){
        PluginFunctions::pickMode(SURFACE_LASSO_SELECTION);
        waitingForPolyLineSelection_ = false;
      }
    }
  }
#endif
}


/*******************************************************************************
        KeyInterface implementation
 *******************************************************************************/

/** \brief Handle key press events for registered keys
 *
 * @param _event the key event that occurred
 */
void SelectionPlugin::slotKeyEvent( QKeyEvent* _event ) {
  //check if we want to select or deselect
  if ( (_event->modifiers() & Qt::ControlModifier) || (_event->key() == Qt::Key_Control) )
    deselection_ = true;
  else
    deselection_ = false;

  //check if we want to select source or target
  if ( (_event->modifiers() & Qt::ShiftModifier) || (_event->key() == Qt::Key_Shift) )
    sourceSelection_ = true;
  else
    sourceSelection_ = false;

  //handle remaining keys
  switch (_event->key())
  {
    case Qt::Key_C :
        slotClearSelection();
        return;
        break;
    case Qt::Key_I :
        slotInvertSelection();
        return;
        break;
    case Qt::Key_Delete :
        slotDeleteSelection();
440
441
        return;
        break;
442
443
    case Qt::Key_F8 :
        saveSelections();
444
445
        return;
        break;
Jan Möbius's avatar
 
Jan Möbius committed
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
    default:
    break;
  }

}

//******************************************************************************

/** \brief Handle key release events for registered keys
 *
 * @param _event the key event that occurred
 */
void SelectionPlugin::slotKeyReleaseEvent( QKeyEvent* _event ) {

  //check if we want to select or deselect
  if ( (_event->modifiers() & Qt::ControlModifier) || (_event->key() == Qt::Key_Control) )
    deselection_ = false;

  //check if we want to select source or target
  if ( (_event->modifiers() & Qt::ShiftModifier) || (_event->key() == Qt::Key_Shift) )
    sourceSelection_ = false;
}


/*******************************************************************************
        MouseInterface implementation
 *******************************************************************************/

/** \brief Handle mouse events
 *
 * maps to a selection-function dependent on current pickMode
 *
 * @param _event the mouse event that occurred
 */
void SelectionPlugin::slotMouseEvent( QMouseEvent* _event ) {

  if ( PluginFunctions::pickMode() == TOGGLE_SELECTION)              toggleSelection(_event);       else
  if ( PluginFunctions::pickMode() == PAINT_SPHERE_SELECTION)        paintSphereSelection(_event);  else
  if ( PluginFunctions::pickMode() == CLOSEST_BOUNDARY_SELECTION)    closestBoundarySelection(_event); else
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
485
486
  if ( PluginFunctions::pickMode() == LASSO_SELECTION)               handleLassoSelection(_event, false); else
  if ( PluginFunctions::pickMode() == VOLUME_LASSO_SELECTION)        handleLassoSelection(_event, true); else
Dirk Wilden's avatar
Dirk Wilden committed
487
  if ( PluginFunctions::pickMode() == CONNECTED_COMPONENT_SELECTION) componentSelection(_event); else
488
489
  if ( PluginFunctions::pickMode() == FLOOD_FILL_SELECTION)          floodFillSelection(_event); else
  if ( PluginFunctions::pickMode() == CREATEMESH )                   createMeshFromSelection( _event );
Jan Möbius's avatar
 
Jan Möbius committed
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
#ifdef ENABLE_POLYLINE_SUPPORT
  else
  if ( PluginFunctions::pickMode() == SURFACE_LASSO_SELECTION)       surfaceLassoSelection(_event);
#endif

}

//******************************************************************************

/** \brief adjust the Sphere radius for PaintSphereSelection
 *
 * @param _event the mouse wheel event that occurred
 * @param  unused
 */
void SelectionPlugin::slotMouseWheelEvent(QWheelEvent * _event, const std::string & /*_mode*/) {
   if ( PluginFunctions::pickMode() == PAINT_SPHERE_SELECTION  ) {
      float d = -(float)_event->delta() / 120.0 * 0.1;
      sphere_radius_ *= 1.0 + d;

      sphere_node_->set_size(sphere_radius_);
      sphere_node_->show();
      emit updateView();
   }
}


/*******************************************************************************
        PickingInterface implementation
 *******************************************************************************/

/** \brief Update selection states when the PickMode changes
 *
 * @param _mode the new PickMode
 */
void SelectionPlugin::slotPickModeChanged( const std::string& _mode) {

  toggleAction_->setChecked(      _mode == TOGGLE_SELECTION );
  paintSphereAction_->setChecked( _mode == PAINT_SPHERE_SELECTION );
  boundaryAction_->setChecked(    _mode == CLOSEST_BOUNDARY_SELECTION );
  lassoAction_->setChecked(       _mode == LASSO_SELECTION );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
530
  volumeLassoAction_->setChecked( _mode == VOLUME_LASSO_SELECTION );
Jan Möbius's avatar
 
Jan Möbius committed
531
  connectedAction_->setChecked(   _mode == CONNECTED_COMPONENT_SELECTION );
Dirk Wilden's avatar
Dirk Wilden committed
532
  floodFillAction_->setChecked(   _mode == FLOOD_FILL_SELECTION );
533
  createMeshFromSelAction_->setChecked(_mode == CREATEMESH );
Jan Möbius's avatar
 
Jan Möbius committed
534
535
536
537
538
539

   if ( _mode != PAINT_SPHERE_SELECTION && sphere_node_->visible() ){
      sphere_node_->hide();
      emit updateView();
   }

Dirk Wilden's avatar
Dirk Wilden committed
540
541
542
543
544
545
   if ( _mode == PAINT_SPHERE_SELECTION && sphere_radius_ == 0.1f){
      //init the sphere radius once
      sphere_radius_ = 0.05 * PluginFunctions::sceneRadius();
   }


Jan Möbius's avatar
 
Jan Möbius committed
546
547
548
549
550
551
552
#ifdef ENABLE_POLYLINE_SUPPORT
  bool check = (_mode == SURFACE_LASSO_SELECTION) || (_mode == "PolyLine" && waitingForPolyLineSelection_);
  surfaceLassoAction_->setChecked(check);

   if (waitingForPolyLineSelection_)
     if (_mode != "" && _mode != "PolyLine" && _mode != SURFACE_LASSO_SELECTION ){
      waitingForPolyLineSelection_ = false;
553
      emit deleteObject(polyLineID_);
Jan Möbius's avatar
 
Jan Möbius committed
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
      polyLineID_ = -1;
    }
#endif
}


/*******************************************************************************
        SelectionPlugin implementation
 *******************************************************************************/

/** \brief called when an action in the selection toolbar was clicked
 *
 * @param _action the action that was clicked
 */
void SelectionPlugin::toolBarActionClicked(QAction * _action)
{
Dirk Wilden's avatar
Dirk Wilden committed
570

Jan Möbius's avatar
 
Jan Möbius committed
571
572
573
574
575
576
577
578
579
580
  //Selction Types
  if ( _action->text() == "Enable Object Selection" ||
       _action->text() == "Enable Vertex Selection" ||
       _action->text() == "Enable Edge Selection" ||
       _action->text() == "Enable Face Selection"){

    unsigned char type = 0;
    if ( objectAction_->isChecked() ){
      type = type | OBJECT;

Dirk Wilden's avatar
Dirk Wilden committed
581
    if ( PluginFunctions::actionMode() == Viewer::ExamineMode )
Jan Möbius's avatar
 
Jan Möbius committed
582
583
584
585
586
587
588
589
590
591
592
593
594
595
      toolBarActionClicked( toggleAction_ ); //automatically switch to toggle

    }if ( vertexAction_->isChecked() )
      type = type | VERTEX;
    if ( edgeAction_->isChecked() )
      type = type | EDGE;
    if ( faceAction_->isChecked() )
      type = type | FACE;

    selectionType_ = type;

    //for object selection only toggle and lasso are available
    paintSphereAction_->setEnabled( !objectAction_->isChecked() );
    boundaryAction_->setEnabled( !objectAction_->isChecked() );
596
#ifdef ENABLE_POLYLINE_SUPPORT
Jan Möbius's avatar
 
Jan Möbius committed
597
    surfaceLassoAction_->setEnabled( !objectAction_->isChecked() );
598
#endif
Jan Möbius's avatar
 
Jan Möbius committed
599
600
601
    connectedAction_->setEnabled( !objectAction_->isChecked() );

  }else{
Dirk Wilden's avatar
Dirk Wilden committed
602

Jan Möbius's avatar
 
Jan Möbius committed
603
604
    //first check if a selection type was set
    if (selectionType_ == 0){
Dirk Wilden's avatar
Dirk Wilden committed
605
      emit log(LOGERR,tr("Choose at least one selection type first."));
Jan Möbius's avatar
 
Jan Möbius committed
606
607
608
609
610
611
      _action->setChecked(false);
      return;
    }
    //Selction Modes
    PluginFunctions::actionMode( Viewer::PickingMode );

Dirk Wilden's avatar
Dirk Wilden committed
612
    if (_action == toggleAction_)
Jan Möbius's avatar
 
Jan Möbius committed
613
      PluginFunctions::pickMode( TOGGLE_SELECTION );
Dirk Wilden's avatar
Dirk Wilden committed
614
    else if (_action == paintSphereAction_)
Jan Möbius's avatar
 
Jan Möbius committed
615
      PluginFunctions::pickMode( PAINT_SPHERE_SELECTION );
Dirk Wilden's avatar
Dirk Wilden committed
616
    else if (_action == boundaryAction_)
Jan Möbius's avatar
 
Jan Möbius committed
617
      PluginFunctions::pickMode( CLOSEST_BOUNDARY_SELECTION );
Dirk Wilden's avatar
Dirk Wilden committed
618
    else if (_action == lassoAction_)
Jan Möbius's avatar
 
Jan Möbius committed
619
      PluginFunctions::pickMode( LASSO_SELECTION );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
620
621
    else if (_action == volumeLassoAction_)
      PluginFunctions::pickMode( VOLUME_LASSO_SELECTION );
Dirk Wilden's avatar
Dirk Wilden committed
622
    else if (_action == connectedAction_)
Jan Möbius's avatar
 
Jan Möbius committed
623
      PluginFunctions::pickMode( CONNECTED_COMPONENT_SELECTION );
Dirk Wilden's avatar
Dirk Wilden committed
624
625
    else if (_action == floodFillAction_)
      PluginFunctions::pickMode( FLOOD_FILL_SELECTION );
626
627
    else if (_action == createMeshFromSelAction_)
         PluginFunctions::pickMode( CREATEMESH );
Dirk Wilden's avatar
Dirk Wilden committed
628
    else if (_action == surfaceLassoAction_){
Jan Möbius's avatar
 
Jan Möbius committed
629
630
631
632
633
634
635
636
637
638
639
640
      waitingForPolyLineSelection_ = true;
      PluginFunctions::pickMode("PolyLine");
    }
  }
}

//******************************************************************************

/** \brief Use current selection to set AREA bits
 */
void SelectionPlugin::slotSetArea() {
  PluginFunctions::IteratorRestriction restriction;
Dirk Wilden's avatar
Dirk Wilden committed
641
  if ( !tool_->restrictOnTargets->isChecked() )
Jan Möbius's avatar
 
Jan Möbius committed
642
643
644
645
    restriction = PluginFunctions::ALL_OBJECTS;
  else
    restriction = PluginFunctions::TARGET_OBJECTS;

Henrik Zimmer's avatar
Henrik Zimmer committed
646
647
648
649
650
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH | DATA_TSPLINE_MESH)) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it)   {
#endif
#ifndef ENABLE_TSPLINEMESH_SUPPORT
Jan Möbius's avatar
 
Jan Möbius committed
651
652
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it)   {
Henrik Zimmer's avatar
Henrik Zimmer committed
653
654
#endif

Mike Kremer's avatar
Mike Kremer committed
655
656
657
658

		// Add selection to existing modeling area
		// if corresponding checkbox is checked
		if (tool_->checkAddArea->checkState() == Qt::Checked) {
Jan Möbius's avatar
Jan Möbius committed
659
			IdList list = getModelingVertices(o_it->id());
Mike Kremer's avatar
Mike Kremer committed
660
661
662
663
664
665
666
667
668
			selectVertices(o_it->id(), list);
		}

		if (o_it->dataType(DATA_TRIANGLE_MESH)) {
			set_area(PluginFunctions::triMesh(*o_it));
		}
		if (o_it->dataType(DATA_POLY_MESH)) {
			set_area(PluginFunctions::polyMesh(*o_it));
		}
Henrik Zimmer's avatar
Henrik Zimmer committed
669
670
671
672
673
674
#ifdef ENABLE_TSPLINEMESH_SUPPORT
		if (o_it->dataType(DATA_TSPLINE_MESH)) {
			set_area(PluginFunctions::tsplineMesh(*o_it));
		}
#endif

Mike Kremer's avatar
Mike Kremer committed
675
676
677

		o_it->update();
	}
Jan Möbius's avatar
 
Jan Möbius committed
678
679
680
681
682
683
684
685
686
687
688
689

  emit updateView();
}


//******************************************************************************


/** \brief Use current selection to set HANDLE bits
 */
void SelectionPlugin::slotSetHandle() {
  PluginFunctions::IteratorRestriction restriction;
Dirk Wilden's avatar
Dirk Wilden committed
690
  if ( !tool_->restrictOnTargets->isChecked() )
Jan Möbius's avatar
 
Jan Möbius committed
691
692
693
694
    restriction = PluginFunctions::ALL_OBJECTS;
  else
    restriction = PluginFunctions::TARGET_OBJECTS;

Henrik Zimmer's avatar
Henrik Zimmer committed
695
#ifndef ENABLE_TSPLINEMESH_SUPPORT
Jan Möbius's avatar
 
Jan Möbius committed
696
697
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it)   {
Henrik Zimmer's avatar
Henrik Zimmer committed
698
699
700
701
702
#endif
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH | DATA_TSPLINE_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it)   {
#endif
Jan Möbius's avatar
 
Jan Möbius committed
703

Mike Kremer's avatar
Mike Kremer committed
704
705
706
		// Add selection to existing handle area
		// if corresponding checkbox is checked
		if (tool_->checkAddArea->checkState() == Qt::Checked) {
Jan Möbius's avatar
Jan Möbius committed
707
			IdList list = getHandleVertices(o_it->id());
Mike Kremer's avatar
Mike Kremer committed
708
709
710
711
712
713
714
			selectVertices(o_it->id(), list);
		}

		if (o_it->dataType(DATA_TRIANGLE_MESH))
			set_handle(PluginFunctions::triMesh(*o_it));
		if (o_it->dataType(DATA_POLY_MESH))
			set_handle(PluginFunctions::polyMesh(*o_it));
Henrik Zimmer's avatar
Henrik Zimmer committed
715
716
717
718
#ifdef ENABLE_TSPLINEMESH_SUPPORT
		if (o_it->dataType(DATA_TSPLINE_MESH))
			set_handle(PluginFunctions::tsplineMesh(*o_it));
#endif
Mike Kremer's avatar
Mike Kremer committed
719
720
721
722
		o_it->update();
	}

	emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
723
724
725
726
727
728
}


//******************************************************************************


Dirk Wilden's avatar
Dirk Wilden committed
729
730
731
/** \brief convert current selection to feature
 */
void SelectionPlugin::slotSetFeatures() {
Mike Kremer's avatar
Mike Kremer committed
732
733
734
735
736
	PluginFunctions::IteratorRestriction restriction;
	if (!tool_->restrictOnTargets->isChecked())
		restriction = PluginFunctions::ALL_OBJECTS;
	else
		restriction = PluginFunctions::TARGET_OBJECTS;
Dirk Wilden's avatar
Dirk Wilden committed
737

Henrik Zimmer's avatar
Henrik Zimmer committed
738
#ifndef ENABLE_TSPLINEMESH_SUPPORT
Mike Kremer's avatar
Mike Kremer committed
739
740
	for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH)); o_it
			!= PluginFunctions::objectsEnd(); ++o_it) {
Henrik Zimmer's avatar
Henrik Zimmer committed
741
#endif
Dirk Wilden's avatar
Dirk Wilden committed
742

Henrik Zimmer's avatar
Henrik Zimmer committed
743
744
745
746
#ifdef ENABLE_TSPLINEMESH_SUPPORT
	for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_TRIANGLE_MESH | DATA_POLY_MESH | DATA_TSPLINE_MESH )); o_it
			!= PluginFunctions::objectsEnd(); ++o_it) {
#endif
Mike Kremer's avatar
Mike Kremer committed
747
748
749
750
		if (o_it->dataType(DATA_TRIANGLE_MESH))
			set_features(PluginFunctions::triMesh(*o_it));
		if (o_it->dataType(DATA_POLY_MESH))
			set_features(PluginFunctions::polyMesh(*o_it));
Henrik Zimmer's avatar
Henrik Zimmer committed
751
752
753
754
755

#ifdef ENABLE_TSPLINEMESH_SUPPORT
		if (o_it->dataType(DATA_TSPLINE_MESH))
			set_features(PluginFunctions::tsplineMesh(*o_it));
#endif
Mike Kremer's avatar
Mike Kremer committed
756
757
758
759
		o_it->update();
	}

	emit updateView();
Dirk Wilden's avatar
Dirk Wilden committed
760
761
762
763
764
}

//******************************************************************************


Jan Möbius's avatar
 
Jan Möbius committed
765
766
767
768
/** \brief Clear Handle Bits
 */
void SelectionPlugin::slotClearHandle() {
  PluginFunctions::IteratorRestriction restriction;
Dirk Wilden's avatar
Dirk Wilden committed
769
  if ( !tool_->restrictOnTargets->isChecked() )
Jan Möbius's avatar
 
Jan Möbius committed
770
771
772
773
    restriction = PluginFunctions::ALL_OBJECTS;
  else
    restriction = PluginFunctions::TARGET_OBJECTS;

Henrik Zimmer's avatar
Henrik Zimmer committed
774
#ifndef ENABLE_TSPLINEMESH_SUPPORT
Jan Möbius's avatar
 
Jan Möbius committed
775
776
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it) {
Henrik Zimmer's avatar
Henrik Zimmer committed
777
778
779
780
781
#endif
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH | DATA_TSPLINE_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it) {
#endif
Jan Möbius's avatar
 
Jan Möbius committed
782
783
784
785
    if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
        clear_handle(PluginFunctions::triMesh(*o_it));
    if ( o_it->dataType( DATA_POLY_MESH ) )
        clear_handle(PluginFunctions::polyMesh(*o_it));
Henrik Zimmer's avatar
Henrik Zimmer committed
786
787
788
789
#ifdef ENABLE_TSPLINEMESH_SUPPORT
    if ( o_it->dataType( DATA_TSPLINE_MESH ) )
        clear_handle(PluginFunctions::tsplineMesh(*o_it));
#endif
Jan Möbius's avatar
 
Jan Möbius committed
790
791
792
793
794
795
796
797
798
799
800
801
802
    o_it->update();
  }

  emit updateView();
}


//******************************************************************************

/** \brief Clear Area Bits
 */
void SelectionPlugin::slotClearArea() {
  PluginFunctions::IteratorRestriction restriction;
Dirk Wilden's avatar
Dirk Wilden committed
803
  if ( !tool_->restrictOnTargets->isChecked() )
Jan Möbius's avatar
 
Jan Möbius committed
804
805
806
807
    restriction = PluginFunctions::ALL_OBJECTS;
  else
    restriction = PluginFunctions::TARGET_OBJECTS;

Henrik Zimmer's avatar
Henrik Zimmer committed
808
#ifndef ENABLE_TSPLINEMESH_SUPPORT
Jan Möbius's avatar
 
Jan Möbius committed
809
810
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it) {
Henrik Zimmer's avatar
Henrik Zimmer committed
811
812
813
814
815
#endif
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH | DATA_TSPLINE_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it) {
#endif
Jan Möbius's avatar
 
Jan Möbius committed
816
817
818
819
    if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
        clear_area(PluginFunctions::triMesh(*o_it));
    if ( o_it->dataType( DATA_POLY_MESH ) )
        clear_area(PluginFunctions::polyMesh(*o_it));
Henrik Zimmer's avatar
Henrik Zimmer committed
820
821
822
823
#ifdef ENABLE_TSPLINEMESH_SUPPORT
    if ( o_it->dataType( DATA_TSPLINE_MESH ) )
        clear_area(PluginFunctions::tsplineMesh(*o_it));
#endif
Jan Möbius's avatar
 
Jan Möbius committed
824
825
826
827
828
829
830
    o_it->update();
  }

  emit updateView();
}


Dirk Wilden's avatar
Dirk Wilden committed
831
832
833
834
835
836
837
838
839
840
841
//******************************************************************************

/** \brief Clear Features
 */
void SelectionPlugin::slotClearFeatures() {
  PluginFunctions::IteratorRestriction restriction;
  if ( !tool_->restrictOnTargets->isChecked() )
    restriction = PluginFunctions::ALL_OBJECTS;
  else
    restriction = PluginFunctions::TARGET_OBJECTS;

Henrik Zimmer's avatar
Henrik Zimmer committed
842
#ifndef ENABLE_TSPLINEMESH_SUPPORT
Dirk Wilden's avatar
Dirk Wilden committed
843
844
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it) {
Henrik Zimmer's avatar
Henrik Zimmer committed
845
846
847
848
849
#endif
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH | DATA_TSPLINE_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it) {
#endif
Dirk Wilden's avatar
Dirk Wilden committed
850
851
852
853
    if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
        clear_features(PluginFunctions::triMesh(*o_it));
    if ( o_it->dataType( DATA_POLY_MESH ) )
        clear_features(PluginFunctions::polyMesh(*o_it));
Henrik Zimmer's avatar
Henrik Zimmer committed
854
855
856
857
#ifdef ENABLE_TSPLINEMESH_SUPPORT
    if ( o_it->dataType( DATA_TSPLINE_MESH ) )
        clear_features(PluginFunctions::tsplineMesh(*o_it));
#endif
Dirk Wilden's avatar
Dirk Wilden committed
858
859
860
861
862
863
    o_it->update();
  }

  emit updateView();
}

Jan Möbius's avatar
 
Jan Möbius committed
864
865
866
867
868
869
//******************************************************************************

/** \brief Delete all selected elements of the target meshes
 */
void SelectionPlugin::slotDeleteSelection() {
  PluginFunctions::IteratorRestriction restriction;
Dirk Wilden's avatar
Dirk Wilden committed
870
  if ( !tool_->restrictOnTargets->isChecked() )
Jan Möbius's avatar
 
Jan Möbius committed
871
872
873
874
    restriction = PluginFunctions::ALL_OBJECTS;
  else
    restriction = PluginFunctions::TARGET_OBJECTS;

Henrik Zimmer's avatar
Henrik Zimmer committed
875
#ifndef ENABLE_TSPLINEMESH_SUPPORT
Jan Möbius's avatar
 
Jan Möbius committed
876
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH )) ;
Henrik Zimmer's avatar
Henrik Zimmer committed
877
878
879
880
881
882
        o_it != PluginFunctions::objectsEnd(); ++o_it) {
#endif
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  for ( PluginFunctions::ObjectIterator o_it(restriction,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH | DATA_TSPLINE_MESH )) ;
        o_it != PluginFunctions::objectsEnd(); ++o_it) {
#endif
Jan Möbius's avatar
 
Jan Möbius committed
883
884
885
886
887
888
    if ( o_it->visible() ){
      bool changed = false;
      if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
          changed = changed || deleteSelection(PluginFunctions::triMesh(*o_it));
      if ( o_it->dataType( DATA_POLY_MESH ) )
          changed = changed || deleteSelection(PluginFunctions::polyMesh(*o_it));
Henrik Zimmer's avatar
Henrik Zimmer committed
889
890
891
892
#ifdef ENABLE_TSPLINEMESH_SUPPORT
      if ( o_it->dataType( DATA_TSPLINE_MESH ) )
          changed = changed || deleteSelection(PluginFunctions::tsplineMesh(*o_it));
#endif
Jan Möbius's avatar
 
Jan Möbius committed
893
894
895
896
897
898
899
900
      o_it->update();
      emit updatedObject(o_it->id());
    }
  }
  emit updateView();
}


Dirk Wilden's avatar
Dirk Wilden committed
901
/** \brief Toggle the selection Restriction
902
 *
Dirk Wilden's avatar
Dirk Wilden committed
903
904
905
 */
void SelectionPlugin::slotToggleSelectionRestriction(){
  if ( tool_->restrictOnTargets->isChecked() )
Dirk Wilden's avatar
Dirk Wilden committed
906
      tool_->restrictOnTargets->setText(tr("Select on target objects only"));
Dirk Wilden's avatar
Dirk Wilden committed
907
  else
Dirk Wilden's avatar
Dirk Wilden committed
908
      tool_->restrictOnTargets->setText(tr("Select on all objects"));
Dirk Wilden's avatar
Dirk Wilden committed
909
910
}

Jan Möbius's avatar
 
Jan Möbius committed
911
912
//******************************************************************************

913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
/** \brief CreateMeshFromSelection Button
*
*/
void SelectionPlugin::slotCreateMeshFromSelection( )
{
    PluginFunctions::actionMode( Viewer::PickingMode );
    PluginFunctions::pickMode( CREATEMESH );
}

//******************************************************************************

/** \brief Create Mesh from Selection (triggered by pickMode)
*
* @param _event the mouse event that occured
*/
void SelectionPlugin::createMeshFromSelection(QMouseEvent * _event)
{
    if (_event->type() == QEvent::MouseButtonPress )
    {
        unsigned int     node_idx, target_idx;
        ACG::Vec3d*      sourcePoint3D = 0;
        
        if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE,
Mike Kremer's avatar
Mike Kremer committed
936
                                            _event->pos(),
937
938
939
940
941
942
943
944
945
946
947
948
949
                                            node_idx,
                                            target_idx,
                                            sourcePoint3D))
        {
            BaseObjectData *obj;
            PluginFunctions::getPickedObject(node_idx, obj);
            createMeshFromSelection( obj->id() );
        }
    }
}

//******************************************************************************

Jan Möbius's avatar
 
Jan Möbius committed
950
951
952
953
954
955
956
957
958
/** \brief store selections of a given object to a given ini file
 *
 * @param _ini reference to the ini file
 * @param _id  id of the object
 */
void SelectionPlugin::saveIniFile( INIFile& _ini , int _id) {

   BaseObjectData* object;
   if ( !PluginFunctions::getObject(_id,object) ) {
Dirk Wilden's avatar
Dirk Wilden committed
959
     emit log(LOGERR,tr("Cannot find object for id ") + QString::number(_id) + tr(" in saveFile") );
Jan Möbius's avatar
 
Jan Möbius committed
960
961
962
963
964
965
966
967
     return;
   }

   std::vector< int > ids;

   // The objects section should already exist
   QString sectionName = object->name();
   if ( !_ini.section_exists( sectionName ) ) {
Dirk Wilden's avatar
Dirk Wilden committed
968
     emit log(LOGERR,tr("Cannot find object section id ") + QString::number(_id) + tr(" in saveFile") );
Jan Möbius's avatar
 
Jan Möbius committed
969
970
971
972
973
974
975
976
977
978
979
     return;
   }

  _ini.add_entry(sectionName , "VertexSelection" , getVertexSelection( object->id()) );
  _ini.add_entry(sectionName , "EdgeSelection"   , getEdgeSelection  ( object->id()) );

  if ( object->dataType( DATA_POLY_MESH ) || object->dataType( DATA_TRIANGLE_MESH )) {
    _ini.add_entry(sectionName , "FaceSelection"  , getFaceSelection   ( object->id() ) );
    _ini.add_entry(sectionName , "HandleRegion"   , getHandleVertices  ( object->id() ) );
    _ini.add_entry(sectionName , "ModelingRegion" , getModelingVertices( object->id() ) );
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
980
981
982
983
984
985
986
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  if ( object->dataType( DATA_TSPLINE_MESH )) {
    _ini.add_entry(sectionName , "FaceSelection"  , getFaceSelection   ( object->id() ) );
    _ini.add_entry(sectionName , "HandleRegion"   , getHandleVertices  ( object->id() ) );
    _ini.add_entry(sectionName , "ModelingRegion" , getModelingVertices( object->id() ) );
  }
#endif
Jan Möbius's avatar
 
Jan Möbius committed
987
988
989
990
991
992
993
994
995
996
997
998
999

}


//******************************************************************************

/** \brief load selections for a given object from a given ini file
 *
 * @param _ini reference to the ini file
 * @param _id  id of the object
 */
void SelectionPlugin::loadIniFile( INIFile& _ini, int _id )
{
Dirk Wilden's avatar
Dirk Wilden committed
1000