1 /*
2 This is a rough draft of a global 'units' thingee, to allow dialogs and
3 the ruler to share info about unit systems... Dunno if this is the
4 right kind of object though, so we may have to redo this or shift things
5 around later when it becomes clearer what we need.
7 This object is used for defining different unit systems.
9 This is intended to eventually replace inkscape/helper/units.*.
11 Need to review the Units support that's in Gtkmm already...
13 */
15 #ifndef INKSCAPE_UTIL_UNITS_H
16 #define INKSCAPE_UTIL_UNITS_H
18 #include <map>
19 #include <glibmm/ustring.h>
21 namespace Inkscape {
22 namespace Util {
24 enum UnitType {
25 UNIT_TYPE_DIMENSIONLESS, /* Percentage */
26 UNIT_TYPE_LINEAR,
27 UNIT_TYPE_LINEAR_SCALED,
28 UNIT_TYPE_RADIAL,
29 UNIT_TYPE_TIME,
30 UNIT_TYPE_FONT_HEIGHT,
31 UNIT_TYPE_QTY,
32 UNIT_TYPE_NONE = -1
33 };
35 class Unit {
36 public:
37 Glib::ustring name;
38 Glib::ustring name_plural;
39 Glib::ustring abbr;
40 Glib::ustring description;
42 UnitType type;
44 double factor;
46 bool isAbsolute() const { return type != UNIT_TYPE_DIMENSIONLESS; }
47 int defaultDigits() const;
48 };
50 class UnitTable {
51 public:
52 UnitTable();
53 virtual ~UnitTable();
55 typedef std::map<Glib::ustring, Unit*> UnitMap;
57 void addUnit(Unit const& u, bool primary);
58 Unit getUnit(Glib::ustring const& name) const;
59 bool deleteUnit(Unit const& u);
60 bool hasUnit(Glib::ustring const &name) const;
62 UnitTable::UnitMap units(UnitType type) const;
64 Glib::ustring primary(UnitType type) const;
66 double getScale() const;
67 void setScale();
69 bool load(Glib::ustring const &filename);
70 bool loadText(Glib::ustring const &filename);
71 bool save(Glib::ustring const &filename);
73 protected:
74 UnitTable::UnitMap _unit_map;
75 Glib::ustring _primary_unit[UNIT_TYPE_QTY];
77 double _linear_scale;
79 private:
80 UnitTable(UnitTable const& t);
81 UnitTable operator=(UnitTable const& t);
83 };
85 } // namespace Util
86 } // namespace Inkscape
88 #endif // define INKSCAPE_UTIL_UNITS_H