Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tdoublekeyframe.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tunit.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TDoubleKeyframe::TDoubleKeyframe(double frame, double value)
Shinya Kitaoka 120a6e
    : m_type(Linear)
Shinya Kitaoka 120a6e
    , m_frame(frame)
Shinya Kitaoka 120a6e
    , m_value(value)
Shinya Kitaoka 120a6e
    , m_step(1)
Shinya Kitaoka 120a6e
    , m_isKeyframe(false)
Shinya Kitaoka 120a6e
    , m_speedIn()
Shinya Kitaoka 120a6e
    , m_speedOut()
Shinya Kitaoka 120a6e
    , m_linkedHandles(true)
Shinya Kitaoka 120a6e
    , m_expressionText("")
Shinya Kitaoka 120a6e
    , m_fileParams()
Shinya Kitaoka 120a6e
    , m_similarShapeOffset(0)
Shinya Kitaoka 120a6e
    , m_unitName("") {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDoubleKeyframe::~TDoubleKeyframe() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDoubleKeyframe::saveData(TOStream &os) const {
Shinya Kitaoka 120a6e
  static std::map<tdoublekeyframe::type, std::string=""> typeCodes;</tdoublekeyframe::type,>
Shinya Kitaoka 120a6e
  if (typeCodes.empty()) {
Shinya Kitaoka 120a6e
    typeCodes[None]                = "n";
Shinya Kitaoka 120a6e
    typeCodes[Constant]            = "C";
Shinya Kitaoka 120a6e
    typeCodes[Linear]              = "L";
Shinya Kitaoka 120a6e
    typeCodes[Exponential]         = "Exp";
Shinya Kitaoka 120a6e
    typeCodes[SpeedInOut]          = "S";
Shinya Kitaoka 120a6e
    typeCodes[EaseInOut]           = "E";
Shinya Kitaoka 120a6e
    typeCodes[EaseInOutPercentage] = "Ep";
Shinya Kitaoka 120a6e
    typeCodes[Expression]          = "Ex";
Shinya Kitaoka 120a6e
    typeCodes[File]                = "F";
Shinya Kitaoka 120a6e
    typeCodes[SimilarShape]        = "SimShape";
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  std::map<std::string, std::string=""> attr;</std::string,>
Shinya Kitaoka 120a6e
  if (!m_linkedHandles) attr["lnk"] = "no";
Shinya Kitaoka 120a6e
  if (m_step > 1) attr["step"]      = std::to_string(m_step);
Shinya Kitaoka 120a6e
  os.openChild(typeCodes[m_type], attr);
Shinya Kitaoka 120a6e
  switch (m_prevType) {
Shinya Kitaoka 120a6e
  case Linear:
Shinya Kitaoka 120a6e
    os.child("prev") << m_value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case SpeedInOut:
Shinya Kitaoka 120a6e
    os.child("prev") << m_value << m_speedIn.x << m_speedIn.y;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case EaseInOut:
Shinya Kitaoka 120a6e
  case EaseInOutPercentage:
Shinya Kitaoka 120a6e
    os.child("prev") << m_value << m_speedIn.x;
Shinya Kitaoka 120a6e
    break;
Rozhuk Ivan 823a31
  default:
Rozhuk Ivan 823a31
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  std::string unitName = m_unitName != "" ? m_unitName : "default";
Shinya Kitaoka 120a6e
  // Dirty resolution. Because the degree sign is converted to unexpected
Shinya Kitaoka 120a6e
  // string...
Shinya Kitaoka 120a6e
  if (QString::fromStdWString(L"\u00b0").toStdString() == unitName)
Shinya Kitaoka 120a6e
    unitName = "\\u00b0";
Shinya Kitaoka 120a6e
  switch (m_type) {
Shinya Kitaoka 120a6e
  case Constant:
Shinya Kitaoka 120a6e
  case Exponential:
Shinya Kitaoka 120a6e
  case Linear:
Shinya Kitaoka 120a6e
    os << m_frame << m_value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case SpeedInOut:
Shinya Kitaoka 120a6e
    os << m_frame << m_value << m_speedOut.x << m_speedOut.y;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case EaseInOut:
Shinya Kitaoka 120a6e
  case EaseInOutPercentage:
Shinya Kitaoka 120a6e
    os << m_frame << m_value << m_speedOut.x;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case Expression:
Shinya Kitaoka 120a6e
    os << m_frame << m_expressionText << unitName;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case SimilarShape:
Shinya Kitaoka 120a6e
    os << m_frame << m_value << m_expressionText << m_similarShapeOffset;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case File:
Shinya Kitaoka 120a6e
    os << m_frame << m_fileParams.m_path << m_fileParams.m_fieldIndex
Shinya Kitaoka 120a6e
       << unitName;
Shinya Kitaoka 120a6e
    break;
Rozhuk Ivan 823a31
  default:
Rozhuk Ivan 823a31
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  os.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDoubleKeyframe::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  static std::map<std::string, tdoublekeyframe::type=""> typeCodes;</std::string,>
Shinya Kitaoka 120a6e
  if (typeCodes.empty()) {
Shinya Kitaoka 120a6e
    typeCodes["n"]        = None;
Shinya Kitaoka 120a6e
    typeCodes["C"]        = Constant;
Shinya Kitaoka 120a6e
    typeCodes["L"]        = Linear;
Shinya Kitaoka 120a6e
    typeCodes["Exp"]      = Exponential;
Shinya Kitaoka 120a6e
    typeCodes["S"]        = SpeedInOut;
Shinya Kitaoka 120a6e
    typeCodes["E"]        = EaseInOut;
Shinya Kitaoka 120a6e
    typeCodes["Ep"]       = EaseInOutPercentage;
Shinya Kitaoka 120a6e
    typeCodes["Ex"]       = Expression;
Shinya Kitaoka 120a6e
    typeCodes["F"]        = File;
Shinya Kitaoka 120a6e
    typeCodes["SimShape"] = SimilarShape;
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  if (!is.matchTag(tagName)) return;
Shinya Kitaoka 120a6e
  std::map<std::string, tdoublekeyframe::type="">::iterator it =</std::string,>
Shinya Kitaoka 120a6e
      typeCodes.find(tagName);
Shinya Kitaoka 120a6e
  if (it == typeCodes.end()) {
Shinya Kitaoka 120a6e
    throw TException(tagName + " : unexpected tag");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_type = it->second;
Shinya Kitaoka 120a6e
  is.getTagParam("step", m_step);
Shinya Kitaoka 120a6e
  std::string lnkValue;
Shinya Kitaoka 120a6e
  if (is.getTagParam("lnk", lnkValue) && lnkValue == "no")
Shinya Kitaoka 120a6e
    m_linkedHandles = false;
Shinya Kitaoka 120a6e
  if (is.matchTag(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName != "prev") throw TException(tagName + " : unexpected tag");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    is >> m_value;
Shinya Kitaoka 120a6e
    if (!is.eos()) {
Shinya Kitaoka 120a6e
      is >> m_speedIn.x;
Shinya Kitaoka 120a6e
      if (!is.eos()) is >> m_speedIn.y;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (!is.matchEndTag()) throw TException(tagName + " : missing endtag");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  double dummy0, dummy1;
Shinya Kitaoka 120a6e
  switch (m_type) {
Shinya Kitaoka 120a6e
  case Constant:
Shinya Kitaoka 120a6e
  case Linear:
Shinya Kitaoka 120a6e
  case Exponential:
Shinya Kitaoka 120a6e
    is >> m_frame >> m_value;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case SpeedInOut:
Shinya Kitaoka 120a6e
    is >> m_frame >> m_value >> m_speedOut.x >> m_speedOut.y;
Shinya Kitaoka 120a6e
    if (!is.eos())
Shinya Kitaoka 120a6e
      is >> dummy0 >>
Shinya Kitaoka 120a6e
          dummy1;  // old and wrong format. used only during the 6.0 release
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case EaseInOut:
Shinya Kitaoka 120a6e
  case EaseInOutPercentage:
Shinya Kitaoka 120a6e
    is >> m_frame >> m_value >> m_speedOut.x;
Shinya Kitaoka 120a6e
    if (!is.eos())
Shinya Kitaoka 120a6e
      is >> dummy0;  // old and wrong format. used only during the 6.0 release
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case Expression:
Shinya Kitaoka 120a6e
    is >> m_frame >> m_expressionText >> m_unitName;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case SimilarShape:
Shinya Kitaoka 120a6e
    is >> m_frame >> m_value >> m_expressionText >> m_similarShapeOffset;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case File:
Shinya Kitaoka 120a6e
    is >> m_frame >> m_fileParams.m_path >> m_fileParams.m_fieldIndex >>
Shinya Kitaoka 120a6e
        m_unitName;
Shinya Kitaoka 120a6e
    break;
Rozhuk Ivan 823a31
  default:
Rozhuk Ivan 823a31
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (!is.matchEndTag()) throw TException(tagName + " : missing endtag");
Shinya Kitaoka 120a6e
  if (m_unitName == "default") m_unitName = "";
Shinya Kitaoka 120a6e
  m_isKeyframe                            = true;
Toshihiro Shimizu 890ddd
}