CtrEditor/ObjetosSim/ucTransporteGuias.xaml.cs

279 lines
7.8 KiB
C#
Raw Normal View History

2024-05-08 08:41:26 -03:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
2024-05-11 11:58:55 -03:00
using CtrEditor.Convertidores;
2024-05-11 15:55:44 -03:00
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
using static System.Runtime.InteropServices.JavaScript.JSType;
2024-05-08 08:41:26 -03:00
namespace CtrEditor.ObjetosSim
{
/// <summary>
/// Interaction logic for ucTransporteGuias.xaml
/// </summary>
public class osTransporteGuias : osBase
2024-05-08 08:41:26 -03:00
{
private string _nombre = "Transporte Guias";
private float _distance;
private float _altoGuia;
private float frictionCoefficient;
private float velMax50hz; // en metros por minuto
private float tiempoRampa;
private bool esMarcha;
private float _ancho;
private float _alto;
private float _left;
private float _top;
private float _angulo;
private float _velocidadActual;
private osBase _osMotor = null;
private string _motor;
private simRectangle? TransporteCentral;
private simLine? Guia_Superior;
private simLine? Guia_Inferior;
public string Motor
{
get => _motor;
set
{
if (_motor != value)
{
_motor = value;
OnPropertyChanged(nameof(Motor));
}
}
}
public override float Left
{
get => _left;
set
{
_left = value;
CanvasSetLeftinMeter(value);
OnPropertyChanged(nameof(Left));
}
}
public override float Top
{
get => _top;
set
{
_top = value;
CanvasSetTopinMeter(value);
OnPropertyChanged(nameof(Top));
}
}
public float Ancho
{
get => _ancho;
set
{
_ancho = value;
OnPropertyChanged(nameof(Ancho));
}
}
public float Alto
{
get => _alto;
set
{
_alto = value;
OnPropertyChanged(nameof(Alto));
}
}
public float Angulo
{
get => _angulo;
set
{
_angulo = value;
OnPropertyChanged(nameof(Angulo));
}
}
public float VelocidadActual
{
get => _velocidadActual;
set
{
_velocidadActual = value;
TransporteCentral?.SetSpeed(value);
OnPropertyChanged(nameof(VelocidadActual));
}
}
public float Distance
{
get { return _distance; }
set
{
if (_distance != value)
{
_distance = value;
OnPropertyChanged(nameof(Distance));
}
}
}
public float AltoGuia
{
get => _altoGuia;
set
{
_altoGuia = value;
OnPropertyChanged(nameof(AltoGuia));
}
}
public override string Nombre
{
get => _nombre;
set
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
}
}
private void ActualizarGeometrias()
{
if (_visualRepresentation is ucTransporteGuias uc)
{
UpdateRectangle(TransporteCentral, uc.Transporte, Alto, Ancho, Angulo);
UpdateOrCreateLine(Guia_Superior, uc.GuiaSuperior);
UpdateOrCreateLine(Guia_Inferior, uc.GuiaInferior) ;
TransporteCentral.Speed = VelocidadActual;
}
}
public float FrictionCoefficient { get => frictionCoefficient; set => frictionCoefficient = value; }
public float VelMax50hz { get => velMax50hz; set => velMax50hz = value; }
public float TiempoRampa { get => tiempoRampa; set => tiempoRampa = value; }
public bool EsMarcha { get => esMarcha; set => esMarcha = value; }
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 UpdateGeometryStep()
{
}
public override void UpdateControl()
{
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
if (_osMotor != null)
{
if (_osMotor is osVMmotorSim motor)
VelocidadActual = motor.Velocidad;
} else
{
if (Motor.Length > 0)
if (_mainViewModel != null)
foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables)
if (objetoSimulable.Nombre == _motor)
{
_osMotor = objetoSimulable;
break;
}
}
}
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
simulationManager.rectangles.Add(TransporteCentral);
simulationManager.lines.Add(Guia_Superior);
simulationManager.lines.Add(Guia_Inferior);
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
if (_visualRepresentation is ucTransporteGuias uc)
{
TransporteCentral = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo);
Guia_Superior = AddLine(simulationManager, uc.GuiaSuperior);
Guia_Inferior = AddLine(simulationManager, uc.GuiaInferior);
}
Motor = Motor; // Forzar la busqueda
}
}
public partial class ucTransporteGuias : UserControl, IDataContainer
{
public osBase? Datos { get; set; }
2024-05-08 08:41:26 -03:00
public ucTransporteGuias()
{
InitializeComponent();
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Datos?.ucLoaded();
2024-05-08 08:41:26 -03:00
}
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;
}
2024-05-08 08:41:26 -03:00
}
}