2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "toonz/txshpalettelevel.h"
|
|
|
|
#include "toonz/txshleveltypes.h"
|
|
|
|
#include "toonz/toonzscene.h"
|
|
|
|
#include "tconvert.h"
|
|
|
|
#include "tstream.h"
|
|
|
|
#include "tfilepath_io.h"
|
|
|
|
#include "tsystem.h"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DEFINE_CLASS_CODE(TXshPaletteLevel, 52)
|
|
|
|
|
|
|
|
PERSIST_IDENTIFIER(TXshPaletteLevel, "paletteLevel")
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// TXshPaletteLevel
|
|
|
|
|
2016-04-19 19:32:17 +12:00
|
|
|
TXshPaletteLevel::TXshPaletteLevel(std::wstring name)
|
2016-06-15 18:43:10 +12:00
|
|
|
: TXshLevel(m_classCode, name), m_palette(0) {
|
|
|
|
m_type = PLT_XSHLEVEL;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TXshPaletteLevel::~TXshPaletteLevel() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPalette *TXshPaletteLevel::getPalette() const { return m_palette; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TXshPaletteLevel::setPalette(TPalette *palette) {
|
|
|
|
if (m_palette != palette) {
|
|
|
|
if (m_palette) m_palette->release();
|
|
|
|
m_palette = palette;
|
|
|
|
if (m_palette) m_palette->addRef();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TXshPaletteLevel::setPath(const TFilePath &path) { m_path = path; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TXshPaletteLevel::loadData(TIStream &is) {
|
|
|
|
std::string tagName;
|
|
|
|
while (is.matchTag(tagName)) {
|
|
|
|
if (tagName == "name") {
|
|
|
|
std::wstring name;
|
|
|
|
is >> name;
|
|
|
|
setName(name);
|
|
|
|
} else if (tagName == "path") {
|
|
|
|
is >> m_path;
|
|
|
|
} else {
|
|
|
|
throw TException("TXshPaletteLevel, unknown tag: " + tagName);
|
|
|
|
}
|
|
|
|
is.closeChild();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TXshPaletteLevel::saveData(TOStream &os) {
|
|
|
|
os.child("path") << m_path;
|
|
|
|
os.child("name") << getName();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TXshPaletteLevel::load() {
|
|
|
|
TFilePath path = getScene()->decodeFilePath(m_path);
|
|
|
|
if (TSystem::doesExistFileOrLevel(path)) {
|
|
|
|
TFileStatus fs(path);
|
|
|
|
TPersist *p = 0;
|
|
|
|
TIStream is(path);
|
2018-09-19 21:41:16 +12:00
|
|
|
TPalette *palette = nullptr;
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
if (is && fs.doesExist()) {
|
2018-09-19 21:41:16 +12:00
|
|
|
std::string tagName;
|
|
|
|
if (is.matchTag(tagName) && tagName == "palette") {
|
|
|
|
std::string gname;
|
|
|
|
is.getTagParam("name", gname);
|
|
|
|
palette = new TPalette();
|
|
|
|
palette->loadData(is);
|
|
|
|
palette->setGlobalName(::to_wstring(gname));
|
|
|
|
is.matchEndTag();
|
|
|
|
palette->setPaletteName(path.getWideName());
|
|
|
|
setPalette(palette);
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
|
|
|
assert(m_palette);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TXshPaletteLevel::save() {
|
|
|
|
TFilePath path = getScene()->decodeFilePath(m_path);
|
2022-01-29 12:12:57 +13:00
|
|
|
if (TSystem::doesExistFileOrLevel(path) && m_palette &&
|
|
|
|
m_palette->getDirtyFlag()) {
|
2019-05-16 07:04:48 +12:00
|
|
|
TFileStatus fs(path);
|
|
|
|
if (!fs.isWritable()) {
|
|
|
|
throw TSystemException(
|
|
|
|
path, "The palette cannot be saved: it is a read only palette.");
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
TOStream os(path);
|
|
|
|
os << m_palette;
|
2022-01-29 12:12:57 +13:00
|
|
|
m_palette->setDirtyFlag(false);
|
2016-06-15 18:43:10 +12:00
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int TXshPaletteLevel::getFrameCount() const { return 0; }
|