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