From cb29af789f07558f1ccc037ac5ac2b88db8e933a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 16 Jul 2024 12:39:25 +0200 Subject: [PATCH] front: create node transitions in NGE --- .../components/MacroEditor/import.ts | 20 ++++++++++++++++++- .../components/MacroEditor/types.ts | 9 ++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/front/src/applications/operationalStudies/components/MacroEditor/import.ts b/front/src/applications/operationalStudies/components/MacroEditor/import.ts index 18749e5d0de..a68634c6f96 100644 --- a/front/src/applications/operationalStudies/components/MacroEditor/import.ts +++ b/front/src/applications/operationalStudies/components/MacroEditor/import.ts @@ -8,6 +8,7 @@ import type { AppDispatch } from 'store'; import type { Node, + Port, Trainrun, TrainrunSection, TrainrunCategory, @@ -241,6 +242,18 @@ const importTimetable = async ( return port; }; + let transitionId = 0; + const createTransition = (port1Id: number, port2Id: number) => { + const transition = { + id: transitionId, + port1Id, + port2Id, + isNonStopTransit: false, + }; + transitionId += 1; + return transition; + }; + let trainrunSectionId = 0; const trainrunSections: TrainrunSection[] = trainSchedules .map((trainSchedule) => { @@ -249,6 +262,7 @@ const importTimetable = async ( if (!foundAllOps) { return []; } + let prevPort: Port | null = null; return ops.slice(0, -1).map((sourceOp, i) => { const sourceNodeId = sourceOp!.obj_id; const targetNodeId = ops[i + 1]!.obj_id; @@ -269,7 +283,11 @@ const importTimetable = async ( sourceNode.ports.push(sourcePort); targetNode.ports.push(targetPort); - // TODO: create transitions between ports + if (prevPort) { + const transition = createTransition(prevPort.id, sourcePort.id); + sourceNode.transitions.push(transition); + } + prevPort = targetPort; const trainrunSection = { id: trainrunSectionId, diff --git a/front/src/applications/operationalStudies/components/MacroEditor/types.ts b/front/src/applications/operationalStudies/components/MacroEditor/types.ts index 31c494e1d66..a3b93e705f0 100644 --- a/front/src/applications/operationalStudies/components/MacroEditor/types.ts +++ b/front/src/applications/operationalStudies/components/MacroEditor/types.ts @@ -14,7 +14,7 @@ export type Node = { positionX: number; positionY: number; ports: Port[]; - transitions: unknown[]; + transitions: Transition[]; connections: unknown[]; resourceId: number; /** Number of tracks where train can stop */ @@ -34,6 +34,13 @@ export type Port = { trainrunSectionId: number; }; +export type Transition = { + id: number; + port1Id: number; + port2Id: number; + isNonStopTransit: boolean; +}; + export enum PortAlignment { Top, Bottom,