127 lines
4.3 KiB
C#
127 lines
4.3 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Newtonsoft.Json;
|
|
using System.Diagnostics;
|
|
using CtrEditor.ObjetosSim;
|
|
using CtrEditor.FuncionesBase;
|
|
|
|
namespace CtrEditor.ObjetosSim.HydraulicComponents
|
|
{
|
|
/// <summary>
|
|
/// UserControl para el tanque hidráulico osHydTank
|
|
/// </summary>
|
|
public partial class ucHydTank : UserControl, IDataContainer
|
|
{
|
|
#region IDataContainer Implementation
|
|
|
|
[JsonIgnore]
|
|
public osBase? Datos { get; set; }
|
|
|
|
public int zIndex_fromFrames { get; set; } = 0;
|
|
|
|
private bool _isHighlighted = false;
|
|
|
|
#endregion
|
|
|
|
public ucHydTank()
|
|
{
|
|
InitializeComponent();
|
|
Loaded += OnUserControlLoaded;
|
|
Unloaded += OnUserControlUnloaded;
|
|
DataContextChanged += OnDataContextChanged;
|
|
|
|
// Debug: Confirmar que el UserControl se está creando
|
|
Debug.WriteLine("ucHydTank Constructor: UserControl del tanque hidráulico creado");
|
|
}
|
|
|
|
private void OnUserControlUnloaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Datos?.ucUnLoaded();
|
|
}
|
|
|
|
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (DataContext is osHydTank tank)
|
|
{
|
|
Datos = tank;
|
|
}
|
|
}
|
|
|
|
private void OnUserControlLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
// Debug: Confirmar que el UserControl se está cargando
|
|
Debug.WriteLine($"ucHydTank.OnUserControlLoaded: DataContext = {DataContext?.GetType().Name ?? "null"}");
|
|
|
|
// Llamar a ucLoaded() usando la propiedad Datos
|
|
Datos?.ucLoaded();
|
|
|
|
// Asegurar que el DataContext esté configurado correctamente
|
|
if (Datos is osHydTank tank)
|
|
{
|
|
Debug.WriteLine($"ucHydTank.OnUserControlLoaded: Tanque '{tank.Nombre}' conectado - Tamaño: {tank.Tamano}");
|
|
// Suscribirse a cambios de propiedades para actualizar la UI
|
|
tank.PropertyChanged += Tank_PropertyChanged;
|
|
UpdateVisualProperties();
|
|
}
|
|
else
|
|
{
|
|
Debug.WriteLine("ucHydTank.OnUserControlLoaded: ERROR - Datos no es osHydTank o es null");
|
|
}
|
|
}
|
|
|
|
private void Tank_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
{
|
|
// Actualizar propiedades visuales cuando cambien propiedades relevantes
|
|
if (e.PropertyName == nameof(osHydTank.FillPercentage) ||
|
|
e.PropertyName == nameof(osHydTank.CurrentLevel) ||
|
|
e.PropertyName == nameof(osHydTank.FlowBalance) ||
|
|
e.PropertyName == nameof(osHydTank.TankType) ||
|
|
e.PropertyName == nameof(osHydTank.ConnectedInletPipe) ||
|
|
e.PropertyName == nameof(osHydTank.ConnectedOutletPipe))
|
|
{
|
|
UpdateVisualProperties();
|
|
}
|
|
}
|
|
|
|
private void UpdateVisualProperties()
|
|
{
|
|
if (Datos is osHydTank tank)
|
|
{
|
|
// Forzar actualización del UI - las propiedades se actualizan automáticamente
|
|
// cuando cambian las propiedades base gracias al binding
|
|
this.InvalidateVisual();
|
|
}
|
|
}
|
|
|
|
#region IDataContainer Implementation Methods
|
|
|
|
public void Highlight(bool state)
|
|
{
|
|
_isHighlighted = state;
|
|
|
|
if (state)
|
|
{
|
|
// Resaltar el contenedor del tanque con borde amarillo y más grueso
|
|
rectTankContainer.Stroke = new SolidColorBrush(Colors.Yellow);
|
|
rectTankContainer.StrokeThickness = 4;
|
|
}
|
|
else
|
|
{
|
|
// Volver al estado normal
|
|
rectTankContainer.Stroke = new SolidColorBrush(Colors.DarkGray);
|
|
rectTankContainer.StrokeThickness = 2;
|
|
}
|
|
}
|
|
|
|
public ZIndexEnum ZIndex_Base()
|
|
{
|
|
return ZIndexEnum.Estaticos;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|