Falta remover los objetos del World de simulacion

This commit is contained in:
Miguel 2024-05-18 15:35:46 +02:00
parent 9ed8a0b7bd
commit 9cf86d001e
4 changed files with 38 additions and 9 deletions

View File

@ -39,6 +39,8 @@ namespace CtrEditor
public ObservableCollection<TipoSimulable> ListaOsBase { get; } = new ObservableCollection<TipoSimulable>(); public ObservableCollection<TipoSimulable> ListaOsBase { get; } = new ObservableCollection<TipoSimulable>();
public Stopwatch stopwatch_PLCRefresh; public Stopwatch stopwatch_PLCRefresh;
public Stopwatch stopwatch_SimRefresh; public Stopwatch stopwatch_SimRefresh;
private float TiempoDesdeStartSimulacion;
private bool Debug_SimulacionCreado = false;
public SimulationManagerFP simulationManager = new SimulationManagerFP(); public SimulationManagerFP simulationManager = new SimulationManagerFP();
@ -326,6 +328,8 @@ namespace CtrEditor
objetoSimulable.UpdateGeometryStart(); objetoSimulable.UpdateGeometryStart();
simulationManager.Debug_DrawInitialBodies(); simulationManager.Debug_DrawInitialBodies();
TiempoDesdeStartSimulacion = 0;
Debug_SimulacionCreado = true;
_timerSimulacion.Start(); _timerSimulacion.Start();
simulationManager.stopwatch.Start(); simulationManager.stopwatch.Start();
@ -335,6 +339,11 @@ namespace CtrEditor
private void StopSimulation() private void StopSimulation()
{ {
if (Debug_SimulacionCreado)
{
simulationManager.Debug_ClearSimulationShapes();
Debug_SimulacionCreado = false;
}
_timerSimulacion.Stop(); _timerSimulacion.Stop();
simulationManager.stopwatch.Stop(); simulationManager.stopwatch.Stop();
stopwatch_SimRefresh.Stop(); stopwatch_SimRefresh.Stop();
@ -347,6 +356,12 @@ namespace CtrEditor
stopwatch_SimRefresh.Stop(); stopwatch_SimRefresh.Stop();
float elapsedMilliseconds = (float)stopwatch_SimRefresh.Elapsed.TotalMilliseconds; float elapsedMilliseconds = (float)stopwatch_SimRefresh.Elapsed.TotalMilliseconds;
// Eliminar el diseño de Debug luego de 2 segundos
if (TiempoDesdeStartSimulacion > 2000)
simulationManager.Debug_ClearSimulationShapes();
else
TiempoDesdeStartSimulacion += elapsedMilliseconds;
// Reiniciar el cronómetro para la próxima medición // Reiniciar el cronómetro para la próxima medición
stopwatch_SimRefresh.Restart(); stopwatch_SimRefresh.Restart();

View File

@ -10,23 +10,29 @@
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<Storyboard x:Key="PulsingStoryboard" RepeatBehavior="Forever"> <Storyboard x:Key="PulsingStoryboard" RepeatBehavior="Forever">
<DoubleAnimation <DoubleAnimation
Storyboard.TargetName="PulsingEllipse" Storyboard.TargetName="AnimatedEllipse"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
From="1" To="0.5" Duration="0:0:1" AutoReverse="True" /> From="1" To="0.5" Duration="0:0:1" AutoReverse="True" />
<DoubleAnimation <DoubleAnimation
Storyboard.TargetName="PulsingEllipse" Storyboard.TargetName="AnimatedEllipse"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
From="1" To="0.5" Duration="0:0:1" AutoReverse="True" /> From="1" To="0.5" Duration="0:0:1" AutoReverse="True" />
</Storyboard> </Storyboard>
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<Ellipse x:Name="PulsingEllipse" <Ellipse
Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
Width="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
Stroke="Yellow"
Fill="Black"
Opacity="0.5"/>
<Ellipse x:Name="AnimatedEllipse"
Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
Stroke="Yellow" Width="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
Fill="Black" Stroke="Blue"
Opacity="0.5" Fill="Transparent"
Width="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"> RenderTransformOrigin="0.5,0.5">
<Ellipse.RenderTransform> <Ellipse.RenderTransform>
<TransformGroup> <TransformGroup>
<ScaleTransform /> <ScaleTransform />

View File

@ -4,6 +4,7 @@ using CtrEditor.Simulacion;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System.Windows.Media.Animation;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
@ -24,6 +25,7 @@ namespace CtrEditor.ObjetosSim
set set
{ {
_centro.X = value + Diametro / 2; _centro.X = value + Diametro / 2;
ActualizarGeometrias();
CanvasSetLeftinMeter(value); CanvasSetLeftinMeter(value);
OnPropertyChanged(nameof(CenterX)); OnPropertyChanged(nameof(CenterX));
OnPropertyChanged(nameof(Left)); OnPropertyChanged(nameof(Left));
@ -35,6 +37,7 @@ namespace CtrEditor.ObjetosSim
set set
{ {
_centro.Y = value + Diametro / 2; _centro.Y = value + Diametro / 2;
ActualizarGeometrias();
CanvasSetTopinMeter(value); CanvasSetTopinMeter(value);
OnPropertyChanged(nameof(CenterY)); OnPropertyChanged(nameof(CenterY));
OnPropertyChanged(nameof(Top)); OnPropertyChanged(nameof(Top));
@ -147,6 +150,11 @@ namespace CtrEditor.ObjetosSim
private void OnLoaded(object sender, RoutedEventArgs e) private void OnLoaded(object sender, RoutedEventArgs e)
{ {
Datos?.ucLoaded(); Datos?.ucLoaded();
Storyboard storyboard = this.Resources["PulsingStoryboard"] as Storyboard;
if (storyboard != null)
{
storyboard.Begin();
}
} }
private void OnUnloaded(object sender, RoutedEventArgs e) private void OnUnloaded(object sender, RoutedEventArgs e)
{ {

View File

@ -367,7 +367,7 @@ namespace CtrEditor.Simulacion
public void Debug_DrawInitialBodies() public void Debug_DrawInitialBodies()
{ {
ClearSimulationShapes(); Debug_ClearSimulationShapes();
world.Step(0.01f); // Para actualizar la BodyList world.Step(0.01f); // Para actualizar la BodyList
foreach (Body body in world.BodyList) foreach (Body body in world.BodyList)
{ {
@ -378,7 +378,7 @@ namespace CtrEditor.Simulacion
} }
} }
private void ClearSimulationShapes() public void Debug_ClearSimulationShapes()
{ {
var simulationShapes = simulationCanvas.Children.OfType<System.Windows.Shapes.Shape>().Where(s => s.Tag as string == "Simulation").ToList(); var simulationShapes = simulationCanvas.Children.OfType<System.Windows.Shapes.Shape>().Where(s => s.Tag as string == "Simulation").ToList();
foreach (var shape in simulationShapes) foreach (var shape in simulationShapes)