diff --git a/src/DSI.ts b/src/DSI.ts index 9846e56ea9fd5e88fc4d454b1ec0090801f16048..0a992cc520a4d4b2d11ab4bc88b2e5f9446d9492 100644 --- a/src/DSI.ts +++ b/src/DSI.ts @@ -47,8 +47,11 @@ export class RealQuantityType extends SIXMLElement implements INamespaced { value: SIXMLNumber; unit: SIXMLElement; dateTime?: SIXMLDate; + + // region choice expandedUnc?: ExpandedUncType; coverageInterval?: CoverageIntervalType; + // endregion choice constructor(el: Partial<RealQuantityType> = {}) { super(el); @@ -56,56 +59,81 @@ export class RealQuantityType extends SIXMLElement implements INamespaced { this.value = new SIXMLNumber(el.value); this.unit = new SIXMLElement(el.unit); if (el.dateTime) this.dateTime = new SIXMLDate(el.dateTime); + + // choice if (el.expandedUnc) this.expandedUnc = new ExpandedUncType(el.expandedUnc); - if (el.coverageInterval) this.coverageInterval = new CoverageIntervalType(el.coverageInterval); + else if (el.coverageInterval) this.coverageInterval = new CoverageIntervalType(el.coverageInterval); } } export class HybridType extends SIXMLElement { - real: RealQuantityType[]; - complex: ComplexQuantityType[]; - list: SIListType[]; - realList: RealListType[]; - realListXMLList: RealListXMLListType[]; - complexList: ComplexListType[]; - constant: ConstantQuantityType[]; + // region choice + real?: RealQuantityType[]; + complex?: ComplexQuantityType[]; + list?: SIListType[]; + realList?: RealListType[]; + realListXMLList?: RealListXMLListType[]; + complexList?: ComplexListType[]; + constant?: ConstantQuantityType[]; + // endregion choice constructor(el: Partial<HybridType> = {}) { super(el); - this.real = ensureArray(el.real).map((x) => new RealQuantityType(x)); - this.complex = ensureArray(el.complex).map((x) => new ComplexQuantityType(x)); - this.list = ensureArray(el.list).map((x) => new SIListType(x)); - this.realList = ensureArray(el.realList).map((x) => new RealListType(x)); - this.realListXMLList = ensureArray(el.realListXMLList).map((x) => new RealListXMLListType(x)); - this.complexList = ensureArray(el.complexList).map((x) => new ComplexListType(x)); - this.constant = ensureArray(el.constant).map((x) => new ConstantQuantityType(x)); + + // choice + if (el.real) this.real = ensureArray(el.real).map((x) => new RealQuantityType(x)); + else if (el.complex) this.complex = ensureArray(el.complex).map((x) => new ComplexQuantityType(x)); + else if (el.list) this.list = ensureArray(el.list).map((x) => new SIListType(x)); + else if (el.realList) this.realList = ensureArray(el.realList).map((x) => new RealListType(x)); + else if (el.realListXMLList) this.realListXMLList = ensureArray(el.realListXMLList).map((x) => new RealListXMLListType(x)); + else if (el.complexList) this.complexList = ensureArray(el.complexList).map((x) => new ComplexListType(x)); + else if (el.constant) this.constant = ensureArray(el.constant).map((x) => new ConstantQuantityType(x)); } } export class ComplexQuantityType extends SIXMLElement { label?: SIXMLElement; - dateTime?: SIXMLDate; + + // region choice valueReal: SIXMLNumber; valueImag: SIXMLNumber; - unit: SIXMLElement[]; + valueMagnitude: SIXMLNumber; valuePhase: SIXMLNumber; + + // unit exists always + unit: SIXMLElement; + + // only exists if valueMagnitude and valuePhase exist unitPhase: SIXMLElement; + // endregion choice + + dateTime?: SIXMLDate; + ellipsoidalRegion?: EllipsoidalRegionType; rectangularRegion?: RectangularRegionType; constructor(el: Partial<ComplexQuantityType> = {}) { super(el); if (el.label) this.label = new SIXMLElement(el.label); + + // choice + if (el.valueReal && el.valueImag) { + this.valueReal = new SIXMLNumber(el.valueReal); + this.valueImag = new SIXMLNumber(el.valueImag); + this.unit = new SIXMLElement(el.unit); + } else if (el.valueMagnitude && el.valuePhase && el.unit && el.unitPhase) { + this.valueMagnitude = new SIXMLNumber(el.valueMagnitude); + this.valuePhase = new SIXMLNumber(el.valuePhase); + this.unit = new SIXMLElement(el.unit); + this.unitPhase = new SIXMLElement(el.unitPhase); + } + if (el.dateTime) this.dateTime = new SIXMLDate(el.dateTime); - this.valueReal = new SIXMLNumber(el.valueReal); - this.valueImag = new SIXMLNumber(el.valueImag); - this.unit = ensureArray(el.unit).map((x) => new SIXMLElement(x)); - this.valueMagnitude = new SIXMLNumber(el.valueMagnitude); - this.valuePhase = new SIXMLNumber(el.valuePhase); - this.unitPhase = new SIXMLElement(el.unitPhase); + + // choice if (el.ellipsoidalRegion) this.ellipsoidalRegion = new EllipsoidalRegionType(el.ellipsoidalRegion); - if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); + else if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); } } @@ -133,38 +161,55 @@ export class RealListXMLListType extends SIXMLElement { valueXMLList: DecimalXMLListType; unitXMLList: UnitXMLListType; dateTimeXMLList?: DateTimeXMLListType; + + // region choice expandedUncXMLList?: ExpandedUncXMLListType; coverageIntervalXMLList?: CoverageIntervalXMLListType; + // endregion choice + + // region choice ellipsoidalRegionXMLList?: EllipsoidalRegionType; rectangularRegionXMLList?: RectangularRegionType; + // endregion choice constructor(el: Partial<RealListXMLListType> = {}) { super(el); if (el.labelXMLList) this.labelXMLList = new StringXMLListType(el.labelXMLList); + this.valueXMLList = new DecimalXMLListType(el.valueXMLList); this.unitXMLList = new UnitXMLListType(el.unitXMLList); + if (el.dateTimeXMLList) this.dateTimeXMLList = new DateTimeXMLListType(el.dateTimeXMLList); + + // choice if (el.expandedUncXMLList) this.expandedUncXMLList = new ExpandedUncXMLListType(el.expandedUncXMLList); - if (el.coverageIntervalXMLList) this.coverageIntervalXMLList = new CoverageIntervalXMLListType(el.coverageIntervalXMLList); + else if (el.coverageIntervalXMLList) this.coverageIntervalXMLList = new CoverageIntervalXMLListType(el.coverageIntervalXMLList); + + // choice if (el.ellipsoidalRegionXMLList) this.ellipsoidalRegionXMLList = new EllipsoidalRegionType(el.ellipsoidalRegionXMLList); - if (el.rectangularRegionXMLList) this.rectangularRegionXMLList = new RectangularRegionType(el.rectangularRegionXMLList); + else if (el.rectangularRegionXMLList) this.rectangularRegionXMLList = new RectangularRegionType(el.rectangularRegionXMLList); } } export class SIListType extends SIXMLElement { label?: SIXMLElement; dateTime?: SIXMLDate; - realList: RealListType[]; - complexList: ComplexListType[]; - list: SIListType[]; + + // region choice + realList?: RealListType[]; + complexList?: ComplexListType[]; + list?: SIListType[]; + // endregion choice constructor(el: Partial<SIListType> = {}) { super(el); if (el.label) this.label = new SIXMLElement(el.label); if (el.dateTime) this.dateTime = new SIXMLDate(el.dateTime); - this.realList = ensureArray(el.realList).map((x) => new RealListType(x)); - this.complexList = ensureArray(el.complexList).map((x) => new ComplexListType(x)); - this.list = ensureArray(el.list).map((x) => new SIListType(x)); + + // choice + if (el.realList) this.realList = ensureArray(el.realList).map((x) => new RealListType(x)); + else if (el.complexList) this.complexList = ensureArray(el.complexList).map((x) => new ComplexListType(x)); + else if (el.list) this.list = ensureArray(el.list).map((x) => new SIListType(x)); } } @@ -235,8 +280,11 @@ export class RealInListType extends SIXMLElement { value: SIXMLNumber; unit?: SIXMLElement; dateTime?: SIXMLDate; + + // region choice expandedUnc?: ExpandedUncType; coverageInterval?: CoverageIntervalType; + // endregion choice constructor(el: Partial<RealInListType> = {}) { super(el); @@ -244,8 +292,10 @@ export class RealInListType extends SIXMLElement { this.value = new SIXMLNumber(el.value); if (el.unit) this.unit = new SIXMLElement(el.unit); if (el.dateTime) this.dateTime = new SIXMLDate(el.dateTime); + + // choice if (el.expandedUnc) this.expandedUnc = new ExpandedUncType(el.expandedUnc); - if (el.coverageInterval) this.coverageInterval = new CoverageIntervalType(el.coverageInterval); + else if (el.coverageInterval) this.coverageInterval = new CoverageIntervalType(el.coverageInterval); } } @@ -254,25 +304,37 @@ export class ComplexInListType extends SIXMLElement { dateTime?: SIXMLDate; valueReal: SIXMLNumber; valueImag: SIXMLNumber; - unit?: SIXMLElement[]; + unit?: SIXMLElement; valueMagnitude: SIXMLNumber; valuePhase: SIXMLNumber; unitPhase?: SIXMLElement; + + // region choice ellipsoidalRegion?: EllipsoidalRegionType; rectangularRegion?: RectangularRegionType; + // endregion choice constructor(el: Partial<ComplexInListType> = {}) { super(el); if (el.label) this.label = new SIXMLElement(el.label); + + // choice + if (el.valueReal && el.valueImag) { + this.valueReal = new SIXMLNumber(el.valueReal); + this.valueImag = new SIXMLNumber(el.valueImag); + if (el.unit) this.unit = new SIXMLElement(el.unit); + } else if (el.valueMagnitude && el.valuePhase) { + this.valueMagnitude = new SIXMLNumber(el.valueMagnitude); + this.valuePhase = new SIXMLNumber(el.valuePhase); + if (el.unit) this.unit = new SIXMLElement(el.unit); + if (el.unitPhase) this.unitPhase = new SIXMLElement(el.unitPhase); + } + if (el.dateTime) this.dateTime = new SIXMLDate(el.dateTime); - this.valueReal = new SIXMLNumber(el.valueReal); - this.valueImag = new SIXMLNumber(el.valueImag); - if (el.unit) this.unit = ensureArray(el.unit).map((x) => new SIXMLElement(x)); - this.valueMagnitude = new SIXMLNumber(el.valueMagnitude); - this.valuePhase = new SIXMLNumber(el.valuePhase); - if (el.unitPhase) this.unitPhase = new SIXMLElement(el.unitPhase); + + // choice if (el.ellipsoidalRegion) this.ellipsoidalRegion = new EllipsoidalRegionType(el.ellipsoidalRegion); - if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); + else if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); } } @@ -290,8 +352,11 @@ export class RealListType extends SIXMLElement { * the unit component is optional in order to allow a combination with * a global unit in the list of real quantities. */ real: RealInListType[]; + + // region choice ellipsoidalRegion?: EllipsoidalRegionType; rectangularRegion?: RectangularRegionType; + // endregion choice constructor(el: Partial<RealListType> = {}) { super(el); @@ -299,20 +364,27 @@ export class RealListType extends SIXMLElement { if (el.dateTime) this.dateTime = new SIXMLDate(el.dateTime); if (el.listUnit) this.listUnit = new SIXMLElement(el.listUnit); if (el.listUnivariateUnc) this.listUnivariateUnc = new ListUnivariateUncType(el.listUnivariateUnc); + this.real = ensureArray(el.real).map((x) => new RealInListType(x)); + + // choice if (el.ellipsoidalRegion) this.ellipsoidalRegion = new EllipsoidalRegionType(el.ellipsoidalRegion); - if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); + else if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); } } export class ListUnivariateUncType extends SIXMLElement { - expandedUnc: ExpandedUncType; - coverageInterval: CoverageIntervalType; + // region choice + expandedUnc?: ExpandedUncType; + coverageInterval?: CoverageIntervalType; + // endregion choice constructor(el: Partial<ListUnivariateUncType> = {}) { super(el); - this.expandedUnc = new ExpandedUncType(el.expandedUnc); - this.coverageInterval = new CoverageIntervalType(el.coverageInterval); + + // choice + if (el.expandedUnc) this.expandedUnc = new ExpandedUncType(el.expandedUnc); + else if (el.coverageInterval) this.coverageInterval = new CoverageIntervalType(el.coverageInterval); } } @@ -380,8 +452,11 @@ export class ComplexListType extends SIXMLElement { * the unit components are optional in order to allow a combination with * a global unit in the list of complex quantities. */ complex: ComplexInListType[]; + + // region choice ellipsoidalRegion?: EllipsoidalRegionType; rectangularRegion?: RectangularRegionType; + // endregion choice constructor(el: Partial<ComplexListType> = {}) { super(el); @@ -391,19 +466,25 @@ export class ComplexListType extends SIXMLElement { if (el.listUnitPhase) this.listUnitPhase = new SIXMLElement(el.listUnitPhase); if (el.listBivariateUnc) this.listBivariateUnc = new ListBivariateUncType(el.listBivariateUnc); this.complex = ensureArray(el.complex).map((x) => new ComplexInListType(x)); + + // choice if (el.ellipsoidalRegion) this.ellipsoidalRegion = new EllipsoidalRegionType(el.ellipsoidalRegion); - if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); + else if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); } } export class ListBivariateUncType extends SIXMLElement { + // region choice ellipsoidalRegion?: EllipsoidalRegionType; rectangularRegion?: RectangularRegionType; + // endregion choice constructor(el: Partial<ListBivariateUncType> = {}) { super(el); + + // choice if (el.ellipsoidalRegion) this.ellipsoidalRegion = new EllipsoidalRegionType(el.ellipsoidalRegion); - if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); + else if (el.rectangularRegion) this.rectangularRegion = new RectangularRegionType(el.rectangularRegion); } }