Compare commits

..

No commits in common. "2e8c3b7d8314ce3c34dbda44e8f0b4118bbd60bb" and "9ed8a0b7bd140e8056f69da9516efa1b2388e4f4" have entirely different histories.

4 changed files with 19 additions and 64 deletions

View File

@ -39,8 +39,6 @@ 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();
@ -328,8 +326,6 @@ 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();
@ -339,11 +335,6 @@ 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();
@ -356,12 +347,6 @@ 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,29 +10,23 @@
<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="AnimatedEllipse" Storyboard.TargetName="PulsingEllipse"
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="AnimatedEllipse" Storyboard.TargetName="PulsingEllipse"
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 <Ellipse x:Name="PulsingEllipse"
Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
Width="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
Stroke="Yellow" Stroke="Yellow"
Fill="Black" Fill="Black"
Opacity="0.5"/> Opacity="0.5"
<Ellipse x:Name="AnimatedEllipse" Width="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}">
Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
Width="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"
Stroke="Blue"
Fill="Transparent"
RenderTransformOrigin="0.5,0.5">
<Ellipse.RenderTransform> <Ellipse.RenderTransform>
<TransformGroup> <TransformGroup>
<ScaleTransform /> <ScaleTransform />

View File

@ -4,7 +4,6 @@ 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>
@ -25,7 +24,6 @@ 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));
@ -37,7 +35,6 @@ 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));
@ -150,11 +147,6 @@ 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

@ -42,16 +42,13 @@ namespace CtrEditor.Simulacion
_radius = diameter / 2; _radius = diameter / 2;
Create(Body.Position); // Recrear el círculo con el nuevo tamaño Create(Body.Position); // Recrear el círculo con el nuevo tamaño
} }
public void RemoverBody()
public void Create(Vector2 position)
{ {
if (Body != null) if (Body != null)
{ {
_world.RemoveBody(Body); _world.RemoveBody(Body);
} }
}
public void Create(Vector2 position)
{
RemoverBody();
Body = BodyFactory.CreateCircle(_world, _radius, 1f, position); Body = BodyFactory.CreateCircle(_world, _radius, 1f, position);
Body.FixtureList[0].IsSensor = true; Body.FixtureList[0].IsSensor = true;
@ -95,16 +92,13 @@ namespace CtrEditor.Simulacion
var newShape = new PolygonShape(PolygonTools.CreateRectangle(width / 2, height / 2), 1f); var newShape = new PolygonShape(PolygonTools.CreateRectangle(width / 2, height / 2), 1f);
Body.CreateFixture(newShape); Body.CreateFixture(newShape);
} }
public void RemoverBody()
public void Create(float width, float height, Vector2 position, float angle = 0)
{ {
if (Body != null) if (Body != null)
{ {
_world.RemoveBody(Body); _world.RemoveBody(Body);
} }
}
public void Create(float width, float height, Vector2 position, float angle = 0)
{
RemoverBody();
Body = BodyFactory.CreateRectangle(_world, width, height, 1f, position); Body = BodyFactory.CreateRectangle(_world, width, height, 1f, position);
Body.FixtureList[0].IsSensor = true; Body.FixtureList[0].IsSensor = true;
Body.BodyType = BodyType.Static; Body.BodyType = BodyType.Static;
@ -123,16 +117,13 @@ namespace CtrEditor.Simulacion
_world = world; _world = world;
Create(start, end); Create(start, end);
} }
public void RemoverBody()
public void Create(Vector2 start, Vector2 end)
{ {
if (Body != null) if (Body != null)
{ {
_world.RemoveBody(Body); _world.RemoveBody(Body); // Elimina el cuerpo anterior si existe
} }
}
public void Create(Vector2 start, Vector2 end)
{
RemoverBody();
Body = BodyFactory.CreateEdge(_world, start, end); Body = BodyFactory.CreateEdge(_world, start, end);
Body.BodyType = BodyType.Static; Body.BodyType = BodyType.Static;
Body.UserData = this; // Importante para la identificación durante la colisión Body.UserData = this; // Importante para la identificación durante la colisión
@ -187,16 +178,13 @@ namespace CtrEditor.Simulacion
} }
set { _mass = value; } set { _mass = value; }
} }
public void RemoverBody()
private void Create(Vector2 position)
{ {
if (Body != null) if (Body != null)
{ {
_world.RemoveBody(Body); _world.RemoveBody(Body); // Remover el cuerpo anterior si existe
} }
}
private void Create(Vector2 position)
{
RemoverBody();
Body = BodyFactory.CreateCircle(_world, _radius, 1f, position); Body = BodyFactory.CreateCircle(_world, _radius, 1f, position);
Body.BodyType = BodyType.Dynamic; Body.BodyType = BodyType.Dynamic;
@ -333,19 +321,15 @@ namespace CtrEditor.Simulacion
switch (Objeto) switch (Objeto)
{ {
case simBotella obj: case simBotella obj:
obj.RemoverBody();
circles.Remove(obj); circles.Remove(obj);
break; break;
case simTransporte obj: case simTransporte obj:
obj.RemoverBody();
rectangles.Remove(obj); rectangles.Remove(obj);
break; break;
case simGuia obj: case simGuia obj:
obj.RemoverBody();
lines.Remove(obj); lines.Remove(obj);
break; break;
case simDescarte obj: case simDescarte obj:
obj.RemoverBody();
descartes.Remove(obj); descartes.Remove(obj);
break; break;
default: default:
@ -383,7 +367,7 @@ namespace CtrEditor.Simulacion
public void Debug_DrawInitialBodies() public void Debug_DrawInitialBodies()
{ {
Debug_ClearSimulationShapes(); 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)
{ {
@ -394,7 +378,7 @@ namespace CtrEditor.Simulacion
} }
} }
public void Debug_ClearSimulationShapes() private void 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)