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 Stopwatch stopwatch_PLCRefresh;
public Stopwatch stopwatch_SimRefresh;
private float TiempoDesdeStartSimulacion;
private bool Debug_SimulacionCreado = false;
public SimulationManagerFP simulationManager = new SimulationManagerFP();
@ -326,6 +328,8 @@ namespace CtrEditor
objetoSimulable.UpdateGeometryStart();
simulationManager.Debug_DrawInitialBodies();
TiempoDesdeStartSimulacion = 0;
Debug_SimulacionCreado = true;
_timerSimulacion.Start();
simulationManager.stopwatch.Start();
@ -335,6 +339,11 @@ namespace CtrEditor
private void StopSimulation()
{
if (Debug_SimulacionCreado)
{
simulationManager.Debug_ClearSimulationShapes();
Debug_SimulacionCreado = false;
}
_timerSimulacion.Stop();
simulationManager.stopwatch.Stop();
stopwatch_SimRefresh.Stop();
@ -347,6 +356,12 @@ namespace CtrEditor
stopwatch_SimRefresh.Stop();
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
stopwatch_SimRefresh.Restart();

View File

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

View File

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

View File

@ -367,7 +367,7 @@ namespace CtrEditor.Simulacion
public void Debug_DrawInitialBodies()
{
ClearSimulationShapes();
Debug_ClearSimulationShapes();
world.Step(0.01f); // Para actualizar la 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();
foreach (var shape in simulationShapes)