@itwin/core-frontend 5.1.0-dev.12 → 5.1.0-dev.14
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/lib/cjs/IModelApp.d.ts +15 -0
- package/lib/cjs/IModelApp.d.ts.map +1 -1
- package/lib/cjs/IModelApp.js +19 -1
- package/lib/cjs/IModelApp.js.map +1 -1
- package/lib/cjs/IpcApp.d.ts +1 -0
- package/lib/cjs/IpcApp.d.ts.map +1 -1
- package/lib/cjs/IpcApp.js +3 -1
- package/lib/cjs/IpcApp.js.map +1 -1
- package/lib/cjs/internal/tile/ClassifierTileTree.js +3 -1
- package/lib/cjs/internal/tile/ClassifierTileTree.js.map +1 -1
- package/lib/cjs/internal/tile/IModelTile.d.ts +1 -0
- package/lib/cjs/internal/tile/IModelTile.d.ts.map +1 -1
- package/lib/cjs/internal/tile/IModelTile.js +4 -0
- package/lib/cjs/internal/tile/IModelTile.js.map +1 -1
- package/lib/cjs/internal/tile/PrimaryTileTree.d.ts.map +1 -1
- package/lib/cjs/internal/tile/PrimaryTileTree.js +4 -3
- package/lib/cjs/internal/tile/PrimaryTileTree.js.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts +76 -7
- package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityFormatter.js +126 -23
- package/lib/cjs/quantity-formatting/QuantityFormatter.js.map +1 -1
- package/lib/cjs/tile/TileAdmin.d.ts +10 -0
- package/lib/cjs/tile/TileAdmin.d.ts.map +1 -1
- package/lib/cjs/tile/TileAdmin.js +3 -0
- package/lib/cjs/tile/TileAdmin.js.map +1 -1
- package/lib/cjs/tools/MeasureTool.d.ts +9 -0
- package/lib/cjs/tools/MeasureTool.d.ts.map +1 -1
- package/lib/cjs/tools/MeasureTool.js +53 -22
- package/lib/cjs/tools/MeasureTool.js.map +1 -1
- package/lib/esm/IModelApp.d.ts +15 -0
- package/lib/esm/IModelApp.d.ts.map +1 -1
- package/lib/esm/IModelApp.js +20 -2
- package/lib/esm/IModelApp.js.map +1 -1
- package/lib/esm/IpcApp.d.ts +1 -0
- package/lib/esm/IpcApp.d.ts.map +1 -1
- package/lib/esm/IpcApp.js +3 -1
- package/lib/esm/IpcApp.js.map +1 -1
- package/lib/esm/internal/tile/ClassifierTileTree.js +3 -1
- package/lib/esm/internal/tile/ClassifierTileTree.js.map +1 -1
- package/lib/esm/internal/tile/IModelTile.d.ts +1 -0
- package/lib/esm/internal/tile/IModelTile.d.ts.map +1 -1
- package/lib/esm/internal/tile/IModelTile.js +4 -0
- package/lib/esm/internal/tile/IModelTile.js.map +1 -1
- package/lib/esm/internal/tile/PrimaryTileTree.d.ts.map +1 -1
- package/lib/esm/internal/tile/PrimaryTileTree.js +4 -3
- package/lib/esm/internal/tile/PrimaryTileTree.js.map +1 -1
- package/lib/esm/quantity-formatting/QuantityFormatter.d.ts +76 -7
- package/lib/esm/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
- package/lib/esm/quantity-formatting/QuantityFormatter.js +124 -23
- package/lib/esm/quantity-formatting/QuantityFormatter.js.map +1 -1
- package/lib/esm/tile/TileAdmin.d.ts +10 -0
- package/lib/esm/tile/TileAdmin.d.ts.map +1 -1
- package/lib/esm/tile/TileAdmin.js +3 -0
- package/lib/esm/tile/TileAdmin.js.map +1 -1
- package/lib/esm/tools/MeasureTool.d.ts +9 -0
- package/lib/esm/tools/MeasureTool.d.ts.map +1 -1
- package/lib/esm/tools/MeasureTool.js +53 -22
- package/lib/esm/tools/MeasureTool.js.map +1 -1
- package/lib/public/scripts/parse-imdl-worker.js +1 -1
- package/lib/workers/webpack/parse-imdl-worker.js +1 -1
- package/package.json +20 -20
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module QuantityFormatting
|
|
3
3
|
*/
|
|
4
|
-
import { BeUiEvent } from "@itwin/core-bentley";
|
|
5
|
-
import { AlternateUnitLabelsProvider, FormatProps, FormatterSpec, ParserSpec, QuantityParseResult, UnitConversionProps, UnitProps, UnitsProvider, UnitSystemKey } from "@itwin/core-quantity";
|
|
4
|
+
import { BeEvent, BeUiEvent } from "@itwin/core-bentley";
|
|
5
|
+
import { AlternateUnitLabelsProvider, FormatDefinition, FormatProps, FormatsChangedArgs, FormatsProvider, FormatterSpec, ParserSpec, QuantityParseResult, UnitConversionProps, UnitProps, UnitsProvider, UnitSystemKey } from "@itwin/core-quantity";
|
|
6
6
|
import { IModelConnection } from "../IModelConnection";
|
|
7
7
|
import { CustomFormatPropEditorSpec } from "./QuantityTypesEditorSpecs";
|
|
8
8
|
/**
|
|
@@ -42,6 +42,18 @@ export type QuantityTypeKey = string;
|
|
|
42
42
|
* @public
|
|
43
43
|
*/
|
|
44
44
|
export type UnitNameKey = string;
|
|
45
|
+
/**
|
|
46
|
+
* Interface for the properties required to create a FormatterSpec or ParserSpec.
|
|
47
|
+
* @beta
|
|
48
|
+
*/
|
|
49
|
+
export interface CreateFormattingSpecProps {
|
|
50
|
+
/** The name of the persistence unit. */
|
|
51
|
+
persistenceUnitName: string;
|
|
52
|
+
/** The format properties to use for the spec. */
|
|
53
|
+
formatProps: FormatProps;
|
|
54
|
+
/** Optional name for the format. */
|
|
55
|
+
formatName?: string;
|
|
56
|
+
}
|
|
45
57
|
/**
|
|
46
58
|
* Class that contains alternate Unit Labels. These labels are used when parsing strings to quantities.
|
|
47
59
|
* One use case is to allow a "^", which is easily input, to be used to specify "°".
|
|
@@ -181,12 +193,37 @@ export interface UnitFormattingSettingsProvider {
|
|
|
181
193
|
* should trigger reloading of the overrides when the "active" imodel changes. */
|
|
182
194
|
readonly maintainOverridesPerIModel: boolean;
|
|
183
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* A default formatsProvider, that provides a limited set of [[FormatDefinition]], associated to a few [[KindOfQuantity]].
|
|
198
|
+
* Maps each KindOfQuantity to a [[QuantityType]].
|
|
199
|
+
* When retrieving a valid [[KindOfQuantity]], returns the [[FormatProps]] for the associated [[QuantityType]].
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
export declare class QuantityTypeFormatsProvider implements FormatsProvider {
|
|
203
|
+
onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;
|
|
204
|
+
constructor();
|
|
205
|
+
private _kindOfQuantityMap;
|
|
206
|
+
getFormat(name: string): Promise<FormatDefinition | undefined>;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* An implementation of the [[FormatsProvider]] interface that forwards calls to getFormats to the underlying FormatsProvider.
|
|
210
|
+
* Also fires the onFormatsChanged event when the underlying FormatsProvider fires its own onFormatsChanged event.
|
|
211
|
+
* @internal
|
|
212
|
+
*/
|
|
213
|
+
export declare class FormatsProviderManager implements FormatsProvider {
|
|
214
|
+
private _formatsProvider;
|
|
215
|
+
onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;
|
|
216
|
+
constructor(_formatsProvider: FormatsProvider);
|
|
217
|
+
getFormat(name: string): Promise<FormatDefinition | undefined>;
|
|
218
|
+
get formatsProvider(): FormatsProvider;
|
|
219
|
+
set formatsProvider(formatsProvider: FormatsProvider);
|
|
220
|
+
}
|
|
184
221
|
/** Class that supports formatting quantity values into strings and parsing strings into quantity values. This class also maintains
|
|
185
222
|
* the "active" unit system and caches FormatterSpecs and ParserSpecs for the "active" unit system to allow synchronous access to
|
|
186
223
|
* parsing and formatting values. The support unit systems are defined by [[UnitSystemKey]] and is kept in synch with the unit systems
|
|
187
224
|
* provided by the Presentation Manager on the backend. The QuantityFormatter contains a registry of quantity type definitions. These definitions implement
|
|
188
|
-
* the [[QuantityTypeDefinition]] interface, which among other things, provide default [FormatProps]
|
|
189
|
-
* to generate both a [FormatterSpec]
|
|
225
|
+
* the [[QuantityTypeDefinition]] interface, which among other things, provide default [[FormatProps]], and provide methods
|
|
226
|
+
* to generate both a [[FormatterSpec]] and a [[ParserSpec]]. There are built-in quantity types that are
|
|
190
227
|
* identified by the [[QuantityType]] enum. [[CustomQuantityTypeDefinition]] can be registered to extend the available quantity types available
|
|
191
228
|
* by frontend tools. The QuantityFormatter also allows the default formats to be overriden.
|
|
192
229
|
*
|
|
@@ -314,18 +351,38 @@ export declare class QuantityFormatter implements UnitsProvider {
|
|
|
314
351
|
* @return A FormatterSpec Promise.
|
|
315
352
|
*/
|
|
316
353
|
getParserSpecByQuantityType(type: QuantityTypeArg, isImperial?: boolean): Promise<ParserSpec | undefined>;
|
|
354
|
+
/** Generates a formatted string asynchronously for a quantity given the provided properties.
|
|
355
|
+
* @param props - an object containing value, valueUnitName, and kindOfQuantityName.
|
|
356
|
+
* @return A promise resolving to a formatted string.
|
|
357
|
+
*/
|
|
358
|
+
formatQuantity(props: {
|
|
359
|
+
value: number;
|
|
360
|
+
valueUnitName: string;
|
|
361
|
+
kindOfQuantityName: string;
|
|
362
|
+
}): Promise<string>;
|
|
317
363
|
/** Generates a formatted string for a quantity given its format spec.
|
|
318
364
|
* @param magnitude The magnitude of the quantity.
|
|
319
365
|
* @param formatSpec The format specification. See methods getFormatterSpecByQuantityType and findFormatterSpecByQuantityType.
|
|
320
|
-
* @return
|
|
366
|
+
* @return a formatted string.
|
|
367
|
+
*/
|
|
368
|
+
formatQuantity(magnitude: number, formatSpec?: FormatterSpec): string;
|
|
369
|
+
private formatQuantityAsync;
|
|
370
|
+
/** Parse input string asynchronously into a quantity given the provided properties.
|
|
371
|
+
* @param props - an object containing value, valueUnitName, and kindOfQuantityName.
|
|
372
|
+
* @return Promise resolving to a QuantityParseResult object containing either the parsed value or an error value if unsuccessful.
|
|
321
373
|
*/
|
|
322
|
-
|
|
374
|
+
parseToQuantityValue(props: {
|
|
375
|
+
value: string;
|
|
376
|
+
valueUnitName: string;
|
|
377
|
+
kindOfQuantityName: string;
|
|
378
|
+
}): Promise<QuantityParseResult>;
|
|
323
379
|
/** Parse input string into quantity given the ParserSpec
|
|
324
380
|
* @param inString The magnitude of the quantity.
|
|
325
381
|
* @param parserSpec The parse specification the defines the expected format of the string and the conversion to the output unit.
|
|
326
382
|
* @return QuantityParseResult object containing either the parsed value or an error value if unsuccessful.
|
|
327
383
|
*/
|
|
328
|
-
parseToQuantityValue(inString: string, parserSpec
|
|
384
|
+
parseToQuantityValue(inString: string, parserSpec?: ParserSpec): QuantityParseResult;
|
|
385
|
+
private parseToQuantityValueAsync;
|
|
329
386
|
/**
|
|
330
387
|
* Get a UnitSystemKey from a string that may have been entered via a key-in. Supports different variation of
|
|
331
388
|
* unit system names that have been used in the past.
|
|
@@ -345,5 +402,17 @@ export declare class QuantityFormatter implements UnitsProvider {
|
|
|
345
402
|
findUnitByName(unitName: string): Promise<UnitProps>;
|
|
346
403
|
/** Returns data needed to convert from one Unit to another in the same Unit Family/Phenomenon. */
|
|
347
404
|
getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;
|
|
405
|
+
/**
|
|
406
|
+
* Creates a [[FormatterSpec]] for a given persistence unit name and format properties, using the [[UnitsProvider]] to resolve the persistence unit.
|
|
407
|
+
* @beta
|
|
408
|
+
* @param props - A [[CreateFormattingSpecProps]] interface.
|
|
409
|
+
*/
|
|
410
|
+
createFormatterSpec(props: CreateFormattingSpecProps): Promise<FormatterSpec>;
|
|
411
|
+
/**
|
|
412
|
+
* Creates a [[ParserSpec]] for a given persistence unit name and format properties, using the [[UnitsProvider]] to resolve the persistence unit.
|
|
413
|
+
* @beta
|
|
414
|
+
* @param props - A [[CreateFormattingSpecProps]] object.
|
|
415
|
+
*/
|
|
416
|
+
createParserSpec(props: CreateFormattingSpecProps): Promise<ParserSpec>;
|
|
348
417
|
}
|
|
349
418
|
//# sourceMappingURL=QuantityFormatter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuantityFormatter.d.ts","sourceRoot":"","sources":["../../../src/quantity-formatting/QuantityFormatter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAgB,SAAS,EAAU,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"QuantityFormatter.d.ts","sourceRoot":"","sources":["../../../src/quantity-formatting/QuantityFormatter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAgB,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,2BAA2B,EAAU,gBAAgB,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,aAAa,EAAc,UAAU,EAAE,mBAAmB,EACnK,mBAAmB,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAC7D,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAIxE;;;GAGG;AACH,oBAAY,YAAY;IACtB,6HAA6H;IAC7H,MAAM,IAAI;IACV,8IAA8I;IAC9I,KAAK,IAAI;IACT,wIAAwI;IACxI,IAAI,IAAI;IACR,8IAA8I;IAC9I,MAAM,IAAI;IACV,4JAA4J;IAC5J,OAAO,IAAI;IACX,yIAAyI;IACzI,UAAU,IAAI;IACd,wIAAwI;IACxI,UAAU,IAAI;IACd,kJAAkJ;IAClJ,YAAY,IAAI;IAChB,gJAAgJ;IAChJ,iBAAiB,IAAI;CACtB;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,MAAM,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,wCAAwC;IACxC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iDAAiD;IACjD,WAAW,EAAE,WAAW,CAAC;IACzB,oCAAoC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,2BAA4B,YAAW,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AiB7E,yBAAyB;IAgBvC;;;OAGG;IACI,uBAAuB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,GAAG,aAAa;IAwB5F,mEAAmE;IAC5D,iBAAiB,CAAC,IAAI,EAAE,eAAe,EAAE,yBAAyB,CAAC,EAAE,OAAO,GAAG,OAAO;IAiB7F;;OAEG;IACI,4BAA4B,CAAC,YAAY,EAAE,eAAe,EAAE,eAAe,CAAC,EAAE,aAAa,EAAE,eAAe,CAAC,EAAE,OAAO;IAQ7H,iDAAiD;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAI3H,0EAA0E;IAC7D,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAIvE,gDAAgD;IACnC,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAIjE,kGAAkG;IACrF,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAIhG;;;;OAIG;IACU,mBAAmB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC;IAO1F;;;;OAIG;IACU,gBAAgB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,UAAU,CAAC;CAMrF"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module QuantityFormatting
|
|
7
7
|
*/
|
|
8
|
-
import { BentleyError, BeUiEvent, Logger } from "@itwin/core-bentley";
|
|
8
|
+
import { BeEvent, BentleyError, BeUiEvent, Logger } from "@itwin/core-bentley";
|
|
9
9
|
import { Format, FormatterSpec, ParseError, ParserSpec, } from "@itwin/core-quantity";
|
|
10
10
|
import { FrontendLoggerCategory } from "../common/FrontendLoggerCategory";
|
|
11
11
|
import { IModelApp } from "../IModelApp";
|
|
@@ -135,12 +135,66 @@ class StandardQuantityTypeDefinition {
|
|
|
135
135
|
return ParserSpec.create(format, unitsProvider, this.persistenceUnit, alternateUnitLabelsProvider);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* A default formatsProvider, that provides a limited set of [[FormatDefinition]], associated to a few [[KindOfQuantity]].
|
|
140
|
+
* Maps each KindOfQuantity to a [[QuantityType]].
|
|
141
|
+
* When retrieving a valid [[KindOfQuantity]], returns the [[FormatProps]] for the associated [[QuantityType]].
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
export class QuantityTypeFormatsProvider {
|
|
145
|
+
onFormatsChanged = new BeEvent();
|
|
146
|
+
constructor() {
|
|
147
|
+
IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(() => {
|
|
148
|
+
this.onFormatsChanged.raiseEvent({ formatsChanged: "all" });
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
_kindOfQuantityMap = new Map([
|
|
152
|
+
["AecUnits.LENGTH", QuantityType.Length],
|
|
153
|
+
["AecUnits.ANGLE", QuantityType.Angle],
|
|
154
|
+
["AecUnits.AREA", QuantityType.Area],
|
|
155
|
+
["AecUnits.VOLUME", QuantityType.Volume],
|
|
156
|
+
["RoadRailUnits.STATION", QuantityType.Stationing],
|
|
157
|
+
["RoadRailUnits.LENGTH", QuantityType.LengthSurvey],
|
|
158
|
+
]);
|
|
159
|
+
async getFormat(name) {
|
|
160
|
+
const quantityType = this._kindOfQuantityMap.get(name);
|
|
161
|
+
if (!quantityType)
|
|
162
|
+
return undefined;
|
|
163
|
+
return IModelApp.quantityFormatter.getFormatPropsByQuantityType(quantityType);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* An implementation of the [[FormatsProvider]] interface that forwards calls to getFormats to the underlying FormatsProvider.
|
|
168
|
+
* Also fires the onFormatsChanged event when the underlying FormatsProvider fires its own onFormatsChanged event.
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
export class FormatsProviderManager {
|
|
172
|
+
_formatsProvider;
|
|
173
|
+
onFormatsChanged = new BeEvent();
|
|
174
|
+
constructor(_formatsProvider) {
|
|
175
|
+
this._formatsProvider = _formatsProvider;
|
|
176
|
+
this._formatsProvider.onFormatsChanged.addListener((args) => {
|
|
177
|
+
this.onFormatsChanged.raiseEvent(args);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async getFormat(name) {
|
|
181
|
+
return this._formatsProvider.getFormat(name);
|
|
182
|
+
}
|
|
183
|
+
get formatsProvider() { return this; }
|
|
184
|
+
set formatsProvider(formatsProvider) {
|
|
185
|
+
this._formatsProvider = formatsProvider;
|
|
186
|
+
this._formatsProvider.onFormatsChanged.addListener((args) => {
|
|
187
|
+
this.onFormatsChanged.raiseEvent(args);
|
|
188
|
+
});
|
|
189
|
+
this.onFormatsChanged.raiseEvent({ formatsChanged: "all" });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
138
192
|
/** Class that supports formatting quantity values into strings and parsing strings into quantity values. This class also maintains
|
|
139
193
|
* the "active" unit system and caches FormatterSpecs and ParserSpecs for the "active" unit system to allow synchronous access to
|
|
140
194
|
* parsing and formatting values. The support unit systems are defined by [[UnitSystemKey]] and is kept in synch with the unit systems
|
|
141
195
|
* provided by the Presentation Manager on the backend. The QuantityFormatter contains a registry of quantity type definitions. These definitions implement
|
|
142
|
-
* the [[QuantityTypeDefinition]] interface, which among other things, provide default [FormatProps]
|
|
143
|
-
* to generate both a [FormatterSpec]
|
|
196
|
+
* the [[QuantityTypeDefinition]] interface, which among other things, provide default [[FormatProps]], and provide methods
|
|
197
|
+
* to generate both a [[FormatterSpec]] and a [[ParserSpec]]. There are built-in quantity types that are
|
|
144
198
|
* identified by the [[QuantityType]] enum. [[CustomQuantityTypeDefinition]] can be registered to extend the available quantity types available
|
|
145
199
|
* by frontend tools. The QuantityFormatter also allows the default formats to be overriden.
|
|
146
200
|
*
|
|
@@ -544,26 +598,51 @@ export class QuantityFormatter {
|
|
|
544
598
|
requestedSystem = isImperial ? "imperial" : "metric";
|
|
545
599
|
return this.getParserSpecByQuantityTypeAndSystem(type, requestedSystem);
|
|
546
600
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
return
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
601
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
602
|
+
formatQuantity(args, spec) {
|
|
603
|
+
if (typeof args === "number") {
|
|
604
|
+
/** Format a quantity value. Default FormatterSpec implementation uses Formatter.formatQuantity. */
|
|
605
|
+
const magnitude = args;
|
|
606
|
+
if (spec)
|
|
607
|
+
return spec.applyFormatting(magnitude);
|
|
608
|
+
return magnitude.toString();
|
|
609
|
+
}
|
|
610
|
+
return this.formatQuantityAsync(args);
|
|
611
|
+
}
|
|
612
|
+
async formatQuantityAsync(args) {
|
|
613
|
+
const { value, valueUnitName, kindOfQuantityName } = args;
|
|
614
|
+
const formatProps = await IModelApp.formatsProvider.getFormat(kindOfQuantityName);
|
|
615
|
+
if (!formatProps)
|
|
616
|
+
return value.toString();
|
|
617
|
+
const formatSpec = await this.createFormatterSpec({
|
|
618
|
+
persistenceUnitName: valueUnitName,
|
|
619
|
+
formatProps,
|
|
620
|
+
formatName: kindOfQuantityName,
|
|
621
|
+
});
|
|
622
|
+
return formatSpec.applyFormatting(value);
|
|
623
|
+
}
|
|
624
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
625
|
+
parseToQuantityValue(args, parserSpec) {
|
|
626
|
+
if (typeof args === "string") {
|
|
627
|
+
/** Parse a quantity value. Default ParserSpec implementation uses ParserSpec.parseToQuantityValue. */
|
|
628
|
+
const inString = args;
|
|
629
|
+
if (parserSpec)
|
|
630
|
+
return parserSpec.parseToQuantityValue(inString);
|
|
631
|
+
return { ok: false, error: ParseError.InvalidParserSpec };
|
|
632
|
+
}
|
|
633
|
+
return this.parseToQuantityValueAsync(args);
|
|
634
|
+
}
|
|
635
|
+
async parseToQuantityValueAsync(args) {
|
|
636
|
+
const { value, valueUnitName, kindOfQuantityName } = args;
|
|
637
|
+
const formatProps = await IModelApp.formatsProvider.getFormat(kindOfQuantityName);
|
|
638
|
+
if (!formatProps)
|
|
639
|
+
return { ok: false, error: ParseError.InvalidParserSpec };
|
|
640
|
+
const parserSpec = await this.createParserSpec({
|
|
641
|
+
persistenceUnitName: valueUnitName,
|
|
642
|
+
formatProps,
|
|
643
|
+
formatName: kindOfQuantityName,
|
|
644
|
+
});
|
|
645
|
+
return parserSpec.parseToQuantityValue(value);
|
|
567
646
|
}
|
|
568
647
|
/**
|
|
569
648
|
* Get a UnitSystemKey from a string that may have been entered via a key-in. Supports different variation of
|
|
@@ -633,6 +712,28 @@ export class QuantityFormatter {
|
|
|
633
712
|
async getConversion(fromUnit, toUnit) {
|
|
634
713
|
return this._unitsProvider.getConversion(fromUnit, toUnit);
|
|
635
714
|
}
|
|
715
|
+
/**
|
|
716
|
+
* Creates a [[FormatterSpec]] for a given persistence unit name and format properties, using the [[UnitsProvider]] to resolve the persistence unit.
|
|
717
|
+
* @beta
|
|
718
|
+
* @param props - A [[CreateFormattingSpecProps]] interface.
|
|
719
|
+
*/
|
|
720
|
+
async createFormatterSpec(props) {
|
|
721
|
+
const { persistenceUnitName, formatProps, formatName } = props;
|
|
722
|
+
const persistenceUnitProps = await this._unitsProvider.findUnitByName(persistenceUnitName);
|
|
723
|
+
const format = await Format.createFromJSON(formatName ?? "temp", this._unitsProvider, formatProps);
|
|
724
|
+
return FormatterSpec.create(`${format.name}_format_spec`, format, this._unitsProvider, persistenceUnitProps);
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Creates a [[ParserSpec]] for a given persistence unit name and format properties, using the [[UnitsProvider]] to resolve the persistence unit.
|
|
728
|
+
* @beta
|
|
729
|
+
* @param props - A [[CreateFormattingSpecProps]] object.
|
|
730
|
+
*/
|
|
731
|
+
async createParserSpec(props) {
|
|
732
|
+
const { persistenceUnitName, formatProps, formatName } = props;
|
|
733
|
+
const persistenceUnitProps = await this._unitsProvider.findUnitByName(persistenceUnitName);
|
|
734
|
+
const format = await Format.createFromJSON(formatName ?? "temp", this._unitsProvider, formatProps);
|
|
735
|
+
return ParserSpec.create(format, this._unitsProvider, persistenceUnitProps);
|
|
736
|
+
}
|
|
636
737
|
}
|
|
637
738
|
// ========================================================================================================================================
|
|
638
739
|
// Default Data
|