SkeletonEditingPlugin.hh 8.54 KB
Newer Older
Dirk Wilden's avatar
Dirk Wilden committed
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 37 38 39 40 41
#ifndef SKELETONEDITINGPLUGIN_HH
#define SKELETONEDITINGPLUGIN_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/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/common/Types.hh>

#include <ObjectTypes/Skeleton/Skeleton.hh>
#include "SkeletonMarker.hh"

/** Plugin for creating and editing skeletons
*/
class SkeletonEditingPlugin : public QObject, BaseInterface, MouseInterface, KeyInterface, PickingInterface, ToolboxInterface, LoggingInterface, ScriptInterface,ToolbarInterface, ContextMenuInterface, LoadSaveInterface, BackupInterface, RPCInterface
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(MouseInterface)
  Q_INTERFACES(KeyInterface)
  Q_INTERFACES(PickingInterface)
  Q_INTERFACES(ToolboxInterface)
  Q_INTERFACES(LoggingInterface)
  Q_INTERFACES(ContextMenuInterface)
  Q_INTERFACES(ScriptInterface)
  Q_INTERFACES(ToolbarInterface)
  Q_INTERFACES(LoadSaveInterface)
  Q_INTERFACES(BackupInterface)
  Q_INTERFACES(RPCInterface)

Matthias Möller's avatar
Matthias Möller committed
42 43 44 45
#if QT_VERSION >= 0x050000
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SkeletonEditing")
#endif

Dirk Wilden's avatar
Dirk Wilden committed
46 47 48
  signals:
    // BaseInterface
    void updateView();
49
    void updatedObject(int, const UpdateType& _type);
Dirk Wilden's avatar
Dirk Wilden committed
50 51
    void nodeVisibilityChanged(int);

52 53 54
    void setRenderer(unsigned int _viewer, QString _rendererName);
    void getCurrentRenderer(unsigned int _viewer, QString& _rendererName);

Dirk Wilden's avatar
Dirk Wilden committed
55
    // PickingInterface
56 57 58 59
    void addPickMode( const std::string& _mode );
    void addHiddenPickMode( const std::string& _mode );
    void setPickModeMouseTracking (const std::string& _mode, bool _mouseTracking);
    void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
Dirk Wilden's avatar
Dirk Wilden committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

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

    // 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);

    // KeyInterface
    void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);

    // ToolboxInterface
    void addToolbox( QString _name  , QWidget* _widget );

    // LoadSaveInterface
    void addEmptyObject(DataType _type, int& _id);
    void deleteObject( int _id);

    // BackupInterface
Dirk Wilden's avatar
Dirk Wilden committed
88
    void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL );
Dirk Wilden's avatar
Dirk Wilden committed
89 90 91 92 93 94

  private slots :

    // BaseInterface
    void initializePlugin();
    void pluginsInitialized();
95
    void slotObjectUpdated( int _id, const UpdateType& _type);
Dirk Wilden's avatar
Dirk Wilden committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109

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

    // KeyInterface
    void slotKeyEvent (QKeyEvent* _event);
    void slotKeyReleaseEvent (QKeyEvent* _event);

    // PickingInterface
    void slotPickModeChanged( const std::string& _mode);

  private:
    void moveJoint(QMouseEvent* _event);
110
    bool canModify(QMouseEvent* _event);
Dirk Wilden's avatar
Dirk Wilden committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 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
    void insertJoint(QMouseEvent* _event);
    void cancelJointInsertion();
    void deleteJoint(QMouseEvent* _event);
    void selectJoint(QMouseEvent* _event);

    Skeleton::Pose* activePose(SkeletonObject* _skeletonObj);
    void setJointPosition(SkeletonObject* _skeletonObj, Skeleton::Joint* _joint, ACG::Vec3d& _position);

    OpenMesh::Vec3d getNearestJoint(SkeletonObject* _skeletonObj, OpenMesh::Vec3d &_hitPoint, int& _bestJointID);
  public:

    /// Default Constructor
    SkeletonEditingPlugin();

    /// Destructor
    ~SkeletonEditingPlugin();

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

    /// Description of the Plugin
    QString description() { return (QString(tr("Create and edit skeletons"))); };


//===========================================================================
/** @name Scriptable Functions
  * @{ */
//===========================================================================

  public slots:
    /// insert a joint in the middle of a bone given by its (unique) tailJoint
    void splitBone( int _objectId, int _tailJoint);

    /// add joint to the skeleton
    void addJoint( int _objectId, int _parent, Vector _position );

    /// delete joint from the skeleton
    void deleteJoint( int _objectId , int _jointId );

    /// transform joint with given matrix
    void transformJoint( int _objectId , int _jointId, Matrix4x4 _matrix );

    /// get global matrix of a joint in the active pose
    Matrix4x4 globalMatrix(int _objectId, int _jointId);

    /// get local matrix of a joint in the active pose
    Matrix4x4 localMatrix(int _objectId, int _jointId);

    /// get global translation of a joint in the active pose
    Vector globalTranslation(int _objectId, int _jointId);

    /// get local translation of a joint in the active pose
    Vector localTranslation(int _objectId, int _jointId);

    /// get the number of animations
    int animationCount(int _objectId);

    /// get the number of frames
    int frameCount(int _objectId, int _animationIndex);

    /// get active animation
    int activeAnimation(int _objectId);

    /// get active frame
    int activeFrame(int _objectId);

    /// set active pose
    void setActivePose(int _objectId, int _animationIndex, int _frame);

    /// add animation
    void addAnimation(int _objectId, QString _name, int _frames);

183 184 185
    /// split selected Joint
    void splitJoint(QMouseEvent* _event);

Dirk Wilden's avatar
Dirk Wilden committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
/** @} */

  public slots:
    QString version() { return QString("1.0"); };


  private slots:
    void slotSetEditingMode(QAction* _action);
    void slotPickToolbarAction(QAction* _action);

    void setDescriptions();

  private:
    QToolBar*     toolbar_;
    QActionGroup* toolBarActions_;
    QAction*      skeletonEditingAction_;

    QToolBar*     pickToolbar_;
    QActionGroup* pickToolBarActions_;
    QAction*      selectJointAction_;
    QAction*      insertJointAction_;
207
    QAction*			splitJointAction_;
Dirk Wilden's avatar
Dirk Wilden committed
208 209 210 211 212
    QAction*      deleteJointAction_;
    QAction*      moveJointAction_;
    QAction*      transformChildManipAction_;
    QAction*      transformAllManipAction_;
    QAction*      rotateManipAction_;
213
    QAction*      inverseKinematicAction_;
Dirk Wilden's avatar
Dirk Wilden committed
214 215 216 217 218 219 220

    int currentSkeleton_;
    int currentJoint_;
    bool jointPreview_;
    
    bool transformChildJoints_;
    bool transformAllFrames_;
221
    bool inverseKinematic_;
Dirk Wilden's avatar
Dirk Wilden committed
222
    
Jan Möbius's avatar
Jan Möbius committed
223 224
    bool dblClick_;

225 226 227 228 229
    /// Stores the last active renderer before we switched to skeleton editing mode
    QString lastRenderer_;
    /// Remembers, if we changed the renderer
    bool rendererChanged_;

Dirk Wilden's avatar
Dirk Wilden committed
230 231 232 233 234 235 236 237 238 239 240
  private:
    // object ids of all objects with active Manipulator
    std::vector< int > activeManipulators_;
    // Size for the manipulators
    double manip_size_;
    // Modifier for the Size (changed by Mousewheel Events)
    double manip_size_modifier_;

    // Object marker to dimm Objects during manipulator transformation
    SkeletonMarker objectMarker_;

Dirk Wilden's avatar
Dirk Wilden committed
241 242
    ACG::Matrix4x4d accumMatrix_;

Dirk Wilden's avatar
Dirk Wilden committed
243 244 245 246 247 248 249 250 251 252
  private:
    /// Place and show the Manipulator
    void placeManip(QMouseEvent* _event);

    /// Show/Hide active manipulators
    void showManipulators();

    /// make sure the manipulator is positioned on a joint
    void updateManipulatorPosition(BaseObjectData* _skeletonObj);

253 254 255
    ///function for computing the position of our joints using inverse Kinematic
    void inverseKinematic(ACG::Vec3d dest,Skeleton::Pose* currentPose,Skeleton::Joint* pickedJoint, std::vector<Skeleton::Joint*> rotatableJoints);

Dirk Wilden's avatar
Dirk Wilden committed
256 257 258 259 260 261 262 263 264 265 266
  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 );

    void slotRotateManipulator(bool _toggled);
};

#endif //SKELETONEDITINGPLUGIN_HH