CtrEditor/ObjetosSim/ucBasicExample.xaml.cs

198 lines
5.4 KiB
C#
Raw Normal View History

2024-06-04 12:33:00 -03:00
using System.Windows;
2024-05-14 13:17:46 -03:00
using System.Windows.Controls;
2024-06-04 12:33:00 -03:00
using System.Windows.Media.Animation;
2024-05-14 13:17:46 -03:00
using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel;
2024-05-14 13:17:46 -03:00
using LibS7Adv;
2024-06-04 12:33:00 -03:00
using CtrEditor.Simulacion;
using System.Windows.Input;
2024-05-14 13:17:46 -03:00
namespace CtrEditor.ObjetosSim
{
/// <summary>
/// Interaction logic for ucBasicExample.xaml
/// </summary>
///
public partial class osBasicExample : osBase, IosBase
2024-05-14 13:17:46 -03:00
{
2024-06-04 12:33:00 -03:00
private osBase _osMotor = null;
2024-05-14 13:17:46 -03:00
2024-06-04 12:33:00 -03:00
private simTransporte SimGeometria;
2024-05-14 13:17:46 -03:00
public static string NombreClase()
2024-05-14 13:17:46 -03:00
{
2024-06-04 12:33:00 -03:00
return "Example";
2024-05-14 13:17:46 -03:00
}
2024-06-04 12:33:00 -03:00
private string nombre = "Transporte TTOP";
public override string Nombre
2024-05-14 13:17:46 -03:00
{
get => nombre;
set => SetProperty(ref nombre, value);
2024-05-14 13:17:46 -03:00
}
[ObservableProperty]
2024-06-04 12:33:00 -03:00
public float velocidadActual;
partial void OnVelocidadActualChanged(float value)
{
SetSpeed();
}
[ObservableProperty]
2024-06-04 12:33:00 -03:00
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]
2024-06-04 12:33:00 -03:00
public string motor;
2024-05-14 13:17:46 -03:00
2024-06-04 12:33:00 -03:00
partial void OnMotorChanged(string value)
2024-05-14 13:17:46 -03:00
{
2024-06-04 12:33:00 -03:00
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
2024-05-14 13:17:46 -03:00
}
[ObservableProperty]
2024-06-04 12:33:00 -03:00
public float ancho;
[ObservableProperty]
2024-06-04 12:33:00 -03:00
public float alto;
[ObservableProperty]
2024-06-04 12:33:00 -03:00
public float angulo;
[ObservableProperty]
public float frictionCoefficient;
[ObservableProperty]
2024-06-04 12:33:00 -03:00
public float velMax50hz;
[ObservableProperty]
public float tiempoRampa;
[ObservableProperty]
public bool esMarcha;
2024-06-04 12:33:00 -03:00
private void ActualizarGeometrias()
2024-05-14 13:17:46 -03:00
{
2024-06-04 12:33:00 -03:00
if (_visualRepresentation is ucBasicExample uc)
{
UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo);
SetSpeed();
}
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
2024-05-14 13:17:46 -03:00
}
public osBasicExample()
{
2024-06-04 12:33:00 -03:00
Ancho = 1;
Alto = 0.10f;
2024-05-14 13:17:46 -03:00
}
2024-06-04 12:33:00 -03:00
public override void SimulationStop()
2024-05-14 13:17:46 -03:00
{
2024-06-04 12:33:00 -03:00
// Se llama al detener la simulacion
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
2024-05-14 13:17:46 -03:00
}
2024-06-04 12:33:00 -03:00
public override void UpdateGeometryStart()
2024-05-14 13:17:46 -03:00
{
2024-06-04 12:33:00 -03:00
// Se llama antes de la simulacion
ActualizarGeometrias();
2024-05-14 13:17:46 -03:00
}
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
2024-05-14 13:17:46 -03:00
{
2024-06-04 12:33:00 -03:00
if (_osMotor != null)
{
if (_osMotor is osVMmotorSim motor)
VelocidadActual = motor.Velocidad;
}
else if (Motor.Length > 0)
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
2024-05-14 13:17:46 -03:00
}
2024-05-14 13:17:46 -03:00
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
base.ucLoaded();
2024-05-14 13:17:46 -03:00
2024-06-04 12:33:00 -03:00
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);
}
2024-06-04 12:33:00 -03:00
2024-05-14 13:17:46 -03:00
}
public partial class ucBasicExample : UserControl, IDataContainer
{
public osBase? Datos { get; set; }
public ucBasicExample()
{
InitializeComponent();
this.Loaded += OnLoaded;
this.Unloaded += OnUnloaded;
2024-05-14 13:17:46 -03:00
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Datos?.ucLoaded();
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
Datos?.ucUnLoaded();
}
2024-06-04 12:33:00 -03:00
public void Resize(float width, float height)
{
if (Datos is osBasicExample datos)
datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
2024-06-04 12:33:00 -03:00
}
2024-05-14 13:17:46 -03:00
public void Move(float LeftPixels, float TopPixels)
{
if (Datos != null)
{
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
}
}
2024-06-04 12:33:00 -03:00
public void Rotate(float Angle)
{
if (Datos != null)
if (Datos is osBasicExample datos)
datos.Angulo += Angle;
2024-06-04 12:33:00 -03:00
}
2024-05-14 13:17:46 -03:00
public void Highlight(bool State) { }
public int ZIndex()
{
2024-06-04 12:33:00 -03:00
return 1;
2024-05-14 13:17:46 -03:00
}
2024-06-04 12:33:00 -03:00
2024-05-14 13:17:46 -03:00
}
}
2024-06-04 12:33:00 -03:00