@packtrack/layout 1.0.13 → 1.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.
@@ -1,4 +1,4 @@
1
- import { Device } from "./device";
1
+ import { Device } from "./index";
2
2
  export declare class Channel {
3
3
  device: Device;
4
4
  name: string;
@@ -0,0 +1,11 @@
1
+ import { Channel } from "./channel";
2
+ export declare class Device {
3
+ identifier: string;
4
+ channels: Channel[];
5
+ lastDiscovery: {
6
+ date: Date;
7
+ address: string;
8
+ };
9
+ constructor(identifier: string);
10
+ dump(): void;
11
+ }
@@ -0,0 +1,20 @@
1
+ export class Device {
2
+ identifier;
3
+ channels = [];
4
+ lastDiscovery;
5
+ constructor(identifier) {
6
+ this.identifier = identifier;
7
+ }
8
+ dump() {
9
+ console.group(`Device ${this.identifier}`);
10
+ if (this.lastDiscovery) {
11
+ console.log(`last discovery: ${this.lastDiscovery.date.toISOString()} ${this.lastDiscovery.address}`);
12
+ }
13
+ console.group('channels');
14
+ for (let channel of this.channels) {
15
+ channel.dump();
16
+ }
17
+ console.groupEnd();
18
+ console.groupEnd();
19
+ }
20
+ }
package/.built/index.d.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  export * from './district';
2
2
  export * from './layout';
3
3
  export * from './position';
4
- export * from './power-district';
5
4
  export * from './route';
6
5
  export * from './router';
7
6
  export * from './section';
8
7
  export * from './tile';
9
8
  export * from './track';
9
+ export * from './power-district/index';
10
+ export * from './power-district/activator';
11
+ export * from './power-district/monitor';
12
+ export * from './power-district/reverser';
10
13
  export * from './positioner/index';
11
14
  export * from './positioner/point';
12
15
  export * from './positioner/responder-type';
13
- export * from './device/device';
16
+ export * from './device/index';
14
17
  export * from './device/channel';
package/.built/index.js CHANGED
@@ -1,14 +1,17 @@
1
1
  export * from './district';
2
2
  export * from './layout';
3
3
  export * from './position';
4
- export * from './power-district';
5
4
  export * from './route';
6
5
  export * from './router';
7
6
  export * from './section';
8
7
  export * from './tile';
9
8
  export * from './track';
9
+ export * from './power-district/index';
10
+ export * from './power-district/activator';
11
+ export * from './power-district/monitor';
12
+ export * from './power-district/reverser';
10
13
  export * from './positioner/index';
11
14
  export * from './positioner/point';
12
15
  export * from './positioner/responder-type';
13
- export * from './device/device';
16
+ export * from './device/index';
14
17
  export * from './device/channel';
@@ -2,7 +2,7 @@ import { District } from "./district";
2
2
  import { PowerDistrict } from "./power-district";
3
3
  import { Router } from "./router";
4
4
  import { Section } from "./section";
5
- import { Device } from "./device/device";
5
+ import { Device } from "./device/index";
6
6
  import { ResponderType } from "./positioner/responder-type";
7
7
  import { Channel } from "./device/channel";
8
8
  export declare class Layout {
package/.built/layout.js CHANGED
@@ -5,10 +5,13 @@ import { Router } from "./router";
5
5
  import { Section } from "./section";
6
6
  import { TilePattern, Tile } from "./tile";
7
7
  import { Track } from "./track";
8
- import { Device } from "./device/device";
8
+ import { Device } from "./device/index";
9
9
  import { ResponderType } from "./positioner/responder-type";
10
10
  import { Channel } from "./device/channel";
11
11
  import { PointPositioner } from "./positioner/point";
12
+ import { PowerDistrictActivator } from "./power-district/activator";
13
+ import { PowerDistrictReverser } from "./power-district/reverser";
14
+ import { PowerDistrictMonitor } from "./power-district/monitor";
12
15
  export class Layout {
13
16
  name;
14
17
  districts = [];
@@ -231,6 +234,23 @@ export class Layout {
231
234
  }
232
235
  loadPowerDistrict(source, district) {
233
236
  const powerDistrict = new PowerDistrict(source.getAttribute('name'), district);
237
+ let actor = source.firstChild;
238
+ while (actor) {
239
+ if (actor.tagName == 'activator' || actor.tagName == 'reverser' || actor.tagName == 'monitor') {
240
+ const device = this.findDevice(actor.getAttribute('device'));
241
+ const channel = this.findChannel(device, actor.getAttribute('channel'));
242
+ if (actor.tagName == 'activator') {
243
+ powerDistrict.activator = new PowerDistrictActivator(device, channel);
244
+ }
245
+ if (actor.tagName == 'reverser') {
246
+ powerDistrict.reverser = new PowerDistrictReverser(device, channel);
247
+ }
248
+ if (actor.tagName == 'monitor') {
249
+ powerDistrict.monitor = new PowerDistrictMonitor(device, channel);
250
+ }
251
+ }
252
+ actor = actor.nextSibling;
253
+ }
234
254
  return powerDistrict;
235
255
  }
236
256
  toDot() {
@@ -0,0 +1,7 @@
1
+ import { Channel } from "../device/channel";
2
+ import { Device } from "../device/index";
3
+ export declare class PowerDistrictActivator {
4
+ device: Device;
5
+ channel: Channel;
6
+ constructor(device: Device, channel: Channel);
7
+ }
@@ -0,0 +1,8 @@
1
+ export class PowerDistrictActivator {
2
+ device;
3
+ channel;
4
+ constructor(device, channel) {
5
+ this.device = device;
6
+ this.channel = channel;
7
+ }
8
+ }
@@ -0,0 +1,14 @@
1
+ import { PowerDistrictActivator } from "./activator";
2
+ import { District } from "../district";
3
+ import { PowerDistrictMonitor } from "./monitor";
4
+ import { PowerDistrictReverser } from "./reverser";
5
+ export declare class PowerDistrict {
6
+ name: string;
7
+ district: District;
8
+ activator?: PowerDistrictActivator;
9
+ reverser?: PowerDistrictReverser;
10
+ monitor?: PowerDistrictMonitor;
11
+ constructor(name: string, district: District);
12
+ get domainName(): string;
13
+ dump(): void;
14
+ }
@@ -0,0 +1,17 @@
1
+ export class PowerDistrict {
2
+ name;
3
+ district;
4
+ activator;
5
+ reverser;
6
+ monitor;
7
+ constructor(name, district) {
8
+ this.name = name;
9
+ this.district = district;
10
+ }
11
+ get domainName() {
12
+ return `${this.name}.${this.district.domainName}`;
13
+ }
14
+ dump() {
15
+ console.log(this.name);
16
+ }
17
+ }
@@ -0,0 +1,7 @@
1
+ import { Channel } from "../device/channel";
2
+ import { Device } from "../device/index";
3
+ export declare class PowerDistrictMonitor {
4
+ device: Device;
5
+ channel: Channel;
6
+ constructor(device: Device, channel: Channel);
7
+ }
@@ -0,0 +1,8 @@
1
+ export class PowerDistrictMonitor {
2
+ device;
3
+ channel;
4
+ constructor(device, channel) {
5
+ this.device = device;
6
+ this.channel = channel;
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ import { Channel } from "../device/channel";
2
+ import { Device } from "../device/index";
3
+ export declare class PowerDistrictReverser {
4
+ device: Device;
5
+ channel: Channel;
6
+ constructor(device: Device, channel: Channel);
7
+ }
@@ -0,0 +1,8 @@
1
+ export class PowerDistrictReverser {
2
+ device;
3
+ channel;
4
+ constructor(device, channel) {
5
+ this.device = device;
6
+ this.channel = channel;
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@packtrack/layout",
3
- "version": "1.0.13",
3
+ "version": "1.1.0",
4
4
  "main": ".built/index.js",
5
5
  "typings": ".built/index.d.ts",
6
6
  "sideEffects": false,
@@ -1,4 +1,4 @@
1
- import { Device } from "./device";
1
+ import { Device } from "./index";
2
2
 
3
3
  export class Channel {
4
4
  constructor(
@@ -11,4 +11,4 @@ export class Channel {
11
11
  }
12
12
 
13
13
  publish(data: any) {}
14
- }
14
+ }
package/source/index.ts CHANGED
@@ -1,16 +1,20 @@
1
1
  export * from './district';
2
2
  export * from './layout';
3
3
  export * from './position';
4
- export * from './power-district';
5
4
  export * from './route';
6
5
  export * from './router';
7
6
  export * from './section';
8
7
  export * from './tile';
9
8
  export * from './track';
10
9
 
10
+ export * from './power-district/index';
11
+ export * from './power-district/activator';
12
+ export * from './power-district/monitor';
13
+ export * from './power-district/reverser';
14
+
11
15
  export * from './positioner/index';
12
16
  export * from './positioner/point';
13
17
  export * from './positioner/responder-type';
14
18
 
15
- export * from './device/device';
19
+ export * from './device/index';
16
20
  export * from './device/channel';
package/source/layout.ts CHANGED
@@ -5,16 +5,19 @@ import { Router } from "./router";
5
5
  import { Section } from "./section";
6
6
  import { TilePattern, Tile } from "./tile";
7
7
  import { Track } from "./track";
8
- import { Device } from "./device/device";
8
+ import { Device } from "./device/index";
9
9
  import { ResponderType } from "./positioner/responder-type";
10
10
  import { Channel } from "./device/channel";
11
11
  import { PointPositioner } from "./positioner/point";
12
+ import { PowerDistrictActivator } from "./power-district/activator";
13
+ import { PowerDistrictReverser } from "./power-district/reverser";
14
+ import { PowerDistrictMonitor } from "./power-district/monitor";
12
15
 
13
16
  export class Layout {
14
17
  name: string;
15
-
18
+
16
19
  districts: District[] = [];
17
-
20
+
18
21
  devices: Device[] = [];
19
22
  responderType: ResponderType[] = [];
20
23
 
@@ -43,28 +46,28 @@ export class Layout {
43
46
  layout.name = railway.getAttribute('name');
44
47
 
45
48
  const version = railway.getAttribute('version');
46
-
49
+
47
50
  if (version == '1') {
48
51
  let district = railway.firstChild;
49
-
52
+
50
53
  while (district) {
51
54
  if (district.tagName == 'district') {
52
55
  layout.districts.push(layout.loadDistrict(district, layout));
53
56
  }
54
-
57
+
55
58
  district = district.nextSibling;
56
59
  }
57
-
60
+
58
61
  district = railway.firstChild;
59
62
  let index = 0;
60
-
63
+
61
64
  while (district) {
62
65
  if (district.tagName == 'district') {
63
66
  layout.linkDistrict(district, layout.districts[index]);
64
-
67
+
65
68
  index++;
66
69
  }
67
-
70
+
68
71
  district = district.nextSibling;
69
72
  }
70
73
  } else {
@@ -73,90 +76,90 @@ export class Layout {
73
76
 
74
77
  return layout;
75
78
  }
76
-
79
+
77
80
  loadDistrict(source, parent: District | Layout) {
78
81
  const district = new District(source.getAttribute('name'), parent);
79
-
82
+
80
83
  let child = source.firstChild;
81
-
84
+
82
85
  while (child) {
83
86
  if (child.tagName == 'power-districts') {
84
87
  let powerDistrict = child.firstChild;
85
-
88
+
86
89
  while (powerDistrict) {
87
90
  if (powerDistrict.tagName == 'power-district') {
88
91
  district.powerDistricts.push(this.loadPowerDistrict(powerDistrict, district));
89
92
  }
90
-
93
+
91
94
  powerDistrict = powerDistrict.nextSibling;
92
95
  }
93
96
  }
94
-
97
+
95
98
  if (child.tagName == 'section') {
96
99
  this.loadSection(child, district);
97
100
  }
98
-
101
+
99
102
  if (child.tagName == 'router') {
100
103
  district.routers.push(this.loadRouter(child, district));
101
104
  }
102
-
105
+
103
106
  if (child.tagName == 'district') {
104
107
  district.children.push(this.loadDistrict(child, district));
105
108
  }
106
-
109
+
107
110
  child = child.nextSibling;
108
111
  }
109
-
112
+
110
113
  return district;
111
114
  }
112
-
115
+
113
116
  linkDistrict(source, district: District) {
114
117
  let child = source.firstChild;
115
-
118
+
116
119
  let sectionIndex = 0;
117
120
  let childIndex = 0;
118
-
121
+
119
122
  while (child) {
120
123
  if (child.tagName == 'section') {
121
124
  this.linkSection(child, district.sections[sectionIndex]);
122
-
125
+
123
126
  sectionIndex++;
124
127
  }
125
-
128
+
126
129
  if (child.tagName == 'router') {
127
130
  this.linkRouter(child, district.routers.find(router => router.name == child.getAttribute('name'))!);
128
131
  }
129
-
132
+
130
133
  if (child.tagName == 'district') {
131
134
  this.linkDistrict(child, district.children[childIndex]);
132
-
135
+
133
136
  childIndex++;
134
137
  }
135
-
138
+
136
139
  child = child.nextSibling;
137
140
  }
138
141
  }
139
-
142
+
140
143
  loadSection(source, district: District) {
141
144
  const section = new Section(source.getAttribute('name'), district);
142
145
  district.sections.push(section);
143
-
146
+
144
147
  let child = source.firstChild;
145
-
148
+
146
149
  while (child) {
147
150
  if (child.tagName == 'tracks') {
148
151
  let trackNode = child.firstChild;
149
-
152
+
150
153
  while (trackNode) {
151
154
  if (trackNode.tagName == 'track') {
152
155
  const track = new Track(
153
- section,
154
- +trackNode.getAttribute('length'),
156
+ section,
157
+ +trackNode.getAttribute('length'),
155
158
  trackNode.getAttribute('path')
156
159
  );
157
160
 
158
161
  section.tracks.push(track);
159
-
162
+
160
163
  let trackChild = trackNode.firstChild;
161
164
 
162
165
  while (trackChild) {
@@ -170,7 +173,7 @@ export class Layout {
170
173
  const responderType = this.findResponderType(positioner.getAttribute('responder'));
171
174
 
172
175
  track.positioners.push(new PointPositioner(
173
- track,
176
+ track,
174
177
  +positioner.getAttribute('offset'),
175
178
  channel,
176
179
  responderType
@@ -184,7 +187,7 @@ export class Layout {
184
187
  trackChild = trackChild.nextSibling;
185
188
  }
186
189
  }
187
-
190
+
188
191
  trackNode = trackNode.nextSibling;
189
192
  }
190
193
  }
@@ -198,7 +201,7 @@ export class Layout {
198
201
 
199
202
  section.tiles.push(new Tile(section, +child.getAttribute('x'), +child.getAttribute('y'), TilePattern.patterns[pattern]))
200
203
  }
201
-
204
+
202
205
  child = child.nextSibling;
203
206
  }
204
207
  }
@@ -241,111 +244,134 @@ export class Layout {
241
244
 
242
245
  return type;
243
246
  }
244
-
247
+
245
248
  linkSection(source, section: Section) {
246
249
  let child = source.firstChild;
247
-
250
+
248
251
  while (child) {
249
252
  if (child.tagName == 'out') {
250
253
  const out = this.findSection(child.getAttribute('section'), section.district);
251
-
254
+
252
255
  section.out = out;
253
256
  out.in = section;
254
257
  }
255
-
258
+
256
259
  child = child.nextSibling;
257
260
  }
258
261
  }
259
-
262
+
260
263
  findSection(path: string, base: District, source = base) {
261
264
  const parts = path.split('.');
262
-
265
+
263
266
  if (parts.length == 0) {
264
267
  throw `section '${path}' not found from '${source.name}': invalid name`;
265
268
  }
266
-
269
+
267
270
  if (parts.length == 1) {
268
271
  const localSection = base.sections.find(section => section.name == parts[0]);
269
-
272
+
270
273
  if (!localSection) {
271
274
  throw new Error(`Section '${path}' not found from '${source.name}': section does not exist in '${base.name}'`);
272
275
  }
273
-
276
+
274
277
  return localSection;
275
278
  }
276
-
279
+
277
280
  const sectionName = parts.pop()!;
278
-
281
+
279
282
  let pool: District | Layout = base;
280
-
283
+
281
284
  for (let index = 0; index < parts.length; index++) {
282
285
  if (pool instanceof Layout || !pool.parent) {
283
286
  throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a parent`);
284
287
  }
285
-
288
+
286
289
  pool = pool.parent!;
287
290
  }
288
-
291
+
289
292
  for (let part of parts) {
290
293
  const child = (pool instanceof District ? pool.children : pool.districts).find(child => child.name == part);
291
-
294
+
292
295
  if (!child) {
293
296
  throw new Error(`Section '${path}' could not be found from '${source.name}': district '${pool.name}' does not have a child named '${part}'`);
294
297
  }
295
-
298
+
296
299
  pool = child;
297
300
  }
298
301
 
299
302
  if (pool instanceof Layout) {
300
303
  throw new Error(`Section '${path}' could not be found from '${source.name}': a layout cannot directly include a section`);
301
304
  }
302
-
305
+
303
306
  return this.findSection(sectionName, pool, source);
304
307
  }
305
-
308
+
306
309
  loadRouter(source, district: District) {
307
310
  const router = new Router(source.getAttribute('name'), district);
308
-
311
+
309
312
  return router;
310
313
  }
311
-
314
+
312
315
  linkRouter(source, router: Router) {
313
316
  let child = source.firstChild;
314
-
317
+
315
318
  while (child) {
316
319
  if (child.tagName == 'route') {
317
320
  const route = new Route(child.getAttribute('name'), router);
318
-
321
+
319
322
  route.in = this.findSection(child.getAttribute('in'), router.district);
320
323
  route.in.out = router;
321
-
324
+
322
325
  route.out = this.findSection(child.getAttribute('out'), router.district);
323
326
  route.out.in = router;
324
-
327
+
325
328
  router.routes.push(route);
326
329
  }
327
-
330
+
328
331
  child = child.nextSibling;
329
332
  }
330
333
  }
331
-
334
+
332
335
  loadPowerDistrict(source, district: District) {
333
336
  const powerDistrict = new PowerDistrict(source.getAttribute('name'), district);
334
-
337
+
338
+ let actor = source.firstChild;
339
+
340
+ while (actor) {
341
+ if (actor.tagName == 'activator' || actor.tagName == 'reverser' || actor.tagName == 'monitor') {
342
+ const device = this.findDevice(actor.getAttribute('device'));
343
+ const channel = this.findChannel(device, actor.getAttribute('channel'));
344
+
345
+ if (actor.tagName == 'activator') {
346
+ powerDistrict.activator = new PowerDistrictActivator(device, channel);
347
+ }
348
+
349
+ if (actor.tagName == 'reverser') {
350
+ powerDistrict.reverser = new PowerDistrictReverser(device, channel);
351
+ }
352
+
353
+ if (actor.tagName == 'monitor') {
354
+ powerDistrict.monitor = new PowerDistrictMonitor(device, channel);
355
+ }
356
+ }
357
+
358
+ actor = actor.nextSibling;
359
+ }
360
+
335
361
  return powerDistrict;
336
362
  }
337
363
 
338
364
  toDot() {
339
365
  let dot = 'digraph G {';
340
-
366
+
341
367
  for (let district of this.districts) {
342
368
  dot += district.toDotDefinition();
343
369
  }
344
-
370
+
345
371
  for (let district of this.districts) {
346
372
  dot += district.toDotConnection();
347
373
  }
348
-
374
+
349
375
  return `${dot}}`;
350
376
  }
351
377
 
@@ -366,11 +392,11 @@ export class Layout {
366
392
 
367
393
  </style>
368
394
  `;
369
-
395
+
370
396
  for (let district of this.districts) {
371
397
  svg += district.toSVG();
372
398
  }
373
-
399
+
374
400
  return `${svg}${inject}</svg>`;
375
401
  }
376
402
 
@@ -396,4 +422,4 @@ export class Layout {
396
422
 
397
423
  console.groupEnd();
398
424
  }
399
- }
425
+ }
@@ -0,0 +1,9 @@
1
+ import { Channel } from "../device/channel";
2
+ import { Device } from "../device/index";
3
+
4
+ export class PowerDistrictActivator {
5
+ constructor(
6
+ public device: Device,
7
+ public channel: Channel
8
+ ) {}
9
+ }
@@ -0,0 +1,24 @@
1
+ import { PowerDistrictActivator } from "./activator";
2
+ import { Device } from "../device/index";
3
+ import { District } from "../district";
4
+ import { PowerDistrictMonitor } from "./monitor";
5
+ import { PowerDistrictReverser } from "./reverser";
6
+
7
+ export class PowerDistrict {
8
+ activator?: PowerDistrictActivator;
9
+ reverser?: PowerDistrictReverser;
10
+ monitor?: PowerDistrictMonitor;
11
+
12
+ constructor(
13
+ public name: string,
14
+ public district: District
15
+ ) {}
16
+
17
+ get domainName() {
18
+ return `${this.name}.${this.district.domainName}`;
19
+ }
20
+
21
+ dump() {
22
+ console.log(this.name);
23
+ }
24
+ }
@@ -0,0 +1,9 @@
1
+ import { Channel } from "../device/channel";
2
+ import { Device } from "../device/index";
3
+
4
+ export class PowerDistrictMonitor {
5
+ constructor(
6
+ public device: Device,
7
+ public channel: Channel
8
+ ) {}
9
+ }
@@ -0,0 +1,9 @@
1
+ import { Channel } from "../device/channel";
2
+ import { Device } from "../device/index";
3
+
4
+ export class PowerDistrictReverser {
5
+ constructor(
6
+ public device: Device,
7
+ public channel: Channel
8
+ ) {}
9
+ }
@@ -1,16 +0,0 @@
1
- import { District } from "./district";
2
-
3
- export class PowerDistrict {
4
- constructor(
5
- public name: string,
6
- public district: District
7
- ) {}
8
-
9
- get domainName() {
10
- return `${this.name}.${this.district.domainName}`;
11
- }
12
-
13
- dump() {
14
- console.log(this.name);
15
- }
16
- }
File without changes