Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/studiopalettecmd.h"
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelhandle.h"
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/studiopalette.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelset.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzfolders.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Campbell Barton d0e335
#include <qapplication></qapplication>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "historytypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*! \namespace StudioPaletteCmd
Toshihiro Shimizu 890ddd
		\brief Provides a collection of methods to manage \b StudioPalette.
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
//=============================================================================
Toshihiro Shimizu 890ddd
//PaletteAssignUndo : Undo for the "Load into Current Palette" command.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class PaletteAssignUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteP m_targetPalette, m_oldPalette, m_newPalette;
Toshihiro Shimizu 890ddd
	TPaletteHandle *m_paletteHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	PaletteAssignUndo(
Toshihiro Shimizu 890ddd
		const TPaletteP &targetPalette,
Toshihiro Shimizu 890ddd
		const TPaletteP &oldPalette,
Toshihiro Shimizu 890ddd
		const TPaletteP &newPalette,
Toshihiro Shimizu 890ddd
		TPaletteHandle *paletteHandle)
Toshihiro Shimizu 890ddd
		: m_targetPalette(targetPalette), m_oldPalette(oldPalette), m_newPalette(newPalette), m_paletteHandle(paletteHandle)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_targetPalette->assign(m_oldPalette.getPointer());
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_targetPalette->assign(m_newPalette.getPointer());
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) +
Toshihiro Shimizu 890ddd
			   (m_targetPalette->getStyleCount() +
Toshihiro Shimizu 890ddd
				m_oldPalette->getStyleCount() +
Toshihiro Shimizu 890ddd
				m_newPalette->getStyleCount()) *
Toshihiro Shimizu 890ddd
				   100;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Load into Current Palette  > %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdWString(m_targetPalette->getPaletteName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//StudioPaletteAssignUndo : Undo for the "Replace with Current Palette" command.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class StudioPaletteAssignUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPaletteP m_oldPalette, m_newPalette;
Toshihiro Shimizu 890ddd
	TFilePath m_fp;
Toshihiro Shimizu 890ddd
	TPaletteHandle *m_paletteHandle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	StudioPaletteAssignUndo(
Toshihiro Shimizu 890ddd
		const TFilePath &targetPath,
Toshihiro Shimizu 890ddd
		const TPaletteP &oldPalette,
Toshihiro Shimizu 890ddd
		const TPaletteP &newPalette,
Toshihiro Shimizu 890ddd
		TPaletteHandle *paletteHandle)
Toshihiro Shimizu 890ddd
		: m_fp(targetPath), m_oldPalette(oldPalette), m_newPalette(newPalette), m_paletteHandle(paletteHandle)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette *sp = StudioPalette::instance();
Toshihiro Shimizu 890ddd
		sp->setPalette(m_fp, m_oldPalette.getPointer(), true);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette *sp = StudioPalette::instance();
Toshihiro Shimizu 890ddd
		sp->setPalette(m_fp, m_newPalette.getPointer(), true);
Toshihiro Shimizu 890ddd
		m_paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) +
Toshihiro Shimizu 890ddd
			   (m_oldPalette->getStyleCount() +
Toshihiro Shimizu 890ddd
				m_newPalette->getStyleCount()) *
Toshihiro Shimizu 890ddd
				   100;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Replace with Current Palette  > %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdString(m_fp.getLevelName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//DeletePaletteUndo
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DeletePaletteUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath m_palettePath;
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DeletePaletteUndo(const TFilePath &palettePath)
Toshihiro Shimizu 890ddd
		: m_palettePath(palettePath)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_palette = StudioPalette::instance()->getPalette(m_palettePath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->setPalette(m_palettePath, m_palette->clone(), true);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->deletePalette(m_palettePath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + sizeof(TPalette);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Delete Studio Palette  : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdString(m_palettePath.getLevelName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//CreatePaletteUndo
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CreatePaletteUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath m_palettePath;
Toshihiro Shimizu 890ddd
	TPaletteP m_palette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	CreatePaletteUndo(const TFilePath &palettePath)
Toshihiro Shimizu 890ddd
		: m_palettePath(palettePath)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_palette = StudioPalette::instance()->getPalette(m_palettePath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->deletePalette(m_palettePath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->setPalette(m_palettePath, m_palette->clone(), true);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + sizeof(TPalette);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Create Studio Palette  : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdString(m_palettePath.getLevelName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//DeleteFolderUndo
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DeleteFolderUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath m_path;
Toshihiro Shimizu 890ddd
	TFilePathSet m_pathSet;
Toshihiro Shimizu 890ddd
	QList<tpalettep> m_paletteList;</tpalettep>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DeleteFolderUndo(const TFilePath &path, const TFilePathSet &pathSet)
Toshihiro Shimizu 890ddd
		: m_path(path), m_pathSet(pathSet), m_paletteList()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		for (TFilePathSet::const_iterator it = m_pathSet.begin(); it != m_pathSet.end(); it++) {
Toshihiro Shimizu 890ddd
			TFilePath path = *it;
Toshihiro Shimizu 890ddd
			if (path.getType() == "tpl")
Toshihiro Shimizu 890ddd
				m_paletteList.push_back(StudioPalette::instance()->getPalette(path));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->createFolder(m_path.getParentDir(), m_path.getWideName());
Toshihiro Shimizu 890ddd
		int paletteCount = -1;
Toshihiro Shimizu 890ddd
		for (TFilePathSet::const_iterator it = m_pathSet.begin(); it != m_pathSet.end(); it++) {
Toshihiro Shimizu 890ddd
			TFilePath path = *it;
Toshihiro Shimizu 890ddd
			if (path.getType() == "tpl") //Is a palette
Toshihiro Shimizu 890ddd
				StudioPalette::instance()->setPalette(path, m_paletteList.at(++paletteCount)->clone(), true);
Toshihiro Shimizu 890ddd
			else //Is a folder
Toshihiro Shimizu 890ddd
				StudioPalette::instance()->createFolder(path.getParentDir(), path.getWideName());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->deleteFolder(m_path);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + sizeof(TPalette);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Delete Studio Palette Folder  : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdString(m_path.getName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//CreateFolderUndo
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CreateFolderUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath m_folderPath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	CreateFolderUndo(const TFilePath &folderPath)
Toshihiro Shimizu 890ddd
		: m_folderPath(folderPath)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->deleteFolder(m_folderPath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->createFolder(m_folderPath.getParentDir(), m_folderPath.getWideName());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this) + sizeof(TPalette);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Create Studio Palette Folder  : %1")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdString(m_folderPath.getName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//MovePaletteUndo
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class MovePaletteUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath m_dstPath, m_srcPath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	MovePaletteUndo(const TFilePath &dstPath, const TFilePath &srcPath)
Toshihiro Shimizu 890ddd
		: m_dstPath(dstPath), m_srcPath(srcPath)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->movePalette(m_srcPath, m_dstPath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->movePalette(m_dstPath, m_srcPath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return sizeof(*this);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QString getHistoryString()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return QObject::tr("Move Studio Palette Folder  : %1 : %2 > %3")
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdString(m_srcPath.getName()))
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdString(m_srcPath.getParentDir().getName()))
Toshihiro Shimizu 890ddd
			.arg(QString::fromStdString(m_dstPath.getParentDir().getName()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int getHistoryType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return HistoryType::Palette;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------
Toshihiro Shimizu 890ddd
void adaptLevelToPalette(TXshLevelHandle *currentLevelHandle, TPaletteHandle *paletteHandle, TPalette *plt, int tolerance, bool noUndo);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class AdjustIntoCurrentPaletteUndo : public TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXshLevelHandle *m_currentLevelHandle;
Toshihiro Shimizu 890ddd
	TPaletteHandle *m_paletteHandle;
Toshihiro Shimizu 890ddd
	TPaletteP m_oldPalette, m_newPalette;
Toshihiro Shimizu 890ddd
	TFrameId m_fid;
Shinya Kitaoka 3bfa54
	std::string m_oldImageId;
Toshihiro Shimizu 890ddd
	static int m_idCount;
Toshihiro Shimizu 890ddd
	int m_undoSize;
Toshihiro Shimizu 890ddd
	int m_tolerance;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	AdjustIntoCurrentPaletteUndo(TXshLevelHandle *currentLevelHandle, TPaletteHandle *paletteHandle, const TFrameId &fid,
Toshihiro Shimizu 890ddd
								 const TImageP &oldImage, const TPaletteP &oldPalette, const TPaletteP &newPalette, int tolerance)
Toshihiro Shimizu 890ddd
		: TUndo(), m_currentLevelHandle(currentLevelHandle), m_paletteHandle(paletteHandle), m_fid(fid), m_oldPalette(oldPalette), m_newPalette(newPalette), m_tolerance(tolerance)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_oldImageId = "AdjustIntoCurrentPaletteUndo_oldImage_" + toString(m_idCount++);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TImageCache::instance()->add(m_oldImageId, (const TImageP)oldImage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_undoSize = ((TToonzImageP)oldImage)->getRaster()->getLx() * ((TToonzImageP)oldImage)->getRaster()->getLy() * ((TToonzImageP)oldImage)->getRaster()->getPixelSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~AdjustIntoCurrentPaletteUndo()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TImageCache::instance()->remove(m_oldImageId);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void undo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TImageP img = TImageCache::instance()->get(m_oldImageId, true);
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *level = m_currentLevelHandle->getSimpleLevel();
Toshihiro Shimizu 890ddd
		level->setPalette(m_oldPalette.getPointer());
Toshihiro Shimizu 890ddd
		//img->setPalette(m_oldPalette.getPointer());
Toshihiro Shimizu 890ddd
		level->setFrame(m_fid, img->cloneImage());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		level->touchFrame(m_fid);
Toshihiro Shimizu 890ddd
		if (level->getFirstFid() == m_fid) {
Toshihiro Shimizu 890ddd
			m_currentLevelHandle->notifyLevelChange();
Toshihiro Shimizu 890ddd
			m_paletteHandle->setPalette(m_oldPalette.getPointer());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			m_oldPalette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
			m_paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void redo() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		adaptLevelToPalette(m_currentLevelHandle, m_paletteHandle, m_newPalette.getPointer(), m_tolerance, true);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_undoSize;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
int AdjustIntoCurrentPaletteUndo::m_idCount = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::loadIntoCurrentPalette(TPaletteHandle *paletteHandle,
Toshihiro Shimizu 890ddd
											  const TFilePath &fp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = StudioPalette::instance()->getPalette(fp, false);
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	loadIntoCurrentPalette(paletteHandle, palette);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
std::map<tpixel, int=""> ToleranceMap;</tpixel,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
int findClosest(const TPixel &color, std::map<tpixel, int=""> &colorMap, int tolerance)</tpixel,>
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<tpixel, int="">::const_iterator it;</tpixel,>
Toshihiro Shimizu 890ddd
	it = ToleranceMap.find(color);
Toshihiro Shimizu 890ddd
	if (it != ToleranceMap.end())
Toshihiro Shimizu 890ddd
		return it->second;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	tolerance *= tolerance;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	it = colorMap.begin();
Toshihiro Shimizu 890ddd
	int index = -1, minDist = 99999999;
Toshihiro Shimizu 890ddd
	int dr, dg, db, dm;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (; it != colorMap.end(); ++it) {
Toshihiro Shimizu 890ddd
		if ((dr = (color.r - it->first.r) * (color.r - it->first.r)) > tolerance)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		if ((dg = (color.g - it->first.g) * (color.g - it->first.g)) > tolerance)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		if ((db = (color.b - it->first.b) * (color.b - it->first.b)) > tolerance)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		if ((dm = (color.m - it->first.m) * (color.m - it->first.m)) > tolerance)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int currDist = dr + dg + db + dm;
Toshihiro Shimizu 890ddd
		if (currDist < minDist)
Toshihiro Shimizu 890ddd
			minDist = currDist, index = it->second;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ToleranceMap[color] = index;
Toshihiro Shimizu 890ddd
	return index;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
int getIndex(const TPixel &color, std::map<tpixel, int=""> &colorMap, TPalette *plt, int tolerance)</tpixel,>
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<tpixel, int="">::const_iterator it;</tpixel,>
Toshihiro Shimizu 890ddd
	it = colorMap.find(color);
Toshihiro Shimizu 890ddd
	if (it != colorMap.end())
Toshihiro Shimizu 890ddd
		return it->second;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (tolerance > 0) {
Toshihiro Shimizu 890ddd
		int index = findClosest(color, colorMap, tolerance);
Toshihiro Shimizu 890ddd
		if (index != -1)
Toshihiro Shimizu 890ddd
			return index;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int index = plt->addStyle(color);
Toshihiro Shimizu 890ddd
	plt->getPage(0)->addStyle(index);
Toshihiro Shimizu 890ddd
	colorMap[color] = index;
Toshihiro Shimizu 890ddd
	return index;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void adaptIndexes(TToonzImageP timg, std::map<tpixel, int=""> &colorMap, TPalette *plt, int tolerance)</tpixel,>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *origPlt = timg->getPalette();
Toshihiro Shimizu 890ddd
	TRasterCM32P r = timg->getRaster();
Toshihiro Shimizu 890ddd
	TPixelCM32 oldPrev = TPixelCM32(), newPrev = TPixelCM32();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int i = 0; i < r->getLy(); i++) {
Toshihiro Shimizu 890ddd
		TPixelCM32 *pix = r->pixels(i);
Toshihiro Shimizu 890ddd
		for (int j = 0; j < r->getLx(); j++, pix++) {
Toshihiro Shimizu 890ddd
			if (*pix == TPixelCM32())
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			if (*pix == oldPrev) {
Toshihiro Shimizu 890ddd
				*pix = newPrev;
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			oldPrev = *pix;
Toshihiro Shimizu 890ddd
			int ink = pix->getInk();
Toshihiro Shimizu 890ddd
			int paint = pix->getPaint();
Toshihiro Shimizu 890ddd
			if (ink > 0) {
Toshihiro Shimizu 890ddd
				TPixel color = origPlt->getStyle(ink)->getMainColor();
Toshihiro Shimizu 890ddd
				int newIndex = getIndex(color, colorMap, plt, tolerance);
Toshihiro Shimizu 890ddd
				pix->setInk(newIndex);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			if (paint > 0) {
Toshihiro Shimizu 890ddd
				TPixel color = origPlt->getStyle(paint)->getMainColor();
Toshihiro Shimizu 890ddd
				int newIndex = getIndex(color, colorMap, plt, tolerance);
Toshihiro Shimizu 890ddd
				pix->setPaint(newIndex);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			newPrev = *pix;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void adaptLevelToPalette(TXshLevelHandle *currentLevelHandle, TPaletteHandle *paletteHandle, TPalette *plt, int tolerance, bool noUndo)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *sl = currentLevelHandle->getSimpleLevel();
Toshihiro Shimizu 890ddd
	QApplication::setOverrideCursor(Qt::WaitCursor);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *oldPalette = sl->getPalette();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ToleranceMap.clear();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::map<tpixel, int=""> colorMap;</tpixel,>
Toshihiro Shimizu 890ddd
	for (int i = 0; i < plt->getStyleCount(); i++) {
Toshihiro Shimizu 890ddd
		if (!plt->getStylePage(i))
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		colorMap[plt->getStyle(i)->getMainColor()] = i;
Toshihiro Shimizu 890ddd
	}
Shinya Kitaoka 3bfa54
	std::vector<tframeid> fids;</tframeid>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	sl->getFids(fids);
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)fids.size(); i++) {
Toshihiro Shimizu 890ddd
		TToonzImageP timg = (TToonzImageP)sl->getFrame(fids[i], true);
Toshihiro Shimizu 890ddd
		if (!timg)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		if (!noUndo)
Toshihiro Shimizu 890ddd
			TUndoManager::manager()->add(
Toshihiro Shimizu 890ddd
				new AdjustIntoCurrentPaletteUndo(currentLevelHandle, paletteHandle, fids[i], timg->cloneImage(), oldPalette->clone(), plt->clone(), tolerance));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		adaptIndexes(timg, colorMap, plt, tolerance);
Toshihiro Shimizu 890ddd
		timg->setPalette(plt);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	QApplication::restoreOverrideCursor();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	currentLevelHandle->getSimpleLevel()->setPalette(plt);
Toshihiro Shimizu 890ddd
	paletteHandle->setPalette(plt);
Toshihiro Shimizu 890ddd
	plt->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
	paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
	currentLevelHandle->notifyLevelChange();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} //namespaxce
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::loadIntoCurrentPalette(TPaletteHandle *paletteHandle, TPalette *plt, TXshLevelHandle *currentLevelHandle, int tolerance)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	adaptLevelToPalette(currentLevelHandle, paletteHandle, plt, tolerance, false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::loadIntoCurrentPalette(TPaletteHandle *paletteHandle,
Toshihiro Shimizu 890ddd
											  TPalette *palette)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(paletteHandle);
Toshihiro Shimizu 890ddd
	TPalette *current = paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
	if (!current)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int styleId = paletteHandle->getStyleIndex();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *old = current->clone();
Toshihiro Shimizu 890ddd
	while (palette->getStyleCount() < current->getStyleCount()) {
Toshihiro Shimizu 890ddd
		int index = palette->getStyleCount();
Toshihiro Shimizu 890ddd
		assert(index < current->getStyleCount());
Toshihiro Shimizu 890ddd
		TColorStyle *style = current->getStyle(index)->clone();
Toshihiro Shimizu 890ddd
		palette->addStyle(style);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	//keep the color model path unchanged
Toshihiro Shimizu 890ddd
	TFilePath oldRefImagePath = current->getRefImgPath();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	current->assign(palette, true);
Toshihiro Shimizu 890ddd
	current->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	current->setRefImgPath(oldRefImagePath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (paletteHandle->getPalette() == current && styleId >= current->getStyleCount())
Toshihiro Shimizu 890ddd
		paletteHandle->setStyleIndex(1);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(
Toshihiro Shimizu 890ddd
		new PaletteAssignUndo(current, old, current->clone(), paletteHandle));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::mergeIntoCurrentPalette(TPaletteHandle *paletteHandle,
Toshihiro Shimizu 890ddd
											   const TFilePath &fp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPalette *palette = StudioPalette::instance()->getPalette(fp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!palette)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	mergeIntoCurrentPalette(paletteHandle, palette);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::mergeIntoCurrentPalette(TPaletteHandle *paletteHandle,
Toshihiro Shimizu 890ddd
											   TPalette *palette)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(paletteHandle);
Toshihiro Shimizu 890ddd
	TPalette *current = paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!current)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (current->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *old = current->clone();
Toshihiro Shimizu 890ddd
	current->merge(palette, true);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(
Toshihiro Shimizu 890ddd
		new PaletteAssignUndo(current, old, current->clone(), paletteHandle));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	palette->setDirtyFlag(true);
Toshihiro Shimizu 890ddd
	paletteHandle->notifyPaletteChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::replaceWithCurrentPalette(TPaletteHandle *paletteHandle,
Toshihiro Shimizu 890ddd
												 TPaletteHandle *stdPaletteHandle,
Toshihiro Shimizu 890ddd
												 const TFilePath &fp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	StudioPalette *sp = StudioPalette::instance();
Toshihiro Shimizu 890ddd
	TPalette *palette = sp->getPalette(fp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!palette || palette->isLocked())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(paletteHandle);
Toshihiro Shimizu 890ddd
	TPalette *current = paletteHandle->getPalette();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!current)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	//keep the studio palette's global name unchanged
Toshihiro Shimizu 890ddd
	std::wstring oldGlobalName = palette->getGlobalName();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *old = palette->clone();
Toshihiro Shimizu 890ddd
	palette->assign(current);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//put back the global name
Toshihiro Shimizu 890ddd
	palette->setGlobalName(oldGlobalName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	sp->setPalette(fp, current, true);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(
Toshihiro Shimizu 890ddd
		new StudioPaletteAssignUndo(fp, old, current->clone(), paletteHandle));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Cambio la studioPalette correntette(palette);
Toshihiro Shimizu 890ddd
	stdPaletteHandle->setPalette(palette);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	stdPaletteHandle->notifyPaletteSwitched();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::updateAllLinkedStyles(TPaletteHandle *paletteHandle, TXsheetHandle *xsheetHandle)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!xsheetHandle)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TXsheet *xsheet = xsheetHandle->getXsheet();
Toshihiro Shimizu 890ddd
	if (!xsheet)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	ToonzScene *scene = xsheet->getScene();
Toshihiro Shimizu 890ddd
	if (!scene)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//emit signal only if something changed
Toshihiro Shimizu 890ddd
	bool somethingChanged = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	StudioPalette *sp = StudioPalette::instance();
Toshihiro Shimizu 890ddd
	TLevelSet *levelSet = scene->getLevelSet();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < levelSet->getLevelCount(); i++) {
Toshihiro Shimizu 890ddd
		TXshLevel *xl = levelSet->getLevel(i);
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
		if (!sl)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		TPalette *palette = sl->getPalette();
Toshihiro Shimizu 890ddd
		if (palette) {
Toshihiro Shimizu 890ddd
			somethingChanged = somethingChanged | sp->updateLinkedColors(palette);
Toshihiro Shimizu 890ddd
			if (sl->getType() == TZP_XSHLEVEL) {
Toshihiro Shimizu 890ddd
				std::vector<tframeid> fids;</tframeid>
Toshihiro Shimizu 890ddd
				sl->getFids(fids);
Toshihiro Shimizu 890ddd
				std::vector<tframeid>::iterator it;</tframeid>
Toshihiro Shimizu 890ddd
				for (it = fids.begin(); it != fids.end(); ++it) {
Toshihiro Shimizu 890ddd
					TFrameId fid = *it;
Shinya Kitaoka 3bfa54
					std::string id = sl->getImageId(fid);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!paletteHandle || !paletteHandle->getPalette())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (somethingChanged)
Toshihiro Shimizu 890ddd
		paletteHandle->notifyColorStyleChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Delete palette identified by \b fp in \b StudioPalette. If there are any
Toshihiro Shimizu 890ddd
		problems in loading send an error message.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::deletePalette(const TFilePath &fp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TUndo *undo = new DeletePaletteUndo(fp);
Toshihiro Shimizu 890ddd
	StudioPalette::instance()->deletePalette(fp);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Move palette from TFilePath \b srcPath to \b TFilePath \b dstPath. If there
Toshihiro Shimizu 890ddd
		are any problems in moving send an error message.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::movePalette(const TFilePath &dstPath, const TFilePath &srcPath)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TSystem::touchParentDir(dstPath);
Toshihiro Shimizu 890ddd
	StudioPalette::instance()->movePalette(dstPath, srcPath);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(new MovePaletteUndo(dstPath, srcPath));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Create palette \b palette in folder \b folderName with name \b paletteName.
Toshihiro Shimizu 890ddd
		If there are any problems send an error message.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
TFilePath StudioPaletteCmd::createPalette(const TFilePath &folderName,
Shinya Kitaoka 3bfa54
										  std::string paletteName,
Toshihiro Shimizu 890ddd
										  const TPalette *palette)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath palettePath;
Toshihiro Shimizu 890ddd
	TFileStatus status(folderName);
Toshihiro Shimizu 890ddd
	if (!status.isDirectory())
Toshihiro Shimizu 890ddd
		throw TException("Select a folder.");
Toshihiro Shimizu 890ddd
	if (!status.doesExist()) {
Toshihiro Shimizu 890ddd
		TSystem::mkDir(folderName);
Toshihiro Shimizu 890ddd
		FolderListenerManager::instance()->notifyFolderChanged(folderName.getParentDir());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	palettePath = StudioPalette::instance()->createPalette(folderName, paletteName);
Toshihiro Shimizu 890ddd
	if (palette)
Toshihiro Shimizu 890ddd
		StudioPalette::instance()->setPalette(palettePath, palette, true);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(new CreatePaletteUndo(palettePath));
Toshihiro Shimizu 890ddd
	return palettePath;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Add a folder in StudioPalette TFilePath \b parentFolderPath. If there
Toshihiro Shimizu 890ddd
		are any problems send an error message.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
TFilePath StudioPaletteCmd::addFolder(const TFilePath &parentFolderPath)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath folderPath;
Toshihiro Shimizu 890ddd
	folderPath = StudioPalette::instance()->createFolder(parentFolderPath);
Toshihiro Shimizu 890ddd
	if (!folderPath.isEmpty())
Toshihiro Shimizu 890ddd
		TUndoManager::manager()->add(new CreateFolderUndo(folderPath));
Toshihiro Shimizu 890ddd
	return folderPath;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Delete folder \b folderPath. If there are any problems in deleting send an
Toshihiro Shimizu 890ddd
		error message.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::deleteFolder(const TFilePath &folderPath)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePathSet folderPathSet;
Toshihiro Shimizu 890ddd
	TSystem::readDirectoryTree(folderPathSet, folderPath, true, false);
Toshihiro Shimizu 890ddd
	TUndo *undo = new DeleteFolderUndo(folderPath, folderPathSet);
Toshihiro Shimizu 890ddd
	StudioPalette::instance()->deleteFolder(folderPath);
Toshihiro Shimizu 890ddd
	TUndoManager::manager()->add(undo);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void StudioPaletteCmd::scanPalettes(const TFilePath &folder, const TFilePath &sourcePath)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//  error("uh oh");
Toshihiro Shimizu 890ddd
}