Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SkeletonEditingPlugin.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 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef SKELETONEDITINGPLUGIN_HH
51 #define SKELETONEDITINGPLUGIN_HH
52 
53 #include <QObject>
54 #include <QMenuBar>
55 
69 
71 #include "SkeletonMarker.hh"
72 
76 {
77  Q_OBJECT
78  Q_INTERFACES(BaseInterface)
79  Q_INTERFACES(MouseInterface)
80  Q_INTERFACES(KeyInterface)
81  Q_INTERFACES(PickingInterface)
82  Q_INTERFACES(ToolboxInterface)
83  Q_INTERFACES(LoggingInterface)
84  Q_INTERFACES(ContextMenuInterface)
85  Q_INTERFACES(ScriptInterface)
86  Q_INTERFACES(ToolbarInterface)
87  Q_INTERFACES(LoadSaveInterface)
88  Q_INTERFACES(BackupInterface)
89  Q_INTERFACES(RPCInterface)
90 
91 #if QT_VERSION >= 0x050000
92  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SkeletonEditing")
93 #endif
94 
95  signals:
96  // BaseInterface
97  void updateView();
98  void updatedObject(int, const UpdateType& _type);
99  void nodeVisibilityChanged(int);
100 
101  void setRenderer(unsigned int _viewer, QString _rendererName);
102  void getCurrentRenderer(unsigned int _viewer, QString& _rendererName);
103 
104  // PickingInterface
105  void addPickMode( const std::string& _mode );
106  void addHiddenPickMode( const std::string& _mode );
107  void setPickModeMouseTracking (const std::string& _mode, bool _mouseTracking);
108  void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
109 
110  // ContextMenuInterface
111  void addContextMenuItem(QAction* _action , ContextMenuType _type);
112 
113  // LoggingInterface
114  void log(Logtype _type, QString _message);
115  void log(QString _message);
116 
117  // ScriptInterface
118  void scriptInfo( QString _functionName );
119  void setSlotDescription(QString _slotName, QString _slotDescription,
120  QStringList _parameters, QStringList _descriptions);
121 
122  // ToolbarInterface
123  void addToolbar(QToolBar* _toolbar);
124  void getToolBar( QString _name, QToolBar*& _toolbar);
125 
126  // KeyInterface
127  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
128 
129  // ToolboxInterface
130  void addToolbox( QString _name , QWidget* _widget );
131 
132  // LoadSaveInterface
133  void addEmptyObject(DataType _type, int& _id);
134  void deleteObject( int _id);
135 
136  // BackupInterface
137  void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL );
138 
139  private slots :
140 
141  // BaseInterface
142  void initializePlugin();
143  void pluginsInitialized();
144  void slotObjectUpdated( int _id, const UpdateType& _type);
145 
146  // MouseInterface
147  void slotMouseWheelEvent(QWheelEvent * _event, const std::string & _mode);
148  void slotMouseEvent( QMouseEvent* _event );
149 
150  // KeyInterface
151  void slotKeyEvent (QKeyEvent* _event);
152  void slotKeyReleaseEvent (QKeyEvent* _event);
153 
154  // PickingInterface
155  void slotPickModeChanged( const std::string& _mode);
156 
157  private:
158  void moveJoint(QMouseEvent* _event);
159  bool canModify(QMouseEvent* _event);
160  void insertJoint(QMouseEvent* _event);
161  void cancelJointInsertion();
162  void deleteJoint(QMouseEvent* _event);
163  void selectJoint(QMouseEvent* _event);
164 
165  Skeleton::Pose* activePose(SkeletonObject* _skeletonObj);
166  void setJointPosition(SkeletonObject* _skeletonObj, Skeleton::Joint* _joint, ACG::Vec3d& _position);
167 
168  OpenMesh::Vec3d getNearestJoint(SkeletonObject* _skeletonObj, OpenMesh::Vec3d &_hitPoint, int& _bestJointID);
169  public:
170 
173 
176 
178  QString name(){ return (QString("Skeleton Editing")); };
179 
181  QString description() { return (QString(tr("Create and edit skeletons"))); };
182 
183 
184 //===========================================================================
187 //===========================================================================
188 
189  public slots:
191  void splitBone( int _objectId, int _tailJoint);
192 
194  void addJoint( int _objectId, int _parent, Vector _position );
195 
197  void deleteJoint( int _objectId , int _jointId );
198 
200  void transformJoint( int _objectId , int _jointId, Matrix4x4 _matrix );
201 
203  Matrix4x4 globalMatrix(int _objectId, int _jointId);
204 
206  Matrix4x4 localMatrix(int _objectId, int _jointId);
207 
209  Vector globalTranslation(int _objectId, int _jointId);
210 
212  Vector localTranslation(int _objectId, int _jointId);
213 
215  int animationCount(int _objectId);
216 
218  int frameCount(int _objectId, int _animationIndex);
219 
221  int activeAnimation(int _objectId);
222 
224  int activeFrame(int _objectId);
225 
227  void setActivePose(int _objectId, int _animationIndex, int _frame);
228 
230  void addAnimation(int _objectId, QString _name, int _frames);
231 
233  void splitJoint(QMouseEvent* _event);
234 
237  public slots:
238  QString version() { return QString("1.0"); };
239 
240 
241  private slots:
242  void slotSetEditingMode(QAction* _action);
243  void slotPickToolbarAction(QAction* _action);
244 
245  void setDescriptions();
246 
247  private:
248  QToolBar* toolbar_;
249  QActionGroup* toolBarActions_;
250  QAction* skeletonEditingAction_;
251 
252  QToolBar* pickToolbar_;
253  QActionGroup* pickToolBarActions_;
254  QAction* selectJointAction_;
255  QAction* insertJointAction_;
256  QAction* splitJointAction_;
257  QAction* deleteJointAction_;
258  QAction* moveJointAction_;
259  QAction* transformChildManipAction_;
260  QAction* transformAllManipAction_;
261  QAction* rotateManipAction_;
262  QAction* inverseKinematicAction_;
263 
264  int currentSkeleton_;
265  int currentJoint_;
266  bool jointPreview_;
267 
268  bool transformChildJoints_;
269  bool transformAllFrames_;
270  bool inverseKinematic_;
271 
272  bool dblClick_;
273 
275  QString lastRenderer_;
278 
279  private:
280  // object ids of all objects with active Manipulator
281  std::vector< int > activeManipulators_;
282  // Size for the manipulators
283  double manip_size_;
284  // Modifier for the Size (changed by Mousewheel Events)
285  double manip_size_modifier_;
286 
287  // Object marker to dimm Objects during manipulator transformation
288  SkeletonMarker objectMarker_;
289 
290  ACG::Matrix4x4d accumMatrix_;
291 
292  private:
294  void placeManip(QMouseEvent* _event);
295 
297  void showManipulators();
298 
300  void updateManipulatorPosition(BaseObjectData* _skeletonObj);
301 
303  void inverseKinematic(ACG::Vec3d dest,Skeleton::Pose* currentPose,Skeleton::Joint* pickedJoint, std::vector<Skeleton::Joint*> rotatableJoints);
304 
305  private slots:
307  void manipulatorMoved( QtTranslationManipulatorNode* _node , QMouseEvent* _event);
308 
311 
312  void slotRotateManipulator(bool _toggled);
313 };
314 
315 #endif //SKELETONEDITINGPLUGIN_HH
void manipulatorMoved(QtTranslationManipulatorNode *_node, QMouseEvent *_event)
move the object when its manipulator moves
Interface class from which all plugins have to be created.
Keyboard Event Interface.
Definition: KeyInterface.hh:76
QString description()
Description of the Plugin.
Matrix4x4 globalMatrix(int _objectId, int _jointId)
get global matrix of a joint in the active pose
QString lastRenderer_
Stores the last active renderer before we switched to skeleton editing mode.
Logtype
Log types for Message Window.
Matrix4x4 localMatrix(int _objectId, int _jointId)
get local matrix of a joint in the active pose
Vector globalTranslation(int _objectId, int _jointId)
get global translation of a joint in the active pose
void updateManipulatorPosition(BaseObjectData *_skeletonObj)
make sure the manipulator is positioned on a joint
void ManipulatorPositionChanged(QtTranslationManipulatorNode *_node)
update object when its manipulator changes position
void setDescriptions()
Set Descriptions for Scripting Slots.
Update type class.
Definition: UpdateType.hh:70
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool rendererChanged_
Remembers, if we changed the renderer.
OpenMesh::Vec3d getNearestJoint(SkeletonObject *_skeletonObj, OpenMesh::Vec3d &_hitPoint, int &_bestJointID)
Get nearest joint to hitPoint (used for snapping)
void addAnimation(int _objectId, QString _name, int _frames)
add animation
~SkeletonEditingPlugin()
Destructor.
bool canModify(QMouseEvent *_event)
checks, if the skeleton can be modified. a skeleton can be modified, if the active pose is the refere...
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:68
Interface for all Plugins which do logging to the logging window of the framework.
void placeManip(QMouseEvent *_event)
Place and show the Manipulator.
Interface to call functions across plugins.
Definition: RPCInterface.hh:71
void slotPickModeChanged(const std::string &_mode)
slot is called when the pickMode changed
SkeletonEditingPlugin()
Default Constructor.
void splitJoint(QMouseEvent *_event)
split selected Joint
Add a toolbox to OpenFlipper.
Interface for all Plugins which provide scriptable Functions.
Interface for all plugins which want to Load or Save files and create Objects.
void splitBone(int _objectId, int _tailJoint)
insert a joint in the middle of a bone given by its (unique) tailJoint
void pluginsInitialized()
Initialization of the plugin when it is loaded by the core.
Allow access to picking functions.
Interface class for backup handling.
void slotMouseEvent(QMouseEvent *_event)
MousePress event occured.
Interface class for creating custom context menus.
Interface class for receiving mouse events.
int animationCount(int _objectId)
get the number of animations
void setActivePose(int _objectId, int _animationIndex, int _frame)
set active pose
void transformJoint(int _objectId, int _jointId, Matrix4x4 _matrix)
transform joint with given matrix
Plugins can add its own toolbox to the main widget's toolbox area by using this interface.
QString name()
Name of the Plugin.
Predefined datatypes.
Definition: DataTypes.hh:96
Vector localTranslation(int _objectId, int _jointId)
get local translation of a joint in the active pose
int activeFrame(int _objectId)
get active frame
void inverseKinematic(ACG::Vec3d dest, Skeleton::Pose *currentPose, Skeleton::Joint *pickedJoint, std::vector< Skeleton::Joint * > rotatableJoints)
function for computing the position of our joints using inverse Kinematic
void showManipulators()
Show/Hide active manipulators.
Represents a single joint in the skeleton.
Definition: JointT.hh:66
int frameCount(int _objectId, int _animationIndex)
get the number of frames
void addJoint(int _objectId, int _parent, Vector _position)
add joint to the skeleton
int activeAnimation(int _objectId)
get active animation