diff --git a/CtrEditor.csproj b/CtrEditor.csproj index 6e88f75..b9c0c5b 100644 --- a/CtrEditor.csproj +++ b/CtrEditor.csproj @@ -10,7 +10,11 @@ - True + False + + + + False @@ -40,6 +44,7 @@ + @@ -92,6 +97,7 @@ + diff --git a/MainViewModel.cs b/MainViewModel.cs index 0db044f..c6fd2a0 100644 --- a/MainViewModel.cs +++ b/MainViewModel.cs @@ -15,6 +15,7 @@ using System.Diagnostics; using System.Reflection; using CommunityToolkit.Mvvm.ComponentModel; using Xceed.Wpf.Toolkit.PropertyGrid; +using System.Text.RegularExpressions; namespace CtrEditor @@ -282,7 +283,28 @@ namespace CtrEditor var NuevoObjetoDuplicado = JsonConvert.DeserializeObject(serializedData, settings); if (NuevoObjetoDuplicado != null) { - NuevoObjetoDuplicado.Nombre += "_Duplicado"; + string nombre = NuevoObjetoDuplicado.Nombre; + + // Expresión regular para identificar un nombre que termina con _número + Regex regex = new Regex(@"_(\d+)$"); + + if (regex.IsMatch(nombre)) + { + // Extraer el número actual y sumarle 1 + var match = regex.Match(nombre); + int numeroActual = int.Parse(match.Groups[1].Value); + int nuevoNumero = numeroActual + 1; + + // Reemplazar el número en el nombre + nombre = regex.Replace(nombre, $"_{nuevoNumero}"); + } + else + { + // Si no termina con _número, añadir _1 + nombre += "_1"; + } + + NuevoObjetoDuplicado.Nombre = nombre; NuevoObjetoDuplicado.Left += 0.5f; NuevoObjetoDuplicado.Top += 0.5f; ObjetosSimulables.Add(NuevoObjetoDuplicado); diff --git a/MainWindow.xaml b/MainWindow.xaml index 0501d22..a7780c7 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -168,11 +168,24 @@ + + + + + + + + + + + + + - + @@ -184,7 +197,7 @@ - + diff --git a/ObjetosSim/Decorativos/ucTextPlate.xaml b/ObjetosSim/Decorativos/ucTextPlate.xaml new file mode 100644 index 0000000..489d4bc --- /dev/null +++ b/ObjetosSim/Decorativos/ucTextPlate.xaml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ObjetosSim/Decorativos/ucTextPlate.xaml.cs b/ObjetosSim/Decorativos/ucTextPlate.xaml.cs new file mode 100644 index 0000000..2974eb9 --- /dev/null +++ b/ObjetosSim/Decorativos/ucTextPlate.xaml.cs @@ -0,0 +1,153 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media.Animation; +using System.Windows.Media; +using CommunityToolkit.Mvvm.ComponentModel; + +using CtrEditor.Siemens; +using CtrEditor.Simulacion; +using System.Windows.Input; + + +namespace CtrEditor.ObjetosSim +{ + /// + /// Interaction logic for ucTextPlate.xaml + /// + /// + + public partial class osTextPlate : osBase, IosBase + { + + public static string NombreClase() + { + return "Plate"; + } + private string nombre = NombreClase(); + public override string Nombre + { + get => nombre; + set => SetProperty(ref nombre, value); + } + + [ObservableProperty] + Color color; + [ObservableProperty] + Color color_Titulo; + + [ObservableProperty] + string titulo; + [ObservableProperty] + public float alto_Titulo; + + + [ObservableProperty] + public float ancho; + [ObservableProperty] + public float alto; + [ObservableProperty] + public float angulo; + + public override void TopChanging(float oldValue, float newValue) { + UpdateChildsTop(newValue - oldValue); + } + public override void LeftChanging(float oldValue, float newValue) { + UpdateChildsLeft(newValue - oldValue); + } + + protected void UpdateChildsTop(float offsetY) + { + if (!string.IsNullOrEmpty(Nombre) && _mainViewModel != null) + { + foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables) + { + if (objetoSimulable != this && objetoSimulable.Group_Panel == Nombre) + { + objetoSimulable.Top += offsetY; + } + } + } + } + protected void UpdateChildsLeft(float offsetX) + { + if (!string.IsNullOrEmpty(Nombre) && _mainViewModel != null) + { + foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables) + { + if (objetoSimulable != this && objetoSimulable.Group_Panel == Nombre) + { + objetoSimulable.Left += offsetX; + } + } + } + } + + + public osTextPlate() + { + Ancho = 0.5f; + Alto = 0.5f; + Alto_Titulo = 0.2f; + Color = Colors.Gray; + Titulo = "Titulo"; + } + + public override void ucUnLoaded() + { + // El UserControl se esta eliminando + // eliminar el objeto de simulacion + } + + } + + public partial class ucTextPlate : UserControl, IDataContainer + { + public osBase? Datos { get; set; } + + public ucTextPlate() + { + 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 osTextPlate 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) + { + if (Datos != null) + if (Datos is osTextPlate datos) + datos.Angulo = Angle; + } + public void Highlight(bool State) { } + public int ZIndex() + { + return 1; + } + + } +} + + + diff --git a/ObjetosSim/Emuladores/ucBottGenerator.xaml b/ObjetosSim/Emuladores/ucBottGenerator.xaml new file mode 100644 index 0000000..24fc082 --- /dev/null +++ b/ObjetosSim/Emuladores/ucBottGenerator.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs b/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs new file mode 100644 index 0000000..f2cf9d0 --- /dev/null +++ b/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs @@ -0,0 +1,208 @@ +using CtrEditor.Siemens; +using System.Windows; +using System.Windows.Controls; +using CommunityToolkit.Mvvm.ComponentModel; +using System.Diagnostics; + +namespace CtrEditor.ObjetosSim +{ + /// + /// Interaction logic for ucBottGenerator.xaml + /// + public partial class osBottGenerator : osBase, IosBase + { + TimerTON_TOFF _TON_TOFF = new TimerTON_TOFF(); + // Otros datos y métodos relevantes para la simulación + + private float TiempoRestante; + private osBotella UltimaBotella; + + public static string NombreClase() + { + return "BottGenerator"; + } + private string nombre = NombreClase(); + public override string Nombre + { + get => nombre; + set => SetProperty(ref nombre, value); + } + + [ObservableProperty] + private float offsetLeftSalida; + [ObservableProperty] + private float offsetTopSalida; + + [ObservableProperty] + private string tag_consenso; + [ObservableProperty] + private bool consenso; + + partial void OnConsensoChanged(bool value) + { + _TON_TOFF.Senal = value; + } + [ObservableProperty] + private bool consenso_NC; + [ObservableProperty] + private bool consenso_Filtrado; + [ObservableProperty] + float filtro_consenso_s; + + [ObservableProperty] + private float botellas_hora; + + partial void OnBotellas_horaChanged(float value) + { + Botellas_segundo = value / 3600; + } + + [ObservableProperty] + private float botellas_segundo; + + partial void OnBotellas_segundoChanged(float value) + { + Botellas_hora = value * 3600; + } + + [ObservableProperty] + private float velocidad_actual_percentual; + [ObservableProperty] + private float diametro_botella; + [ObservableProperty] + private float ancho; + [ObservableProperty] + private float alto; + [ObservableProperty] + private float angulo; + + public osBottGenerator() + { + Ancho = 0.30f; + Alto = 0.30f; + Angulo = 0; + Velocidad_actual_percentual = 0; + Diametro_botella = 0.1f; + Botellas_hora = 10000; + Filtro_consenso_s = 1; + } + + public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) + { + if (Consenso_NC) + Consenso = !LeerBitTag(Tag_consenso); + else + Consenso = LeerBitTag(Tag_consenso); + } + + public override void UpdateControl(int elapsedMilliseconds) + { + bool habilitado; + + _TON_TOFF.Tiempo_ON_s = _TON_TOFF.Tiempo_OFF_s = Filtro_consenso_s; + + if (Consenso_Filtrado) + habilitado = _TON_TOFF.SenalFiltrada(); + else + habilitado = Consenso; + + if (habilitado && Velocidad_actual_percentual > 0) + { + TiempoRestante -= elapsedMilliseconds / 1000.0f; + if (TiempoRestante <= 0) + { + TiempoRestante += 3600 / (Botellas_hora * (Velocidad_actual_percentual / 100.0f)); + + var X = Left + OffsetLeftSalida; + var Y = Top + OffsetTopSalida; + + if (UltimaBotella != null && UltimaBotella.RemoverDesdeSimulacion) + UltimaBotella = null; + + if (UltimaBotella == null) + { + // No hay botellas, se puede crear una nueva directamente + var nuevaBotella = _mainViewModel.CrearObjetoSimulable(typeof(osBotella), X, Y); + ((osBotella)nuevaBotella).Diametro = Diametro_botella; + nuevaBotella.AutoCreated = true; + UltimaBotella = (osBotella)nuevaBotella; + } + else + { + // Calcular la distancia entre el centro de la última botella y la nueva posición + float distancia = (float)Math.Sqrt(Math.Pow(UltimaBotella.Left - X, 2) + Math.Pow(UltimaBotella.Top - Y, 2)); + float distanciaMinima = Diametro_botella / 2; // Asumiendo que el diámetro de la nueva botella es similar + + if (distancia > distanciaMinima) + { + var nuevaBotella = _mainViewModel.CrearObjetoSimulable(typeof(osBotella), X, Y); + ((osBotella)nuevaBotella).Diametro = Diametro_botella; + nuevaBotella.AutoCreated = true; + UltimaBotella = (osBotella)nuevaBotella; + } + } + } + } + else + { + TiempoRestante = 0; + } + } + + 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 ucBottGenerator : UserControl, IDataContainer + { + public osBase? Datos { get; set; } + + public ucBottGenerator() + { + 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 osBottGenerator 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 osBottGenerator datos) + datos.Angulo = Angle; + } + public void Highlight(bool State) { } + public int ZIndex() + { + return 10; + } + } + +} diff --git a/ObjetosSim/Estaticos/ucTransporteGuias.xaml b/ObjetosSim/Estaticos/ucTransporteGuias.xaml index e39b5d1..2e4b7ea 100644 --- a/ObjetosSim/Estaticos/ucTransporteGuias.xaml +++ b/ObjetosSim/Estaticos/ucTransporteGuias.xaml @@ -28,18 +28,37 @@ - - - + + + + + - - - - + + + + + + + + + + + + diff --git a/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs b/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs index 268d817..0649551 100644 --- a/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs @@ -1,5 +1,6 @@ using System.Windows; using System.Windows.Controls; +using System.Windows.Media; using CommunityToolkit.Mvvm.ComponentModel; using CtrEditor.Siemens; using CtrEditor.Simulacion; @@ -60,6 +61,9 @@ namespace CtrEditor.ObjetosSim } + [ObservableProperty] + Color color = Colors.Blue; + [ObservableProperty] public string motor; @@ -110,10 +114,9 @@ namespace CtrEditor.ObjetosSim UpdateOrCreateLine(Guia_Superior, uc.GuiaSuperior); UpdateOrCreateLine(Guia_Inferior, uc.GuiaInferior) ; - SimGeometria.DistanceGuide2Guide = Alto; - SimGeometria.Speed = VelocidadActual; + SimGeometria.DistanceGuide2Guide = Alto; SimGeometria.isBrake = esFreno; - ActualizarAnimacionStoryBoardTransporte(VelocidadActual); + SetSpeed(); } } @@ -123,7 +126,7 @@ namespace CtrEditor.ObjetosSim Ancho = 1; Alto = 0.10f; AltoGuia = 0.03f; - Distance = 0.01f; + Distance = 0.01f; } public override void UpdateGeometryStart() diff --git a/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml b/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml index 6cdeae4..d38e034 100644 --- a/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml +++ b/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml @@ -39,7 +39,7 @@ - + @@ -67,14 +67,13 @@ AnchoCentro="{Binding AnchoCentral, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}" Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}" AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}" - Canvas.Top="{Binding Distance, Converter={StaticResource MeterToPixelConverter},ConverterParameter=-1}" - Color="Blue"/> + Canvas.Top="{Binding Distance, Converter={StaticResource MeterToPixelConverter},ConverterParameter=-1}" Color="{Binding Color}"/> + Color="{Binding Color}"> diff --git a/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml.cs b/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml.cs index e7f2b19..a1b317e 100644 --- a/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteGuiasUnion.xaml.cs @@ -36,7 +36,7 @@ namespace CtrEditor.ObjetosSim } [ObservableProperty] - string color; + Color color; [ObservableProperty] public string motorA; diff --git a/ObjetosSim/Estaticos/ucVMmotorSim.xaml b/ObjetosSim/Estaticos/ucVMmotorSim.xaml index 1da6a69..b591197 100644 --- a/ObjetosSim/Estaticos/ucVMmotorSim.xaml +++ b/ObjetosSim/Estaticos/ucVMmotorSim.xaml @@ -9,25 +9,35 @@ - + - - - - - + + + + + + + + + + + - + diff --git a/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs b/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs index 707d9f2..5830ef9 100644 --- a/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs +++ b/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs @@ -35,6 +35,9 @@ namespace CtrEditor.ObjetosSim [ObservableProperty] public ImageSource imageSource_oculta; + [ObservableProperty] + public float angulo; + [ObservableProperty] public float tamano; [ObservableProperty] @@ -105,6 +108,7 @@ namespace CtrEditor.ObjetosSim // El UserControl ya se ha cargado y podemos obtener las coordenadas para // crear el objeto de simulacion ActualizarLeftTop(); + OnVelocidadChanged(Velocidad); } } @@ -136,7 +140,11 @@ namespace CtrEditor.ObjetosSim Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels); } } - public void Rotate(float Angle) { } + public void Rotate(float Angle) { + if (Datos != null) + if (Datos is osVMmotorSim datos) + datos.Angulo = Angle; + } public void Highlight(bool State) { } public int ZIndex() { diff --git a/ObjetosSim/SensoresComandos/ucBoton.xaml b/ObjetosSim/SensoresComandos/ucBoton.xaml index 58b4837..36a88e7 100644 --- a/ObjetosSim/SensoresComandos/ucBoton.xaml +++ b/ObjetosSim/SensoresComandos/ucBoton.xaml @@ -12,7 +12,15 @@ - + + + + + + + + + - + + + + diff --git a/ObjetosSim/SensoresComandos/ucBoton.xaml.cs b/ObjetosSim/SensoresComandos/ucBoton.xaml.cs index 49795a1..6232a26 100644 --- a/ObjetosSim/SensoresComandos/ucBoton.xaml.cs +++ b/ObjetosSim/SensoresComandos/ucBoton.xaml.cs @@ -26,9 +26,15 @@ namespace CtrEditor.ObjetosSim set => SetProperty(ref nombre, value); } + [ObservableProperty] + string button_Name; + [ObservableProperty] public bool tipo_NC; + [ObservableProperty] + Color color_Titulo; + [ObservableProperty] Color color; @@ -41,6 +47,10 @@ namespace CtrEditor.ObjetosSim private Color colorButton_oculto; [ObservableProperty] public float tamano; + + [ObservableProperty] + public float angulo; + [ObservableProperty] public bool estado; @@ -75,6 +85,8 @@ namespace CtrEditor.ObjetosSim Tag = "M50.0"; // Set initial color Color = Colors.LightBlue; + color_Titulo = Colors.Black; + button_Name = "TAG"; } public override void UpdateGeometryStart() @@ -163,7 +175,10 @@ namespace CtrEditor.ObjetosSim Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels); } } - public void Rotate(float Angle) { } + public void Rotate(float Angle) { + if (Datos is osBoton osBotonData) + osBotonData.Angulo = Angle; + } public void Highlight(bool State) { } public int ZIndex() { diff --git a/ObjetosSim/SensoresComandos/ucPhotocell.xaml b/ObjetosSim/SensoresComandos/ucPhotocell.xaml index 749f434..315f67e 100644 --- a/ObjetosSim/SensoresComandos/ucPhotocell.xaml +++ b/ObjetosSim/SensoresComandos/ucPhotocell.xaml @@ -16,27 +16,29 @@ - + - + - + - + + + Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=0.1}" + Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=2}" + VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,0,0,0" Grid.Column="1"/> - + @@ -46,8 +48,8 @@ - + \ No newline at end of file diff --git a/ObjetosSim/UserControlFactory.cs b/ObjetosSim/UserControlFactory.cs index 28a5158..867d156 100644 --- a/ObjetosSim/UserControlFactory.cs +++ b/ObjetosSim/UserControlFactory.cs @@ -92,8 +92,8 @@ namespace CtrEditor.ObjetosSim // Add properties dynamically based on attributes var properties = TypeDescriptor.GetProperties(selectedObject) .Cast() - .Where(prop => !prop.Attributes.OfType().Any()); - + .Where(prop => !prop.Attributes.OfType().Any()).OrderBy(prop => prop.Name); + foreach (var property in properties) { var displayNameAttr = property.Attributes.OfType().FirstOrDefault(); @@ -112,8 +112,11 @@ namespace CtrEditor.ObjetosSim { propertyDefinition.DisplayName = property.Name.Replace("_", " "); } - - propertyGrid.PropertyDefinitions.Add(propertyDefinition); + if (property.PropertyType == typeof(double) || property.PropertyType == typeof(float) || property.PropertyType == typeof(string) || property.PropertyType == typeof(int) || + property.PropertyType == typeof(bool) || property.PropertyType == typeof(Color)) + { + propertyGrid.PropertyDefinitions.Add(propertyDefinition); + } } } diff --git a/ObjetosSim/UserControls/ThreeLinesControl.xaml.cs b/ObjetosSim/UserControls/ThreeLinesControl.xaml.cs index 21be1f1..03c10a7 100644 --- a/ObjetosSim/UserControls/ThreeLinesControl.xaml.cs +++ b/ObjetosSim/UserControls/ThreeLinesControl.xaml.cs @@ -23,7 +23,7 @@ namespace CtrEditor.ObjetosSim.UserControls { InitializeComponent(); this.Loaded += ThreeLinesControl_Loaded; - Color = Brushes.Gray; + //Color = Colors.Gray; } private void ThreeLinesControl_Loaded(object sender, RoutedEventArgs e) @@ -31,8 +31,14 @@ namespace CtrEditor.ObjetosSim.UserControls CreateOrUpdateRectangles(); } - [ObservableProperty] - private Brush color; + public Color Color + { + get { return (Color)GetValue(ColorProperty); } + set { SetValue(ColorProperty, value); } + } + + public static readonly DependencyProperty ColorProperty = + DependencyProperty.Register("Color", typeof(Color), typeof(ThreeLinesControl), new PropertyMetadata(Colors.Red, OnDimensionsChanged)); public double AnchoRecto { @@ -85,7 +91,7 @@ namespace CtrEditor.ObjetosSim.UserControls { Width = AnchoRecto, Height = AltoGuia, - Fill = Color + Fill = new SolidColorBrush(Color) }; Canvas.SetLeft(_liz, 0); Canvas.SetTop(_liz, -AltoGuia / 2); @@ -96,7 +102,7 @@ namespace CtrEditor.ObjetosSim.UserControls { Width = CalculateLcWidth(), Height = AltoGuia, - Fill = Color, + Fill = new SolidColorBrush(Color), RenderTransformOrigin = new Point(0, 0.5) }; _lc.RenderTransform = new RotateTransform(GetRotationAngle(AnchoCentro, Altura)); @@ -109,7 +115,7 @@ namespace CtrEditor.ObjetosSim.UserControls { Width = AnchoRecto, Height = AltoGuia, - Fill = Color + Fill = new SolidColorBrush(Color) }; Canvas.SetLeft(_lde, AnchoRecto + AnchoCentro); Canvas.SetTop(_lde, Altura - AltoGuia / 2); @@ -120,12 +126,14 @@ namespace CtrEditor.ObjetosSim.UserControls // Actualizar Liz _liz.Width = AnchoRecto; _liz.Height = AltoGuia; + _liz.Fill = new SolidColorBrush(Color); Canvas.SetLeft(_liz, 0); Canvas.SetTop(_liz, -AltoGuia / 2); // Actualizar Lc _lc.Width = CalculateLcWidth(); _lc.Height = AltoGuia; + _lc.Fill = new SolidColorBrush(Color); _lc.RenderTransform = new RotateTransform(GetRotationAngle(AnchoCentro, Altura)); Canvas.SetLeft(_lc, AnchoRecto); Canvas.SetTop(_lc, -AltoGuia / 2); @@ -133,6 +141,7 @@ namespace CtrEditor.ObjetosSim.UserControls // Actualizar Lde _lde.Width = AnchoRecto; _lde.Height = AltoGuia; + _lde.Fill = new SolidColorBrush(Color); Canvas.SetLeft(_lde, AnchoRecto + AnchoCentro); Canvas.SetTop(_lde, Altura - AltoGuia / 2); } diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs index 4f76524..6dab284 100644 --- a/ObjetosSim/osBase.cs +++ b/ObjetosSim/osBase.cs @@ -68,18 +68,33 @@ namespace CtrEditor.ObjetosSim CanvasSetLeftinMeter(value); LeftChanged(value); } + + partial void OnLeftChanging(float oldValue, float newValue) + { + LeftChanging(oldValue, newValue); + } + public virtual void LeftChanged(float value) { } + public virtual void LeftChanging(float oldValue, float newValue) { } [ObservableProperty] private float top; + [ObservableProperty] + private string group_Panel; + partial void OnTopChanged(float value) { CanvasSetTopinMeter(value); TopChanged(value); } + partial void OnTopChanging(float oldValue, float newValue) + { + TopChanging(oldValue, newValue); + } public virtual void TopChanged(float value) { } + public virtual void TopChanging(float oldValue, float newValue) { } /// /// Usado para saber cuando un objeto fue creado manualmente o por algun generador @@ -176,7 +191,6 @@ namespace CtrEditor.ObjetosSim [JsonIgnore] public SimulationManagerFP simulationManager; - /// /// Prepara la clase para ser serializable poniendo a null los objetos que tienen referencias circulares /// Luego se debe llamar a RestaurarDatosNoSerializables para restaurar el estado original diff --git a/ObjetosSim/ucBasicExample.xaml b/ObjetosSim/ucBasicExample.xaml index 2779c15..7b050ee 100644 --- a/ObjetosSim/ucBasicExample.xaml +++ b/ObjetosSim/ucBasicExample.xaml @@ -1,37 +1,41 @@  + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:i="http://schemas.microsoft.com/xaml/behaviors" + xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" + mc:Ignorable="d"> - + + + + + + + + + + + + + + - + - - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/ObjetosSim/ucBasicExample.xaml.cs b/ObjetosSim/ucBasicExample.xaml.cs index efd7ab8..48b2ac1 100644 --- a/ObjetosSim/ucBasicExample.xaml.cs +++ b/ObjetosSim/ucBasicExample.xaml.cs @@ -1,11 +1,14 @@ - -using CtrEditor.Siemens; -using System.Windows; +using System.Windows; using System.Windows.Controls; +using System.Windows.Media.Animation; using System.Windows.Media; -using Newtonsoft.Json; using CommunityToolkit.Mvvm.ComponentModel; +using CtrEditor.Siemens; +using CtrEditor.Simulacion; +using System.Windows.Input; + + namespace CtrEditor.ObjetosSim { /// @@ -15,80 +18,112 @@ namespace CtrEditor.ObjetosSim public partial class osBasicExample : osBase, IosBase { + private osBase _osMotor = null; - // Otros datos y métodos relevantes para la simulación + private simTransporte SimGeometria; public static string NombreClase() { - return "Ejemplo"; + return "Example"; } - private string nombre = NombreClase(); + private string nombre = "Transporte TTOP"; public override string Nombre { get => nombre; set => SetProperty(ref nombre, value); } - [JsonIgnore] [ObservableProperty] - public ImageSource imageSource_oculta; + public float velocidadActual; - [ObservableProperty] - public float tamano; - [ObservableProperty] - public float maxRatedHz; - - [ObservableProperty] - public float tiempoRampa; - - partial void OnTiempoRampaChanged(float value) + partial void OnVelocidadActualChanged(float value) { - if (value < 0.1f) - value = 0.1f; - tiempoRampa = value; + SetSpeed(); } [ObservableProperty] - public bool encendido; - [ObservableProperty] - public int pLC_NumeroMotor; - [ObservableProperty] - public float ratio; + bool invertirDireccion; - [ObservableProperty] - public float velocidad; - - partial void OnVelocidadChanged(float value) + partial void OnInvertirDireccionChanged(bool value) { - if (value > 0) - ImageSource_oculta = ImageFromPath("/imagenes/motorVerde.png"); + SetSpeed(); + if (_visualRepresentation is ucBasicExample uc) + { + CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); + ActualizarAnimacionStoryBoardTransporte(VelocidadActual); + } + } + + void SetSpeed() + { + if (InvertirDireccion) + SimGeometria?.SetSpeed(-VelocidadActual); else - ImageSource_oculta = ImageFromPath("/imagenes/motorNegro.png"); + SimGeometria?.SetSpeed(VelocidadActual); + ActualizarAnimacionStoryBoardTransporte(VelocidadActual); + } + + + [ObservableProperty] + public string motor; + + partial void OnMotorChanged(string value) + { + _osMotor = ObtenerLink(Motor, typeof(osVMmotorSim)); + } + + [ObservableProperty] + public float ancho; + [ObservableProperty] + public float alto; + [ObservableProperty] + public float angulo; + [ObservableProperty] + public float frictionCoefficient; + [ObservableProperty] + public float velMax50hz; + [ObservableProperty] + public float tiempoRampa; + [ObservableProperty] + public bool esMarcha; + + + private void ActualizarGeometrias() + { + if (_visualRepresentation is ucBasicExample uc) + { + UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo); + SetSpeed(); + } + ActualizarAnimacionStoryBoardTransporte(VelocidadActual); } public osBasicExample() { - Tamano = 0.30f; - PLC_NumeroMotor = 31; - MaxRatedHz = 100; - TiempoRampa = 3; - ImageSource_oculta = ImageFromPath("/imagenes/motor2.png"); + Ancho = 1; + Alto = 0.10f; } + public override void SimulationStop() + { + // Se llama al detener la simulacion + ActualizarAnimacionStoryBoardTransporte(VelocidadActual); + } public override void UpdateGeometryStart() { // Se llama antes de la simulacion - + ActualizarGeometrias(); } + public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { - - } - - public override void UpdateControl(int elapsedMilliseconds) - { - // Calculamos la velocidad - + if (_osMotor != null) + { + if (_osMotor is osVMmotorSim motor) + VelocidadActual = motor.Velocidad; + } + else if (Motor.Length > 0) + _osMotor = ObtenerLink(Motor, typeof(osVMmotorSim)); } public override void ucLoaded() @@ -97,7 +132,19 @@ namespace CtrEditor.ObjetosSim // crear el objeto de simulacion ActualizarLeftTop(); + if (_visualRepresentation is ucBasicExample uc) + { + SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo); + CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); + } } + public override void ucUnLoaded() + { + // El UserControl se esta eliminando + // eliminar el objeto de simulacion + simulationManager.Remove(SimGeometria); + } + } public partial class ucBasicExample : UserControl, IDataContainer @@ -118,7 +165,11 @@ namespace CtrEditor.ObjetosSim { Datos?.ucUnLoaded(); } - public void Resize(float width, float height) { } + public void Resize(float width, float height) + { + if (Datos is osBasicExample datos) + datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width); + } public void Move(float LeftPixels, float TopPixels) { if (Datos != null) @@ -127,11 +178,20 @@ namespace CtrEditor.ObjetosSim Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels); } } - public void Rotate(float Angle) { } + public void Rotate(float Angle) + { + if (Datos != null) + if (Datos is osBasicExample datos) + datos.Angulo = Angle; + } public void Highlight(bool State) { } public int ZIndex() { - return 10; + return 1; } + } } + + + diff --git a/XAMLhelpers.cs b/XAMLhelpers.cs index 5b7deb3..97575ab 100644 --- a/XAMLhelpers.cs +++ b/XAMLhelpers.cs @@ -385,14 +385,14 @@ namespace CtrEditor { if (value is double floatValue) { - return floatValue.ToString("0.00", culture); // Formatear a dos decimales + return floatValue.ToString("0.00", culture).Replace('.', ','); // Formatear a dos decimales } return value; // Devolver el valor original si no es un float } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is string stringValue && double.TryParse(stringValue, NumberStyles.Float, culture, out double result)) + if (value is string stringValue && double.TryParse(stringValue.Replace(',', '.'), NumberStyles.Float, culture, out double result)) { return result; } diff --git a/imagenes/gear.png b/imagenes/gear.png new file mode 100644 index 0000000..f31d364 Binary files /dev/null and b/imagenes/gear.png differ