Skip to content

Commit 216125c

Browse files
committed
wip: fis ts chain ports assignation
Signed-off-by: Louis Greiner <[email protected]>
1 parent 6ac86fd commit 216125c

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

src/app/services/data/node.service.ts

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,16 @@ export class NodeService implements OnDestroy {
178178
initPortOrdering() {
179179
this.nodesStore.nodes.forEach((node) => {
180180
node.getPorts().forEach((port) => {
181-
const oppositeNode = node.getOppositeNode(port.getTrainrunSection());
181+
const oppositeExpandedNode = this.getOppositeExpandedNode(port.getTrainrunSection(), node);
182182
const portAlignments = VisAVisPortPlacement.placePortsOnSourceAndTargetNode(
183183
node,
184-
oppositeNode,
184+
oppositeExpandedNode,
185185
);
186+
console.log(port, portAlignments);
186187
port.setPositionAlignment(portAlignments.sourcePortPlacement);
187-
oppositeNode
188+
oppositeExpandedNode
188189
.getPortOfTrainrunSection(port.getTrainrunSection().getId())
189-
.setPositionAlignment(portAlignments.targetPortPlacement);
190+
?.setPositionAlignment(portAlignments.targetPortPlacement);
190191
});
191192

192193
node.updateTransitionsAndConnections();
@@ -479,8 +480,15 @@ export class NodeService implements OnDestroy {
479480
}
480481

481482
addPortsToNodes(sourceNodeId: number, targetNodeId: number, trainrunSection: TrainrunSection) {
482-
const sourceNode = this.getNodeFromId(sourceNodeId);
483-
const targetNode = this.getNodeFromId(targetNodeId);
483+
const sourceNode = this.getOppositeExpandedNode(
484+
trainrunSection,
485+
this.getNodeFromId(targetNodeId),
486+
);
487+
const targetNode = this.getOppositeExpandedNode(
488+
trainrunSection,
489+
this.getNodeFromId(sourceNodeId),
490+
);
491+
// console.log(trainrunSection, sourceNode, targetNode);
484492
const portAlignments = VisAVisPortPlacement.placePortsOnSourceAndTargetNode(
485493
sourceNode,
486494
targetNode,
@@ -1128,6 +1136,30 @@ export class NodeService implements OnDestroy {
11281136
return {minCoordX: minX, minCoordY: minY, maxCoordX: maxX, maxCoordY: maxY};
11291137
}
11301138

1139+
getOppositeExpandedNode(trainrunSection: TrainrunSection, currentNode: Node): Node | undefined {
1140+
const groups = this.trainrunSectionService.groupTrainrunSectionsIntoChains(
1141+
this.trainrunSectionService.getAllTrainrunSectionsForTrainrun(
1142+
trainrunSection.getTrainrunId(),
1143+
),
1144+
);
1145+
// keep only the groups which contain the given trainrun section
1146+
const filteredGroup = groups.find(
1147+
(group) => group.find((trs) => trs.getId() === trainrunSection.getId()) !== undefined,
1148+
);
1149+
if (filteredGroup === undefined) {
1150+
return undefined;
1151+
}
1152+
if (currentNode.getId() === trainrunSection.getSourceNodeId()) {
1153+
// get target node of the last trainrun section in the group
1154+
const lastTrainrunSection = filteredGroup.at(-1);
1155+
return this.getNodeFromId(lastTrainrunSection.getTargetNodeId());
1156+
} else {
1157+
// get source node of the first trainrun section in the group
1158+
const firstTrainrunSection = filteredGroup.at(0);
1159+
return this.getNodeFromId(firstTrainrunSection.getSourceNodeId());
1160+
}
1161+
}
1162+
11311163
private deleteNodeWithoutUpdate(nodeId: number, enforceUpdate = true) {
11321164
const node = this.getNodeFromId(nodeId);
11331165
const connectedTrainrunSections = node.getConnectedTrainrunSections();
@@ -1152,17 +1184,20 @@ export class NodeService implements OnDestroy {
11521184
node.setPosition(newPositionX, newPositionY);
11531185
if (dragEnd) {
11541186
node.getPorts().forEach((port) => {
1155-
const oppositeNode = node.getOppositeNode(port.getTrainrunSection());
1187+
const oppositeExpandedNode = this.getOppositeExpandedNode(port.getTrainrunSection(), node);
11561188
const portAlignments = VisAVisPortPlacement.placePortsOnSourceAndTargetNode(
11571189
node,
1158-
oppositeNode,
1190+
oppositeExpandedNode,
11591191
);
11601192
port.setPositionAlignment(portAlignments.sourcePortPlacement);
1161-
oppositeNode
1193+
oppositeExpandedNode
11621194
.getPortOfTrainrunSection(port.getTrainrunSection().getId())
1163-
.setPositionAlignment(portAlignments.targetPortPlacement);
1164-
oppositeNode.updateTransitionsAndConnections();
1165-
this.trainrunSectionService.updateTrainrunSectionRouting(oppositeNode, enforceUpdate);
1195+
?.setPositionAlignment(portAlignments.targetPortPlacement);
1196+
oppositeExpandedNode.updateTransitionsAndConnections();
1197+
this.trainrunSectionService.updateTrainrunSectionRouting(
1198+
oppositeExpandedNode,
1199+
enforceUpdate,
1200+
);
11661201
});
11671202
node.reorderAllPorts();
11681203
this.operation.emit(new NodeOperation(OperationType.update, node));

src/app/services/data/trainrunsection.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,14 +976,18 @@ export class TrainrunSectionService implements OnDestroy {
976976

977977
node2.replaceTrainrunSectionOnPort(trainrunSection1, trainrunSection2);
978978

979+
const sourceExpandedNode = this.nodeService.getOppositeExpandedNode(trainrunSection1, node2);
980+
const targetExpandedNode = this.nodeService.getOppositeExpandedNode(trainrunSection1, node1);
981+
979982
trainrunSection1.setTargetNode(nodeIntermediate);
980-
nodeIntermediate.addPortWithRespectToOppositeNode(node1, trainrunSection1);
981-
node1.reAlignPortWithRespectToOppositeNode(nodeIntermediate, trainrunSection1);
983+
node2.addPortWithRespectToOppositeNode(sourceExpandedNode, trainrunSection1);
984+
node1.reAlignPortWithRespectToOppositeNode(targetExpandedNode, trainrunSection1);
985+
// console.log(node1, node2);
982986

983987
trainrunSection2.setSourceNode(nodeIntermediate);
984988
trainrunSection2.setTargetNode(node2);
985-
nodeIntermediate.addPortWithRespectToOppositeNode(node2, trainrunSection2);
986-
node2.reAlignPortWithRespectToOppositeNode(nodeIntermediate, trainrunSection2);
989+
node1.addPortWithRespectToOppositeNode(targetExpandedNode, trainrunSection2);
990+
node2.reAlignPortWithRespectToOppositeNode(sourceExpandedNode, trainrunSection2);
987991

988992
this.reRouteAffectedTrainrunSections(node1.getId(), nodeIntermediate.getId());
989993
this.reRouteAffectedTrainrunSections(node2.getId(), nodeIntermediate.getId());

0 commit comments

Comments
 (0)