From 794a5898c5e69ae3dde3817431480950fafad1de Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 15 May 2024 09:59:48 +0200 Subject: [PATCH] Mejora con la implementacion de la funcion que calcula el porcentaje de superfecie compartida por una botella y un transporte --- ObjetosSim/UserControlFactory.cs | 5 + ObjetosSim/ucSensTemperatura.xaml | 33 +++ ObjetosSim/ucSensTemperatura.xaml.cs | 222 ++++++++++++++++++++ ObjetosSim/ucTanque.xaml | 13 +- ObjetosSim/ucTanque.xaml.cs | 29 ++- Simulacion/FPhysics.cs | 32 ++- Simulacion/InterseccionCirculoRectangulo.cs | 73 +++++++ 7 files changed, 400 insertions(+), 7 deletions(-) create mode 100644 ObjetosSim/ucSensTemperatura.xaml create mode 100644 ObjetosSim/ucSensTemperatura.xaml.cs create mode 100644 Simulacion/InterseccionCirculoRectangulo.cs diff --git a/ObjetosSim/UserControlFactory.cs b/ObjetosSim/UserControlFactory.cs index 4c0fe9b..e281b25 100644 --- a/ObjetosSim/UserControlFactory.cs +++ b/ObjetosSim/UserControlFactory.cs @@ -29,6 +29,9 @@ namespace CtrEditor.ObjetosSim return new ucBoton(); if (tipoObjeto == typeof(osTanque)) return new ucTanque(); + if (tipoObjeto == typeof(osSensTemperatura)) + return new ucSensTemperatura(); + // Puedes añadir más condiciones para otros tipos @@ -53,6 +56,8 @@ namespace CtrEditor.ObjetosSim return new osBoton(); if (tipoObjeto == typeof(osTanque)) return new osTanque(); + if (tipoObjeto == typeof(osSensTemperatura)) + return new osSensTemperatura(); // Puedes añadir más condiciones para otros tipos diff --git a/ObjetosSim/ucSensTemperatura.xaml b/ObjetosSim/ucSensTemperatura.xaml new file mode 100644 index 0000000..287ccfc --- /dev/null +++ b/ObjetosSim/ucSensTemperatura.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/ObjetosSim/ucSensTemperatura.xaml.cs b/ObjetosSim/ucSensTemperatura.xaml.cs new file mode 100644 index 0000000..d93f030 --- /dev/null +++ b/ObjetosSim/ucSensTemperatura.xaml.cs @@ -0,0 +1,222 @@ +using CtrEditor.Convertidores; +using CtrEditor.Siemens; +using Siemens.Simatic.Simulation.Runtime; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace CtrEditor.ObjetosSim +{ + /// + /// Interaction logic for ucSensTemperatura.xaml + /// + public class osSensTemperatura : osBase + { + // Otros datos y métodos relevantes para la simulación + + private string _nombre = "Temperatura"; + private float _ancho; + private float _alto; + private float _left; + private float _top; + private float _angulo; + private string _tag; + private float _value; + private float _max_OUT_Scaled; + private float _min_OUT_Scaled; + + public string Tag + { + get => _tag; + set + { + if (_tag != value) + { + _tag = value; + OnPropertyChanged(nameof(Tag)); + } + } + } + + public float Min_OUT_Scaled + { + get => _min_OUT_Scaled; + set + { + _min_OUT_Scaled = value; + OnPropertyChanged(nameof(Min_OUT_Scaled)); + } + } + public float Max_OUT_Scaled + { + get => _max_OUT_Scaled; + set + { + _max_OUT_Scaled = value; + OnPropertyChanged(nameof(Max_OUT_Scaled)); + } + } + + public float Value + { + get => _value; + set + { + _value = value; + OnPropertyChanged(nameof(Value)); + } + } + public override float Left + { + get => _left; + set + { + _left = value; + CanvasSetLeftinMeter(value); + OnPropertyChanged(nameof(Left)); + } + } + public override float Top + { + get => _top; + set + { + _top = value; + CanvasSetTopinMeter(value); + OnPropertyChanged(nameof(Top)); + } + } + + public float Ancho + { + get => _ancho; + set + { + _ancho = value; + OnPropertyChanged(nameof(Ancho)); + } + } + public float Alto + { + get => _alto; + set + { + _alto = value; + OnPropertyChanged(nameof(Alto)); + } + } + + public float Angulo + { + get => _angulo; + set + { + _angulo = value; + OnPropertyChanged(nameof(Angulo)); + } + } + + public override string Nombre + { + get => _nombre; + set + { + if (_nombre != value) + { + _nombre = value; + OnPropertyChanged(nameof(Nombre)); + } + } + } + + public osSensTemperatura() + { + Ancho = 0.4f; + Alto = 1f; + Max_OUT_Scaled = 27648; + Min_OUT_Scaled = 0; + } + + public override void UpdateGeometryStart() + { + // Se llama antes de la simulacion + + } + public override void UpdateGeometryStep() + { + } + public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) + { + if (Tag.Length > 0) + { + SDataValue s = new SDataValue(); + s.UInt16 = (ushort)((Value / 100.0 * Max_OUT_Scaled) + Min_OUT_Scaled); + plc.EscribirTag(Tag, s); + } + } + + public override void UpdateControl() + { + + } + public override void ucLoaded() + { + // El UserControl ya se ha cargado y podemos obtener las coordenadas para + // crear el objeto de simulacion + } + + } + + public partial class ucSensTemperatura : UserControl, IDataContainer + { + public osBase? Datos { get; set; } + + public ucSensTemperatura() + { + InitializeComponent(); + this.Loaded += OnLoaded; + } + private void OnLoaded(object sender, RoutedEventArgs e) + { + Datos?.ucLoaded(); + } + public void Resize(float width, float height) + { + if (Datos is osSensTemperatura datos) + { + datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width); + datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(width); + } + } + 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) + { + if (Datos != null) + if (Datos is osSensTemperatura datos) + datos.Angulo = Angle; + } + public void Highlight(bool State) { } + public int ZIndex() + { + return 10; + } + } +} diff --git a/ObjetosSim/ucTanque.xaml b/ObjetosSim/ucTanque.xaml index c91e3f1..c50dc78 100644 --- a/ObjetosSim/ucTanque.xaml +++ b/ObjetosSim/ucTanque.xaml @@ -18,8 +18,16 @@ Source="/tank.png" Width="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" - Stretch="Uniform"/> - + Stretch="Uniform"> + + + +