223 lines
6.5 KiB
C#
223 lines
6.5 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CtrEditor.Siemens;
|
|
using CtrEditor.Simulacion;
|
|
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
|
|
using System.ComponentModel;
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ucTransporteTTop.xaml
|
|
/// </summary>
|
|
///
|
|
|
|
public partial class osTransporteTTop : osBase, IosBase
|
|
{
|
|
|
|
private simTransporte SimGeometria;
|
|
private osVMmotorSim Motor;
|
|
|
|
public static string NombreClase()
|
|
{
|
|
return "Transporte";
|
|
}
|
|
private string nombre = "Transporte TTOP";
|
|
|
|
[property: Category("Id:")]
|
|
public override string Nombre
|
|
{
|
|
get => nombre;
|
|
set => SetProperty(ref nombre, value);
|
|
}
|
|
|
|
[ObservableProperty]
|
|
[property: Category("Simulation:")]
|
|
public float velocidadActual;
|
|
|
|
partial void OnVelocidadActualChanged(float value)
|
|
{
|
|
SetSpeed();
|
|
}
|
|
|
|
[ObservableProperty]
|
|
[property: Category("Simulation:")]
|
|
bool invertirDireccion;
|
|
|
|
partial void OnInvertirDireccionChanged(bool value)
|
|
{
|
|
SetSpeed();
|
|
if (_visualRepresentation is ucTransporteTTop uc)
|
|
{
|
|
CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion);
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
}
|
|
|
|
void SetSpeed()
|
|
{
|
|
if (InvertirDireccion)
|
|
SimGeometria?.SetSpeed(-VelocidadActual);
|
|
else
|
|
SimGeometria?.SetSpeed(VelocidadActual);
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
|
|
[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]
|
|
[property: Category("Layout:")]
|
|
public float ancho;
|
|
[ObservableProperty]
|
|
[property: Category("Layout:")]
|
|
public float alto;
|
|
[ObservableProperty]
|
|
[property: Category("Layout:")]
|
|
public float angulo;
|
|
|
|
[ObservableProperty]
|
|
[property: Category("Setup:")]
|
|
public float frictionCoefficient;
|
|
[ObservableProperty]
|
|
[property: Category("Setup:")]
|
|
public float velMax50hz;
|
|
[ObservableProperty]
|
|
[property: Category("Setup:")]
|
|
public float tiempoRampa;
|
|
[ObservableProperty]
|
|
[property: Category("Setup:")]
|
|
public bool esMarcha;
|
|
|
|
|
|
private void ActualizarGeometrias()
|
|
{
|
|
if (_visualRepresentation is ucTransporteTTop uc)
|
|
{
|
|
UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo);
|
|
SetSpeed();
|
|
}
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
|
|
public osTransporteTTop()
|
|
{
|
|
Ancho = 1;
|
|
Alto = 0.10f;
|
|
}
|
|
|
|
public override void SimulationStop()
|
|
{
|
|
// Se llama al detener la simulacion
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
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 ucTransporteTTop uc)
|
|
{
|
|
SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo);
|
|
CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion);
|
|
}
|
|
}
|
|
public override void ucUnLoaded()
|
|
{
|
|
// El UserControl se esta eliminando
|
|
// eliminar el objeto de simulacion
|
|
simulationManager.Remove(SimGeometria);
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|