Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
#include "toonz/stageobjectutil.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjecttree.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjectspline.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcamera.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tfxhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjectcmd.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "edittoolgadgets.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// For Qt translation support
Toshihiro Shimizu 890ddd
#include <qcoreapplication></qcoreapplication>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qdebug></qdebug>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// Scale Constraints
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace ScaleConstraints
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
enum { None = 0,
Toshihiro Shimizu 890ddd
	   AspectRatio,
Toshihiro Shimizu 890ddd
	   Mass };
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::IntVar LockCenterX("EditToolLockCenterX", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockCenterY("EditToolLockCenterY", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockPositionX("EditToolLockPositionX", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockPositionY("EditToolLockPositionY", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockRotation("EditToolLockRotation", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockShearH("EditToolLockShearH", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockShearV("EditToolLockShearV", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockScaleH("EditToolLockScaleH", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockScaleV("EditToolLockScaleV", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar LockGlobalScale("EditToolLockGlobalScale", 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowEWNSposition("EditToolShowEWNSposition", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowZposition("EditToolShowZposition", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowSOposition("EditToolShowSOposition", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowRotation("EditToolShowRotation", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowGlobalScale("EditToolShowGlobalScale", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowHVscale("EditToolShowHVscale", 1);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowShear("EditToolShowShear", 0);
Toshihiro Shimizu 890ddd
TEnv::IntVar ShowCenterPosition("EditToolShowCenterPosition", 0);
Toshihiro Shimizu 890ddd
TEnv::StringVar Active("EditToolActiveAxis", "Position");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using EditToolGadgets::DragTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragCenterTool
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
	bool m_lockCenterX;
Toshihiro Shimizu 890ddd
	bool m_lockCenterY;
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(bool lockCenterX, bool lockCenterY)
Toshihiro Shimizu 890ddd
		: m_objId(TTool::getApplication()->getCurrentTool()->getTool()->getObjectId()), m_frame(TTool::getApplication()->getCurrentTool()->getTool()->getFrame()), m_lockCenterX(lockCenterX), m_lockCenterY(lockCenterY)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockCenterX && m_lockCenterY)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TXsheet *xsh = TTool::getApplication()->getCurrentTool()->getTool()->getXsheet();
Toshihiro Shimizu 890ddd
		m_center = m_oldCenter = xsh->getCenter(m_objId, m_frame);
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
		m_affine = xsh->getPlacement(m_objId, m_frame).inv() * xsh->getParentPlacement(m_objId, m_frame);
Toshihiro Shimizu 890ddd
		m_affine.a13 = m_affine.a23 = 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockCenterX && m_lockCenterY)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		double factor = 1.0 / Stage::inch;
Toshihiro Shimizu 890ddd
		TPointD delta = pos - m_firstPos;
Toshihiro Shimizu 890ddd
		if (m_lockCenterX)
Toshihiro Shimizu 890ddd
			delta = TPointD(0.0, delta.y);
Toshihiro Shimizu 890ddd
		else if (m_lockCenterY)
Toshihiro Shimizu 890ddd
			delta = TPointD(delta.x, 0.0);
Toshihiro Shimizu 890ddd
		m_center = m_oldCenter + (m_affine * delta) * factor;
Toshihiro Shimizu 890ddd
		TTool::getApplication()->getCurrentTool()->getTool()->getXsheet()->setCenter(m_objId, m_frame, m_center);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if ((m_lockCenterX && m_lockCenterY) || m_firstPos == pos)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		UndoStageObjectCenterMove *undo = new UndoStageObjectCenterMove(m_objId, m_frame, m_oldCenter, m_center);
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		undo->setObjectHandle(app->getCurrentObject());
Toshihiro Shimizu 890ddd
		undo->setXsheetHandle(app->getCurrentXsheet());
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragChannelTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragChannelTool : public DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TStageObjectValues m_before, m_after;
Toshihiro Shimizu 890ddd
	bool m_globalKeyframesEnabled;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_isStarted;
Toshihiro Shimizu 890ddd
	TPointD m_firstPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragChannelTool(TStageObject::Channel a0, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: m_globalKeyframesEnabled(globalKeyframesEnabled), m_isStarted(false), m_firstPos()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		m_before.setFrameHandle(app->getCurrentFrame());
Toshihiro Shimizu 890ddd
		m_before.setObjectHandle(app->getCurrentObject());
Toshihiro Shimizu 890ddd
		m_before.setXsheetHandle(app->getCurrentXsheet());
Toshihiro Shimizu 890ddd
		m_before.add(a0);
Toshihiro Shimizu 890ddd
		if (m_globalKeyframesEnabled) {
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Angle);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_X);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Y);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Z);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_SO);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_ScaleX);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_ScaleY);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Scale);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Path);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_ShearX);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_ShearY);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_after = m_before;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	DragChannelTool(TStageObject::Channel a0, TStageObject::Channel a1, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: m_globalKeyframesEnabled(globalKeyframesEnabled), m_isStarted(false), m_firstPos()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		m_before.setFrameHandle(app->getCurrentFrame());
Toshihiro Shimizu 890ddd
		m_before.setObjectHandle(app->getCurrentObject());
Toshihiro Shimizu 890ddd
		m_before.setXsheetHandle(app->getCurrentXsheet());
Toshihiro Shimizu 890ddd
		m_before.add(a0);
Toshihiro Shimizu 890ddd
		m_before.add(a1);
Toshihiro Shimizu 890ddd
		if (m_globalKeyframesEnabled) {
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Angle);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_X);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Y);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Z);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_SO);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_ScaleX);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_ScaleY);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Scale);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_Path);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_ShearX);
Toshihiro Shimizu 890ddd
			m_before.add(TStageObject::T_ShearY);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_after = m_before;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void enableGlobalKeyframes(bool enabled) { m_globalKeyframesEnabled = enabled; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void start()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_isStarted = true;
Toshihiro Shimizu 890ddd
		m_before.updateValues();
Toshihiro Shimizu 890ddd
		m_after = m_before;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD getCenter()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();
Toshihiro Shimizu 890ddd
		TStageObjectId objId = tool->getObjectId();
Toshihiro Shimizu 890ddd
		int frame = tool->getFrame();
Toshihiro Shimizu 890ddd
		TXsheet *xsh = tool->getXsheet();
Toshihiro Shimizu 890ddd
		return xsh->getParentPlacement(objId, frame).inv() * xsh->getPlacement(objId, frame) * (Stage::inch * xsh->getCenter(objId, frame));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getOldValue(int index) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_before.getValue(index);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	double getValue(int index) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_after.getValue(index);
Toshihiro Shimizu 890ddd
	}
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
		if (!m_isStarted || m_firstPos == pos)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			m_isStarted = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		UndoStageObjectMove *undo = new UndoStageObjectMove(m_before, m_after);
Toshihiro Shimizu 890ddd
		undo->setObjectHandle(app->getCurrentObject());
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
		app->getCurrentScene()->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragPositionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragPositionTool : public DragChannelTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool m_lockPositionX;
Toshihiro Shimizu 890ddd
	bool m_lockPositionY;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragPositionTool(bool lockPositionX, bool lockPositionY, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: DragChannelTool(TStageObject::T_X, TStageObject::T_Y, globalKeyframesEnabled), m_lockPositionX(lockPositionX), m_lockPositionY(lockPositionY)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockPositionX && m_lockPositionY)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		start();
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockPositionX && m_lockPositionY)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TPointD delta = pos - m_firstPos;
Toshihiro Shimizu 890ddd
		if (m_lockPositionX)
Toshihiro Shimizu 890ddd
			delta = TPointD(0, delta.y);
Toshihiro Shimizu 890ddd
		else if (m_lockPositionY)
Toshihiro Shimizu 890ddd
			delta = TPointD(delta.x, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
			if (fabs(delta.x) > fabs(delta.y))
Toshihiro Shimizu 890ddd
				delta.y = 0;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				delta.x = 0;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		double factor = 1.0 / Stage::inch;
Toshihiro Shimizu 890ddd
		setValues(getOldValue(0) + delta.x * factor, getOldValue(1) + delta.y * factor);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragSplinePositionTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragSplinePositionTool : public DragChannelTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const TStroke *m_spline;
Toshihiro Shimizu 890ddd
	std::vector<double> m_lengthAtCPs;</double>
Toshihiro Shimizu 890ddd
	double m_offset;
Toshihiro Shimizu 890ddd
	double m_splineLength;
Toshihiro Shimizu 890ddd
	double m_tolerance;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragSplinePositionTool(const TStroke *spline, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: DragChannelTool(TStageObject::T_Path, globalKeyframesEnabled), m_spline(spline), m_offset(0.0), m_splineLength(0), m_tolerance(0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getLengthAtPos(const TPointD &pos) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(m_spline);
Toshihiro Shimizu 890ddd
		double t = m_spline->getW(pos);
Toshihiro Shimizu 890ddd
		return m_spline->getLength(t);
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
    double length = m_spline->getLength();
Toshihiro Shimizu 890ddd
    if(length>0) return 100 * m_spline->getLength(t) / length;
Toshihiro Shimizu 890ddd
    else return 0.0;
Toshihiro Shimizu 890ddd
    */
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double paramValueToLength(double s) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return s * m_splineLength * 0.01;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	double lengthToParamValue(double len) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_splineLength > 0)
Toshihiro Shimizu 890ddd
			return 100 * len / m_splineLength;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			return 0.0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
		start();
Toshihiro Shimizu 890ddd
		assert(m_spline);
Toshihiro Shimizu 890ddd
		m_tolerance = sqrt(tglGetPixelSize2()) * 10;
Toshihiro Shimizu 890ddd
		m_splineLength = m_spline->getLength();
Toshihiro Shimizu 890ddd
		m_lengthAtCPs.clear();
Toshihiro Shimizu 890ddd
		int n = m_spline->getControlPointCount();
Toshihiro Shimizu 890ddd
		for (int i = 0; i < n; i += 4)
Toshihiro Shimizu 890ddd
			m_lengthAtCPs.push_back(m_spline->getLengthAtControlPoint(i));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_offset = paramValueToLength(getOldValue(0)) - getLengthAtPos(pos);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool snapLengthToControlPoint(double &len) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int n = (int)m_lengthAtCPs.size();
Toshihiro Shimizu 890ddd
		if (n <= 0)
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		double cpLen = len;
Toshihiro Shimizu 890ddd
		int k = 0;
Toshihiro Shimizu 890ddd
		while (k < n && m_lengthAtCPs[k] <= len)
Toshihiro Shimizu 890ddd
			k++;
Toshihiro Shimizu 890ddd
		if (k >= n) {
Toshihiro Shimizu 890ddd
			// len is >= all CP lengths. The closest is the last
Toshihiro Shimizu 890ddd
			cpLen = m_lengthAtCPs.back();
Toshihiro Shimizu 890ddd
		} else if (k == 0) {
Toshihiro Shimizu 890ddd
			// len is < all CP lengths. the closest is the first
Toshihiro Shimizu 890ddd
			cpLen = m_lengthAtCPs.front();
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			// m_lengthAtCPs[k-1]<=len && len < m_lengthAtCPs[k]
Toshihiro Shimizu 890ddd
			double cpLen0 = m_lengthAtCPs[k - 1];
Toshihiro Shimizu 890ddd
			double cpLen1 = m_lengthAtCPs[k];
Toshihiro Shimizu 890ddd
			assert(cpLen0 <= len && len < cpLen1);
Toshihiro Shimizu 890ddd
			cpLen = (len - cpLen0 < cpLen1 - len) ? cpLen0 : cpLen1;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (fabs(cpLen - len) < m_tolerance) {
Toshihiro Shimizu 890ddd
			len = cpLen;
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		double len = tcrop(getLengthAtPos(pos) + m_offset, 0.0, m_splineLength);
Toshihiro Shimizu 890ddd
		snapLengthToControlPoint(len);
Toshihiro Shimizu 890ddd
		setValue(lengthToParamValue(len));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragRotationTool
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_lockRotation;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragRotationTool(bool lockRotation, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: DragChannelTool(TStageObject::T_Angle, globalKeyframesEnabled), m_lockRotation(lockRotation)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockRotation)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
		m_lastPos = pos;
Toshihiro Shimizu 890ddd
		m_center = getCenter();
Toshihiro Shimizu 890ddd
		start();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockRotation)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TPointD a = m_lastPos - m_center;
Toshihiro Shimizu 890ddd
		TPointD b = pos - m_center;
Toshihiro Shimizu 890ddd
		m_lastPos = pos;
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
    if(cameraFlag)
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
       // m_viewer->updateViewMatrix();
Toshihiro Shimizu 890ddd
       b = m_viewer->mouseToTool(gb) - m_curCenter;
Toshihiro Shimizu 890ddd
       a = m_viewer->mouseToTool(gc) - m_curCenter;
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
    */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		double a2 = norm2(a), b2 = norm2(b);
Toshihiro Shimizu 890ddd
		const double eps = 1e-8;
Toshihiro Shimizu 890ddd
		if (a2 < eps || b2 < eps)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		double dang = 180 * asin(cross(a, b) / sqrt(a2 * b2)) / TConsts::pi;
Toshihiro Shimizu 890ddd
		setValue(getValue(0) + dang);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragIsotropicScaleTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragIsotropicScaleTool : public DragChannelTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD m_center;
Toshihiro Shimizu 890ddd
	double m_r0;
Toshihiro Shimizu 890ddd
	bool m_lockGlobalScale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragIsotropicScaleTool(bool lockGlobalScale, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: DragChannelTool(TStageObject::T_Scale, globalKeyframesEnabled), m_lockGlobalScale(lockGlobalScale), m_r0(0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockGlobalScale)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
		m_center = getCenter();
Toshihiro Shimizu 890ddd
		start();
Toshihiro Shimizu 890ddd
		m_r0 = norm(m_firstPos - m_center);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockGlobalScale)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		if (m_r0 < 0.001)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// TPointD a = m_firstPos - m_center;
Toshihiro Shimizu 890ddd
		double r1 = norm(pos - m_center);
Toshihiro Shimizu 890ddd
		if (r1 < 0.0001)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		setValue(getOldValue(0) * r1 / m_r0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragScaleTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragScaleTool : public DragChannelTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD m_center;
Toshihiro Shimizu 890ddd
	int m_constraint;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_lockScaleH;
Toshihiro Shimizu 890ddd
	bool m_lockScaleV;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragScaleTool(int constraint, bool lockScaleH, bool lockScaleV, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: DragChannelTool(TStageObject::T_ScaleX, TStageObject::T_ScaleY, globalKeyframesEnabled), m_constraint(constraint), m_lockScaleH(lockScaleH), m_lockScaleV(lockScaleV)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockScaleH && m_lockScaleV)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
		m_center = getCenter();
Toshihiro Shimizu 890ddd
		start();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockScaleH && m_lockScaleV)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TPointD center = m_center + TPointD(40, 40);
Toshihiro Shimizu 890ddd
		TPointD a = m_firstPos - center;
Toshihiro Shimizu 890ddd
		TPointD b = pos - center;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		const double eps = 1e-8;
Toshihiro Shimizu 890ddd
		if (norm2(a) < eps || norm2(b) < eps)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		double fx = b.x / a.x;
Toshihiro Shimizu 890ddd
		if (fabs(fx) > 1)
Toshihiro Shimizu 890ddd
			fx = tsign(fx) * sqrt(abs(fx));
Toshihiro Shimizu 890ddd
		double fy = b.y / a.y;
Toshihiro Shimizu 890ddd
		if (fabs(fy) > 1)
Toshihiro Shimizu 890ddd
			fy = tsign(fy) * sqrt(abs(fy));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int constraint = m_constraint;
Toshihiro Shimizu 890ddd
		if (constraint == ScaleConstraints::None && e.isShiftPressed())
Toshihiro Shimizu 890ddd
			constraint = ScaleConstraints::AspectRatio;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (constraint == ScaleConstraints::AspectRatio) {
Toshihiro Shimizu 890ddd
			TPointD c = pos - m_firstPos;
Toshihiro Shimizu 890ddd
			if (fabs(c.x) > fabs(c.y))
Toshihiro Shimizu 890ddd
				fy = fx;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				fx = fy;
Toshihiro Shimizu 890ddd
		} else if (constraint == ScaleConstraints::Mass) {
Toshihiro Shimizu 890ddd
			double bxay = b.x * a.y;
Toshihiro Shimizu 890ddd
			double byax = b.y * a.x;
Toshihiro Shimizu 890ddd
			if (fabs(bxay) < eps || fabs(byax) < eps)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			fx = bxay / byax;
Toshihiro Shimizu 890ddd
			fy = byax / bxay;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (fabs(fx) > eps && fabs(fy) > eps) {
Toshihiro Shimizu 890ddd
			double oldv0 = getOldValue(0);
Toshihiro Shimizu 890ddd
			double oldv1 = getOldValue(1);
Toshihiro Shimizu 890ddd
			if (fabs(oldv0) < 0.001)
Toshihiro Shimizu 890ddd
				oldv0 = 0.001;
Toshihiro Shimizu 890ddd
			if (fabs(oldv1) < 0.001)
Toshihiro Shimizu 890ddd
				oldv1 = 0.001;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			double valueX = oldv0 * fx;
Toshihiro Shimizu 890ddd
			double valueY = oldv1 * fy;
Toshihiro Shimizu 890ddd
			if (m_lockScaleH)
Toshihiro Shimizu 890ddd
				valueX = oldv0;
Toshihiro Shimizu 890ddd
			else if (m_lockScaleV)
Toshihiro Shimizu 890ddd
				valueY = oldv1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			setValues(valueX, valueY);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragShearTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragShearTool : public DragChannelTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD m_center;
Toshihiro Shimizu 890ddd
	bool m_lockShearH;
Toshihiro Shimizu 890ddd
	bool m_lockShearV;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragShearTool(bool lockShearH, bool lockShearV, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: DragChannelTool(TStageObject::T_ShearX, TStageObject::T_ShearY, globalKeyframesEnabled), m_lockShearH(lockShearH), m_lockShearV(lockShearV)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockShearH && m_lockShearV)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
		m_center = getCenter();
Toshihiro Shimizu 890ddd
		start();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_lockShearH && m_lockShearV)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TPointD a = m_firstPos - m_center;
Toshihiro Shimizu 890ddd
		TPointD b = pos - m_center;
Toshihiro Shimizu 890ddd
		double fx = a.x - b.x;
Toshihiro Shimizu 890ddd
		double fy = b.y - a.y;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (m_lockShearH)
Toshihiro Shimizu 890ddd
			fx = 0;
Toshihiro Shimizu 890ddd
		else if (m_lockShearV)
Toshihiro Shimizu 890ddd
			fy = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (e.isShiftPressed()) {
Toshihiro Shimizu 890ddd
			if (fabs(fx) > fabs(fy))
Toshihiro Shimizu 890ddd
				fy = 0;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				fx = 0;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		setValues(getOldValue(0) + 0.01 * fx, getOldValue(1) + 0.01 * fy);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragZTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragZTool : public DragChannelTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPoint m_lastPos;
Toshihiro Shimizu 890ddd
	TTool::Viewer *m_viewer;
Toshihiro Shimizu 890ddd
	double m_dz;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DragZTool(TTool::Viewer *viewer, bool globalKeyframesEnabled)
Toshihiro Shimizu 890ddd
		: DragChannelTool(TStageObject::T_Z, globalKeyframesEnabled), m_viewer(viewer) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_lastPos = e.m_pos;
Toshihiro Shimizu 890ddd
		m_firstPos = pos;
Toshihiro Shimizu 890ddd
		m_dz = 0;
Toshihiro Shimizu 890ddd
		start();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		double dz = m_viewer->projectToZ(e.m_pos - m_lastPos);
Toshihiro Shimizu 890ddd
		m_lastPos = e.m_pos;
Toshihiro Shimizu 890ddd
		if (dz != 0.0) {
Toshihiro Shimizu 890ddd
			m_dz += dz;
Toshihiro Shimizu 890ddd
			setValue(getOldValue(0) + m_dz);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// EditTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class EditTool : public TTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Q_DECLARE_TR_FUNCTIONS(EditTool)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DragTool *m_dragTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_firstTime;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	enum {
Toshihiro Shimizu 890ddd
		None = -1,
Toshihiro Shimizu 890ddd
		Translation = 1,
Toshihiro Shimizu 890ddd
		Rotation,
Toshihiro Shimizu 890ddd
		Scale,
Toshihiro Shimizu 890ddd
		ScaleX,
Toshihiro Shimizu 890ddd
		ScaleY,
Toshihiro Shimizu 890ddd
		ScaleXY,
Toshihiro Shimizu 890ddd
		Center,
Toshihiro Shimizu 890ddd
		ZTranslation,
Toshihiro Shimizu 890ddd
		Shear,
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//DragInfo m_dragInfo;
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
Toshihiro Shimizu 890ddd
	bool m_active;
Toshihiro Shimizu 890ddd
	bool m_keyFrameAdded;
Toshihiro Shimizu 890ddd
	int m_what;
Toshihiro Shimizu 890ddd
	int m_highlightedDevice;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double m_oldValues[2];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double m_currentScaleFactor;
Toshihiro Shimizu 890ddd
	FxGadgetController *m_fxGadgetController;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TEnumProperty m_scaleConstraint;
Toshihiro Shimizu 890ddd
	TEnumProperty m_autoSelect;
Toshihiro Shimizu 890ddd
	TBoolProperty m_globalKeyframes;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockCenterX;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockCenterY;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockPositionX;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockPositionY;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockRotation;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockShearH;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockShearV;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockScaleH;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockScaleV;
Toshihiro Shimizu 890ddd
	TBoolProperty m_lockGlobalScale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TBoolProperty m_showEWNSposition;
Toshihiro Shimizu 890ddd
	TBoolProperty m_showZposition;
Toshihiro Shimizu 890ddd
	TBoolProperty m_showSOposition;
Toshihiro Shimizu 890ddd
	TBoolProperty m_showRotation;
Toshihiro Shimizu 890ddd
	TBoolProperty m_showGlobalScale;
Toshihiro Shimizu 890ddd
	TBoolProperty m_showHVscale;
Toshihiro Shimizu 890ddd
	TBoolProperty m_showShear;
Toshihiro Shimizu 890ddd
	TBoolProperty m_showCenterPosition;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TEnumProperty m_activeAxis;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPropertyGroup m_prop;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	EditTool();
Toshihiro Shimizu 890ddd
	~EditTool();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ToolType getToolType() const { return TTool::ColumnTool; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool doesApply() const; // ritorna vero se posso deformare l'oggetto corrente
Toshihiro Shimizu 890ddd
	void saveOldValues();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const TStroke *getSpline() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void rotate();
Toshihiro Shimizu 890ddd
	void move();
Toshihiro Shimizu 890ddd
	void moveCenter();
Toshihiro Shimizu 890ddd
	void scale();
Toshihiro Shimizu 890ddd
	void isoScale();
Toshihiro Shimizu 890ddd
	void squeeze();
Toshihiro Shimizu 890ddd
	void shear(const TPointD &pos, bool single);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void updateTranslation();
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
	void mouseMove(const TPointD &, const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void transform(const TAffine &aff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onActivate();
Toshihiro Shimizu 890ddd
	void onDeactivate();
Shinya Kitaoka 3bfa54
	bool onPropertyChanged(std::string propertyName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void computeBBox();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getCursorId() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPropertyGroup *getProperties(int targetType)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return &m_prop;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void updateMatrix()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		setMatrix(getCurrentObjectParentMatrix2()); // getCurrentObjectParentMatrix());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	void drawText(const TPointD &p, double unit, std::string text);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
EditTool::EditTool()
Toshihiro Shimizu 890ddd
	: TTool("T_Edit"), m_active(false), m_what(Translation), m_highlightedDevice(None), m_currentScaleFactor(1), m_fxGadgetController(0), m_keyFrameAdded(false), m_scaleConstraint("Scale Constraint:") // W_ToolOptions_ScaleConstraint
Toshihiro Shimizu 890ddd
	  ,
Toshihiro Shimizu 890ddd
	  m_autoSelect("Auto Select Column") // W_ToolOptions_AutoSelect
Toshihiro Shimizu 890ddd
	  ,
Toshihiro Shimizu 890ddd
	  m_globalKeyframes("Global Key", false) // W_ToolsOptions_GlobalKeyframes
Toshihiro Shimizu 890ddd
	  ,
Toshihiro Shimizu 890ddd
	  m_lockCenterX("Lock Center E/W", false), m_lockCenterY("Lock Center N/S", false), m_lockPositionX("Lock Position E/W", false), m_lockPositionY("Lock Position N/S", false), m_lockRotation("Lock Rotation", false), m_lockShearH("Lock Shear H", false), m_lockShearV("Lock Shear V", false), m_lockScaleH("Lock Scale H", false), m_lockScaleV("Lock Scale V", false), m_lockGlobalScale("Lock Global Scale", false), m_showEWNSposition("E/W and N/S Positions", true), m_showZposition("Z Position", true), m_showSOposition("SO", true), m_showRotation("Rotation", true), m_showGlobalScale("Global Scale", true), m_showHVscale("Horizontal and Vertical Scale", true), m_showShear("Shear", true), m_showCenterPosition("Center Position", true), m_dragTool(0), m_firstTime(true), m_activeAxis("Active Axis")
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bind(TTool::AllTargets);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_scaleConstraint);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_autoSelect);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_globalKeyframes);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockCenterX);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockCenterY);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockPositionX);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockPositionY);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockRotation);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockShearH);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockShearV);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockScaleH);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockScaleV);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_lockGlobalScale);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_prop.bind(m_showEWNSposition);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_showZposition);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_showSOposition);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_showRotation);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_showGlobalScale);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_showHVscale);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_showShear);
Toshihiro Shimizu 890ddd
	m_prop.bind(m_showCenterPosition);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_scaleConstraint.addValue(L"None");
Toshihiro Shimizu 890ddd
	m_scaleConstraint.addValue(L"A/R");
Toshihiro Shimizu 890ddd
	m_scaleConstraint.addValue(L"Mass");
Toshihiro Shimizu 890ddd
	m_scaleConstraint.setValue(L"None");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_autoSelect.addValue(L"None");
Toshihiro Shimizu 890ddd
	m_autoSelect.addValue(L"Column");
Toshihiro Shimizu 890ddd
	m_autoSelect.addValue(L"Pegbar");
Toshihiro Shimizu 890ddd
	m_autoSelect.setValue(L"None");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_globalKeyframes.setId("GlobalKey");
Toshihiro Shimizu 890ddd
	m_autoSelect.setId("AutoSelect");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_prop.bind(m_activeAxis);
Toshihiro Shimizu 890ddd
	m_activeAxis.addValue(L"Position");
Toshihiro Shimizu 890ddd
	m_activeAxis.addValue(L"Rotation");
Toshihiro Shimizu 890ddd
	m_activeAxis.addValue(L"Scale");
Toshihiro Shimizu 890ddd
	m_activeAxis.addValue(L"Shear");
Toshihiro Shimizu 890ddd
	m_activeAxis.addValue(L"Center");
Toshihiro Shimizu 890ddd
	m_activeAxis.setValue(L"Position");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_activeAxis.setId("EditToolActiveAxis");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
EditTool::~EditTool()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_dragTool;
Toshihiro Shimizu 890ddd
	delete m_fxGadgetController;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void EditTool::updateTranslation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_scaleConstraint.setQStringName(tr("Scale Constraint:"));
Toshihiro Shimizu 890ddd
	m_autoSelect.setQStringName(tr("Auto Select Column"));
Toshihiro Shimizu 890ddd
	m_globalKeyframes.setQStringName(tr("Global Key"));
Toshihiro Shimizu 890ddd
	m_lockCenterX.setQStringName(tr("Lock Center E/W"));
Toshihiro Shimizu 890ddd
	m_lockCenterY.setQStringName(tr("Lock Center N/S"));
Toshihiro Shimizu 890ddd
	m_lockPositionX.setQStringName(tr("Lock Position E/W"));
Toshihiro Shimizu 890ddd
	m_lockPositionY.setQStringName(tr("Lock Position N/S"));
Toshihiro Shimizu 890ddd
	m_lockRotation.setQStringName(tr("Lock Rotation"));
Toshihiro Shimizu 890ddd
	m_lockShearH.setQStringName(tr("Lock Shear H"));
Toshihiro Shimizu 890ddd
	m_lockShearV.setQStringName(tr("Lock Shear V"));
Toshihiro Shimizu 890ddd
	m_lockScaleH.setQStringName(tr("Lock Scale H"));
Toshihiro Shimizu 890ddd
	m_lockScaleV.setQStringName(tr("Lock Scale V"));
Toshihiro Shimizu 890ddd
	m_lockGlobalScale.setQStringName(tr("Lock Global Scale"));
Toshihiro Shimizu 890ddd
	m_showEWNSposition.setQStringName(tr("E/W and N/S Positions"));
Toshihiro Shimizu 890ddd
	m_showZposition.setQStringName(tr("Z Position"));
Toshihiro Shimizu 890ddd
	m_showSOposition.setQStringName(tr("SO"));
Toshihiro Shimizu 890ddd
	m_showRotation.setQStringName(tr("Rotation"));
Toshihiro Shimizu 890ddd
	m_showGlobalScale.setQStringName(tr("Global Scale"));
Toshihiro Shimizu 890ddd
	m_showHVscale.setQStringName(tr("Horizontal and Vertical Scale"));
Toshihiro Shimizu 890ddd
	m_showShear.setQStringName(tr("Shear"));
Toshihiro Shimizu 890ddd
	m_showCenterPosition.setQStringName(tr("Center Position"));
Toshihiro Shimizu 890ddd
	m_activeAxis.setQStringName(tr("Active Axis"));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool EditTool::doesApply() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *xsh = TTool::getApplication()->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
	assert(xsh);
Toshihiro Shimizu 890ddd
	TStageObjectId objId = TTool::getApplication()->getCurrentObject()->getObjectId();
Toshihiro Shimizu 890ddd
	if (objId.isColumn()) {
Toshihiro Shimizu 890ddd
		TXshColumn *column = xsh->getColumn(objId.getIndex());
Toshihiro Shimizu 890ddd
		if (column && column->getSoundColumn())
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const TStroke *EditTool::getSpline() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
	TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
	TStageObjectId objId = app->getCurrentObject()->getObjectId();
Toshihiro Shimizu 890ddd
	TStageObject *pegbar = xsh->getStageObject(objId);
Toshihiro Shimizu 890ddd
	TStageObjectSpline *spline = pegbar ? pegbar->getSpline() : 0;
Toshihiro Shimizu 890ddd
	return spline ? spline->getStroke() : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void EditTool::mouseMove(const TPointD &, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*--左ドラッグ中なら無視--*/
Toshihiro Shimizu 890ddd
	if (e.isLeftButtonPressed())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- FxGadgetを表示していなかったらPICKをしないで済ませる --*/
Toshihiro Shimizu 890ddd
	int selectedDevice = -1;
Toshihiro Shimizu 890ddd
	if (m_fxGadgetController->hasGadget())
Toshihiro Shimizu 890ddd
		selectedDevice = pick(e.m_pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (selectedDevice < 1000) {
Toshihiro Shimizu 890ddd
		selectedDevice = m_what;
Toshihiro Shimizu 890ddd
		if (m_what == Translation && e.isCtrlPressed())
Toshihiro Shimizu 890ddd
			selectedDevice = ZTranslation;
Toshihiro Shimizu 890ddd
		else if (m_what == ZTranslation && !e.isCtrlPressed()) /*--ここには、一度Z移動をした後に入る可能性がある--*/
Toshihiro Shimizu 890ddd
			selectedDevice = Translation;
Toshihiro Shimizu 890ddd
		else if (m_what == Scale && e.isCtrlPressed())
Toshihiro Shimizu 890ddd
			selectedDevice = ScaleXY;
Toshihiro Shimizu 890ddd
		else if (m_what == ScaleXY && !e.isCtrlPressed())
Toshihiro Shimizu 890ddd
			selectedDevice = Scale;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (selectedDevice != m_highlightedDevice) {
Toshihiro Shimizu 890ddd
		m_highlightedDevice = selectedDevice;
Toshihiro Shimizu 890ddd
		m_fxGadgetController->selectById(selectedDevice);
Toshihiro Shimizu 890ddd
		invalidate();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPoint ga, gb, gc;
Toshihiro Shimizu 890ddd
TPoint lastScreenPos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void EditTool::leftButtonDown(const TPointD &ppos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD pos = ppos;
Toshihiro Shimizu 890ddd
	/*-- Soundカラムの場合は何もしない --*/
Toshihiro Shimizu 890ddd
	if (!doesApply())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_activeAxis.getValue() == L"Position")
Toshihiro Shimizu 890ddd
		if (e.isCtrlPressed())
Toshihiro Shimizu 890ddd
			m_what = ZTranslation;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			m_what = Translation;
Toshihiro Shimizu 890ddd
	else if (m_activeAxis.getValue() == L"Scale")
Toshihiro Shimizu 890ddd
		if (e.isCtrlPressed())
Toshihiro Shimizu 890ddd
			m_what = ScaleXY;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			m_what = Scale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int scaleConstraint = 0;
Toshihiro Shimizu 890ddd
	if (m_scaleConstraint.getValue() == L"A/R")
Toshihiro Shimizu 890ddd
		scaleConstraint = ScaleConstraints::AspectRatio;
Toshihiro Shimizu 890ddd
	else if (m_scaleConstraint.getValue() == L"Mass")
Toshihiro Shimizu 890ddd
		scaleConstraint = ScaleConstraints::Mass;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(m_dragTool == 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_highlightedDevice >= 1000) {
Toshihiro Shimizu 890ddd
		m_dragTool = m_fxGadgetController->createDragTool(m_highlightedDevice);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_dragTool) {
Toshihiro Shimizu 890ddd
		switch (m_what) {
Toshihiro Shimizu 890ddd
		case Center:
Toshihiro Shimizu 890ddd
			m_dragTool = new DragCenterTool(
Toshihiro Shimizu 890ddd
				m_lockCenterX.getValue(),
Toshihiro Shimizu 890ddd
				m_lockCenterY.getValue());
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		case Translation:
Toshihiro Shimizu 890ddd
			if (const TStroke *spline = getSpline())
Toshihiro Shimizu 890ddd
				m_dragTool = new DragSplinePositionTool(spline, m_globalKeyframes.getValue());
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				m_dragTool = new DragPositionTool(
Toshihiro Shimizu 890ddd
					m_lockPositionX.getValue(),
Toshihiro Shimizu 890ddd
					m_lockPositionY.getValue(),
Toshihiro Shimizu 890ddd
					m_globalKeyframes.getValue());
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		case Rotation:
Toshihiro Shimizu 890ddd
			m_dragTool = new DragRotationTool(m_lockRotation.getValue(), m_globalKeyframes.getValue());
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		case Scale:
Toshihiro Shimizu 890ddd
			m_dragTool = new DragIsotropicScaleTool(m_lockGlobalScale.getValue(), m_globalKeyframes.getValue());
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		case ScaleXY:
Toshihiro Shimizu 890ddd
			m_dragTool = new DragScaleTool(scaleConstraint, m_lockScaleH.getValue(), m_lockScaleV.getValue(), m_globalKeyframes.getValue());
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		case Shear:
Toshihiro Shimizu 890ddd
			m_dragTool = new DragShearTool(
Toshihiro Shimizu 890ddd
				m_lockShearH.getValue(),
Toshihiro Shimizu 890ddd
				m_lockShearV.getValue(),
Toshihiro Shimizu 890ddd
				m_globalKeyframes.getValue());
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		case ZTranslation:
Toshihiro Shimizu 890ddd
			m_dragTool = new DragZTool(m_viewer, m_globalKeyframes.getValue());
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_dragTool) {
Toshihiro Shimizu 890ddd
		m_dragTool->enableGlobalKeyframes(m_globalKeyframes.getValue());
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
		m_dragTool->leftButtonDown(pos, e);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void EditTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_dragTool)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_dragTool->leftButtonDrag(pos, e);
Toshihiro Shimizu 890ddd
	TTool::getApplication()->getCurrentObject()->notifyObjectIdChanged(true);
Toshihiro Shimizu 890ddd
	invalidate();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void EditTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_dragTool) {
Toshihiro Shimizu 890ddd
		m_dragTool->leftButtonUp(pos, e);
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
		delete m_dragTool;
Toshihiro Shimizu 890ddd
		m_dragTool = 0;
Toshihiro Shimizu 890ddd
		TTool::getApplication()->getCurrentObject()->notifyObjectIdChanged(false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_keyFrameAdded = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void drawArrow(double r, bool filled)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double z0 = 0.25 * r;
Toshihiro Shimizu 890ddd
	double z1 = 2 * r;
Toshihiro Shimizu 890ddd
	double z2 = 4 * r;
Toshihiro Shimizu 890ddd
	double x0 = r;
Toshihiro Shimizu 890ddd
	double x1 = 2 * r;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (filled) {
Toshihiro Shimizu 890ddd
		glBegin(GL_POLYGON);
Toshihiro Shimizu 890ddd
		glVertex3d(x1, 0, z2);
Toshihiro Shimizu 890ddd
		glVertex3d(-x1, 0, z2);
Toshihiro Shimizu 890ddd
		glVertex3d(-x1, 0, -z2);
Toshihiro Shimizu 890ddd
		glVertex3d(x1, 0, -z2);
Toshihiro Shimizu 890ddd
		glVertex3d(x1, 0, z2);
Toshihiro Shimizu 890ddd
		glEnd();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
		glVertex3d(x0, 0, z0);
Toshihiro Shimizu 890ddd
		glVertex3d(x0, 0, z1);
Toshihiro Shimizu 890ddd
		glVertex3d(x1, 0, z1);
Toshihiro Shimizu 890ddd
		glVertex3d(0, 0, z2);
Toshihiro Shimizu 890ddd
		glVertex3d(-x1, 0, z1);
Toshihiro Shimizu 890ddd
		glVertex3d(-x0, 0, z1);
Toshihiro Shimizu 890ddd
		glVertex3d(-x0, 0, z0);
Toshihiro Shimizu 890ddd
		glVertex3d(-x0, 0, z0);
Toshihiro Shimizu 890ddd
		glEnd();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
		glVertex3d(x0, 0, -z0);
Toshihiro Shimizu 890ddd
		glVertex3d(x0, 0, -z1);
Toshihiro Shimizu 890ddd
		glVertex3d(x1, 0, -z1);
Toshihiro Shimizu 890ddd
		glVertex3d(0, 0, -z2);
Toshihiro Shimizu 890ddd
		glVertex3d(-x1, 0, -z1);
Toshihiro Shimizu 890ddd
		glVertex3d(-x0, 0, -z1);
Toshihiro Shimizu 890ddd
		glVertex3d(-x0, 0, -z0);
Toshihiro Shimizu 890ddd
		glVertex3d(-x0, 0, -z0);
Toshihiro Shimizu 890ddd
		glEnd();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void drawCameraIcon()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
	glVertex2i(5, 0);
Toshihiro Shimizu 890ddd
	glVertex2i(16, 0);
Toshihiro Shimizu 890ddd
	glVertex2i(16, 3);
Toshihiro Shimizu 890ddd
	glVertex2i(16, 3);
Toshihiro Shimizu 890ddd
	glVertex2i(22, 0);
Toshihiro Shimizu 890ddd
	glVertex2i(22, 9);
Toshihiro Shimizu 890ddd
	glVertex2i(16, 6);
Toshihiro Shimizu 890ddd
	glVertex2i(16, 9);
Toshihiro Shimizu 890ddd
	glVertex2i(14, 9);
Toshihiro Shimizu 890ddd
	glVertex2i(16, 11);
Toshihiro Shimizu 890ddd
	glVertex2i(16, 14);
Toshihiro Shimizu 890ddd
	glVertex2i(14, 16);
Toshihiro Shimizu 890ddd
	glVertex2i(11, 16);
Toshihiro Shimizu 890ddd
	glVertex2i(9, 14);
Toshihiro Shimizu 890ddd
	glVertex2i(9, 11);
Toshihiro Shimizu 890ddd
	glVertex2i(11, 9);
Toshihiro Shimizu 890ddd
	glVertex2i(7, 9);
Toshihiro Shimizu 890ddd
	glVertex2i(7, 11);
Toshihiro Shimizu 890ddd
	glVertex2i(5, 13);
Toshihiro Shimizu 890ddd
	glVertex2i(2, 13);
Toshihiro Shimizu 890ddd
	glVertex2i(0, 11);
Toshihiro Shimizu 890ddd
	glVertex2i(0, 8);
Toshihiro Shimizu 890ddd
	glVertex2i(2, 6);
Toshihiro Shimizu 890ddd
	glVertex2i(5, 6);
Toshihiro Shimizu 890ddd
	glVertex2i(5, 0);
Toshihiro Shimizu 890ddd
	glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void drawZArrow()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*--矢印--*/
Toshihiro Shimizu 890ddd
	glBegin(GL_LINE_LOOP);
Toshihiro Shimizu 890ddd
	glVertex2i(0, 3);
Toshihiro Shimizu 890ddd
	glVertex2i(2, 2);
Toshihiro Shimizu 890ddd
	glVertex2i(1, 2);
Toshihiro Shimizu 890ddd
	glVertex2i(2, -3);
Toshihiro Shimizu 890ddd
	glVertex2i(4, -3);
Toshihiro Shimizu 890ddd
	glVertex2i(0, -6);
Toshihiro Shimizu 890ddd
	glVertex2i(-4, -3);
Toshihiro Shimizu 890ddd
	glVertex2i(-2, -3);
Toshihiro Shimizu 890ddd
	glVertex2i(-1, 2);
Toshihiro Shimizu 890ddd
	glVertex2i(-2, 2);
Toshihiro Shimizu 890ddd
	glEnd();
Toshihiro Shimizu 890ddd
	/*--Zの文字--*/
Toshihiro Shimizu 890ddd
	glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
	glVertex2i(3, 4);
Toshihiro Shimizu 890ddd
	glVertex2i(5, 4);
Toshihiro Shimizu 890ddd
	glVertex2i(3, 1);
Toshihiro Shimizu 890ddd
	glVertex2i(5, 1);
Toshihiro Shimizu 890ddd
	glEnd();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void EditTool::drawText(const TPointD &p, double unit, std::string text)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	glPushMatrix();
Toshihiro Shimizu 890ddd
	glTranslated(p.x, p.y, 0.0);
Toshihiro Shimizu 890ddd
	double sc = unit * 1.6;
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
  double w = sc * tglGetTextWidth(text, GLUT_STROKE_ROMAN);
Toshihiro Shimizu 890ddd
  double h = sc;
Toshihiro Shimizu 890ddd
  glEnable(GL_BLEND);
Toshihiro Shimizu 890ddd
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Toshihiro Shimizu 890ddd
  glColor4d(0.9,0.9,0.1,0.5);
Toshihiro Shimizu 890ddd
  glRectd(0,0,w,h);
Toshihiro Shimizu 890ddd
  glDisable(GL_BLEND);
Toshihiro Shimizu 890ddd
  glColor3d(0,0,0);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glScaled(sc, sc, 1);
Toshihiro Shimizu 890ddd
	tglDrawText(TPointD(8, -3), text);
Toshihiro Shimizu 890ddd
	glPopMatrix();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void EditTool::draw()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// the tool is using the coordinate system of the parent object
Toshihiro Shimizu 890ddd
	//glColor3d(1,0,1);
Toshihiro Shimizu 890ddd
	//tglDrawCircle(crossHair,50);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*--Level編集モードのときは表示しない--*/
Toshihiro Shimizu 890ddd
	if (TTool::getApplication()->getCurrentFrame()->isEditingLevel())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	const TPixel32 normalColor(250, 127, 240);
Toshihiro Shimizu 890ddd
	const TPixel32 highlightedColor(150, 255, 140);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// collect information
Toshihiro Shimizu 890ddd
	TXsheet *xsh = getXsheet();
Toshihiro Shimizu 890ddd
	/*--編集中のStageObjectIDを取得--*/
Toshihiro Shimizu 890ddd
	TStageObjectId objId = getObjectId();
Toshihiro Shimizu 890ddd
	int frame = getFrame();
Toshihiro Shimizu 890ddd
	TAffine parentAff = xsh->getParentPlacement(objId, frame);
Toshihiro Shimizu 890ddd
	TAffine aff = xsh->getPlacement(objId, frame);
Toshihiro Shimizu 890ddd
	TPointD center = Stage::inch * xsh->getCenter(objId, frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*--3D表示のとき、Zを動かせるようにする--*/
Toshihiro Shimizu 890ddd
	if (getViewer()->is3DView()) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		glPushName(ZTranslation);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		tglColor(m_highlightedDevice == ZTranslation ? highlightedColor : normalColor);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		double z = xsh->getZ(objId, frame);
Toshihiro Shimizu 890ddd
		glTranslated(0, -1, z);
Toshihiro Shimizu 890ddd
		drawArrow(50, isPicking());
Toshihiro Shimizu 890ddd
		glPopName();
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double unit = sqrt(tglGetPixelSize2());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- ObjectのCenter位置を取得 --*/
Toshihiro Shimizu 890ddd
	glPushMatrix();
Toshihiro Shimizu 890ddd
	tglMultMatrix(parentAff.inv() * TTranslation(aff * TPointD(0.0, 0.0)));
Toshihiro Shimizu 890ddd
	tglColor(normalColor);
Toshihiro Shimizu 890ddd
	tglDrawDisk(TPointD(0.0, 0.0), unit * 4);
Toshihiro Shimizu 890ddd
	glPopMatrix();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- Z移動 : 矢印(中心はCameraのCenter) --*/
Toshihiro Shimizu 890ddd
	if (m_activeAxis.getValue() == L"Position" && m_highlightedDevice == ZTranslation) {
Toshihiro Shimizu 890ddd
		tglColor(normalColor);
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		TStageObjectId currentCamId = xsh->getStageObjectTree()->getCurrentCameraId();
Toshihiro Shimizu 890ddd
		TAffine camParentAff = xsh->getParentPlacement(currentCamId, frame);
Toshihiro Shimizu 890ddd
		TAffine camAff = xsh->getPlacement(currentCamId, frame);
Toshihiro Shimizu 890ddd
		tglMultMatrix(camParentAff.inv() * TTranslation(camAff * TPointD(0.0, 0.0)));
Toshihiro Shimizu 890ddd
		glScaled(unit * 8, unit * 8, 1);
Toshihiro Shimizu 890ddd
		drawZArrow();
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- Rotation, Position : 垂直/水平線 --*/
Toshihiro Shimizu 890ddd
	if (m_activeAxis.getValue() == L"Rotation" || m_activeAxis.getValue() == L"Position") {
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		tglMultMatrix(parentAff.inv() * aff * TTranslation(center));
Toshihiro Shimizu 890ddd
		glScaled(unit, unit, 1);
Toshihiro Shimizu 890ddd
		tglColor(normalColor);
Toshihiro Shimizu 890ddd
		glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
		glVertex2i(-800, 0);
Toshihiro Shimizu 890ddd
		glVertex2i(800, 0);
Toshihiro Shimizu 890ddd
		glEnd();
Toshihiro Shimizu 890ddd
		glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
		glVertex2i(0, -100);
Toshihiro Shimizu 890ddd
		glVertex2i(0, 100);
Toshihiro Shimizu 890ddd
		glEnd();
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	glPushMatrix();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	tglMultMatrix(parentAff.inv() * TTranslation(aff * center));
Toshihiro Shimizu 890ddd
	center = TPointD();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool dragging = m_dragTool != 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// draw center
Toshihiro Shimizu 890ddd
	tglColor(normalColor);
Toshihiro Shimizu 890ddd
	glPushName(Center);
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		tglDrawCircle(center, unit * 10);
Toshihiro Shimizu 890ddd
		tglDrawCircle(center, unit * 8);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/*-- 円の中に十字を描く Center位置にTranslate済み --*/
Toshihiro Shimizu 890ddd
		glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
		glVertex2d(-unit * 8, 0.0);
Toshihiro Shimizu 890ddd
		glVertex2d(unit * 8, 0.0);
Toshihiro Shimizu 890ddd
		glEnd();
Toshihiro Shimizu 890ddd
		glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
		glVertex2d(0.0, -unit * 8);
Toshihiro Shimizu 890ddd
		glVertex2d(0.0, unit * 8);
Toshihiro Shimizu 890ddd
		glEnd();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	glPopName();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// draw label (column/pegbar name; possibly camera icon)
Toshihiro Shimizu 890ddd
	tglColor(normalColor);
Toshihiro Shimizu 890ddd
	glPushMatrix();
Toshihiro Shimizu 890ddd
	glTranslated(center.x + unit * 10, center.y - unit * 20, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- Object名を表示 --*/
Toshihiro Shimizu 890ddd
	TStageObject *pegbar = xsh->getStageObject(objId);
Shinya Kitaoka 3bfa54
	std::string name = pegbar->getFullName();
Toshihiro Shimizu 890ddd
	if (objId.isColumn() || objId.isPegbar() || objId.isTable()) {
Toshihiro Shimizu 890ddd
		glScaled(unit * 2, unit * 1.5, 1);
Toshihiro Shimizu 890ddd
		tglDrawText(TPointD(0, 0), name);
Toshihiro Shimizu 890ddd
	} else if (objId.isCamera()) {
Toshihiro Shimizu 890ddd
		glPushMatrix();
Toshihiro Shimizu 890ddd
		glScaled(unit * 2, unit * 1.5, 1);
Toshihiro Shimizu 890ddd
		tglDrawText(TPointD(12, 0), name);
Toshihiro Shimizu 890ddd
		glPopMatrix();
Toshihiro Shimizu 890ddd
		glScaled(unit, unit, 1);
Toshihiro Shimizu 890ddd
		drawCameraIcon();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	glPopMatrix();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*--- アクティブでないカメラのPegbarを編集するときは、カメラ枠を表示する ---*/
Toshihiro Shimizu 890ddd
	if (objId.isCamera()) {
Toshihiro Shimizu 890ddd
		if (xsh->getStageObjectTree()->getCurrentCameraId() != objId) {
Toshihiro Shimizu 890ddd
			//TODO : glLineStipple has been deprecated in the OpenGL APIs. Need to be replaced. 2016/1/20 shun_iwasawa
Toshihiro Shimizu 890ddd
			glEnable(GL_LINE_STIPPLE);
Toshihiro Shimizu 890ddd
			glColor3d(1.0, 0.0, 1.0);
Toshihiro Shimizu 890ddd
			glLineStipple(1, 0x1111);
Toshihiro Shimizu 890ddd
			TRectD cameraRect =
Toshihiro Shimizu 890ddd
				TTool::getApplication()
Toshihiro Shimizu 890ddd
					->getCurrentScene()
Toshihiro Shimizu 890ddd
					->getScene()
Toshihiro Shimizu 890ddd
					->getCurrentCamera()
Toshihiro Shimizu 890ddd
					->getStageRect();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			glPushMatrix();
Toshihiro Shimizu 890ddd
			tglDrawRect(cameraRect);
Toshihiro Shimizu 890ddd
			glPopMatrix();
Toshihiro Shimizu 890ddd
			glDisable(GL_LINE_STIPPLE);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glPopMatrix();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_fxGadgetController->draw(isPicking());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void EditTool::onActivate()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_firstTime) {
Toshihiro Shimizu 890ddd
		m_lockCenterX.setValue(LockCenterX ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockCenterY.setValue(LockCenterY ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockPositionX.setValue(LockPositionX ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockPositionY.setValue(LockPositionY ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockRotation.setValue(LockRotation ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockShearH.setValue(LockShearH ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockShearV.setValue(LockShearV ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockScaleH.setValue(LockScaleH ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockScaleV.setValue(LockScaleV ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_lockGlobalScale.setValue(LockGlobalScale ? 1 : 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_showEWNSposition.setValue(ShowEWNSposition ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_showZposition.setValue(ShowZposition ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_showSOposition.setValue(ShowSOposition ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_showRotation.setValue(ShowRotation ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_showGlobalScale.setValue(ShowGlobalScale ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_showHVscale.setValue(ShowHVscale ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_showShear.setValue(ShowShear ? 1 : 0);
Toshihiro Shimizu 890ddd
		m_showCenterPosition.setValue(ShowCenterPosition ? 1 : 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_fxGadgetController = new FxGadgetController(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
    m_foo.setTool(this);
Toshihiro Shimizu 890ddd
    m_foo.setFxHandle(getApplication()->getCurrentFx());
Toshihiro Shimizu 890ddd
    */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_firstTime = false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TStageObjectId objId = getObjectId();
Toshihiro Shimizu 890ddd
	if (objId == TStageObjectId::NoneId) {
Toshihiro Shimizu 890ddd
		int index = getColumnIndex();
Toshihiro Shimizu 890ddd
		if (index == -1)
Toshihiro Shimizu 890ddd
			objId = TStageObjectId::CameraId(0);
Toshihiro Shimizu 890ddd
		objId = TStageObjectId::ColumnId(index);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TTool::getApplication()->getCurrentObject()->setObjectId(objId);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void EditTool::onDeactivate()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
bool EditTool::onPropertyChanged(std::string propertyName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (propertyName == m_lockCenterX.getName())
Toshihiro Shimizu 890ddd
		LockCenterX = (int)m_lockCenterX.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockCenterY.getName())
Toshihiro Shimizu 890ddd
		LockCenterY = (int)m_lockCenterY.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockPositionX.getName())
Toshihiro Shimizu 890ddd
		LockPositionX = (int)m_lockPositionX.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockPositionY.getName())
Toshihiro Shimizu 890ddd
		LockPositionY = (int)m_lockPositionY.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockRotation.getName())
Toshihiro Shimizu 890ddd
		LockRotation = (int)m_lockRotation.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockShearH.getName())
Toshihiro Shimizu 890ddd
		LockShearH = (int)m_lockShearH.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockShearV.getName())
Toshihiro Shimizu 890ddd
		LockShearV = (int)m_lockShearV.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockScaleH.getName())
Toshihiro Shimizu 890ddd
		LockScaleH = (int)m_lockScaleH.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockScaleV.getName())
Toshihiro Shimizu 890ddd
		LockScaleV = (int)m_lockScaleV.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_lockGlobalScale.getName())
Toshihiro Shimizu 890ddd
		LockGlobalScale = (int)m_lockGlobalScale.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_showEWNSposition.getName())
Toshihiro Shimizu 890ddd
		ShowEWNSposition = (int)m_showEWNSposition.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_showZposition.getName())
Toshihiro Shimizu 890ddd
		ShowZposition = (int)m_showZposition.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_showSOposition.getName())
Toshihiro Shimizu 890ddd
		ShowSOposition = (int)m_showSOposition.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_showRotation.getName())
Toshihiro Shimizu 890ddd
		ShowRotation = (int)m_showRotation.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_showGlobalScale.getName())
Toshihiro Shimizu 890ddd
		ShowGlobalScale = (int)m_showGlobalScale.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_showHVscale.getName())
Toshihiro Shimizu 890ddd
		ShowHVscale = (int)m_showHVscale.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_showShear.getName())
Toshihiro Shimizu 890ddd
		ShowShear = (int)m_showShear.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	else if (propertyName == m_showCenterPosition.getName())
Toshihiro Shimizu 890ddd
		ShowCenterPosition = (int)m_showCenterPosition.getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- Active Axis の変更 --*/
Toshihiro Shimizu 890ddd
	else if (propertyName == m_activeAxis.getName()) {
Toshihiro Shimizu 890ddd
		std::wstring activeAxis = m_activeAxis.getValue();
Toshihiro Shimizu 890ddd
		if (activeAxis == L"Position")
Toshihiro Shimizu 890ddd
			m_what = Translation;
Toshihiro Shimizu 890ddd
		else if (activeAxis == L"Rotation")
Toshihiro Shimizu 890ddd
			m_what = Rotation;
Toshihiro Shimizu 890ddd
		else if (activeAxis == L"Scale")
Toshihiro Shimizu 890ddd
			m_what = Scale;
Toshihiro Shimizu 890ddd
		else if (activeAxis == L"Shear")
Toshihiro Shimizu 890ddd
			m_what = Shear;
Toshihiro Shimizu 890ddd
		else if (activeAxis == L"Center")
Toshihiro Shimizu 890ddd
			m_what = Center;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int EditTool::getCursorId() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*--- FxParameter操作中のカーソル ---*/
Toshihiro Shimizu 890ddd
	if (m_highlightedDevice >= 1000)
Toshihiro Shimizu 890ddd
		return ToolCursor::FxGadgetCursor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*--- カーソルをアクティブな軸に応じて選ぶ --*/
Toshihiro Shimizu 890ddd
	std::wstring activeAxis = m_activeAxis.getValue();
Toshihiro Shimizu 890ddd
	if (activeAxis == L"Position") {
Toshihiro Shimizu 890ddd
		if (m_highlightedDevice == ZTranslation)
Toshihiro Shimizu 890ddd
			return ToolCursor::MoveZCursor;
Toshihiro Shimizu 890ddd
		else if (LockPositionX && LockPositionY)
Toshihiro Shimizu 890ddd
			return ToolCursor::DisableCursor;
Toshihiro Shimizu 890ddd
		else if (LockPositionX)
Toshihiro Shimizu 890ddd
			return ToolCursor::MoveNSCursor;
Toshihiro Shimizu 890ddd
		else if (LockPositionY)
Toshihiro Shimizu 890ddd
			return ToolCursor::MoveEWCursor;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			return ToolCursor::MoveCursor;
Toshihiro Shimizu 890ddd
	} else if (activeAxis == L"Rotation") {
Toshihiro Shimizu 890ddd
		return ToolCursor::RotCursor;
Toshihiro Shimizu 890ddd
	} else if (activeAxis == L"Scale") {
Toshihiro Shimizu 890ddd
		if (m_highlightedDevice == ScaleXY) {
Toshihiro Shimizu 890ddd
			if (LockScaleH && LockScaleV)
Toshihiro Shimizu 890ddd
				return ToolCursor::DisableCursor;
Toshihiro Shimizu 890ddd
			else if (LockScaleH)
Toshihiro Shimizu 890ddd
				return ToolCursor::ScaleVCursor;
Toshihiro Shimizu 890ddd
			else if (LockScaleV)
Toshihiro Shimizu 890ddd
				return ToolCursor::ScaleHCursor;
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				return ToolCursor::ScaleHVCursor;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			return ToolCursor::ScaleGlobalCursor;
Toshihiro Shimizu 890ddd
	} else if (activeAxis == L"Shear") {
Toshihiro Shimizu 890ddd
		if (LockShearH && LockShearV)
Toshihiro Shimizu 890ddd
			return ToolCursor::DisableCursor;
Toshihiro Shimizu 890ddd
		else if (LockShearH)
Toshihiro Shimizu 890ddd
			return ToolCursor::ScaleVCursor;
Toshihiro Shimizu 890ddd
		else if (LockShearV)
Toshihiro Shimizu 890ddd
			return ToolCursor::ScaleHCursor;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			return ToolCursor::ScaleCursor;
Toshihiro Shimizu 890ddd
	} else if (activeAxis == L"Center") {
Toshihiro Shimizu 890ddd
		if (LockCenterX && LockCenterY)
Toshihiro Shimizu 890ddd
			return ToolCursor::DisableCursor;
Toshihiro Shimizu 890ddd
		else if (LockCenterX)
Toshihiro Shimizu 890ddd
			return ToolCursor::MoveNSCursor;
Toshihiro Shimizu 890ddd
		else if (LockCenterY)
Toshihiro Shimizu 890ddd
			return ToolCursor::MoveEWCursor;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			return ToolCursor::MoveCursor;
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		return ToolCursor::StrokeSelectCursor;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
EditTool arrowTool;