From 3bc314182cfda5ab6fe89642fe584500be9aece0 Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 24 Jun 2025 17:45:47 +0200 Subject: [PATCH] =?UTF-8?q?Se=20realizaron=20mejoras=20en=20la=20clase=20M?= =?UTF-8?q?ainViewModel=20al=20agregar=20espacios=20en=20blanco=20para=20m?= =?UTF-8?q?ejorar=20la=20legibilidad.=20En=20TagEditorAttribute,=20se=20a?= =?UTF-8?q?=C3=B1adieron=20nuevos=20atributos=20y=20se=20implement=C3=B3?= =?UTF-8?q?=20la=20l=C3=B3gica=20para=20manejar=20nombres=20personalizados?= =?UTF-8?q?=20de=20propiedades.=20En=20UserControlFactory,=20se=20optimiz?= =?UTF-8?q?=C3=B3=20la=20obtenci=C3=B3n=20de=20nombres=20de=20propiedades?= =?UTF-8?q?=20y=20se=20eliminaron=20espacios=20en=20blanco=20innecesarios.?= =?UTF-8?q?=20Finalmente,=20se=20a=C3=B1adi=C3=B3=20un=20atributo=20Name?= =?UTF-8?q?=20en=20ucTransporteTTop=20para=20el=20coeficiente=20de=20fricc?= =?UTF-8?q?i=C3=B3n,=20mejorando=20la=20claridad=20en=20la=20interfaz=20de?= =?UTF-8?q?=20usuario.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainViewModel.cs | 2 ++ ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs | 1 + ObjetosSim/TagEditorAttribute.cs | 20 ++++++++++++- ObjetosSim/UserControlFactory.cs | 30 ++++++++++++++----- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/MainViewModel.cs b/MainViewModel.cs index 4d9c303..bad6e71 100644 --- a/MainViewModel.cs +++ b/MainViewModel.cs @@ -1337,6 +1337,8 @@ namespace CtrEditor // Mostrar como modeless (no modal) libraryWindow.Show(); } + + } public class SimulationData diff --git a/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs b/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs index 092132f..2799823 100644 --- a/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs @@ -105,6 +105,7 @@ namespace CtrEditor.ObjetosSim [ObservableProperty] [property: Category("Setup:")] + [property: Name("Coeficiente de Fricción")] public float frictionCoefficient; [ObservableProperty] [property: Category("Setup:")] diff --git a/ObjetosSim/TagEditorAttribute.cs b/ObjetosSim/TagEditorAttribute.cs index baa3ce6..8ad8d52 100644 --- a/ObjetosSim/TagEditorAttribute.cs +++ b/ObjetosSim/TagEditorAttribute.cs @@ -1,3 +1,4 @@ +using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; @@ -12,9 +13,26 @@ namespace CtrEditor.ObjetosSim /// /// Atributo para marcar propiedades que deben usar el editor de etiquetas /// + [AttributeUsage(AttributeTargets.Property)] public class TagEditorAttribute : Attribute { - public TagEditorAttribute() { } + public Type? EditorType { get; } + + public TagEditorAttribute(Type? editorType = null) + { + EditorType = editorType; + } + } + + [AttributeUsage(AttributeTargets.Property)] + public class NameAttribute : Attribute + { + public string DisplayName { get; } + + public NameAttribute(string displayName) + { + DisplayName = displayName ?? throw new ArgumentNullException(nameof(displayName)); + } } /// diff --git a/ObjetosSim/UserControlFactory.cs b/ObjetosSim/UserControlFactory.cs index 28bfc91..362e2d9 100644 --- a/ObjetosSim/UserControlFactory.cs +++ b/ObjetosSim/UserControlFactory.cs @@ -91,7 +91,7 @@ namespace CtrEditor.ObjetosSim { // Forzar la actualización de bindings pendientes antes de limpiar ForzarActualizacionBindings(propertyGrid); - + // Clear previous properties propertyGrid.SelectedObject = null; propertyGrid.PropertyDefinitions.Clear(); @@ -129,7 +129,7 @@ namespace CtrEditor.ObjetosSim // Pequeña pausa para permitir que se procesen los eventos System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke( - System.Windows.Threading.DispatcherPriority.Background, + System.Windows.Threading.DispatcherPriority.Background, new Action(() => { })); } catch (Exception ex) @@ -144,7 +144,7 @@ namespace CtrEditor.ObjetosSim for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) { var child = VisualTreeHelper.GetChild(parent, i); - + // Buscar TextBox, ComboBox, y otros controles de edición comunes if (child is TextBox textBox) { @@ -163,7 +163,7 @@ namespace CtrEditor.ObjetosSim var expression = checkBox.GetBindingExpression(CheckBox.IsCheckedProperty); expression?.UpdateSource(); } - + // Recursión para buscar en controles hijos ForzarActualizacionControlesEditores(child); } @@ -173,7 +173,7 @@ namespace CtrEditor.ObjetosSim { // Forzar la actualización de bindings pendientes antes de cambiar el objeto ForzarActualizacionBindings(propertyGrid); - + // Limpia las propiedades previas propertyGrid.SelectedObject = null; propertyGrid.PropertyDefinitions.Clear(); @@ -190,12 +190,26 @@ namespace CtrEditor.ObjetosSim continue; var displayNameAttr = property.Attributes.OfType().FirstOrDefault(); + var customNameAttr = property.Attributes.OfType().FirstOrDefault(); + + string displayName; + if (customNameAttr != null) + { + displayName = customNameAttr.DisplayName; + } + else if (displayNameAttr != null) + { + displayName = displayNameAttr.DisplayName; + } + else + { + displayName = property.Name.Replace("_", " "); + } + var propertyDefinition = new PropertyDefinition { TargetProperties = new[] { property.Name }, - DisplayName = displayNameAttr != null - ? displayNameAttr.DisplayName - : property.Name.Replace("_", " ") + DisplayName = displayName }; // Aquí se añaden todas las propiedades; para "ImagePath" no se requiere