Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/hook.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Hook::Hook() : m_id(0), m_trackerObjectId(-1) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool Hook::isEmpty() const { return m_frames.empty(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool Hook::isKeyframe(const TFrameId &fid) const {
Shinya Kitaoka 120a6e
  return m_frames.count(fid) > 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Hook::Frames::const_iterator Hook::find(TFrameId fid) const {
Shinya Kitaoka 120a6e
  if (m_frames.empty()) return m_frames.end();
Shinya Kitaoka 120a6e
  Frames::const_iterator it;
Shinya Kitaoka 120a6e
  it = m_frames.lower_bound(fid);
Shinya Kitaoka 120a6e
  if (it == m_frames.end()) {
Shinya Kitaoka 120a6e
    // dopo l'ultimo
Shinya Kitaoka 120a6e
    assert(it != m_frames.begin());
Shinya Kitaoka 120a6e
    --it;
Shinya Kitaoka 120a6e
  } else if (it->first == fid || it == m_frames.begin()) {
Shinya Kitaoka 120a6e
    // giusto o prima del primo
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    --it;
Shinya Kitaoka 120a6e
  return it;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPointD Hook::getPos(const TFrameId &fid) const {
Shinya Kitaoka 120a6e
  // return TPointD(0,0);
Shinya Kitaoka 120a6e
  Frames::const_iterator it = find(fid);
Shinya Kitaoka 120a6e
  if (it == m_frames.end())
Shinya Kitaoka 120a6e
    return TPointD();
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return it->second.m_pos;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPointD Hook::getAPos(const TFrameId &fid) const {
Shinya Kitaoka 120a6e
  Frames::const_iterator it = find(fid);
Shinya Kitaoka 120a6e
  if (it == m_frames.end())
Shinya Kitaoka 120a6e
    return TPointD();
Shinya Kitaoka 120a6e
  else if (it->first == fid)
Shinya Kitaoka 120a6e
    return it->second.m_aPos;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return it->second.m_bPos;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPointD Hook::getBPos(const TFrameId &fid) const {
Shinya Kitaoka 120a6e
  Frames::const_iterator it = find(fid);
Shinya Kitaoka 120a6e
  if (it == m_frames.end())
Shinya Kitaoka 120a6e
    return TPointD();
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return it->second.m_bPos;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Hook::setAPos(const TFrameId &fid, TPointD pos) {
Shinya Kitaoka 120a6e
  Frames::iterator it = m_frames.lower_bound(fid);
Shinya Kitaoka 120a6e
  Frame f;
Shinya Kitaoka 120a6e
  if (it != m_frames.end() && it->first == fid) {
Shinya Kitaoka 120a6e
    f = it->second;
Shinya Kitaoka 120a6e
    if (f.m_aPos == f.m_bPos)
Shinya Kitaoka 120a6e
      f.m_aPos = f.m_bPos = pos;
Shinya Kitaoka 120a6e
    else if (tdistance2(pos, f.m_bPos) <= 1)
Shinya Kitaoka 120a6e
      f.m_aPos = f.m_bPos;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      f.m_aPos = pos;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    f.m_aPos = f.m_bPos = pos;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_frames[fid] = f;
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Hook::setBPos(const TFrameId &fid, TPointD pos) {
Shinya Kitaoka 120a6e
  Frames::iterator it = m_frames.lower_bound(fid);
Shinya Kitaoka 120a6e
  Frame f;
Shinya Kitaoka 120a6e
  if (it != m_frames.end() && it->first == fid) {
Shinya Kitaoka 120a6e
    f = it->second;
Shinya Kitaoka 120a6e
    if (tdistance2(pos, f.m_aPos) <= 1)
Shinya Kitaoka 120a6e
      f.m_bPos = f.m_aPos;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      f.m_bPos = pos;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    f.m_aPos = getAPos(fid);
Shinya Kitaoka 120a6e
    f.m_bPos = pos;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_frames[fid] = f;
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Shinya Kitaoka 120a6e
TRectD Hook::getTrackerRegion(const TFrameId &fid) {
Shinya Kitaoka 120a6e
  TRectD rect;
Shinya Kitaoka 120a6e
  rect.x0 = getPos(fid).x - (getTrackerRegionWidth() * 0.5);
Shinya Kitaoka 120a6e
  rect.y0 = getPos(fid).y - (getTrackerRegionHeight() * 0.5);
Shinya Kitaoka 120a6e
  rect.x1 = getPos(fid).x + (getTrackerRegionWidth() * 0.5);
Shinya Kitaoka 120a6e
  rect.y1 = getPos(fid).y + (getTrackerRegionHeight() * 0.5);
Shinya Kitaoka 120a6e
  return rect;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Hook::update() {
Shinya Kitaoka 120a6e
  TPointD delta;
Shinya Kitaoka 120a6e
  for (Frames::iterator it = m_frames.begin(); it != m_frames.end(); ++it) {
Shinya Kitaoka 120a6e
    it->second.m_pos = it->second.m_aPos + delta;
Shinya Kitaoka 120a6e
    delta -= it->second.m_bPos - it->second.m_aPos;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_delta = delta;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Hook::renumber(const std::map<tframeid, tframeid=""> &renumberTable) {</tframeid,>
Shinya Kitaoka 120a6e
  Frames oldFrames = m_frames;
Shinya Kitaoka 120a6e
  m_frames.clear();
Shinya Kitaoka 120a6e
  for (Frames::iterator it = oldFrames.begin(); it != oldFrames.end(); ++it) {
Shinya Kitaoka 120a6e
    std::map<tframeid, tframeid="">::const_iterator j =</tframeid,>
Shinya Kitaoka 120a6e
        renumberTable.find(it->first);
Shinya Kitaoka 120a6e
    assert(j != renumberTable.end());
Shinya Kitaoka 120a6e
    if (j == renumberTable.end()) continue;
Shinya Kitaoka 120a6e
    m_frames[j->second] = it->second;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Hook::eraseFrame(const TFrameId &fid) { m_frames.erase(fid); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Hook::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  Frames::iterator j;
Shinya Kitaoka 120a6e
  for (j = m_frames.begin(); j != m_frames.end(); ++j) {
Shinya Kitaoka 120a6e
    os.openChild("frame");
Shinya Kitaoka 120a6e
    os << j->first.getNumber();
Shinya Kitaoka 120a6e
    os << j->second.m_aPos.x << j->second.m_aPos.y;
Shinya Kitaoka 120a6e
    os << j->second.m_bPos.x << j->second.m_bPos.y;
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (m_trackerObjectId >= 0) {
Shinya Kitaoka 120a6e
    os.openChild("tracker");
Shinya Kitaoka 120a6e
    os << m_trackerObjectId << m_width << m_height;
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Hook::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  m_frames.clear();
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.matchTag(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName == "frame") {
Shinya Kitaoka 120a6e
      Frame f;
Shinya Kitaoka 120a6e
      int frameNumber = 0;
Shinya Kitaoka 120a6e
      is >> frameNumber;
Shinya Kitaoka 120a6e
      is >> f.m_aPos.x >> f.m_aPos.y;
Shinya Kitaoka 120a6e
      is >> f.m_bPos.x >> f.m_bPos.y;
Shinya Kitaoka 120a6e
      m_frames[TFrameId(frameNumber)] = f;
Shinya Kitaoka 120a6e
      m_trackerObjectId               = -1;
Shinya Kitaoka 120a6e
    } else if (tagName == "tracker") {
Shinya Kitaoka 120a6e
      is >> m_trackerObjectId;
Shinya Kitaoka 120a6e
      is >> m_width;
Shinya Kitaoka 120a6e
      is >> m_height;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      throw TException("expected ");
Shinya Kitaoka 120a6e
    is.matchEndTag();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
HookSet::HookSet() : m_trackerObjectsSet(new TrackerObjectsSet) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
HookSet::~HookSet() {
Shinya Kitaoka 120a6e
  clearPointerContainer(m_hooks);
Shinya Kitaoka 120a6e
  delete m_trackerObjectsSet;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
HookSet::HookSet(const HookSet &other)
Shinya Kitaoka 120a6e
    : m_hooks(other.m_hooks), m_trackerObjectsSet(new TrackerObjectsSet) {
Shinya Kitaoka 120a6e
  int h, hCount = m_hooks.size();
Shinya Kitaoka 120a6e
  for (h                       = 0; h != hCount; ++h)
Shinya Kitaoka 120a6e
    if (m_hooks[h]) m_hooks[h] = new Hook(*m_hooks[h]);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
HookSet &HookSet::operator=(const HookSet &other) {
Shinya Kitaoka 120a6e
  clearPointerContainer(m_hooks);
Shinya Kitaoka 120a6e
  m_hooks = other.m_hooks;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int h, hCount = m_hooks.size();
Shinya Kitaoka 120a6e
  for (h                       = 0; h != hCount; ++h)
Shinya Kitaoka 120a6e
    if (m_hooks[h]) m_hooks[h] = new Hook(*m_hooks[h]);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int HookSet::getHookCount() const { return m_hooks.size(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Hook *HookSet::getHook(int index) const {
Shinya Kitaoka 120a6e
  return 0 <= index && index < getHookCount() ? m_hooks[index] : 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Hook *HookSet::touchHook(int index) {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < maxHooksCount);
Shinya Kitaoka 120a6e
  if (index < 0 || index >= maxHooksCount) return 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (index >= (int)m_hooks.size()) m_hooks.push_back(0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_hooks[index] == 0) {
Shinya Kitaoka 120a6e
    Hook *hook     = new Hook();
Shinya Kitaoka 120a6e
    m_hooks[index] = hook;
Shinya Kitaoka 120a6e
    hook->m_id     = index;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return m_hooks[index];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Hook *HookSet::addHook() {
Shinya Kitaoka 120a6e
  int h, hCount = m_hooks.size();
Shinya Kitaoka 120a6e
  for (h = 0; h != hCount; ++h) {
Shinya Kitaoka 120a6e
    if (m_hooks[h] == 0) {
Shinya Kitaoka 120a6e
      Hook *hook = new Hook();
Shinya Kitaoka 120a6e
      m_hooks[h] = hook;
Shinya Kitaoka 120a6e
      hook->m_id = h;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      return hook;
Shinya Kitaoka 120a6e
    } else if (m_hooks[h]->isEmpty())
Shinya Kitaoka 120a6e
      return m_hooks[h];
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_hooks.size() >= maxHooksCount) return 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Hook *hook = new Hook();
Shinya Kitaoka 120a6e
  hook->m_id = m_hooks.size();
Shinya Kitaoka 120a6e
  m_hooks.push_back(hook);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return hook;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void HookSet::clearHook(Hook *hook) {
Shinya Kitaoka 120a6e
  for (int i                           = 0; i < (int)m_hooks.size(); i++)
Shinya Kitaoka 120a6e
    if (m_hooks[i] == hook) m_hooks[i] = 0;
Shinya Kitaoka 120a6e
  delete hook;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void HookSet::clearHooks() {
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)m_hooks.size(); i++) delete m_hooks[i];
Shinya Kitaoka 120a6e
  m_hooks.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TrackerObjectsSet *HookSet::getTrackerObjectsSet() const {
Shinya Kitaoka 120a6e
  // Ripulisco l'insieme dei tracker objects
Shinya Kitaoka 120a6e
  m_trackerObjectsSet->clearAll();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // costruisco il tracker object in base agli Hook
Shinya Kitaoka 120a6e
  for (int i = 0; i < getHookCount(); ++i) {
Shinya Kitaoka 120a6e
    Hook *hook = getHook(i);
Shinya Kitaoka 120a6e
    if (!hook || hook->isEmpty()) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int trackerObjectId = hook->getTrackerObjectId();
Shinya Kitaoka 120a6e
    if (trackerObjectId >= 0)  // se l'Hook ha anche una regione
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      TrackerObject *trackerObject =
Shinya Kitaoka 120a6e
          m_trackerObjectsSet->getObject(trackerObjectId);
Shinya Kitaoka 120a6e
      if (trackerObject == NULL) {
Shinya Kitaoka 120a6e
        trackerObject = new TrackerObject(trackerObjectId);
Shinya Kitaoka 120a6e
        m_trackerObjectsSet->addObject(trackerObject);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      trackerObject = m_trackerObjectsSet->getObject(trackerObjectId);
Shinya Kitaoka 120a6e
      assert(trackerObject != NULL);
Shinya Kitaoka 120a6e
      trackerObject->addHook(hook);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return m_trackerObjectsSet;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void HookSet::renumber(const std::map<tframeid, tframeid=""> &renumberTable) {</tframeid,>
Shinya Kitaoka 120a6e
  for (int i = 0; i < getHookCount(); i++)
Shinya Kitaoka 120a6e
    if (getHook(i)) getHook(i)->renumber(renumberTable);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void HookSet::eraseFrame(const TFrameId &fid) {
Shinya Kitaoka 120a6e
  for (int i = 0; i < getHookCount(); i++)
Shinya Kitaoka 120a6e
    if (getHook(i)) getHook(i)->eraseFrame(fid);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void HookSet::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  for (int i = 0; i < getHookCount(); ++i) {
Shinya Kitaoka 120a6e
    os.openChild("hook");
Shinya Kitaoka 120a6e
    Hook *hook = getHook(i);
Shinya Kitaoka 120a6e
    // Pay attention: it is necessary that empty hook will be however saved
Shinya Kitaoka 120a6e
    // in the xml file.
Shinya Kitaoka 120a6e
    if (hook) hook->saveData(os);
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void HookSet::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.matchTag(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName == "hook") {
Shinya Kitaoka 120a6e
      Hook *hook = new Hook();
Shinya Kitaoka 120a6e
      hook->m_id = m_hooks.size();
Shinya Kitaoka 120a6e
      hook->loadData(is);
Shinya Kitaoka 120a6e
      is.matchEndTag();
Shinya Kitaoka 120a6e
      m_hooks.push_back(hook);
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    is.matchEndTag();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//	TRACKER
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Hook *TrackerObject::getHook(int index) {
Shinya Kitaoka 120a6e
  assert(index >= 0 && index < getHooksCount());
Shinya Kitaoka 120a6e
  return m_hooks.at(index);
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void TrackerObject::addHook(Hook *hook) { m_hooks.push_back(hook); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TrackerObject::removeHook(int index) {
Shinya Kitaoka 120a6e
  assert(index >= 0 && index < (int)m_hooks.size());
Shinya Kitaoka 120a6e
  m_hooks.erase(m_hooks.begin() + index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TrackerObject *TrackerObjectsSet::getObject(int objectId) {
Shinya Kitaoka 120a6e
  assert(objectId >= 0);
Shinya Kitaoka 120a6e
  std::map<int, *="" trackerobject="">::iterator it = m_trackerObjects.find(objectId);</int,>
Shinya Kitaoka 120a6e
  if (it != m_trackerObjects.end())
Shinya Kitaoka 120a6e
    return it->second;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return NULL;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TrackerObject *TrackerObjectsSet::getObjectFromIndex(int index) {
Shinya Kitaoka 120a6e
  assert(index >= 0 && index < (int)m_trackerObjects.size());
Shinya Kitaoka 120a6e
  return m_trackerObjects[index];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// return objectIndex, return -1 if objectId doesn't exist
Shinya Kitaoka 120a6e
int TrackerObjectsSet::getIndexFromId(int objectId) {
Shinya Kitaoka 120a6e
  int index = -1;
Shinya Kitaoka 120a6e
  int i     = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)m_trackerObjects.size(); i++) {
Shinya Kitaoka 120a6e
    int id = m_trackerObjects[i]->getId();
Shinya Kitaoka 120a6e
    if (id == objectId) {
Shinya Kitaoka 120a6e
      index = i;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return index;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
int TrackerObjectsSet::getIdFromIndex(int index) {
Shinya Kitaoka 120a6e
  assert(index >= 0 && index < (int)m_trackerObjects.size());
Shinya Kitaoka 120a6e
  return m_trackerObjects[index]->getId();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// add new object, return new object Id
Shinya Kitaoka 120a6e
int TrackerObjectsSet::addObject() {
Shinya Kitaoka 120a6e
  // assegno l'id
Shinya Kitaoka 120a6e
  int id;
Shinya Kitaoka 120a6e
  if (m_trackerObjects.size() > 0) {
Shinya Kitaoka 120a6e
    std::map<int, *="" trackerobject="">::iterator it = m_trackerObjects.end();</int,>
Shinya Kitaoka 120a6e
    --it;
Shinya Kitaoka 120a6e
    id = it->first + 1;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    id = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TrackerObject *trackerObject = new TrackerObject(id);
Shinya Kitaoka 120a6e
  m_trackerObjects[id]         = trackerObject;
Shinya Kitaoka 120a6e
  return id;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TrackerObjectsSet::addObject(TrackerObject *trackerObject) {
Shinya Kitaoka 120a6e
  assert(trackerObject);
Shinya Kitaoka 120a6e
  int id = trackerObject->getId();
Shinya Kitaoka 120a6e
  assert(id >= 0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_trackerObjects[id] = trackerObject;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TrackerObjectsSet::removeObject(int objectId) {
Shinya Kitaoka 120a6e
  assert(objectId >= 0);
Shinya Kitaoka 120a6e
  std::map<int, *="" trackerobject="">::iterator tt = m_trackerObjects.find(objectId);</int,>
Shinya Kitaoka 120a6e
  if (tt != m_trackerObjects.end()) {
Shinya Kitaoka 120a6e
    delete tt->second;
Shinya Kitaoka 120a6e
    m_trackerObjects.erase(tt);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TrackerObjectsSet::clearAll() {
Shinya Kitaoka 120a6e
  std::map<int, *="" trackerobject="">::iterator tt, tEnd(m_trackerObjects.end());</int,>
Shinya Kitaoka 120a6e
  for (tt = m_trackerObjects.begin(); tt != tEnd; ++tt) delete tt->second;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_trackerObjects.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string getHookName(int code) {
Shinya Kitaoka 120a6e
  assert(0 <= code && code < 10);
Shinya Kitaoka 120a6e
  if (code == 0)
Shinya Kitaoka 120a6e
    return "B";
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return "H" + std::to_string(code);
Toshihiro Shimizu 890ddd
}