Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TRangeParamImp {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TRangeParamImp(const DoublePair &v)
Shinya Kitaoka 120a6e
      : m_min(new TDoubleParam(v.first)), m_max(new TDoubleParam(v.second)) {}
Shinya Kitaoka 120a6e
  TRangeParamImp(const TRangeParamImp &src)
Shinya Kitaoka 120a6e
      : m_min(src.m_min->clone()), m_max(src.m_max->clone()) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~TRangeParamImp() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParamP m_min, m_max;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TRangeParam, "rangeParam")
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRangeParam::TRangeParam(const DoublePair &v) : m_data(new TRangeParamImp(v)) {
Shinya Kitaoka 120a6e
  addParam(m_data->m_min, "min");
Shinya Kitaoka 120a6e
  addParam(m_data->m_max, "max");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRangeParam::TRangeParam(const TRangeParam &src)
Shinya Kitaoka 120a6e
    : TParamSet(src.getName()), m_data(new TRangeParamImp(*src.m_data)) {
Shinya Kitaoka 120a6e
  addParam(m_data->m_min, "min");
Shinya Kitaoka 120a6e
  addParam(m_data->m_max, "max");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRangeParam::~TRangeParam() { delete m_data; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRangeParam::copy(TParam *src) {
Shinya Kitaoka 120a6e
  TRangeParam *p = dynamic_cast<trangeparam *="">(src);</trangeparam>
Shinya Kitaoka 120a6e
  if (!p) throw TException("invalid source for copy");
Shinya Kitaoka 120a6e
  setName(src->getName());
Shinya Kitaoka 120a6e
  m_data->m_min->copy(p->m_data->m_min.getPointer());
Shinya Kitaoka 120a6e
  m_data->m_max->copy(p->m_data->m_max.getPointer());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DoublePair TRangeParam::getDefaultValue() const {
Shinya Kitaoka 120a6e
  return DoublePair(m_data->m_min->getDefaultValue(),
Shinya Kitaoka 120a6e
                    m_data->m_max->getDefaultValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DoublePair TRangeParam::getValue(double frame) const {
Shinya Kitaoka 120a6e
  return DoublePair(m_data->m_min->getValue(frame),
Shinya Kitaoka 120a6e
                    m_data->m_max->getValue(frame));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TRangeParam::setValue(double frame, const DoublePair &v) {
Shinya Kitaoka 120a6e
  beginParameterChange();
Shinya Kitaoka 120a6e
  m_data->m_min->setValue(frame, v.first);
Shinya Kitaoka 120a6e
  m_data->m_max->setValue(frame, v.second);
Shinya Kitaoka 120a6e
  endParameterChange();
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRangeParam::setDefaultValue(const DoublePair &v) {
Shinya Kitaoka 120a6e
  m_data->m_min->setDefaultValue(v.first);
Shinya Kitaoka 120a6e
  m_data->m_max->setDefaultValue(v.second);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRangeParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string childName;
Shinya Kitaoka 120a6e
  while (is.openChild(childName)) {
Shinya Kitaoka 120a6e
    if (childName == "min")
Shinya Kitaoka 120a6e
      m_data->m_min->loadData(is);
Shinya Kitaoka 120a6e
    else if (childName == "max")
Shinya Kitaoka 120a6e
      m_data->m_max->loadData(is);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      throw TException("unknown tag");
Shinya Kitaoka 120a6e
    is.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRangeParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os.openChild("min");
Shinya Kitaoka 120a6e
  m_data->m_min->saveData(os);
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.openChild("max");
Shinya Kitaoka 120a6e
  m_data->m_max->saveData(os);
Shinya Kitaoka 120a6e
  os.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDoubleParamP &TRangeParam::getMin() { return m_data->m_min; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDoubleParamP &TRangeParam::getMax() { return m_data->m_max; }
Toshihiro Shimizu 890ddd
#ifdef BUTTA
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TRangeParam::getNextKeyframe(double frame) const {
Shinya Kitaoka 120a6e
  int f_min = m_data->m_min->getNextKeyframe(frame);
Shinya Kitaoka 120a6e
  int f_max = m_data->m_max->getNextKeyframe(frame);
Shinya Kitaoka 120a6e
  if (f_min <= f_max && f_min != -1)
Shinya Kitaoka 120a6e
    return f_min;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    if (f_max != -1)
Shinya Kitaoka 120a6e
      return f_max;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return -1;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TRangeParam::getPrevKeyframe(double frame) const {
Shinya Kitaoka 120a6e
  int f_min = m_data->m_min->getPrevKeyframe(frame);
Shinya Kitaoka 120a6e
  int f_max = m_data->m_max->getPrevKeyframe(frame);
Shinya Kitaoka 120a6e
  if (f_min >= f_max)
Shinya Kitaoka 120a6e
    return f_min;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return f_max;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRangeParam::deleteKeyframe(double frame, bool undoing) {
Shinya Kitaoka 120a6e
  m_data->m_min->deleteKeyframe(frame, undoing);
Shinya Kitaoka 120a6e
  m_data->m_max->deleteKeyframe(frame, undoing);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TRangeParam::isKeyframe(double frame) const {
Shinya Kitaoka 120a6e
  bool min, max;
Shinya Kitaoka 120a6e
  min = m_data->m_min->isKeyframe(frame);
Shinya Kitaoka 120a6e
  max = m_data->m_max->isKeyframe(frame);
Shinya Kitaoka 120a6e
  return (min || max);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif