From 638e4a648fae665866f1cdfee2bb5c73350383ec Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Tue, 14 Oct 2025 13:57:08 +0200 Subject: [PATCH] aggiunta la preview dei movimenti di tipo duration --- target_simulator/core/models.py | 6 ++++-- target_simulator/gui/ppi_display.py | 32 +++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/target_simulator/core/models.py b/target_simulator/core/models.py index 1ef3b8a..16443e8 100644 --- a/target_simulator/core/models.py +++ b/target_simulator/core/models.py @@ -122,8 +122,10 @@ class Target: total_duration = sum(wp.duration_s or 0.0 for wp in self.trajectory if wp.duration_s) # Create a time mapping for each point in the spline path - self._spline_point_times = [i * (total_duration / (len(self._spline_path) - 1)) for i in range(len(self._spline_path))] - if not self._spline_point_times: self._spline_point_times = [0.0] + if self._spline_path is not None and len(self._spline_path) > 1: + self._spline_point_times = [i * (total_duration / (len(self._spline_path) - 1)) for i in range(len(self._spline_path))] + else: + self._spline_point_times = [0.0] self._update_current_polar_coords() diff --git a/target_simulator/gui/ppi_display.py b/target_simulator/gui/ppi_display.py index e6502a9..4d243d9 100644 --- a/target_simulator/gui/ppi_display.py +++ b/target_simulator/gui/ppi_display.py @@ -12,6 +12,7 @@ import numpy as np import copy from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg +from target_simulator.core.models import NM_TO_FT # Use absolute imports from target_simulator.core.models import Target, Waypoint, ManeuverType @@ -192,8 +193,35 @@ class PPIDisplay(ttk.Frame): return # Classic preview (polyline) SOLO se spline non attiva # (la preview spline cancella la classica) - thetas = [math.radians(getattr(wp, 'target_azimuth_deg', 0)) for wp in waypoints] - rs = [getattr(wp, 'target_range_nm', 0) for wp in waypoints] + # Costruisci la lista dei punti da visualizzare + points = [] + for i, wp in enumerate(waypoints): + if getattr(wp, 'maneuver_type', None) == ManeuverType.FLY_TO_POINT: + # Usa range/azimuth + r = getattr(wp, 'target_range_nm', 0) + theta = math.radians(getattr(wp, 'target_azimuth_deg', 0)) + points.append((theta, r, wp)) + elif getattr(wp, 'maneuver_type', None) == ManeuverType.FLY_FOR_DURATION: + # Calcola punto terminale + # Serve punto di partenza + if i == 0: + # Se non c'รจ punto iniziale, ignora + continue + prev_wp = waypoints[i-1] + r0 = getattr(prev_wp, 'target_range_nm', 0) + theta0 = math.radians(getattr(prev_wp, 'target_azimuth_deg', 0)) + vel_fps = getattr(wp, 'target_velocity_fps', 0) + vel_nmps = vel_fps / NM_TO_FT if vel_fps else 0 + duration = getattr(wp, 'duration_s', 0) + heading_deg = getattr(wp, 'target_heading_deg', 0) + heading_rad = math.radians(heading_deg) + # Calcola delta x/y in coordinate polari + dr = vel_nmps * duration + theta1 = theta0 + heading_rad + r1 = r0 + dr + points.append((theta1, r1, wp)) + thetas = [p[0] for p in points] + rs = [p[1] for p in points] if len(thetas) == 1: # Mostra solo il punto iniziale con stile simulazione self._preview_artist.set_data([], [])