CtrEditor/ObjetosSim/Decorativos/ucTextPlate.xaml.cs

154 lines
4.1 KiB
C#
Raw Normal View History

2024-06-04 12:33:00 -03:00
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
using System.Windows.Input;
namespace CtrEditor.ObjetosSim
{
/// <summary>
/// Interaction logic for ucTextPlate.xaml
/// </summary>
///
public partial class osTextPlate : osBase, IosBase
{
public static string NombreClase()
{
return "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;
[ObservableProperty]
public float ancho;
[ObservableProperty]
public float alto;
[ObservableProperty]
public float angulo;
public override void TopChanging(float oldValue, float newValue) {
UpdateChildsTop(newValue - oldValue);
}
public override void LeftChanging(float oldValue, float newValue) {
UpdateChildsLeft(newValue - oldValue);
}
protected void UpdateChildsTop(float offsetY)
{
if (!string.IsNullOrEmpty(Nombre) && _mainViewModel != null)
{
foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables)
{
if (objetoSimulable != this && objetoSimulable.Group_Panel == Nombre)
{
objetoSimulable.Top += offsetY;
}
}
}
}
protected void UpdateChildsLeft(float offsetX)
{
if (!string.IsNullOrEmpty(Nombre) && _mainViewModel != null)
{
foreach (var objetoSimulable in _mainViewModel.ObjetosSimulables)
{
if (objetoSimulable != this && objetoSimulable.Group_Panel == Nombre)
{
objetoSimulable.Left += offsetX;
}
}
}
}
public osTextPlate()
{
Ancho = 0.5f;
Alto = 0.5f;
Alto_Titulo = 0.2f;
Color = Colors.Gray;
Titulo = "Titulo";
}
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
}
}
public partial class ucTextPlate : UserControl, IDataContainer
{
public osBase? Datos { get; set; }
public ucTextPlate()
{
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 Resize(float width, float height)
{
if (Datos is osTextPlate datos)
{
datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(height);
}
}
public void Move(float LeftPixels, float TopPixels)
{
if (Datos != null)
{
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
}
}
public void Rotate(float Angle)
{
if (Datos != null)
if (Datos is osTextPlate datos)
datos.Angulo = Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
{
return 1;
}
}
}