154 lines
4.2 KiB
C#
154 lines
4.2 KiB
C#
using System.ComponentModel;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CtrEditor.FuncionesBase;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using Newtonsoft.Json;
|
|
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
|
|
using Color = System.Windows.Media.Color;
|
|
using Colors = System.Windows.Media.Colors;
|
|
using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute;
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ucFramePlate.xaml
|
|
/// </summary>
|
|
///
|
|
|
|
public partial class osFramePlate : osBase, IosBase
|
|
{
|
|
[JsonIgnore]
|
|
public float offsetY;
|
|
[JsonIgnore]
|
|
public float offsetX;
|
|
|
|
public static string NombreClase()
|
|
{
|
|
return "Frame 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;
|
|
|
|
// Encoder
|
|
[ObservableProperty]
|
|
[property: Description("This is a link to a Encoder for X.")]
|
|
[property: Category("Encoders:")]
|
|
[property: ItemsSource(typeof(osBaseItemsSource<osEncoderMotorLineal>))]
|
|
private string encoder_X;
|
|
|
|
[ObservableProperty]
|
|
[property: Description("K Pulses per meter for Moving")]
|
|
[property: Category("Encoders:")]
|
|
public float k_encoder_X;
|
|
|
|
[ObservableProperty]
|
|
[property: Description("X in meter offset Left. Position when the encoder is 0")]
|
|
[property: Category("Encoders:")]
|
|
public float offset_encoder_X;
|
|
|
|
[JsonIgnore]
|
|
private osEncoderMotorLineal EncoderX;
|
|
|
|
[JsonIgnore]
|
|
private float EncoderXValue;
|
|
|
|
partial void OnEncoder_XChanged(string value)
|
|
{
|
|
if (_mainViewModel != null && value != null && value.Length > 0)
|
|
{
|
|
EncoderX = (osEncoderMotorLineal)_mainViewModel.ObjetosSimulables.FirstOrDefault(s => (s is osEncoderMotorLineal && s.Nombre == value), null);
|
|
}
|
|
}
|
|
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
|
{
|
|
if (EncoderX == null)
|
|
return;
|
|
if (K_encoder_X == 0)
|
|
return;
|
|
if (EncoderXValue != EncoderX.Valor_Actual)
|
|
Left = (EncoderX.Valor_Actual / k_encoder_X) + offset_encoder_X;
|
|
EncoderXValue = EncoderX.Valor_Actual;
|
|
}
|
|
|
|
public override void TopChanging(float oldValue, float newValue)
|
|
{
|
|
offsetY = newValue - oldValue;
|
|
}
|
|
public override void LeftChanging(float oldValue, float newValue)
|
|
{
|
|
offsetX = newValue - oldValue;
|
|
}
|
|
|
|
public osFramePlate()
|
|
{
|
|
Ancho = 0.5f;
|
|
Alto = 0.5f;
|
|
Alto_Titulo = 0.2f;
|
|
Color = Colors.WhiteSmoke;
|
|
Titulo = "Frame";
|
|
}
|
|
|
|
public override void ucLoaded()
|
|
{
|
|
base.ucLoaded();
|
|
// El UserControl se ha cargado
|
|
OnEncoder_XChanged(Encoder_X);
|
|
}
|
|
|
|
public override void ucUnLoaded()
|
|
{
|
|
base.ucUnLoaded();
|
|
// El UserControl se esta eliminando
|
|
// eliminar el objeto de simulacion
|
|
}
|
|
|
|
}
|
|
|
|
public partial class ucFramePlate : UserControl, IDataContainer
|
|
{
|
|
public osBase? Datos { get; set; }
|
|
|
|
public ucFramePlate()
|
|
{
|
|
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 Highlight(bool State) { }
|
|
public ZIndexEnum ZIndex()
|
|
{
|
|
return ZIndexEnum.Decorativos;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|