MovePlugin.hh 15.9 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
34
35
36
/*===========================================================================*\
 *                                                                           *
 *                              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
37
 *   $Revision$                                                       *
38
39
40
41
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
42

Jan Möbius's avatar
 
Jan Möbius committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef MOVEPLUGIN_HH
#define MOVEPLUGIN_HH

#include <QObject>
#include <QMenuBar>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/MouseInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/PickingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
58
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
59
60
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
Dirk Wilden's avatar
Dirk Wilden committed
61
#include <ObjectTypes/Plane/Plane.hh>
Jan Möbius's avatar
 
Jan Möbius committed
62
63
64
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>

#include "MoveToolbar.hh"
65
#include "MoveProps.hh"
66
#include "MoveObjectMarker.hh"
Jan Möbius's avatar
 
Jan Möbius committed
67
68
69
70
71

enum SelectionType {VERTEX, EDGE, FACE };

/** Plugin for moving objects and selections
*/
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
72
class MovePlugin : public QObject, BaseInterface, MouseInterface, KeyInterface, PickingInterface, ToolboxInterface, BackupInterface, LoggingInterface, ScriptInterface,ToolbarInterface, ContextMenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
73
74
75
76
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(MouseInterface)
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
77
  Q_INTERFACES(KeyInterface)
Jan Möbius's avatar
 
Jan Möbius committed
78
79
80
81
  Q_INTERFACES(PickingInterface)
  Q_INTERFACES(ToolboxInterface)
  Q_INTERFACES(BackupInterface)
  Q_INTERFACES(LoggingInterface)
82
  Q_INTERFACES(ContextMenuInterface)
Jan Möbius's avatar
 
Jan Möbius committed
83
84
85
86
87
88
89
  Q_INTERFACES(ScriptInterface)
  Q_INTERFACES(ToolbarInterface)

  signals:
    // BaseInterface
    void updateView();
    void updatedObject(int);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
90
    void visibilityChanged(int);
Jan Möbius's avatar
 
Jan Möbius committed
91
92
93
94
95

    // PickingInterface
    void addPickMode( const std::string _mode );
    void addHiddenPickMode( const std::string _mode );
    void setPickModeMouseTracking (const std::string _mode, bool _mouseTracking);
96
    void setPickModeToolbar (const std::string _mode, QToolBar * _toolbar);
Jan Möbius's avatar
 
Jan Möbius committed
97

98
99
    // ContextMenuInterface
    void addContextMenuItem(QAction* _action , ContextMenuType _type);
100

Jan Möbius's avatar
 
Jan Möbius committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    // BackupInterface
    void createBackup( int _id , QString _name );

    // LoggingInterface
    void log(Logtype _type, QString _message);
    void log(QString _message);

    // ScriptInterface
    void scriptInfo( QString _functionName  );
    void setSlotDescription(QString     _slotName,   QString     _slotDescription,
                            QStringList _parameters, QStringList _descriptions);

    // ToolbarInterface
    void addToolbar(QToolBar* _toolbar);
    void getToolBar( QString _name, QToolBar*& _toolbar);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
116

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
117
118
119
    // KeyInterface
    void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);

Jan Möbius's avatar
 
Jan Möbius committed
120
121
122
123
124
125
126
127
128
  private slots :

    // BaseInterface
    void pluginsInitialized();

    // MouseInterface
    void slotMouseWheelEvent(QWheelEvent * _event, const std::string & _mode);
    void slotMouseEvent( QMouseEvent* _event );

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
129
130
131
132
    // KeyInterface
    void slotKeyEvent (QKeyEvent* _event);
    void slotKeyReleaseEvent (QKeyEvent* _event);

Jan Möbius's avatar
 
Jan Möbius committed
133
134
135
136
137
138
139
140
141
142
143
144
145
    // PickingInterface
    void slotPickModeChanged( const std::string& _mode);

    // BackupInterface
    void slotBackupRequested( int /*_id*/ , QString /*_name*/ , int /*_backup_id*/){};
    void slotRestoreRequested( int /*_id*/ , QString /*_name*/ , int /*_backup_id*/){};

  public :

    /// Default Constructor
    MovePlugin();

    /// Destructor
146
    ~MovePlugin();
Jan Möbius's avatar
 
Jan Möbius committed
147
148
149
150
151
152
153
154

    /// Initialize the toolbar (create a widget in the right side toolbox)
    bool initializeToolbox(QWidget*& _widget);

    /// Name of the Plugin
    QString name(){ return (QString("Move")); };

    /// Description of the Plugin
Jan Möbius's avatar
Jan Möbius committed
155
    QString description() { return (QString(tr("Moves Meshes with Manipulators"))); };
Jan Möbius's avatar
 
Jan Möbius committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

//===========================================================================
/** @name ToolBox
  * @{ */
//===========================================================================

  private:
    /// stores the current axes in the tool
    int axisA_;
    int axisB_;

  private slots:

    /// Position of manipulator in tab changed
    void slotSetPosition();

    /// Toggle the first axis for changing direction in tab
    void slotToggleAxisA();

    /// Toggle the second axis for changing direction in tab
    void slotToggleAxisB();

    /// Set Direction of manipulator in tab changed
    void slotSetDirection();

    /// perform a translation for Manipulator in tab
    void slotTranslation();

    /// Project the current manipulator onto the tangent plane of the object
    void slotProjectToTangentPlane();

    /// Move the current manipulator to the cog of the object
    void slotMoveManipToCOG();

    /// Rotate Manipulator (with values from Tab)
    void slotRotate();

    /// Scale (with values from Tab)
    void slotScale();

196
    /// Move target Meshes cog to the origin
Jan Möbius's avatar
 
Jan Möbius committed
197
198
199
200
201
202
203
204
205
206
    void slotMoveToOrigin();

    /// Scale Boundingbox Diagonal to unit size
    void slotUnifyBoundingBoxDiagonal();

  private:

    /// Update the Dialog with the last clicked manipulator
    void updateManipulatorDialog();

207
208
209
210
211
212
213
214
215
216
217
218
    /// Get closest vertex to hitpoint
    template <typename MeshType>
    OpenMesh::Vec3d getNearestVertex(MeshType* _mesh, uint _fh, OpenMesh::Vec3d& _hitPoint);

    /// Get closest edge to hitpoint
    template <typename MeshType>
    OpenMesh::Vec3d getNearestEdge(MeshType* _mesh, uint _fh, OpenMesh::Vec3d& _hitPoint);

    /// Get closest face to hitpoint
    template <typename MeshType>
    OpenMesh::Vec3d getNearestFace(MeshType* _mesh, uint _fh, OpenMesh::Vec3d& _hitPoint);

Jan Möbius's avatar
 
Jan Möbius committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
    /// True if the toolbox widget is active
    bool toolboxActive_;

    /// Widget for Toolbox
    moveToolbarWidget* tool_;

/** @} */

//===========================================================================
/** @name ToolBar
  * @{ */
//===========================================================================

  private :
    QAction* moveAction_;
    QAction* moveSelectionAction_;

    QActionGroup* toolBarActions_;
Jan Möbius's avatar
Jan Möbius committed
237
238
    
    QToolBar* toolbar_;
Jan Möbius's avatar
 
Jan Möbius committed
239
240
241
242
243
244
245
246

  private slots:

    /// Called by Toolbar to enable move mode
    void slotSetMoveMode(QAction* _action);

/** @} */

247
248
249
250
251
252
//===========================================================================
/** @name PickToolBar
  * @{ */
//===========================================================================

  private :
253
    QToolBar* pickToolbar_;
254
255

    QAction* placeAction_;
256
257
    QAction* rotateTranslateAction_;
    QAction* rotateManipAction_;
258
259
260
261
262
    QAction* resizeAction_;

    QAction* biggerManipAction_;
    QAction* smallerManipAction_;

263
264
    QAction* placeAndSnapAction_;

265
266
267
268
269
270
271
272
273
    QActionGroup* pickToolBarActions_;

  private slots:

    /// Called by pick Toolbar
    void slotPickToolbarAction(QAction* _action);

/** @} */

Jan Möbius's avatar
 
Jan Möbius committed
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
//===========================================================================
/** @name Manipulator Handling
  * @{ */
//===========================================================================

  private slots:

    /// move the object when its manipulator moves
    void manipulatorMoved( QtTranslationManipulatorNode* _node , QMouseEvent* _event);

    /// update object when its manipulator changes position
    void ManipulatorPositionChanged(QtTranslationManipulatorNode* _node );

  private:

    ///Transform a mesh with the given transformation matrix
    template< typename MeshT >
    void transformMesh(ACG::Matrix4x4d _mat , MeshT& _mesh );

    #ifdef ENABLE_POLYLINE_SUPPORT
    ///Transform a polyline with the given transformation matrix
    template< class PolyLineT >
    void transformPolyLine( ACG::Matrix4x4d _mat , PolyLineT& _polyLine  );
    #endif

    /** Get the Matrix of the last active Manipulator ( Identity if not found or hidden Manipulator )
      *
      * @param _reset reset the transformation matrix of the manipulator to identity)
      * @return current transformation matrix of the manipulator
      */
    ACG::Matrix4x4d getLastManipulatorMatrix(bool _reset = true);

    /// Checks if the manipulators should be visible or not
    void showManipulators( );

    /// Place and show the Manipulator
310
    void placeManip(QMouseEvent * _event, bool _snap = false);
Jan Möbius's avatar
 
Jan Möbius committed
311
312
313
314

    /// scale mesh to have a boundingboxdiagonal of one
    template< typename MeshT >
    void unifyBBDiag(MeshT& _mesh );
315

316
317
318
    /// get bounding box diagonal of a mesh
    template< typename MeshT >
    void getBB( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max  );
319

320
321
322
    /// Scales object such that bounding box diagonal has unit length
    template< typename MeshT >
    void unifyBBDiag( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max  );
Jan Möbius's avatar
 
Jan Möbius committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

    /// Size for the manipulators
    double manip_size_;

    /// Modifier for the Size (changed by Mousewheel Events)
    double manip_size_modifier_;

    /// Stores the last manipulator which has been clicked ( used for the toolbox dialog)
    int lastActiveManipulator_;

    /// Set Descriptions for scriptable functions
    void setDescriptions();

    /// Move an object with given id
    void moveObject(ACG::Matrix4x4d mat, int _id);

    /// Move selection on an object with given id
    void moveSelection(ACG::Matrix4x4d mat, int _id);

342
343
344
    /// Object marker to dimm Objects during manipulator transformation
    MoveObjectMarker objectMarker_;

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
345
346
347
348
349
  private:

    /// Holds the current manipulator mode
    QtTranslationManipulatorNode::ManipulatorMode manMode_;

350
351
    void setManipMode (QtTranslationManipulatorNode::ManipulatorMode _mode);

Jan Möbius's avatar
 
Jan Möbius committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/** @} */

//===========================================================================
/** @name Selection Plugin Communication
  * @{ */
//===========================================================================

    /// have we already tried to connect to Selection Plugin?
    bool selectionConnected_;

    /// Current SelectionType of SelectionPlugin
    SelectionType selectionType_;

    /// Connect to SelectionPlugin
    void connectSelectionActions();

  private slots:

    /// The SelectionMode changed in SelectionPlugin
    void slotSelectionModeChanged(QAction* _action);

373
    /// Sets whether all targets should be affected or not
374
    void setAllTargets(bool _state);
375

Jan Möbius's avatar
 
Jan Möbius committed
376
/** @} */
377

378
379
380
381
  //===========================================================================
  /** @name Context Menu
   * @{ */
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
382

383
384
    private slots:

385
386
    /// Show properties of move manipulator in a dialog
    void showProps( );
387

Mike Kremer's avatar
Mike Kremer committed
388
    /// Get properties dialog widget that is attached to BaseDataObject obj
389
    movePropsWidget* getDialogWidget(BaseObjectData* _obj);
390

Mike Kremer's avatar
Mike Kremer committed
391
    /// Get parent properties dialog widget of QPushButton but
392
    movePropsWidget* getDialogFromButton(QPushButton* _but);
393

Mike Kremer's avatar
Mike Kremer committed
394
395
    /** Override ContextMenuInterface slot in order to avoid appearance of
     * context menu entry when clicking on other nodes (other than manpipulator nodes)
396
     */
397
    void slotUpdateContextMenuNode( int _nodeId );
398

399
    private:
Mike Kremer's avatar
Mike Kremer committed
400
    /// List of properties dialogs (each corresponding to one manipulator)
401
    QList<movePropsWidget*> propsWindows_;
402

Mike Kremer's avatar
Mike Kremer committed
403
    /// Context menu entry
404
    QAction* contextAction_;
405

406
407
408
    /// Checked if transformation should be applied to all target objs
    QAction* toAllTargets_;

409
/** @} */
410

Jan Möbius's avatar
 
Jan Möbius committed
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
//===========================================================================
/** @name Scriptable Functions
  * @{ */
//===========================================================================

public slots :

  /// translate an Object by a given vector
  void translate( int _objectId , Vector _vector );

  /// translate given vertices by a vector
  void translate( int _objectId , idList _vHandles, Vector _vector );

  /// translate current selection of an Object by a given vector
  void translateSelection( int _objectId , Vector _vector );

  /// transform an Object by a given matrix
  void transform( int _objectId , Matrix4x4 _matrix );

  /// transform given vertices by a matrix
  void transform( int _objectId , idList _vHandles, Matrix4x4 _matrix );

  /// transform current selection of an Object by a given matrix
  void transformVertexSelection( int _objectId , Matrix4x4 _matrix );

  /// transform current selection of an Object by a given matrix
  void transformFaceSelection( int _objectId , Matrix4x4 _matrix );

  /// transform current selection of an Object by a given matrix
  void transformEdgeSelection( int _objectId , Matrix4x4 _matrix );

  /// Set the position of the manipulator
  void setManipulatorPosition( int _objectId , Vector _position );

  /// Get the position of the manipulator
  Vector manipulatorPosition( int _objectId );

  /// Set the direction of the manipulator
  void setManipulatorDirection( int _objectId , Vector _directionX, Vector _directionY );

  /// Get the x-direction of the manipulator
  Vector manipulatorDirectionX( int _objectId );

  /// Get the y-direction of the manipulator
  Vector manipulatorDirectionY( int _objectId );

  /// Get the z-direction of the manipulator
  Vector manipulatorDirectionZ( int _objectId );
/** @} */

  public slots:
462
    QString version() { return QString("1.2"); };
Jan Möbius's avatar
 
Jan Möbius committed
463
464

  private:
465
    bool hide_;
Jan Möbius's avatar
 
Jan Möbius committed
466

467
468
    bool allTargets_;

469
    bool placeMode_;
Jan Möbius's avatar
 
Jan Möbius committed
470
471
472
};

#endif //MOVEPLUGIN_HH