Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef SKELETON_SUBTOOLS_INCLUDED
Toshihiro Shimizu 890ddd
#define SKELETON_SUBTOOLS_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/skeleton.h"
Toshihiro Shimizu 890ddd
#include "toonz/stageobjectutil.h"
Toshihiro Shimizu 890ddd
#include "toonz/ikengine.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qobject></qobject>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class SkeletonTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace SkeletonSubtools
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	SkeletonTool *m_tool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragTool(SkeletonTool *tool) : m_tool(tool) {}
Toshihiro Shimizu 890ddd
	virtual ~DragTool() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void draw() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void leftButtonDown(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual void leftButtonUp(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	SkeletonTool *getTool() const { return m_tool; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragCenterTool : public DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStageObjectId m_objId;
Toshihiro Shimizu 890ddd
	int m_frame;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD m_firstPos;
Toshihiro Shimizu 890ddd
	TPointD m_oldCenter;
Toshihiro Shimizu 890ddd
	TPointD m_center;
Toshihiro Shimizu 890ddd
	TAffine m_affine;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragCenterTool(SkeletonTool *tool);
Toshihiro Shimizu 890ddd
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
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragChannelTool : public DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TStageObjectValues m_before, m_after;
Toshihiro Shimizu 890ddd
	bool m_dragged;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragChannelTool(SkeletonTool *tool, TStageObject::Channel a0);
Toshihiro Shimizu 890ddd
	DragChannelTool(SkeletonTool *tool, TStageObject::Channel a0, TStageObject::Channel a1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void start();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD getCenter();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getOldValue(int index) const { return m_before.getValue(index); }
Toshihiro Shimizu 890ddd
	double getValue(int index) const { return m_after.getValue(index); }
Toshihiro Shimizu 890ddd
	void setValue(double v)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_after.setValue(v);
Toshihiro Shimizu 890ddd
		m_after.applyValues();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void setValues(double v0, double v1)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_after.setValues(v0, v1);
Toshihiro Shimizu 890ddd
		m_after.applyValues();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &pos, const TMouseEvent &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragPositionTool : public DragChannelTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD m_firstPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragPositionTool(SkeletonTool *tool);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragRotationTool : public DragChannelTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD m_lastPos;
Toshihiro Shimizu 890ddd
	TPointD m_center;
Toshihiro Shimizu 890ddd
	bool m_snapped;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragRotationTool(SkeletonTool *tool, bool snapped);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ParentChangeTool : public DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTool::Viewer *m_viewer;
Toshihiro Shimizu 890ddd
	TPoint m_firstWinPos;
Toshihiro Shimizu 890ddd
	TPointD m_lastPos, m_lastPos2;
Toshihiro Shimizu 890ddd
	TPointD m_center;
Toshihiro Shimizu 890ddd
	int m_index;
Toshihiro Shimizu 890ddd
	int m_handle;
Toshihiro Shimizu 890ddd
	bool m_snapped;
Toshihiro Shimizu 890ddd
	int m_mode;
Toshihiro Shimizu 890ddd
	TAffine m_affine;
Toshihiro Shimizu 890ddd
	TStageObjectId m_objId;
Toshihiro Shimizu 890ddd
	TPointD m_oldCenter, m_oldOffset;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	struct Peer {
Toshihiro Shimizu 890ddd
		TPointD m_pos;
Toshihiro Shimizu 890ddd
		int m_columnIndex;
Toshihiro Shimizu 890ddd
		int m_handle; // 0=centerB,-1,-2,....=H1,H2...
Toshihiro Shimizu 890ddd
		int m_name;   // per glPushName()
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	struct Element {
Toshihiro Shimizu 890ddd
		int m_columnIndex;
Toshihiro Shimizu 890ddd
		TRectD m_bbox;
Toshihiro Shimizu 890ddd
		TAffine m_aff;
Toshihiro Shimizu 890ddd
		std::vector<peer> m_peers;</peer>
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	std::map<int, element=""> m_elements;</int,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double m_pixelSize;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ParentChangeTool(SkeletonTool *tool, TTool::Viewer *viewer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &pos, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class IKToolUndo;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class IKTool : public DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTool::Viewer *m_viewer;
Toshihiro Shimizu 890ddd
	TPointD m_pos;
Toshihiro Shimizu 890ddd
	Skeleton *m_skeleton;
Toshihiro Shimizu 890ddd
	int m_columnIndex;
Toshihiro Shimizu 890ddd
	IKEngine m_engine;
Toshihiro Shimizu 890ddd
	bool m_valid;
Toshihiro Shimizu 890ddd
	TAffine m_footPlacement, m_firstFootPlacement;
Toshihiro Shimizu 890ddd
	TStageObject *m_foot, *m_firstFoot;
Toshihiro Shimizu 890ddd
	bool m_IHateIK;
Toshihiro Shimizu 890ddd
	IKToolUndo *m_undo;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	struct Joint {
Toshihiro Shimizu 890ddd
		Skeleton::Bone *m_bone, *m_prevBone;
Toshihiro Shimizu 890ddd
		int m_prevColumnIndex;
Toshihiro Shimizu 890ddd
		double m_angleOffset;
Toshihiro Shimizu 890ddd
		double m_sign;
Toshihiro Shimizu 890ddd
		bool m_active;
Toshihiro Shimizu 890ddd
		TStageObjectValues m_oldValues;
Toshihiro Shimizu 890ddd
		Joint()
Toshihiro Shimizu 890ddd
			: m_bone(0), m_prevBone(0), m_angleOffset(0), m_sign(1), m_active(true) {}
Toshihiro Shimizu 890ddd
		Joint(Skeleton::Bone *bone, Skeleton::Bone *prevBone, double sign)
Toshihiro Shimizu 890ddd
			: m_bone(bone), m_prevBone(prevBone), m_angleOffset(0), m_sign(sign), m_active(true) {}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	std::vector<joint> m_joints;</joint>
Toshihiro Shimizu 890ddd
	bool isParentOf(int columnIndex, int childColumnIndex) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	IKTool(SkeletonTool *tool, TTool::Viewer *viewer, Skeleton *skeleton, int columnIndex);
Toshihiro Shimizu 890ddd
	~IKTool();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void initEngine(const TPointD &pos);
Toshihiro Shimizu 890ddd
	void storeOldValues();
Toshihiro Shimizu 890ddd
	void computeIHateIK();
Toshihiro Shimizu 890ddd
	void setAngleOffsets();
Toshihiro Shimizu 890ddd
	void apply();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ChangeDrawingTool : public DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int m_oldY;
Toshihiro Shimizu 890ddd
	int m_dir;
Toshihiro Shimizu 890ddd
	TUndo *m_undo;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ChangeDrawingTool(SkeletonTool *tool, int d);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool changeDrawing(int delta);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CommandHandler : public QObject
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_OBJECT
Toshihiro Shimizu 890ddd
	Skeleton *m_skeleton;
Toshihiro Shimizu 890ddd
	std::set<int> *m_tempPinnedSet;</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	CommandHandler();
Toshihiro Shimizu 890ddd
	~CommandHandler();
Toshihiro Shimizu 890ddd
	void setTempPinnedSet(std::set<int> *tempPinnedSet) { m_tempPinnedSet = tempPinnedSet; }</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setSkeleton(Skeleton *skeleton);
Toshihiro Shimizu 890ddd
public slots:
Toshihiro Shimizu 890ddd
	void clearPinnedRanges();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace SkeletonSubtools
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif