2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef SKELETON_TOOL_INCLUDED
|
|
|
|
#define SKELETON_TOOL_INCLUDED
|
|
|
|
|
|
|
|
#include "tools/tool.h"
|
|
|
|
#include "tgeometry.h"
|
|
|
|
#include "tproperty.h"
|
|
|
|
#include "toonz/hook.h"
|
|
|
|
#include "toonz/skeleton.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace SkeletonSubtools {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
class DragTool;
|
|
|
|
class CommandHandler;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class HookData {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
int m_columnIndex;
|
|
|
|
int m_hookId; // 0=center (e.g. B,C,...), 1,2... = hook
|
|
|
|
TPointD m_pos;
|
|
|
|
std::string m_name; // name visualized in the balloons
|
|
|
|
bool m_isPivot; // true if this is the level "pivot", i.e. the current handle
|
|
|
|
HookData(TXsheet *xsh, int columnIndex, int hookId, const TPointD &pos);
|
|
|
|
std::string getHandle() const { return m_hookId > 0 ? "H" + m_name : m_name; }
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class MagicLink {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
HookData m_h0, m_h1;
|
|
|
|
double m_dist2;
|
|
|
|
MagicLink(const HookData &h0, const HookData &h1, double dist2)
|
|
|
|
: m_h0(h0), m_h1(h1), m_dist2(dist2) {}
|
|
|
|
bool operator<(const MagicLink &link) const { return m_dist2 < link.m_dist2; }
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class SkeletonTool : public TTool {
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(SkeletonTool)
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
SkeletonSubtools::DragTool *m_dragTool;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPointD m_lastPos;
|
|
|
|
TPointD m_curPos;
|
|
|
|
TPointD m_firstPos;
|
|
|
|
TPointD m_curCenter;
|
|
|
|
TPointD m_parentProbe;
|
|
|
|
bool m_parentProbeEnabled;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool m_active;
|
|
|
|
bool m_firstTime;
|
|
|
|
int m_device;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TEnumProperty m_mode;
|
|
|
|
TBoolProperty m_showOnlyActiveSkeleton;
|
|
|
|
TBoolProperty m_globalKeyframes;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPropertyGroup m_prop;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::vector<SkeletonSubtools::MagicLink> m_magicLinks;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::set<int> m_temporaryPinnedColumns;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int m_currentFrame;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
SkeletonSubtools::CommandHandler *m_commandHandler;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// column currently selected, during a click&drag operation
|
|
|
|
int m_otherColumn;
|
|
|
|
TRectD m_otherColumnBBox;
|
|
|
|
TAffine m_otherColumnBBoxAff;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPointD m_labelPos;
|
|
|
|
std::string m_label;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
SkeletonTool();
|
|
|
|
~SkeletonTool();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
ToolType getToolType() const override { return TTool::ColumnTool; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
void updateTranslation() override; // QString localization stuff
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool doesApply() const; // ritorna vero se posso deformare l'oggetto corrente
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
void onEnter() override {}
|
|
|
|
void leftButtonDown(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
void leftButtonDrag(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
|
|
|
|
void mouseMove(const TPointD &, const TMouseEvent &e) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
void onImageChanged() override { invalidate(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
void reset() override { m_temporaryPinnedColumns.clear(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
bool onPropertyChanged(std::string propertyName) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
void draw() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void drawSkeleton(const Skeleton &skeleton, int row);
|
|
|
|
void drawLevelBoundingBox(int frame, int columnIndex);
|
|
|
|
void getImageBoundingBox(TRectD &bbox, TAffine &aff, int frame,
|
|
|
|
int columnIndex);
|
|
|
|
void drawIKJoint(const Skeleton::Bone *bone);
|
|
|
|
void drawJoint(const TPointD &p, bool current);
|
|
|
|
void drawBone(const TPointD &a, const TPointD &b, bool selected);
|
|
|
|
void drawIKBone(const TPointD &a, const TPointD &b);
|
|
|
|
void drawMainGadget(const TPointD ¢er);
|
|
|
|
void drawDrawingBrowser(const TXshCell &cell, const TPointD ¢er);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setParentProbe(const TPointD &parentProbe) {
|
|
|
|
m_parentProbe = parentProbe;
|
|
|
|
m_parentProbeEnabled = true;
|
|
|
|
}
|
|
|
|
void resetParentProbe() { m_parentProbeEnabled = false; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void drawHooks();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void computeMagicLinks();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2018-02-19 19:34:13 +13:00
|
|
|
bool keyDown(QKeyEvent *event) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
void onActivate() override;
|
|
|
|
void onDeactivate() override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int getMagicLinkCount() const { return (int)m_magicLinks.size(); }
|
|
|
|
SkeletonSubtools::MagicLink getMagicLink(int index) const;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void magicLink(int index);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
int getCursorId() const override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// TRaster32P getToolIcon() const {return Pixmaps::arrow;}
|
2020-09-16 09:49:57 +12:00
|
|
|
TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2020-09-16 09:49:57 +12:00
|
|
|
void updateMatrix() override { setMatrix(getCurrentObjectParentMatrix()); }
|
|
|
|
void addContextMenuItems(QMenu *menu) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
bool select(const TSelection *) { return false; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void togglePinnedStatus(int columnIndex, int frame, bool shiftPressed);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void buildSkeleton(Skeleton &skeleton, int columnIndex);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void setTemporaryPinnedColumns(const std::set<int> &tmp) {
|
|
|
|
m_temporaryPinnedColumns = tmp;
|
|
|
|
}
|
|
|
|
bool isGlobalKeyframesEnabled() const;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|