SkeletonEditingPlugin.hh 11.7 KB
Newer Older
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
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
42

43

Dirk Wilden's avatar
Dirk Wilden committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#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"

67 68
#include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>

Dirk Wilden's avatar
Dirk Wilden committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/** 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)

87 88
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SkeletonEditing")

Dirk Wilden's avatar
Dirk Wilden committed
89 90 91
  signals:
    // BaseInterface
    void updateView();
92
    void updatedObject(int, const UpdateType& _type);
Dirk Wilden's avatar
Dirk Wilden committed
93 94
    void nodeVisibilityChanged(int);

95 96 97
    void setRenderer(unsigned int _viewer, QString _rendererName);
    void getCurrentRenderer(unsigned int _viewer, QString& _rendererName);

Dirk Wilden's avatar
Dirk Wilden committed
98
    // PickingInterface
99 100 101 102
    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
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

    // 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
131
    void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL );
Dirk Wilden's avatar
Dirk Wilden committed
132 133 134 135 136 137

  private slots :

    // BaseInterface
    void initializePlugin();
    void pluginsInitialized();
138
    void slotObjectUpdated( int _id, const UpdateType& _type);
Dirk Wilden's avatar
Dirk Wilden committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152

    // 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);
153
    bool canModify(QMouseEvent* _event);
Dirk Wilden's avatar
Dirk Wilden committed
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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
    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);

226 227 228
    /// split selected Joint
    void splitJoint(QMouseEvent* _event);

Dirk Wilden's avatar
Dirk Wilden committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
/** @} */

  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_;
250
    QAction*			splitJointAction_;
Dirk Wilden's avatar
Dirk Wilden committed
251 252 253 254 255
    QAction*      deleteJointAction_;
    QAction*      moveJointAction_;
    QAction*      transformChildManipAction_;
    QAction*      transformAllManipAction_;
    QAction*      rotateManipAction_;
256
    QAction*      inverseKinematicAction_;
Dirk Wilden's avatar
Dirk Wilden committed
257 258 259 260 261 262 263

    int currentSkeleton_;
    int currentJoint_;
    bool jointPreview_;
    
    bool transformChildJoints_;
    bool transformAllFrames_;
264
    bool inverseKinematic_;
Dirk Wilden's avatar
Dirk Wilden committed
265
    
Jan Möbius's avatar
Jan Möbius committed
266 267
    bool dblClick_;

268 269 270 271 272
    /// 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
273 274 275 276 277 278 279 280 281 282 283
  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_;

284 285
    ACG::Matrix4x4d accumMatrix_;

Dirk Wilden's avatar
Dirk Wilden committed
286 287 288 289 290 291 292 293 294 295
  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);

296 297 298
    ///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
299 300 301 302 303 304 305 306 307 308 309
  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