FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
types.ts
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
3
4import { z } from 'zod';
5import type {
6 AssetLibraryTemplate,
7 AssetTemplateInsertionResult,
8} from '../assetTemplates';
9import {
10 AntennaSchema,
11 FixedRotationSchema,
12 GlobalParametersSchema,
13 MotionPathSchema,
14 NoiseEntrySchema,
15 PlatformComponentSchema,
16 PlatformSchema,
17 PositionWaypointSchema,
18 RotationPathSchema,
19 RotationWaypointSchema,
20 ScenarioDataSchema,
21 SchedulePeriodSchema,
22 TimingSchema,
23 WaveformSchema,
24} from '../scenarioSchema';
25
26// --- Zod Inferred Types ---
27export type GlobalParameters = z.infer<typeof GlobalParametersSchema>;
28export type Waveform = z.infer<typeof WaveformSchema>;
29export type NoiseEntry = z.infer<typeof NoiseEntrySchema>;
30export type Timing = z.infer<typeof TimingSchema>;
31export type Antenna = z.infer<typeof AntennaSchema>;
32export type PositionWaypoint = z.infer<typeof PositionWaypointSchema>;
33export type MotionPath = z.infer<typeof MotionPathSchema>;
34export type FixedRotation = z.infer<typeof FixedRotationSchema>;
35export type RotationWaypoint = z.infer<typeof RotationWaypointSchema>;
36export type RotationPath = z.infer<typeof RotationPathSchema>;
37export type PlatformComponent = z.infer<typeof PlatformComponentSchema>;
38export type SchedulePeriod = z.infer<typeof SchedulePeriodSchema>;
39export type Platform = z.infer<typeof PlatformSchema> & {
40 pathPoints?: {
41 x: number;
42 y: number;
43 z: number;
44 vx: number;
45 vy: number;
46 vz: number;
47 }[];
48 rotationPathPoints?: { azimuth: number; elevation: number }[];
49};
50
51// --- Visibility Type Definitions ---
52export type VisualizationLayers = {
53 showAxes: boolean;
54 showPatterns: boolean;
55 showBoresights: boolean;
56 showLinks: boolean;
57 showLinkLabels: boolean;
58 showLinkMonostatic: boolean;
59 showLinkIlluminator: boolean;
60 showLinkScattered: boolean;
61 showLinkDirect: boolean;
62 showVelocities: boolean;
63 showPlatforms: boolean;
64 showPlatformLabels: boolean;
65 showMotionPaths: boolean;
66};
67
68// --- Component Type Definitions ---
69export type MonostaticComponent = Extract<
70 PlatformComponent,
71 { type: 'monostatic' }
72>;
73export type TransmitterComponent = Extract<
74 PlatformComponent,
75 { type: 'transmitter' }
76>;
77export type ReceiverComponent = Extract<
78 PlatformComponent,
79 { type: 'receiver' }
80>;
81export type TargetComponent = Extract<PlatformComponent, { type: 'target' }>;
82
83export type ScenarioData = Omit<
84 z.infer<typeof ScenarioDataSchema>,
85 'platforms'
86> & {
87 platforms: Platform[];
88};
89
90export type ScenarioItem =
91 | GlobalParameters
92 | Waveform
93 | Timing
94 | Antenna
95 | Platform;
96
97// --- Store Shape ---
98export type ViewControlAction = {
99 type: 'frame' | 'focus' | 'follow' | null;
100 targetId?: string;
101 timestamp: number;
102};
103
104export type NotificationSeverity = 'success' | 'warning' | 'error';
105
106export type NotificationState = {
107 open: boolean;
108 message: string;
109 severity: NotificationSeverity;
110};
111
112export type ScenarioState = ScenarioData & {
113 selectedItemId: string | null;
114 selectedComponentId: string | null;
115 isDirty: boolean;
116 isPlaying: boolean;
117 currentTime: number;
118 targetPlaybackDuration: number | null;
119 isBackendSyncing: boolean;
120 backendVersion: number;
121 scenarioFilePath: string | null;
122 outputDirectory: string | null;
123 antennaPreviewErrors: Record<string, string>;
124 notificationSnackbar: NotificationState;
125 notificationQueue: NotificationState[];
126 viewControlAction: ViewControlAction;
127 visibility: VisualizationLayers;
128};
129
130// --- Action Slice Types ---
131export type AssetActions = {
132 addWaveform: () => void;
133 addTiming: () => void;
134 addAntenna: () => void;
135 addNoiseEntry: (timingId: string) => void;
136 removeNoiseEntry: (timingId: string, entryId: string) => void;
137 setAntennaPattern: (
138 antennaId: string,
139 newPattern: Antenna['pattern']
140 ) => void;
141};
142
143export type PlatformActions = {
144 addPlatform: () => void;
145 addPositionWaypoint: (platformId: string) => void;
146 removePositionWaypoint: (platformId: string, waypointId: string) => void;
147 addRotationWaypoint: (platformId: string) => void;
148 removeRotationWaypoint: (platformId: string, waypointId: string) => void;
149 addPlatformComponent: (
150 platformId: string,
151 componentType: PlatformComponent['type']
152 ) => void;
153 removePlatformComponent: (platformId: string, componentId: string) => void;
154 setPlatformRcsModel: (
155 platformId: string,
156 componentId: string,
157 newModel: TargetComponent['rcs_model']
158 ) => void;
159 fetchPlatformPath: (platformId: string) => Promise<void>;
160};
161
162export type ScenarioActions = {
163 selectItem: (itemId: string | null) => void;
164 updateItem: (itemId: string, propertyPath: string, value: unknown) => void;
165 setRotationAngleUnit: (
166 unit: GlobalParameters['rotationAngleUnit'],
167 convertExisting: boolean
168 ) => void;
169 removeItem: (itemId: string) => void;
170 loadScenario: (backendData: unknown) => void;
171 resetScenario: () => void;
172 setScenarioFilePath: (path: string | null) => void;
173 setOutputDirectory: (dir: string | null) => void;
174 insertAssetTemplate: (
175 template: AssetLibraryTemplate
176 ) => AssetTemplateInsertionResult;
177};
178
179export type BackendActions = {
180 syncBackend: () => Promise<void>;
181 fetchFromBackend: () => Promise<void>;
182};
183
184export type PlaybackActions = {
185 togglePlayPause: () => void;
186 setCurrentTime: (time: number | ((prevTime: number) => number)) => void;
187 setTargetPlaybackDuration: (duration: number | null) => void;
188};
189
190export type ErrorActions = {
191 showError: (message: string) => void;
192 showSuccess: (message: string) => void;
193 showWarning: (message: string) => void;
194 hideNotification: () => void;
195 advanceNotification: () => void;
196 setAntennaPreviewError: (antennaId: string, message: string) => void;
197 clearAntennaPreviewError: (antennaId: string) => void;
198};
199
200export type ViewControlActions = {
201 frameScene: () => void;
202 focusOnItem: (itemId: string) => void;
203 toggleFollowItem: (itemId: string) => void;
204 clearViewControlAction: () => void;
205 toggleLayer: (layer: keyof VisualizationLayers) => void;
206};
207
208// --- Full Store Type ---
209export type FullScenarioActions = AssetActions &
210 PlatformActions &
211 ScenarioActions &
212 BackendActions &
213 PlaybackActions &
214 ErrorActions &
215 ViewControlActions;
216
217export type ScenarioStore = ScenarioState & FullScenarioActions;