Skip to content

Commit 7083a90

Browse files
committed
fix(ports): adapt port indexes assignation for collapsed nodes sections chain
Important: the other Netzgrafik JSON files must be updated, either in the feature branch, either here (but they might also change due to other PRs that will be merged afterwards in the feature branch). Signed-off-by: Louis Greiner <louis.greiner@proton.me>
1 parent 913e5b2 commit 7083a90

File tree

4 files changed

+52
-32
lines changed

4 files changed

+52
-32
lines changed

src/app/models/node.model.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,27 +482,27 @@ export class Node {
482482
a.getPositionAlignment() === PortAlignment.Right
483483
) {
484484
if (
485-
a.getOppositeNodePosition(this.getId()).getY() >
486-
b.getOppositeNodePosition(this.getId()).getY()
485+
a.getOppositeExpandedNodePosition(this.getId()).getY() >
486+
b.getOppositeExpandedNodePosition(this.getId()).getY()
487487
) {
488488
return 1;
489489
} else if (
490-
a.getOppositeNodePosition(this.getId()).getY() ===
491-
b.getOppositeNodePosition(this.getId()).getY()
490+
a.getOppositeExpandedNodePosition(this.getId()).getY() ===
491+
b.getOppositeExpandedNodePosition(this.getId()).getY()
492492
) {
493493
return Node.orderPortsTrainCategory(a, b);
494494
} else {
495495
return -1;
496496
}
497497
} else {
498498
if (
499-
a.getOppositeNodePosition(this.getId()).getX() >
500-
b.getOppositeNodePosition(this.getId()).getX()
499+
a.getOppositeExpandedNodePosition(this.getId()).getX() >
500+
b.getOppositeExpandedNodePosition(this.getId()).getX()
501501
) {
502502
return 1;
503503
} else if (
504-
a.getOppositeNodePosition(this.getId()).getX() ===
505-
b.getOppositeNodePosition(this.getId()).getX()
504+
a.getOppositeExpandedNodePosition(this.getId()).getX() ===
505+
b.getOppositeExpandedNodePosition(this.getId()).getX()
506506
) {
507507
return Node.orderPortsTrainCategory(a, b);
508508
} else {

src/app/models/port.model.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import {PortAlignment, PortDto} from "../data-structures/technical.data.structures";
22
import {TrainrunSection} from "./trainrunsection.model";
33
import {Vec2D} from "../utils/vec2D";
4+
import {
5+
BackwardExpandedStopIterator,
6+
ExpandedTrainrunIterator,
7+
TrainrunIterator,
8+
} from "../services/util/trainrun.iterator";
49

510
export class Port {
611
private static currentId = 0;
@@ -67,18 +72,21 @@ export class Port {
6772
return this.trainrunSection;
6873
}
6974

70-
getOppositeNodePosition(fromNodeId: number): Vec2D {
71-
if (this.getTrainrunSection().getSourceNodeId() === fromNodeId) {
72-
return new Vec2D(
73-
this.getTrainrunSection().getTargetNode().getPositionX(),
74-
this.getTrainrunSection().getTargetNode().getPositionY(),
75-
);
76-
} else {
77-
return new Vec2D(
78-
this.getTrainrunSection().getSourceNode().getPositionX(),
79-
this.getTrainrunSection().getSourceNode().getPositionY(),
80-
);
75+
getOppositeExpandedNodePosition(fromNodeId: number): Vec2D {
76+
const trainrunSection = this.getTrainrunSection();
77+
const isFromSourceNode = trainrunSection.getSourceNodeId() === fromNodeId;
78+
79+
const iterator = isFromSourceNode
80+
? new ExpandedTrainrunIterator(null, trainrunSection.getSourceNode(), trainrunSection)
81+
: new BackwardExpandedStopIterator(null, trainrunSection.getTargetNode(), trainrunSection);
82+
while (iterator.hasNext()) {
83+
iterator.next();
8184
}
85+
86+
return new Vec2D(
87+
iterator.current().node.getPositionX(),
88+
iterator.current().node.getPositionY(),
89+
);
8290
}
8391

8492
getDto(): PortDto {

src/app/sample-netzgrafik/netzgrafik_demo_standalone_github.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@
362362
"positionY": 96,
363363
"ports": [
364364
{"id": 1145, "trainrunSectionId": 565, "positionIndex": 0, "positionAlignment": 1},
365-
{"id": 1167, "trainrunSectionId": 576, "positionIndex": 0, "positionAlignment": 2},
366-
{"id": 1212, "trainrunSectionId": 598, "positionIndex": 1, "positionAlignment": 2},
365+
{"id": 1212, "trainrunSectionId": 598, "positionIndex": 0, "positionAlignment": 2},
366+
{"id": 1167, "trainrunSectionId": 576, "positionIndex": 1, "positionAlignment": 2},
367367
{"id": 1144, "trainrunSectionId": 740, "positionIndex": 2, "positionAlignment": 2},
368368
{"id": 1419, "trainrunSectionId": 702, "positionIndex": 0, "positionAlignment": 3}
369369
],
@@ -968,8 +968,8 @@
968968
{"id": 1227, "trainrunSectionId": 606, "positionIndex": 0, "positionAlignment": 3},
969969
{"id": 1243, "trainrunSectionId": 614, "positionIndex": 1, "positionAlignment": 3},
970970
{"id": 1211, "trainrunSectionId": 757, "positionIndex": 2, "positionAlignment": 3},
971-
{"id": 1143, "trainrunSectionId": 564, "positionIndex": 3, "positionAlignment": 3},
972-
{"id": 1168, "trainrunSectionId": 576, "positionIndex": 4, "positionAlignment": 3}
971+
{"id": 1168, "trainrunSectionId": 576, "positionIndex": 3, "positionAlignment": 3},
972+
{"id": 1143, "trainrunSectionId": 564, "positionIndex": 4, "positionAlignment": 3}
973973
],
974974
"transitions": [
975975
{"id": 247, "port1Id": 1142, "port2Id": 1143, "isNonStopTransit": false},
@@ -1635,8 +1635,8 @@
16351635
{"id": 1094, "trainrunSectionId": 539, "positionIndex": 1, "positionAlignment": 1},
16361636
{"id": 1102, "trainrunSectionId": 543, "positionIndex": 2, "positionAlignment": 1},
16371637
{"id": 1098, "trainrunSectionId": 735, "positionIndex": 3, "positionAlignment": 1},
1638-
{"id": 1363, "trainrunSectionId": 674, "positionIndex": 0, "positionAlignment": 3},
1639-
{"id": 1361, "trainrunSectionId": 673, "positionIndex": 1, "positionAlignment": 3}
1638+
{"id": 1361, "trainrunSectionId": 673, "positionIndex": 0, "positionAlignment": 3},
1639+
{"id": 1363, "trainrunSectionId": 674, "positionIndex": 1, "positionAlignment": 3}
16401640
],
16411641
"transitions": [
16421642
{"id": 328, "port1Id": 1353, "port2Id": 1098, "isNonStopTransit": false},
@@ -1670,8 +1670,8 @@
16701670
"positionX": -2560,
16711671
"positionY": 288,
16721672
"ports": [
1673-
{"id": 1379, "trainrunSectionId": 682, "positionIndex": 0, "positionAlignment": 2},
1674-
{"id": 1381, "trainrunSectionId": 683, "positionIndex": 1, "positionAlignment": 2},
1673+
{"id": 1381, "trainrunSectionId": 683, "positionIndex": 0, "positionAlignment": 2},
1674+
{"id": 1379, "trainrunSectionId": 682, "positionIndex": 1, "positionAlignment": 2},
16751675
{"id": 1206, "trainrunSectionId": 595, "positionIndex": 0, "positionAlignment": 3},
16761676
{"id": 1110, "trainrunSectionId": 547, "positionIndex": 1, "positionAlignment": 3}
16771677
],
@@ -1860,9 +1860,9 @@
18601860
"positionX": -3520,
18611861
"positionY": 544,
18621862
"ports": [
1863-
{"id": 1421, "trainrunSectionId": 703, "positionIndex": 0, "positionAlignment": 2},
1864-
{"id": 1423, "trainrunSectionId": 704, "positionIndex": 1, "positionAlignment": 2},
1865-
{"id": 1425, "trainrunSectionId": 705, "positionIndex": 2, "positionAlignment": 2},
1863+
{"id": 1423, "trainrunSectionId": 704, "positionIndex": 0, "positionAlignment": 2},
1864+
{"id": 1425, "trainrunSectionId": 705, "positionIndex": 1, "positionAlignment": 2},
1865+
{"id": 1421, "trainrunSectionId": 703, "positionIndex": 2, "positionAlignment": 2},
18661866
{"id": 1184, "trainrunSectionId": 752, "positionIndex": 0, "positionAlignment": 3},
18671867
{"id": 1208, "trainrunSectionId": 596, "positionIndex": 1, "positionAlignment": 3},
18681868
{"id": 1188, "trainrunSectionId": 586, "positionIndex": 2, "positionAlignment": 3}

src/app/services/util/trainrun.iterator.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class TrainrunIterator {
232232
this.currentElement = this.pointerElement;
233233
this.pointerElement = new TrainrunSectionNodePair(undefined, undefined);
234234
// log the issue
235-
this.logService.error(
235+
this.logService?.error(
236236
$localize`:@@app.services.util.trainrun-iteration.error.infinity-loop:Iterator has detected an infinity loop. The iteration terminated early!`,
237237
new Error().stack,
238238
);
@@ -275,7 +275,7 @@ export class BackwardTrainrunIterator extends TrainrunIterator {
275275
this.currentElement = this.pointerElement;
276276
this.pointerElement = new TrainrunSectionNodePair(undefined, undefined);
277277
// log the issue
278-
this.logService.error(
278+
this.logService?.error(
279279
$localize`:@@app.services.util.trainrun-iteration.error.infinity-loop:Iterator has detected an infinity loop. The iteration terminated early!`,
280280
new Error().stack,
281281
);
@@ -331,3 +331,15 @@ export class ExpandedTrainrunIterator extends TrainrunIterator {
331331
return super.next();
332332
}
333333
}
334+
335+
export class BackwardExpandedStopIterator extends BackwardTrainrunIterator {
336+
public next(): TrainrunSectionNodePair {
337+
if (!this.pointerElement.node.getIsCollapsed()) {
338+
// The trainrun has a stop and break the backward iteration
339+
this.currentElement = this.pointerElement;
340+
this.pointerElement = new TrainrunSectionNodePair(undefined, undefined);
341+
return this.currentElement;
342+
}
343+
return super.next();
344+
}
345+
}

0 commit comments

Comments
 (0)