Developer Documentation
Loading...
Searching...
No Matches
MovePlugin.hh
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42#pragma once
43
44#include <QObject>
45#include <QMenuBar>
46
64
65#ifdef ENABLE_SKELETON_SUPPORT
67#endif
68
69#if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
70#include <OpenVolumeMesh/Attribs/NormalAttrib.hh>
71#endif
72
73#include "MoveToolbar.hh"
74#include "MoveProps.hh"
75#include "MoveObjectMarker.hh"
76
77#include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>
78
82{
83 Q_OBJECT
84 Q_INTERFACES(BaseInterface)
85 Q_INTERFACES(MouseInterface)
86 Q_INTERFACES(KeyInterface)
87 Q_INTERFACES(PickingInterface)
88 Q_INTERFACES(ToolboxInterface)
89 Q_INTERFACES(BackupInterface)
90 Q_INTERFACES(LoggingInterface)
91 Q_INTERFACES(ContextMenuInterface)
92 Q_INTERFACES(ScriptInterface)
93 Q_INTERFACES(ToolbarInterface)
94 Q_INTERFACES(LoadSaveInterface)
95 Q_INTERFACES(RPCInterface)
96 Q_INTERFACES(PythonInterface)
97
98 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Move")
99
100public:
101 typedef unsigned int SelectionType;
102 static const SelectionType VERTEX = 1;
103 static const SelectionType EDGE = 2;
104 static const SelectionType FACE = 4;
105 static const SelectionType CELL = 8;
106
107 signals:
108 // BaseInterface
109 void updateView() override;
110 void updatedObject(int, const UpdateType& _type) override;
111 void nodeVisibilityChanged(int) override;
112
113 // PickingInterface
114 void addPickMode( const std::string& _mode ) override;
115 void addHiddenPickMode( const std::string& _mode ) override;
116 void setPickModeMouseTracking (const std::string& _mode, bool _mouseTracking) override;
117 void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar) override;
118
119 // ContextMenuInterface
120 void addContextMenuItem(QAction* _action , ContextMenuType _type) override;
121
122 // BackupInterface
123 void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL) override;
124
125 // LoggingInterface
126 void log(Logtype _type, QString _message) override;
127 void log(QString _message) override;
128
129 // ScriptInterface
130 void scriptInfo( QString _functionName );
131 void setSlotDescription(QString _slotName, QString _slotDescription,
132 QStringList _parameters, QStringList _descriptions) override;
133
134 // ToolbarInterface
135 void addToolbar(QToolBar* _toolbar) override;
136 void getToolBar( QString _name, QToolBar*& _toolbar) override;
137
138 // KeyInterface
139 void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false) override;
140
141 // ToolboxInterface
142 void addToolbox( QString _name , QWidget* _widget, QIcon* _icon ) override;
143
144 // RPCInterface
145 void pluginExists(QString _pluginName, bool &_exists) override;
146 void functionExists(QString _pluginName, QString _functionName, bool &_exists) override;
147
148 private slots :
149
150 // BaseInterface
151 void initializePlugin() override;
152 void pluginsInitialized() override;
153
154 void slotAllCleared() override;
155
156 // LoadSaveInterface
157 void objectDeleted( int _id ) override;
158
159 // MouseInterface
160 void slotMouseWheelEvent(QWheelEvent * _event, const std::string & _mode) override;
161 void slotMouseEvent( QMouseEvent* _event ) override;
162
163 // KeyInterface
164 void slotKeyEvent (QKeyEvent* _event) override;
165 void slotKeyReleaseEvent (QKeyEvent* _event) override;
166
167 // PickingInterface
168 void slotPickModeChanged( const std::string& _mode) override;
169
170 public :
171
173 MovePlugin();
174
176 ~MovePlugin();
177
179 QString name() override { return (QString("Move")); };
180
182 QString description() override { return (QString(tr("Moves Meshes with Manipulators"))); };
183
184//===========================================================================
187//===========================================================================
188
189 private:
193
195 {
196 DIAGONAL,
197 LONGEST_AXIS,
198 ALL_AXIS
199 };
200
201 private slots:
202
204 void slotSetPosition();
205
207 void slotToggleAxisA();
208
210 void slotToggleAxisB();
211
213 void slotSetDirection();
214
216 void slotTranslation();
217
220
222 void slotMoveManipToCOG();
223
225 void slotRotate();
226
228 void slotScale();
229
231
233
234 private:
235
238
240 template <typename MeshType>
241 OpenMesh::Vec3d getNearestVertex(MeshType* _mesh, uint _fh, OpenMesh::Vec3d& _hitPoint);
242
244 template <typename MeshType>
245 OpenMesh::Vec3d getNearestEdge(MeshType* _mesh, uint _fh, OpenMesh::Vec3d& _hitPoint);
246
248 template <typename MeshType>
249 OpenMesh::Vec3d getNearestFace(MeshType* _mesh, uint _fh, OpenMesh::Vec3d& _hitPoint);
250
253
256
257 QIcon* toolIcon_;
258
261//===========================================================================
264//===========================================================================
265
266 private :
267 QAction* moveAction_;
269
270 QActionGroup* toolBarActions_;
271
272 QToolBar* toolbar_;
273
274 private slots:
275
277 void slotSetMoveMode(QAction* _action);
278
281//===========================================================================
284//===========================================================================
285
286 private :
287 QToolBar* pickToolbar_;
288
289 QAction* placeAction_;
293
296
300
302
303 QActionGroup* pickToolBarActions_;
304
305 private slots:
306
308 void slotPickToolbarAction(QAction* _action);
309
312//===========================================================================
315//===========================================================================
316
317 private:
318 //object ids of all objects with active Manipulator
319 std::vector< int > activeManipulators_;
320
321 private slots:
322
324 void manipulatorMoved( QtTranslationManipulatorNode* _node , QMouseEvent* _event);
325
328
329 private:
330
332
334 template< typename MeshT >
335 void transformMesh(ACG::Matrix4x4d _mat , MeshT& _mesh );
336
337 #ifdef ENABLE_POLYLINE_SUPPORT
339 template< class PolyLineT >
340 void transformPolyLine( ACG::Matrix4x4d _mat , PolyLineT& _polyLine );
341 #endif
342
343 #ifdef ENABLE_SKELETON_SUPPORT
345 void transformSkeleton( ACG::Matrix4x4d _mat , Skeleton& _skeleton );
346 #endif
347
348 #if defined(ENABLE_HEXAHEDRALMESH_SUPPORT) || defined(ENABLE_POLYHEDRALMESH_SUPPORT) || defined(ENABLE_TETRAHEDRALMESH_SUPPORT)
350 template< typename VolumeMeshT >
351 void transformVolumeMesh(ACG::Matrix4x4d _mat , VolumeMeshT& _mesh , OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib );
352
354 template< typename VolumeMeshT >
355 ACG::Vec3d cogVolumeMesh( VolumeMeshT& _mesh );
356
358 template< typename VolumeMeshT >
359 void getBBVolumeMesh( VolumeMeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max );
360
362 template< typename VolumeMeshT >
363 void unifyBBVolumeMesh(VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib, Unificationtype u = MovePlugin::DIAGONAL);
364
366 template< typename VolumeMeshT >
367 void unifyBBVolumeMesh( VolumeMeshT& _mesh, OpenVolumeMesh::NormalAttrib<VolumeMeshT>& _normalAttrib, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max, Unificationtype u = MovePlugin::DIAGONAL );
368 #endif
369
375 ACG::Matrix4x4d getLastManipulatorMatrix(bool _reset = true);
376
378 void showManipulators( );
379
381 void placeManip(QMouseEvent * _event, bool _snap = false);
382
384 template< typename MeshT >
385 void unifyBB(MeshT& _mesh , Unificationtype u = MovePlugin::DIAGONAL);
386
388 template< typename MeshT >
389 void getBB( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max );
390
392 template< typename MeshT >
393 void unifyBB( MeshT& _mesh, ACG::Vec3d& _bb_min, ACG::Vec3d& _bb_max, Unificationtype u = MovePlugin::DIAGONAL );
394
397
400
403
405 void setDescriptions();
406
408 void moveObject(ACG::Matrix4x4d mat, int _id);
409
411 void moveSelection(ACG::Matrix4x4d mat, int _id, QEvent::Type _type);
412
415
416 private:
417
420
422
425//===========================================================================
428//===========================================================================
429
431 SelectionType selectionType_;
432
434 void updateSelectionType();
435
436 private slots:
437
439 void setAllTargets(bool _state);
440
443 //===========================================================================
446 //===========================================================================
447
448 private slots:
449
451 void showProps( );
452
454 void hideManipulator();
455
458
460 movePropsWidget* getDialogFromButton(QPushButton* _but);
461
465 void slotUpdateContextMenuNode( int _nodeId ) override;
466
467 private:
468
469 void setPickModeProps(movePropsWidget* _pW, const std::string &_pickmode);
470
472 QList<movePropsWidget*> propsWindows_;
473
476
479
482
485
488
491//===========================================================================
494//===========================================================================
495
496public slots :
497
499 void slotMoveToOrigin();
500
503
506
509
511 void translate( int _objectId , Vector _vector );
512
514 void translate( int _objectId , IdList _vHandles, Vector _vector );
515
517 void translateVertexSelection( int _objectId , Vector _vector );
518
520 void translateFaceSelection( int _objectId , Vector _vector );
521
523 void translateEdgeSelection( int _objectId , Vector _vector );
524
526 void transform( int _objectId , Matrix4x4 _matrix );
527
529 void transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix );
530
532 bool transformVertexSelection( int _objectId , Matrix4x4 _matrix );
533
535 bool transformFaceSelection( int _objectId , Matrix4x4 _matrix );
536
538 bool transformEdgeSelection( int _objectId , Matrix4x4 _matrix );
539
541 bool transformCellSelection( int _objectId , Matrix4x4 _matrix );
542
544 void transformHandleRegion(int _objectId, Matrix4x4 _matrix);
545
547 void setManipulatorPosition( int _objectId , Vector _position );
548
550 Vector manipulatorPosition( int _objectId );
551
553 void setManipulatorDirection( int _objectId , Vector _directionX, Vector _directionY );
554
556 Vector manipulatorDirectionX( int _objectId );
557
559 Vector manipulatorDirectionY( int _objectId );
560
562 Vector manipulatorDirectionZ( int _objectId );
563
566 void objectRenderingMatrixIdentity(int _objectId);
567
573 void objectRenderingMatrixScale(int _objectId, double _s);
574
580 void objectRenderingMatrixTranslate(int _objectId, Vector _translation);
581
588 void objectRenderingMatrixRotate(int _objectId, Vector _axis, double _angle);
589
598 Matrix4x4 getObjectRenderingMatrix(int _objectId);
599
602 public slots:
603 QString version() override { return QString("1.2"); };
604
605 private:
606 bool hide_;
607
608 bool allTargets_;
609
610 bool placeMode_;
611
614};
615
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition DataTypes.hh:181
Logtype
Log types for Message Window.
Interface class for backup handling.
Interface class from which all plugins have to be created.
Interface class for creating custom context menus.
Keyboard Event Interface.
Interface for all plugins which want to Load or Save files and create Objects.
Interface for all Plugins which do logging to the logging window of the framework.
Interface class for receiving mouse events.
void moveSelection(ACG::Matrix4x4d mat, int _id, QEvent::Type _type)
Move selection on an object with given id.
void slotTranslation()
perform a translation for Manipulator in tab
QAction * placeAction_
Called by pick Toolbar.
int axisA_
stores the current axes in the tool
~MovePlugin()
Destructor.
void objectRenderingMatrixTranslate(int _objectId, Vector _translation)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
QActionGroup * pickToolBarActions_
Called by pick Toolbar.
void slotSetDirection()
Set Direction of manipulator in tab changed.
std::vector< int > activeManipulators_
Size for the manipulators.
void slotScale()
Scale (with values from Tab)
OpenMesh::Vec3d getNearestEdge(MeshType *_mesh, uint _fh, OpenMesh::Vec3d &_hitPoint)
Get closest edge to hitpoint.
void slotPickToolbarAction(QAction *_action)
Called by pick Toolbar.
QString name() override
Name of the Plugin.
movePropsWidget * getDialogFromButton(QPushButton *_but)
Get parent properties dialog widget of QPushButton but.
void translateEdgeSelection(int _objectId, Vector _vector)
translate current edge selection of an Object by a given vector
void transformMesh(ACG::Matrix4x4d _mat, MeshT &_mesh)
Transform a mesh with the given transformation matrix.
void slotUnifyBoundingBoxAllAxis()
Scale all Boundingbox axis to unit size.
ACG::Matrix4x4d getLastManipulatorMatrix(bool _reset=true)
Get the Matrix of the last active Manipulator ( Identity if not found or hidden Manipulator )
void slotUnifyBoundingBoxLongestAxis()
Scale Boundingbox longest axis to unit size (keeps aspect ratio)
void slotUpdateContextMenuNode(int _nodeId) override
Hide context menu entry when right clicking on node other than manipulator node.
QtTranslationManipulatorNode::ManipulatorMode manMode_
Holds the current manipulator mode.
void objectRenderingMatrixIdentity(int _objectId)
Sets the Object Matrix in the scenegraph to identity.
void updateManipulatorDialog()
Update the Dialog with the last clicked manipulator.
void setDescriptions()
Set Descriptions for scriptable functions.
QAction * placeAndSnapAction_
Called by pick Toolbar.
void getBB(MeshT &_mesh, ACG::Vec3d &_bb_min, ACG::Vec3d &_bb_max)
get bounding box diagonal of a mesh
void slotSetPosition()
Position of manipulator in tab changed.
void slotEnableSelectionMode()
stores the current axes in the tool
Vector manipulatorDirectionX(int _objectId)
Get the x-direction of the manipulator.
bool transformCellSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
void slotEnableObjectMode()
stores the current axes in the tool
QAction * moveSelectionAction_
Called by Toolbar to enable move mode.
void showManipulators()
Checks if the manipulators should be visible or not.
void slotMouseEvent(QMouseEvent *_event) override
MousePress event occured.
QAction * contextActionHide_
Context menu entry to hide a manipulator.
void slotToggleAxisB()
Toggle the second axis for changing direction in tab.
movePropsWidget * getDialogWidget(BaseObjectData *_obj)
Get properties dialog widget that is attached to BaseDataObject obj.
void showProps()
Show properties of move manipulator in a dialog ( Called via context for picking. Get the picked id f...
void slotUnifyBoundingBoxDiagonal()
Scale Boundingbox Diagonal to unit size.
void translate(int _objectId, Vector _vector)
translate an Object by a given vector
Matrix4x4 getObjectRenderingMatrix(int _objectId)
Gets the Object Matrix in the scenegraph.
void hideManipulator()
Hide the manipulator( Called via context for picking. Get the picked id from the Qvariant attached to...
int axisB_
stores the current axes in the tool
Vector manipulatorPosition(int _objectId)
Get the position of the manipulator.
MoveObjectMarker objectMarker_
Object marker to dimm Objects during manipulator transformation.
QAction * contextMenuManipControlsAction_
Action holding the context menu for toolbar replication.
QList< movePropsWidget * > propsWindows_
List of properties dialogs (each corresponding to one manipulator)
double manip_size_modifier_
Modifier for the Size (changed by Mousewheel Events)
QMenu * contextMenuManipControl_
Additional Context Menu replicating the toolbar stuff.
void unifyBB(MeshT &_mesh, Unificationtype u=MovePlugin::DIAGONAL)
scale mesh to have a boundingboxdiagonal of one
void objectRenderingMatrixRotate(int _objectId, Vector _axis, double _angle)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
void objectRenderingMatrixScale(int _objectId, double _s)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
void slotToggleAxisA()
Toggle the first axis for changing direction in tab.
bool transformVertexSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
void slotSetMoveMode(QAction *_action)
Called by Toolbar to enable move mode.
QAction * contextAction_
Context menu entry for showing per manipulator settings.
Vector manipulatorDirectionY(int _objectId)
Get the y-direction of the manipulator.
void unifyBoundingBox(Unificationtype u)
Size for the manipulators.
QAction * currentPoseManipAction_
Called by pick Toolbar.
OpenMesh::Vec3d getNearestFace(MeshType *_mesh, uint _fh, OpenMesh::Vec3d &_hitPoint)
Get closest face to hitpoint.
QString description() override
Description of the Plugin.
void ManipulatorPositionChanged(QtTranslationManipulatorNode *_node)
update object when its manipulator changes position
QAction * toAllTargets_
Checked if transformation should be applied to all target objs.
void slotRotate()
Rotate Manipulator (with values from Tab)
void setPickModeProps(movePropsWidget *_pW, const std::string &_pickmode)
List of properties dialogs (each corresponding to one manipulator)
void slotProjectToTangentPlane()
Project the current manipulator onto the tangent plane of the object.
bool transformEdgeSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
QIcon * toolIcon_
stores the current axes in the tool
int lastActiveManipulator_
Stores the last manipulator which has been clicked ( used for the toolbox dialog)
bool toolboxActive_
True if the toolbox widget is active.
void setAllTargets(bool _state)
Sets whether all targets should be affected or not.
Vector manipulatorDirectionZ(int _objectId)
Get the z-direction of the manipulator.
SelectionType selectionType_
Current SelectionType of SelectionPlugin.
QAction * biggerManipAction_
Called by pick Toolbar.
void manipulatorMoved(QtTranslationManipulatorNode *_node, QMouseEvent *_event)
move the object when its manipulator moves
QAction * fixChildManipAction_
Called by pick Toolbar.
moveToolbarWidget * tool_
Widget for Toolbox.
bool transformedSelected_
stores if any selected elements where transformed
void slotPickModeChanged(const std::string &_mode) override
slot is called when the pickMode changed
void setManipMode(QtTranslationManipulatorNode::ManipulatorMode _mode)
Set the manipulator manipulation mode.
OpenMesh::Vec3d getNearestVertex(MeshType *_mesh, uint _fh, OpenMesh::Vec3d &_hitPoint)
Get closest vertex to hitpoint.
double manip_size_
Size for the manipulators.
QAction * resizeAction_
Called by pick Toolbar.
void translateFaceSelection(int _objectId, Vector _vector)
translate current face selection of an Object by a given vector
QToolBar * toolbar_
Called by Toolbar to enable move mode.
void setManipulatorPosition(int _objectId, Vector _position)
Set the position of the manipulator.
void setManipulatorDirection(int _objectId, Vector _directionX, Vector _directionY)
Set the direction of the manipulator.
void pluginsInitialized() override
Initialization of the plugin when it is loaded by the core.
QActionGroup * toolBarActions_
Called by Toolbar to enable move mode.
QAction * rotateTranslateAction_
Called by pick Toolbar.
void transformHandleRegion(int _objectId, Matrix4x4 _matrix)
Transform handle region using the given transformation matrix.
MovePlugin()
Default Constructor.
Definition MovePlugin.cc:85
void translateVertexSelection(int _objectId, Vector _vector)
translate current vertex selection of an Object by a given vector
QAction * smallerManipAction_
Called by pick Toolbar.
QAction * moveAction_
Called by Toolbar to enable move mode.
QAction * transformRefPoseManipAction_
Called by pick Toolbar.
void slotMoveManipToCOG()
Move the current manipulator to the cog of the object.
void moveObject(ACG::Matrix4x4d mat, int _id)
Move an object with given id.
void updateSelectionType()
Get current primitive selection.
Unificationtype
stores the current axes in the tool
void transform(int _objectId, Matrix4x4 _matrix)
transform an Object by a given matrix
bool transformFaceSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
QToolBar * pickToolbar_
Called by pick Toolbar.
void slotMoveToOrigin()
Move target Meshes cog to the origin.
void placeManip(QMouseEvent *_event, bool _snap=false)
Place and show the Manipulator.
QAction * rotateManipAction_
Called by pick Toolbar.
Allow access to picking functions.
Interface class for exporting functions to python.
Interface to call functions across plugins.
Interface for all Plugins which provide scriptable Functions.
Add a toolbox to OpenFlipper.
Plugins can add its own toolbox to the main widget's toolbox area by using this interface.
Update type class.
Definition UpdateType.hh:59
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.