|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TUNIT_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define TUNIT_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TNZBASE_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(push)
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4251)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TUnitConverter
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
virtual ~TUnitConverter() {}
|
|
Toshihiro Shimizu |
890ddd |
virtual TUnitConverter *clone() const = 0;
|
|
Toshihiro Shimizu |
890ddd |
virtual double convertTo(double v) const = 0;
|
|
Toshihiro Shimizu |
890ddd |
virtual double convertFrom(double v) const = 0;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TSimpleUnitConverter : public TUnitConverter
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const double m_factor, m_offset;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TSimpleUnitConverter(double factor = 1, double offset = 0)
|
|
Toshihiro Shimizu |
890ddd |
: m_factor(factor), m_offset(offset) {}
|
|
Toshihiro Shimizu |
890ddd |
TUnitConverter *clone() const { return new TSimpleUnitConverter(*this); }
|
|
Toshihiro Shimizu |
890ddd |
double convertTo(double v) const { return v * m_factor + m_offset; }
|
|
Toshihiro Shimizu |
890ddd |
double convertFrom(double v) const { return (v - m_offset) / m_factor; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TUnit
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring m_defaultExtension;
|
|
Shinya Kitaoka |
3bfa54 |
std::vector<std::wstring> m_extensions;</std::wstring>
|
|
Toshihiro Shimizu |
890ddd |
TUnitConverter *m_converter;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
3bfa54 |
TUnit(std::wstring ext, TUnitConverter *converter = 0);
|
|
Toshihiro Shimizu |
890ddd |
TUnit(const TUnit &);
|
|
Toshihiro Shimizu |
890ddd |
~TUnit();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TUnit *clone() const { return new TUnit(*this); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
const std::vector<std::wstring> &getExtensions() const { return m_extensions; }</std::wstring>
|
|
Shinya Kitaoka |
3bfa54 |
void addExtension(std::wstring ext);
|
|
Shinya Kitaoka |
3bfa54 |
bool isExtension(std::wstring ext) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring getDefaultExtension() const { return m_defaultExtension; }
|
|
Shinya Kitaoka |
3bfa54 |
void setDefaultExtension(std::wstring ext);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double convertTo(double v) const { return m_converter->convertTo(v); }
|
|
Toshihiro Shimizu |
890ddd |
double convertFrom(double v) const { return m_converter->convertFrom(v); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
// not implemented
|
|
Toshihiro Shimizu |
890ddd |
TUnit &operator=(const TUnit &);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TMeasure
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_name;
|
|
Toshihiro Shimizu |
890ddd |
TUnit *m_mainUnit, *m_currentUnit, *m_standardUnit;
|
|
Shinya Kitaoka |
3bfa54 |
std::map<std::wstring, *="" tunit=""> m_extensions;</std::wstring,>
|
|
Toshihiro Shimizu |
890ddd |
double m_defaultValue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
3bfa54 |
TMeasure(std::string name, TUnit *mainUnit);
|
|
Toshihiro Shimizu |
890ddd |
TMeasure(const TMeasure &);
|
|
Toshihiro Shimizu |
890ddd |
~TMeasure();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string getName() const { return m_name; }
|
|
Shinya Kitaoka |
3bfa54 |
void setName(std::string name) { m_name = name; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void add(TUnit *unit);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// main unit e' quella usata "internamente". puo' essere "strana"
|
|
Toshihiro Shimizu |
890ddd |
const TUnit *getMainUnit() const { return m_mainUnit; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// current unit e' quella ad es. definita in preferences
|
|
Toshihiro Shimizu |
890ddd |
const TUnit *getCurrentUnit() const { return m_currentUnit; }
|
|
Toshihiro Shimizu |
890ddd |
void setCurrentUnit(TUnit *unit);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// standard unit e' quella usata nelle espressioni
|
|
Toshihiro Shimizu |
890ddd |
const TUnit *getStandardUnit() const { return m_standardUnit; }
|
|
Toshihiro Shimizu |
890ddd |
void setStandardUnit(TUnit *unit);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
TUnit *getUnit(std::wstring ext) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// defaultValue e' espresso in main unit
|
|
Toshihiro Shimizu |
890ddd |
double getDefaultValue() const { return m_defaultValue; }
|
|
Toshihiro Shimizu |
890ddd |
void setDefaultValue(double v) { m_defaultValue = v; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
// not implemented
|
|
Toshihiro Shimizu |
890ddd |
TMeasure &operator=(const TMeasure &);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TMeasureManager
|
|
Toshihiro Shimizu |
890ddd |
{ // singleton
|
|
Shinya Kitaoka |
3bfa54 |
std::map<std::string, *="" tmeasure=""> m_measures;</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
TMeasureManager();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
static TMeasureManager *instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static TMeasureManager _instance;
|
|
Toshihiro Shimizu |
890ddd |
return &_instance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void add(TMeasure *m);
|
|
Shinya Kitaoka |
3bfa54 |
TMeasure *get(std::string name) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef double CameraSizeProvider();
|
|
Toshihiro Shimizu |
890ddd |
void addCameraMeasures(CameraSizeProvider *cameraSizeProvider);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TMeasuredValue
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const TMeasure *m_measure;
|
|
Toshihiro Shimizu |
890ddd |
double m_value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
3bfa54 |
TMeasuredValue(std::string measureName);
|
|
Toshihiro Shimizu |
890ddd |
~TMeasuredValue();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const TMeasure *getMeasure() const { return m_measure; }
|
|
Toshihiro Shimizu |
890ddd |
void setMeasure(const TMeasure *measure);
|
|
Shinya Kitaoka |
3bfa54 |
void setMeasure(std::string measureName);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
enum UnitType { MainUnit,
|
|
Toshihiro Shimizu |
890ddd |
CurrentUnit };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double getValue(UnitType uType) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return uType == MainUnit ? m_value : m_measure->getCurrentUnit()->convertTo(m_value);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void setValue(UnitType uType, double value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_value = uType == MainUnit ? value : m_measure->getCurrentUnit()->convertFrom(value);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
bool setValue(std::wstring s, int *pErr = 0); // if pErr != then *pErr contains error code. *pErr == 0 means OK
|
|
Shinya Kitaoka |
3bfa54 |
std::wstring toWideString(int decimals = 7) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
// not implemented
|
|
Toshihiro Shimizu |
890ddd |
TMeasuredValue(const TMeasuredValue &);
|
|
Toshihiro Shimizu |
890ddd |
TMeasuredValue &operator=(const TMeasuredValue &);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// bruttacchietto. L'aspect ratio della field guide viene usata nelle conversioni
|
|
Toshihiro Shimizu |
890ddd |
// fra fld e inch sulla verticale
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace UnitParameters
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef std::pair<double, double=""> (*CurrentDpiGetter)();</double,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAPI void setFieldGuideAspectRatio(double ar);
|
|
Toshihiro Shimizu |
890ddd |
DVAPI double getFieldGuideAspectRatio();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAPI void setCurrentDpiGetter(CurrentDpiGetter f);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(pop)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|