2024-05-22 14:21:39 -03:00
|
|
|
|
using System.Windows;
|
2024-05-02 11:06:45 -03:00
|
|
|
|
using System.Windows.Controls;
|
2024-05-25 09:38:36 -03:00
|
|
|
|
//using using Microsoft.Xna.Framework;
|
2024-05-31 10:06:49 -03:00
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
using LibS7Adv;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
using CtrEditor.Simulacion;
|
2024-05-22 14:21:39 -03:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-05-25 09:38:36 -03:00
|
|
|
|
using nkast.Aether.Physics2D.Common;
|
2024-05-26 06:50:25 -03:00
|
|
|
|
using System.Windows.Media;
|
2024-06-30 13:17:44 -03:00
|
|
|
|
using CtrEditor.FuncionesBase;
|
2024-05-02 11:06:45 -03:00
|
|
|
|
|
2024-05-04 06:00:52 -03:00
|
|
|
|
namespace CtrEditor.ObjetosSim
|
2024-05-02 11:06:45 -03:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-05-04 06:00:52 -03:00
|
|
|
|
/// Interaction logic for ucBotella.xaml
|
2024-05-02 11:06:45 -03:00
|
|
|
|
/// </summary>
|
2024-05-04 06:00:52 -03:00
|
|
|
|
///
|
2024-05-18 18:14:46 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
public partial class osBotella : osBase, IosBase
|
2024-05-02 11:06:45 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
private simBotella SimGeometria;
|
2024-05-06 12:31:45 -03:00
|
|
|
|
|
2024-05-04 06:00:52 -03:00
|
|
|
|
// Otros datos y métodos relevantes para la simulación
|
|
|
|
|
|
2024-05-19 16:38:57 -03:00
|
|
|
|
public static string NombreClase()
|
|
|
|
|
{
|
|
|
|
|
return "Botella";
|
|
|
|
|
}
|
2024-05-22 14:21:39 -03:00
|
|
|
|
private string nombre = NombreClase();
|
|
|
|
|
public override string Nombre
|
|
|
|
|
{
|
|
|
|
|
get => nombre;
|
|
|
|
|
set => SetProperty(ref nombre, value);
|
2024-05-08 03:00:31 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 13:17:44 -03:00
|
|
|
|
public override void OnMove(float LeftPixels, float TopPixels)
|
2024-06-30 09:32:32 -03:00
|
|
|
|
{
|
|
|
|
|
UpdateAfterMove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnResize(float Delta_Width, float Delta_Height)
|
|
|
|
|
{
|
|
|
|
|
Diametro += Delta_Width;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 06:50:25 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private Brush colorButton_oculto;
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private float diametro;
|
2024-05-06 12:31:45 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
partial void OnDiametroChanged(float value)
|
2024-05-08 04:15:28 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
SimGeometria?.SetDiameter(Diametro);
|
2024-05-08 04:15:28 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 05:34:20 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private string velocidad_desde_simulacion;
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private float inercia_desde_simulacion;
|
|
|
|
|
|
2024-05-30 13:48:37 -03:00
|
|
|
|
[ObservableProperty]
|
2024-09-12 11:43:39 -03:00
|
|
|
|
private bool preserve_Outside_Transport;
|
2024-05-30 13:48:37 -03:00
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private float porcentaje_Traccion;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private float mass;
|
|
|
|
|
partial void OnMassChanged(float value)
|
2024-05-08 03:00:31 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
SimGeometria?.SetMass(value);
|
2024-05-03 05:13:25 -03:00
|
|
|
|
}
|
2024-05-22 14:21:39 -03:00
|
|
|
|
|
|
|
|
|
public Vector2 GetCentro()
|
2024-05-06 12:31:45 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
return new Vector2 (Left+Diametro/2,Top+Diametro/2);
|
2024-05-06 12:31:45 -03:00
|
|
|
|
}
|
2024-05-08 03:00:31 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
public void SetCentro(float x, float y)
|
|
|
|
|
{ Left = x; Top = y; }
|
|
|
|
|
|
|
|
|
|
public void SetCentro(Vector2 centro)
|
|
|
|
|
{
|
|
|
|
|
Left = centro.X - Diametro / 2;
|
|
|
|
|
Top = centro.Y - Diametro / 2;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
private void ActualizarGeometrias()
|
2024-05-08 03:00:31 -03:00
|
|
|
|
{
|
2024-09-12 11:43:39 -03:00
|
|
|
|
if (SimGeometria != null && !RemoverDesdeSimulacion)
|
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
SimGeometria.SetPosition(GetCentro());
|
2024-05-08 03:00:31 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public osBotella()
|
|
|
|
|
{
|
2024-05-08 08:41:26 -03:00
|
|
|
|
Diametro = 0.10f;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
Mass = 1;
|
2024-05-26 06:50:25 -03:00
|
|
|
|
ColorButton_oculto = Brushes.Gray;
|
2025-01-04 06:34:19 -03:00
|
|
|
|
Preserve_Outside_Transport = true;
|
2024-05-08 03:00:31 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 06:50:25 -03:00
|
|
|
|
public void UpdateAfterMove()
|
2024-05-06 12:31:45 -03:00
|
|
|
|
{
|
2024-09-12 11:43:39 -03:00
|
|
|
|
if (!RemoverDesdeSimulacion)
|
|
|
|
|
{
|
|
|
|
|
ActualizarGeometrias();
|
|
|
|
|
SimGeometria?.SetDiameter(Diametro);
|
|
|
|
|
}
|
2024-05-06 12:31:45 -03:00
|
|
|
|
}
|
2024-05-26 06:50:25 -03:00
|
|
|
|
|
|
|
|
|
public override void UpdateGeometryStart()
|
2024-05-22 14:21:39 -03:00
|
|
|
|
{
|
2024-05-26 06:50:25 -03:00
|
|
|
|
// Se llama antes de la simulacion
|
|
|
|
|
ActualizarGeometrias();
|
|
|
|
|
SimGeometria?.SetDiameter(Diametro);
|
2024-05-22 14:21:39 -03:00
|
|
|
|
}
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public override void UpdateGeometryStep()
|
2024-05-10 20:40:51 -03:00
|
|
|
|
{
|
|
|
|
|
// Se llama antes de la simulacion
|
2024-05-14 03:15:54 -03:00
|
|
|
|
ActualizarGeometrias();
|
2024-05-10 20:40:51 -03:00
|
|
|
|
}
|
2024-05-16 13:45:14 -03:00
|
|
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
2024-05-06 12:31:45 -03:00
|
|
|
|
{
|
2024-09-12 11:43:39 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
SetCentro(SimGeometria.Center);
|
2024-05-26 06:50:25 -03:00
|
|
|
|
if (SimGeometria.isRestricted)
|
|
|
|
|
ColorButton_oculto = Brushes.Yellow;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (SimGeometria.isOnTransports > 0)
|
|
|
|
|
ColorButton_oculto = Brushes.Red;
|
|
|
|
|
else
|
|
|
|
|
ColorButton_oculto = Brushes.Gray;
|
|
|
|
|
}
|
2024-09-12 11:43:39 -03:00
|
|
|
|
|
|
|
|
|
// Ha sido marcada para remover
|
|
|
|
|
if (SimGeometria.Descartar)
|
2024-05-18 09:58:41 -03:00
|
|
|
|
RemoverDesdeSimulacion = true;
|
2024-09-12 11:43:39 -03:00
|
|
|
|
|
|
|
|
|
// Eliminar la botella si esta fuera de un transporte
|
|
|
|
|
if (!Preserve_Outside_Transport && Porcentaje_Traccion == 0 && Math.Abs(SimGeometria.Body.LinearVelocity.X) <= 0.001 && Math.Abs(SimGeometria.Body.LinearVelocity.Y) <= 0.001)
|
|
|
|
|
RemoverDesdeSimulacion = true;
|
|
|
|
|
|
2024-05-27 05:34:20 -03:00
|
|
|
|
Velocidad_desde_simulacion = SimGeometria.Body.LinearVelocity.ToString();
|
|
|
|
|
Inercia_desde_simulacion = SimGeometria.Body.Inertia;
|
2024-05-30 13:48:37 -03:00
|
|
|
|
Porcentaje_Traccion = SimGeometria.OverlapPercentage;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public override void ucLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
|
|
|
// crear el objeto de simulacion
|
2024-06-09 12:33:09 -03:00
|
|
|
|
base.ucLoaded();
|
2024-05-22 14:21:39 -03:00
|
|
|
|
SimGeometria = simulationManager.AddCircle(Diametro, GetCentro(), Mass);
|
2024-05-06 12:31:45 -03:00
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
public override void ucUnLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl se esta eliminando
|
|
|
|
|
// eliminar el objeto de simulacion
|
2024-05-22 14:21:39 -03:00
|
|
|
|
simulationManager.Remove(SimGeometria);
|
2024-05-18 09:58:41 -03:00
|
|
|
|
}
|
2024-05-14 03:15:54 -03:00
|
|
|
|
|
2024-05-02 11:06:45 -03:00
|
|
|
|
}
|
2024-05-03 03:58:21 -03:00
|
|
|
|
|
2024-05-04 15:35:06 -03:00
|
|
|
|
public partial class ucBotella : UserControl, IDataContainer
|
2024-05-04 06:00:52 -03:00
|
|
|
|
{
|
2024-05-04 15:35:06 -03:00
|
|
|
|
public osBase? Datos { get; set; }
|
|
|
|
|
|
2024-05-04 06:00:52 -03:00
|
|
|
|
public ucBotella()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-14 03:15:54 -03:00
|
|
|
|
this.Loaded += OnLoaded;
|
2024-05-18 09:58:41 -03:00
|
|
|
|
this.Unloaded += OnUnloaded;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
}
|
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos?.ucLoaded();
|
2024-05-04 06:00:52 -03:00
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos?.ucUnLoaded();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-04 16:27:04 -03:00
|
|
|
|
public void Highlight(bool State) { }
|
2024-06-30 13:17:44 -03:00
|
|
|
|
public ZIndexEnum ZIndex()
|
2024-05-08 03:00:31 -03:00
|
|
|
|
{
|
2024-06-30 13:17:44 -03:00
|
|
|
|
return ZIndexEnum.Dinamicos;
|
2024-05-08 03:00:31 -03:00
|
|
|
|
}
|
2024-05-04 06:00:52 -03:00
|
|
|
|
}
|
2024-05-02 11:06:45 -03:00
|
|
|
|
}
|