217 lines
6.3 KiB
C#
217 lines
6.3 KiB
C#
using System.ComponentModel;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CtrEditor.Siemens;
|
|
using CtrEditor.Simulacion;
|
|
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ucTransporteCurva.xaml
|
|
/// </summary>
|
|
public partial class osTransporteCurva : osBase, IosBase
|
|
{
|
|
private osBase Motor = null;
|
|
|
|
private simCurve Simulation_TransporteCurva;
|
|
|
|
private float _velocidadActual;
|
|
|
|
public static string NombreClase()
|
|
{
|
|
return "Transporte Curva 90";
|
|
}
|
|
private string nombre = "Transporte Curva 90";
|
|
public override string Nombre
|
|
{
|
|
get => nombre;
|
|
set => SetProperty(ref nombre, value);
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public float velocidadActual;
|
|
|
|
partial void OnVelocidadActualChanged(float value)
|
|
{
|
|
SetSpeed();
|
|
}
|
|
|
|
[ObservableProperty]
|
|
bool invertirDireccion;
|
|
|
|
partial void OnInvertirDireccionChanged(bool value)
|
|
{
|
|
SetSpeed();
|
|
}
|
|
|
|
void SetSpeed()
|
|
{
|
|
if (InvertirDireccion)
|
|
Simulation_TransporteCurva?.SetSpeed(-VelocidadActual);
|
|
else
|
|
Simulation_TransporteCurva?.SetSpeed(VelocidadActual);
|
|
}
|
|
|
|
[ObservableProperty]
|
|
private float radioExterno;
|
|
[ObservableProperty]
|
|
private float radioInterno;
|
|
|
|
[ObservableProperty]
|
|
[property: Description("Link to Motor")]
|
|
[property: Category("PLC link:")]
|
|
[property: ItemsSource(typeof(osBaseItemsSource<osVMmotorSim>))]
|
|
string id_Motor;
|
|
|
|
partial void OnId_MotorChanged(string value)
|
|
{
|
|
if (Motor != null)
|
|
Motor.PropertyChanged -= OnMotorPropertyChanged;
|
|
if (_mainViewModel != null && value != null && value.Length > 0)
|
|
{
|
|
Motor = (osVMmotorSim)_mainViewModel.ObjetosSimulables.FirstOrDefault(s => (s is osVMmotorSim && s.Nombre == value), null);
|
|
if (Motor != null)
|
|
Motor.PropertyChanged += OnMotorPropertyChanged;
|
|
}
|
|
}
|
|
|
|
private void OnMotorPropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
if (e.PropertyName == nameof(osVMmotorSim.Nombre))
|
|
{
|
|
Id_Motor = ((osVMmotorSim)sender).Nombre;
|
|
}
|
|
}
|
|
|
|
[ObservableProperty]
|
|
[NotifyPropertyChangedFor(nameof(AnguloFinal))]
|
|
public float angulo;
|
|
|
|
[ObservableProperty]
|
|
[NotifyPropertyChangedFor(nameof(AnguloFinal))]
|
|
private float arco_en_grados;
|
|
|
|
[Hidden]
|
|
public float AnguloFinal
|
|
{
|
|
get => Angulo+Arco_en_grados;
|
|
}
|
|
|
|
private void ActualizarGeometrias()
|
|
{
|
|
if (_visualRepresentation is ucTransporteCurva uc)
|
|
{
|
|
UpdateCurve(Simulation_TransporteCurva, RadioInterno, RadioExterno, Angulo, Angulo+Arco_en_grados);
|
|
SetSpeed();
|
|
}
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public float frictionCoefficient;
|
|
[ObservableProperty]
|
|
public float velMax50hz;
|
|
[ObservableProperty]
|
|
public float tiempoRampa;
|
|
[ObservableProperty]
|
|
public bool esMarcha;
|
|
|
|
public osTransporteCurva()
|
|
{
|
|
RadioExterno = 1.3f;
|
|
RadioInterno = 1;
|
|
Arco_en_grados = 90;
|
|
}
|
|
|
|
public override void UpdateGeometryStart()
|
|
{
|
|
// Se llama antes de la simulacion
|
|
ActualizarGeometrias();
|
|
|
|
|
|
}
|
|
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
|
|
{
|
|
if (Motor != null)
|
|
{
|
|
if (Motor is osVMmotorSim motor)
|
|
VelocidadActual = motor.Velocidad;
|
|
}
|
|
}
|
|
|
|
public override void ucLoaded()
|
|
{
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
// crear el objeto de simulacion
|
|
base.ucLoaded();
|
|
|
|
OnId_MotorChanged(Id_Motor); // Link Id_Motor = Motor
|
|
|
|
if (_visualRepresentation is ucTransporteCurva uc)
|
|
Simulation_TransporteCurva = AddCurve(RadioInterno,RadioExterno, Angulo, Angulo + Arco_en_grados);
|
|
|
|
// AddCurve(float innerRadius, float outerRadius, float startAngle, float endAngle, Vector2 position)
|
|
}
|
|
public override void ucUnLoaded()
|
|
{
|
|
// El UserControl se esta eliminando
|
|
// eliminar el objeto de simulacion
|
|
simulationManager?.Remove(Simulation_TransporteCurva);
|
|
}
|
|
|
|
}
|
|
|
|
public partial class ucTransporteCurva : UserControl, IDataContainer
|
|
{
|
|
public osBase? Datos { get; set; }
|
|
|
|
public ucTransporteCurva()
|
|
{
|
|
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 RadioExterno, float RadioInterno)
|
|
{
|
|
if (Datos is osTransporteCurva datos)
|
|
{
|
|
if (RadioExterno > RadioInterno && RadioExterno > 0 && RadioInterno >= 0)
|
|
{
|
|
datos.RadioExterno = PixelToMeter.Instance.calc.PixelsToMeters(RadioExterno);
|
|
datos.RadioInterno = PixelToMeter.Instance.calc.PixelsToMeters(RadioInterno);
|
|
}
|
|
}
|
|
}
|
|
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 osTransporteCurva datos)
|
|
datos.Angulo = Angle;
|
|
}
|
|
public void Highlight(bool State) { }
|
|
public int ZIndex()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
}
|
|
|
|
}
|