|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tnotanimatableparam.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstream.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
PERSIST_IDENTIFIER(TIntParam, "intParam")
|
|
Toshihiro Shimizu |
890ddd |
PERSIST_IDENTIFIER(TBoolParam, "boolParam")
|
|
Toshihiro Shimizu |
890ddd |
PERSIST_IDENTIFIER(TFilePathParam, "filePathParam")
|
|
Toshihiro Shimizu |
890ddd |
PERSIST_IDENTIFIER(TStringParam, "stringParam")
|
|
Toshihiro Shimizu |
890ddd |
PERSIST_IDENTIFIER(TNADoubleParam, "naDoubleParam")
|
|
Toshihiro Shimizu |
890ddd |
//PERSIST_IDENTIFIER(TIntEnumParam, "intEnumParam")
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPersistDeclarationT<tenumparam> TEnumParam::m_declaration("intEnumParam");</tenumparam>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TIntParam::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int def, value;
|
|
Toshihiro Shimizu |
890ddd |
is >> def;
|
|
Toshihiro Shimizu |
890ddd |
if (is.eos()) {
|
|
Toshihiro Shimizu |
890ddd |
def += 1;
|
|
Toshihiro Shimizu |
890ddd |
setDefaultValue(def);
|
|
Toshihiro Shimizu |
890ddd |
setValue(def, false);
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
setDefaultValue(def);
|
|
Toshihiro Shimizu |
890ddd |
is >> value;
|
|
Toshihiro Shimizu |
890ddd |
setValue(value, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TIntParam::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os << getDefaultValue();
|
|
Toshihiro Shimizu |
890ddd |
os << getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TIntParam::isWheelEnabled() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_isWheelEnabled;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TIntParam::enableWheel(bool on)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_isWheelEnabled = on;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TBoolParam::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int def, value;
|
|
Toshihiro Shimizu |
890ddd |
is >> def >> value;
|
|
Toshihiro Shimizu |
890ddd |
setDefaultValue(def ? true : false);
|
|
Toshihiro Shimizu |
890ddd |
setValue(value ? true : false, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TBoolParam::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os << (int)getDefaultValue() << (int)getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TFilePathParam::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath def, value;
|
|
Toshihiro Shimizu |
890ddd |
is >> def >> value;
|
|
Toshihiro Shimizu |
890ddd |
setDefaultValue(def);
|
|
Toshihiro Shimizu |
890ddd |
setValue(value, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TFilePathParam::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os << getDefaultValue();
|
|
Toshihiro Shimizu |
890ddd |
os << getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
void TStringParam::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring def, value;
|
|
Toshihiro Shimizu |
890ddd |
is >> def >> value;
|
|
Toshihiro Shimizu |
890ddd |
setDefaultValue(def);
|
|
Toshihiro Shimizu |
890ddd |
setValue(value, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void TStringParam::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os << getDefaultValue();
|
|
Toshihiro Shimizu |
890ddd |
os << getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
void TNADoubleParam::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double def, value;
|
|
Toshihiro Shimizu |
890ddd |
is >> def >> value;
|
|
Toshihiro Shimizu |
890ddd |
setDefaultValue(def);
|
|
Toshihiro Shimizu |
890ddd |
setValue(value, false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void TNADoubleParam::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os << getDefaultValue();
|
|
Toshihiro Shimizu |
890ddd |
os << getValue();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
template <typename t=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
class matchesValue
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
T m_v;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
matchesValue(T v) : m_v(v) {}
|
|
Shinya Kitaoka |
3bfa54 |
bool operator()(const std::pair<t, std::string=""> &p) { return m_v == p.first; }</t,>
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TEnumParamImp
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::pair<int, std::string="">> m_items;</std::pair<int,>
|
|
Shinya Kitaoka |
262a92 |
void copy(std::unique_ptr<tenumparamimp>& src)</tenumparamimp>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_items.clear();
|
|
Shinya Kitaoka |
3bfa54 |
std::back_insert_iterator<std::vector<std::pair<int, std::string="">>> bii(m_items);</std::vector<std::pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
std::copy(src->m_items.begin(), src->m_items.end(), bii);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
bool checkValue(int v)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::pair<int, std::string="">>::iterator it =</std::pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
std::find_if(m_items.begin(), m_items.end(), matchesValue<int>(v));</int>
|
|
Toshihiro Shimizu |
890ddd |
return it != m_items.end();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
TEnumParam::TEnumParam(const int &v, const std::string &caption)
|
|
Toshihiro Shimizu |
890ddd |
: TNotAnimatableParam<int>(v), m_imp(new TEnumParamImp())</int>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
addItem(v, caption);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TEnumParam::copy(TParam *src)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TNotAnimatableParam<int>::copy(src);</int>
|
|
Toshihiro Shimizu |
890ddd |
TEnumParam *p = dynamic_cast<tenumparam *="">(src);</tenumparam>
|
|
Toshihiro Shimizu |
890ddd |
if (!p)
|
|
Toshihiro Shimizu |
890ddd |
throw TException("invalid source for copy");
|
|
Toshihiro Shimizu |
890ddd |
TEnumParam::setName(src->getName());
|
|
Toshihiro Shimizu |
890ddd |
m_imp->copy(p->m_imp);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEnumParam::~TEnumParam()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEnumParam::TEnumParam(const TEnumParam &src)
|
|
Toshihiro Shimizu |
890ddd |
: TNotAnimatableParam<int>(src), m_imp(new TEnumParamImp(*src.m_imp))</int>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TEnumParam::TEnumParam()
|
|
Toshihiro Shimizu |
890ddd |
: TNotAnimatableParam<int>(), m_imp(new TEnumParamImp())</int>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TEnumParam::setValue(int v, bool undoing)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool valid = false;
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::pair<int, std::string="">>::iterator it = m_imp->m_items.begin();</std::pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
for (; it != m_imp->m_items.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
if (it->first == v) {
|
|
Toshihiro Shimizu |
890ddd |
valid = true;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!valid)
|
|
Toshihiro Shimizu |
890ddd |
throw TException("out of range parameter value");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TNotAnimatableParam<int>::setValue(v, undoing);</int>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TEnumParam::setValue(const std::string &caption, bool undoing)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool valid = false;
|
|
Toshihiro Shimizu |
890ddd |
int v = 0;
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::pair<int, std::string="">>::iterator it = m_imp->m_items.begin();</std::pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
for (; it != m_imp->m_items.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
if (it->second == caption) {
|
|
Toshihiro Shimizu |
890ddd |
v = it->first;
|
|
Toshihiro Shimizu |
890ddd |
valid = true;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!valid)
|
|
Toshihiro Shimizu |
890ddd |
throw TException("out of range parameter value");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TNotAnimatableParam<int>::setValue(v, undoing);</int>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TEnumParam::addItem(const int &item, const std::string &caption)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_imp->m_items.push_back(std::make_pair(item, caption));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TEnumParam::getItemCount() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_imp->m_items.size();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void TEnumParam::getItem(int i, int &item, std::string &caption) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(i >= 0 && i < m_imp->m_items.size());
|
|
Toshihiro Shimizu |
890ddd |
item = m_imp->m_items[i].first;
|
|
Toshihiro Shimizu |
890ddd |
caption = m_imp->m_items[i].second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TEnumParam::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int value;
|
|
Toshihiro Shimizu |
890ddd |
is >> value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
setValue(value, false);
|
|
Toshihiro Shimizu |
890ddd |
} catch (TException &) {
|
|
Toshihiro Shimizu |
890ddd |
TNotAnimatableParam<int>::reset();</int>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TEnumParam::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
os << TNotAnimatableParam<int>::getValue();</int>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TIntParam::setValueRange(int min, int max)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(min < max);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
minValue = min;
|
|
Toshihiro Shimizu |
890ddd |
maxValue = max;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool TIntParam::getValueRange(int &min, int &max) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
min = minValue;
|
|
Toshihiro Shimizu |
890ddd |
max = maxValue;
|
|
Toshihiro Shimizu |
890ddd |
return min < max;
|
|
Toshihiro Shimizu |
890ddd |
}
|