|
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 |
|
|
Toshihiro Shimizu |
890ddd |
#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 |
{
|
|
Toshihiro Shimizu |
890ddd |
wstring m_defaultExtension;
|
|
Toshihiro Shimizu |
890ddd |
std::vector<wstring> m_extensions;</wstring>
|
|
Toshihiro Shimizu |
890ddd |
TUnitConverter *m_converter;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TUnit(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 |
|
|
Toshihiro Shimizu |
890ddd |
const std::vector<wstring> &getExtensions() const { return m_extensions; }</wstring>
|
|
Toshihiro Shimizu |
890ddd |
void addExtension(wstring ext);
|
|
Toshihiro Shimizu |
890ddd |
bool isExtension(wstring ext) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
wstring getDefaultExtension() const { return m_defaultExtension; }
|
|
Toshihiro Shimizu |
890ddd |
void setDefaultExtension(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 |
{
|
|
Toshihiro Shimizu |
890ddd |
string m_name;
|
|
Toshihiro Shimizu |
890ddd |
TUnit *m_mainUnit, *m_currentUnit, *m_standardUnit;
|
|
Toshihiro Shimizu |
890ddd |
std::map<wstring, *="" tunit=""> m_extensions;</wstring,>
|
|
Toshihiro Shimizu |
890ddd |
double m_defaultValue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
TMeasure(string name, TUnit *mainUnit);
|
|
Toshihiro Shimizu |
890ddd |
TMeasure(const TMeasure &);
|
|
Toshihiro Shimizu |
890ddd |
~TMeasure();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
string getName() const { return m_name; }
|
|
Toshihiro Shimizu |
890ddd |
void setName(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 |
|
|
Toshihiro Shimizu |
890ddd |
TUnit *getUnit(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
|
|
Toshihiro Shimizu |
890ddd |
std::map<string, *="" tmeasure=""> m_measures;</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);
|
|
Toshihiro Shimizu |
890ddd |
TMeasure *get(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:
|
|
Toshihiro Shimizu |
890ddd |
TMeasuredValue(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);
|
|
Toshihiro Shimizu |
890ddd |
void setMeasure(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 |
|
|
Toshihiro Shimizu |
890ddd |
bool setValue(wstring s, int *pErr = 0); // if pErr != then *pErr contains error code. *pErr == 0 means OK
|
|
Toshihiro Shimizu |
890ddd |
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 |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(pop)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|