@dirkwa/s-100 0.0.0-stage → 0.0.1

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/dist/render.js ADDED
@@ -0,0 +1,350 @@
1
+ // Drawing items to OpenLayers features and styles.
2
+ import Feature from 'ol/Feature.js';
3
+ import Circle from 'ol/geom/Circle.js';
4
+ import Point from 'ol/geom/Point.js';
5
+ import MultiPoint from 'ol/geom/MultiPoint.js';
6
+ import LineString from 'ol/geom/LineString.js';
7
+ import MultiLineString from 'ol/geom/MultiLineString.js';
8
+ import Polygon from 'ol/geom/Polygon.js';
9
+ import { fromLonLat, toLonLat } from 'ol/proj.js';
10
+ import { Fill, Icon, Stroke, Style, Text } from 'ol/style.js';
11
+ import { featureGeom, parseSpatialId, spatialGeom } from "./geometry.js";
12
+ import { parseInstructions } from "./instructions.js";
13
+ export const PX_PER_MM = 96 / 25.4;
14
+ /** Screen-sized augmented paths of the S-101 catalogue reach at most 26 mm from their light; a layer drawing them needs this render buffer. */
15
+ export const AUGMENTED_RENDER_BUFFER = Math.ceil(30 * PX_PER_MM);
16
+ const PT_TO_PX = 96 / 72;
17
+ function toOl(g) {
18
+ switch (g.type) {
19
+ case 'Point':
20
+ return new Point(fromLonLat(g.coord));
21
+ case 'MultiPoint':
22
+ return new MultiPoint(g.coords.map((c) => fromLonLat(c)));
23
+ case 'LineString':
24
+ return g.lines.length === 1
25
+ ? new LineString(g.lines[0].map((c) => fromLonLat(c)))
26
+ : new MultiLineString(g.lines.map((l) => l.map((c) => fromLonLat(c))));
27
+ case 'Polygon':
28
+ return new Polygon(g.rings.map((r) => r.map((c) => fromLonLat(c))));
29
+ }
30
+ }
31
+ function asLines(g) {
32
+ if (g instanceof Polygon)
33
+ return new MultiLineString(g.getCoordinates());
34
+ return g;
35
+ }
36
+ function asPoint(g) {
37
+ if (g instanceof Polygon)
38
+ return g.getInteriorPoint();
39
+ if (g instanceof LineString)
40
+ return new Point(g.getCoordinateAt(0.5));
41
+ if (g instanceof MultiLineString) {
42
+ const first = g.getLineString(0);
43
+ return first ? new Point(first.getCoordinateAt(0.5)) : g;
44
+ }
45
+ return g;
46
+ }
47
+ /**
48
+ * A ground-sized path gets a circle covering its reach, so the layer selects it while any part is in view;
49
+ * the style draws it from the circle's centre.
50
+ */
51
+ function augmentedGeometry(anchor, path) {
52
+ if (!path.geographic || !(anchor instanceof Point))
53
+ return anchor;
54
+ const reach = Math.max(...path.segments.map((s) => (s.type === 'ray' ? s.length : s.radius)));
55
+ const center = anchor.getCoordinates();
56
+ const mapUnitsPerMetre = 1 / Math.cos((toLonLat(center)[1] * Math.PI) / 180);
57
+ return new Circle(center, reach * mapUnitsPerMetre);
58
+ }
59
+ const augmentedAnchor = (f) => {
60
+ const g = f.getGeometry();
61
+ return g instanceof Circle ? new Point(g.getCenter()) : g;
62
+ };
63
+ function geometryFor(ds, item, own) {
64
+ let g = own;
65
+ if (item.augmentedPoint)
66
+ g = new Point(fromLonLat(item.augmentedPoint));
67
+ else if (item.spatialRefs.length) {
68
+ const parts = item.spatialRefs
69
+ .map((id) => spatialGeom(ds, { ...parseSpatialId(id), ornt: 1 }))
70
+ .filter((x) => !!x);
71
+ if (parts.length === 1)
72
+ g = toOl(parts[0]);
73
+ else if (parts.length)
74
+ g = toOl({
75
+ type: 'LineString',
76
+ lines: parts.flatMap((p) => (p.type === 'LineString' ? p.lines : []))
77
+ });
78
+ }
79
+ if (!g)
80
+ return undefined;
81
+ if (item.augmented)
82
+ return augmentedGeometry(asPoint(g), item.augmented);
83
+ if (item.kind === 'line')
84
+ return asLines(g);
85
+ if (item.kind === 'point' || item.kind === 'text')
86
+ return asPoint(g);
87
+ if (!(g instanceof Polygon))
88
+ return undefined;
89
+ return g;
90
+ }
91
+ /** One OL feature per drawing item; the item rides along as property `item`. */
92
+ export function buildFeatures(ds, instructions) {
93
+ const features = [];
94
+ const groups = new Set();
95
+ for (const [id, src] of instructions) {
96
+ const f = ds.features.get(Number(id));
97
+ if (!f)
98
+ continue;
99
+ const g = featureGeom(ds, f.spas);
100
+ const own = g ? toOl(g) : undefined;
101
+ for (const item of parseInstructions(src)) {
102
+ const geom = geometryFor(ds, item, own);
103
+ if (!geom)
104
+ continue;
105
+ for (const vg of item.viewingGroups)
106
+ groups.add(vg);
107
+ const of = new Feature({ geometry: geom });
108
+ of.set('item', item, true);
109
+ of.set('code', f.code, true);
110
+ features.push(of);
111
+ }
112
+ }
113
+ return { features, groups };
114
+ }
115
+ const TEXT_ALIGN = {
116
+ Start: 'left',
117
+ End: 'right',
118
+ Center: 'center'
119
+ };
120
+ const TEXT_BASELINE = {
121
+ Top: 'top',
122
+ Bottom: 'bottom',
123
+ Center: 'middle',
124
+ Baseline: 'alphabetic'
125
+ };
126
+ /** Styles for one colour palette, cached per drawing item shape. */
127
+ export class Stylist {
128
+ cat;
129
+ colors;
130
+ css;
131
+ styles = new Map();
132
+ icons = new Map();
133
+ constructor(cat, palette) {
134
+ this.cat = cat;
135
+ const colors = cat.palettes[palette];
136
+ if (!colors)
137
+ throw new Error(`unknown palette ${palette}`);
138
+ this.colors = colors;
139
+ const rules = Object.entries(this.colors).map(([t, c]) => `.f${t}{fill:${c}}.s${t}{stroke:${c}}`);
140
+ this.css = `${rules.join('')}.f0{fill:none}.sl{stroke-linecap:round;stroke-linejoin:round}.layout{display:none}`;
141
+ }
142
+ color(token, transparency = 0) {
143
+ const hex = this.colors[token] ?? '#ff00ff';
144
+ if (!transparency)
145
+ return hex;
146
+ const a = Math.round((1 - transparency) * 255)
147
+ .toString(16)
148
+ .padStart(2, '0');
149
+ return hex + a;
150
+ }
151
+ icon(name) {
152
+ let ic = this.icons.get(name);
153
+ if (ic)
154
+ return ic;
155
+ const svg = this.cat.symbols[name];
156
+ if (!svg)
157
+ return undefined;
158
+ const vb = /viewBox="([-\d.\s]+)"/.exec(svg)?.[1].trim().split(/\s+/).map(Number) ?? [
159
+ 0, 0, 1, 1
160
+ ];
161
+ const colored = svg.replace(/(<svg[^>]*>)/, `$1<style>${this.css}</style>`);
162
+ ic = {
163
+ src: 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(colored),
164
+ anchor: [-vb[0] / vb[2], -vb[1] / vb[3]],
165
+ size: [vb[2] * PX_PER_MM, vb[3] * PX_PER_MM]
166
+ };
167
+ this.icons.set(name, ic);
168
+ return ic;
169
+ }
170
+ pattern(name) {
171
+ const def = this.cat.areaFills[name];
172
+ const ic = def && this.icon(def.symbol);
173
+ if (!def || !ic)
174
+ return 'rgba(0,0,0,0)';
175
+ const w = Math.max(1, Math.round(def.v1[0] * PX_PER_MM));
176
+ const h = Math.max(1, Math.round((def.v2[1] || def.v1[0]) * PX_PER_MM));
177
+ const canvas = document.createElement('canvas');
178
+ canvas.width = w;
179
+ canvas.height = h;
180
+ const ctx = canvas.getContext('2d');
181
+ if (!ctx)
182
+ return 'rgba(0,0,0,0)';
183
+ const img = new Image();
184
+ img.src = ic.src;
185
+ const pat = ctx.createPattern(canvas, 'repeat');
186
+ if (!pat)
187
+ return 'rgba(0,0,0,0)';
188
+ img.onload = () => {
189
+ ctx.drawImage(img, w / 2 - ic.anchor[0] * ic.size[0], h / 2 - ic.anchor[1] * ic.size[1], ic.size[0], ic.size[1]);
190
+ this.onPatternReady?.();
191
+ };
192
+ return pat;
193
+ }
194
+ onPatternReady;
195
+ style(item) {
196
+ const key = JSON.stringify([
197
+ item.kind,
198
+ item.ref,
199
+ item.augmented,
200
+ item.color,
201
+ item.width,
202
+ item.dash,
203
+ item.rotation,
204
+ item.offset,
205
+ item.text,
206
+ item.fontSize,
207
+ item.fontColor,
208
+ item.hAlign,
209
+ item.vAlign,
210
+ item.transparency,
211
+ item.priority
212
+ ]);
213
+ let s = this.styles.get(key);
214
+ if (!s) {
215
+ s = this.make(item);
216
+ this.styles.set(key, s);
217
+ }
218
+ return s;
219
+ }
220
+ /** Colour, width and dash in pixels of a simple or a named catalogue line style. */
221
+ lineLook(item) {
222
+ if (item.ref === '_simple_') {
223
+ return {
224
+ color: this.color(item.color ?? 'CHBLK'),
225
+ width: (item.width ?? 0.32) * PX_PER_MM,
226
+ dash: item.dash?.map((v) => Math.max(v, 0.01) * PX_PER_MM)
227
+ };
228
+ }
229
+ const ls = this.cat.lineStyles[item.ref];
230
+ if (!ls)
231
+ return { color: '#ff00ff', width: 1 };
232
+ const dash = [];
233
+ ls.dashes.forEach(([start, len], i) => {
234
+ const next = i + 1 < ls.dashes.length ? ls.dashes[i + 1][0] : ls.interval + ls.dashes[0][0];
235
+ dash.push(len * PX_PER_MM, Math.max(next - start - len, 0.01) * PX_PER_MM);
236
+ });
237
+ return {
238
+ color: this.color(ls.color),
239
+ width: ls.width * PX_PER_MM,
240
+ dash: dash.length ? dash : undefined
241
+ };
242
+ }
243
+ augmentedStyle(item, path) {
244
+ const { color, width, dash } = this.lineLook(item);
245
+ return new Style({
246
+ zIndex: item.priority,
247
+ geometry: augmentedAnchor,
248
+ renderer: (coords, state) => {
249
+ const [x, y] = coords;
250
+ const mm = PX_PER_MM * state.pixelRatio;
251
+ const geometry = state.geometry;
252
+ if (!(geometry instanceof Point))
253
+ return;
254
+ const groundPerPixel = state.resolution * Math.cos((toLonLat(geometry.getCoordinates())[1] * Math.PI) / 180);
255
+ const metres = state.pixelRatio / groundPerPixel;
256
+ const k = path.geographic ? metres : mm;
257
+ const ctx = state.context;
258
+ ctx.save();
259
+ ctx.strokeStyle = color;
260
+ ctx.lineWidth = width * state.pixelRatio;
261
+ ctx.lineCap = 'butt';
262
+ ctx.setLineDash(dash ? dash.map((v) => v * state.pixelRatio) : []);
263
+ ctx.beginPath();
264
+ for (const seg of path.segments) {
265
+ if (seg.type === 'ray') {
266
+ const a = screenAngle(seg.bearing);
267
+ ctx.moveTo(x, y);
268
+ ctx.lineTo(x + Math.cos(a) * seg.length * k, y + Math.sin(a) * seg.length * k);
269
+ }
270
+ else {
271
+ const [ox, oy] = path.localCentres ? seg.centre : [0, 0];
272
+ // LocalCRS is screen-aligned, but this canvas turns with the view (clockwise by state.rotation).
273
+ const cos = Math.cos(state.rotation);
274
+ const sin = Math.sin(state.rotation);
275
+ const cx = x + (ox * cos - oy * sin) * mm;
276
+ const cy = y + (-ox * sin - oy * cos) * mm;
277
+ const a0 = screenAngle(seg.start);
278
+ const a1 = a0 + (seg.extent * Math.PI) / 180;
279
+ ctx.moveTo(cx + Math.cos(a0) * seg.radius * k, cy + Math.sin(a0) * seg.radius * k);
280
+ ctx.arc(cx, cy, seg.radius * k, a0, a1, seg.extent < 0);
281
+ }
282
+ }
283
+ ctx.stroke();
284
+ ctx.restore();
285
+ }
286
+ });
287
+ }
288
+ make(item) {
289
+ const zIndex = item.priority;
290
+ switch (item.kind) {
291
+ case 'fill':
292
+ return [
293
+ new Style({ zIndex, fill: new Fill({ color: this.color(item.ref, item.transparency) }) })
294
+ ];
295
+ case 'pattern':
296
+ return [new Style({ zIndex, fill: new Fill({ color: this.pattern(item.ref) }) })];
297
+ case 'line': {
298
+ if (item.augmented)
299
+ return [this.augmentedStyle(item, item.augmented)];
300
+ const { color, width, dash } = this.lineLook(item);
301
+ return [new Style({ zIndex, stroke: new Stroke({ color, width, lineDash: dash }) })];
302
+ }
303
+ case 'point': {
304
+ const ic = this.icon(item.ref);
305
+ if (!ic)
306
+ return [];
307
+ return [
308
+ new Style({
309
+ zIndex,
310
+ image: new Icon({
311
+ src: ic.src,
312
+ anchor: ic.anchor,
313
+ width: ic.size[0],
314
+ height: ic.size[1],
315
+ rotation: ((item.rotation ?? 0) * Math.PI) / 180,
316
+ rotateWithView: false,
317
+ displacement: [
318
+ (item.offset?.[0] ?? 0) * PX_PER_MM,
319
+ (item.offset?.[1] ?? 0) * PX_PER_MM
320
+ ]
321
+ })
322
+ })
323
+ ];
324
+ }
325
+ case 'text':
326
+ return [
327
+ new Style({
328
+ zIndex,
329
+ text: new Text({
330
+ text: item.text,
331
+ font: `${item.italic ? 'italic ' : ''}${(item.fontSize ?? 10) * PT_TO_PX}px Roboto, Arial, sans-serif`,
332
+ fill: new Fill({ color: this.color(item.fontColor ?? 'CHBLK') }),
333
+ textAlign: TEXT_ALIGN[item.hAlign ?? 'Start'],
334
+ textBaseline: TEXT_BASELINE[item.vAlign ?? 'Baseline'],
335
+ offsetX: (item.offset?.[0] ?? 0) * PX_PER_MM,
336
+ offsetY: -(item.offset?.[1] ?? 0) * PX_PER_MM
337
+ })
338
+ })
339
+ ];
340
+ }
341
+ }
342
+ }
343
+ /** Canvas angle of a true bearing, clockwise from east; the layer's canvas applies the view's rotation. */
344
+ function screenAngle(bearing) {
345
+ return ((bearing - 90) * Math.PI) / 180;
346
+ }
347
+ /** Scale denominator shown at a Web Mercator resolution and latitude, for ScaleMinimum. */
348
+ export function scaleAt(resolution, latDeg) {
349
+ return (resolution * Math.cos((latDeg * Math.PI) / 180)) / 0.00028;
350
+ }
@@ -0,0 +1,96 @@
1
+ /** Record and field update instructions (RUIN, ATIN, IUIN, FAUI, SAUI, MUIN, RAUI, COUI, CCUI, SEUI). */
2
+ export declare const INSERT = 1;
3
+ export declare const DELETE = 2;
4
+ export declare const MODIFY = 3;
5
+ export interface AttrRow {
6
+ code: string;
7
+ /** Position among the siblings with the same code, from 1. */
8
+ atix: number;
9
+ /** Row number of the parent complex attribute within the same field, from 1; 0 for none. */
10
+ paix: number;
11
+ atin: number;
12
+ value: string;
13
+ }
14
+ export interface AssocRow {
15
+ rrnm: number;
16
+ rrid: number;
17
+ association: string;
18
+ role: string;
19
+ instruction: number;
20
+ attrs: AttrRow[];
21
+ }
22
+ export interface RefRow {
23
+ rrnm: number;
24
+ rrid: number;
25
+ ornt: number;
26
+ smin: number;
27
+ smax: number;
28
+ usag: number;
29
+ /** SAUI for SPAS, RAUI for RIAS. */
30
+ instruction: number;
31
+ }
32
+ export interface MaskRow {
33
+ rrnm: number;
34
+ rrid: number;
35
+ mind: number;
36
+ muin: number;
37
+ }
38
+ /** Integer coordinates as stored, x first: [x, y] or [x, y, z] per position. */
39
+ export interface CoordList {
40
+ dim: 2 | 3;
41
+ values: number[];
42
+ }
43
+ export interface Control {
44
+ instruction: number;
45
+ /** First position concerned, from 1. */
46
+ index: number;
47
+ count: number;
48
+ }
49
+ export interface RawRecord {
50
+ tag: string;
51
+ rcnm: number;
52
+ rcid: number;
53
+ rver: number;
54
+ ruin: number;
55
+ /** Feature or information type name. */
56
+ code: string;
57
+ attr: AttrRow[][];
58
+ inas: AssocRow[];
59
+ fasc: AssocRow[];
60
+ foid?: {
61
+ agen: number;
62
+ fidn: number;
63
+ fids: number;
64
+ };
65
+ spas: RefRow[];
66
+ mask: MaskRow[];
67
+ point?: number[];
68
+ coords?: CoordList;
69
+ /** COCC */
70
+ coordControl?: Control;
71
+ /** SECC */
72
+ segmentControl?: Control;
73
+ ptas?: {
74
+ rrnm: number;
75
+ rrid: number;
76
+ topi: number;
77
+ }[];
78
+ cuco: RefRow[];
79
+ /** CCOC */
80
+ componentControl?: Control;
81
+ rias: RefRow[];
82
+ }
83
+ export interface DatasetInfo {
84
+ name: string;
85
+ edition: string;
86
+ /** PROF: 1 base, 2 update. */
87
+ profile: number;
88
+ cmfx: number;
89
+ cmfy: number;
90
+ cmfz: number;
91
+ }
92
+ export interface RecordFile {
93
+ info: DatasetInfo;
94
+ records: RawRecord[];
95
+ }
96
+ export declare function readRecords(bytes: Uint8Array): RecordFile;
@@ -0,0 +1,157 @@
1
+ // S-101 records as read from one exchange set file, with the file's numeric codes already turned into
2
+ // their names, so base and update files (each with its own code tables) can be merged by name.
3
+ import { Iso8211Reader } from "./iso8211.js";
4
+ /** Record and field update instructions (RUIN, ATIN, IUIN, FAUI, SAUI, MUIN, RAUI, COUI, CCUI, SEUI). */
5
+ export const INSERT = 1;
6
+ export const DELETE = 2;
7
+ export const MODIFY = 3;
8
+ const NONE = [];
9
+ const RECORD_TAGS = new Set(['IRID', 'PRID', 'MRID', 'CRID', 'CCID', 'SRID', 'FRID']);
10
+ export function readRecords(bytes) {
11
+ const reader = new Iso8211Reader(bytes);
12
+ const tables = {
13
+ ATCS: new Map(),
14
+ ITCS: new Map(),
15
+ FTCS: new Map(),
16
+ IACS: new Map(),
17
+ FACS: new Map(),
18
+ ARCS: new Map()
19
+ };
20
+ const name = (table, n) => tables[table].get(Number(n)) ?? `#${n}`;
21
+ const info = { name: '', edition: '', profile: 1, cmfx: 1e7, cmfy: 1e7, cmfz: 10 };
22
+ const records = [];
23
+ const attrRows = (rows) => rows.map((r) => ({
24
+ code: name('ATCS', r.NATC),
25
+ atix: Number(r.ATIX),
26
+ paix: Number(r.PAIX),
27
+ atin: Number(r.ATIN),
28
+ value: String(r.ATVL ?? '')
29
+ }));
30
+ const assoc = (f, assocTable, codeKey, instKey) => ({
31
+ rrnm: Number(f.head.RRNM),
32
+ rrid: Number(f.head.RRID),
33
+ association: name(assocTable, f.head[codeKey]),
34
+ role: name('ARCS', f.head.NARC),
35
+ instruction: Number(f.head[instKey]),
36
+ attrs: attrRows(f.rows)
37
+ });
38
+ const refRows = (fields, instKey) => fields.flatMap((f) => f.rows.map((r) => ({
39
+ rrnm: Number(r.RRNM),
40
+ rrid: Number(r.RRID),
41
+ ornt: Number(r.ORNT),
42
+ smin: Number(r.SMIN ?? 0),
43
+ smax: Number(r.SMAX ?? 0),
44
+ usag: Number(r.USAG ?? 0),
45
+ instruction: instKey ? Number(r[instKey]) : INSERT
46
+ })));
47
+ const control = (f, inst, index, count) => f && {
48
+ instruction: Number(f.head[inst]),
49
+ index: Number(f.head[index]),
50
+ count: Number(f.head[count])
51
+ };
52
+ for (const rec of reader.records()) {
53
+ const first = rec.fields.find((f) => f.tag !== '0001');
54
+ if (!first)
55
+ continue;
56
+ const byTag = new Map();
57
+ for (const f of rec.fields) {
58
+ const list = byTag.get(f.tag);
59
+ if (list)
60
+ list.push(f);
61
+ else
62
+ byTag.set(f.tag, [f]);
63
+ }
64
+ const get = (tag) => byTag.get(tag) ?? NONE;
65
+ if (first.tag === 'DSID') {
66
+ info.name = String(first.head.DSNM ?? '');
67
+ info.edition = String(first.head.DSED ?? '');
68
+ info.profile = Number(first.head.PROF);
69
+ const dssi = get('DSSI').at(0);
70
+ if (dssi) {
71
+ info.cmfx = Number(dssi.head.CMFX);
72
+ info.cmfy = Number(dssi.head.CMFY);
73
+ info.cmfz = Number(dssi.head.CMFZ);
74
+ }
75
+ for (const [tag, code, num] of [
76
+ ['ATCS', 'ATCD', 'ANCD'],
77
+ ['ITCS', 'ITCD', 'ITNC'],
78
+ ['FTCS', 'FTCD', 'FTNC'],
79
+ ['IACS', 'IACD', 'IANC'],
80
+ ['FACS', 'FACD', 'FANC'],
81
+ ['ARCS', 'ARCD', 'ARNC']
82
+ ]) {
83
+ for (const f of get(tag))
84
+ for (const r of f.rows)
85
+ tables[tag].set(Number(r[num]), String(r[code]));
86
+ }
87
+ continue;
88
+ }
89
+ if (!RECORD_TAGS.has(first.tag)) {
90
+ // A base cell may carry records this reader has no use for, such as the CRS record; an update may
91
+ // not, since skipping one of its records would apply the update in part.
92
+ if (info.profile === 2)
93
+ throw new Error(`${info.name}: unexpected ${first.tag} record in an update file`);
94
+ continue;
95
+ }
96
+ const h = first.head;
97
+ const record = {
98
+ tag: first.tag,
99
+ rcnm: Number(h.RCNM),
100
+ rcid: Number(h.RCID),
101
+ rver: Number(h.RVER),
102
+ ruin: Number(h.RUIN),
103
+ code: first.tag === 'FRID'
104
+ ? name('FTCS', h.NFTC)
105
+ : first.tag === 'IRID'
106
+ ? name('ITCS', h.NITC)
107
+ : '',
108
+ attr: get('ATTR').map((f) => attrRows(f.rows)),
109
+ inas: get('INAS').map((f) => assoc(f, 'IACS', 'NIAC', 'IUIN')),
110
+ fasc: get('FASC').map((f) => assoc(f, 'FACS', 'NFAC', 'FAUI')),
111
+ spas: refRows(get('SPAS'), 'SAUI'),
112
+ mask: get('MASK').flatMap((f) => f.rows.map((r) => ({
113
+ rrnm: Number(r.RRNM),
114
+ rrid: Number(r.RRID),
115
+ mind: Number(r.MIND),
116
+ muin: Number(r.MUIN)
117
+ }))),
118
+ cuco: refRows(get('CUCO')),
119
+ rias: refRows(get('RIAS'), 'RAUI'),
120
+ coordControl: control(get('COCC').at(0), 'COUI', 'COIX', 'NCOR'),
121
+ segmentControl: control(get('SECC').at(0), 'SEUI', 'SEIX', 'NSEG'),
122
+ componentControl: control(get('CCOC').at(0), 'CCUI', 'CCIX', 'NCCO')
123
+ };
124
+ const foid = get('FOID').at(0);
125
+ if (foid)
126
+ record.foid = {
127
+ agen: Number(foid.head.AGEN),
128
+ fidn: Number(foid.head.FIDN),
129
+ fids: Number(foid.head.FIDS)
130
+ };
131
+ const c2it = get('C2IT').at(0);
132
+ const c3it = get('C3IT').at(0);
133
+ if (c2it)
134
+ record.point = [Number(c2it.head.XCOO), Number(c2it.head.YCOO)];
135
+ else if (c3it)
136
+ record.point = [Number(c3it.head.XCOO), Number(c3it.head.YCOO), Number(c3it.head.ZCOO)];
137
+ const c2il = get('C2IL');
138
+ const c3il = get('C3IL');
139
+ if (c2il.length || c3il.length) {
140
+ const dim = c2il.length ? 2 : 3;
141
+ const values = [];
142
+ for (const f of c2il.length ? c2il : c3il) {
143
+ for (const r of f.rows) {
144
+ values.push(Number(r.XCOO), Number(r.YCOO));
145
+ if (dim === 3)
146
+ values.push(Number(r.ZCOO));
147
+ }
148
+ }
149
+ record.coords = { dim, values };
150
+ }
151
+ const ptas = get('PTAS');
152
+ if (ptas.length)
153
+ record.ptas = ptas.flatMap((f) => f.rows.map((r) => ({ rrnm: Number(r.RRNM), rrid: Number(r.RRID), topi: Number(r.TOPI) })));
154
+ records.push(record);
155
+ }
156
+ return { info, records };
157
+ }
@@ -0,0 +1,43 @@
1
+ import { type AttrRow, type DatasetInfo, type RawRecord, type RecordFile } from './s101-records.ts';
2
+ export interface AttrTree {
3
+ code: string;
4
+ atix: number;
5
+ value: string;
6
+ children: AttrTree[];
7
+ }
8
+ export interface Assoc {
9
+ rrnm: number;
10
+ rrid: number;
11
+ association: string;
12
+ role: string;
13
+ attrs: AttrTree[];
14
+ }
15
+ export interface Rec extends Omit<RawRecord, 'attr' | 'inas' | 'fasc' | 'ruin'> {
16
+ /** The record's attributes, from all of its ATTR fields. */
17
+ attr: AttrTree[];
18
+ inas: Assoc[];
19
+ fasc: Assoc[];
20
+ }
21
+ export interface MergedCell {
22
+ info: DatasetInfo;
23
+ /** Keyed by `${rcnm}:${rcid}`. */
24
+ records: Map<string, Rec>;
25
+ cancelled: boolean;
26
+ /** Number of update files applied. */
27
+ updates: number;
28
+ }
29
+ /**
30
+ * Applies ATTR-like rows to an attribute tree. In a base record every row inserts; in an update a row
31
+ * inserts, deletes or modifies the sibling it names by code and ATIX, under the parent its PAIX names
32
+ * among the update's own rows.
33
+ */
34
+ export declare function applyAttrRows(roots: AttrTree[], rows: AttrRow[], isBase: boolean, rec: {
35
+ tag: string;
36
+ rcid: number;
37
+ }): void;
38
+ export declare function baseCell(file: RecordFile): MergedCell;
39
+ /**
40
+ * Applies one update file. Throws if the update does not fit the cell, as an ECDIS rejects such an update,
41
+ * and leaves the cell as it was.
42
+ */
43
+ export declare function applyUpdate(cell: MergedCell, file: RecordFile): void;