API Documentation
Loading...
Searching...
No Matches
UnitManager.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/Unit.h>
3#include <NDEVR/Resource.h>
4#include <NDEVR/Pointer.h>
5#include <NDEVR/TranslatedString.h>
6#include <NDEVR/Dictionary.h>
7#include <NDEVR/INIInterface.h>
8namespace NDEVR
9{
10 class INIFactory;
12 {
13 public:
14 UnitOption(const String& id, const TranslatedString& name)
15 : name(name)
16 , id(id)
17 {}
18 virtual ~UnitOption() {};
19 virtual TranslatedString title() const { return name; };
20 virtual ConstPointer<Unit> unit() const = 0;
21 virtual bool hasMemberUnit(const ConstPointer<Unit>& unit) const = 0;
22 virtual ConstPointer<Unit> unit(const ConstPointer<Unit>&) const { return unit(); };
24
25
28 };
30 {
31 public:
33 : UnitOption(unit->name, unit->translatedName())
34 , base_unit(unit)
35 , custom_title(custom_title)
36 {}
37 virtual TranslatedString title() const final override;
38 virtual bool hasMemberUnit(const ConstPointer<Unit>& unit) const final override;
39 virtual ConstPointer<Unit> unit() const final override { return base_unit; };
40 virtual Buffer<ConstPointer<UnitOption>> subOptions() const final override { return m_sub_options; };
41 virtual Buffer<ConstPointer<UnitOption>>& editSubOptions() { return m_sub_options; };
44 protected:
46 };
48 {
49 public:
51 : UnitOption(id, name)
52 {}
53 virtual ConstPointer<Unit> unit() const final override;
54 virtual bool hasMemberUnit(const ConstPointer<Unit>& unit) const final override;
55 virtual ConstPointer<Unit> unit(const ConstPointer<Unit>& distance_unit) const final override;
56 };
57 class UnitManager;
58 /**--------------------------------------------------------------------------------------------------
59 Class: BaseValues
60 \brief A program-defined unit that can be used for some specific task different from a program-wide unit.
61 *-----------------------------------------------------------------------------------------------**/
63 {
64 public:
65 CustomUnit(const String& id, const TranslatedString& name, UnitType unit_type)
66 : name(name)
67 , id(id)
68 , unit_type(unit_type)
69 {}
70 virtual ~CustomUnit() {};
74 [[nodiscard]] virtual TranslatedString title() const { return name; };
75 [[nodiscard]] virtual Resource<ConstPointer<Unit>>& unitResource(UnitManager& manager) = 0;
76 [[nodiscard]] virtual Buffer<ConstPointer<UnitOption>> options( UnitManager& manager) const = 0;
77 virtual void prepareForINI(const UnitManager&) {};
78 virtual void setupINI(INIFactory&) = 0;
79 virtual void resetToDefault( UnitManager&);
80 virtual void finishReadingINI( UnitManager&) {};
81 virtual ConstPointer<Unit> currentUnit();
82 virtual ConstPointer<Unit> currentUnit( UnitManager& manager);
83 [[nodiscard]] virtual ConstPointer<Unit> defaultUnit( UnitManager&) const = 0;
84 };
85 /**--------------------------------------------------------------------------------------------------
86 Class: BaseValues
87 \brief A unit that mirrors another set unit
88 *-----------------------------------------------------------------------------------------------**/
90 {
91 public:
92 ReferenceCustomUnit(const String& id, const TranslatedString& name, UnitType unit_type)
93 : CustomUnit(id, name, unit_type)
94 {}
96 [[nodiscard]] virtual Resource<ConstPointer<Unit>>& unitResource(UnitManager& manager) override;
97 [[nodiscard]] virtual Buffer<ConstPointer<UnitOption>> options( UnitManager& manager) const override;
98 virtual void prepareForINI(const UnitManager&) override{}
99 virtual void setupINI(INIFactory&) override {};
100 virtual void resetToDefault( UnitManager&) override;
101 virtual void finishReadingINI( UnitManager&) override {};
102 virtual ConstPointer<Unit> currentUnit( UnitManager& manager) override;
103 [[nodiscard]] virtual ConstPointer<Unit> defaultUnit( UnitManager&) const override;
104 };
105 /**--------------------------------------------------------------------------------------------------
106 Class: BaseValues
107 \brief A program-defined unit that can be used for some specific task different from a program-wide unit.
108 *-----------------------------------------------------------------------------------------------**/
110 {
111 public:
112 BasicCustomUnit(const String& name, const TranslatedString& title, UnitType type);
113 virtual void prepareForINI(const UnitManager& manager) override;
114 virtual void setupINI(INIFactory& ini) override;
115 virtual void finishReadingINI(UnitManager& manager) override;
116 [[nodiscard]] virtual TranslatedString title() const override { return m_title; };
117 [[nodiscard]] virtual Resource<ConstPointer<Unit>>& unitResource(UnitManager& manager) override;
118 [[nodiscard]] Buffer<ConstPointer<UnitOption>> options(UnitManager& manager) const override;
119 [[nodiscard]] virtual ConstPointer<Unit> defaultUnit(UnitManager&) const override;
120 protected:
124 };
126 {
127 public:
128 UnitManager();
129 UnitManager(const UnitManager& manager);
130 ~UnitManager();
131 void setToDefaultMetric(bool preserve_spacial);
132 void setToDefaultImperial(bool preserve_spacial);
133 void tieToManager(const UnitManager& manager);
134 void getINI(INIFactory& factory) override;
135 void prepareForINI(INIFactory& factory) override;
136 void finishReadingINI(INIFactory& factory) override;
137 void updateCoordinateBase(const ConstPointer<Unit>& base);
138 [[nodiscard]] static UnitManager& DefaultManager();
139
140 [[nodiscard]] ConstPointer<Unit> unit(UnitType type) const;
141 [[nodiscard]] ConstPointer<Unit> orientationOffsetUnit() const;
142 [[nodiscard]] Resource<ConstPointer<Unit>>& unitResource(UnitType type);
143 void setUnit(UnitType type, const ConstPointer<Unit>& unit);
144 void clearUnitOptions(UnitType type);
145 void setUnitOptionsToDefault(UnitType type);
146 void setUnitOptions(UnitType type, const Buffer<ConstPointer<UnitOption>>& options);
147 void setUnitOptions(UnitType type, const Buffer<ConstPointer<Unit>>& options);
148
149 [[nodiscard]] Buffer<ConstPointer<UnitOption>> unitOptions(UnitType units) const;
150 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& angleUnitOptions() const { return m_angle_unit_options; };
151 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& latLonUnitOptions() const { return m_lat_lon_unit_options; };
152 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& distanceUnitOptions() const { return m_distance_unit_options; };
153 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& areaUnitOptions() const { return m_area_unit_options; };
154 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& volumeUnitOptions() const { return m_volume_unit_options; };
155 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& weightUnitOptions() const { return m_weight_unit_options; };
156 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& coordinateSpaceFormatOptions() const { return m_coordinate_format_options; }
157 [[nodiscard]] const Buffer<DynamicPointer<CustomUnit>>& specialUnits() const { return m_special_units; }
158 void addSpecialUnit(const DynamicPointer<CustomUnit>& custom_unit);
159 ConstPointer<Unit> specialUnit(const String& name);
160 Resource<ConstPointer<Unit>>& specialUnitResource(const String& name);
161 bool hasSpecialUnit(const String& name) const;
162 void setupDefaultAngleUnitOptions();
163 void setupDefaultDistanceOptions();
164 void setupDefaultCoordinateSpaceOptions();
165 void setupDefaultVolumeOptions();
166 void setupDefaultAreaOptions();
167 void setupDefaultWeightOptions();
168 void setupDefaultLatLonOptions();
169 [[nodiscard]] ConstPointer<Unit> unit(const String& name) const;
170
171
172 [[nodiscard]] ConstPointer<Unit> parseUnit(const String& name, UnitType type = UnitType::e_undefined_unit) const;
173 [[nodiscard]] ConstPointer<Unit> determineUnit(const Buffer<String>& unit_parts, UnitType type) const;
174
175 bool canBeImperial(const ConstPointer<Unit>& unit) const;
176 bool canBeMetric(const ConstPointer<Unit>& unit) const;
177 void addFormatOption(UnitType unit_type, const ConstPointer<UnitOption>& format_option);
178 void removeFormatOption(UnitType unit_type, const ConstPointer<UnitOption>& format_option);
179 [[nodiscard]] static ConstPointer<UnitOption> ActiveOption(const Buffer<ConstPointer<UnitOption>>& options, const ConstPointer<Unit>& unit);
180 UnitManager& operator=(const UnitManager& manager);
181 public:
192 protected:
203 //For INI read/writes
213 protected:
214 ResourceListener* m_tie_to_listener = nullptr;
215 };
216}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
A program-defined unit that can be used for some specific task different from a program-wide unit.
Definition UnitManager.h:110
String m_ini_unit_name
Definition UnitManager.h:122
Resource< ConstPointer< Unit > > m_unit
Definition UnitManager.h:123
TranslatedString m_title
Definition UnitManager.h:121
virtual TranslatedString title() const override
Definition UnitManager.h:116
Definition UnitManager.h:30
Buffer< ConstPointer< UnitOption > > m_sub_options
Definition UnitManager.h:45
TranslatedString custom_title
Definition UnitManager.h:43
ConstPointer< Unit > base_unit
Definition UnitManager.h:42
BasicUnitOption(const ConstPointer< Unit > &unit, const TranslatedString &custom_title=TranslatedString())
Definition UnitManager.h:32
virtual Buffer< ConstPointer< UnitOption > > & editSubOptions()
Definition UnitManager.h:41
virtual Buffer< ConstPointer< UnitOption > > subOptions() const final override
Definition UnitManager.h:40
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition GraphicsPipeline.h:42
Definition UnitManager.h:48
CoordinateUnitOption(const String &id, const TranslatedString &name)
Definition UnitManager.h:50
A program-defined unit that can be used for some specific task different from a program-wide unit.
Definition UnitManager.h:63
virtual TranslatedString title() const
Definition UnitManager.h:74
CustomUnit(const String &id, const TranslatedString &name, UnitType unit_type)
Definition UnitManager.h:65
virtual void finishReadingINI(UnitManager &)
Definition UnitManager.h:80
virtual void setupINI(INIFactory &)=0
TranslatedString name
Definition UnitManager.h:71
String id
Definition UnitManager.h:72
virtual void prepareForINI(const UnitManager &)
Definition UnitManager.h:77
virtual ~CustomUnit()
Definition UnitManager.h:70
virtual ConstPointer< Unit > defaultUnit(UnitManager &) const =0
virtual Resource< ConstPointer< Unit > > & unitResource(UnitManager &manager)=0
virtual Buffer< ConstPointer< UnitOption > > options(UnitManager &manager) const =0
UnitType unit_type
Definition UnitManager.h:73
Definition Dictionary.h:48
Definition Pointer.hpp:303
Definition INIReader.h:57
Definition INIInterface.h:40
A unit that mirrors another set unit.
Definition UnitManager.h:90
virtual void finishReadingINI(UnitManager &) override
Definition UnitManager.h:101
virtual void prepareForINI(const UnitManager &) override
Definition UnitManager.h:98
virtual ~ReferenceCustomUnit()
Definition UnitManager.h:95
ReferenceCustomUnit(const String &id, const TranslatedString &name, UnitType unit_type)
Definition UnitManager.h:92
virtual void setupINI(INIFactory &) override
Definition UnitManager.h:99
Definition Toggle.h:41
Definition ResourceListener.h:55
Definition String.h:40
Definition TranslatedString.h:9
Definition UnitManager.h:126
Resource< ConstPointer< Unit > > weight_unit
Definition UnitManager.h:188
String distance_space_name
Definition UnitManager.h:207
Resource< ConstPointer< Unit > > distance_unit
Definition UnitManager.h:184
Buffer< ConstPointer< UnitOption > > m_area_unit_options
Definition UnitManager.h:196
Buffer< DynamicPointer< CustomUnit > > m_special_units
Definition UnitManager.h:201
String orientation_space_name
Definition UnitManager.h:205
Resource< ConstPointer< Unit > > volume_unit
Definition UnitManager.h:187
static Resource< ConstPointer< Unit > > default_orientation_space_unit
Definition UnitManager.h:191
Buffer< ConstPointer< UnitOption > > m_volume_unit_options
Definition UnitManager.h:197
Buffer< ConstPointer< UnitOption > > m_weight_unit_options
Definition UnitManager.h:198
const Buffer< ConstPointer< UnitOption > > & coordinateSpaceFormatOptions() const
Definition UnitManager.h:156
const Buffer< ConstPointer< UnitOption > > & latLonUnitOptions() const
Definition UnitManager.h:151
Buffer< ConstPointer< UnitOption > > m_coordinate_format_options
Definition UnitManager.h:199
String surface_area_name
Definition UnitManager.h:208
String volume_name
Definition UnitManager.h:209
const Buffer< ConstPointer< UnitOption > > & angleUnitOptions() const
Definition UnitManager.h:150
const Buffer< ConstPointer< UnitOption > > & areaUnitOptions() const
Definition UnitManager.h:153
const Buffer< ConstPointer< UnitOption > > & distanceUnitOptions() const
Definition UnitManager.h:152
String coordinate_space_name
Definition UnitManager.h:206
const Buffer< ConstPointer< UnitOption > > & volumeUnitOptions() const
Definition UnitManager.h:154
String temperature_name
Definition UnitManager.h:210
Buffer< ConstPointer< UnitOption > > m_angle_unit_options
Definition UnitManager.h:193
Resource< ConstPointer< Unit > > coordinate_space_unit
Definition UnitManager.h:185
String angle_name
Definition UnitManager.h:204
Resource< ConstPointer< Unit > > surface_area_unit
Definition UnitManager.h:186
String lat_lon_name
Definition UnitManager.h:212
const Buffer< ConstPointer< UnitOption > > & weightUnitOptions() const
Definition UnitManager.h:155
Resource< ConstPointer< Unit > > lat_lon_unit
Definition UnitManager.h:190
Resource< ConstPointer< Unit > > temperature_unit
Definition UnitManager.h:189
Dictionary< String, ConstPointer< UnitOption > > m_registered_units
Definition UnitManager.h:200
String weight_name
Definition UnitManager.h:211
Buffer< ConstPointer< UnitOption > > m_distance_unit_options
Definition UnitManager.h:195
Resource< ConstPointer< Unit > > angle_unit
Definition UnitManager.h:182
Dictionary< String, DynamicPointer< CustomUnit > > m_special_unit_lookup
Definition UnitManager.h:202
Resource< ConstPointer< Unit > > orientation_space_unit
Definition UnitManager.h:183
const Buffer< DynamicPointer< CustomUnit > > & specialUnits() const
Definition UnitManager.h:157
Buffer< ConstPointer< UnitOption > > m_lat_lon_unit_options
Definition UnitManager.h:194
Definition UnitManager.h:12
virtual TranslatedString title() const
Definition UnitManager.h:19
virtual bool hasMemberUnit(const ConstPointer< Unit > &unit) const =0
TranslatedString name
Definition UnitManager.h:26
String id
Definition UnitManager.h:27
virtual ~UnitOption()
Definition UnitManager.h:18
virtual ConstPointer< Unit > unit() const =0
virtual ConstPointer< Unit > unit(const ConstPointer< Unit > &) const
Definition UnitManager.h:22
UnitOption(const String &id, const TranslatedString &name)
Definition UnitManager.h:14
virtual Buffer< ConstPointer< UnitOption > > subOptions() const
Definition UnitManager.h:23
Definition ACIColor.h:37
UnitType
Definition Unit.h:10
Definition Unit.h:28