CtrEditor/ObjetosSim/ucBotella.xaml.cs

188 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework;
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
using Newtonsoft.Json.Linq;
namespace CtrEditor.ObjetosSim
{
/// <summary>
/// Interaction logic for ucBotella.xaml
/// </summary>
///
public class osBotella : osBase
{
private float _diametro;
private float _mass;
private Vector2 _centro = new Vector2(); // Centro
private string _nombre = "Botella";
private simCircle Simulacion_Botella;
// Otros datos y métodos relevantes para la simulación
public float Diametro {
get => _diametro;
set
{
_diametro = value;
Simulacion_Botella?.SetDiameter(Diametro);
OnPropertyChanged(nameof(Diametro));
}
}
public float Mass {
get => _mass;
set
{
_mass = value;
Simulacion_Botella?.SetMass(value);
OnPropertyChanged(nameof(Mass));
}
}
public override float Left
{
get => _centro.X-Diametro/2;
set
{
_centro.X = value+Diametro/2;
CanvasSetLeftinMeter(value);
OnPropertyChanged(nameof(Left));
}
}
public override float Top
{
get => _centro.Y - Diametro / 2;
set
{
_centro.Y = value + Diametro / 2;
CanvasSetTopinMeter(value);
OnPropertyChanged(nameof(Top));
}
}
public float CenterX
{
get => _centro.X;
set
{
_centro.X = value;
CanvasSetLeftinMeter(Left);
OnPropertyChanged(nameof(CenterX));
OnPropertyChanged(nameof(Left));
}
}
public float CenterY
{
get => _centro.Y;
set
{
_centro.Y = value;
CanvasSetTopinMeter(Top);
OnPropertyChanged(nameof(CenterY));
OnPropertyChanged(nameof(Top));
}
}
private void ActualizarGeometrias()
{
if (Simulacion_Botella != null)
{
Simulacion_Botella.SetDiameter(Diametro);
Simulacion_Botella.SetPosition(CenterX, CenterY);
}
}
public override string Nombre
{
get => _nombre;
set
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
}
}
public osBotella()
{
Diametro = 0.10f;
Mass = 1;
}
public override void UpdateGeometryStart()
{
// Se llama antes de la simulacion
ActualizarGeometrias();
}
public override void UpdateGeometryStep()
{
// Se llama antes de la simulacion
ActualizarGeometrias();
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { }
public override void UpdateControl()
{
CenterX = Simulacion_Botella.CenterX;
CenterY = Simulacion_Botella.CenterY;
}
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
Simulacion_Botella = simulationManager.AddCircle(Diametro, _centro, Mass);
}
}
public partial class ucBotella : UserControl, IDataContainer
{
public osBase? Datos { get; set; }
public ucBotella()
{
InitializeComponent();
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Datos?.ucLoaded();
}
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);
}
}
public void Rotate(float Angle) { }
public void Highlight(bool State) { }
public int ZIndex()
{
return 10;
}
}
}