From 8eaa604a7dc8ef487ff36ad048e3255d931ef049 Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Wed, 8 Oct 2025 14:59:45 +0200 Subject: [PATCH] fix scale between ppi_display and main_view --- target_simulator/gui/ppi_display.py | 42 ++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/target_simulator/gui/ppi_display.py b/target_simulator/gui/ppi_display.py index 55d5e97..d5e4664 100644 --- a/target_simulator/gui/ppi_display.py +++ b/target_simulator/gui/ppi_display.py @@ -146,28 +146,52 @@ class PPIDisplay(ttk.Frame): self.canvas.draw() def draw_trajectory_preview(self, initial_state: dict, waypoints: List[Waypoint]): - # (This method is unchanged) + """Simulates and draws a trajectory preview without auto-zooming.""" self.clear_previews() - if not waypoints: self.canvas.draw(); return + + # --- NUOVA LOGICA --- + # Assicura che l'asse Y sia sincronizzato con la combobox prima di disegnare. + self._on_range_selected() + + if not waypoints: + # Disegna solo il punto di partenza se non ci sono waypoint + start_r, start_theta = initial_state['initial_range_nm'], math.radians(initial_state['initial_azimuth_deg']) + self._start_plot.set_data([start_theta], [start_r]) + self.canvas.draw() + return + temp_target = Target(target_id=0, **initial_state, trajectory=copy.deepcopy(waypoints)) - path_thetas, path_rs = [], []; wp_thetas, wp_rs = [], [] + + path_thetas, path_rs = [], [] + wp_thetas, wp_rs = [], [] + total_duration = sum(wp.duration_s for wp in waypoints) sim_time, time_step = 0.0, 0.5 - path_thetas.append(math.radians(temp_target.current_azimuth_deg)); path_rs.append(temp_target.current_range_nm) + + path_thetas.append(math.radians(temp_target.current_azimuth_deg)) + path_rs.append(temp_target.current_range_nm) + while sim_time < total_duration: wp_index_before = temp_target._current_waypoint_index temp_target.update_state(time_step) - path_thetas.append(math.radians(temp_target.current_azimuth_deg)); path_rs.append(temp_target.current_range_nm) + path_thetas.append(math.radians(temp_target.current_azimuth_deg)) + path_rs.append(temp_target.current_range_nm) + if temp_target._current_waypoint_index > wp_index_before: - wp_thetas.append(path_thetas[-2]); wp_rs.append(path_rs[-2]) + wp_thetas.append(path_thetas[-2]) + wp_rs.append(path_rs[-2]) sim_time += time_step + start_r, start_theta = initial_state['initial_range_nm'], math.radians(initial_state['initial_azimuth_deg']) self._start_plot.set_data([start_theta], [start_r]) self._waypoints_plot.set_data(wp_thetas, wp_rs) self._path_plot.set_data(path_thetas, path_rs) - max_r = max(path_rs) if path_rs else start_r - self.ax.set_ylim(0, max_r * 1.1) - self._update_scan_lines() # Also update scan lines to fit preview if it zooms out + + # --- LOGICA DI AUTO-ZOOM RIMOSSA --- + # max_r = max(path_rs) if path_rs else start_r + # self.ax.set_ylim(0, max_r * 1.1) + + self._update_scan_lines() self.canvas.draw() def clear_previews(self):