tahoma2d/toonz/sources/toonzlib/xshhandlemanager.cpp

154 lines
4.3 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
// TnzLib includes
#include "toonz/txsheet.h"
#include "toonz/txshcell.h"
#include "toonz/hook.h"
#include "toonz/dpiscale.h"
#include "toonz/txshsimplelevel.h"
#include "toonz/stage.h"
#include "xshhandlemanager.h"
//*******************************************************************************
// Local namespace
//*******************************************************************************
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
// Returns the sum of each pass hook between fid and precFid.
TPointD forwardPass(const TFrameId &fid, const TFrameId &precFid,
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *sl, Hook *hook) {
TPointD delta;
std::vector<TFrameId> levelFids;
sl->getFids(levelFids);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int f, fCount = levelFids.size();
for (f = 0; f != fCount; ++f) {
const TFrameId &levelFid = levelFids[f];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (levelFid < precFid) continue;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (levelFid >= fid) break;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (hook->isKeyframe(levelFid))
delta += hook->getAPos(levelFid) - hook->getBPos(levelFid);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return delta;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
// Returns subtraction of each pass hook between fid and precFid.
TPointD backwardPass(const TFrameId &fid, const TFrameId &precFid,
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *sl, Hook *hook) {
TPointD delta;
std::vector<TFrameId> levelFids;
sl->getFids(levelFids);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int f, fCount = levelFids.size();
for (f = 0; f != fCount; ++f) {
const TFrameId &levelFid = levelFids[f];
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (levelFid < fid) continue;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (levelFid >= precFid) break;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (hook->isKeyframe(levelFid))
delta -= hook->getAPos(levelFid) - hook->getBPos(levelFid);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return delta;
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
// Compute pass hook between fid and precFid
TPointD computePassHook(const TFrameId &fid, const TFrameId &precFid,
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *sl, Hook *hook) {
if (fid < precFid && (precFid.getNumber() - fid.getNumber()) <= 2)
return backwardPass(fid, precFid, sl, hook);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return forwardPass(fid, precFid, sl, hook);
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
} // namespace
2016-03-19 06:57:51 +13:00
//*******************************************************************************
// XshHandleManager implementation
//*******************************************************************************
2016-06-15 18:43:10 +12:00
TPointD XshHandleManager::getHandlePos(const TStageObjectId &id,
const std::string &handle,
int row) const {
static const double unit = 8.0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(m_xsh->getScene());
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (handle == "")
return TPointD();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
else if (handle[0] == 'H' && handle.length() > 1) {
// Hook port case
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!id.isColumn()) return TPointD();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int hookIndex = 0;
{
int h, hLength = handle.length();
for (h = 1; h != hLength; ++h)
hookIndex = hookIndex * 10 + (handle[h] - '0');
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TStageObject *obj = m_xsh->getStageObject(id);
if (const PlasticSkeletonDeformationP &def =
obj->getPlasticSkeletonDeformation()) {
int skelId = def->skeletonId(row);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PlasticSkeleton skel;
def->storeDeformedSkeleton(skelId, row, skel);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int v = def->vertexIndex(hookIndex, skelId);
return (v >= 0) ? TScale(1.0 / Stage::inch) * skel.vertex(v).P()
: TPointD();
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
--hookIndex;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int col = id.getIndex();
TXshCell cell(m_xsh->getCell(row, col));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshLevel *xl = cell.m_level.getPointer();
if (!xl) return TPointD();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *sl = xl->getSimpleLevel();
if (!sl) return TPointD();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Hook *hook = sl->getHookSet()->getHook(hookIndex);
if (!hook) return TPointD();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TFrameId fid(cell.m_frameId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPointD pos = hook->getAPos(fid) * (1.0 / Stage::inch);
TPointD delta;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
for (int r = row - 1; r >= 0; --r) {
cell = m_xsh->getCell(r, col);
if (cell.m_level.getPointer() != xl) break;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TFrameId &precFid = cell.m_frameId;
delta += computePassHook(fid, precFid, sl, hook);
fid = precFid;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
pos += delta * (1.0 / Stage::inch);
pos = getDpiAffine(sl, cell.m_frameId, true) * pos;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return pos;
} else if ('A' <= handle[0] && handle[0] <= 'Z')
return TPointD(unit * (handle[0] - 'B'), 0);
else if ('a' <= handle[0] && handle[0] <= 'z')
return TPointD(0.5 * unit * (handle[0] - 'b'), 0);
else
return TPointD();
2016-03-19 06:57:51 +13:00
}