tahoma2d/toonz/sources/toonzlib/txshpalettelevel.cpp

112 lines
3.1 KiB
C++
Raw Normal View History

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
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);
TPalette *palette = nullptr;
2016-06-15 18:43:10 +12:00
if (is && fs.doesExist()) {
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);
if (TSystem::doesExistFileOrLevel(path) && m_palette) {
TOStream os(path);
os << m_palette;
}
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
int TXshPaletteLevel::getFrameCount() const { return 0; }