UNPKG

isoxml-angular

Version:

JavaScript library to parse and generate ISOXML (ISO11783-10) files

66 lines (65 loc) 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtendedTask = void 0; const classRegistry_1 = require("../classRegistry"); const baseEntities_1 = require("../baseEntities"); const Grid_1 = require("./Grid"); const utils_1 = require("../utils"); class ExtendedTask extends baseEntities_1.Task { constructor(attributes, isoxmlManager) { super(attributes, isoxmlManager); this.tag = "TSK" /* TAGS.Task */; } static fromXML(xml, isoxmlManager, internalId) { return baseEntities_1.Task.fromXML(xml, isoxmlManager, internalId, ExtendedTask); } addGridFromGeoJSON(geoJSON, DDI, deviceElemRef, vpnRef) { const processDataVariable = this.isoxmlManager.createEntityFromAttributes("PDV" /* TAGS.ProcessDataVariable */, Object.assign(Object.assign({ ProcessDataDDI: (0, utils_1.DDIToString)(DDI), ProcessDataValue: 0 }, deviceElemRef && { DeviceElementIdRef: deviceElemRef }), vpnRef && { ValuePresentationIdRef: vpnRef })); this.attributes.TreatmentZone = [ this.isoxmlManager.createEntityFromAttributes("TZN" /* TAGS.TreatmentZone */, { TreatmentZoneCode: 0, ProcessDataVariable: [processDataVariable] }), this.isoxmlManager.createEntityFromAttributes("TZN" /* TAGS.TreatmentZone */, { TreatmentZoneCode: 1, ProcessDataVariable: [processDataVariable] }) ]; this.attributes.OutOfFieldTreatmentZoneCode = 0; this.attributes.Grid = [ Grid_1.ExtendedGrid.fromGeoJSON(geoJSON, this.isoxmlManager, 1) ]; } getGridAsGeoJSON() { if (!this.attributes.Grid) { return null; } return this.attributes.Grid[0].toGeoJSON(); } getGridValuesDescription() { var _a; const grid = (_a = this.attributes.Grid) === null || _a === void 0 ? void 0 : _a[0]; if (!grid) { return []; } const treatmentZoneCodes = grid.getAllReferencedTZNCodes(); if (treatmentZoneCodes.length === 0) { return []; } // we assume that all the referenced TreatmentZones have the same set of ProcessDataVariables const treatmentZone = (this.attributes.TreatmentZone || []) .find(tz => tz.attributes.TreatmentZoneCode === treatmentZoneCodes[0]); if (!treatmentZone) { return []; } return (treatmentZone.attributes.ProcessDataVariable || []).map(pdv => { var _a, _b; const vpn = (_a = pdv.attributes.ValuePresentationIdRef) === null || _a === void 0 ? void 0 : _a.entity; const det = (_b = pdv.attributes.DeviceElementIdRef) === null || _b === void 0 ? void 0 : _b.entity; const pdp = det === null || det === void 0 ? void 0 : det.getDataProcess(pdv.attributes.ProcessDataDDI); return (0, utils_1.constructValueInformation)(pdv.attributes.ProcessDataDDI, vpn, pdp); }); } } exports.ExtendedTask = ExtendedTask; (0, classRegistry_1.registerEntityClass)('main', "TSK" /* TAGS.Task */, ExtendedTask);