diff --git a/App.xaml b/App.xaml index 62a4792..80f30c2 100644 --- a/App.xaml +++ b/App.xaml @@ -21,6 +21,7 @@ TargetType="{x:Type osExtraccion:osBuscarCoincidencias}" /> + diff --git a/MainViewModel.cs b/MainViewModel.cs index 4f38103..359ff6a 100644 --- a/MainViewModel.cs +++ b/MainViewModel.cs @@ -33,6 +33,10 @@ namespace CtrEditor private double stopwatch_SimPLC_last; private double stopwatch_SimModel_last; + private double accumulatedSimTime; + private double accumulatedPlcTime; + private int simSampleCount; + private int plcSampleCount; private float TiempoDesdeStartSimulacion; private bool Debug_SimulacionCreado = false; @@ -41,6 +45,7 @@ namespace CtrEditor private readonly DispatcherTimer _timerSimulacion; private readonly DispatcherTimer _timerPLCUpdate; + private readonly DispatcherTimer _timerDisplayUpdate; public Canvas MainCanvas; @@ -327,7 +332,7 @@ namespace CtrEditor PLCViewModel = new PLCViewModel(); _timerPLCUpdate = new DispatcherTimer(); - _timerPLCUpdate.Interval = TimeSpan.FromMilliseconds(10); // ajusta el intervalo según sea necesario + _timerPLCUpdate.Interval = TimeSpan.FromMilliseconds(10); // Restaurado a 10ms _timerPLCUpdate.Tick += OnRefreshEvent; InitializeTipoSimulableList(); @@ -335,9 +340,15 @@ namespace CtrEditor ItemDoubleClickCommand = new ParameterizedRelayCommand(ExecuteDoubleClick); _timerSimulacion = new DispatcherTimer(); - _timerSimulacion.Interval = TimeSpan.FromMilliseconds(10); // ajusta el intervalo según sea necesario + _timerSimulacion.Interval = TimeSpan.FromMilliseconds(10); // Restaurado a 10ms _timerSimulacion.Tick += OnTickSimulacion; + // Nuevo timer para actualización de display + _timerDisplayUpdate = new DispatcherTimer(); + _timerDisplayUpdate.Interval = TimeSpan.FromMilliseconds(250); + _timerDisplayUpdate.Tick += OnDisplayUpdate; + _timerDisplayUpdate.Start(); + StartSimulationCommand = new RelayCommand(StartSimulation); StopSimulationCommand = new RelayCommand(StopSimulation); @@ -636,6 +647,9 @@ namespace CtrEditor { IsSimulationRunning = true; + // Ocultar rectángulos de selección antes de iniciar la simulación + _objectManager.UpdateSelectionVisuals(); + foreach (var objetoSimulable in ObjetosSimulables) objetoSimulable.UpdateGeometryStart(); @@ -660,6 +674,9 @@ namespace CtrEditor Debug_SimulacionCreado = false; } _timerSimulacion.Stop(); + + // Restaurar los rectángulos de selección si hay objetos seleccionados + _objectManager.UpdateSelectionVisuals(); } private void OnTickSimulacion(object sender, EventArgs e) @@ -669,6 +686,10 @@ namespace CtrEditor // Detener el cronómetro y obtener el tiempo transcurrido en milisegundos var elapsedMilliseconds = stopwatch_Sim.Elapsed.TotalMilliseconds - stopwatch_SimModel_last; stopwatch_SimModel_last = stopwatch_Sim.Elapsed.TotalMilliseconds; + + // Acumular tiempo para el promedio + accumulatedSimTime += elapsedMilliseconds; + simSampleCount++; // Eliminar el diseño de Debug luego de 2 segundos if (TiempoDesdeStartSimulacion > 12000) @@ -724,6 +745,10 @@ namespace CtrEditor var elapsedMilliseconds = stopwatch_Sim.Elapsed.TotalMilliseconds - stopwatch_SimPLC_last; stopwatch_SimPLC_last = stopwatch_Sim.Elapsed.TotalMilliseconds; + // Acumular tiempo para el promedio + accumulatedPlcTime += elapsedMilliseconds; + plcSampleCount++; + // Reiniciar el cronómetro para la próxima medición var remainingObjetosSimulables = ObjetosSimulables.Except(objetosSimulablesLlamados).ToList(); @@ -897,6 +922,29 @@ namespace CtrEditor inhibitSaveChangesControl = false; } } + + [ObservableProperty] + private double simulationSpeed; + + [ObservableProperty] + private double plcUpdateSpeed; + + private void OnDisplayUpdate(object? sender, EventArgs e) + { + if (simSampleCount > 0) + { + SimulationSpeed = accumulatedSimTime / simSampleCount; + accumulatedSimTime = 0; + simSampleCount = 0; + } + + if (plcSampleCount > 0) + { + PlcUpdateSpeed = accumulatedPlcTime / plcSampleCount; + accumulatedPlcTime = 0; + plcSampleCount = 0; + } + } } public class SimulationData { diff --git a/MainWindow.xaml b/MainWindow.xaml index 334aecd..c22e481 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -105,13 +105,27 @@ - + + + + + + + + + + + + + - + + + + + + + + + + + + + +