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 System.Diagnostics;
using Newtonsoft.Json.Linq;
using System.Reflection;
namespace CtrEditor
{
@ -232,7 +233,7 @@ namespace CtrEditor
ItemDoubleClickCommand = new ParameterizedRelayCommand(ExecuteDoubleClick);
_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;
StartSimulationCommand = new RelayCommand(StartSimulation);
@ -330,14 +331,18 @@ namespace CtrEditor
var baseType = typeof(osBase);
var types = AppDomain.CurrentDomain.GetAssemblies()
.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)
{
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()
{
foreach (var objetoSimulable in ObjetosSimulables)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,18 +21,25 @@ namespace CtrEditor.ObjetosSim.UserControls
/// <summary>
/// Interaction logic for ucPhotocell.xaml
/// </summary>
public class osPhotocell : osBase
public class osPhotocell : osBase, IosBase
{
private float _ancho;
private float _altoPhotocell;
private float _left;
private float _top;
private float _angulo;
private string _nombre = "Photocell";
private string _nombre = NombreClase();
private bool _luzCortada;
private string _tagPhotocellOUT;
private bool _tipoNC;
private simBarrera Simulation_Photocell;
public static string NombreClase()
{
return "Photocell";
}
public bool 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
{
get => _left;
@ -140,7 +173,9 @@ namespace CtrEditor.ObjetosSim.UserControls
{
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()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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