189 lines
5.2 KiB
C#
189 lines
5.2 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
//using using Microsoft.Xna.Framework;
|
|
|
|
using CtrEditor.Siemens;
|
|
using CtrEditor.Simulacion;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using nkast.Aether.Physics2D.Common;
|
|
using System.Windows.Media;
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ucBotella.xaml
|
|
/// </summary>
|
|
///
|
|
|
|
public partial class osBotella : osBase, IosBase
|
|
{
|
|
private simBotella SimGeometria;
|
|
|
|
// Otros datos y métodos relevantes para la simulación
|
|
|
|
public static string NombreClase()
|
|
{
|
|
return "Botella";
|
|
}
|
|
private string nombre = NombreClase();
|
|
public override string Nombre
|
|
{
|
|
get => nombre;
|
|
set => SetProperty(ref nombre, value);
|
|
}
|
|
|
|
[ObservableProperty]
|
|
private Brush colorButton_oculto;
|
|
|
|
[ObservableProperty]
|
|
private float diametro;
|
|
|
|
partial void OnDiametroChanged(float value)
|
|
{
|
|
SimGeometria?.SetDiameter(Diametro);
|
|
}
|
|
|
|
[ObservableProperty]
|
|
private string velocidad_desde_simulacion;
|
|
[ObservableProperty]
|
|
private float inercia_desde_simulacion;
|
|
|
|
[ObservableProperty]
|
|
bool test;
|
|
|
|
partial void OnTestChanged(bool value)
|
|
{
|
|
SimGeometria.Body.LinearVelocity = new Vector2(1,1);
|
|
}
|
|
|
|
[ObservableProperty]
|
|
private float porcentaje_Traccion;
|
|
|
|
[ObservableProperty]
|
|
private float mass;
|
|
partial void OnMassChanged(float value)
|
|
{
|
|
SimGeometria?.SetMass(value);
|
|
}
|
|
|
|
public Vector2 GetCentro()
|
|
{
|
|
return new Vector2 (Left+Diametro/2,Top+Diametro/2);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
private void ActualizarGeometrias()
|
|
{
|
|
if (SimGeometria != null)
|
|
{
|
|
|
|
SimGeometria.SetPosition(GetCentro());
|
|
}
|
|
}
|
|
|
|
public osBotella()
|
|
{
|
|
Diametro = 0.10f;
|
|
Mass = 1;
|
|
ColorButton_oculto = Brushes.Gray;
|
|
}
|
|
|
|
public void UpdateAfterMove()
|
|
{
|
|
ActualizarGeometrias();
|
|
SimGeometria?.SetDiameter(Diametro);
|
|
}
|
|
|
|
public override void UpdateGeometryStart()
|
|
{
|
|
// Se llama antes de la simulacion
|
|
ActualizarGeometrias();
|
|
SimGeometria?.SetDiameter(Diametro);
|
|
}
|
|
public override void UpdateGeometryStep()
|
|
{
|
|
// Se llama antes de la simulacion
|
|
ActualizarGeometrias();
|
|
}
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
|
{
|
|
SetCentro(SimGeometria.Center);
|
|
if (SimGeometria.isRestricted)
|
|
ColorButton_oculto = Brushes.Yellow;
|
|
else
|
|
{
|
|
if (SimGeometria.isOnTransports > 0)
|
|
ColorButton_oculto = Brushes.Red;
|
|
else
|
|
ColorButton_oculto = Brushes.Gray;
|
|
}
|
|
if (SimGeometria.Descartar) // Ha sido marcada para remover
|
|
RemoverDesdeSimulacion = true;
|
|
Velocidad_desde_simulacion = SimGeometria.Body.LinearVelocity.ToString();
|
|
Inercia_desde_simulacion = SimGeometria.Body.Inertia;
|
|
Porcentaje_Traccion = SimGeometria.OverlapPercentage;
|
|
}
|
|
|
|
public override void ucLoaded()
|
|
{
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
// crear el objeto de simulacion
|
|
ActualizarLeftTop();
|
|
SimGeometria = simulationManager.AddCircle(Diametro, GetCentro(), Mass);
|
|
}
|
|
public override void ucUnLoaded()
|
|
{
|
|
// El UserControl se esta eliminando
|
|
// eliminar el objeto de simulacion
|
|
simulationManager.Remove(SimGeometria);
|
|
}
|
|
|
|
}
|
|
|
|
public partial class ucBotella : UserControl, IDataContainer
|
|
{
|
|
public osBase? Datos { get; set; }
|
|
|
|
public ucBotella()
|
|
{
|
|
InitializeComponent();
|
|
this.Loaded += OnLoaded;
|
|
this.Unloaded += OnUnloaded;
|
|
}
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Datos?.ucLoaded();
|
|
}
|
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Datos?.ucUnLoaded();
|
|
}
|
|
|
|
public void Resize(float width, float height) { }
|
|
public void Move(float LeftPixels, float TopPixels)
|
|
{
|
|
if (Datos != null)
|
|
{
|
|
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
|
|
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
|
|
if (Datos is osBotella botella)
|
|
botella.UpdateAfterMove();
|
|
}
|
|
}
|
|
public void Rotate(float Angle) { }
|
|
public void Highlight(bool State) { }
|
|
public int ZIndex()
|
|
{
|
|
return 10;
|
|
}
|
|
}
|
|
}
|