SkeletonEditingPlugin.hh 7.74 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#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)

  signals:
    // BaseInterface
    void updateView();
    void updatedObject(int, const UpdateType _type);
    void nodeVisibilityChanged(int);

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

    // 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
81
    void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL );
Dirk Wilden's avatar
Dirk Wilden committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

  private slots :

    // BaseInterface
    void initializePlugin();
    void pluginsInitialized();
    void slotObjectUpdated( int _id, const UpdateType _type);

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

/** @} */

  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_;
    QAction*      deleteJointAction_;
    QAction*      moveJointAction_;
    QAction*      transformChildManipAction_;
    QAction*      transformAllManipAction_;
    QAction*      rotateManipAction_;
201
    QAction*      inverseKinematicAction_;
Dirk Wilden's avatar
Dirk Wilden committed
202 203 204 205 206 207 208

    int currentSkeleton_;
    int currentJoint_;
    bool jointPreview_;
    
    bool transformChildJoints_;
    bool transformAllFrames_;
209
    bool inverseKinematic_;
Dirk Wilden's avatar
Dirk Wilden committed
210
    
Jan Möbius's avatar
Jan Möbius committed
211 212
    bool dblClick_;

Dirk Wilden's avatar
Dirk Wilden committed
213 214 215 216 217 218 219 220 221 222 223
  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
224 225
    ACG::Matrix4x4d accumMatrix_;

Dirk Wilden's avatar
Dirk Wilden committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
  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);

  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