From 20467c88ae39f9118b9cc7266d73de27019264da Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 13 Jun 2025 23:50:19 +0200 Subject: [PATCH] =?UTF-8?q?Se=20agregaron=20nuevas=20propiedades=20y=20m?= =?UTF-8?q?=C3=A9todos=20para=20gestionar=20el=20=C3=A1ngulo=20de=20rotaci?= =?UTF-8?q?=C3=B3n=20en=20la=20clase=20ucFramePlate,=20incluyendo=20la=20i?= =?UTF-8?q?mplementaci=C3=B3n=20de=20encoders=20para=20la=20rotaci=C3=B3n.?= =?UTF-8?q?=20Se=20mejor=C3=B3=20la=20actualizaci=C3=B3n=20de=20la=20posic?= =?UTF-8?q?i=C3=B3n=20en=20funci=C3=B3n=20del=20valor=20del=20encoder=20de?= =?UTF-8?q?=20rotaci=C3=B3n=20y=20se=20implementaron=20cambios=20en=20la?= =?UTF-8?q?=20gesti=C3=B3n=20de=20eventos=20para=20reflejar=20adecuadament?= =?UTF-8?q?e=20las=20modificaciones=20en=20el=20=C3=A1ngulo.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ObjetosSim/Decorativos/ucFramePlate.xaml.cs | 85 ++++++++++++++++++++- ObjetosSim/osBase.cs | 12 +++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/ObjetosSim/Decorativos/ucFramePlate.xaml.cs b/ObjetosSim/Decorativos/ucFramePlate.xaml.cs index ae38e51..f7b15a9 100644 --- a/ObjetosSim/Decorativos/ucFramePlate.xaml.cs +++ b/ObjetosSim/Decorativos/ucFramePlate.xaml.cs @@ -24,6 +24,8 @@ namespace CtrEditor.ObjetosSim public float offsetY; [JsonIgnore] public float offsetX; + [JsonIgnore] + public float offsetAngulo; public static string NombreClase() { @@ -103,6 +105,29 @@ namespace CtrEditor.ObjetosSim [property: Category("Encoders:")] public float offset_encoder_Y; + // Encoder Rotation + [ObservableProperty] + [property: Description("This is a link to a Encoder for Rotation.")] + [property: Category("Encoders:")] + [property: ItemsSource(typeof(osBaseItemsSource))] + private string encoder_Rotation; + + [ObservableProperty] + [property: Description("K Pulses per degree for Rotation")] + [property: Category("Encoders:")] + public float k_encoder_Rotation; + + [ObservableProperty] + [property: ReadOnly(true)] + [property: Description("Actual Rotation Angle")] + [property: Category("Encoders:")] + public float encoder_Rotation_Angle; + + [ObservableProperty] + [property: Description("Angle in degrees offset. Angle when the encoder is 0")] + [property: Category("Encoders:")] + public float offset_encoder_Rotation; + partial void OnK_encoder_YChanged(float value) { UpdatePosition(); @@ -123,18 +148,34 @@ namespace CtrEditor.ObjetosSim UpdatePosition(); } + partial void OnK_encoder_RotationChanged(float value) + { + UpdatePosition(); + } + + partial void OnOffset_encoder_RotationChanged(float value) + { + UpdatePosition(); + } + [JsonIgnore] private osEncoderMotorLineal EncoderX; [JsonIgnore] private osEncoderMotorLineal EncoderY; + [JsonIgnore] + private osEncoderMotorLineal EncoderRotation; + [JsonIgnore] private bool isUpdatingFromEncoderX = false; [JsonIgnore] private bool isUpdatingFromEncoderY = false; + [JsonIgnore] + private bool isUpdatingFromEncoderRotation = false; + partial void OnEncoder_XChanged(string value) { if (EncoderX != null) @@ -159,6 +200,18 @@ namespace CtrEditor.ObjetosSim } } + partial void OnEncoder_RotationChanged(string value) + { + if (EncoderRotation != null) + EncoderRotation.PropertyChanged -= OnEncoderRotationPropertyChanged; + if (_mainViewModel != null && value != null && value.Length > 0) + { + EncoderRotation = (osEncoderMotorLineal)_mainViewModel.ObjetosSimulables.FirstOrDefault(s => (s is osEncoderMotorLineal && s.Nombre == value), null); + if (EncoderRotation != null) + EncoderRotation.PropertyChanged += OnEncoderRotationPropertyChanged; + } + } + private void OnEncoderXPropertyChanged(object sender, PropertyChangedEventArgs e) { if (!isUpdatingFromEncoderX) @@ -195,12 +248,30 @@ namespace CtrEditor.ObjetosSim } } + private void OnEncoderRotationPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (!isUpdatingFromEncoderRotation) + { + isUpdatingFromEncoderRotation = true; + // Actualizamos el nombre si este fue modificado + if (e.PropertyName == nameof(osEncoderMotorLineal.Nombre)) + Encoder_Rotation = ((osEncoderMotorLineal)sender).Nombre; + + if (e.PropertyName == nameof(osEncoderMotorLineal.Valor_Actual)) + { + UpdatePosition(); + } + + isUpdatingFromEncoderRotation = false; + } + } + public void UpdatePosition() { // Update X position if encoder is available if (EncoderX != null && K_encoder_X != 0) { - Encoder_Y_Position = EncoderY.Valor_Actual; + Encoder_X_Position = EncoderX.Valor_Actual; Left = (Encoder_X_Position / k_encoder_X) + offset_encoder_X; } // Update Y position if encoder is available @@ -209,6 +280,12 @@ namespace CtrEditor.ObjetosSim Encoder_Y_Position = EncoderY.Valor_Actual; Top = (Encoder_Y_Position / k_encoder_Y) + offset_encoder_Y; } + // Update rotation angle if encoder is available + if (EncoderRotation != null && K_encoder_Rotation != 0) + { + Encoder_Rotation_Angle = EncoderRotation.Valor_Actual; + Angulo = (Encoder_Rotation_Angle / k_encoder_Rotation) + offset_encoder_Rotation; + } } public override void TopChanging(float oldValue, float newValue) @@ -220,6 +297,11 @@ namespace CtrEditor.ObjetosSim offsetX = newValue - oldValue; } + public override void AnguloChanging(float oldValue, float newValue) + { + offsetAngulo = newValue - oldValue; + } + [ObservableProperty] [property: Description("Show/Hide the plate background")] [property: Category("Appearance:")] @@ -242,6 +324,7 @@ namespace CtrEditor.ObjetosSim // El UserControl se ha cargado OnEncoder_XChanged(Encoder_X); OnEncoder_YChanged(Encoder_Y); + OnEncoder_RotationChanged(Encoder_Rotation); UpdateZIndex(Zindex_FramePlate); } diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs index 91c0f00..1c12902 100644 --- a/ObjetosSim/osBase.cs +++ b/ObjetosSim/osBase.cs @@ -160,7 +160,13 @@ namespace CtrEditor.ObjetosSim { AnguloChanged(value); } + partial void OnAnguloChanging(float oldValue, float newValue) + { + AnguloChanging(oldValue, newValue); + } + public virtual void AnguloChanged(float value) { } + public virtual void AnguloChanging(float oldValue, float newValue) { } public void Resize(double width, double height) @@ -328,6 +334,12 @@ namespace CtrEditor.ObjetosSim OnMoveResizeRotate(); } + if (e.PropertyName == nameof(osFramePlate.Angulo)) + { + Angulo += ((osFramePlate)sender).offsetAngulo; + OnMoveResizeRotate(); + } + if (e.PropertyName == nameof(osFramePlate.Zindex_FramePlate)) UpdateZIndex(((osFramePlate)sender).Zindex_FramePlate);