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