From 0e174fc308c32cc67dce2be9490cc8ed2d26756f Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 22 May 2024 19:21:39 +0200 Subject: [PATCH] Actualizado a CommunityToolkit.Mvvm.ComponentModel para todos los UserControl --- Convertidores/Converters.cs | 19 -- CtrEditor.csproj | 4 - MainViewModel.cs | 9 +- .../UserControls/CircularSegment.xaml.cs | 13 +- ObjetosSim/UserControls/ucBasicExample.xaml | 29 +- .../UserControls/ucBasicExample.xaml.cs | 160 ++++------ ObjetosSim/UserControls/ucBotella.xaml.cs | 138 +++------ ObjetosSim/UserControls/ucBoton.xaml | 7 +- ObjetosSim/UserControls/ucBoton.xaml.cs | 125 ++------ ObjetosSim/UserControls/ucDescarte.xaml | 5 + ObjetosSim/UserControls/ucDescarte.xaml.cs | 122 +++----- ObjetosSim/UserControls/ucFiller.xaml | 9 +- ObjetosSim/UserControls/ucFiller.xaml.cs | 192 ++---------- ObjetosSim/UserControls/ucGuia.xaml.cs | 37 +-- ObjetosSim/UserControls/ucPhotocell.xaml | 11 +- ObjetosSim/UserControls/ucPhotocell.xaml.cs | 189 ++++-------- .../UserControls/ucSensTemperatura.xaml | 6 + .../UserControls/ucSensTemperatura.xaml.cs | 164 ++-------- ObjetosSim/UserControls/ucTanque.xaml | 5 + ObjetosSim/UserControls/ucTanque.xaml.cs | 284 +++--------------- .../UserControls/ucTransporteCurva.xaml.cs | 30 +- .../UserControls/ucTransporteGuias.xaml | 25 +- .../UserControls/ucTransporteGuias.xaml.cs | 202 +++---------- ObjetosSim/UserControls/ucTransporteTTop.xaml | 39 +-- .../UserControls/ucTransporteTTop.xaml.cs | 62 ++-- ObjetosSim/UserControls/ucVMmotorSim.xaml | 26 +- ObjetosSim/UserControls/ucVMmotorSim.xaml.cs | 186 +++--------- ObjetosSim/osBase.cs | 88 +++++- Simulacion/FPhysics.cs | 5 +- 29 files changed, 629 insertions(+), 1562 deletions(-) diff --git a/Convertidores/Converters.cs b/Convertidores/Converters.cs index d5a34b1..6a3c41f 100644 --- a/Convertidores/Converters.cs +++ b/Convertidores/Converters.cs @@ -11,25 +11,6 @@ using System.Windows.Media; namespace CtrEditor.Convertidores { - public class SpeedAndWidthToDurationConverter : IMultiValueConverter - { - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) - { - if (values.Length == 2 && values[0] is double speed && values[1] is double width && speed > 0) - { - // Convert speed (meters per minute) to duration (seconds) - double durationInSeconds = (width * 60) / speed; - return new Duration(TimeSpan.FromSeconds(durationInSeconds)); - } - return DependencyProperty.UnsetValue; - } - - public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - } - public class HalfWidthConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/CtrEditor.csproj b/CtrEditor.csproj index 84e6647..ea917eb 100644 --- a/CtrEditor.csproj +++ b/CtrEditor.csproj @@ -11,7 +11,6 @@ - @@ -44,12 +43,9 @@ - - - diff --git a/MainViewModel.cs b/MainViewModel.cs index ead3a47..c5ba0b5 100644 --- a/MainViewModel.cs +++ b/MainViewModel.cs @@ -389,6 +389,8 @@ namespace CtrEditor private void StartSimulation() { + IsSimulationRunning = true; + foreach (var objetoSimulable in ObjetosSimulables) objetoSimulable.UpdateGeometryStart(); @@ -399,11 +401,15 @@ namespace CtrEditor _timerSimulacion.Start(); simulationManager.stopwatch.Start(); stopwatch_SimRefresh.Start(); - IsSimulationRunning = true; } private void StopSimulation() { + IsSimulationRunning = false; + + foreach (var objetoSimulable in ObjetosSimulables) + objetoSimulable.SimulationStop(); + if (Debug_SimulacionCreado) { simulationManager.Debug_ClearSimulationShapes(); @@ -412,7 +418,6 @@ namespace CtrEditor _timerSimulacion.Stop(); simulationManager.stopwatch.Stop(); stopwatch_SimRefresh.Stop(); - IsSimulationRunning = false; } private void OnTickSimulacion(object sender, EventArgs e) diff --git a/ObjetosSim/UserControls/CircularSegment.xaml.cs b/ObjetosSim/UserControls/CircularSegment.xaml.cs index 9f38c9d..26ffb33 100644 --- a/ObjetosSim/UserControls/CircularSegment.xaml.cs +++ b/ObjetosSim/UserControls/CircularSegment.xaml.cs @@ -1,17 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +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.UserControls { diff --git a/ObjetosSim/UserControls/ucBasicExample.xaml b/ObjetosSim/UserControls/ucBasicExample.xaml index 4da0235..1aa5709 100644 --- a/ObjetosSim/UserControls/ucBasicExample.xaml +++ b/ObjetosSim/UserControls/ucBasicExample.xaml @@ -5,20 +5,33 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CtrEditor.ObjetosSim" mc:Ignorable="d" + xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:convert="clr-namespace:CtrEditor.Convertidores"> + + + + - - - - - + + + + + + + diff --git a/ObjetosSim/UserControls/ucBasicExample.xaml.cs b/ObjetosSim/UserControls/ucBasicExample.xaml.cs index 84d6443..e17073b 100644 --- a/ObjetosSim/UserControls/ucBasicExample.xaml.cs +++ b/ObjetosSim/UserControls/ucBasicExample.xaml.cs @@ -1,134 +1,103 @@ using CtrEditor.Convertidores; using CtrEditor.Siemens; -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; +using Newtonsoft.Json; +using CommunityToolkit.Mvvm.ComponentModel; namespace CtrEditor.ObjetosSim { /// /// Interaction logic for ucBasicExample.xaml /// - public class osBasicExample : osBase, IosBase + /// + + public partial class osBasicExample : osBase, IosBase { + // Otros datos y métodos relevantes para la simulación - private string _nombre = "Ejemplo"; - private float _ancho; - private float _alto; - private float _angulo; - private float _left; - private float _top; - - public override float Left + public static string NombreClase() { - get => _left; - set - { - _left = value; - CanvasSetLeftinMeter(value); - OnPropertyChanged(nameof(Left)); - } + return "Ejemplo"; } - 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)); - } - } - + private string nombre = NombreClase(); public override string Nombre { - get => _nombre; - set - { - if (_nombre != value) - { - _nombre = value; - OnPropertyChanged(nameof(Nombre)); - } - } + get => nombre; + set => SetProperty(ref nombre, value); + } + + [JsonIgnore] + [ObservableProperty] + public ImageSource imageSource_oculta; + + [ObservableProperty] + public float tamano; + [ObservableProperty] + public float maxRatedHz; + + [ObservableProperty] + public float tiempoRampa; + + partial void OnTiempoRampaChanged(float value) + { + if (value < 0.1f) + value = 0.1f; + tiempoRampa = value; + } + + [ObservableProperty] + public bool encendido; + [ObservableProperty] + public int pLC_NumeroMotor; + [ObservableProperty] + public float ratio; + + [ObservableProperty] + public float velocidad; + + partial void OnVelocidadChanged(float value) + { + if (value > 0) + ImageSource_oculta = ImageFromPath("/imagenes/motorVerde.png"); + else + ImageSource_oculta = ImageFromPath("/imagenes/motorNegro.png"); } public osBasicExample() { - Ancho = 0.30f; - Alto = 0.30f; + Tamano = 0.30f; + PLC_NumeroMotor = 31; + MaxRatedHz = 100; + TiempoRampa = 3; + ImageSource_oculta = ImageFromPath("/imagenes/motor2.png"); } public override void UpdateGeometryStart() { // Se llama antes de la simulacion - } - public override void UpdateGeometryStep() - { } public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { + } 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 override void ucUnLoaded() - { - // El UserControl se esta eliminando - // eliminar el objeto de simulacion - } - + } } public partial class ucBasicExample : UserControl, IDataContainer @@ -149,13 +118,7 @@ namespace CtrEditor.ObjetosSim { Datos?.ucUnLoaded(); } - public void Resize(float width, float height) { - if (Datos is osBasicExample datos) - { - datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width); - datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(width); - } - } + public void Resize(float width, float height) { } public void Move(float LeftPixels, float TopPixels) { if (Datos != null) @@ -164,12 +127,7 @@ namespace CtrEditor.ObjetosSim Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels); } } - public void Rotate(float Angle) - { - if (Datos != null) - if (Datos is osBasicExample datos) - datos.Angulo = Angle; - } + public void Rotate(float Angle) { } public void Highlight(bool State) { } public int ZIndex() { diff --git a/ObjetosSim/UserControls/ucBotella.xaml.cs b/ObjetosSim/UserControls/ucBotella.xaml.cs index 2264017..b42291f 100644 --- a/ObjetosSim/UserControls/ucBotella.xaml.cs +++ b/ObjetosSim/UserControls/ucBotella.xaml.cs @@ -1,22 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +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; using Microsoft.Xna.Framework; using CtrEditor.Convertidores; using CtrEditor.Siemens; using CtrEditor.Simulacion; -using Newtonsoft.Json.Linq; +using CommunityToolkit.Mvvm.ComponentModel; namespace CtrEditor.ObjetosSim { @@ -25,13 +13,9 @@ namespace CtrEditor.ObjetosSim /// /// - public class osBotella : osBase, IosBase + public partial class osBotella : osBase, IosBase { - private float _diametro; - private float _mass; - private Vector2 _centro = new Vector2(); // Centro - private string _nombre = NombreClase(); - private simBotella Simulacion_Botella; + private simBotella SimGeometria; // Otros datos y métodos relevantes para la simulación @@ -39,92 +23,48 @@ namespace CtrEditor.ObjetosSim { return "Botella"; } - - public float Diametro { - get => _diametro; - set - { - _diametro = value; - Simulacion_Botella?.SetDiameter(Diametro); - OnPropertyChanged(nameof(Diametro)); - } + private string nombre = NombreClase(); + public override string Nombre + { + get => nombre; + set => SetProperty(ref nombre, value); } - public float Mass { - get => _mass; - set - { - _mass = value; - Simulacion_Botella?.SetMass(value); - OnPropertyChanged(nameof(Mass)); - } + [ObservableProperty] + private float diametro; + + partial void OnDiametroChanged(float value) + { + SimGeometria?.SetDiameter(Diametro); } - public override float Left + [ObservableProperty] + private float mass; + partial void OnMassChanged(float value) { - get => _centro.X-Diametro/2; - set - { - _centro.X = value+Diametro/2; - CanvasSetLeftinMeter(value); - OnPropertyChanged(nameof(CenterX)); - OnPropertyChanged(nameof(Left)); - } - } - public override float Top - { - get => _centro.Y - Diametro / 2; - set - { - _centro.Y = value + Diametro / 2; - CanvasSetTopinMeter(value); - OnPropertyChanged(nameof(CenterY)); - OnPropertyChanged(nameof(Top)); - } + SimGeometria?.SetMass(value); } - public float CenterX + public Vector2 GetCentro() { - get => _centro.X; - set - { - _centro.X = value; - CanvasSetLeftinMeter(Left); - OnPropertyChanged(nameof(CenterX)); - OnPropertyChanged(nameof(Left)); - } + return new Vector2 (Left+Diametro/2,Top+Diametro/2); } - public float CenterY - { - get => _centro.Y; - set - { - _centro.Y = value; - CanvasSetTopinMeter(Top); - OnPropertyChanged(nameof(CenterY)); - OnPropertyChanged(nameof(Top)); - } + + public void SetCentro(float x, float y) + { Left = x; Top = y; } + + public void SetCentro(Vector2 centro) + { + Left = centro.X - Diametro / 2; + Top = centro.Y - Diametro / 2; } private void ActualizarGeometrias() { - if (Simulacion_Botella != null) + if (SimGeometria != null) { - Simulacion_Botella.SetDiameter(Diametro); - Simulacion_Botella.SetPosition(CenterX, CenterY); - } - } - - public override string Nombre - { - get => _nombre; - set - { - if (_nombre != value) - { - _nombre = value; - OnPropertyChanged(nameof(Nombre)); - } + SimGeometria.SetDiameter(Diametro); + SimGeometria.SetPosition(GetCentro()); } } @@ -139,6 +79,11 @@ namespace CtrEditor.ObjetosSim // Se llama antes de la simulacion ActualizarGeometrias(); } + public override void SimulationStop() + { + // Se llama al detener la simulacion. Util para detener Storyboards + } + public override void UpdateGeometryStep() { // Se llama antes de la simulacion @@ -149,10 +94,9 @@ namespace CtrEditor.ObjetosSim public override void UpdateControl(int elapsedMilliseconds) { - CenterX = Simulacion_Botella.CenterX; - CenterY = Simulacion_Botella.CenterY; + SetCentro(SimGeometria.Center); - if (Simulacion_Botella.Descartar) // Ha sido marcada para remover + if (SimGeometria.Descartar) // Ha sido marcada para remover RemoverDesdeSimulacion = true; } @@ -161,13 +105,13 @@ namespace CtrEditor.ObjetosSim // El UserControl ya se ha cargado y podemos obtener las coordenadas para // crear el objeto de simulacion ActualizarLeftTop(); - Simulacion_Botella = simulationManager.AddCircle(Diametro, _centro, Mass); + SimGeometria = simulationManager.AddCircle(Diametro, GetCentro(), Mass); } public override void ucUnLoaded() { // El UserControl se esta eliminando // eliminar el objeto de simulacion - simulationManager.Remove(Simulacion_Botella); + simulationManager.Remove(SimGeometria); } } diff --git a/ObjetosSim/UserControls/ucBoton.xaml b/ObjetosSim/UserControls/ucBoton.xaml index 7c15b83..b83f3d1 100644 --- a/ObjetosSim/UserControls/ucBoton.xaml +++ b/ObjetosSim/UserControls/ucBoton.xaml @@ -6,12 +6,17 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:convert="clr-namespace:CtrEditor.Convertidores" + xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" mc:Ignorable="d"> + + + + - /// Interaction logic for ucBoton.xaml /// - public class osBoton : osBase, IosBase + public partial class osBoton : osBase, IosBase { // Otros datos y métodos relevantes para la simulación - private string _nombre = "Boton"; - private float _tamano; - private float _left; - private float _top; - private bool _estado; - private string _tag; - - private Brush _color; - private Brush _colorButton; - public static string NombreClase() { return "Boton"; } - - public Brush Color - { - get => _color; - set - { - _color = value; - OnPropertyChanged(nameof(Color)); - } - } - - [Hidden] - public Brush ColorButton - { - get => _colorButton; - set - { - _colorButton = value; - OnPropertyChanged(nameof(ColorButton)); - } - } - - 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 Tamano - { - get => _tamano; - set - { - _tamano = value; - OnPropertyChanged(nameof(Tamano)); - } - } - public bool Estado - { - get => _estado; - set - { - _estado = value; - if (value) - ColorButton = Brushes.LightGreen; - else - ColorButton = Color; - OnPropertyChanged(nameof(Estado)); - } - } - + private string nombre = NombreClase(); public override string Nombre { - get => _nombre; - set - { - if (_nombre != value) - { - _nombre = value; - OnPropertyChanged(nameof(Nombre)); - } - } + get => nombre; + set => SetProperty(ref nombre, value); } - public string Tag + + [ObservableProperty] + private Brush color; + [ObservableProperty] + private Brush colorButton_oculto; + [ObservableProperty] + public float tamano; + [ObservableProperty] + public bool estado; + + partial void OnEstadoChanged(bool value) { - get => _tag; - set - { - if (_tag != value) - { - _tag = value; - OnPropertyChanged(nameof(Tag)); - } - } + if (value) + ColorButton_oculto = Brushes.LightGreen; + else + ColorButton_oculto = Color; } + [ObservableProperty] + public string tag; + public void ButtonDownCommand() { Estado = true; @@ -140,13 +68,10 @@ namespace CtrEditor.ObjetosSim { // Se llama antes de la simulacion - } - public override void UpdateGeometryStep() - { } public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { - plc.EscribirTagBool(_tag, Estado); + plc.EscribirTagBool(Tag, Estado); } public override void UpdateControl(int elapsedMilliseconds) diff --git a/ObjetosSim/UserControls/ucDescarte.xaml b/ObjetosSim/UserControls/ucDescarte.xaml index 26cb01f..595978f 100644 --- a/ObjetosSim/UserControls/ucDescarte.xaml +++ b/ObjetosSim/UserControls/ucDescarte.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CtrEditor.ObjetosSim" mc:Ignorable="d" + xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:convert="clr-namespace:CtrEditor.Convertidores"> @@ -20,6 +21,10 @@ + + + + /// Interaction logic for ucDescarte.xaml /// - public class osDescarte : osBase, IosBase + public partial class osDescarte : osBase, IosBase { // Otros datos y métodos relevantes para la simulación + private simDescarte SimGeometria; - private string _nombre = "Descarte"; - 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; - set - { - _centro.X = value + Diametro / 2; - ActualizarGeometrias(); - CanvasSetLeftinMeter(value); - OnPropertyChanged(nameof(CenterX)); - OnPropertyChanged(nameof(Left)); - } - } - public override float Top - { - get => _centro.Y - Diametro / 2; - set - { - _centro.Y = value + Diametro / 2; - ActualizarGeometrias(); - CanvasSetTopinMeter(value); - OnPropertyChanged(nameof(CenterY)); - OnPropertyChanged(nameof(Top)); - } - } - - public float CenterX - { - get => _centro.X; - set - { - _centro.X = value; - CanvasSetLeftinMeter(Left); - OnPropertyChanged(nameof(CenterX)); - OnPropertyChanged(nameof(Left)); - } - } - public float CenterY - { - get => _centro.Y; - set - { - _centro.Y = value; - CanvasSetTopinMeter(Top); - OnPropertyChanged(nameof(CenterY)); - OnPropertyChanged(nameof(Top)); - } - } - - public float Diametro - { - get => _diametro; - set - { - _diametro = value; - AreaDeDescarte?.SetDiameter(Diametro); - OnPropertyChanged(nameof(Diametro)); - } - } - + private string nombre = NombreClase(); public override string Nombre { - get => _nombre; - set - { - if (_nombre != value) - { - _nombre = value; - OnPropertyChanged(nameof(Nombre)); - } - } + get => nombre; + set => SetProperty(ref nombre, value); } + [ObservableProperty] + private float diametro; + + partial void OnDiametroChanged(float value) + { + SimGeometria?.SetDiameter(Diametro); + } + + public Vector2 GetCentro() + { + return new Vector2(Left + Diametro / 2, Top + Diametro / 2); + } + + public void SetCentro(float x, float y) + { Left = x; Top = y; } + + public void SetCentro(Vector2 centro) + { + Left = centro.X - Diametro / 2; + Top = centro.Y - Diametro / 2; + } + + public override void LeftChanged(float value) + { + ActualizarGeometrias(); + } + + public override void TopChanged(float value) + { + ActualizarGeometrias(); + } + + private void ActualizarGeometrias() { - if (AreaDeDescarte != null) + if (SimGeometria != null) { - AreaDeDescarte.SetDiameter(Diametro); - AreaDeDescarte.SetPosition(CenterX, CenterY); + SimGeometria.SetDiameter(Diametro); + SimGeometria.SetPosition(GetCentro()); } } @@ -129,13 +95,13 @@ namespace CtrEditor.ObjetosSim // El UserControl ya se ha cargado y podemos obtener las coordenadas para // crear el objeto de simulacion ActualizarLeftTop(); - AreaDeDescarte = simulationManager.AddDescarte(Diametro, _centro); + SimGeometria = simulationManager.AddDescarte(Diametro, GetCentro()); } public override void ucUnLoaded() { // El UserControl se esta eliminando // eliminar el objeto de simulacion - simulationManager.Remove(AreaDeDescarte); + simulationManager.Remove(SimGeometria); } } diff --git a/ObjetosSim/UserControls/ucFiller.xaml b/ObjetosSim/UserControls/ucFiller.xaml index f39e039..c5a66aa 100644 --- a/ObjetosSim/UserControls/ucFiller.xaml +++ b/ObjetosSim/UserControls/ucFiller.xaml @@ -5,12 +5,17 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CtrEditor.ObjetosSim" mc:Ignorable="d" - xmlns:convert="clr-namespace:CtrEditor.Convertidores"> + xmlns:convert="clr-namespace:CtrEditor.Convertidores" + xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"> - + + + + + /// Interaction logic for ucFiller.xaml /// - public class osFiller : osBase, IosBase + public partial class osFiller : osBase, IosBase { // Otros datos y métodos relevantes para la simulación - private string _nombre = "Filler"; - private float _ancho; - private float _alto; - private float _left; - private float _top; - private float _angulo; - private float _botellas_hora; - private float _velocidad_actual; - private float _diametro_botella; - private string _tag_consenso; - private bool _consenso; private float TiempoRestante; - private float _leftSalida; - private float _topSalida; private osBotella UltimaBotella; public static string NombreClase() { return "Filler"; } - public float OffsetLeftSalida - { - get => _leftSalida; - set - { - _leftSalida = value; - OnPropertyChanged(nameof(OffsetLeftSalida)); - } - } - public float OffsetTopSalida - { - get => _topSalida; - set - { - _topSalida = value; - OnPropertyChanged(nameof(OffsetTopSalida)); - } - } - - public bool Consenso - { - get => _consenso; - set - { - _consenso = value; - OnPropertyChanged(nameof(Consenso)); - } - } - - public float Botellas_hora - { - get => _botellas_hora; - set - { - _botellas_hora = value; - OnPropertyChanged(nameof(Botellas_hora)); - } - } - public float Velocidad_actual_percentual - { - get => _velocidad_actual; - set - { - _velocidad_actual = value; - OnPropertyChanged(nameof(Velocidad_actual_percentual)); - } - } - public float Diametro_botella - { - get => _diametro_botella; - set - { - _diametro_botella = value; - OnPropertyChanged(nameof(Diametro_botella)); - } - } - public string Tag_consenso - { - get => _tag_consenso; - set - { - _tag_consenso = value; - OnPropertyChanged(nameof(Tag_consenso)); - } - } - - 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)); - } - } - + private string nombre = NombreClase(); public override string Nombre { - get => _nombre; - set - { - if (_nombre != value) - { - _nombre = value; - OnPropertyChanged(nameof(Nombre)); - } - } + get => nombre; + set => SetProperty(ref nombre, value); } + [ObservableProperty] + public float offsetLeftSalida; + [ObservableProperty] + public float offsetTopSalida; + [ObservableProperty] + public bool consenso; + [ObservableProperty] + public float botellas_hora; + [ObservableProperty] + public float velocidad_actual_percentual; + [ObservableProperty] + public float diametro_botella; + [ObservableProperty] + public string tag_consenso; + [ObservableProperty] + public float ancho; + [ObservableProperty] + public float alto; + [ObservableProperty] + public float angulo; + public osFiller() { Ancho = 0.30f; @@ -185,14 +58,6 @@ namespace CtrEditor.ObjetosSim Botellas_hora = 10000; } - public override void UpdateGeometryStart() - { - // Se llama antes de la simulacion - - } - public override void UpdateGeometryStep() - { - } public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { Consenso = LeerBitTag(plc, Tag_consenso); @@ -249,11 +114,6 @@ namespace CtrEditor.ObjetosSim // crear el objeto de simulacion ActualizarLeftTop(); } - public override void ucUnLoaded() - { - // El UserControl se esta eliminando - // eliminar el objeto de simulacion - } } diff --git a/ObjetosSim/UserControls/ucGuia.xaml.cs b/ObjetosSim/UserControls/ucGuia.xaml.cs index 57ef364..021c9a4 100644 --- a/ObjetosSim/UserControls/ucGuia.xaml.cs +++ b/ObjetosSim/UserControls/ucGuia.xaml.cs @@ -1,24 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +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; using CommunityToolkit.Mvvm.ComponentModel; using CtrEditor.Convertidores; using CtrEditor.Siemens; using CtrEditor.Simulacion; -using FarseerPhysics.Dynamics; -using Microsoft.Xna.Framework; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace CtrEditor.ObjetosSim { @@ -39,26 +24,6 @@ namespace CtrEditor.ObjetosSim get => nombre; set => SetProperty(ref nombre, value); } - private float left; - public override float Left - { - get => left; - set - { - CanvasSetLeftinMeter(value); - SetProperty(ref left, value); - } - } - private float top; - public override float Top - { - get => top; - set - { - CanvasSetTopinMeter(value); - SetProperty(ref top, value); - } - } [ObservableProperty] public float ancho; diff --git a/ObjetosSim/UserControls/ucPhotocell.xaml b/ObjetosSim/UserControls/ucPhotocell.xaml index c6892f9..afbd8d8 100644 --- a/ObjetosSim/UserControls/ucPhotocell.xaml +++ b/ObjetosSim/UserControls/ucPhotocell.xaml @@ -5,12 +5,17 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls" mc:Ignorable="d" + xmlns:vm="clr-namespace:CtrEditor.ObjetosSim.UserControls" xmlns:convert="clr-namespace:CtrEditor.Convertidores"> + + + + @@ -26,8 +31,10 @@ -