169 lines
4.6 KiB
C#
169 lines
4.6 KiB
C#
using CtrEditor.Convertidores;
|
|
using CtrEditor.Siemens;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using Newtonsoft.Json;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using System.Collections.ObjectModel;
|
|
using LiveChartsCore;
|
|
using LiveChartsCore.SkiaSharpView;
|
|
using LiveChartsCore.Defaults;
|
|
using System.Diagnostics;
|
|
|
|
namespace CtrEditor.ObjetosSim.Traces
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ucTraceSimple.xaml
|
|
/// </summary>
|
|
public partial class osTraceSimple : osBase, IosBase
|
|
{
|
|
|
|
private List<float> data;
|
|
Stopwatch stopwatch;
|
|
private double YScale { get; set; }
|
|
|
|
// Otros datos y métodos relevantes para la simulación
|
|
|
|
public static string NombreClase()
|
|
{
|
|
return "Trace";
|
|
}
|
|
private string nombre = NombreClase();
|
|
public override string Nombre
|
|
{
|
|
get => nombre;
|
|
set => SetProperty(ref nombre, value);
|
|
}
|
|
|
|
[ObservableProperty]
|
|
float alto;
|
|
|
|
[ObservableProperty]
|
|
float ancho;
|
|
|
|
[ObservableProperty]
|
|
string tag_serie;
|
|
|
|
[ObservableProperty]
|
|
string x_Series_Name;
|
|
|
|
[ObservableProperty]
|
|
string y_Series_Name;
|
|
|
|
private readonly ObservableCollection<ObservableValue> _observableValues;
|
|
|
|
|
|
public ObservableCollection<ISeries> Series { get; set; }
|
|
|
|
public osTraceSimple()
|
|
{
|
|
// Use ObservableCollections to let the chart listen for changes (or any INotifyCollectionChanged).
|
|
_observableValues = new ObservableCollection<ObservableValue>();
|
|
Series = new ObservableCollection<ISeries>
|
|
{
|
|
new LineSeries<ObservableValue>
|
|
{
|
|
Values = _observableValues,
|
|
Fill = null
|
|
}
|
|
};
|
|
data = new List<float>();
|
|
stopwatch = new Stopwatch();
|
|
|
|
YScale = 2.0;
|
|
Alto = 1;
|
|
Ancho = 1;
|
|
}
|
|
|
|
public override void UpdateGeometryStart()
|
|
{
|
|
// Se llama antes de la simulacion
|
|
|
|
}
|
|
|
|
public override void UpdatePLCPrimerCiclo()
|
|
{
|
|
stopwatch.Start();
|
|
}
|
|
|
|
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
|
|
{
|
|
if (Tag_serie != null && Tag_serie.Length > 0) {
|
|
var value = LeerBitTag(Tag_serie) == false ? 0 : 1;
|
|
data.Add(value);
|
|
}
|
|
if (data.Count > 50)
|
|
data.RemoveAt(0);
|
|
if (stopwatch.ElapsedMilliseconds > 1000)
|
|
{
|
|
stopwatch.Reset();
|
|
stopwatch.Start();
|
|
foreach (var v in data)
|
|
{
|
|
_observableValues.Add(new(v));
|
|
if (_observableValues.Count > 50)
|
|
_observableValues.RemoveAt(0);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
|
{
|
|
// Calculamos la velocidad
|
|
|
|
}
|
|
|
|
public override void ucLoaded()
|
|
{
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
// crear el objeto de simulacion
|
|
ActualizarLeftTop();
|
|
|
|
}
|
|
}
|
|
|
|
public partial class ucTraceSimple : UserControl, IDataContainer
|
|
{
|
|
public osBase? Datos { get; set; }
|
|
|
|
public ucTraceSimple()
|
|
{
|
|
InitializeComponent();
|
|
this.Loaded += OnLoaded;
|
|
this.Unloaded += OnUnloaded;
|
|
}
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Datos?.ucLoaded();
|
|
}
|
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Datos?.ucUnLoaded();
|
|
}
|
|
public void Resize(float width, float height) {
|
|
if (Datos is osTraceSimple datos)
|
|
{
|
|
datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
|
|
datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(height);
|
|
}
|
|
}
|
|
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) { }
|
|
public void Highlight(bool State) { }
|
|
public int ZIndex()
|
|
{
|
|
return 10;
|
|
}
|
|
}
|
|
|
|
}
|