Mejorado de CargarPropiedadesosDatos
This commit is contained in:
parent
c1ac20964e
commit
667cd18f5d
1
App.xaml
1
App.xaml
|
@ -15,6 +15,7 @@
|
||||||
<local:BrushToColorNameConverter x:Key="BrushToColorNameConverter"/>
|
<local:BrushToColorNameConverter x:Key="BrushToColorNameConverter"/>
|
||||||
<local:VerticalPositionConverter x:Key="VerticalPositionConverter"/>
|
<local:VerticalPositionConverter x:Key="VerticalPositionConverter"/>
|
||||||
<local:SumConverter x:Key="SumConverter" />
|
<local:SumConverter x:Key="SumConverter" />
|
||||||
|
<local:StringToBrushConverter x:Key="StringToBrushConverter"/>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
|
|
||||||
|
|
|
@ -68,12 +68,14 @@
|
||||||
Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||||
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||||
Canvas.Top="{Binding Distance, Converter={StaticResource MeterToPixelConverter},ConverterParameter=-1}"
|
Canvas.Top="{Binding Distance, Converter={StaticResource MeterToPixelConverter},ConverterParameter=-1}"
|
||||||
/>
|
Color="Blue"/>
|
||||||
|
|
||||||
<uc:ThreeLinesControl x:Name="GuiaInferior" AnchoRecto="{Binding AnchoRecto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
<uc:ThreeLinesControl x:Name="GuiaInferior" AnchoRecto="{Binding AnchoRecto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||||
AnchoCentro="{Binding AnchoCentral, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
AnchoCentro="{Binding AnchoCentral, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||||
Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
Altura="{Binding Alto, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||||
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}">
|
AltoGuia="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter},ConverterParameter=1}"
|
||||||
|
Color="Blue">
|
||||||
|
|
||||||
<Canvas.Top>
|
<Canvas.Top>
|
||||||
<MultiBinding Converter="{StaticResource SumConverter}">
|
<MultiBinding Converter="{StaticResource SumConverter}">
|
||||||
<Binding Path="Alto" Converter="{StaticResource MeterToPixelConverter}" ConverterParameter="1.0" />
|
<Binding Path="Alto" Converter="{StaticResource MeterToPixelConverter}" ConverterParameter="1.0" />
|
||||||
|
|
|
@ -35,6 +35,9 @@ namespace CtrEditor.ObjetosSim
|
||||||
set => SetProperty(ref nombre, value);
|
set => SetProperty(ref nombre, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
string color;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public string motorA;
|
public string motorA;
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,13 @@ namespace CtrEditor.ObjetosSim
|
||||||
public bool tipo_NC;
|
public bool tipo_NC;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private Brush color;
|
private Brush color;
|
||||||
|
|
||||||
|
partial void OnColorChanged(Brush value)
|
||||||
|
{
|
||||||
|
OnEstadoChanged(Estado);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private Brush colorButton_oculto;
|
private Brush colorButton_oculto;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
|
|
|
@ -8,6 +8,8 @@ using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using CtrEditor.ObjetosSim.UserControls;
|
using CtrEditor.ObjetosSim.UserControls;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
namespace CtrEditor.ObjetosSim
|
namespace CtrEditor.ObjetosSim
|
||||||
{
|
{
|
||||||
|
@ -76,10 +78,11 @@ namespace CtrEditor.ObjetosSim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void CargarPropiedadesosDatos(Object selectedObject, StackPanel PanelEdicion, ResourceDictionary Resources)
|
public static void CargarPropiedadesosDatos(Object selectedObject, StackPanel PanelEdicion, ResourceDictionary Resources)
|
||||||
{
|
{
|
||||||
PanelEdicion.Children.Clear();
|
PanelEdicion.Children.Clear();
|
||||||
var properties = selectedObject.GetType().GetProperties();
|
var properties = selectedObject.GetType().GetProperties().OrderBy(p => p.Name); // Ordenar alfabéticamente
|
||||||
|
|
||||||
foreach (var property in properties)
|
foreach (var property in properties)
|
||||||
{
|
{
|
||||||
|
@ -120,17 +123,37 @@ namespace CtrEditor.ObjetosSim
|
||||||
|
|
||||||
if (property.PropertyType == typeof(float))
|
if (property.PropertyType == typeof(float))
|
||||||
{
|
{
|
||||||
if (Resources != null)
|
if (Application.Current.Resources.Contains("floatFormatter"))
|
||||||
binding.Converter = (FloatToFormattedStringConverter)Resources["floatFormatter"];
|
{
|
||||||
|
binding.Converter = Application.Current.Resources["floatFormatter"] as IValueConverter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (property.PropertyType == typeof(double))
|
if (property.PropertyType == typeof(double))
|
||||||
{
|
{
|
||||||
if (Resources != null)
|
if (Application.Current.Resources.Contains("doubleFormatter"))
|
||||||
binding.Converter = (DoubleToFormattedStringConverter)Resources["doubleFormatter"];
|
{
|
||||||
|
binding.Converter = Application.Current.Resources["doubleFormatter"] as IValueConverter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textBox.SetBinding(TextBox.TextProperty, binding);
|
textBox.SetBinding(TextBox.TextProperty, binding);
|
||||||
|
|
||||||
|
textBox.KeyDown += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Enter || e.Key == Key.Down)
|
||||||
|
{
|
||||||
|
var request = new TraversalRequest(FocusNavigationDirection.Next);
|
||||||
|
request.Wrapped = true;
|
||||||
|
textBox.MoveFocus(request);
|
||||||
|
}
|
||||||
|
else if (e.Key == Key.Up)
|
||||||
|
{
|
||||||
|
var request = new TraversalRequest(FocusNavigationDirection.Previous);
|
||||||
|
request.Wrapped = true;
|
||||||
|
textBox.MoveFocus(request);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Grid.SetColumn(textBox, 1);
|
Grid.SetColumn(textBox, 1);
|
||||||
grid.Children.Add(textBox);
|
grid.Children.Add(textBox);
|
||||||
}
|
}
|
||||||
|
@ -150,59 +173,94 @@ namespace CtrEditor.ObjetosSim
|
||||||
|
|
||||||
checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
|
checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
|
||||||
|
|
||||||
|
checkBox.KeyDown += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Enter || e.Key == Key.Down)
|
||||||
|
{
|
||||||
|
var request = new TraversalRequest(FocusNavigationDirection.Next);
|
||||||
|
request.Wrapped = true;
|
||||||
|
checkBox.MoveFocus(request);
|
||||||
|
}
|
||||||
|
else if (e.Key == Key.Up)
|
||||||
|
{
|
||||||
|
var request = new TraversalRequest(FocusNavigationDirection.Previous);
|
||||||
|
request.Wrapped = true;
|
||||||
|
checkBox.MoveFocus(request);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Grid.SetColumn(checkBox, 1);
|
Grid.SetColumn(checkBox, 1);
|
||||||
grid.Children.Add(checkBox);
|
grid.Children.Add(checkBox);
|
||||||
}
|
}
|
||||||
else if (property.PropertyType == typeof(Brush))
|
else if (property.PropertyType == typeof(Brush))
|
||||||
{
|
{
|
||||||
var listBox = new ListBox
|
var comboBox = new ComboBox
|
||||||
{
|
{
|
||||||
ItemsSource = new List<string> { "Rojo", "Azul", "Negro", "Verde", "Gris" },
|
ItemsSource = new List<Tuple<string, SolidColorBrush>>
|
||||||
|
{
|
||||||
|
Tuple.Create("Rojo", Brushes.Red),
|
||||||
|
Tuple.Create("Azul", Brushes.Blue),
|
||||||
|
Tuple.Create("Negro", Brushes.Black),
|
||||||
|
Tuple.Create("Verde", Brushes.Green),
|
||||||
|
Tuple.Create("Gris", Brushes.Gray)
|
||||||
|
},
|
||||||
|
SelectedValuePath = "Item2",
|
||||||
Margin = new Thickness(0),
|
Margin = new Thickness(0),
|
||||||
MinWidth = 200
|
MinWidth = 200
|
||||||
};
|
};
|
||||||
|
|
||||||
listBox.SelectionChanged += (sender, e) =>
|
|
||||||
{
|
|
||||||
if (listBox.SelectedItem != null)
|
|
||||||
{
|
|
||||||
switch (listBox.SelectedItem.ToString())
|
|
||||||
{
|
|
||||||
case "Rojo":
|
|
||||||
property.SetValue(selectedObject, Brushes.Red);
|
|
||||||
break;
|
|
||||||
case "Azul":
|
|
||||||
property.SetValue(selectedObject, Brushes.Blue);
|
|
||||||
break;
|
|
||||||
case "Negro":
|
|
||||||
property.SetValue(selectedObject, Brushes.Black);
|
|
||||||
break;
|
|
||||||
case "Verde":
|
|
||||||
property.SetValue(selectedObject, Brushes.Green);
|
|
||||||
break;
|
|
||||||
case "Gris":
|
|
||||||
property.SetValue(selectedObject, Brushes.Gray);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var binding = new Binding(property.Name)
|
var binding = new Binding(property.Name)
|
||||||
{
|
{
|
||||||
Source = selectedObject,
|
Source = selectedObject,
|
||||||
Mode = BindingMode.TwoWay,
|
Mode = BindingMode.TwoWay,
|
||||||
Converter = new BrushToColorNameConverter()
|
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
|
||||||
};
|
};
|
||||||
|
|
||||||
listBox.SetBinding(ListBox.SelectedItemProperty, binding);
|
comboBox.SetBinding(ComboBox.SelectedValueProperty, binding);
|
||||||
|
|
||||||
Grid.SetColumn(listBox, 1);
|
comboBox.KeyDown += (sender, e) =>
|
||||||
grid.Children.Add(listBox);
|
{
|
||||||
|
if (e.Key == Key.Enter || e.Key == Key.Down)
|
||||||
|
{
|
||||||
|
var request = new TraversalRequest(FocusNavigationDirection.Next);
|
||||||
|
request.Wrapped = true;
|
||||||
|
comboBox.MoveFocus(request);
|
||||||
|
}
|
||||||
|
else if (e.Key == Key.Up)
|
||||||
|
{
|
||||||
|
var request = new TraversalRequest(FocusNavigationDirection.Previous);
|
||||||
|
request.Wrapped = true;
|
||||||
|
comboBox.MoveFocus(request);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var template = new DataTemplate();
|
||||||
|
var stackPanelFactory = new FrameworkElementFactory(typeof(StackPanel));
|
||||||
|
stackPanelFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
|
||||||
|
|
||||||
|
var rectangleFactory = new FrameworkElementFactory(typeof(Rectangle));
|
||||||
|
rectangleFactory.SetValue(Rectangle.WidthProperty, 16.0);
|
||||||
|
rectangleFactory.SetValue(Rectangle.HeightProperty, 16.0);
|
||||||
|
rectangleFactory.SetBinding(Rectangle.FillProperty, new Binding("Item2"));
|
||||||
|
stackPanelFactory.AppendChild(rectangleFactory);
|
||||||
|
|
||||||
|
var textBlockFactory = new FrameworkElementFactory(typeof(TextBlock));
|
||||||
|
textBlockFactory.SetBinding(TextBlock.TextProperty, new Binding("Item1"));
|
||||||
|
stackPanelFactory.AppendChild(textBlockFactory);
|
||||||
|
|
||||||
|
template.VisualTree = stackPanelFactory;
|
||||||
|
comboBox.ItemTemplate = template;
|
||||||
|
|
||||||
|
Grid.SetColumn(comboBox, 1);
|
||||||
|
grid.Children.Add(comboBox);
|
||||||
}
|
}
|
||||||
PanelEdicion.Children.Add(grid);
|
PanelEdicion.Children.Add(grid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static List<string> CargarPropiedadesosDatosTags(Object selectedObject, StackPanel PanelEdicion, ResourceDictionary Resources)
|
public static List<string> CargarPropiedadesosDatosTags(Object selectedObject, StackPanel PanelEdicion, ResourceDictionary Resources)
|
||||||
{
|
{
|
||||||
PanelEdicion.Children.Clear();
|
PanelEdicion.Children.Clear();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Windows;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
@ -8,6 +9,10 @@ namespace CtrEditor.ObjetosSim.UserControls
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for ThreeLinesControl.xaml
|
/// Interaction logic for ThreeLinesControl.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
///
|
||||||
|
|
||||||
|
|
||||||
|
[ObservableObject]
|
||||||
public partial class ThreeLinesControl : UserControl
|
public partial class ThreeLinesControl : UserControl
|
||||||
{
|
{
|
||||||
private Rectangle _liz;
|
private Rectangle _liz;
|
||||||
|
@ -18,6 +23,7 @@ namespace CtrEditor.ObjetosSim.UserControls
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Loaded += ThreeLinesControl_Loaded;
|
this.Loaded += ThreeLinesControl_Loaded;
|
||||||
|
Color = Brushes.Gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThreeLinesControl_Loaded(object sender, RoutedEventArgs e)
|
private void ThreeLinesControl_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
@ -25,6 +31,9 @@ namespace CtrEditor.ObjetosSim.UserControls
|
||||||
CreateOrUpdateRectangles();
|
CreateOrUpdateRectangles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private Brush color;
|
||||||
|
|
||||||
public double AnchoRecto
|
public double AnchoRecto
|
||||||
{
|
{
|
||||||
get { return (double)GetValue(AnchoRectoProperty); }
|
get { return (double)GetValue(AnchoRectoProperty); }
|
||||||
|
@ -76,7 +85,7 @@ namespace CtrEditor.ObjetosSim.UserControls
|
||||||
{
|
{
|
||||||
Width = AnchoRecto,
|
Width = AnchoRecto,
|
||||||
Height = AltoGuia,
|
Height = AltoGuia,
|
||||||
Fill = Brushes.Blue
|
Fill = Color
|
||||||
};
|
};
|
||||||
Canvas.SetLeft(_liz, 0);
|
Canvas.SetLeft(_liz, 0);
|
||||||
Canvas.SetTop(_liz, -AltoGuia / 2);
|
Canvas.SetTop(_liz, -AltoGuia / 2);
|
||||||
|
@ -87,7 +96,7 @@ namespace CtrEditor.ObjetosSim.UserControls
|
||||||
{
|
{
|
||||||
Width = CalculateLcWidth(),
|
Width = CalculateLcWidth(),
|
||||||
Height = AltoGuia,
|
Height = AltoGuia,
|
||||||
Fill = Brushes.Red,
|
Fill = Color,
|
||||||
RenderTransformOrigin = new Point(0, 0.5)
|
RenderTransformOrigin = new Point(0, 0.5)
|
||||||
};
|
};
|
||||||
_lc.RenderTransform = new RotateTransform(GetRotationAngle(AnchoCentro, Altura));
|
_lc.RenderTransform = new RotateTransform(GetRotationAngle(AnchoCentro, Altura));
|
||||||
|
@ -100,7 +109,7 @@ namespace CtrEditor.ObjetosSim.UserControls
|
||||||
{
|
{
|
||||||
Width = AnchoRecto,
|
Width = AnchoRecto,
|
||||||
Height = AltoGuia,
|
Height = AltoGuia,
|
||||||
Fill = Brushes.Green
|
Fill = Color
|
||||||
};
|
};
|
||||||
Canvas.SetLeft(_lde, AnchoRecto + AnchoCentro);
|
Canvas.SetLeft(_lde, AnchoRecto + AnchoCentro);
|
||||||
Canvas.SetTop(_lde, Altura - AltoGuia / 2);
|
Canvas.SetTop(_lde, Altura - AltoGuia / 2);
|
||||||
|
|
|
@ -447,7 +447,7 @@ namespace CtrEditor.Simulacion
|
||||||
Body.SetFriction(0.2f);
|
Body.SetFriction(0.2f);
|
||||||
|
|
||||||
// Configurar amortiguamiento
|
// Configurar amortiguamiento
|
||||||
Body.LinearDamping = 1f; // Ajustar para controlar la reducción de la velocidad lineal
|
Body.LinearDamping = 3f; // Ajustar para controlar la reducción de la velocidad lineal
|
||||||
Body.AngularDamping = 1f; // Ajustar para controlar la reducción de la velocidad angular
|
Body.AngularDamping = 1f; // Ajustar para controlar la reducción de la velocidad angular
|
||||||
Body.SetRestitution(0f); // Baja restitución para menos rebote
|
Body.SetRestitution(0f); // Baja restitución para menos rebote
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,22 @@ using System.Windows;
|
||||||
|
|
||||||
namespace CtrEditor
|
namespace CtrEditor
|
||||||
{
|
{
|
||||||
|
public class StringToBrushConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is string colorString)
|
||||||
|
{
|
||||||
|
return (Brush)new BrushConverter().ConvertFromString(colorString);
|
||||||
|
}
|
||||||
|
return Brushes.Transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
public class SumConverter : IMultiValueConverter
|
public class SumConverter : IMultiValueConverter
|
||||||
{
|
{
|
||||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
|
Loading…
Reference in New Issue