227 lines
6.7 KiB
C#
227 lines
6.7 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CtrEditor.Convertidores;
|
|
using CtrEditor.Siemens;
|
|
using CtrEditor.Simulacion;
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ucTransporteGuias.xaml
|
|
/// </summary>
|
|
public partial class osTransporteGuias : osBase, IosBase
|
|
{
|
|
private osBase _osMotor = null;
|
|
|
|
private simTransporte? SimGeometria;
|
|
private simGuia? Guia_Superior;
|
|
private simGuia? Guia_Inferior;
|
|
|
|
|
|
public static string NombreClase()
|
|
{
|
|
return "Transporte Guias";
|
|
}
|
|
private string nombre = NombreClase();
|
|
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();
|
|
if (_visualRepresentation is ucTransporteGuias uc)
|
|
{
|
|
CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion);
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
}
|
|
|
|
void SetSpeed()
|
|
{
|
|
if (InvertirDireccion)
|
|
SimGeometria?.SetSpeed(-VelocidadActual);
|
|
else
|
|
SimGeometria?.SetSpeed(VelocidadActual);
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
|
|
|
|
[ObservableProperty]
|
|
public string motor;
|
|
|
|
partial void OnMotorChanged(string value)
|
|
{
|
|
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public float ancho;
|
|
[ObservableProperty]
|
|
public float alto;
|
|
|
|
partial void OnAltoChanged(float value)
|
|
{
|
|
ActualizarGeometrias();
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public bool esFreno;
|
|
|
|
partial void OnEsFrenoChanged(bool value)
|
|
{
|
|
if (SimGeometria != null)
|
|
SimGeometria.isBrake = value;
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public float angulo;
|
|
[ObservableProperty]
|
|
public float frictionCoefficient;
|
|
[ObservableProperty]
|
|
public float velMax50hz;
|
|
[ObservableProperty]
|
|
public float tiempoRampa;
|
|
[ObservableProperty]
|
|
public bool esMarcha;
|
|
[ObservableProperty]
|
|
private float distance;
|
|
[ObservableProperty]
|
|
private float altoGuia;
|
|
|
|
private void ActualizarGeometrias()
|
|
{
|
|
if (_visualRepresentation is ucTransporteGuias uc)
|
|
{
|
|
UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo);
|
|
UpdateOrCreateLine(Guia_Superior, uc.GuiaSuperior);
|
|
UpdateOrCreateLine(Guia_Inferior, uc.GuiaInferior) ;
|
|
|
|
SimGeometria.DistanceGuide2Guide = Alto;
|
|
SimGeometria.Speed = VelocidadActual;
|
|
SimGeometria.isBrake = esFreno;
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
}
|
|
|
|
|
|
public osTransporteGuias()
|
|
{
|
|
Ancho = 1;
|
|
Alto = 0.10f;
|
|
AltoGuia = 0.03f;
|
|
Distance = 0.01f;
|
|
}
|
|
|
|
public override void UpdateGeometryStart()
|
|
{
|
|
// Se llama antes de la simulacion
|
|
ActualizarGeometrias();
|
|
}
|
|
public override void SimulationStop()
|
|
{
|
|
// Se llama al detener la simulacion
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
|
|
{
|
|
if (_osMotor != null)
|
|
{
|
|
if (_osMotor is osVMmotorSim motor)
|
|
VelocidadActual = motor.Velocidad;
|
|
} else if (Motor.Length > 0)
|
|
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
|
|
}
|
|
|
|
public override void ucLoaded()
|
|
{
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
// crear el objeto de simulacion
|
|
ActualizarLeftTop();
|
|
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
// crear el objeto de simulacion
|
|
if (_visualRepresentation is ucTransporteGuias uc)
|
|
{
|
|
SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo);
|
|
SimGeometria.TransportWithGuides = true;
|
|
SimGeometria.DistanceGuide2Guide = Alto;
|
|
Guia_Superior = AddLine(simulationManager, uc.GuiaSuperior);
|
|
Guia_Inferior = AddLine(simulationManager, uc.GuiaInferior);
|
|
|
|
CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion);
|
|
}
|
|
Motor = Motor; // Forzar la busqueda
|
|
}
|
|
public override void ucUnLoaded()
|
|
{
|
|
// El UserControl se esta eliminando
|
|
// eliminar el objeto de simulacion
|
|
simulationManager.Remove(SimGeometria);
|
|
simulationManager.Remove(Guia_Superior);
|
|
simulationManager.Remove(Guia_Inferior);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public partial class ucTransporteGuias : UserControl, IDataContainer
|
|
{
|
|
public osBase? Datos { get; set; }
|
|
|
|
public ucTransporteGuias()
|
|
{
|
|
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 osTransporteGuias 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 osTransporteGuias datos)
|
|
datos.Angulo = Angle;
|
|
}
|
|
public void Highlight(bool State) { }
|
|
public int ZIndex()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
}
|
|
}
|