@itwin/ecschema-metadata 3.1.0-dev.6 → 3.1.0
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 +38 -3
- package/lib/cjs/Context.d.ts +5 -0
- package/lib/cjs/Context.d.ts.map +1 -1
- package/lib/cjs/Context.js +13 -0
- package/lib/cjs/Context.js.map +1 -1
- package/lib/cjs/Deserialization/Helper.js +3 -3
- package/lib/cjs/Deserialization/Helper.js.map +1 -1
- package/lib/cjs/Metadata/Format.d.ts +2 -15
- package/lib/cjs/Metadata/Format.d.ts.map +1 -1
- package/lib/cjs/Metadata/Format.js +42 -119
- package/lib/cjs/Metadata/Format.js.map +1 -1
- package/lib/cjs/Metadata/KindOfQuantity.js +2 -2
- package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
- package/lib/cjs/Metadata/OverrideFormat.d.ts +1 -1
- package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
- package/lib/cjs/Metadata/Unit.d.ts +4 -0
- package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
- package/lib/cjs/Metadata/Unit.js +6 -0
- package/lib/cjs/Metadata/Unit.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.d.ts +1 -2
- package/lib/cjs/UnitConversion/UnitConversion.d.ts.map +1 -1
- package/lib/cjs/UnitConversion/UnitConversion.js +1 -2
- package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.d.ts +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.js +1 -1
- package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
- package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +78 -0
- package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts.map +1 -0
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js +237 -0
- package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -0
- package/lib/cjs/ecschema-metadata.d.ts +3 -1
- package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
- package/lib/cjs/ecschema-metadata.js +3 -1
- package/lib/cjs/ecschema-metadata.js.map +1 -1
- package/package.json +7 -5
- package/lib/cjs/utils/FormatEnums.d.ts +0 -106
- package/lib/cjs/utils/FormatEnums.d.ts.map +0 -1
- package/lib/cjs/utils/FormatEnums.js +0 -265
- package/lib/cjs/utils/FormatEnums.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OverrideFormat.js","sourceRoot":"","sources":["../../../src/Metadata/OverrideFormat.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oFAAiF;AACjF,4CAA8C;AAO9C;;;GAGG;AACH,MAAa,cAAc;IAazB,YAAY,MAAc,EAAE,SAAkD,EAAE,aAAgE;QAC9I,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,4BAA4B,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC1F,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;IAC9B,CAAC;IAED,mCAAmC;IACnC,IAAW,SAAS,KAA6C,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IACpJ,IAAW,KAAK,KAAK,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5F,sCAAsC;IACtC,IAAW,QAAQ,KAAa,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,IAAW,WAAW,KAAa,OA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Ac,KAAK,SAAS,IAAI,cAAc,CAAC,IAAI,KAAK,SAAS,IAAI,cAAc,CAAC,MAAM,KAAK,SAAS;YACtG,cAAc,CAAC,MAAM,CAAC,cAAc,KAAK,0BAAc,CAAC,MAAM,CAAC;IAC1E,CAAC;CACF;AA7FD,wCA6FC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Metadata\r\n */\r\n\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from \"
|
|
1
|
+
{"version":3,"file":"OverrideFormat.js","sourceRoot":"","sources":["../../../src/Metadata/OverrideFormat.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oFAAiF;AACjF,4CAA8C;AAO9C;;;GAGG;AACH,MAAa,cAAc;IAazB,YAAY,MAAc,EAAE,SAAkD,EAAE,aAAgE;QAC9I,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,4BAA4B,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC1F,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;IAC9B,CAAC;IAED,mCAAmC;IACnC,IAAW,SAAS,KAA6C,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IACpJ,IAAW,KAAK,KAAK,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC,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GAAG,CAAC;;gBAEjC,QAAQ,IAAI,IAAI,IAAI,CAAC,QAAQ,IAAI,SAAS,GAAG,CAAC;QAClD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,gBAAgB,CAAC,MAAW;QACxC,MAAM,cAAc,GAAG,MAAwB,CAAC;QAEhD,OAAO,cAAc,KAAK,SAAS,IAAI,cAAc,CAAC,IAAI,KAAK,SAAS,IAAI,cAAc,CAAC,MAAM,KAAK,SAAS;YACtG,cAAc,CAAC,MAAM,CAAC,cAAc,KAAK,0BAAc,CAAC,MAAM,CAAC;IAC1E,CAAC;CACF;AA7FD,wCA6FC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Metadata\r\n */\r\n\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from \"@itwin/core-quantity\";\r\nimport { Format } from \"./Format\";\r\nimport { InvertedUnit } from \"./InvertedUnit\";\r\nimport { Schema } from \"./Schema\";\r\nimport { Unit } from \"./Unit\";\r\n\r\n/**\r\n * Overrides of a Format, from a Schema, and is SchemaItem that is used specifically on KindOfQuantity.\r\n * @beta\r\n */\r\nexport class OverrideFormat {\r\n private _precision?: DecimalPrecision | FractionalPrecision;\r\n private _units?: Array<[Unit | InvertedUnit, string | undefined]>;\r\n\r\n /** The Format that this OverrideFormat is extending */\r\n public readonly parent: Format;\r\n\r\n /** The name of this OverrideFormat.\r\n *\r\n * This should be set to the [FormatString]($docs/bis/ec/kindofquantity/#format-string) which represents the format override.\r\n */\r\n public readonly name: string;\r\n\r\n constructor(parent: Format, precision?: DecimalPrecision | FractionalPrecision, unitAndLabels?: Array<[Unit | InvertedUnit, string | undefined]>) {\r\n this.parent = parent;\r\n this.name = OverrideFormat.createOverrideFormatFullName(parent, precision, unitAndLabels);\r\n this._precision = precision;\r\n this._units = unitAndLabels;\r\n }\r\n\r\n // Properties that can be overriden\r\n public get precision(): DecimalPrecision | FractionalPrecision { return (undefined === this._precision) ? this.parent.precision : this._precision; }\r\n public get units() { return (undefined === this._units) ? this.parent.units : this._units; }\r\n\r\n // Properties that cannot be overriden\r\n public get fullName(): string { return this.name; }\r\n public get roundFactor(): number { return this.parent.roundFactor; }\r\n public get type(): FormatType { return this.parent.type; }\r\n public get minWidth(): number | undefined { return this.parent.minWidth; }\r\n public get scientificType(): ScientificType | undefined { return this.parent.scientificType; }\r\n public get showSignOption(): ShowSignOption { return this.parent.showSignOption; }\r\n public get decimalSeparator(): string { return this.parent.decimalSeparator; }\r\n public get thousandSeparator(): string { return this.parent.thousandSeparator; }\r\n public get uomSeparator(): string { return this.parent.uomSeparator; }\r\n public get stationSeparator(): string { return this.parent.stationSeparator; }\r\n public get stationOffsetSize(): number | undefined { return this.parent.stationOffsetSize; }\r\n public get formatTraits(): FormatTraits { return this.parent.formatTraits; }\r\n public get spacer(): string | undefined { return this.parent.spacer; }\r\n public get includeZero(): boolean | undefined { return this.parent.includeZero; }\r\n\r\n public hasFormatTrait(formatTrait: FormatTraits) {\r\n return (this.parent.formatTraits & formatTrait) === formatTrait;\r\n }\r\n\r\n /** Returns the format string of this override in the Xml full name format.\r\n * @alpha\r\n */\r\n public fullNameXml(koqSchema: Schema): string {\r\n let fullName = XmlSerializationUtils.createXmlTypedName(koqSchema, this.parent.schema, this.parent.name);\r\n\r\n if (undefined !== this.precision)\r\n fullName += `(${this.precision.toString()})`;\r\n\r\n if (undefined === this._units)\r\n return fullName;\r\n for (const [unit, unitLabel] of this._units) {\r\n fullName += \"[\";\r\n fullName += XmlSerializationUtils.createXmlTypedName(koqSchema, unit.schema, unit.name);\r\n fullName += `|${unitLabel}]`;\r\n }\r\n return fullName;\r\n }\r\n\r\n /**\r\n * Creates a valid OverrideFormat fullName from the parent Format and overridden units.\r\n * @param parent The parent Format.\r\n * @param unitAndLabels The overridden unit and labels collection.\r\n */\r\n public static createOverrideFormatFullName(parent: Format, precision?: DecimalPrecision | FractionalPrecision, unitAndLabels?: Array<[Unit | InvertedUnit, string | undefined]>): string {\r\n let fullName = parent.fullName;\r\n\r\n if (precision)\r\n fullName += `(${precision.toString()})`;\r\n\r\n if (undefined === unitAndLabels)\r\n return fullName;\r\n for (const [unit, unitLabel] of unitAndLabels)\r\n if (undefined === unitLabel)\r\n fullName += `[${unit.fullName}]`;\r\n else\r\n fullName += `[${unit.fullName}|${unitLabel}]`;\r\n return fullName;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static isOverrideFormat(object: any): object is OverrideFormat {\r\n const overrideFormat = object as OverrideFormat;\r\n\r\n return overrideFormat !== undefined && overrideFormat.name !== undefined && overrideFormat.parent !== undefined &&\r\n overrideFormat.parent.schemaItemType === SchemaItemType.Format;\r\n }\r\n}\r\n"]}
|
|
@@ -31,6 +31,10 @@ export declare class Unit extends SchemaItem {
|
|
|
31
31
|
* @alpha
|
|
32
32
|
*/
|
|
33
33
|
static areCompatible(unitA: Unit, unitB: Unit): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* @alpha
|
|
36
|
+
*/
|
|
37
|
+
static isUnit(object: any): object is Unit;
|
|
34
38
|
/**
|
|
35
39
|
* Save this Unit's properties to an object for serializing to JSON.
|
|
36
40
|
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Unit.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Unit.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,oBAAoB,EAAE,o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|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @alpha
|
|
49
|
+
*/
|
|
50
|
+
static isUnit(object) {
|
|
51
|
+
return SchemaItem_1.SchemaItem.isSchemaItem(object) && object.schemaItemType === ECObjects_1.SchemaItemType.Unit;
|
|
52
|
+
}
|
|
47
53
|
/**
|
|
48
54
|
* Save this Unit's properties to an object for serializing to JSON.
|
|
49
55
|
* @param standalone Serialization includes only this object (as opposed to the full schema).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../../src/Metadata/Unit.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAK/D,6CAA0C;AAG1C;;;;GAIG;AACH,MAAa,IAAK,SAAQ,uBAAU;IASlC,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,IAAI,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAED,IAAW,UAAU,KAAuC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IACtF,IAAW,UAAU,KAAuC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IACtF,IAAW,UAAU,KAAa,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5D,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,IAAW,WAAW,KAAa,OAAO,IAAI,CA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AI,SAAS,KAAK,SAAS,CAAC,SAAS,EAAE;YACrC,IAAI,SAAS,CAAC,SAAS,KAAK,IAAI,CAAC,UAAU;gBACzC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC;SACzC;QAED,IAAI,SAAS,KAAK,SAAS,CAAC,WAAW,EAAE;YACvC,IAAI,SAAS,CAAC,WAAW,KAAK,IAAI,CAAC,YAAY;gBAC7C,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,WAAW,CAAC;SAC7C;QAED,IAAI,SAAS,KAAK,SAAS,CAAC,MAAM,EAAE;YAClC,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO;gBACnC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;SACnC;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,SAAoB;QACjD,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAgC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAgC;QAC5D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,UAAkB;QAC9C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;CACF;AA1JD,oBA0JC;AACD;;;GAGG;AACH,MAAsB,WAAY,SAAQ,IAAI;CAK7C;AALD,kCAKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Metadata\r\n */\r\n\r\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { UnitProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedPhenomenon, LazyLoadedUnitSystem } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { Phenomenon } from \"./Phenomenon\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { UnitSystem } from \"./UnitSystem\";\r\n\r\n/**\r\n * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a\r\n * first-class concept is to allow the iModel to not be dependent on any hard-coded Units\r\n * @beta\r\n */\r\nexport class Unit extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Unit; // eslint-disable-line\r\n protected _phenomenon?: LazyLoadedPhenomenon;\r\n protected _unitSystem?: LazyLoadedUnitSystem;\r\n protected _definition: string;\r\n protected _numerator: number;\r\n protected _denominator: number;\r\n protected _offset: number;\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Unit;\r\n this._definition = \"\";\r\n this._numerator = 1.0;\r\n this._denominator = 1.0;\r\n this._offset = 0.0;\r\n }\r\n\r\n public get phenomenon(): LazyLoadedPhenomenon | undefined { return this._phenomenon; }\r\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\r\n public get definition(): string { return this._definition; }\r\n public get numerator(): number { return this._numerator; }\r\n public get offset(): number { return this._offset; }\r\n public get denominator(): number { return this._denominator; }\r\n\r\n /**\r\n * Returns true if a conversion can be calculated between the input units\r\n * @alpha\r\n */\r\n public static async areCompatible(unitA: Unit, unitB: Unit): Promise<boolean> {\r\n const unitAPhenomenon = await unitA.phenomenon;\r\n const unitBPhenomenon = await unitB.phenomenon;\r\n\r\n if (!unitAPhenomenon || !unitBPhenomenon || !unitAPhenomenon.key.matches(unitBPhenomenon.key))\r\n return false;\r\n return true;\r\n }\r\n\r\n /**\r\n * Save this Unit's properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): UnitProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.phenomenon = this.phenomenon!.fullName;\r\n schemaJson.unitSystem = this.unitSystem!.fullName;\r\n schemaJson.definition = this.definition;\r\n if (undefined !== this.numerator)\r\n schemaJson.numerator = this.numerator;\r\n if (undefined !== this.denominator)\r\n schemaJson.denominator = this.denominator;\r\n if (undefined !== this.offset)\r\n schemaJson.offset = this.offset;\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n\r\n const phenomenon = await this.phenomenon;\r\n if (undefined !== phenomenon) {\r\n const phenomenonName = XmlSerializationUtils.createXmlTypedName(this.schema, phenomenon.schema, phenomenon.name);\r\n itemElement.setAttribute(\"phenomenon\", phenomenonName);\r\n }\r\n\r\n const unitSystem = await this.unitSystem;\r\n if (undefined !== unitSystem) {\r\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\r\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\r\n }\r\n\r\n itemElement.setAttribute(\"definition\", this.definition);\r\n itemElement.setAttribute(\"numerator\", this.numerator.toString());\r\n itemElement.setAttribute(\"denominator\", this.denominator.toString());\r\n itemElement.setAttribute(\"offset\", this.offset.toString());\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(unitProps: UnitProps) {\r\n super.fromJSONSync(unitProps);\r\n\r\n const phenomenonSchemaItemKey = this.schema.getSchemaItemKey(unitProps.phenomenon);\r\n if (!phenomenonSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n this._phenomenon = new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(phenomenonSchemaItemKey,\r\n async () => {\r\n const phenom = await this.schema.lookupItem<Phenomenon>(phenomenonSchemaItemKey);\r\n if (undefined === phenom)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n return phenom;\r\n });\r\n\r\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(unitProps.unitSystem);\r\n if (!unitSystemSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\r\n async () => {\r\n const unitSystem = await this.schema.lookupItem<UnitSystem>(unitSystemSchemaItemKey);\r\n if (undefined === unitSystem)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n return unitSystem;\r\n });\r\n\r\n if (this._definition !== \"\" && unitProps.definition.toLowerCase() !== this._definition.toLowerCase())\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this.name} has an invalid 'definition' attribute.`);\r\n else if (this._definition === \"\")\r\n this._definition = unitProps.definition;\r\n\r\n if (undefined !== unitProps.numerator) {\r\n if (unitProps.numerator !== this._numerator)\r\n this._numerator = unitProps.numerator;\r\n }\r\n\r\n if (undefined !== unitProps.denominator) {\r\n if (unitProps.denominator !== this._denominator)\r\n this._denominator = unitProps.denominator;\r\n }\r\n\r\n if (undefined !== unitProps.offset) {\r\n if (unitProps.offset !== this._offset)\r\n this._offset = unitProps.offset;\r\n }\r\n }\r\n\r\n public override async fromJSON(unitProps: UnitProps) {\r\n this.fromJSONSync(unitProps);\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setPhenomenon(phenomenon: LazyLoadedPhenomenon) {\r\n this._phenomenon = phenomenon;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\r\n this._unitSystem = unitSystem;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setDefinition(definition: string) {\r\n this._definition = definition;\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableUnit extends Unit {\r\n public abstract override setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;\r\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;\r\n public abstract override setDefinition(definition: string): Promise<void>;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../../src/Metadata/Unit.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA8C;AAC9C,4CAA+D;AAK/D,6CAA0C;AAG1C;;;;GAIG;AACH,MAAa,IAAK,SAAQ,uBAAU;IASlC,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,IAAI,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAED,IAAW,UAAU,KAAuC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IACtF,IAAW,UAAU,KAAuC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IACtF,IAAW,UAAU,KAAa,OAAO,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C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;CACF;AAjKD,oBAiKC;AACD;;;GAGG;AACH,MAAsB,WAAY,SAAQ,IAAI;CAK7C;AALD,kCAKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Metadata\r\n */\r\n\r\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { UnitProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedPhenomenon, LazyLoadedUnitSystem } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { Phenomenon } from \"./Phenomenon\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { UnitSystem } from \"./UnitSystem\";\r\n\r\n/**\r\n * An abstract class that adds the ability to define Units and everything that goes with them, within an ECSchema as a\r\n * first-class concept is to allow the iModel to not be dependent on any hard-coded Units\r\n * @beta\r\n */\r\nexport class Unit extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Unit; // eslint-disable-line\r\n protected _phenomenon?: LazyLoadedPhenomenon;\r\n protected _unitSystem?: LazyLoadedUnitSystem;\r\n protected _definition: string;\r\n protected _numerator: number;\r\n protected _denominator: number;\r\n protected _offset: number;\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Unit;\r\n this._definition = \"\";\r\n this._numerator = 1.0;\r\n this._denominator = 1.0;\r\n this._offset = 0.0;\r\n }\r\n\r\n public get phenomenon(): LazyLoadedPhenomenon | undefined { return this._phenomenon; }\r\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\r\n public get definition(): string { return this._definition; }\r\n public get numerator(): number { return this._numerator; }\r\n public get offset(): number { return this._offset; }\r\n public get denominator(): number { return this._denominator; }\r\n\r\n /**\r\n * Returns true if a conversion can be calculated between the input units\r\n * @alpha\r\n */\r\n public static async areCompatible(unitA: Unit, unitB: Unit): Promise<boolean> {\r\n const unitAPhenomenon = await unitA.phenomenon;\r\n const unitBPhenomenon = await unitB.phenomenon;\r\n\r\n if (!unitAPhenomenon || !unitBPhenomenon || !unitAPhenomenon.key.matches(unitBPhenomenon.key))\r\n return false;\r\n return true;\r\n }\r\n\r\n /**\r\n * @alpha\r\n */\r\n public static isUnit(object: any): object is Unit {\r\n return SchemaItem.isSchemaItem(object) && object.schemaItemType === SchemaItemType.Unit;\r\n }\r\n\r\n /**\r\n * Save this Unit's properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): UnitProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.phenomenon = this.phenomenon!.fullName;\r\n schemaJson.unitSystem = this.unitSystem!.fullName;\r\n schemaJson.definition = this.definition;\r\n if (undefined !== this.numerator)\r\n schemaJson.numerator = this.numerator;\r\n if (undefined !== this.denominator)\r\n schemaJson.denominator = this.denominator;\r\n if (undefined !== this.offset)\r\n schemaJson.offset = this.offset;\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n\r\n const phenomenon = await this.phenomenon;\r\n if (undefined !== phenomenon) {\r\n const phenomenonName = XmlSerializationUtils.createXmlTypedName(this.schema, phenomenon.schema, phenomenon.name);\r\n itemElement.setAttribute(\"phenomenon\", phenomenonName);\r\n }\r\n\r\n const unitSystem = await this.unitSystem;\r\n if (undefined !== unitSystem) {\r\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\r\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\r\n }\r\n\r\n itemElement.setAttribute(\"definition\", this.definition);\r\n itemElement.setAttribute(\"numerator\", this.numerator.toString());\r\n itemElement.setAttribute(\"denominator\", this.denominator.toString());\r\n itemElement.setAttribute(\"offset\", this.offset.toString());\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(unitProps: UnitProps) {\r\n super.fromJSONSync(unitProps);\r\n\r\n const phenomenonSchemaItemKey = this.schema.getSchemaItemKey(unitProps.phenomenon);\r\n if (!phenomenonSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n this._phenomenon = new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(phenomenonSchemaItemKey,\r\n async () => {\r\n const phenom = await this.schema.lookupItem<Phenomenon>(phenomenonSchemaItemKey);\r\n if (undefined === phenom)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the phenomenon ${unitProps.phenomenon}.`);\r\n return phenom;\r\n });\r\n\r\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(unitProps.unitSystem);\r\n if (!unitSystemSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\r\n async () => {\r\n const unitSystem = await this.schema.lookupItem<UnitSystem>(unitSystemSchemaItemKey);\r\n if (undefined === unitSystem)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${unitProps.unitSystem}.`);\r\n return unitSystem;\r\n });\r\n\r\n if (this._definition !== \"\" && unitProps.definition.toLowerCase() !== this._definition.toLowerCase())\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Unit ${this.name} has an invalid 'definition' attribute.`);\r\n else if (this._definition === \"\")\r\n this._definition = unitProps.definition;\r\n\r\n if (undefined !== unitProps.numerator) {\r\n if (unitProps.numerator !== this._numerator)\r\n this._numerator = unitProps.numerator;\r\n }\r\n\r\n if (undefined !== unitProps.denominator) {\r\n if (unitProps.denominator !== this._denominator)\r\n this._denominator = unitProps.denominator;\r\n }\r\n\r\n if (undefined !== unitProps.offset) {\r\n if (unitProps.offset !== this._offset)\r\n this._offset = unitProps.offset;\r\n }\r\n }\r\n\r\n public override async fromJSON(unitProps: UnitProps) {\r\n this.fromJSONSync(unitProps);\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setPhenomenon(phenomenon: LazyLoadedPhenomenon) {\r\n this._phenomenon = phenomenon;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\r\n this._unitSystem = unitSystem;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing.\r\n */\r\n protected async setDefinition(definition: string) {\r\n this._definition = definition;\r\n }\r\n}\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableUnit extends Unit {\r\n public abstract override setPhenomenon(phenomenon: LazyLoadedPhenomenon): Promise<void>;\r\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): Promise<void>;\r\n public abstract override setDefinition(definition: string): Promise<void>;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
|
|
@@ -2,12 +2,11 @@ import { Constant } from "../Metadata/Constant";
|
|
|
2
2
|
import { Unit } from "../Metadata/Unit";
|
|
3
3
|
/**
|
|
4
4
|
* Class used for storing calculated conversion between two Units [[UnitConverter.calculateConversion]] and converting values from one Unit to another [[UnitConverter.evaluate]]
|
|
5
|
-
* @
|
|
5
|
+
* @internal
|
|
6
6
|
*/
|
|
7
7
|
export declare class UnitConversion {
|
|
8
8
|
readonly factor: number;
|
|
9
9
|
readonly offset: number;
|
|
10
|
-
/** @internal */
|
|
11
10
|
constructor(factor?: number, offset?: number);
|
|
12
11
|
/**
|
|
13
12
|
* Converts x using UnitConversion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnitConversion.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConversion.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC;;;GAGG;AACH,qBAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"UnitConversion.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConversion.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC;;;GAGG;AACH,qBAAa,cAAc;aACG,MAAM,EAAE,MAAM;aAAwB,MAAM,EAAE,MAAM;gBAApD,MAAM,GAAE,MAAY,EAAkB,MAAM,GAAE,MAAY;IAEtF;;;;OAIG;IACI,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAIlC;;;OAGG;IACI,OAAO,IAAI,cAAc;IAKhC;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc;IAO1D;;;OAGG;IACI,QAAQ,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc;IAO3D;;;OAGG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc;IAY3C,gBAAgB;IAChB,OAAc,QAAQ,iBAAwB;IAE9C;;;OAGG;WACW,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,QAAQ,GAAG,cAAc;CAM1D"}
|
|
@@ -9,10 +9,9 @@ const almostEqual = require("almost-equal");
|
|
|
9
9
|
const ECObjects_1 = require("../ECObjects");
|
|
10
10
|
/**
|
|
11
11
|
* Class used for storing calculated conversion between two Units [[UnitConverter.calculateConversion]] and converting values from one Unit to another [[UnitConverter.evaluate]]
|
|
12
|
-
* @
|
|
12
|
+
* @internal
|
|
13
13
|
*/
|
|
14
14
|
class UnitConversion {
|
|
15
|
-
/** @internal */
|
|
16
15
|
constructor(factor = 1.0, offset = 0.0) {
|
|
17
16
|
this.factor = factor;
|
|
18
17
|
this.offset = offset;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnitConversion.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConversion.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,4CAA4C;AAG5C,4CAA8C;AAE9C;;;GAGG;AACH,MAAa,cAAc;IACzB,
|
|
1
|
+
{"version":3,"file":"UnitConversion.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConversion.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,4CAA4C;AAG5C,4CAA8C;AAE9C;;;GAGG;AACH,MAAa,cAAc;IACzB,YAA4B,SAAiB,GAAG,EAAkB,SAAiB,GAAG;QAA1D,WAAM,GAAN,MAAM,CAAc;QAAkB,WAAM,GAAN,MAAM,CAAc;IAAG,CAAC;IAE1F;;;;OAIG;IACI,QAAQ,CAAC,CAAS;QACvB,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,MAAM,aAAa,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;QACxC,OAAO,IAAI,cAAc,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC;IACzE,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,UAA0B;QACvC,OAAO,IAAI,cAAc,CACvB,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,EAC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H,wCAyEC;AAbC,gBAAgB;AACF,uBAAQ,GAAG,IAAI,cAAc,EAAE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport * as almostEqual from \"almost-equal\";\r\nimport { Constant } from \"../Metadata/Constant\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\n\r\n/**\r\n * Class used for storing calculated conversion between two Units [[UnitConverter.calculateConversion]] and converting values from one Unit to another [[UnitConverter.evaluate]]\r\n * @internal\r\n */\r\nexport class UnitConversion {\r\n constructor(public readonly factor: number = 1.0, public readonly offset: number = 0.0) {}\r\n\r\n /**\r\n * Converts x using UnitConversion\r\n * @param x Input magnitude to be converted\r\n * @returns Output magnitude after conversion\r\n */\r\n public evaluate(x: number): number {\r\n return this.factor * x + this.offset;\r\n }\r\n\r\n /**\r\n * Used to invert source's UnitConversion so that it can be composed with target's UnitConversion cleanly\r\n * @internal\r\n */\r\n public inverse(): UnitConversion {\r\n const inverseFactor = 1.0 / this.factor;\r\n return new UnitConversion(inverseFactor, -this.offset * inverseFactor);\r\n }\r\n\r\n /**\r\n * Combines two UnitConversions\r\n * Used to combine source's UnitConversion and target's UnitConversion for a final UnitConversion that can be evaluated\r\n * @internal\r\n */\r\n public compose(conversion: UnitConversion): UnitConversion {\r\n return new UnitConversion(\r\n this.factor * conversion.factor,\r\n conversion.factor * this.offset + conversion.offset\r\n );\r\n }\r\n\r\n /**\r\n * Multiples two UnitConversions together to calculate factor during reducing\r\n * @internal\r\n */\r\n public multiply(conversion: UnitConversion): UnitConversion {\r\n if (almostEqual(conversion.offset, 0.0) && almostEqual(this.offset, 0.0))\r\n return new UnitConversion(this.factor * conversion.factor, 0.0);\r\n\r\n throw new Error(\"Cannot multiply two maps with non-zero offsets\");\r\n }\r\n\r\n /**\r\n * Raise UnitConversion's factor with power exponent to calculate factor during reducing\r\n * @internal\r\n */\r\n public raise(power: number): UnitConversion {\r\n if (almostEqual(power, 1.0))\r\n return new UnitConversion(this.factor, this.offset);\r\n else if (almostEqual(power, 0.0))\r\n return new UnitConversion(1.0, 0.0);\r\n\r\n if (almostEqual(this.offset, 0.0))\r\n return new UnitConversion(this.factor ** power, 0.0);\r\n\r\n throw new Error(\"Cannot raise map with non-zero offset\");\r\n }\r\n\r\n /** @internal */\r\n public static identity = new UnitConversion();\r\n\r\n /**\r\n * Returns UnitConversion with unit's numerator and denominator in factor and unit's offset in offset for reducing\r\n * @internal\r\n */\r\n public static from(unit: Unit | Constant): UnitConversion {\r\n if (unit.schemaItemType === SchemaItemType.Unit)\r\n return new UnitConversion(unit.denominator / unit.numerator, -unit.offset);\r\n\r\n return new UnitConversion(unit.denominator / unit.numerator, 0.0);\r\n }\r\n}\r\n"]}
|
|
@@ -2,7 +2,7 @@ import { SchemaContext } from "../Context";
|
|
|
2
2
|
import { UnitConversion } from "./UnitConversion";
|
|
3
3
|
/**
|
|
4
4
|
* Class constructed with SchemaContext and used to calculate [[UnitConversion]] between Units
|
|
5
|
-
* @
|
|
5
|
+
* @internal
|
|
6
6
|
*/
|
|
7
7
|
export declare class UnitConverter {
|
|
8
8
|
private readonly _context;
|
|
@@ -13,7 +13,7 @@ const UnitConversion_1 = require("./UnitConversion");
|
|
|
13
13
|
const UnitTree_1 = require("./UnitTree");
|
|
14
14
|
/**
|
|
15
15
|
* Class constructed with SchemaContext and used to calculate [[UnitConversion]] between Units
|
|
16
|
-
* @
|
|
16
|
+
* @internal
|
|
17
17
|
*/
|
|
18
18
|
class UnitConverter {
|
|
19
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnitConverter.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConverter.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAkE;AAGlE,uDAAoD;AACpD,2CAAwC;A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GAAG,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAC5E,2BAA2B;gBAC3B,OAAO,KAAK,CAAC;aACd;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjHD,sCAiHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { BentleyError, BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { SchemaContext } from \"../Context\";\r\nimport { Constant } from \"../Metadata/Constant\";\r\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaKey } from \"../SchemaKey\";\r\nimport { UnitConversion } from \"./UnitConversion\";\r\nimport { UnitGraph } from \"./UnitTree\";\r\n\r\n/**\r\n * Class constructed with SchemaContext and used to calculate [[UnitConversion]] between Units\r\n * @
|
|
1
|
+
{"version":3,"file":"UnitConverter.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConverter.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAkE;AAGlE,uDAAoD;AACpD,2CAAwC;AACxC,4CAAyC;AACzC,qDAAkD;AAClD,yCAAuC;AAEvC;;;GAGG;AACH,MAAa,aAAa;IAGxB;;;OAGG;IACH,YAA6B,QAAuB;QAAvB,aAAQ,GAAR,QAAQ,CAAe;QAClD,IAAI,CAAC,OAAO,GAAG,IAAI,oBAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,mBAAmB,CAAC,QAAgB,EAAE,MAAc;QAC/D,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAAC,GAAG,uBAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChF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;OAKG;IACK,mBAAmB,CAAC,aAAkC,EAAE,WAAgC;QAC9F,qGAAqG;QACrG,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,aAAa,CAAC,OAAO,EAAE,EAAE;YAClD,MAAM,CAAC,EAAE,cAAc,CAAC,GAAG,uBAAU,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YACzD,IAAI,cAAc,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC,EAAE;gBAC3C,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;aAC3B;SACF;QAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE;YAChD,MAAM,CAAC,EAAE,cAAc,CAAC,GAAG,uBAAU,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YACzD,IAAI,cAAc,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC,EAAE;gBAC3C,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;aACzB;SACF;QAED,IAAI,aAAa,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI;YACzC,OAAO,KAAK,CAAC;QAEf,KAAK,MAAM,GAAG,IAAI,aAAa,CAAC,IAAI,EAAE,EAAE;YACtC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAC5E,2BAA2B;gBAC3B,OAAO,KAAK,CAAC;aACd;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjHD,sCAiHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { BentleyError, BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { SchemaContext } from \"../Context\";\r\nimport { Constant } from \"../Metadata/Constant\";\r\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaKey } from \"../SchemaKey\";\r\nimport { UnitConversion } from \"./UnitConversion\";\r\nimport { UnitGraph } from \"./UnitTree\";\r\n\r\n/**\r\n * Class constructed with SchemaContext and used to calculate [[UnitConversion]] between Units\r\n * @internal\r\n */\r\nexport class UnitConverter {\r\n private _uGraph: UnitGraph;\r\n\r\n /**\r\n * Create Converter context\r\n * @param _context SchemaContext with contexts added to it.\r\n */\r\n constructor(private readonly _context: SchemaContext) {\r\n this._uGraph = new UnitGraph(this._context);\r\n }\r\n\r\n /**\r\n * Find conversion between from and to units, formatted {schemaName}.{schemaItemName} or {schemaName}:{schemaItemName}\r\n * @param fromUnit SchemaItem full name of source unit\r\n * @param toUnit SchemaItem full name of target unit\r\n * @returns [[UnitConversion]] converting fromUnit -> toUnit with a factor and an offset\r\n * @throws Error if from and to Units' SchemaItem is not found in Schema or Schema prefix is not found in SchemaContext\r\n * @throws Error if from and to Units do not belong to the same phenomenon\r\n * @throws Error if definitions' SchemaItems cannot be found in its own or referenced Schemas\r\n * @throws Error if base units of source and target unit do not match\r\n */\r\n public async calculateConversion(fromUnit: string, toUnit: string): Promise<UnitConversion> {\r\n const [fromSchemaName, fromSchemaItemName] = SchemaItem.parseFullName(fromUnit);\r\n const [toSchemaName, toSchemaItemName] = SchemaItem.parseFullName(toUnit);\r\n const fromSchemaKey = new SchemaKey(fromSchemaName);\r\n const toSchemaKey = new SchemaKey(toSchemaName);\r\n\r\n const fromSchema = await this._context.getSchema(fromSchemaKey);\r\n const toSchema = await this._context.getSchema(toSchemaKey);\r\n\r\n if (!fromSchema || !toSchema) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find from's and/or to's schema\", () => {\r\n return { from: fromUnit, fromSchema: fromSchemaName, to: toUnit, toSchema: toSchemaName };\r\n });\r\n }\r\n\r\n const from = await this._uGraph.resolveUnit(fromSchemaItemName, fromSchema);\r\n const to = await this._uGraph.resolveUnit(toSchemaItemName, toSchema);\r\n\r\n return this.processUnits(from, to);\r\n }\r\n\r\n /**\r\n * @param from Source unit converted from\r\n * @param to Target unit converted to\r\n * @internal\r\n */\r\n private async processUnits(from: Unit | Constant, to: Unit | Constant): Promise<UnitConversion> {\r\n if (from.key.matches(to.key)) return UnitConversion.identity;\r\n\r\n const areCompatible = await Unit.areCompatible(from as Unit, to as Unit);\r\n if (!areCompatible)\r\n throw new BentleyError(BentleyStatus.ERROR, `Source and target units do not belong to same phenomenon`, () => {\r\n return { from, to };\r\n });\r\n\r\n // Add nodes and subsequent children to graph\r\n await this._uGraph.addUnit(from);\r\n await this._uGraph.addUnit(to);\r\n\r\n const fromBaseUnits = new Map<string, number>();\r\n const toBaseUnits = new Map<string, number>();\r\n // Calculate map of UnitConversions to get between from -> base\r\n const fromMapStore = this._uGraph.reduce(from, fromBaseUnits);\r\n // Calculate map of UnitConversions to get between base -> to\r\n const toMapStore = this._uGraph.reduce(to, toBaseUnits);\r\n\r\n if (!this.checkBaseUnitsMatch(fromBaseUnits, toBaseUnits))\r\n throw new BentleyError(BentleyStatus.ERROR, `Source and target units do not have matching base units`, () => {\r\n return { from, to };\r\n });\r\n\r\n // Final calculations to get singular UnitConversion between from -> to\r\n const fromMap = fromMapStore.get(from.key.fullName) || UnitConversion.identity;\r\n const toMap = toMapStore.get(to.key.fullName) || UnitConversion.identity;\r\n const fromInverse = fromMap.inverse();\r\n return fromInverse.compose(toMap);\r\n }\r\n\r\n /**\r\n * Check if fromBaseUnits's base units and exponents matches toBaseUnits's\r\n * @param fromBaseUnits Map of base units for source unit\r\n * @param toBaseUnits Map of base units for target unit\r\n * @internal\r\n */\r\n private checkBaseUnitsMatch(fromBaseUnits: Map<string, number>, toBaseUnits: Map<string, number>): boolean {\r\n // Trim maps of \"One\" and value that equal zero as they do not affect the base units and calculations\r\n for (const [key, value] of fromBaseUnits.entries()) {\r\n const [, schemaItemName] = SchemaItem.parseFullName(key);\r\n if (schemaItemName === \"ONE\" || value === 0) {\r\n fromBaseUnits.delete(key);\r\n }\r\n }\r\n\r\n for (const [key, value] of toBaseUnits.entries()) {\r\n const [, schemaItemName] = SchemaItem.parseFullName(key);\r\n if (schemaItemName === \"ONE\" || value === 0) {\r\n toBaseUnits.delete(key);\r\n }\r\n }\r\n\r\n if (fromBaseUnits.size !== toBaseUnits.size)\r\n return false;\r\n\r\n for (const key of fromBaseUnits.keys()) {\r\n if (!toBaseUnits.has(key) || fromBaseUnits.get(key) !== toBaseUnits.get(key)) {\r\n // Mismatching key or value\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { UnitConversion, UnitExtraData, UnitProps, UnitsProvider } from "@itwin/core-quantity";
|
|
2
|
+
import { ISchemaLocater } from "../Context";
|
|
3
|
+
/**
|
|
4
|
+
* Class used to find Units in SchemaContext by attributes such as Phenomenon and DisplayLabel.
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export declare class SchemaUnitProvider implements UnitsProvider {
|
|
8
|
+
private _unitExtraData;
|
|
9
|
+
private _unitConverter;
|
|
10
|
+
private _context;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param contextOrLocater The SchemaContext or a different ISchemaLocater implementation used to retrieve the schema. The SchemaContext
|
|
14
|
+
* class implements the ISchemaLocater interface. If the provided locater is not a SchemaContext instance a new SchemaContext will be
|
|
15
|
+
* created and the locater will be added.
|
|
16
|
+
* @param _unitExtraData Additional data like alternate display label not found in Units Schema to match with Units; Defaults to empty array.
|
|
17
|
+
*/
|
|
18
|
+
constructor(contextOrLocater: ISchemaLocater, _unitExtraData?: UnitExtraData[]);
|
|
19
|
+
/**
|
|
20
|
+
* Find unit in a schema that has unitName.
|
|
21
|
+
* @param unitName Full name of unit.
|
|
22
|
+
* @returns UnitProps interface from @itwin/core-quantity whose name matches unitName.
|
|
23
|
+
*/
|
|
24
|
+
findUnitByName(unitName: string): Promise<UnitProps>;
|
|
25
|
+
/**
|
|
26
|
+
* Find all units in context that belongs to given phenomenon.
|
|
27
|
+
* @param phenomenon Full name of phenomenon.
|
|
28
|
+
* @returns Array of UnitProps (from @itwin/core-quantity) interface objects whose name matches phenomenon param.
|
|
29
|
+
*/
|
|
30
|
+
getUnitsByFamily(phenomenon: string): Promise<Array<UnitProps>>;
|
|
31
|
+
/**
|
|
32
|
+
* Find alternate display labels associated with unitName, if any.
|
|
33
|
+
* @param unitName Full name of Unit.
|
|
34
|
+
*/
|
|
35
|
+
getAlternateDisplayLabels(unitName: string): Array<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Finds Unit by unitLabel, which could be a display label in the schema or alternate an display label defined in
|
|
38
|
+
* this._unitExtraData. If there are duplicates of the same display label in the context or teh same alternate display
|
|
39
|
+
* labels, specify schemaName, phenomenon, or unitSystem to get a specific unit.
|
|
40
|
+
*
|
|
41
|
+
* @param unitLabel Display label or alternate display label to query unit by.
|
|
42
|
+
* @param schemaName Ensure Unit with unitLabel belongs to Schema with schemaName.
|
|
43
|
+
* @param phenomenon Full name of phenomenon that Unit belongs to.
|
|
44
|
+
* @param unitSystem Full name of unitSystem that Unit belongs to.
|
|
45
|
+
* @returns The UnitProps interface from the @itwin/core-quantity package.
|
|
46
|
+
*/
|
|
47
|
+
findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the @itwin/core-quantity UnitConversion for the given fromUnit and toUnit.
|
|
50
|
+
* @param fromUnit The UnitProps of the 'from' unit.
|
|
51
|
+
* @param toUnit The UnitProps of the 'to' unit.
|
|
52
|
+
* @returns The UnitConversion interface from the @itwin/core-quantity package.
|
|
53
|
+
*/
|
|
54
|
+
getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversion>;
|
|
55
|
+
/**
|
|
56
|
+
* Find unit in a schema that has unitName.
|
|
57
|
+
* @param unitName Full name of unit.
|
|
58
|
+
* @returns Unit whose full name matches unitName.
|
|
59
|
+
*/
|
|
60
|
+
private findECUnitByName;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the @itwin/core UnitProps for the given Unit.
|
|
63
|
+
* @param unit The Unit to convert.
|
|
64
|
+
* @returns UnitProps interface from @itwin/core.
|
|
65
|
+
*/
|
|
66
|
+
private getUnitsProps;
|
|
67
|
+
/**
|
|
68
|
+
* Finds Unit by displayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
private findUnitByDisplayLabel;
|
|
72
|
+
/**
|
|
73
|
+
* Finds Unit by altDisplayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
private findUnitByAltDisplayLabel;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=SchemaUnitProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaUnitProvider.d.ts","sourceRoot":"","sources":["../../../src/UnitProvider/SchemaUnitProvider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAC;AAO3D;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IAWR,OAAO,CAAC,cAAc;IAVpE,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAgB;IAEhC;;;;;;OAMG;gBACS,gBAAgB,EAAE,cAAc,EAAU,cAAc,GAAE,aAAa,EAAO;IAU1F;;;;OAIG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAKjE;;;;OAIG;IACU,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IA0C5E;;;OAGG;IACI,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAWjE;;;;;;;;;;OAUG;IACU,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;IAuB3H;;;;;OAKG;IACU,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC;IAQ3F;;;;OAIG;YACW,gBAAgB;IA2B9B;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAUrB;;;OAGG;YACW,sBAAsB;IAoBpC;;;OAGG;YACW,yBAAyB;CAoBxC"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaUnitProvider = void 0;
|
|
4
|
+
/*---------------------------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
9
|
+
const Context_1 = require("../Context");
|
|
10
|
+
const SchemaItem_1 = require("../Metadata/SchemaItem");
|
|
11
|
+
const SchemaKey_1 = require("../SchemaKey");
|
|
12
|
+
const Unit_1 = require("../Metadata/Unit");
|
|
13
|
+
const ECObjects_1 = require("../ECObjects");
|
|
14
|
+
const UnitConverter_1 = require("../UnitConversion/UnitConverter");
|
|
15
|
+
/**
|
|
16
|
+
* Class used to find Units in SchemaContext by attributes such as Phenomenon and DisplayLabel.
|
|
17
|
+
* @alpha
|
|
18
|
+
*/
|
|
19
|
+
class SchemaUnitProvider {
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param contextOrLocater The SchemaContext or a different ISchemaLocater implementation used to retrieve the schema. The SchemaContext
|
|
23
|
+
* class implements the ISchemaLocater interface. If the provided locater is not a SchemaContext instance a new SchemaContext will be
|
|
24
|
+
* created and the locater will be added.
|
|
25
|
+
* @param _unitExtraData Additional data like alternate display label not found in Units Schema to match with Units; Defaults to empty array.
|
|
26
|
+
*/
|
|
27
|
+
constructor(contextOrLocater, _unitExtraData = []) {
|
|
28
|
+
this._unitExtraData = _unitExtraData;
|
|
29
|
+
if (contextOrLocater instanceof Context_1.SchemaContext) {
|
|
30
|
+
this._context = contextOrLocater;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this._context = new Context_1.SchemaContext();
|
|
34
|
+
this._context.addLocater(contextOrLocater);
|
|
35
|
+
}
|
|
36
|
+
this._unitConverter = new UnitConverter_1.UnitConverter(this._context);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Find unit in a schema that has unitName.
|
|
40
|
+
* @param unitName Full name of unit.
|
|
41
|
+
* @returns UnitProps interface from @itwin/core-quantity whose name matches unitName.
|
|
42
|
+
*/
|
|
43
|
+
async findUnitByName(unitName) {
|
|
44
|
+
const unit = await this.findECUnitByName(unitName);
|
|
45
|
+
return this.getUnitsProps(unit);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Find all units in context that belongs to given phenomenon.
|
|
49
|
+
* @param phenomenon Full name of phenomenon.
|
|
50
|
+
* @returns Array of UnitProps (from @itwin/core-quantity) interface objects whose name matches phenomenon param.
|
|
51
|
+
*/
|
|
52
|
+
async getUnitsByFamily(phenomenon) {
|
|
53
|
+
// Check if schema exists and phenomenon exists in schema
|
|
54
|
+
const [schemaName, schemaItemName] = SchemaItem_1.SchemaItem.parseFullName(phenomenon);
|
|
55
|
+
const schemaKey = new SchemaKey_1.SchemaKey(schemaName);
|
|
56
|
+
const schema = await this._context.getSchema(schemaKey);
|
|
57
|
+
if (!schema) {
|
|
58
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find schema for phenomenon", () => {
|
|
59
|
+
return { phenomenon, schema: schemaName };
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const itemKey = new SchemaKey_1.SchemaItemKey(schemaItemName, schema.schemaKey);
|
|
63
|
+
const phenom = await this._context.getSchemaItem(itemKey);
|
|
64
|
+
if (!phenom)
|
|
65
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find schema item/phenomenon", () => {
|
|
66
|
+
return { item: schemaItemName, schema: schemaName };
|
|
67
|
+
});
|
|
68
|
+
if (phenom.schemaItemType !== ECObjects_1.SchemaItemType.Phenomenon)
|
|
69
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Item is not a phenomenon", () => {
|
|
70
|
+
return { itemType: phenom.key.fullName };
|
|
71
|
+
});
|
|
72
|
+
// Find units' full name that match given phenomenon param.
|
|
73
|
+
const filteredUnits = [];
|
|
74
|
+
const schemaItems = this._context.getSchemaItems();
|
|
75
|
+
let { value, done } = schemaItems.next();
|
|
76
|
+
while (!done) {
|
|
77
|
+
if (Unit_1.Unit.isUnit(value)) {
|
|
78
|
+
const foundPhenomenon = await value.phenomenon;
|
|
79
|
+
if (foundPhenomenon && foundPhenomenon.key.matchesFullName(phenomenon)) {
|
|
80
|
+
const unitProps = this.getUnitsProps(value);
|
|
81
|
+
filteredUnits.push(unitProps);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
({ value, done } = schemaItems.next());
|
|
85
|
+
}
|
|
86
|
+
return filteredUnits;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Find alternate display labels associated with unitName, if any.
|
|
90
|
+
* @param unitName Full name of Unit.
|
|
91
|
+
*/
|
|
92
|
+
getAlternateDisplayLabels(unitName) {
|
|
93
|
+
let alternateLabels = [];
|
|
94
|
+
for (const entry of this._unitExtraData) {
|
|
95
|
+
if (entry.name.toLowerCase() === unitName.toLowerCase()) {
|
|
96
|
+
alternateLabels = entry.altDisplayLabels;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return alternateLabels;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Finds Unit by unitLabel, which could be a display label in the schema or alternate an display label defined in
|
|
103
|
+
* this._unitExtraData. If there are duplicates of the same display label in the context or teh same alternate display
|
|
104
|
+
* labels, specify schemaName, phenomenon, or unitSystem to get a specific unit.
|
|
105
|
+
*
|
|
106
|
+
* @param unitLabel Display label or alternate display label to query unit by.
|
|
107
|
+
* @param schemaName Ensure Unit with unitLabel belongs to Schema with schemaName.
|
|
108
|
+
* @param phenomenon Full name of phenomenon that Unit belongs to.
|
|
109
|
+
* @param unitSystem Full name of unitSystem that Unit belongs to.
|
|
110
|
+
* @returns The UnitProps interface from the @itwin/core-quantity package.
|
|
111
|
+
*/
|
|
112
|
+
async findUnit(unitLabel, schemaName, phenomenon, unitSystem) {
|
|
113
|
+
const findLabel = unitLabel.toLowerCase();
|
|
114
|
+
const findSchema = schemaName ? schemaName.toLowerCase() : undefined;
|
|
115
|
+
const findPhenomenon = phenomenon ? phenomenon.toLowerCase() : undefined;
|
|
116
|
+
const findUnitSystem = unitSystem ? unitSystem.toLowerCase() : undefined;
|
|
117
|
+
let foundUnit;
|
|
118
|
+
try {
|
|
119
|
+
try {
|
|
120
|
+
foundUnit = await this.findUnitByDisplayLabel(findLabel, findSchema, findPhenomenon, findUnitSystem);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
// If there is no Unit with display label that matches label, then check for alternate display labels that may match
|
|
124
|
+
foundUnit = await this.findUnitByAltDisplayLabel(findLabel, findSchema, findPhenomenon, findUnitSystem);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find unit with label", () => {
|
|
129
|
+
return { unitLabel };
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return this.getUnitsProps(foundUnit);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gets the @itwin/core-quantity UnitConversion for the given fromUnit and toUnit.
|
|
136
|
+
* @param fromUnit The UnitProps of the 'from' unit.
|
|
137
|
+
* @param toUnit The UnitProps of the 'to' unit.
|
|
138
|
+
* @returns The UnitConversion interface from the @itwin/core-quantity package.
|
|
139
|
+
*/
|
|
140
|
+
async getConversion(fromUnit, toUnit) {
|
|
141
|
+
const conversion = await this._unitConverter.calculateConversion(fromUnit.name, toUnit.name);
|
|
142
|
+
return {
|
|
143
|
+
factor: conversion.factor,
|
|
144
|
+
offset: conversion.offset,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Find unit in a schema that has unitName.
|
|
149
|
+
* @param unitName Full name of unit.
|
|
150
|
+
* @returns Unit whose full name matches unitName.
|
|
151
|
+
*/
|
|
152
|
+
async findECUnitByName(unitName) {
|
|
153
|
+
// Check if schema exists and unit exists in schema
|
|
154
|
+
const [schemaName, schemaItemName] = SchemaItem_1.SchemaItem.parseFullName(unitName);
|
|
155
|
+
const schemaKey = new SchemaKey_1.SchemaKey(schemaName);
|
|
156
|
+
const schema = await this._context.getSchema(schemaKey);
|
|
157
|
+
if (!schema) {
|
|
158
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find schema for unit", () => {
|
|
159
|
+
return { schema: schemaName, unit: unitName };
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
const itemKey = new SchemaKey_1.SchemaItemKey(schemaItemName, schema.schemaKey);
|
|
163
|
+
const item = await this._context.getSchemaItem(itemKey);
|
|
164
|
+
if (!item)
|
|
165
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find schema item/unit", () => {
|
|
166
|
+
return { item: schemaItemName, schema: schemaName };
|
|
167
|
+
});
|
|
168
|
+
if (item.schemaItemType === ECObjects_1.SchemaItemType.Unit)
|
|
169
|
+
return item;
|
|
170
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Item is not a unit", () => {
|
|
171
|
+
return { itemType: item.key.fullName };
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Gets the @itwin/core UnitProps for the given Unit.
|
|
176
|
+
* @param unit The Unit to convert.
|
|
177
|
+
* @returns UnitProps interface from @itwin/core.
|
|
178
|
+
*/
|
|
179
|
+
getUnitsProps(unit) {
|
|
180
|
+
var _a;
|
|
181
|
+
return {
|
|
182
|
+
name: unit.fullName,
|
|
183
|
+
label: (_a = unit.label) !== null && _a !== void 0 ? _a : "",
|
|
184
|
+
phenomenon: unit.phenomenon ? unit.phenomenon.fullName : "",
|
|
185
|
+
isValid: true,
|
|
186
|
+
system: unit.unitSystem === undefined ? "" : unit.unitSystem.fullName,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Finds Unit by displayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
async findUnitByDisplayLabel(displayLabel, schemaName, phenomenon, unitSystem) {
|
|
194
|
+
var _a;
|
|
195
|
+
const schemaItems = this._context.getSchemaItems();
|
|
196
|
+
let { value, done } = schemaItems.next();
|
|
197
|
+
while (!done) {
|
|
198
|
+
if (Unit_1.Unit.isUnit(value) && ((_a = value.label) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === displayLabel) {
|
|
199
|
+
const currPhenomenon = await value.phenomenon;
|
|
200
|
+
const currUnitSystem = await value.unitSystem;
|
|
201
|
+
if (!schemaName || value.schema.name.toLowerCase() === schemaName)
|
|
202
|
+
if (!phenomenon || (currPhenomenon && currPhenomenon.key.matchesFullName(phenomenon)))
|
|
203
|
+
if (!unitSystem || (currUnitSystem && currUnitSystem.key.matchesFullName(unitSystem)))
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
({ value, done } = schemaItems.next());
|
|
207
|
+
}
|
|
208
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find unit with display label", () => {
|
|
209
|
+
return { displayLabel };
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Finds Unit by altDisplayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
|
|
214
|
+
* @internal
|
|
215
|
+
*/
|
|
216
|
+
async findUnitByAltDisplayLabel(altDisplayLabel, schemaName, phenomenon, unitSystem) {
|
|
217
|
+
for (const entry of this._unitExtraData) {
|
|
218
|
+
if (entry.altDisplayLabels && entry.altDisplayLabels.length > 0) {
|
|
219
|
+
if (entry.altDisplayLabels.findIndex((ref) => ref.toLowerCase() === altDisplayLabel) !== -1) {
|
|
220
|
+
// Found altDisplayLabel that matches label to find
|
|
221
|
+
const unit = await this.findECUnitByName(entry.name);
|
|
222
|
+
const foundPhenomenon = await unit.phenomenon;
|
|
223
|
+
const foundUnitSystem = await unit.unitSystem;
|
|
224
|
+
if (!schemaName || unit.schema.name.toLowerCase() === schemaName)
|
|
225
|
+
if (!phenomenon || (foundPhenomenon && foundPhenomenon.key.matchesFullName(phenomenon)))
|
|
226
|
+
if (!unitSystem || (foundUnitSystem && foundUnitSystem.key.matchesFullName(unitSystem)))
|
|
227
|
+
return unit;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find unit with alternate display label", () => {
|
|
232
|
+
return { altDisplayLabel };
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.SchemaUnitProvider = SchemaUnitProvider;
|
|
237
|
+
//# sourceMappingURL=SchemaUnitProvider.js.map
|