2024-05-22 14:21:39 -03:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-05-31 10:06:49 -03:00
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
using LibS7Adv;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
2024-06-30 13:17:44 -03:00
|
|
|
|
using CtrEditor.FuncionesBase;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
|
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for ucBoton.xaml
|
|
|
|
|
/// </summary>
|
2024-05-22 14:21:39 -03:00
|
|
|
|
public partial class osBoton : osBase, IosBase
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
|
|
|
|
// Otros datos y métodos relevantes para la simulación
|
|
|
|
|
|
2024-05-19 16:38:57 -03:00
|
|
|
|
public static string NombreClase()
|
|
|
|
|
{
|
|
|
|
|
return "Boton";
|
|
|
|
|
}
|
2024-05-22 14:21:39 -03:00
|
|
|
|
private string nombre = NombreClase();
|
|
|
|
|
public override string Nombre
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
get => nombre;
|
|
|
|
|
set => SetProperty(ref nombre, value);
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 12:33:00 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
string button_Name;
|
|
|
|
|
|
2024-05-23 14:56:14 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public bool tipo_NC;
|
2024-06-02 04:13:01 -03:00
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
[property: Hidden]
|
|
|
|
|
Color color_Pressed;
|
|
|
|
|
|
2024-06-04 12:33:00 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
Color color_Titulo;
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
2024-06-02 04:13:01 -03:00
|
|
|
|
Color color;
|
2024-05-31 19:34:58 -03:00
|
|
|
|
|
2024-06-02 04:13:01 -03:00
|
|
|
|
partial void OnColorChanged(Color value)
|
2024-05-31 19:34:58 -03:00
|
|
|
|
{
|
|
|
|
|
OnEstadoChanged(Estado);
|
|
|
|
|
}
|
2024-06-02 04:13:01 -03:00
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
[property: Hidden]
|
|
|
|
|
private Color colorButton;
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public float tamano;
|
2024-06-04 12:33:00 -03:00
|
|
|
|
|
2024-06-30 09:32:32 -03:00
|
|
|
|
public override void OnResize(float Delta_Width, float Delta_Height)
|
|
|
|
|
{
|
|
|
|
|
Tamano += Delta_Width + Delta_Height;
|
|
|
|
|
}
|
2024-06-04 12:33:00 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public bool estado;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
partial void OnEstadoChanged(bool value)
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
if (value)
|
2024-06-28 14:47:08 -03:00
|
|
|
|
Color_Pressed = Colors.LightGreen;
|
2024-05-22 14:21:39 -03:00
|
|
|
|
else
|
2024-06-28 14:47:08 -03:00
|
|
|
|
Color_Pressed = Colors.Gray;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
if (!Tipo_NC)
|
2024-05-23 14:56:14 -03:00
|
|
|
|
EscribirBitTag(Tag, value);
|
|
|
|
|
else
|
|
|
|
|
EscribirBitTag(Tag, !value);
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public string tag;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
|
2024-06-28 14:47:08 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public string tag_Luz;
|
|
|
|
|
|
2024-05-14 12:10:32 -03:00
|
|
|
|
public void ButtonDownCommand()
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
|
|
|
|
Estado = true;
|
|
|
|
|
}
|
2024-05-14 12:10:32 -03:00
|
|
|
|
public void ButtonUpCommand()
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
|
|
|
|
Estado = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public osBoton()
|
|
|
|
|
{
|
|
|
|
|
Tamano = 0.30f;
|
|
|
|
|
Estado = false;
|
|
|
|
|
Tag = "M50.0";
|
|
|
|
|
// Set initial color
|
2024-06-02 04:13:01 -03:00
|
|
|
|
Color = Colors.LightBlue;
|
2024-06-04 12:33:00 -03:00
|
|
|
|
color_Titulo = Colors.Black;
|
|
|
|
|
button_Name = "TAG";
|
2024-06-28 14:47:08 -03:00
|
|
|
|
Color_Pressed = Colors.Gray;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UpdateGeometryStart()
|
|
|
|
|
{
|
|
|
|
|
// Se llama antes de la simulacion
|
|
|
|
|
|
|
|
|
|
}
|
2024-06-28 14:47:08 -03:00
|
|
|
|
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
|
|
|
|
{
|
|
|
|
|
if (LeerBitTag(Tag_Luz))
|
|
|
|
|
ColorButton = ObtenerColorMasClaroYSaturado(Color, 0.3, 0.5);
|
|
|
|
|
else ColorButton = Color;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UpdatePLCPrimerCiclo() {
|
|
|
|
|
// Escribimos el valor actual al iniciar la conexion
|
|
|
|
|
// Esto es util para NC principalmente
|
|
|
|
|
|
|
|
|
|
OnEstadoChanged(Estado);
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 13:45:14 -03:00
|
|
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public override void ucLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
|
|
|
// crear el objeto de simulacion
|
2024-06-09 12:33:09 -03:00
|
|
|
|
base.ucLoaded();
|
2024-06-28 14:47:08 -03:00
|
|
|
|
ColorButton = Color;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
public override void ucUnLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl se esta eliminando
|
|
|
|
|
// eliminar el objeto de simulacion
|
|
|
|
|
}
|
2024-05-14 09:15:10 -03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class ucBoton : UserControl, IDataContainer
|
|
|
|
|
{
|
|
|
|
|
public osBase? Datos { get; set; }
|
|
|
|
|
|
|
|
|
|
public ucBoton()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-18 09:58:41 -03:00
|
|
|
|
this.DataContextChanged += OnDataContextChanged;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
this.Loaded += OnLoaded;
|
2024-05-18 09:58:41 -03:00
|
|
|
|
this.Unloaded += OnUnloaded;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos?.ucLoaded();
|
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos?.ucUnLoaded();
|
|
|
|
|
}
|
2024-05-14 12:10:32 -03:00
|
|
|
|
|
|
|
|
|
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos = e.NewValue as osBase;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
|
|
|
|
if (Datos is osBoton osBotonData)
|
|
|
|
|
{
|
2024-05-14 12:10:32 -03:00
|
|
|
|
osBotonData.ButtonDownCommand();
|
|
|
|
|
e.Handled = true; // Evita que el evento se propague
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-14 12:10:32 -03:00
|
|
|
|
private void Ellipse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
|
|
|
|
if (Datos is osBoton osBotonData)
|
|
|
|
|
{
|
2024-05-14 12:10:32 -03:00
|
|
|
|
osBotonData.ButtonUpCommand();
|
|
|
|
|
e.Handled = true; // Evita que el evento se propague
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Highlight(bool State) { }
|
2024-06-30 13:17:44 -03:00
|
|
|
|
public ZIndexEnum ZIndex()
|
2024-05-14 09:15:10 -03:00
|
|
|
|
{
|
2024-06-30 13:17:44 -03:00
|
|
|
|
return ZIndexEnum.Estaticos;
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
2024-06-30 13:17:44 -03:00
|
|
|
|
|
2024-05-14 09:15:10 -03:00
|
|
|
|
}
|
|
|
|
|
}
|