2024-05-31 10:06:49 -03:00
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
using LibS7Adv;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
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;
|
2024-06-30 13:17:44 -03:00
|
|
|
|
using CtrEditor.FuncionesBase;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
|
2024-05-31 10:06:49 -03:00
|
|
|
|
namespace CtrEditor.ObjetosSim
|
2024-05-27 05:34:20 -03:00
|
|
|
|
{
|
|
|
|
|
/// <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();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
2024-05-27 05:34:20 -03:00
|
|
|
|
{
|
|
|
|
|
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
|
2024-06-09 12:33:09 -03:00
|
|
|
|
base.ucLoaded();
|
2024-05-27 05:34:20 -03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2024-06-28 14:47:08 -03:00
|
|
|
|
datos.Ancho += PixelToMeter.Instance.calc.PixelsToMeters(width);
|
|
|
|
|
datos.Alto += PixelToMeter.Instance.calc.PixelsToMeters(height);
|
2024-05-27 05:34:20 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Move(float LeftPixels, float TopPixels)
|
|
|
|
|
{
|
|
|
|
|
if (Datos != null)
|
|
|
|
|
{
|
|
|
|
|
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
|
|
|
|
|
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-30 09:32:32 -03:00
|
|
|
|
public float Angle() { return 0; } public void Rotate(float Angle) { }
|
2024-05-27 05:34:20 -03:00
|
|
|
|
public void Highlight(bool State) { }
|
2024-06-30 13:17:44 -03:00
|
|
|
|
public ZIndexEnum ZIndex()
|
2024-05-27 05:34:20 -03:00
|
|
|
|
{
|
2024-06-30 13:17:44 -03:00
|
|
|
|
return ZIndexEnum.Trace;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
}
|
2024-06-30 13:17:44 -03:00
|
|
|
|
|
2024-05-27 05:34:20 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|