Skip to content

Commit 3feddac

Browse files
committed
front: manchette: display waypoints added with map click
1 parent a419de4 commit 3feddac

File tree

6 files changed

+67
-11
lines changed

6 files changed

+67
-11
lines changed

front/public/locales/en/simulation.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"used": "used"
3535
},
3636
"projectionInProgress": "Projection in progress: {{ count }}/{{ total }} trains",
37+
"requestedPoint": "requested point ({{ count }})",
3738
"reset": "Reset the chart",
3839
"resetTimer": "Reset timer",
3940
"rotate": "Rotate the chart",

front/public/locales/fr/simulation.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"used": "utilisée"
3535
},
3636
"projectionInProgress": "Projection en cours: {{ count }}/{{ total }} trains",
37+
"requestedPoint": "point demandé ({{ count }})",
3738
"reset": "Réinitialiser le graphique",
3839
"resetTimer": "Réinitialiser le compteur",
3940
"rotate": "Pivoter le graphique",

front/src/applications/operationalStudies/hooks/useScenarioData.ts

+6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ const useScenarioData = () => {
9292
[projectedTrainsById]
9393
);
9494

95+
const trainScheduleUsedForProjection = useMemo(
96+
() => trainSchedules?.find((trainSchedule) => trainSchedule.id === trainIdUsedForProjection),
97+
[trainIdUsedForProjection, trainSchedules]
98+
);
99+
95100
useEffect(() => {
96101
if (!rawTrainSchedules) {
97102
setTrainSchedules(undefined);
@@ -193,6 +198,7 @@ const useScenarioData = () => {
193198
infra: { infra, isInfraLoaded, reloadCount },
194199
trainScheduleSummaries,
195200
trainSchedules,
201+
trainScheduleUsedForProjection,
196202
trainIdUsedForProjection,
197203
projectedTrains,
198204
simulationResults,

front/src/applications/operationalStudies/views/v2/ScenarioV2.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const Scenario = () => {
9797
infra: { infra, isInfraLoaded, reloadCount },
9898
trainScheduleSummaries,
9999
trainSchedules,
100+
trainScheduleUsedForProjection,
100101
trainIdUsedForProjection,
101102
projectedTrains,
102103
simulationResults,
@@ -308,6 +309,7 @@ const Scenario = () => {
308309
collapsedTimetable={collapsedTimetable}
309310
spaceTimeData={projectedTrains}
310311
simulationResults={simulationResults}
312+
trainScheduleUsedForProjection={trainScheduleUsedForProjection}
311313
trainIdUsedForProjection={trainIdUsedForProjection}
312314
infraId={infraId}
313315
timetableTrainNb={timetable.train_ids.length}

front/src/applications/operationalStudies/views/v2/SimulationResultsV2.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useSelector } from 'react-redux';
88
import { Rnd } from 'react-rnd';
99

1010
import type { SimulationResults, TrainSpaceTimeData } from 'applications/operationalStudies/types';
11+
import type { TrainScheduleResult } from 'common/api/osrdEditoastApi';
1112
import SimulationWarpedMap from 'common/Map/WarpedMap/SimulationWarpedMap';
1213
import { getScaleDomainFromValuesV2 } from 'modules/simulationResult/components/ChartHelpers/getScaleDomainFromValues';
1314
import SimulationResultsMapV2 from 'modules/simulationResult/components/SimulationResultsMapV2';
@@ -33,6 +34,7 @@ type SimulationResultsV2Props = {
3334
collapsedTimetable: boolean;
3435
spaceTimeData?: TrainSpaceTimeData[];
3536
infraId?: number;
37+
trainScheduleUsedForProjection?: TrainScheduleResult;
3638
trainIdUsedForProjection?: number;
3739
simulationResults: SimulationResults;
3840
timetableTrainNb: number;
@@ -42,6 +44,7 @@ const SimulationResultsV2 = ({
4244
collapsedTimetable,
4345
spaceTimeData,
4446
infraId,
47+
trainScheduleUsedForProjection,
4548
trainIdUsedForProjection,
4649
simulationResults: {
4750
selectedTrainSchedule,
@@ -88,6 +91,7 @@ const SimulationResultsV2 = ({
8891
);
8992

9093
const projectedOperationalPoints = useGetProjectedTrainOperationalPoints(
94+
trainScheduleUsedForProjection,
9195
trainIdUsedForProjection,
9296
infraId
9397
);

front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts

+53-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
import { useEffect, useState } from 'react';
22

3+
import { useTranslation } from 'react-i18next';
4+
35
import { STDCM_TRAIN_ID } from 'applications/stdcm/consts';
46
import {
57
osrdEditoastApi,
68
type PathProperties,
7-
type PostInfraByInfraIdPathPropertiesApiArg,
9+
type TrainScheduleResult,
810
} from 'common/api/osrdEditoastApi';
11+
import { addElementAtIndex } from 'utils/array';
912

1013
const useGetProjectedTrainOperationalPoints = (
14+
trainScheduleUsedForProjection?: TrainScheduleResult,
1115
trainIdUsedForProjection?: number,
1216
infraId?: number
1317
) => {
18+
const { t } = useTranslation('simulation');
1419
const [operationalPoints, setOperationalPoints] = useState<
1520
NonNullable<PathProperties['operational_points']>
1621
>([]);
1722

1823
const { data: pathfindingResult } = osrdEditoastApi.endpoints.getTrainScheduleByIdPath.useQuery(
1924
{
20-
id: trainIdUsedForProjection as number,
21-
infraId: infraId as number,
25+
id: trainIdUsedForProjection!,
26+
infraId: infraId!,
2227
},
2328
{
2429
skip: !trainIdUsedForProjection || !infraId || trainIdUsedForProjection === STDCM_TRAIN_ID,
@@ -30,23 +35,60 @@ const useGetProjectedTrainOperationalPoints = (
3035

3136
useEffect(() => {
3237
const getOperationalPoints = async () => {
33-
if (infraId && pathfindingResult && pathfindingResult.status === 'success') {
34-
const pathPropertiesParams: PostInfraByInfraIdPathPropertiesApiArg = {
38+
if (infraId && trainScheduleUsedForProjection && pathfindingResult?.status === 'success') {
39+
const { operational_points } = await postPathProperties({
3540
infraId,
3641
props: ['operational_points'],
3742
pathPropertiesInput: {
3843
track_section_ranges: pathfindingResult.track_section_ranges,
3944
},
40-
};
41-
const { operational_points } = await postPathProperties(pathPropertiesParams).unwrap();
45+
}).unwrap();
46+
47+
let operationalPointsWithAllWaypoints = operational_points!;
48+
49+
// Check if there are vias added by map click and insert them in the operational points
50+
let waypointCounter = 1;
51+
52+
trainScheduleUsedForProjection.path.forEach((step, i) => {
53+
if (!('track' in step)) return;
54+
55+
const positionOnPath = pathfindingResult.path_item_positions[i];
56+
const indexToInsert = operationalPointsWithAllWaypoints.findIndex(
57+
(op) => op.position >= positionOnPath
58+
);
59+
60+
const formattedStep: NonNullable<PathProperties['operational_points']>[number] = {
61+
id: step.id,
62+
extensions: {
63+
identifier: {
64+
name: t('requestedPoint', { count: waypointCounter }),
65+
uic: 0,
66+
},
67+
},
68+
part: { track: step.track, position: step.offset },
69+
position: positionOnPath,
70+
};
71+
72+
waypointCounter += 1;
73+
74+
// If we can't find any op position greater than the current step position, we add it at the end
75+
if (indexToInsert === -1) {
76+
operationalPointsWithAllWaypoints.push(formattedStep);
77+
return;
78+
}
79+
80+
operationalPointsWithAllWaypoints = addElementAtIndex(
81+
operationalPointsWithAllWaypoints,
82+
indexToInsert,
83+
formattedStep
84+
);
85+
});
4286

43-
setOperationalPoints(
44-
operational_points as NonNullable<PathProperties['operational_points']>
45-
);
87+
setOperationalPoints(operationalPointsWithAllWaypoints);
4688
}
4789
};
4890
getOperationalPoints();
49-
}, [pathfindingResult, infraId]);
91+
}, [pathfindingResult, infraId, t]);
5092

5193
return operationalPoints;
5294
};

0 commit comments

Comments
 (0)