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