Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tools/tool.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzTools includes
Toshihiro Shimizu 890ddd
#include "tools/toolcommandids.h"
Toshihiro Shimizu 890ddd
#include "tools/toolhandle.h"
Toshihiro Shimizu 890ddd
#include "tools/cursors.h"
Toshihiro Shimizu 890ddd
#include "tools/tooloptions.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/icongenerator.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonzqt/menubarcommand.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobject.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjectspline.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjecttree.h"
Toshihiro Shimizu 890ddd
#include "toonz/dpiscale.h"
Toshihiro Shimizu 890ddd
#include "toonz/palettecontroller.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*****************************************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace
Toshihiro Shimizu 890ddd
//*****************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Global variables
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef std::pair<std::string, ttool::tooltargettype=""> ToolKey;</std::string,>
Toshihiro Shimizu 890ddd
typedef std::map<toolkey, *="" ttool=""> ToolTable;</toolkey,>
Toshihiro Shimizu 890ddd
ToolTable *toolTable = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
std::set<std::string> *toolNames = 0;</std::string>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Local classes
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct DummyTool : public TTool {
Toshihiro Shimizu 890ddd
	ToolType getToolType() const { return TTool::LevelReadTool; }	// Test level type
Toshihiro Shimizu 890ddd
	ToolTargetType getTargetType() const { return TTool::NoTarget; } // Works on nothing
Toshihiro Shimizu 890ddd
	int getCursorId() const { return ToolCursor::ForbiddenCursor; }  // Forbids everything
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DummyTool() : TTool("T_Dummy") {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} theDummyTool;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ToolSelector
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::string m_toolName;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ToolSelector(std::string toolName) : m_toolName(toolName) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void selectTool()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TTool::Application *app = TTool::getApplication();
Toshihiro Shimizu 890ddd
		if (app)
Toshihiro Shimizu 890ddd
			app->getCurrentTool()->setTool(QString::fromStdString(m_toolName));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Local functions
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFrameId getNewFrameId(TXshSimpleLevel *sl, int row)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameId fid(row + 1);
Toshihiro Shimizu 890ddd
	if (sl->isFid(fid)) {
Toshihiro Shimizu 890ddd
		fid = TFrameId(fid.getNumber(), 'a');
Toshihiro Shimizu 890ddd
		while (fid.getLetter() < 'z' && sl->isFid(fid))
Toshihiro Shimizu 890ddd
			fid = TFrameId(fid.getNumber(), fid.getLetter() + 1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return fid;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*****************************************************************************************
Toshihiro Shimizu 890ddd
//    TTool  static members
Toshihiro Shimizu 890ddd
//*****************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTool::Application *TTool::m_application = 0;
Toshihiro Shimizu 890ddd
std::set<tframeid> TTool::m_selectedFrames = std::set<tframeid>();</tframeid></tframeid>
Toshihiro Shimizu 890ddd
bool TTool::m_isLevelCreated = false;
Toshihiro Shimizu 890ddd
bool TTool::m_isFrameCreated = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// m_cellsData
Toshihiro Shimizu 890ddd
// brutto brutto. fix quick & dirty del baco #6213 (undo con animation sheet)
Toshihiro Shimizu 890ddd
// bisogna ripensare la logica degli undo e del touchImage
Toshihiro Shimizu 890ddd
// m_cellsData viene inizializzato nel touchImage() in modalita' animation sheet
Toshihiro Shimizu 890ddd
// contiene una o due terne che rappresentano range di celle (dell'xsheet) modificate dall'inserimento
Toshihiro Shimizu 890ddd
// di un nuovo frame: [r0,r1,type].
Toshihiro Shimizu 890ddd
// type = 0 : vecchio (cella[r0-1]) => nuovo
Toshihiro Shimizu 890ddd
// type = 1 : vuoto => vecchio (cella[r0-1])
Toshihiro Shimizu 890ddd
// type = 2 : vuoto => nuovo
Toshihiro Shimizu 890ddd
// cfr. il codice di TTool::touchImage() ToolUtils::TToolUndo::removeLevelAndFrameIfNeeded()
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
std::vector<int> TTool::m_cellsData;</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*****************************************************************************************
Toshihiro Shimizu 890ddd
//    TTool  implementation
Toshihiro Shimizu 890ddd
//*****************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TTool::TTool(std::string name)
Toshihiro Shimizu 890ddd
	: m_name(name), m_viewer(0), m_targetType(NoTarget), m_enabled(true), m_active(false), m_picking(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TTool *TTool::getTool(std::string toolName, ToolTargetType targetType)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!toolTable)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	ToolTable::iterator it = toolTable->find(std::make_pair(toolName, targetType));
Toshihiro Shimizu 890ddd
	if (it == toolTable->end())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	return it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTool::bind(int targetType)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_targetType = targetType;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!toolTable)
Toshihiro Shimizu 890ddd
		toolTable = new ToolTable();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!toolNames)
Toshihiro Shimizu 890ddd
		toolNames = new std::set<std::string>();</std::string>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::string name = getName();
Toshihiro Shimizu 890ddd
	if (toolNames->count(name) == 0) {
Toshihiro Shimizu 890ddd
		toolNames->insert(name);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Initialize with the dummy tool
Toshihiro Shimizu 890ddd
		toolTable->insert(std::make_pair(std::make_pair(name, ToonzImage), &theDummyTool));
Toshihiro Shimizu 890ddd
		toolTable->insert(std::make_pair(std::make_pair(name, VectorImage), &theDummyTool));
Toshihiro Shimizu 890ddd
		toolTable->insert(std::make_pair(std::make_pair(name, RasterImage), &theDummyTool));
Toshihiro Shimizu 890ddd
		toolTable->insert(std::make_pair(std::make_pair(name, MeshImage), &theDummyTool));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ToolSelector *toolSelector = new ToolSelector(name);
Toshihiro Shimizu 890ddd
		CommandManager::instance()->setHandler(name.c_str(),
Toshihiro Shimizu 890ddd
											   new CommandHandlerHelper<toolselector>(toolSelector, &ToolSelector::selectTool));</toolselector>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (targetType & ToonzImage)
Toshihiro Shimizu 890ddd
		(*toolTable)[std::make_pair(name, ToonzImage)] = this;
Toshihiro Shimizu 890ddd
	if (targetType & VectorImage)
Toshihiro Shimizu 890ddd
		(*toolTable)[std::make_pair(name, VectorImage)] = this;
Toshihiro Shimizu 890ddd
	if (targetType & RasterImage)
Toshihiro Shimizu 890ddd
		(*toolTable)[std::make_pair(name, RasterImage)] = this;
Toshihiro Shimizu 890ddd
	if (targetType & MeshImage)
Toshihiro Shimizu 890ddd
		(*toolTable)[std::make_pair(name, MeshImage)] = this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToolOptionsBox *TTool::createOptionsBox()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteHandle *currPalette = m_application->getPaletteController()->getCurrentLevelPalette();
Toshihiro Shimizu 890ddd
	ToolHandle *currTool = m_application->getCurrentTool();
Toshihiro Shimizu 890ddd
	return new GenericToolOptionsBox(0, this, currPalette, 0, currTool);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TTool::getPixelSize() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_viewer ? m_viewer->getPixelSize() : 1.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshCell TTool::getImageCell()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_application);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXshCell result;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameHandle *currentFrame = m_application->getCurrentFrame();
Toshihiro Shimizu 890ddd
	TXshLevelHandle *currentLevel = m_application->getCurrentLevel();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (currentFrame->isEditingLevel()) {
Toshihiro Shimizu 890ddd
		if (TXshLevel *xl = currentLevel->getLevel()) {
Toshihiro Shimizu 890ddd
			if (TXshSimpleLevel *sl = xl->getSimpleLevel()) {
Toshihiro Shimizu 890ddd
				result.m_level = xl;
Toshihiro Shimizu 890ddd
				result.m_frameId = currentFrame->getFid();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet()) {
Toshihiro Shimizu 890ddd
			if (!m_application->getCurrentObject()->isSpline()) {
Toshihiro Shimizu 890ddd
				int row = currentFrame->getFrame();
Toshihiro Shimizu 890ddd
				int col = m_application->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				result = xsh->getCell(row, col);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return result;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TImage *TTool::getImage(bool toBeModified, int subsampling)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_application);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_application->getCurrentFrame()->isPlaying())
Toshihiro Shimizu 890ddd
		toBeModified = false; // In playback mode, you are not going to modify images
Toshihiro Shimizu 890ddd
							  // Probably useless - tools are disabled when playing...
Toshihiro Shimizu 890ddd
	const TXshCell &cell = getImageCell();
Toshihiro Shimizu 890ddd
	if (cell.isEmpty()) {
Toshihiro Shimizu 890ddd
		TObjectHandle *currentObject = m_application->getCurrentObject();
Toshihiro Shimizu 890ddd
		return currentObject->isSpline() ? currentObject->getSplineImage() : (TImage *)0;
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		return cell.getImage(toBeModified, subsampling).getPointer();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TImage *TTool::touchImage()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_cellsData.clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_isLevelCreated = false;
Toshihiro Shimizu 890ddd
	m_isFrameCreated = false;
Toshihiro Shimizu 890ddd
	Preferences *pref = Preferences::instance();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isAutoCreateEnabled = pref->isAutoCreateEnabled();
Toshihiro Shimizu 890ddd
	bool animationSheetEnabled = pref->isAnimationSheetEnabled();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameHandle *currentFrame = m_application->getCurrentFrame();
Toshihiro Shimizu 890ddd
	TXshLevelHandle *currentLevel = m_application->getCurrentLevel();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (currentFrame->isEditingLevel()) {
Toshihiro Shimizu 890ddd
		// Editing level
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// no level => return 0
Toshihiro Shimizu 890ddd
		TXshLevel *xl = currentLevel->getLevel();
Toshihiro Shimizu 890ddd
		if (!xl)
Toshihiro Shimizu 890ddd
			return 0;
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = xl->getSimpleLevel();
Toshihiro Shimizu 890ddd
		if (!sl || sl->isEmpty())
Toshihiro Shimizu 890ddd
			return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFrameId fid = currentFrame->getFid();
Toshihiro Shimizu 890ddd
		TImageP img = sl->getFrame(fid, true);
Toshihiro Shimizu 890ddd
		if (!img) {
Toshihiro Shimizu 890ddd
			// no drawing found
Toshihiro Shimizu 890ddd
			if (sl->isSubsequence() || sl->isReadOnly() || !isAutoCreateEnabled)
Toshihiro Shimizu 890ddd
				return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// create a new drawing
Toshihiro Shimizu 890ddd
			img = sl->createEmptyFrame();
Toshihiro Shimizu 890ddd
			sl->setFrame(fid, img);
Toshihiro Shimizu 890ddd
			currentLevel->notifyLevelChange();
Toshihiro Shimizu 890ddd
			m_isFrameCreated = true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return img.getPointer();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		// editing xsheet
Toshihiro Shimizu 890ddd
		if (m_application->getCurrentObject()->isSpline())
Toshihiro Shimizu 890ddd
			return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TSceneHandle *currentScene = m_application->getCurrentScene();
Toshihiro Shimizu 890ddd
		ToonzScene *scene = currentScene->getScene();
Toshihiro Shimizu 890ddd
		int row = currentFrame->getFrame();
Toshihiro Shimizu 890ddd
		int col = m_application->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
		if (col < 0)
Toshihiro Shimizu 890ddd
			return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TXsheetHandle *currentXsheet = m_application->getCurrentXsheet();
Toshihiro Shimizu 890ddd
		TXsheet *xsh = currentXsheet->getXsheet();
Toshihiro Shimizu 890ddd
		if (!xsh)
Toshihiro Shimizu 890ddd
			return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TXshCell cell = xsh->getCell(row, col);
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = cell.getSimpleLevel();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (sl != 0) {
Toshihiro Shimizu 890ddd
			// current cell is not empty
Toshihiro Shimizu 890ddd
			if (isAutoCreateEnabled && animationSheetEnabled && row > 0 &&
Toshihiro Shimizu 890ddd
				xsh->getCell(row - 1, col) == xsh->getCell(row, col)) {
Toshihiro Shimizu 890ddd
				// animationSheet is enabled and the current cell is a "hold". We must create a new drawing.
Toshihiro Shimizu 890ddd
				// measure the hold length (starting from the current row) : r0-r1
Toshihiro Shimizu 890ddd
				int r0 = row, r1 = row;
Toshihiro Shimizu 890ddd
				while (xsh->getCell(r1 + 1, col) == cell)
Toshihiro Shimizu 890ddd
					r1++;
Toshihiro Shimizu 890ddd
				// find the proper frameid (possibly addisng suffix, in order to avoid a fid already used)
Toshihiro Shimizu 890ddd
				TFrameId fid = getNewFrameId(sl, row);
Toshihiro Shimizu 890ddd
				// create the new drawing
Toshihiro Shimizu 890ddd
				TImageP img = sl->createEmptyFrame();
Toshihiro Shimizu 890ddd
				m_isFrameCreated = true;
Toshihiro Shimizu 890ddd
				// insert the drawing in the level
Toshihiro Shimizu 890ddd
				sl->setFrame(fid, img);
Toshihiro Shimizu 890ddd
				// update the cell
Toshihiro Shimizu 890ddd
				cell = TXshCell(sl, fid);
Toshihiro Shimizu 890ddd
				// update the xsheet (change the current cell and possibly all the following "hold")
Toshihiro Shimizu 890ddd
				for (int r = r0; r <= r1; r++)
Toshihiro Shimizu 890ddd
					xsh->setCell(r, col, cell);
Toshihiro Shimizu 890ddd
				// notify
Toshihiro Shimizu 890ddd
				currentXsheet->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
				currentScene->notifyCastChange();
Toshihiro Shimizu 890ddd
				currentLevel->notifyLevelChange();
Toshihiro Shimizu 890ddd
				m_cellsData.push_back(r0);
Toshihiro Shimizu 890ddd
				m_cellsData.push_back(r1);
Toshihiro Shimizu 890ddd
				m_cellsData.push_back(0);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			// we've found the image. return it.
Toshihiro Shimizu 890ddd
			return cell.getImage(true).getPointer();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// current cell is empty.
Toshihiro Shimizu 890ddd
		if (!isAutoCreateEnabled)
Toshihiro Shimizu 890ddd
			return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// get the column range
Toshihiro Shimizu 890ddd
		int r0, r1;
Toshihiro Shimizu 890ddd
		xsh->getCellRange(col, r0, r1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (animationSheetEnabled && r0 <= r1) {
Toshihiro Shimizu 890ddd
			// animation sheet enabled and not empty column. We must create a new drawing in the column level and possibly add "holds"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// find the last not-empty cell before the current one (a) and the first after (b)
Toshihiro Shimizu 890ddd
			int a = row - 1, b = row + 1;
Toshihiro Shimizu 890ddd
			while (a >= r0 && xsh->getCell(a, col).isEmpty())
Toshihiro Shimizu 890ddd
				a--;
Toshihiro Shimizu 890ddd
			while (b <= r1 && xsh->getCell(b, col).isEmpty())
Toshihiro Shimizu 890ddd
				b++;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// find the level we must attach to
Toshihiro Shimizu 890ddd
			if (a >= r0) {
Toshihiro Shimizu 890ddd
				// there is a not-emtpy cell before the current one
Toshihiro Shimizu 890ddd
				sl = xsh->getCell(a, col).getSimpleLevel();
Toshihiro Shimizu 890ddd
			} else if (b <= r1) {
Toshihiro Shimizu 890ddd
				sl = xsh->getCell(b, col).getSimpleLevel();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			if (sl) {
Toshihiro Shimizu 890ddd
				// note: sl should be always !=0 (the column is not empty)
Toshihiro Shimizu 890ddd
				// if - for some reason - it is ==0 then we skip to the standard (i.e. !animationSheetEnabled) beahviour
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				// create the drawing
Toshihiro Shimizu 890ddd
				// find the proper frameid (possibly addisng suffix, in order to avoid a fid already used)
Toshihiro Shimizu 890ddd
				TFrameId fid = getNewFrameId(sl, row);
Toshihiro Shimizu 890ddd
				// create the new drawing
Toshihiro Shimizu 890ddd
				TImageP img = sl->createEmptyFrame();
Toshihiro Shimizu 890ddd
				m_isFrameCreated = true;
Toshihiro Shimizu 890ddd
				// insert the drawing in the level
Toshihiro Shimizu 890ddd
				sl->setFrame(fid, img);
Toshihiro Shimizu 890ddd
				// update the cell
Toshihiro Shimizu 890ddd
				cell = TXshCell(sl, fid);
Toshihiro Shimizu 890ddd
				xsh->setCell(row, col, cell);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				// create holds
Toshihiro Shimizu 890ddd
				if (a >= r0) {
Toshihiro Shimizu 890ddd
					// create a hold before : [a+1, row-1]
Toshihiro Shimizu 890ddd
					TXshCell aCell = xsh->getCell(a, col);
Toshihiro Shimizu 890ddd
					for (int i = a + 1; i < row; i++)
Toshihiro Shimizu 890ddd
						xsh->setCell(i, col, aCell);
Toshihiro Shimizu 890ddd
					m_cellsData.push_back(a + 1);
Toshihiro Shimizu 890ddd
					m_cellsData.push_back(row - 1);
Toshihiro Shimizu 890ddd
					m_cellsData.push_back(1); // vuoto => vecchio
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
					if (b <= r1 && xsh->getCell(b, col).getSimpleLevel() == sl) {
Toshihiro Shimizu 890ddd
						// create also a hold after
Toshihiro Shimizu 890ddd
						for (int i = row + 1; i < b; i++)
Toshihiro Shimizu 890ddd
							xsh->setCell(i, col, cell);
Toshihiro Shimizu 890ddd
						m_cellsData.push_back(row);
Toshihiro Shimizu 890ddd
						m_cellsData.push_back(b - 1);
Toshihiro Shimizu 890ddd
						m_cellsData.push_back(2); // vuoto => nuovo
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						m_cellsData.push_back(row);
Toshihiro Shimizu 890ddd
						m_cellsData.push_back(row);
Toshihiro Shimizu 890ddd
						m_cellsData.push_back(2); // vuoto => nuovo
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				} else if (b <= r1) {
Toshihiro Shimizu 890ddd
					// create a hold after
Toshihiro Shimizu 890ddd
					for (int i = row + 1; i < b; i++)
Toshihiro Shimizu 890ddd
						xsh->setCell(i, col, cell);
Toshihiro Shimizu 890ddd
					m_cellsData.push_back(row);
Toshihiro Shimizu 890ddd
					m_cellsData.push_back(b - 1);
Toshihiro Shimizu 890ddd
					m_cellsData.push_back(2); // vuoto => nuovo
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			// notify & return
Toshihiro Shimizu 890ddd
			currentXsheet->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
			currentScene->notifyCastChange();
Toshihiro Shimizu 890ddd
			currentLevel->notifyLevelChange();
Toshihiro Shimizu 890ddd
			return cell.getImage(true).getPointer();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (row > 0 && xsh->getCell(row - 1, col).getSimpleLevel() != 0 && !animationSheetEnabled) {
Toshihiro Shimizu 890ddd
			sl = xsh->getCell(row - 1, col).getSimpleLevel();
Toshihiro Shimizu 890ddd
			if (sl->getType() != OVL_XSHLEVEL || sl->getPath().getFrame() != TFrameId::NO_FRAME) {
Toshihiro Shimizu 890ddd
				// la cella precedente contiene un drawing di un livello. animationSheet e' disabilitato
Toshihiro Shimizu 890ddd
				// creo un nuovo frame
Toshihiro Shimizu 890ddd
				currentLevel->setLevel(sl);
Toshihiro Shimizu 890ddd
				if (sl->isSubsequence() || sl->isReadOnly())
Toshihiro Shimizu 890ddd
					return 0;
Toshihiro Shimizu 890ddd
				TFrameId fid = sl->index2fid(sl->getFrameCount());
Toshihiro Shimizu 890ddd
				TImageP img = sl->createEmptyFrame();
Toshihiro Shimizu 890ddd
				m_isFrameCreated = true;
Toshihiro Shimizu 890ddd
				sl->setFrame(fid, img);
Toshihiro Shimizu 890ddd
				cell = TXshCell(sl, fid);
Toshihiro Shimizu 890ddd
				xsh->setCell(row, col, cell);
Toshihiro Shimizu 890ddd
				currentXsheet->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
				currentScene->notifyCastChange();
Toshihiro Shimizu 890ddd
				currentLevel->notifyLevelChange();
Toshihiro Shimizu 890ddd
				return img.getPointer();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// animation sheet disabled or empty column. autoCreate is enabled: we must create a new level
Toshihiro Shimizu 890ddd
		int levelType = pref->getDefLevelType();
Toshihiro Shimizu 890ddd
		TXshLevel *xl = scene->createNewLevel(levelType);
Toshihiro Shimizu 890ddd
		sl = xl->getSimpleLevel();
Toshihiro Shimizu 890ddd
		m_isLevelCreated = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// create the drawing
Toshihiro Shimizu 890ddd
		TFrameId fid = animationSheetEnabled ? getNewFrameId(sl, row) : TFrameId(1);
Toshihiro Shimizu 890ddd
		TImageP img = sl->createEmptyFrame();
Toshihiro Shimizu 890ddd
		m_isFrameCreated = true;
Toshihiro Shimizu 890ddd
		sl->setFrame(fid, img);
Toshihiro Shimizu 890ddd
		cell = TXshCell(sl, fid);
Toshihiro Shimizu 890ddd
		xsh->setCell(row, col, cell);
Toshihiro Shimizu 890ddd
		if (animationSheetEnabled) {
Toshihiro Shimizu 890ddd
			m_cellsData.push_back(row);
Toshihiro Shimizu 890ddd
			m_cellsData.push_back(row);
Toshihiro Shimizu 890ddd
			m_cellsData.push_back(2); // vuoto => nuovo
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		currentXsheet->notifyXsheetChanged();
Toshihiro Shimizu 890ddd
		currentScene->notifyCastChange();
Toshihiro Shimizu 890ddd
		currentLevel->notifyLevelChange();
Toshihiro Shimizu 890ddd
		return img.getPointer();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTool::updateToolsPropertiesTranslation()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ToolTable::iterator tt, tEnd(toolTable->end());
Toshihiro Shimizu 890ddd
	for (tt = toolTable->begin(); tt != tEnd; ++tt)
Toshihiro Shimizu 890ddd
		tt->second->updateTranslation();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTool::invalidate(const TRectD &rect)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_viewer) {
Toshihiro Shimizu 890ddd
		if (rect.isEmpty())
Toshihiro Shimizu 890ddd
			m_viewer->GLInvalidateAll();
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			TPointD dpiScale(1, 1);
Toshihiro Shimizu 890ddd
			TXshSimpleLevel *sl = getApplication()->getCurrentLevel()->getSimpleLevel();
Toshihiro Shimizu 890ddd
			if (sl)
Toshihiro Shimizu 890ddd
				dpiScale = getCurrentDpiScale(sl, getCurrentFid());
Toshihiro Shimizu 890ddd
			m_viewer->GLInvalidateRect(getCurrentColumnMatrix() * TScale(dpiScale.x, dpiScale.y) * rect);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TTool::pick(const TPoint &p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_viewer)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_picking = true;
Toshihiro Shimizu 890ddd
	int ret = m_viewer->pick(p);
Toshihiro Shimizu 890ddd
	m_picking = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXsheet *TTool::getXsheet() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	return m_application->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TTool::getFrame()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	return m_application->getCurrentFrame()->getFrame();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TTool::getColumnIndex()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	return m_application->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TStageObjectId TTool::getObjectId()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return TStageObjectId();
Toshihiro Shimizu 890ddd
	return m_application->getCurrentObject()->getObjectId();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTool::Application *TTool::getApplication()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_application == 0)
Toshihiro Shimizu 890ddd
		assert(!"you MUST call the TTool::setApplication function in the main of the program!");
Toshihiro Shimizu 890ddd
	return m_application;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*! Notify change of current image: update icon and notify level change.
Toshihiro Shimizu 890ddd
    If current object is a spline commit spline chenged.
Toshihiro Shimizu 890ddd
    If current mode is EditingLevel touch current frame.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void TTool::notifyImageChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	onImageChanged();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_application->getCurrentScene()->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
	if (m_application->getCurrentFrame()->isEditingLevel()) {
Toshihiro Shimizu 890ddd
		TXshLevel *xl = m_application->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
		if (!xl)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = xl->getSimpleLevel();
Toshihiro Shimizu 890ddd
		if (!sl)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TFrameId fid = m_application->getCurrentFrame()->getFid();
Toshihiro Shimizu 890ddd
		sl->touchFrame(fid);
Toshihiro Shimizu 890ddd
		// sl->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		IconGenerator::instance()->invalidate(sl, fid);
Toshihiro Shimizu 890ddd
		IconGenerator::instance()->invalidateSceneIcon();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
		if (!xsh)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TObjectHandle *currentObject = m_application->getCurrentObject();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (currentObject->isSpline()) {
Toshihiro Shimizu 890ddd
			m_application->getCurrentObject()->commitSplineChanges();
Toshihiro Shimizu 890ddd
			TStageObject *pegbar = xsh->getStageObject(currentObject->getObjectId());
Toshihiro Shimizu 890ddd
			IconGenerator::instance()->invalidate(pegbar->getSpline());
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			int row = m_application->getCurrentFrame()->getFrame();
Toshihiro Shimizu 890ddd
			int col = m_application->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
			if (col < 0)
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			TXshCell cell = xsh->getCell(row, col);
Toshihiro Shimizu 890ddd
			TXshSimpleLevel *sl = cell.getSimpleLevel();
Toshihiro Shimizu 890ddd
			if (sl) {
Toshihiro Shimizu 890ddd
				IconGenerator::instance()->invalidate(sl, cell.m_frameId);
Toshihiro Shimizu 890ddd
				sl->touchFrame(cell.m_frameId);
Toshihiro Shimizu 890ddd
				IconGenerator::instance()->invalidateSceneIcon();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_application->getCurrentLevel()->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*! Notify change of image in \b fid: update icon and notify level change.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void TTool::notifyImageChanged(const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	onImageChanged();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_application->getCurrentScene()->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
	if (m_application->getCurrentFrame()->isEditingLevel()) {
Toshihiro Shimizu 890ddd
		TXshLevel *xl = m_application->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
		if (!xl)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = xl->getSimpleLevel();
Toshihiro Shimizu 890ddd
		if (!sl)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		sl->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		IconGenerator::instance()->invalidate(sl, fid);
Toshihiro Shimizu 890ddd
		IconGenerator::instance()->invalidateSceneIcon();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		int row = m_application->getCurrentFrame()->getFrame();
Toshihiro Shimizu 890ddd
		int col = m_application->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
		if (col < 0)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
		if (!xsh)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TXshCell cell = xsh->getCell(row, col);
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = cell.getSimpleLevel();
Toshihiro Shimizu 890ddd
		if (sl) {
Toshihiro Shimizu 890ddd
			IconGenerator::instance()->invalidate(sl, fid);
Toshihiro Shimizu 890ddd
			IconGenerator::instance()->invalidateSceneIcon();
Toshihiro Shimizu 890ddd
			sl->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_application->getCurrentLevel()->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFrameId TTool::getCurrentFid() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return TFrameId();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameHandle *fh = m_application->getCurrentFrame();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (fh->isEditingLevel())
Toshihiro Shimizu 890ddd
		return fh->getFid();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int row = m_application->getCurrentFrame()->getFrame();
Toshihiro Shimizu 890ddd
	int col = m_application->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
	TXshCell cell = m_application->getCurrentXsheet()
Toshihiro Shimizu 890ddd
						->getXsheet()
Toshihiro Shimizu 890ddd
						->getCell(row, col);
Toshihiro Shimizu 890ddd
	if (cell.isEmpty())
Toshihiro Shimizu 890ddd
		return TFrameId::NO_FRAME;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return cell.getFrameId();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TAffine TTool::getCurrentColumnMatrix() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return getColumnMatrix(m_application->getCurrentColumn()->getColumnIndex());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TAffine TTool::getCurrentColumnParentMatrix() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameHandle *fh = m_application->getCurrentFrame();
Toshihiro Shimizu 890ddd
	if (fh->isEditingLevel())
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
	int frame = fh->getFrame();
Toshihiro Shimizu 890ddd
	int columnIndex = m_application->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
	TStageObjectId parentId = xsh->getStageObjectParent(TStageObjectId::ColumnId(columnIndex));
Toshihiro Shimizu 890ddd
	return xsh->getPlacement(parentId, frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TAffine TTool::getCurrentObjectParentMatrix() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
	int frame = m_application->getCurrentFrame()->getFrame();
Toshihiro Shimizu 890ddd
	TStageObjectId currentObjectId = m_application->getCurrentObject()->getObjectId();
Toshihiro Shimizu 890ddd
	if (currentObjectId == TStageObjectId::NoneId)
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
	TStageObjectId parentId = xsh->getStageObjectParent(currentObjectId);
Toshihiro Shimizu 890ddd
	if (parentId == TStageObjectId::NoneId)
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return xsh->getPlacement(parentId, frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TAffine TTool::getColumnMatrix(int columnIndex) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_application)
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameHandle *fh = m_application->getCurrentFrame();
Toshihiro Shimizu 890ddd
	if (fh->isEditingLevel())
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
	int frame = fh->getFrame();
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
	TStageObjectId columnId = TStageObjectId::ColumnId(columnIndex);
Toshihiro Shimizu 890ddd
	TAffine columnPlacement = xsh->getPlacement(columnId, frame);
Toshihiro Shimizu 890ddd
	double columnZ = xsh->getZ(columnId, frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId();
Toshihiro Shimizu 890ddd
	TStageObject *camera = xsh->getStageObject(cameraId);
Toshihiro Shimizu 890ddd
	TAffine cameraPlacement = camera->getPlacement(frame);
Toshihiro Shimizu 890ddd
	double cameraZ = camera->getZ(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TStageObject *object = xsh->getStageObject(columnId);
Toshihiro Shimizu 890ddd
	TAffine placement;
Toshihiro Shimizu 890ddd
	TStageObject::perspective(
Toshihiro Shimizu 890ddd
		placement,
Toshihiro Shimizu 890ddd
		cameraPlacement, cameraZ,
Toshihiro Shimizu 890ddd
		columnPlacement, columnZ,
Toshihiro Shimizu 890ddd
		object->getGlobalNoScaleZ());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return placement;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TAffine TTool::getCurrentObjectParentMatrix2() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTool::Application *app = m_application;
Toshihiro Shimizu 890ddd
	TFrameHandle *fh = app->getCurrentFrame();
Toshihiro Shimizu 890ddd
	if (fh->isEditingLevel())
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
	int frame = fh->getFrame();
Toshihiro Shimizu 890ddd
	TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
	TStageObjectId id = app->getCurrentObject()->getObjectId();
Toshihiro Shimizu 890ddd
	double objZ = xsh->getZ(id, frame);
Toshihiro Shimizu 890ddd
	TStageObjectId parentId = xsh->getStageObjectParent(id);
Toshihiro Shimizu 890ddd
	if (parentId == TStageObjectId::NoneId)
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
	id = parentId;
Toshihiro Shimizu 890ddd
	TAffine objPlacement = xsh->getPlacement(id, frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId();
Toshihiro Shimizu 890ddd
	TStageObject *camera = xsh->getStageObject(cameraId);
Toshihiro Shimizu 890ddd
	TAffine cameraPlacement = camera->getPlacement(frame);
Toshihiro Shimizu 890ddd
	double cameraZ = camera->getZ(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TAffine placement;
Toshihiro Shimizu 890ddd
	TStageObject::perspective(
Toshihiro Shimizu 890ddd
		placement,
Toshihiro Shimizu 890ddd
		cameraPlacement, cameraZ,
Toshihiro Shimizu 890ddd
		objPlacement, objZ,
Toshihiro Shimizu 890ddd
		0);
Toshihiro Shimizu 890ddd
	return placement;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTool::updateMatrix()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_application);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_application->getCurrentObject()->isSpline())
Toshihiro Shimizu 890ddd
		setMatrix(getCurrentObjectParentMatrix2());
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		setMatrix(getCurrentColumnMatrix());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTool::resetInputMethod()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_viewer)
Toshihiro Shimizu 890ddd
		m_viewer->resetInputMethod();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TTool::isColumnLocked(int columnIndex) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (columnIndex < 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	TXsheet *xsh = getXsheet();
Toshihiro Shimizu 890ddd
	TXshColumn *column = xsh->getColumn(columnIndex);
Toshihiro Shimizu 890ddd
	return column->isLocked();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QString TTool::updateEnabled()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// Disable every tool during playback
Toshihiro Shimizu 890ddd
	if (m_application->getCurrentFrame()->isPlaying())
Toshihiro Shimizu 890ddd
		return (enable(false), QString());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Release Generic tools at once
Toshihiro Shimizu 890ddd
	int toolType = getToolType();
Toshihiro Shimizu 890ddd
	int targetType = getTargetType();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (toolType == TTool::GenericTool)
Toshihiro Shimizu 890ddd
		return (enable(true), QString());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Retrieve vars and view modes
Toshihiro Shimizu 890ddd
	TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int rowIndex = m_application->getCurrentFrame()->getFrame();
Toshihiro Shimizu 890ddd
	int columnIndex = m_application->getCurrentColumn()->getColumnIndex();
Toshihiro Shimizu 890ddd
	TXshColumn *column = (columnIndex >= 0) ? xsh->getColumn(columnIndex) : 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXshLevel *xl = m_application->getCurrentLevel()->getLevel();
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
	int levelType = sl ? sl->getType() : NO_XSHLEVEL;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TStageObject *obj = xsh->getStageObject(TStageObjectId::ColumnId(columnIndex));
Toshihiro Shimizu 890ddd
	bool spline = m_application->getCurrentObject()->isSpline();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool filmstrip = m_application->getCurrentFrame()->isEditingLevel();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-- MultiLayerStylePickerONのときは、現状に関わらず使用可能 --*/
Toshihiro Shimizu 890ddd
	if (m_name == T_StylePicker && Preferences::instance()->isMultiLayerStylePickerEnabled())
Toshihiro Shimizu 890ddd
		return (enable(true), QString());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Check against unplaced columns (not in filmstrip mode)
Toshihiro Shimizu 890ddd
	if (column && !filmstrip) {
Toshihiro Shimizu 890ddd
		if (column->isLocked())
Toshihiro Shimizu 890ddd
			return (enable(false), QObject::tr("The current column is locked."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		else if (column->getSoundColumn())
Toshihiro Shimizu 890ddd
			return (enable(false), QObject::tr("It is not possible to edit the audio column."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		else if (column->getSoundTextColumn())
Toshihiro Shimizu 890ddd
			return (enable(false), QObject::tr("It is not possible to edit the Magpie column."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (toolType == TTool::ColumnTool) {
Toshihiro Shimizu 890ddd
			// Check column target
Toshihiro Shimizu 890ddd
			if (column->getLevelColumn() && !(targetType & LevelColumns))
Toshihiro Shimizu 890ddd
				return (enable(false), QObject::tr("The current tool cannot be used on a Level column."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (column->getMeshColumn() && !(targetType & MeshColumns))
Toshihiro Shimizu 890ddd
				return (enable(false), QObject::tr("The current tool cannot be used on a Mesh column."));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Check column tools
Toshihiro Shimizu 890ddd
	if (toolType == TTool::ColumnTool) {
Toshihiro Shimizu 890ddd
		if (filmstrip)
Toshihiro Shimizu 890ddd
			return (enable(false), QObject::tr("The current tool cannot be used in Level Strip mode."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if ((!column || column->isEmpty()) && !(targetType & TTool::EmptyTarget))
Toshihiro Shimizu 890ddd
			return (enable(false), QString());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Check LevelRead & LevelWrite tools
Toshihiro Shimizu 890ddd
	if (toolType & TTool::LevelTool) {
Toshihiro Shimizu 890ddd
		// Check against splines
Toshihiro Shimizu 890ddd
		if (spline) {
Toshihiro Shimizu 890ddd
			return (targetType & Splines) ? (enable(true), QString()) : (enable(false), QObject::tr("The current tool cannot be used to edit a motion path."));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Check against empty levels
Toshihiro Shimizu 890ddd
		if (!xl)
Toshihiro Shimizu 890ddd
			return (targetType & EmptyTarget) ? (enable(true), QString()) : (enable(false), QString());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Check against simple-level-edness
Toshihiro Shimizu 890ddd
		if (!sl)
Toshihiro Shimizu 890ddd
			return (enable(false), QObject::tr("The current level is not editable.")); // Does it happen at all btw?
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Check against level types
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			if ((levelType == PLI_XSHLEVEL) && !(targetType & VectorImage))
Toshihiro Shimizu 890ddd
				return (enable(false), QObject::tr("The current tool cannot be used on a Vector Level."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if ((levelType == TZP_XSHLEVEL) && !(targetType & ToonzImage))
Toshihiro Shimizu 890ddd
				return (enable(false), QObject::tr("The current tool cannot be used on a Toonz Level."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if ((levelType == OVL_XSHLEVEL) && !(targetType & RasterImage))
Toshihiro Shimizu 890ddd
				return (enable(false), QObject::tr("The current tool cannot be used on a Raster Level."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if ((levelType == MESH_XSHLEVEL) && !(targetType & MeshImage))
Toshihiro Shimizu 890ddd
				return (enable(false), QObject::tr("The current tool cannot be used on a Mesh Level."));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Check against impossibly traceable movements on the column
Toshihiro Shimizu 890ddd
		if ((levelType & LEVELCOLUMN_XSHLEVEL) && !filmstrip) {
Toshihiro Shimizu 890ddd
			// Test for Mesh-deformed levels
Toshihiro Shimizu 890ddd
			const TStageObjectId &parentId = obj->getParent();
Toshihiro Shimizu 890ddd
			if (parentId.isColumn() && obj->getParentHandle()[0] != 'H') {
Toshihiro Shimizu 890ddd
				TXshSimpleLevel *parentSl = xsh->getCell(rowIndex, parentId.getIndex()).getSimpleLevel();
Toshihiro Shimizu 890ddd
				if (parentSl && parentSl->getType() == MESH_XSHLEVEL)
Toshihiro Shimizu 890ddd
					return (enable(false), QObject::tr("The current tool cannot be used on a mesh-deformed level"));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Check TTool::ImageType tools
Toshihiro Shimizu 890ddd
		if (toolType == TTool::LevelWriteTool) {
Toshihiro Shimizu 890ddd
			// Check level against read-only status
Toshihiro Shimizu 890ddd
			if (sl->isReadOnly()) {
Toshihiro Shimizu 890ddd
				const std::set<tframeid> &editableFrames = sl->getEditableRange();</tframeid>
Toshihiro Shimizu 890ddd
				TFrameId currentFid = getCurrentFid();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				if (editableFrames.find(currentFid) == editableFrames.end())
Toshihiro Shimizu 890ddd
					return (enable(false), QObject::tr("The current frame is locked: any editing is forbidden."));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// Check level type write support
Toshihiro Shimizu 890ddd
			if (sl->getPath().getType() == "psd" || // We don't have the API to write psd files
Toshihiro Shimizu 890ddd
				sl->is16BitChannelLevel() ||		// Inherited by previous implementation. Could be fixed?
Toshihiro Shimizu 890ddd
				sl->getProperties()->getBpp() == 1) // Black & White images. Again, could be fixed?
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				return (enable(false), QObject::tr("The current level is not editable."));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return (enable(true), QString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTool::setSelectedFrames(const std::set<tframeid> &selectedFrames)</tframeid>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_selectedFrames = selectedFrames;
Toshihiro Shimizu 890ddd
	onSelectedFramesChanged();
Toshihiro Shimizu 890ddd
}