@itwin/core-frontend 3.1.0-dev.24 → 3.1.0-dev.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +156 -35
- package/lib/cjs/DrawingViewState.d.ts.map +1 -1
- package/lib/cjs/DrawingViewState.js +6 -5
- package/lib/cjs/DrawingViewState.js.map +1 -1
- package/lib/cjs/IModelApp.d.ts +1 -3
- package/lib/cjs/IModelApp.d.ts.map +1 -1
- package/lib/cjs/IModelApp.js +8 -6
- package/lib/cjs/IModelApp.js.map +1 -1
- package/lib/cjs/RealityDataSource.d.ts +50 -14
- package/lib/cjs/RealityDataSource.d.ts.map +1 -1
- package/lib/cjs/RealityDataSource.js +19 -241
- package/lib/cjs/RealityDataSource.js.map +1 -1
- package/lib/cjs/RealityDataSourceCesiumIonAssetImpl.d.ts +67 -0
- package/lib/cjs/RealityDataSourceCesiumIonAssetImpl.d.ts.map +1 -0
- package/lib/cjs/RealityDataSourceCesiumIonAssetImpl.js +166 -0
- package/lib/cjs/RealityDataSourceCesiumIonAssetImpl.js.map +1 -0
- package/lib/cjs/RealityDataSourceContextShareImpl.d.ts +83 -0
- package/lib/cjs/RealityDataSourceContextShareImpl.d.ts.map +1 -0
- package/lib/cjs/RealityDataSourceContextShareImpl.js +234 -0
- package/lib/cjs/RealityDataSourceContextShareImpl.js.map +1 -0
- package/lib/cjs/RealityDataSourceTilesetUrlImpl.d.ts +65 -0
- package/lib/cjs/RealityDataSourceTilesetUrlImpl.d.ts.map +1 -0
- package/lib/cjs/RealityDataSourceTilesetUrlImpl.js +135 -0
- package/lib/cjs/RealityDataSourceTilesetUrlImpl.js.map +1 -0
- package/lib/cjs/SheetViewState.js +4 -0
- package/lib/cjs/SheetViewState.js.map +1 -1
- package/lib/cjs/ViewState.d.ts +8 -0
- package/lib/cjs/ViewState.d.ts.map +1 -1
- package/lib/cjs/ViewState.js.map +1 -1
- package/lib/cjs/Viewport.d.ts +19 -3
- package/lib/cjs/Viewport.d.ts.map +1 -1
- package/lib/cjs/Viewport.js +20 -0
- package/lib/cjs/Viewport.js.map +1 -1
- package/lib/cjs/core-frontend.d.ts +1 -0
- package/lib/cjs/core-frontend.d.ts.map +1 -1
- package/lib/cjs/core-frontend.js +1 -0
- package/lib/cjs/core-frontend.js.map +1 -1
- package/lib/cjs/quantity-formatting/BasicUnitsProvider.d.ts +2 -2
- package/lib/cjs/quantity-formatting/BasicUnitsProvider.d.ts.map +1 -1
- package/lib/cjs/quantity-formatting/BasicUnitsProvider.js +48 -44
- package/lib/cjs/quantity-formatting/BasicUnitsProvider.js.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts +90 -80
- package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityFormatter.js +76 -45
- package/lib/cjs/quantity-formatting/QuantityFormatter.js.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityTypesEditorSpecs.d.ts +54 -0
- package/lib/cjs/quantity-formatting/QuantityTypesEditorSpecs.d.ts.map +1 -0
- package/lib/cjs/quantity-formatting/QuantityTypesEditorSpecs.js +32 -0
- package/lib/cjs/quantity-formatting/QuantityTypesEditorSpecs.js.map +1 -0
- package/lib/cjs/quantity-formatting/UnitsData.d.ts +11 -0
- package/lib/cjs/quantity-formatting/UnitsData.d.ts.map +1 -0
- package/lib/cjs/quantity-formatting/UnitsData.js +59 -0
- package/lib/cjs/quantity-formatting/UnitsData.js.map +1 -0
- package/lib/cjs/tile/OPCFormatInterpreter.d.ts +21 -0
- package/lib/cjs/tile/OPCFormatInterpreter.d.ts.map +1 -0
- package/lib/cjs/tile/OPCFormatInterpreter.js +81 -0
- package/lib/cjs/tile/OPCFormatInterpreter.js.map +1 -0
- package/lib/cjs/tile/PntsReader.d.ts.map +1 -1
- package/lib/cjs/tile/PntsReader.js +79 -17
- package/lib/cjs/tile/PntsReader.js.map +1 -1
- package/lib/cjs/tile/ThreeDTileFormatInterpreter.d.ts +51 -0
- package/lib/cjs/tile/ThreeDTileFormatInterpreter.d.ts.map +1 -0
- package/lib/cjs/tile/ThreeDTileFormatInterpreter.js +160 -0
- package/lib/cjs/tile/ThreeDTileFormatInterpreter.js.map +1 -0
- package/lib/cjs/tile/internal.d.ts +2 -0
- package/lib/cjs/tile/internal.d.ts.map +1 -1
- package/lib/cjs/tile/internal.js +2 -0
- package/lib/cjs/tile/internal.js.map +1 -1
- package/lib/esm/DrawingViewState.d.ts.map +1 -1
- package/lib/esm/DrawingViewState.js +6 -5
- package/lib/esm/DrawingViewState.js.map +1 -1
- package/lib/esm/IModelApp.d.ts +1 -3
- package/lib/esm/IModelApp.d.ts.map +1 -1
- package/lib/esm/IModelApp.js +8 -6
- package/lib/esm/IModelApp.js.map +1 -1
- package/lib/esm/RealityDataSource.d.ts +50 -14
- package/lib/esm/RealityDataSource.d.ts.map +1 -1
- package/lib/esm/RealityDataSource.js +22 -244
- package/lib/esm/RealityDataSource.js.map +1 -1
- package/lib/esm/RealityDataSourceCesiumIonAssetImpl.d.ts +67 -0
- package/lib/esm/RealityDataSourceCesiumIonAssetImpl.d.ts.map +1 -0
- package/lib/esm/RealityDataSourceCesiumIonAssetImpl.js +162 -0
- package/lib/esm/RealityDataSourceCesiumIonAssetImpl.js.map +1 -0
- package/lib/esm/RealityDataSourceContextShareImpl.d.ts +83 -0
- package/lib/esm/RealityDataSourceContextShareImpl.d.ts.map +1 -0
- package/lib/esm/RealityDataSourceContextShareImpl.js +230 -0
- package/lib/esm/RealityDataSourceContextShareImpl.js.map +1 -0
- package/lib/esm/RealityDataSourceTilesetUrlImpl.d.ts +65 -0
- package/lib/esm/RealityDataSourceTilesetUrlImpl.d.ts.map +1 -0
- package/lib/esm/RealityDataSourceTilesetUrlImpl.js +131 -0
- package/lib/esm/RealityDataSourceTilesetUrlImpl.js.map +1 -0
- package/lib/esm/SheetViewState.js +4 -0
- package/lib/esm/SheetViewState.js.map +1 -1
- package/lib/esm/ViewState.d.ts +8 -0
- package/lib/esm/ViewState.d.ts.map +1 -1
- package/lib/esm/ViewState.js.map +1 -1
- package/lib/esm/Viewport.d.ts +19 -3
- package/lib/esm/Viewport.d.ts.map +1 -1
- package/lib/esm/Viewport.js +20 -0
- package/lib/esm/Viewport.js.map +1 -1
- package/lib/esm/core-frontend.d.ts +1 -0
- package/lib/esm/core-frontend.d.ts.map +1 -1
- package/lib/esm/core-frontend.js +1 -0
- package/lib/esm/core-frontend.js.map +1 -1
- package/lib/esm/quantity-formatting/BasicUnitsProvider.d.ts +2 -2
- package/lib/esm/quantity-formatting/BasicUnitsProvider.d.ts.map +1 -1
- package/lib/esm/quantity-formatting/BasicUnitsProvider.js +48 -44
- package/lib/esm/quantity-formatting/BasicUnitsProvider.js.map +1 -1
- package/lib/esm/quantity-formatting/QuantityFormatter.d.ts +90 -80
- package/lib/esm/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
- package/lib/esm/quantity-formatting/QuantityFormatter.js +75 -41
- package/lib/esm/quantity-formatting/QuantityFormatter.js.map +1 -1
- package/lib/esm/quantity-formatting/QuantityTypesEditorSpecs.d.ts +54 -0
- package/lib/esm/quantity-formatting/QuantityTypesEditorSpecs.d.ts.map +1 -0
- package/lib/esm/quantity-formatting/QuantityTypesEditorSpecs.js +26 -0
- package/lib/esm/quantity-formatting/QuantityTypesEditorSpecs.js.map +1 -0
- package/lib/esm/quantity-formatting/UnitsData.d.ts +11 -0
- package/lib/esm/quantity-formatting/UnitsData.d.ts.map +1 -0
- package/lib/esm/quantity-formatting/UnitsData.js +56 -0
- package/lib/esm/quantity-formatting/UnitsData.js.map +1 -0
- package/lib/esm/tile/OPCFormatInterpreter.d.ts +21 -0
- package/lib/esm/tile/OPCFormatInterpreter.d.ts.map +1 -0
- package/lib/esm/tile/OPCFormatInterpreter.js +77 -0
- package/lib/esm/tile/OPCFormatInterpreter.js.map +1 -0
- package/lib/esm/tile/PntsReader.d.ts.map +1 -1
- package/lib/esm/tile/PntsReader.js +79 -17
- package/lib/esm/tile/PntsReader.js.map +1 -1
- package/lib/esm/tile/ThreeDTileFormatInterpreter.d.ts +51 -0
- package/lib/esm/tile/ThreeDTileFormatInterpreter.d.ts.map +1 -0
- package/lib/esm/tile/ThreeDTileFormatInterpreter.js +156 -0
- package/lib/esm/tile/ThreeDTileFormatInterpreter.js.map +1 -0
- package/lib/esm/tile/internal.d.ts +2 -0
- package/lib/esm/tile/internal.d.ts.map +1 -1
- package/lib/esm/tile/internal.js +2 -0
- package/lib/esm/tile/internal.js.map +1 -1
- package/package.json +20 -20
|
@@ -7,25 +7,35 @@
|
|
|
7
7
|
* @module QuantityFormatting
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.QuantityFormatter = exports.isCustomQuantityTypeDefinition = exports.
|
|
10
|
+
exports.QuantityFormatter = exports.isCustomQuantityTypeDefinition = exports.getQuantityTypeKey = exports.AlternateUnitLabelsRegistry = exports.QuantityType = void 0;
|
|
11
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
12
|
const core_quantity_1 = require("@itwin/core-quantity");
|
|
13
13
|
const IModelApp_1 = require("../IModelApp");
|
|
14
14
|
const BasicUnitsProvider_1 = require("./BasicUnitsProvider");
|
|
15
15
|
// cSpell:ignore FORMATPROPS FORMATKEY ussurvey uscustomary USCUSTOM
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
16
|
+
/**
|
|
17
|
+
* Defines standard format types for tools that need to display measurements to user.
|
|
18
|
+
* @public
|
|
18
19
|
*/
|
|
19
20
|
var QuantityType;
|
|
20
21
|
(function (QuantityType) {
|
|
22
|
+
/** Length which is stored in meters. Typically formatted to display in meters or feet-inches based on active unit system. */
|
|
21
23
|
QuantityType[QuantityType["Length"] = 1] = "Length";
|
|
24
|
+
/** Angular value which is stored in radians. Typically formatted to display degrees or Degrees-Minute-Seconds based on active unit system. */
|
|
22
25
|
QuantityType[QuantityType["Angle"] = 2] = "Angle";
|
|
26
|
+
/** Area value store in meters squared. Typically formatted to display in meters squared or feet squared based on active unit system. */
|
|
23
27
|
QuantityType[QuantityType["Area"] = 3] = "Area";
|
|
28
|
+
/** Volume value which is stored in meters cubed. Typically formatted to display in meters cubed or feet cubed based on active unit system. */
|
|
24
29
|
QuantityType[QuantityType["Volume"] = 4] = "Volume";
|
|
30
|
+
/** LatLong is an angular value which is stored in radians. Typically formatted to display degrees or Degrees-Minute-Seconds based on active unit system. */
|
|
25
31
|
QuantityType[QuantityType["LatLong"] = 5] = "LatLong";
|
|
32
|
+
/** Coordinate/Location value which is stored in meters. Typically formatted to display in meters or feet based on active unit system. */
|
|
26
33
|
QuantityType[QuantityType["Coordinate"] = 6] = "Coordinate";
|
|
34
|
+
/** Stationing is a distance value stored in meters. Typically formatted to display `xxx+xx` or `xx+xxx` based on active unit system. */
|
|
27
35
|
QuantityType[QuantityType["Stationing"] = 7] = "Stationing";
|
|
36
|
+
/** LengthSurvey is a distance value stored in meters. Typically formatted to display in meters or US Survey Feet based on active unit system.. */
|
|
28
37
|
QuantityType[QuantityType["LengthSurvey"] = 8] = "LengthSurvey";
|
|
38
|
+
/** LengthEngineering is a distance value stored in meters. Typically formatted to display either meters or feet based on active unit system. */
|
|
29
39
|
QuantityType[QuantityType["LengthEngineering"] = 9] = "LengthEngineering";
|
|
30
40
|
})(QuantityType = exports.QuantityType || (exports.QuantityType = {}));
|
|
31
41
|
/**
|
|
@@ -52,8 +62,10 @@ class AlternateUnitLabelsRegistry {
|
|
|
52
62
|
}
|
|
53
63
|
}
|
|
54
64
|
exports.AlternateUnitLabelsRegistry = AlternateUnitLabelsRegistry;
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
65
|
+
/**
|
|
66
|
+
* Function to return a QuantityTypeKey given either a QuantityType enum value or a string. This allows caching and
|
|
67
|
+
* retrieving standard and custom quantity types.
|
|
68
|
+
* @public
|
|
57
69
|
*/
|
|
58
70
|
function getQuantityTypeKey(type) {
|
|
59
71
|
// For QuantityType enum values, build a string that shouldn't collide with anything a user may come up with
|
|
@@ -62,35 +74,14 @@ function getQuantityTypeKey(type) {
|
|
|
62
74
|
return type;
|
|
63
75
|
}
|
|
64
76
|
exports.getQuantityTypeKey = getQuantityTypeKey;
|
|
65
|
-
/** CheckboxFormatPropEditorSpec type guard.
|
|
66
|
-
* @beta
|
|
67
|
-
*/
|
|
68
|
-
const isCheckboxFormatPropEditorSpec = (item) => {
|
|
69
|
-
return item.editorType === "checkbox";
|
|
70
|
-
};
|
|
71
|
-
exports.isCheckboxFormatPropEditorSpec = isCheckboxFormatPropEditorSpec;
|
|
72
|
-
/** TextInputFormatPropEditorSpec type guard.
|
|
73
|
-
* @beta
|
|
74
|
-
*/
|
|
75
|
-
const isTextInputFormatPropEditorSpec = (item) => {
|
|
76
|
-
return item.editorType === "text";
|
|
77
|
-
};
|
|
78
|
-
exports.isTextInputFormatPropEditorSpec = isTextInputFormatPropEditorSpec;
|
|
79
|
-
/** TextSelectFormatPropEditorSpec type guard.
|
|
80
|
-
* @beta
|
|
81
|
-
*/
|
|
82
|
-
const isTextSelectFormatPropEditorSpec = (item) => {
|
|
83
|
-
return item.editorType === "select";
|
|
84
|
-
};
|
|
85
|
-
exports.isTextSelectFormatPropEditorSpec = isTextSelectFormatPropEditorSpec;
|
|
86
77
|
/** CustomQuantityTypeDefinition type guard.
|
|
87
|
-
* @
|
|
78
|
+
* @public
|
|
88
79
|
*/
|
|
89
80
|
function isCustomQuantityTypeDefinition(item) {
|
|
90
81
|
return !!item.isCompatibleFormatProps;
|
|
91
82
|
}
|
|
92
83
|
exports.isCustomQuantityTypeDefinition = isCustomQuantityTypeDefinition;
|
|
93
|
-
/** private class to hold standard quantity definitions and implement QuantityTypeDefinition interface */
|
|
84
|
+
/** private class to hold standard quantity definitions as defined by QuantityType enum and implement QuantityTypeDefinition interface */
|
|
94
85
|
class StandardQuantityTypeDefinition {
|
|
95
86
|
constructor(type, persistenceUnit, _labelKey, _descriptionKey) {
|
|
96
87
|
this.type = type;
|
|
@@ -114,6 +105,7 @@ class StandardQuantityTypeDefinition {
|
|
|
114
105
|
}
|
|
115
106
|
return (_a = this._description) !== null && _a !== void 0 ? _a : this.label;
|
|
116
107
|
}
|
|
108
|
+
/** Get a default format to show quantity in persistence unit with precision or 6 decimal places. */
|
|
117
109
|
getDefaultFormatPropsBySystem(requestedSystem) {
|
|
118
110
|
// Fallback same as Format "DefaultRealU" in Formats ecschema
|
|
119
111
|
const fallbackProps = {
|
|
@@ -152,7 +144,7 @@ class StandardQuantityTypeDefinition {
|
|
|
152
144
|
* identified by the [[QuantityType]] enum. [[CustomQuantityTypeDefinition]] can be registered to extend the available quantity types available
|
|
153
145
|
* by frontend tools. The QuantityFormatter also allows the default formats to be overriden.
|
|
154
146
|
*
|
|
155
|
-
* @
|
|
147
|
+
* @public
|
|
156
148
|
*/
|
|
157
149
|
class QuantityFormatter {
|
|
158
150
|
/**
|
|
@@ -163,10 +155,15 @@ class QuantityFormatter {
|
|
|
163
155
|
constructor(showMetricOrUnitSystem) {
|
|
164
156
|
this._unitsProvider = new BasicUnitsProvider_1.BasicUnitsProvider();
|
|
165
157
|
this._alternateUnitLabelsRegistry = new AlternateUnitLabelsRegistry((0, BasicUnitsProvider_1.getDefaultAlternateUnitLabels)());
|
|
158
|
+
/** Registry containing available quantity type definitions. */
|
|
166
159
|
this._quantityTypeRegistry = new Map();
|
|
160
|
+
/** Active UnitSystem key - must be one of "imperial", "metric", "usCustomary", or "usSurvey". */
|
|
167
161
|
this._activeUnitSystem = "imperial";
|
|
162
|
+
/** Map of FormatSpecs for all available QuantityTypes and the active Unit System */
|
|
168
163
|
this._activeFormatSpecsByType = new Map();
|
|
164
|
+
/** Map of ParserSpecs for all available QuantityTypes and the active Unit System */
|
|
169
165
|
this._activeParserSpecsByType = new Map();
|
|
166
|
+
/** Map of FormatSpecs that have been overriden from the default. */
|
|
170
167
|
this._overrideFormatPropsByUnitSystem = new Map();
|
|
171
168
|
/** Called after the active unit system is changed.
|
|
172
169
|
* The system will report the UnitSystemKey/name of the the system that was activated.
|
|
@@ -198,6 +195,7 @@ class QuantityFormatter {
|
|
|
198
195
|
return undefined;
|
|
199
196
|
return overrideMap.get(quantityTypeKey);
|
|
200
197
|
}
|
|
198
|
+
/** Method used to register all QuantityTypes defined in QuantityType enum. */
|
|
201
199
|
async initializeQuantityTypesRegistry() {
|
|
202
200
|
// QuantityType.Length
|
|
203
201
|
const lengthUnit = await this.findUnitByName("Units.M");
|
|
@@ -241,15 +239,13 @@ class QuantityFormatter {
|
|
|
241
239
|
// load cache for every registered QuantityType
|
|
242
240
|
[...this.quantityTypesRegistry.keys()].forEach((key) => {
|
|
243
241
|
const entry = this.quantityTypesRegistry.get(key);
|
|
244
|
-
formatPropsByType.set(entry, this.
|
|
242
|
+
formatPropsByType.set(entry, this.getFormatPropsByQuantityTypeEntryAndSystem(entry, systemKey));
|
|
245
243
|
});
|
|
246
|
-
const formatPropPromises = new Array();
|
|
247
244
|
for (const [entry, formatProps] of formatPropsByType) {
|
|
248
|
-
|
|
245
|
+
await this.loadFormatAndParserSpec(entry, formatProps);
|
|
249
246
|
}
|
|
250
|
-
await Promise.all(formatPropPromises);
|
|
251
247
|
}
|
|
252
|
-
|
|
248
|
+
getFormatPropsByQuantityTypeEntryAndSystem(quantityEntry, requestedSystem, ignoreOverrides) {
|
|
253
249
|
if (!ignoreOverrides) {
|
|
254
250
|
const overrideProps = this.getOverrideFormatPropsByQuantityType(quantityEntry.key, requestedSystem);
|
|
255
251
|
if (overrideProps)
|
|
@@ -322,9 +318,11 @@ class QuantityFormatter {
|
|
|
322
318
|
// initialize default format and parsing specs
|
|
323
319
|
await this.loadFormatAndParsingMapsForSystem();
|
|
324
320
|
}
|
|
321
|
+
/** Return a map that serves as a registry of all standard and custom quantity types. */
|
|
325
322
|
get quantityTypesRegistry() {
|
|
326
323
|
return this._quantityTypeRegistry;
|
|
327
324
|
}
|
|
325
|
+
/** Return the class the contain map of all alternate labels for units. These alternate labels are used when parsing strings in quantity values. */
|
|
328
326
|
get alternateUnitLabelsProvider() {
|
|
329
327
|
return this._alternateUnitLabelsRegistry;
|
|
330
328
|
}
|
|
@@ -337,13 +335,30 @@ class QuantityFormatter {
|
|
|
337
335
|
this._alternateUnitLabelsRegistry.addAlternateLabels(key, ...labels);
|
|
338
336
|
this.onUnitsProviderChanged.emit();
|
|
339
337
|
}
|
|
338
|
+
/** Get/Set the active UnitsProvider class. */
|
|
340
339
|
get unitsProvider() {
|
|
341
340
|
return this._unitsProvider;
|
|
342
341
|
}
|
|
343
342
|
set unitsProvider(unitsProvider) {
|
|
343
|
+
this.setUnitsProvider(unitsProvider); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
344
|
+
}
|
|
345
|
+
/** async method to set a units provider and reload caches */
|
|
346
|
+
async setUnitsProvider(unitsProvider) {
|
|
344
347
|
this._unitsProvider = unitsProvider;
|
|
348
|
+
// force all cached data to be reinitialized
|
|
349
|
+
await IModelApp_1.IModelApp.quantityFormatter.onInitialized();
|
|
350
|
+
// force default tool to start so any tool that may be using cached data will not be using bad data.
|
|
351
|
+
if (IModelApp_1.IModelApp.toolAdmin)
|
|
352
|
+
await IModelApp_1.IModelApp.toolAdmin.startDefaultTool();
|
|
345
353
|
this.onUnitsProviderChanged.emit();
|
|
346
354
|
}
|
|
355
|
+
/** Async call typically used after IModel is closed to reset UnitsProvider to default one that does not require an Units schema. */
|
|
356
|
+
async resetToUseInternalUnitsProvider() {
|
|
357
|
+
if (this._unitsProvider instanceof BasicUnitsProvider_1.BasicUnitsProvider)
|
|
358
|
+
return;
|
|
359
|
+
await this.setUnitsProvider(new BasicUnitsProvider_1.BasicUnitsProvider());
|
|
360
|
+
}
|
|
361
|
+
/** Async call to register a CustomQuantityType and load the FormatSpec and ParserSpec for the new type. */
|
|
347
362
|
async registerQuantityType(entry, replace) {
|
|
348
363
|
if (!replace && this._quantityTypeRegistry.has(entry.key))
|
|
349
364
|
return false;
|
|
@@ -360,7 +375,7 @@ class QuantityFormatter {
|
|
|
360
375
|
}
|
|
361
376
|
/** Reinitialize caches. Typically called by active UnitFormattingSettingsProvider.
|
|
362
377
|
* startDefaultTool - set to true to start the Default to instead of leaving any active tool pointing to cached unit data that is no longer valid
|
|
363
|
-
* @
|
|
378
|
+
* @public
|
|
364
379
|
*/
|
|
365
380
|
async reinitializeFormatAndParsingsMaps(overrideFormatPropsByUnitSystem, unitSystemKey, fireUnitSystemChanged, startDefaultTool) {
|
|
366
381
|
this._overrideFormatPropsByUnitSystem.clear();
|
|
@@ -390,15 +405,17 @@ class QuantityFormatter {
|
|
|
390
405
|
if (IModelApp_1.IModelApp.toolAdmin && restartActiveTool)
|
|
391
406
|
return IModelApp_1.IModelApp.toolAdmin.startDefaultTool();
|
|
392
407
|
}
|
|
393
|
-
/**
|
|
408
|
+
/** Retrieve the active [[UnitSystemKey]] which is used to determine what formats are to be used to display quantities */
|
|
394
409
|
get activeUnitSystem() { return this._activeUnitSystem; }
|
|
410
|
+
/** Clear any formatting override for specified quantity type, but only for the "active" Unit System. */
|
|
395
411
|
async clearOverrideFormats(type) {
|
|
396
412
|
await this.clearOverrideFormatsByQuantityTypeKey(this.getQuantityTypeKey(type));
|
|
397
413
|
}
|
|
414
|
+
/** Set formatting override for specified quantity type, but only for the "active" Unit System. */
|
|
398
415
|
async setOverrideFormats(type, overrideEntry) {
|
|
399
416
|
await this.setOverrideFormatsByQuantityTypeKey(this.getQuantityTypeKey(type), overrideEntry);
|
|
400
417
|
}
|
|
401
|
-
|
|
418
|
+
/** Set Override Format for a quantity type, but only in the "active" Unit System. */
|
|
402
419
|
async setOverrideFormat(type, overrideFormat) {
|
|
403
420
|
const typeKey = this.getQuantityTypeKey(type);
|
|
404
421
|
let overrideEntry = {};
|
|
@@ -412,6 +429,7 @@ class QuantityFormatter {
|
|
|
412
429
|
overrideEntry = { usSurvey: overrideFormat };
|
|
413
430
|
await this.setOverrideFormatsByQuantityTypeKey(typeKey, overrideEntry);
|
|
414
431
|
}
|
|
432
|
+
/** Clear formatting override for all quantity types, but only for the "active" Unit System. */
|
|
415
433
|
async clearAllOverrideFormats() {
|
|
416
434
|
if (0 === this._overrideFormatPropsByUnitSystem.size)
|
|
417
435
|
return;
|
|
@@ -434,10 +452,11 @@ class QuantityFormatter {
|
|
|
434
452
|
}
|
|
435
453
|
}
|
|
436
454
|
}
|
|
437
|
-
/** Converts a QuantityTypeArg into a QuantityTypeKey/string value. */
|
|
455
|
+
/** Converts a QuantityTypeArg into a QuantityTypeKey/string value that can be used to lookup custom and standard quantity types. */
|
|
438
456
|
getQuantityTypeKey(type) {
|
|
439
457
|
return getQuantityTypeKey(type);
|
|
440
458
|
}
|
|
459
|
+
/** Return [[QuantityTypeDefinition]] if type has been registered. Standard QuantityTypes are automatically registered. */
|
|
441
460
|
getQuantityDefinition(type) {
|
|
442
461
|
return this.quantityTypesRegistry.get(this.getQuantityTypeKey(type));
|
|
443
462
|
}
|
|
@@ -447,13 +466,14 @@ class QuantityFormatter {
|
|
|
447
466
|
findFormatterSpecByQuantityType(type, _unused) {
|
|
448
467
|
return this._activeFormatSpecsByType.get(this.getQuantityTypeKey(type));
|
|
449
468
|
}
|
|
469
|
+
/** Asynchronous Call to get a FormatterSpec for a QuantityType. This formatter spec can be used to synchronously format quantities. */
|
|
450
470
|
async generateFormatterSpecByType(type, formatProps) {
|
|
451
471
|
const quantityTypeDefinition = this.quantityTypesRegistry.get(this.getQuantityTypeKey(type));
|
|
452
472
|
if (quantityTypeDefinition)
|
|
453
473
|
return quantityTypeDefinition.generateFormatterSpec(formatProps, this.unitsProvider);
|
|
454
474
|
throw new Error(`Unable to generate FormatSpec for QuantityType ${type}`);
|
|
455
475
|
}
|
|
456
|
-
/** Asynchronous Call to get a FormatterSpec
|
|
476
|
+
/** Asynchronous Call to get a FormatterSpec for a QuantityType and a Unit System. This formatter spec can be used to synchronously format quantities.
|
|
457
477
|
* @param type One of the built-in quantity types supported.
|
|
458
478
|
* @param system Requested unit system key. Note it is more efficient to use setActiveUnitSystem to set up formatters for all
|
|
459
479
|
* quantity types of a unit system.
|
|
@@ -470,7 +490,7 @@ class QuantityFormatter {
|
|
|
470
490
|
const entry = this.quantityTypesRegistry.get(quantityKey);
|
|
471
491
|
if (!entry)
|
|
472
492
|
throw new Error(`Unable to find registered quantity type with key ${quantityKey}`);
|
|
473
|
-
return entry.generateFormatterSpec(this.
|
|
493
|
+
return entry.generateFormatterSpec(this.getFormatPropsByQuantityTypeEntryAndSystem(entry, requestedSystem), this.unitsProvider);
|
|
474
494
|
}
|
|
475
495
|
/** Asynchronous Call to get a FormatterSpec for a QuantityType.
|
|
476
496
|
* @param type One of the built-in quantity types supported.
|
|
@@ -489,6 +509,7 @@ class QuantityFormatter {
|
|
|
489
509
|
findParserSpecByQuantityType(type) {
|
|
490
510
|
return this._activeParserSpecsByType.get(this.getQuantityTypeKey(type));
|
|
491
511
|
}
|
|
512
|
+
/** Asynchronous Call to get a ParserSpec for a QuantityType. If the UnitSystemKey is not specified the active Unit System is used. **/
|
|
492
513
|
async getParserSpecByQuantityTypeAndSystem(type, system) {
|
|
493
514
|
const quantityKey = this.getQuantityTypeKey(type);
|
|
494
515
|
const requestedSystem = system !== null && system !== void 0 ? system : this.activeUnitSystem;
|
|
@@ -500,7 +521,7 @@ class QuantityFormatter {
|
|
|
500
521
|
const entry = this.quantityTypesRegistry.get(quantityKey);
|
|
501
522
|
if (!entry)
|
|
502
523
|
throw new Error(`Unable to find registered quantity type with key ${quantityKey}`);
|
|
503
|
-
return entry.generateParserSpec(this.
|
|
524
|
+
return entry.generateParserSpec(this.getFormatPropsByQuantityTypeEntryAndSystem(entry, requestedSystem), this.unitsProvider);
|
|
504
525
|
}
|
|
505
526
|
/** Asynchronous Call to get a ParserSpec for a QuantityType.
|
|
506
527
|
* @param type One of the built-in quantity types supported.
|
|
@@ -534,7 +555,9 @@ class QuantityFormatter {
|
|
|
534
555
|
return parserSpec.parseToQuantityValue(inString);
|
|
535
556
|
return { ok: false, error: core_quantity_1.ParseError.InvalidParserSpec };
|
|
536
557
|
}
|
|
537
|
-
/**
|
|
558
|
+
/**
|
|
559
|
+
* Get a UnitSystemKey from a string that may have been entered via a key-in. Supports different variation of
|
|
560
|
+
* unit system names that have been used in the past.
|
|
538
561
|
*/
|
|
539
562
|
getUnitSystemFromString(inputSystem, fallback) {
|
|
540
563
|
switch (inputSystem.toLowerCase()) {
|
|
@@ -559,6 +582,7 @@ class QuantityFormatter {
|
|
|
559
582
|
}
|
|
560
583
|
return "imperial";
|
|
561
584
|
}
|
|
585
|
+
/** Return true if the QuantityType is using an override format. */
|
|
562
586
|
hasActiveOverride(type, checkOnlyActiveUnitSystem) {
|
|
563
587
|
const quantityTypeKey = this.getQuantityTypeKey(type);
|
|
564
588
|
if (checkOnlyActiveUnitSystem) {
|
|
@@ -573,22 +597,29 @@ class QuantityFormatter {
|
|
|
573
597
|
}
|
|
574
598
|
return false;
|
|
575
599
|
}
|
|
600
|
+
/** Get the cached FormatProps give a quantity type. If ignoreOverrides is false then if the format has been overridden
|
|
601
|
+
* the overridden format is returned, else the standard format is returned.
|
|
602
|
+
*/
|
|
576
603
|
getFormatPropsByQuantityType(quantityType, requestedSystem, ignoreOverrides) {
|
|
577
604
|
const quantityEntry = this.quantityTypesRegistry.get(this.getQuantityTypeKey(quantityType));
|
|
578
605
|
if (quantityEntry)
|
|
579
|
-
return this.
|
|
606
|
+
return this.getFormatPropsByQuantityTypeEntryAndSystem(quantityEntry, requestedSystem !== null && requestedSystem !== void 0 ? requestedSystem : this.activeUnitSystem, ignoreOverrides);
|
|
580
607
|
return undefined;
|
|
581
608
|
}
|
|
582
609
|
// keep following to maintain existing API of implementing UnitsProvider
|
|
583
|
-
|
|
584
|
-
|
|
610
|
+
/** Find [UnitProp] for a specific unit label. */
|
|
611
|
+
async findUnit(unitLabel, schemaName, phenomenon, unitSystem) {
|
|
612
|
+
return this._unitsProvider.findUnit(unitLabel, schemaName, phenomenon, unitSystem);
|
|
585
613
|
}
|
|
614
|
+
/** Returns all defined units for the specified Unit Family/Phenomenon. */
|
|
586
615
|
async getUnitsByFamily(phenomenon) {
|
|
587
616
|
return this._unitsProvider.getUnitsByFamily(phenomenon);
|
|
588
617
|
}
|
|
618
|
+
/** Find [UnitProp] for a specific unit name. */
|
|
589
619
|
async findUnitByName(unitName) {
|
|
590
620
|
return this._unitsProvider.findUnitByName(unitName);
|
|
591
621
|
}
|
|
622
|
+
/** Returns data needed to convert from one Unit to another in the same Unit Family/Phenomenon. */
|
|
592
623
|
async getConversion(fromUnit, toUnit) {
|
|
593
624
|
return this._unitsProvider.getConversion(fromUnit, toUnit);
|
|
594
625
|
}
|