Cambiada la lista de Funciones para que muestre Nombre en vez del nombre de la clase

This commit is contained in:
Miguel 2024-05-19 21:38:57 +02:00
parent 1bccd5d33b
commit 0d18cae40a
16 changed files with 108 additions and 31 deletions

View File

@ -28,6 +28,7 @@ using CtrEditor.Convertidores;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Diagnostics; using System.Diagnostics;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Reflection;
namespace CtrEditor namespace CtrEditor
{ {
@ -232,7 +233,7 @@ namespace CtrEditor
ItemDoubleClickCommand = new ParameterizedRelayCommand(ExecuteDoubleClick); ItemDoubleClickCommand = new ParameterizedRelayCommand(ExecuteDoubleClick);
_timerSimulacion = new DispatcherTimer(); _timerSimulacion = new DispatcherTimer();
_timerSimulacion.Interval = TimeSpan.FromMilliseconds(16); // ajusta el intervalo según sea necesario _timerSimulacion.Interval = TimeSpan.FromMilliseconds(1); // ajusta el intervalo según sea necesario
_timerSimulacion.Tick += OnTickSimulacion; _timerSimulacion.Tick += OnTickSimulacion;
StartSimulationCommand = new RelayCommand(StartSimulation); StartSimulationCommand = new RelayCommand(StartSimulation);
@ -330,14 +331,18 @@ namespace CtrEditor
var baseType = typeof(osBase); var baseType = typeof(osBase);
var types = AppDomain.CurrentDomain.GetAssemblies() var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes()) .SelectMany(assembly => assembly.GetTypes())
.Where(type => type.IsSubclassOf(baseType) && !type.IsAbstract); .Where(type => type.IsSubclassOf(baseType) && !type.IsAbstract && typeof(IosBase).IsAssignableFrom(type));
foreach (var type in types) foreach (var type in types)
{ {
ListaOsBase.Add(new TipoSimulable { Nombre = type.Name, Tipo = type }); var methodInfo = type.GetMethod("NombreClase", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
string nombre = methodInfo != null ? methodInfo.Invoke(null, null)?.ToString() : "Nombre no encontrado";
ListaOsBase.Add(new TipoSimulable { Nombre = nombre, Tipo = type });
} }
} }
private void StartSimulation() private void StartSimulation()
{ {
foreach (var objetoSimulable in ObjetosSimulables) foreach (var objetoSimulable in ObjetosSimulables)

View File

@ -20,7 +20,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucBasicExample.xaml /// Interaction logic for ucBasicExample.xaml
/// </summary> /// </summary>
public class osBasicExample : osBase public class osBasicExample : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación

View File

@ -25,16 +25,20 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
/// ///
public class osBotella : osBase public class osBotella : osBase, IosBase
{ {
private float _diametro; private float _diametro;
private float _mass; private float _mass;
private Vector2 _centro = new Vector2(); // Centro private Vector2 _centro = new Vector2(); // Centro
private string _nombre = "Botella"; private string _nombre = NombreClase();
private simBotella Simulacion_Botella; private simBotella Simulacion_Botella;
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
public static string NombreClase()
{
return "Botella";
}
public float Diametro { public float Diametro {
get => _diametro; get => _diametro;

View File

@ -20,7 +20,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucBoton.xaml /// Interaction logic for ucBoton.xaml
/// </summary> /// </summary>
public class osBoton : osBase public class osBoton : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -32,7 +32,12 @@ namespace CtrEditor.ObjetosSim
private string _tag; private string _tag;
private Brush _color; private Brush _color;
private Brush _colorButton; private Brush _colorButton;
public static string NombreClase()
{
return "Boton";
}
public Brush Color public Brush Color
{ {

View File

@ -10,7 +10,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucDescarte.xaml /// Interaction logic for ucDescarte.xaml
/// </summary> /// </summary>
public class osDescarte : osBase public class osDescarte : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -18,7 +18,10 @@ namespace CtrEditor.ObjetosSim
private float _diametro; private float _diametro;
private Vector2 _centro = new Vector2(); // Centro private Vector2 _centro = new Vector2(); // Centro
private simDescarte AreaDeDescarte; private simDescarte AreaDeDescarte;
public static string NombreClase()
{
return "Descarte";
}
public override float Left public override float Left
{ {
get => _centro.X - Diametro / 2; get => _centro.X - Diametro / 2;

View File

@ -22,7 +22,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucFiller.xaml /// Interaction logic for ucFiller.xaml
/// </summary> /// </summary>
public class osFiller : osBase public class osFiller : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -42,6 +42,10 @@ namespace CtrEditor.ObjetosSim
private float _topSalida; private float _topSalida;
private List<osBotella> Botellas = new List<osBotella>(); private List<osBotella> Botellas = new List<osBotella>();
public static string NombreClase()
{
return "Filler";
}
public float OffsetLeftSalida public float OffsetLeftSalida
{ {
get => _leftSalida; get => _leftSalida;

View File

@ -24,7 +24,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucGuia.xaml /// Interaction logic for ucGuia.xaml
/// </summary> /// </summary>
public class osGuia : osBase public class osGuia : osBase, IosBase
{ {
private float _ancho; private float _ancho;
private float _altoGuia; private float _altoGuia;
@ -35,6 +35,10 @@ namespace CtrEditor.ObjetosSim
private simGuia Simulation_Guia; private simGuia Simulation_Guia;
public static string NombreClase()
{
return "Guia";
}
public override float Left public override float Left
{ {
get => _left; get => _left;

View File

@ -21,18 +21,25 @@ namespace CtrEditor.ObjetosSim.UserControls
/// <summary> /// <summary>
/// Interaction logic for ucPhotocell.xaml /// Interaction logic for ucPhotocell.xaml
/// </summary> /// </summary>
public class osPhotocell : osBase public class osPhotocell : osBase, IosBase
{ {
private float _ancho; private float _ancho;
private float _altoPhotocell; private float _altoPhotocell;
private float _left; private float _left;
private float _top; private float _top;
private float _angulo; private float _angulo;
private string _nombre = "Photocell"; private string _nombre = NombreClase();
private bool _luzCortada; private bool _luzCortada;
private string _tagPhotocellOUT;
private bool _tipoNC;
private simBarrera Simulation_Photocell; private simBarrera Simulation_Photocell;
public static string NombreClase()
{
return "Photocell";
}
public bool LuzCortada public bool LuzCortada
{ {
get => _luzCortada; get => _luzCortada;
@ -46,6 +53,32 @@ namespace CtrEditor.ObjetosSim.UserControls
} }
} }
public bool Tipo_NC
{
get => _tipoNC;
set
{
if (_tipoNC != value)
{
_tipoNC = value;
OnPropertyChanged(nameof(Tipo_NC));
}
}
}
public string TagPhotocell_OUT
{
get => _tagPhotocellOUT;
set
{
if (_tagPhotocellOUT != value)
{
_tagPhotocellOUT = value;
OnPropertyChanged(nameof(TagPhotocell_OUT));
}
}
}
public override float Left public override float Left
{ {
get => _left; get => _left;
@ -140,7 +173,9 @@ namespace CtrEditor.ObjetosSim.UserControls
{ {
Simulation_Photocell.LuzCortada = false; Simulation_Photocell.LuzCortada = false;
} }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { } public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) {
EscribirBitTag(plc, TagPhotocell_OUT, LuzCortada);
}
public override void ucLoaded() public override void ucLoaded()
{ {
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para

View File

@ -21,7 +21,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucSensTemperatura.xaml /// Interaction logic for ucSensTemperatura.xaml
/// </summary> /// </summary>
public class osSensTemperatura : osBase public class osSensTemperatura : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -36,6 +36,10 @@ namespace CtrEditor.ObjetosSim
private float _max_OUT_Scaled; private float _max_OUT_Scaled;
private float _min_OUT_Scaled; private float _min_OUT_Scaled;
public static string NombreClase()
{
return "Temperatura";
}
public string Tag public string Tag
{ {
get => _tag; get => _tag;

View File

@ -23,7 +23,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucTanque.xaml /// Interaction logic for ucTanque.xaml
/// </summary> /// </summary>
public class osTanque : osBase public class osTanque : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -45,6 +45,10 @@ namespace CtrEditor.ObjetosSim
private bool _SalidaAbierta_Bool; private bool _SalidaAbierta_Bool;
private float _capacidadLitros; private float _capacidadLitros;
public static string NombreClase()
{
return "Tanque";
}
public float Capacidad_Litros public float Capacidad_Litros
{ {
get => _capacidadLitros; get => _capacidadLitros;

View File

@ -21,7 +21,7 @@ namespace CtrEditor.ObjetosSim.UserControls
/// <summary> /// <summary>
/// Interaction logic for ucTransporteCurva.xaml /// Interaction logic for ucTransporteCurva.xaml
/// </summary> /// </summary>
public class osTransporteCurva : osBase public class osTransporteCurva : osBase, IosBase
{ {
private string _nombre = "Transporte Curva"; private string _nombre = "Transporte Curva";

View File

@ -22,7 +22,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucTransporteGuias.xaml /// Interaction logic for ucTransporteGuias.xaml
/// </summary> /// </summary>
public class osTransporteGuias : osBase public class osTransporteGuias : osBase, IosBase
{ {
private string _nombre = "Transporte Guias"; private string _nombre = "Transporte Guias";
@ -48,7 +48,10 @@ namespace CtrEditor.ObjetosSim
private simGuia? Guia_Inferior; private simGuia? Guia_Inferior;
public static string NombreClase()
{
return "Transporte Guias";
}
public string Motor public string Motor
{ {
get => _motor; get => _motor;

View File

@ -12,7 +12,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
/// ///
public class osTransporteTTop : osBase public class osTransporteTTop : osBase, IosBase
{ {
private string _nombre = "Transporte TTOP"; private string _nombre = "Transporte TTOP";
@ -32,6 +32,10 @@ namespace CtrEditor.ObjetosSim
private simTransporte Simulation_Transporte; private simTransporte Simulation_Transporte;
public static string NombreClase()
{
return "Transporte";
}
public string Motor public string Motor
{ {
get => _motor; get => _motor;

View File

@ -24,12 +24,12 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
/// ///
public class osVMmotorSim : osBase public class osVMmotorSim : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
private string _nombre = "VetroMeccanica Motor"; private string _nombre = NombreClase();
private float _tamano; private float _tamano;
private float _left; private float _left;
private float _top; private float _top;
@ -43,6 +43,11 @@ namespace CtrEditor.ObjetosSim
private VMSimMotor motState = new VMSimMotor(); private VMSimMotor motState = new VMSimMotor();
public static string NombreClase()
{
return "VetroMeccanica Motor";
}
[Hidden] [Hidden]
[JsonIgnore] [JsonIgnore]
public ImageSource ImageSource public ImageSource ImageSource

View File

@ -27,9 +27,7 @@ namespace CtrEditor.ObjetosSim
public interface IosBase public interface IosBase
{ {
string Nombre { get; } static abstract string NombreClase();
void UpdateControl(int elapsedMilliseconds);
} }
public interface IDataContainer public interface IDataContainer
@ -43,8 +41,10 @@ namespace CtrEditor.ObjetosSim
int ZIndex(); int ZIndex();
} }
public abstract class osBase : INotifyPropertyChanged, IosBase public abstract class osBase : INotifyPropertyChanged
{ {
public virtual string Nombre { get; set; } = "osBase";
public abstract float Left { get; set; } public abstract float Left { get; set; }
public abstract float Top { get; set; } public abstract float Top { get; set; }
@ -55,8 +55,6 @@ namespace CtrEditor.ObjetosSim
[JsonIgnore] [JsonIgnore]
protected UserControl? _visualRepresentation = null; protected UserControl? _visualRepresentation = null;
public abstract string Nombre { get; set; }
public abstract void UpdateControl(int elapsedMilliseconds); public abstract void UpdateControl(int elapsedMilliseconds);
public abstract void UpdateGeometryStart(); public abstract void UpdateGeometryStart();
public abstract void UpdateGeometryStep(); public abstract void UpdateGeometryStep();
@ -76,7 +74,6 @@ namespace CtrEditor.ObjetosSim
[JsonIgnore] [JsonIgnore]
public SimulationManagerFP simulationManager; public SimulationManagerFP simulationManager;
protected osBase ObtenerLink(string NameLink, Type tipoOsBase) protected osBase ObtenerLink(string NameLink, Type tipoOsBase)
{ {
if (!string.IsNullOrEmpty(NameLink) && _mainViewModel != null) if (!string.IsNullOrEmpty(NameLink) && _mainViewModel != null)

View File

@ -42,7 +42,7 @@ namespace CtrEditor.Siemens
{ {
IsConnected = false; IsConnected = false;
PLCInterface = new PLCModel(); PLCInterface = new PLCModel();
_timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) }; _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(1) };
_timer.Tick += (s, e) => Refresh(); _timer.Tick += (s, e) => Refresh();
ConnectCommand = new RelayCommand(Connect, () => true); ConnectCommand = new RelayCommand(Connect, () => true);