Actualizados todos los objetos Transporte con la nueva logica

This commit is contained in:
Miguel 2024-06-09 10:55:21 +02:00
parent c58a264d38
commit 2187783fe2
4 changed files with 123 additions and 55 deletions

View File

@ -1,11 +1,10 @@
using System.Windows; using System.ComponentModel;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using Newtonsoft.Json.Linq; using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
@ -14,7 +13,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
public partial class osTransporteCurva : osBase, IosBase public partial class osTransporteCurva : osBase, IosBase
{ {
private osBase _osMotor = null; private osBase Motor = null;
private simCurve Simulation_TransporteCurva; private simCurve Simulation_TransporteCurva;
@ -59,8 +58,32 @@ namespace CtrEditor.ObjetosSim
private float radioExterno; private float radioExterno;
[ObservableProperty] [ObservableProperty]
private float radioInterno; private float radioInterno;
[ObservableProperty]
private string motor; [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] [ObservableProperty]
[NotifyPropertyChangedFor(nameof(AnguloFinal))] [NotifyPropertyChangedFor(nameof(AnguloFinal))]
@ -110,13 +133,11 @@ namespace CtrEditor.ObjetosSim
} }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
if (_osMotor != null) if (Motor != null)
{ {
if (_osMotor is osVMmotorSim motor) if (Motor is osVMmotorSim motor)
VelocidadActual = motor.Velocidad; VelocidadActual = motor.Velocidad;
} }
else
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
} }
public override void ucLoaded() public override void ucLoaded()
@ -125,6 +146,8 @@ namespace CtrEditor.ObjetosSim
// crear el objeto de simulacion // crear el objeto de simulacion
ActualizarLeftTop(); ActualizarLeftTop();
OnId_MotorChanged(Id_Motor); // Link Id_Motor = Motor
if (_visualRepresentation is ucTransporteCurva uc) if (_visualRepresentation is ucTransporteCurva uc)
Simulation_TransporteCurva = AddCurve(RadioInterno,RadioExterno, Angulo, Angulo + Arco_en_grados); Simulation_TransporteCurva = AddCurve(RadioInterno,RadioExterno, Angulo, Angulo + Arco_en_grados);

View File

@ -1,9 +1,11 @@
using System.Windows; using System.ComponentModel;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
@ -12,7 +14,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
public partial class osTransporteGuias : osBase, IosBase public partial class osTransporteGuias : osBase, IosBase
{ {
private osBase _osMotor = null; private osBase Motor = null;
private simTransporte? SimGeometria; private simTransporte? SimGeometria;
private simGuia? Guia_Superior; private simGuia? Guia_Superior;
@ -24,6 +26,7 @@ namespace CtrEditor.ObjetosSim
return "Transporte Guias"; return "Transporte Guias";
} }
private string nombre = NombreClase(); private string nombre = NombreClase();
public override string Nombre public override string Nombre
{ {
get => nombre; get => nombre;
@ -65,11 +68,29 @@ namespace CtrEditor.ObjetosSim
Color color = Colors.Blue; Color color = Colors.Blue;
[ObservableProperty] [ObservableProperty]
public string motor; [property: Description("Link to Motor")]
[property: Category("PLC link:")]
[property: ItemsSource(typeof(osBaseItemsSource<osVMmotorSim>))]
string id_Motor;
partial void OnMotorChanged(string value) partial void OnId_MotorChanged(string value)
{ {
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim)); 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] [ObservableProperty]
@ -112,9 +133,9 @@ namespace CtrEditor.ObjetosSim
{ {
UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo); UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo);
UpdateOrCreateLine(Guia_Superior, uc.GuiaSuperior); UpdateOrCreateLine(Guia_Superior, uc.GuiaSuperior);
UpdateOrCreateLine(Guia_Inferior, uc.GuiaInferior) ; UpdateOrCreateLine(Guia_Inferior, uc.GuiaInferior);
SimGeometria.DistanceGuide2Guide = Alto; SimGeometria.DistanceGuide2Guide = Alto;
SimGeometria.isBrake = esFreno; SimGeometria.isBrake = esFreno;
SetSpeed(); SetSpeed();
} }
@ -126,7 +147,7 @@ namespace CtrEditor.ObjetosSim
Ancho = 1; Ancho = 1;
Alto = 0.10f; Alto = 0.10f;
AltoGuia = 0.03f; AltoGuia = 0.03f;
Distance = 0.01f; Distance = 0.01f;
} }
public override void UpdateGeometryStart() public override void UpdateGeometryStart()
@ -141,12 +162,9 @@ namespace CtrEditor.ObjetosSim
} }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
if (_osMotor != null) if (Motor != null)
{ if (Motor is osVMmotorSim id_motor)
if (_osMotor is osVMmotorSim motor) VelocidadActual = id_motor.Velocidad;
VelocidadActual = motor.Velocidad;
} else if (Motor.Length > 0)
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
} }
public override void ucLoaded() public override void ucLoaded()
@ -167,7 +185,7 @@ namespace CtrEditor.ObjetosSim
CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion);
} }
Motor = Motor; // Forzar la busqueda OnId_MotorChanged(Id_Motor); // Link Id_Motor = Motor
} }
public override void ucUnLoaded() public override void ucUnLoaded()
{ {

View File

@ -1,4 +1,5 @@
using System.Windows; using System.ComponentModel;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
@ -6,7 +7,7 @@ using System.Windows.Shapes;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using SkiaSharp; using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
@ -29,6 +30,7 @@ namespace CtrEditor.ObjetosSim
return "Transporte Guias Union"; return "Transporte Guias Union";
} }
private string nombre = NombreClase(); private string nombre = NombreClase();
public override string Nombre public override string Nombre
{ {
get => nombre; get => nombre;
@ -39,13 +41,59 @@ namespace CtrEditor.ObjetosSim
Color color; Color color;
[ObservableProperty] [ObservableProperty]
public string motorA; [property: Description("Link to Motor A")]
[property: Category("PLC link:")]
[property: ItemsSource(typeof(osBaseItemsSource<osVMmotorSim>))]
string id_MotorA;
partial void OnMotorAChanged(string value) partial void OnId_MotorAChanged(string value)
{ {
_osMotorA = ObtenerLink(MotorA, typeof(osVMmotorSim)); if (_osMotorA != null)
_osMotorA.PropertyChanged -= OnMotorPropertyChangedA;
if (_mainViewModel != null && value != null && value.Length > 0)
{
_osMotorA = (osVMmotorSim)_mainViewModel.ObjetosSimulables.FirstOrDefault(s => (s is osVMmotorSim && s.Nombre == value), null);
if (_osMotorA != null)
_osMotorA.PropertyChanged += OnMotorPropertyChangedA;
}
} }
private void OnMotorPropertyChangedA(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(osVMmotorSim.Nombre))
{
Id_MotorA = ((osVMmotorSim)sender).Nombre;
}
}
[ObservableProperty]
[property: Description("Link to Motor B")]
[property: Category("PLC link:")]
[property: ItemsSource(typeof(osBaseItemsSource<osVMmotorSim>))]
string id_MotorB;
partial void OnId_MotorBChanged(string value)
{
if (_osMotorB != null)
_osMotorB.PropertyChanged -= OnMotorPropertyChangedB;
if (_mainViewModel != null && value != null && value.Length > 0)
{
_osMotorB = (osVMmotorSim)_mainViewModel.ObjetosSimulables.FirstOrDefault(s => (s is osVMmotorSim && s.Nombre == value), null);
if (_osMotorB != null)
_osMotorB.PropertyChanged += OnMotorPropertyChangedB;
}
}
private void OnMotorPropertyChangedB(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(osVMmotorSim.Nombre))
{
Id_MotorB = ((osVMmotorSim)sender).Nombre;
}
}
[ObservableProperty] [ObservableProperty]
public float velocidadActualA; public float velocidadActualA;
@ -73,15 +121,6 @@ namespace CtrEditor.ObjetosSim
} }
[ObservableProperty]
public string motorB;
partial void OnMotorBChanged(string value)
{
_osMotorB = ObtenerLink(MotorB, typeof(osVMmotorSim));
}
[ObservableProperty] [ObservableProperty]
public float velocidadActualB; public float velocidadActualB;
@ -231,17 +270,12 @@ namespace CtrEditor.ObjetosSim
if (_osMotorA is osVMmotorSim motor) if (_osMotorA is osVMmotorSim motor)
VelocidadActualA = motor.Velocidad; VelocidadActualA = motor.Velocidad;
} }
else if (MotorA.Length > 0)
_osMotorA = ObtenerLink(MotorA, typeof(osVMmotorSim));
if (_osMotorB != null) if (_osMotorB != null)
{ {
if (_osMotorB is osVMmotorSim motor) if (_osMotorB is osVMmotorSim motor)
VelocidadActualB = motor.Velocidad; VelocidadActualB = motor.Velocidad;
} }
else if (MotorB.Length > 0)
_osMotorB = ObtenerLink(MotorB, typeof(osVMmotorSim));
} }
public override void ucLoaded() public override void ucLoaded()
@ -277,7 +311,8 @@ namespace CtrEditor.ObjetosSim
TransportsVelocidad.Add(uc.TransporteB, new FloatReference(() => VelocidadActualB, value => VelocidadActualB = value)); TransportsVelocidad.Add(uc.TransporteB, new FloatReference(() => VelocidadActualB, value => VelocidadActualB = value));
} }
OnMotorAChanged(MotorA); OnId_MotorAChanged(Id_MotorA); // Link Id_Motor = Motor
OnId_MotorBChanged(Id_MotorB); // Link Id_Motor = Motor
} }

View File

@ -1,18 +1,10 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Windows.Input;
using Newtonsoft.Json;
using System.Collections.Generic;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.ComponentModel; using System.ComponentModel;
using System.Xml.Linq;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
@ -161,7 +153,7 @@ namespace CtrEditor.ObjetosSim
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion // crear el objeto de simulacion
ActualizarLeftTop(); ActualizarLeftTop();
OnId_MotorChanged(Id_Motor); OnId_MotorChanged(Id_Motor); // Link Id_Motor = Motor
if (_visualRepresentation is ucTransporteTTop uc) if (_visualRepresentation is ucTransporteTTop uc)
{ {