using System.Windows; using System.Windows.Controls; using System.Windows.Media.Animation; using System.Windows.Media; using CommunityToolkit.Mvvm.ComponentModel; using CtrEditor.Convertidores; using CtrEditor.Siemens; using CtrEditor.Simulacion; namespace CtrEditor.ObjetosSim { /// /// Interaction logic for ucTransporteTTop.xaml /// /// public partial class osTransporteTTop : osBase, IosBase { private osBase _osMotor = null; private simTransporte Simulation_Transporte; public static string NombreClase() { return "Transporte"; } private string nombre = "Transporte TTOP"; public override string Nombre { get => nombre; set => SetProperty(ref nombre, value); } private float left; public override float Left { get => left; set { CanvasSetLeftinMeter(value); SetProperty(ref left, value); } } private float top; public override float Top { get => top; set { CanvasSetTopinMeter(value); SetProperty(ref top, value); } } private float velocidadActual; public float VelocidadActual { get => velocidadActual; set { velocidadActual = value; Simulation_Transporte?.SetSpeed(value); SetProperty(ref velocidadActual, value); } } [ObservableProperty] public string motor; [ObservableProperty] public float ancho; [ObservableProperty] public float alto; [ObservableProperty] public float angulo; [ObservableProperty] public float frictionCoefficient; [ObservableProperty] public float velMax50hz; [ObservableProperty] public float tiempoRampa; [ObservableProperty] public bool esMarcha; private void ActualizarGeometrias() { if (_visualRepresentation is ucTransporteTTop uc) { UpdateRectangle(Simulation_Transporte, uc.Transporte,Alto,Ancho,Angulo); Simulation_Transporte.Speed = VelocidadActual; } } public osTransporteTTop() { Ancho = 1; Alto = 0.10f; } public override void UpdateGeometryStart() { // Se llama antes de la simulacion ActualizarGeometrias(); } public override void UpdateGeometryStep() { } public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { if (_osMotor != null) { if (_osMotor is osVMmotorSim motor) VelocidadActual = motor.Velocidad; } else _osMotor = ObtenerLink(Motor, typeof(osVMmotorSim)); } 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(); if (_visualRepresentation is ucTransporteTTop uc) Simulation_Transporte = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo); } public override void ucUnLoaded() { // El UserControl se esta eliminando // eliminar el objeto de simulacion simulationManager.Remove(Simulation_Transporte); } } public partial class ucTransporteTTop : UserControl, IDataContainer { public osBase? Datos { get; set; } public ucTransporteTTop() { 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) { if (Datos is osTransporteTTop datos) datos.Ancho = 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) { if (Datos != null) if (Datos is osTransporteTTop datos) datos.Angulo = Angle; } public void Highlight(bool State) { } public int ZIndex() { return 1; } } }