From 211c518be645f5bc5260c43c5105e6bf4a2d9b46 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 26 Mar 2025 15:18:58 +0100 Subject: [PATCH] Agregada la posibilidad de invertir la imagen ucCustomImage --- FuncionesBase/BooleanToDoubleConverter.cs | 30 +++++++++++++++++++ ObjetosSim/Decorativos/ucCustomImage.xaml | 10 ++++++- ObjetosSim/Decorativos/ucCustomImage.xaml.cs | 20 +++++++++++++ ObjetosSim/Decorativos/ucFramePlate.xaml.cs | 24 +++++++++++++-- .../ucTransporteTTopDualInverter.xaml.cs | 10 ++++--- ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs | 2 +- .../ucEncoderMotorLineal.xaml.cs | 17 ++++++++++- ObjetosSim/osBase.cs | 10 +++++++ 8 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 FuncionesBase/BooleanToDoubleConverter.cs diff --git a/FuncionesBase/BooleanToDoubleConverter.cs b/FuncionesBase/BooleanToDoubleConverter.cs new file mode 100644 index 0000000..7c16b15 --- /dev/null +++ b/FuncionesBase/BooleanToDoubleConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace CtrEditor.FuncionesBase +{ + public class BooleanToDoubleConverter : IValueConverter + { + public double TrueValue { get; set; } = -1; + public double FalseValue { get; set; } = 1; + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool boolValue) + { + return boolValue ? TrueValue : FalseValue; + } + return FalseValue; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is double doubleValue) + { + return Math.Abs(doubleValue - TrueValue) < double.Epsilon; + } + return false; + } + } +} diff --git a/ObjetosSim/Decorativos/ucCustomImage.xaml b/ObjetosSim/Decorativos/ucCustomImage.xaml index 5a410fb..46fd1c0 100644 --- a/ObjetosSim/Decorativos/ucCustomImage.xaml +++ b/ObjetosSim/Decorativos/ucCustomImage.xaml @@ -1,14 +1,22 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" + xmlns:funcionesbase="clr-namespace:CtrEditor.FuncionesBase"> + + + + + diff --git a/ObjetosSim/Decorativos/ucCustomImage.xaml.cs b/ObjetosSim/Decorativos/ucCustomImage.xaml.cs index c1c6a98..8525fb1 100644 --- a/ObjetosSim/Decorativos/ucCustomImage.xaml.cs +++ b/ObjetosSim/Decorativos/ucCustomImage.xaml.cs @@ -33,6 +33,16 @@ namespace CtrEditor.ObjetosSim [property: Category("Image:")] private string imagePath; + [ObservableProperty] + [property: Description("Flip the image horizontally")] + [property: Category("Image:")] + private bool horizontal_Flip; + + [ObservableProperty] + [property: Description("Flip the image vertically")] + [property: Category("Image:")] + private bool vertical_Flip; + [JsonIgnore] [ObservableProperty] @@ -51,6 +61,16 @@ namespace CtrEditor.ObjetosSim } } + partial void OnHorizontal_FlipChanged(bool value) + { + // Property changed handler will trigger UI update through binding + } + + partial void OnVertical_FlipChanged(bool value) + { + // Property changed handler will trigger UI update through binding + } + public osCustomImage() { Ancho = 0.30f; diff --git a/ObjetosSim/Decorativos/ucFramePlate.xaml.cs b/ObjetosSim/Decorativos/ucFramePlate.xaml.cs index 61cad55..ae38e51 100644 --- a/ObjetosSim/Decorativos/ucFramePlate.xaml.cs +++ b/ObjetosSim/Decorativos/ucFramePlate.xaml.cs @@ -68,6 +68,13 @@ namespace CtrEditor.ObjetosSim [property: Category("Encoders:")] public float k_encoder_X; + [ObservableProperty] + [property: ReadOnly(true)] + [property: Description("Actual Position X")] + [property: Category("Encoders:")] + public float encoder_X_Position; + + [ObservableProperty] [property: Description("X in meter offset Left. Position when the encoder is 0")] [property: Category("Encoders:")] @@ -85,6 +92,12 @@ namespace CtrEditor.ObjetosSim [property: Category("Encoders:")] public float k_encoder_Y; + [ObservableProperty] + [property: ReadOnly(true)] + [property: Description("Actual Position Y")] + [property: Category("Encoders:")] + public float encoder_Y_Position; + [ObservableProperty] [property: Description("Y in meter offset Top. Position when the encoder is 0")] [property: Category("Encoders:")] @@ -186,11 +199,16 @@ namespace CtrEditor.ObjetosSim { // Update X position if encoder is available if (EncoderX != null && K_encoder_X != 0) - Left = (EncoderX.Valor_Actual / k_encoder_X) + offset_encoder_X; - + { + Encoder_Y_Position = EncoderY.Valor_Actual; + Left = (Encoder_X_Position / k_encoder_X) + offset_encoder_X; + } // Update Y position if encoder is available if (EncoderY != null && K_encoder_Y != 0) - Top = (EncoderY.Valor_Actual / k_encoder_Y) + offset_encoder_Y; + { + Encoder_Y_Position = EncoderY.Valor_Actual; + Top = (Encoder_Y_Position / k_encoder_Y) + offset_encoder_Y; + } } public override void TopChanging(float oldValue, float newValue) diff --git a/ObjetosSim/Estaticos/ucTransporteTTopDualInverter.xaml.cs b/ObjetosSim/Estaticos/ucTransporteTTopDualInverter.xaml.cs index adc66dc..5748995 100644 --- a/ObjetosSim/Estaticos/ucTransporteTTopDualInverter.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteTTopDualInverter.xaml.cs @@ -13,7 +13,7 @@ using System.Text.Json.Serialization; namespace CtrEditor.ObjetosSim { /// - /// Interaction logic for ucTransporteTTop.xaml + /// Interaction logic for ucTransporteTTopDualInverter.xaml /// /// @@ -53,7 +53,7 @@ namespace CtrEditor.ObjetosSim partial void OnInvertirDireccionChanged(bool value) { SetSpeed(); - if (_visualRepresentation is ucTransporteTTop uc) + if (_visualRepresentation is ucTransporteTTopDualInverter uc) { CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); ActualizarAnimacionStoryBoardTransporte(VelocidadActual); @@ -156,7 +156,7 @@ namespace CtrEditor.ObjetosSim private void ActualizarGeometrias() { - if (_visualRepresentation is ucTransporteTTop uc) + if (_visualRepresentation is ucTransporteTTopDualInverter uc) { UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo); SetSpeed(); @@ -206,6 +206,8 @@ namespace CtrEditor.ObjetosSim else VelocidadActual = 0; } + else + VelocidadActual = 0; } public override void ucLoaded() @@ -216,7 +218,7 @@ namespace CtrEditor.ObjetosSim OnId_Motor_AChanged(Id_Motor_A); // Link Id_Motor = Motor OnId_Motor_BChanged(Id_Motor_B); // Link Id_Motor = Motor - if (_visualRepresentation is ucTransporteTTop uc) + if (_visualRepresentation is ucTransporteTTopDualInverter uc) { SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo); CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); diff --git a/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs b/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs index f8074e5..0708de6 100644 --- a/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs +++ b/ObjetosSim/Estaticos/ucVMmotorSim.xaml.cs @@ -213,7 +213,7 @@ namespace CtrEditor.ObjetosSim // Update local state from ControlWord OUT_Run = control.run; - OUT_Stop = control.stop; + OUT_Stop = !control.stop; OUT_Reversal = control.reversal; OUT_OUT_VFD_REQ_Speed_Hz = control.reqSpeedHz; diff --git a/ObjetosSim/SensoresComandos/ucEncoderMotorLineal.xaml.cs b/ObjetosSim/SensoresComandos/ucEncoderMotorLineal.xaml.cs index 08752f1..2054945 100644 --- a/ObjetosSim/SensoresComandos/ucEncoderMotorLineal.xaml.cs +++ b/ObjetosSim/SensoresComandos/ucEncoderMotorLineal.xaml.cs @@ -56,6 +56,12 @@ namespace CtrEditor.ObjetosSim [property: Category("PLC link:")] string tag_Valor; + [ObservableProperty] + [property: Description("Tag para leer el valor del encoder. Este tag tiene prioridad sobre el Motor. Si se usa solo se lee el tag para actualizar la posicion.")] + [property: Category("PLC link:")] + string tag_ReadValor; + + partial void OnId_MotorChanged(string value) { if (Motor != null) @@ -85,7 +91,16 @@ namespace CtrEditor.ObjetosSim public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds) { - if (Motor != null && Motor is osVMmotorSim motor) + if (Tag_ReadValor != null && Tag_ReadValor.Length > 0) + { + // Bypass motor and read directly from tag + var value = LeerDINTTag(tag_ReadValor); + if (value != null) + { + Valor_Actual = (int)value; + return; + } + } else if (Motor != null && Motor is osVMmotorSim motor) { VelocidadActual = motor.Velocidad; diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs index 51d480c..98e4f0c 100644 --- a/ObjetosSim/osBase.cs +++ b/ObjetosSim/osBase.cs @@ -782,6 +782,16 @@ namespace CtrEditor.ObjetosSim } } + public int? LeerDINTTag(string Tag) + { + if (_plc == null) return null; + if (!string.IsNullOrEmpty(Tag)) + { + return _plc.LeerTagDInt(Tag); + } + return null; + } + public void EscribirWordTagScaled(string Tag, float Value, float IN_scale_Min, float IN_scale_Max, float OUT_scale_Min, float OUT_scale_Max) { if (_plc == null) return;