205 lines
5.6 KiB
C#
205 lines
5.6 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media.Animation;
|
|
using System.Windows.Media;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
using LibS7Adv;
|
|
using CtrEditor.Simulacion;
|
|
using System.Windows.Input;
|
|
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ucBasicExample.xaml
|
|
/// </summary>
|
|
///
|
|
|
|
public partial class osBasicExample : osBase, IosBase
|
|
{
|
|
private osBase _osMotor = null;
|
|
|
|
private simTransporte SimGeometria;
|
|
|
|
public static string NombreClase()
|
|
{
|
|
return "Example";
|
|
}
|
|
private string nombre = "Transporte TTOP";
|
|
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 ucBasicExample 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;
|
|
[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 ucBasicExample uc)
|
|
{
|
|
UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo);
|
|
SetSpeed();
|
|
}
|
|
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
|
|
}
|
|
|
|
public osBasicExample()
|
|
{
|
|
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(PLCViewModel 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
|
|
base.ucLoaded();
|
|
|
|
if (_visualRepresentation is ucBasicExample 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 ucBasicExample : UserControl, IDataContainer
|
|
{
|
|
public osBase? Datos { get; set; }
|
|
|
|
public ucBasicExample()
|
|
{
|
|
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 osBasicExample 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 float Angle()
|
|
{
|
|
if (Datos != null)
|
|
if (Datos is osBasicExample datos)
|
|
return datos.Angulo;
|
|
return 0f;
|
|
}
|
|
public void Rotate(float Angle)
|
|
{
|
|
if (Datos != null)
|
|
if (Datos is osBasicExample datos)
|
|
datos.Angulo += Angle;
|
|
}
|
|
public void Highlight(bool State) { }
|
|
public int ZIndex()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|