using CtrEditor.Convertidores; using CtrEditor.Siemens; using CtrEditor.Simulacion; using System.Windows; using System.Windows.Controls; using Microsoft.Xna.Framework; using System.Windows.Media.Animation; namespace CtrEditor.ObjetosSim { /// /// Interaction logic for ucDescarte.xaml /// public class osDescarte : osBase { // Otros datos y métodos relevantes para la simulación private string _nombre = "Descarte"; private float _diametro; private Vector2 _centro = new Vector2(); // Centro private simDescarte AreaDeDescarte; public override float Left { get => _centro.X - Diametro / 2; set { _centro.X = value + Diametro / 2; ActualizarGeometrias(); CanvasSetLeftinMeter(value); OnPropertyChanged(nameof(CenterX)); OnPropertyChanged(nameof(Left)); } } public override float Top { get => _centro.Y - Diametro / 2; set { _centro.Y = value + Diametro / 2; ActualizarGeometrias(); CanvasSetTopinMeter(value); OnPropertyChanged(nameof(CenterY)); 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)); } } public float Diametro { get => _diametro; set { _diametro = value; AreaDeDescarte?.SetDiameter(Diametro); OnPropertyChanged(nameof(Diametro)); } } public override string Nombre { get => _nombre; set { if (_nombre != value) { _nombre = value; OnPropertyChanged(nameof(Nombre)); } } } private void ActualizarGeometrias() { if (AreaDeDescarte != null) { AreaDeDescarte.SetDiameter(Diametro); AreaDeDescarte.SetPosition(CenterX, CenterY); } } public osDescarte() { Diametro = 1f; } public override void UpdateGeometryStart() { // Se llama antes de la simulacion ActualizarGeometrias(); } public override void UpdateGeometryStep() { } public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { } public override void UpdateControl(int elapsedMilliseconds) { } public override void ucLoaded() { // El UserControl ya se ha cargado y podemos obtener las coordenadas para // crear el objeto de simulacion ActualizarLeftTop(); AreaDeDescarte = simulationManager.AddDescarte(Diametro, _centro); } public override void ucUnLoaded() { // El UserControl se esta eliminando // eliminar el objeto de simulacion simulationManager.Remove(AreaDeDescarte); } } public partial class ucDescarte : UserControl, IDataContainer { public osBase? Datos { get; set; } public ucDescarte() { InitializeComponent(); this.Loaded += OnLoaded; this.Unloaded += OnUnloaded; } 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) { Datos?.ucUnLoaded(); } public void Resize(float width, float height) { if (Datos is osDescarte datos) { datos.Diametro = PixelToMeter.Instance.calc.PixelsToMeters(width); } } 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; } } }