Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MeshObjectSelectionPlugin.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen *
5  * www.openflipper.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenFlipper. *
9  * *
10  * OpenFlipper is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenFlipper is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenFlipper. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 15034 $ *
38  * $Author: moebius $ *
39  * $Date: 2012-07-16 13:26:20 +0200 (Mo, 16 Jul 2012) $ *
40  * *
41 \*===========================================================================*/
42 
43 #ifndef MESHOBJECTSELECTIONPLUGIN_HH
44 #define MESHOBJECTSELECTIONPLUGIN_HH
45 
46 #include <QObject>
47 
55 #include <OpenFlipper/BasePlugin/INIInterface.hh>
58 
61 #include <OpenFlipper/INIFile/INIFile.hh>
62 
65 
66 #include "ConversionDialog.hh"
67 
70 {
71  Q_OBJECT
72  Q_INTERFACES(BaseInterface)
73  Q_INTERFACES(KeyInterface)
74  Q_INTERFACES(INIInterface)
75  Q_INTERFACES(BackupInterface)
76  Q_INTERFACES(ScriptInterface)
77  Q_INTERFACES(LoggingInterface)
78  Q_INTERFACES(LoadSaveInterface)
79  Q_INTERFACES(SelectionInterface)
80 
81 public:
84 
87 
88  friend class SelectVolumeAction;
89 
90 signals:
91 
92  // BaseInterface
93  void updateView();
94  void updatedObject(int, const UpdateType&);
95  void nodeVisibilityChanged(int _identifier);
96  void setSlotDescription(QString _slotName, QString _slotDescription,
97  QStringList _parameters, QStringList _descriptions);
98 
99  // BackupInterface
100  void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL);
101 
102  // LoggingInterface
103  void log(Logtype _type, QString _message);
104  void log(QString _message);
105 
106  // SelectionInterface
107  void addSelectionEnvironment(QString _modeName, QString _description, QIcon _icon, QString& _handleName);
108  void registerType(QString _handleName, DataType _type);
109  void addPrimitiveType(QString _handleName, QString _name, QIcon _icon, SelectionInterface::PrimitiveType& _typeHandle);
110  void addSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u);
111 
112  void showToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
113 
114  void showLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
115  void showVolumeLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
116  void showSphereSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
117  void showClosestBoundarySelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
118  void showFloodFillSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
119  void showComponentsSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
120 
121  void getActiveDataTypes(SelectionInterface::TypeList& _types);
122  void getActivePrimitiveType(SelectionInterface::PrimitiveType& _type);
123  void targetObjectsOnly(bool& _targetsOnly);
124 
125  void registerKeyShortcut(int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier);
126 
127  // LoadSaveInterface
128  void deleteObject(int _objectId);
129  void addEmptyObject( DataType _type, int& _id);
130 
131  // ScriptInterface
132  void scriptInfo(QString _functionName);
133 
134 public slots:
135 
136  // SelectionInterface
137  void loadSelection(int _objId, const QString& _filename);
138 
139 private slots:
140 
141  // INIInterface
142  void loadIniFile(INIFile& _ini, int _id);
143  void saveIniFile(INIFile& _ini, int _id);
144 
145  // BaseInterface
146  void initializePlugin();
147  void pluginsInitialized();
148  void noguiSupported() {};
149 
150  // SelectionInterface
151  void slotSelectionOperation(QString _operation);
152  void slotToggleSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
153 
154  void slotLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
155  void slotVolumeLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
156  void slotSphereSelection(QMouseEvent* _event, double _radius, SelectionInterface::PrimitiveType _currentType, bool _deselect);
157  void slotClosestBoundarySelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
158  void slotFloodFillSelection(QMouseEvent* _event, double _maxAngle, SelectionInterface::PrimitiveType _currentType, bool _deselect);
159  void slotComponentsSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
160 
161  void slotLoadSelection(const INIFile& _file);
162  void slotSaveSelection(INIFile& _file);
163 
164  void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers);
165 
166 public:
167 
168  // BaseInterface
169  QString name() {
170  return (QString(tr("Mesh Object Selection")));
171  };
172 
173  QString description() {
174  return (QString(tr("Allows to select parts of Mesh Objects")));
175  };
176 
177  //===========================================================================
180  //===========================================================================
181 private:
182 
184  void updateSlotDescriptions();
185 
187  void setColorForSelection(const int _objectId, const PrimitiveType _primitiveType);
188 
191  //===========================================================================
194  //===========================================================================
195 private slots:
196 
198  void conversionRequested();
199 
202 public slots:
203 
204  QString version() {
205  return QString("1.0");
206  };
207 
208  // Is vertex type active? (for use in plugins that need mesh selection)
209  bool vertexTypeActive() {
210  SelectionInterface::PrimitiveType t = 0u;
211  emit getActivePrimitiveType(t);
212  return (t & vertexType_) > 0;
213  }
214 
215  // Is vertex type active? (for use in plugins that need mesh selection)
216  bool edgeTypeActive() {
217  SelectionInterface::PrimitiveType t = 0u;
218  emit getActivePrimitiveType(t);
219  return (t & edgeType_) > 0;
220  }
221 
222  // Is face type active? (for use in plugins that need mesh selection)
223  bool faceTypeActive() {
224  SelectionInterface::PrimitiveType t = 0u;
225  emit getActivePrimitiveType(t);
226  return (t & faceType_) > 0;
227  }
228 
229  //===========================================================================
232  //===========================================================================
233 public slots:
234 
235  //==========================================
236  // VERTEX OPERATIONS
237  //==========================================
238 
240  void selectVertices(int objectId, IdList _vertexList);
241 
243  void unselectVertices(int objectId, IdList _vertexList);
244 
246  void selectAllVertices(int _objectId);
247 
249  void clearVertexSelection(int _objectId);
250 
252  void invertVertexSelection(int _objectId);
253 
255  void selectBoundaryVertices(int _objectId);
256 
258  void selectClosestBoundaryVertices(int _objectId, int _vertexId);
259 
261  void shrinkVertexSelection(int _objectId);
262 
264  void growVertexSelection(int _objectId);
265 
267  IdList getVertexSelection(int _objectId);
268 
270  void deleteVertexSelection(int _objectId);
271 
272  int createMeshFromVertexSelection( int _objectId);
273 
275  void colorizeVertexSelection(int _objectId, int _r, int _g, int _b, int a);
276 
277  //==========================================
278 
280  void selectHandleVertices(int objectId, IdList _vertexList);
281 
283  void unselectHandleVertices(int objectId, IdList _vertexList);
284 
286  void clearHandleVertices(int objectId);
287 
289  void setAllHandleVertices(int objectId);
290 
292  IdList getHandleVertices(int objectId);
293 
295  void loadFlipperModelingSelection(int _objectId, QString _filename);
296 
298  void saveFlipperModelingSelection(int _objectId, QString _filename);
299 
300  //==========================================
301 
303  void selectModelingVertices(int objectId, IdList _vertexList);
304 
306  void unselectModelingVertices(int objectId, IdList _vertexList);
307 
309  void selectVerticesByValue(int _objectId, QString _component, bool _greater, double _value );
310 
312  void clearModelingVertices(int objectId);
313 
315  void setAllModelingVertices(int objectId);
316 
318  IdList getModelingVertices(int objectId);
319 
320  //==========================================
321  // EDGE OPERATIONS
322  //==========================================
323 
325  void selectEdges(int objectId, IdList _vertexList);
326 
328  void unselectEdges(int objectId, IdList _vertexList);
329 
331  void selectAllEdges(int objectId);
332 
334  void invertEdgeSelection(int objectId);
335 
337  void clearEdgeSelection(int objectId);
338 
340  void selectBoundaryEdges(int objectId);
341 
343  void deleteEdgeSelection(int _objectId);
344 
346  IdList getEdgeSelection(int objectId);
347 
349  IdList convertEdgesToVertexPairs(int _id, const IdList& _edges);
350 
352  IdList convertVertexPairsToEdges(int _id, const IdList& _vertices);
353 
355  int createMeshFromEdgeSelection( int _objectId);
356 
358  void colorizeEdgeSelection(int objectId, int r, int g, int b, int a);
359 
360  //==========================================
361  // HALFEDGE OPERATIONS
362  //==========================================
363 
365  void selectHalfedges(int objectId, IdList _vertexList);
366 
368  void unselectHalfedges(int objectId, IdList _vertexList);
369 
371  void selectAllHalfedges(int objectId);
372 
374  void invertHalfedgeSelection(int objectId);
375 
377  void clearHalfedgeSelection(int objectId);
378 
380  void selectBoundaryHalfedges(int objectId);
381 
383  IdList getHalfedgeSelection(int objectId);
384 
386  IdList convertHalfedgesToVertexPairs(int _id, const IdList& _halfedges);
387 
389  IdList convertVertexPairsToHalfedges(int _id, const IdList& _vertices);
390 
392  void colorizeHalfedgeSelection(int objectId, int r, int g, int b, int a);
393 
394  //==========================================
395  // FACE OPERATIONS
396  //==========================================
397 
399  void selectFaces(int objectId, IdList _facesList);
400 
402  void unselectFaces(int objectId, IdList _facesList);
403 
405  void selectAllFaces(int objectId);
406 
408  void clearFaceSelection(int objectId);
409 
411  void invertFaceSelection(int objectId);
412 
414  void deleteFaceSelection(int _objectId);
415 
417  void selectBoundaryFaces(int objectId);
418 
420  void shrinkFaceSelection(int objectId);
421 
423  void growFaceSelection(int objectId);
424 
426  IdList getFaceSelection(int objectId);
427 
429  int createMeshFromFaceSelection( int _objectId);
430 
432  void colorizeFaceSelection(int objectId, int r, int g, int b, int a);
433 
434  //===========================================================================
435 
437  void lassoSelect(QRegion& _region, PrimitiveType _primitiveType, bool _deselection);
438 
441  //===========================================================================
444  //===========================================================================
445 
446 private:
447 
449  template<typename MeshT>
450  bool deleteSelection(MeshT* _mesh, PrimitiveType _primitiveType);
451 
453  template<typename MeshT>
454  void update_regions(MeshT* _mesh);
455 
457  template<typename MeshT>
458  void toggleMeshSelection(MeshT* _mesh, uint _fh, ACG::Vec3d& _hit_point, PrimitiveType _primitiveType);
459 
461  template<typename MeshT>
462  void paintSphereSelection(MeshT* _mesh, int _target_idx, typename MeshT::Point _hitpoint,
463  double _radius, PrimitiveType _primitiveTypes, bool _deselection);
464 
466  template<class MeshT>
467  bool volumeSelection(MeshT* _mesh, ACG::GLState& _state, QRegion *_region,
468  PrimitiveType _primitiveTypes, bool _deselection);
469 
471  template<class MeshT>
472  void closestBoundarySelection(MeshT* _mesh, int _vh, PrimitiveType _primitiveTypes, bool _deselection);
473 
475  template<class MeshT>
476  void floodFillSelection(MeshT* _mesh, uint _fh, double _maxAngle,
477  PrimitiveType _primitiveTypes, bool _deselection);
478 
480  template<typename MeshT>
481  void componentsMeshSelection(MeshT* _mesh, uint _fh, ACG::Vec3d& _hit_point, PrimitiveType _primitiveType);
482 
484  template<class MeshT>
485  void colorizeSelection(MeshT* _mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha);
486 
488  template< class MeshT >
489  void createMeshFromSelection( MeshT& _mesh, MeshT& _newMesh, PrimitiveType _primitiveType);
490 
492  template< class MeshT >
493  void selectVerticesByValue(MeshT* _mesh, QString _component, bool _greater, double _value);
494 
497  //===========================================================================
500  //===========================================================================
501 private:
502 
504  int createMeshFromSelection( int _objectId , PrimitiveType _primitiveType);
505 
508  //===========================================================================
511  //===========================================================================
512 
513 private:
514 
517 
519  SelectionInterface::PrimitiveType vertexType_;
520  SelectionInterface::PrimitiveType edgeType_;
521  SelectionInterface::PrimitiveType halfedgeType_;
522  SelectionInterface::PrimitiveType faceType_;
523 
524  SelectionInterface::PrimitiveType allSupportedTypes_;
525 
527  QPolygon lasso_2Dpoints_;
528 
530  QVector<QPoint> volumeLassoPoints_;
531 
533 
536 };
537 
540 {
541 public:
542 
543  SelectVolumeAction(QRegion&_region, MeshObjectSelectionPlugin* _plugin,
544  unsigned int _type, bool _deselection, ACG::GLState& _state) :
545  state_(_state), region_(_region), plugin_(_plugin), type_(_type), deselection_(_deselection) {};
546 
547  void enter(BaseNode* /*_node*/) {};
548 
549  void leave(BaseNode* /*_node*/) {};
550 
551  bool operator()(BaseNode* _node);
552 
553 private:
554  ACG::GLState& state_;
555  QRegion& region_;
556  MeshObjectSelectionPlugin* plugin_;
557  unsigned int type_;
558  bool deselection_;
559 };
560 //=============================================================================
561 #if defined(INCLUDE_TEMPLATES) && !defined(MESHOBJECTSELECTIONPLUGINT_CC)
562 #define MESHOBJECTSELECTIONPLUGINT_TEMPLATES
563 #include "MeshObjectSelectionPluginT.cc"
564 #endif
565 
566 //=============================================================================
567 #endif // MESHOBJECTSELECTIONPLUGIN_HH defined
568 //=============================================================================