diff --git a/MainViewModel.cs b/MainViewModel.cs
index 14483b9..669bdc4 100644
--- a/MainViewModel.cs
+++ b/MainViewModel.cs
@@ -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)
diff --git a/ObjetosSim/UserControls/ucBasicExample.xaml.cs b/ObjetosSim/UserControls/ucBasicExample.xaml.cs
index fd1709b..84d6443 100644
--- a/ObjetosSim/UserControls/ucBasicExample.xaml.cs
+++ b/ObjetosSim/UserControls/ucBasicExample.xaml.cs
@@ -20,7 +20,7 @@ namespace CtrEditor.ObjetosSim
///
/// Interaction logic for ucBasicExample.xaml
///
- public class osBasicExample : osBase
+ public class osBasicExample : osBase, IosBase
{
// Otros datos y métodos relevantes para la simulación
diff --git a/ObjetosSim/UserControls/ucBotella.xaml.cs b/ObjetosSim/UserControls/ucBotella.xaml.cs
index 38e50dc..2264017 100644
--- a/ObjetosSim/UserControls/ucBotella.xaml.cs
+++ b/ObjetosSim/UserControls/ucBotella.xaml.cs
@@ -25,16 +25,20 @@ namespace CtrEditor.ObjetosSim
///
///
- 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;
diff --git a/ObjetosSim/UserControls/ucBoton.xaml.cs b/ObjetosSim/UserControls/ucBoton.xaml.cs
index 2da959f..666d693 100644
--- a/ObjetosSim/UserControls/ucBoton.xaml.cs
+++ b/ObjetosSim/UserControls/ucBoton.xaml.cs
@@ -20,7 +20,7 @@ namespace CtrEditor.ObjetosSim
///
/// Interaction logic for ucBoton.xaml
///
- 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
{
diff --git a/ObjetosSim/UserControls/ucDescarte.xaml.cs b/ObjetosSim/UserControls/ucDescarte.xaml.cs
index 93e9690..ff3e079 100644
--- a/ObjetosSim/UserControls/ucDescarte.xaml.cs
+++ b/ObjetosSim/UserControls/ucDescarte.xaml.cs
@@ -10,7 +10,7 @@ namespace CtrEditor.ObjetosSim
///
/// Interaction logic for ucDescarte.xaml
///
- 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;
diff --git a/ObjetosSim/UserControls/ucFiller.xaml.cs b/ObjetosSim/UserControls/ucFiller.xaml.cs
index 0460c5a..af5ef81 100644
--- a/ObjetosSim/UserControls/ucFiller.xaml.cs
+++ b/ObjetosSim/UserControls/ucFiller.xaml.cs
@@ -22,7 +22,7 @@ namespace CtrEditor.ObjetosSim
///
/// Interaction logic for ucFiller.xaml
///
- 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 Botellas = new List();
+ public static string NombreClase()
+ {
+ return "Filler";
+ }
public float OffsetLeftSalida
{
get => _leftSalida;
diff --git a/ObjetosSim/UserControls/ucGuia.xaml.cs b/ObjetosSim/UserControls/ucGuia.xaml.cs
index bdc1815..e5f3cd2 100644
--- a/ObjetosSim/UserControls/ucGuia.xaml.cs
+++ b/ObjetosSim/UserControls/ucGuia.xaml.cs
@@ -24,7 +24,7 @@ namespace CtrEditor.ObjetosSim
///
/// Interaction logic for ucGuia.xaml
///
- 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;
diff --git a/ObjetosSim/UserControls/ucPhotocell.xaml.cs b/ObjetosSim/UserControls/ucPhotocell.xaml.cs
index af4c154..d74f4b1 100644
--- a/ObjetosSim/UserControls/ucPhotocell.xaml.cs
+++ b/ObjetosSim/UserControls/ucPhotocell.xaml.cs
@@ -21,18 +21,25 @@ namespace CtrEditor.ObjetosSim.UserControls
///
/// Interaction logic for ucPhotocell.xaml
///
- 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
diff --git a/ObjetosSim/UserControls/ucSensTemperatura.xaml.cs b/ObjetosSim/UserControls/ucSensTemperatura.xaml.cs
index d38bcb3..b2e6745 100644
--- a/ObjetosSim/UserControls/ucSensTemperatura.xaml.cs
+++ b/ObjetosSim/UserControls/ucSensTemperatura.xaml.cs
@@ -21,7 +21,7 @@ namespace CtrEditor.ObjetosSim
///
/// Interaction logic for ucSensTemperatura.xaml
///
- 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;
diff --git a/ObjetosSim/UserControls/ucTanque.xaml.cs b/ObjetosSim/UserControls/ucTanque.xaml.cs
index 1a5b362..0339490 100644
--- a/ObjetosSim/UserControls/ucTanque.xaml.cs
+++ b/ObjetosSim/UserControls/ucTanque.xaml.cs
@@ -23,7 +23,7 @@ namespace CtrEditor.ObjetosSim
///
/// Interaction logic for ucTanque.xaml
///
- 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;
diff --git a/ObjetosSim/UserControls/ucTransporteCurva.xaml.cs b/ObjetosSim/UserControls/ucTransporteCurva.xaml.cs
index b96de51..f7bd8fb 100644
--- a/ObjetosSim/UserControls/ucTransporteCurva.xaml.cs
+++ b/ObjetosSim/UserControls/ucTransporteCurva.xaml.cs
@@ -21,7 +21,7 @@ namespace CtrEditor.ObjetosSim.UserControls
///
/// Interaction logic for ucTransporteCurva.xaml
///
- public class osTransporteCurva : osBase
+ public class osTransporteCurva : osBase, IosBase
{
private string _nombre = "Transporte Curva";
diff --git a/ObjetosSim/UserControls/ucTransporteGuias.xaml.cs b/ObjetosSim/UserControls/ucTransporteGuias.xaml.cs
index 0ab58d0..14d9a3a 100644
--- a/ObjetosSim/UserControls/ucTransporteGuias.xaml.cs
+++ b/ObjetosSim/UserControls/ucTransporteGuias.xaml.cs
@@ -22,7 +22,7 @@ namespace CtrEditor.ObjetosSim
///
/// Interaction logic for ucTransporteGuias.xaml
///
- 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;
diff --git a/ObjetosSim/UserControls/ucTransporteTTop.xaml.cs b/ObjetosSim/UserControls/ucTransporteTTop.xaml.cs
index 6547479..994ddb1 100644
--- a/ObjetosSim/UserControls/ucTransporteTTop.xaml.cs
+++ b/ObjetosSim/UserControls/ucTransporteTTop.xaml.cs
@@ -12,7 +12,7 @@ namespace CtrEditor.ObjetosSim
///
///
- 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;
diff --git a/ObjetosSim/UserControls/ucVMmotorSim.xaml.cs b/ObjetosSim/UserControls/ucVMmotorSim.xaml.cs
index c3f69a4..b2930ba 100644
--- a/ObjetosSim/UserControls/ucVMmotorSim.xaml.cs
+++ b/ObjetosSim/UserControls/ucVMmotorSim.xaml.cs
@@ -24,12 +24,12 @@ namespace CtrEditor.ObjetosSim
///
///
- 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
diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs
index 823873e..34e5c4c 100644
--- a/ObjetosSim/osBase.cs
+++ b/ObjetosSim/osBase.cs
@@ -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)
diff --git a/Siemens/PLCControl.xaml.cs b/Siemens/PLCControl.xaml.cs
index f083d72..4f46644 100644
--- a/Siemens/PLCControl.xaml.cs
+++ b/Siemens/PLCControl.xaml.cs
@@ -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);