sin conseguir capturar los eventos del boton
This commit is contained in:
parent
9c8eb0b348
commit
b224070690
|
@ -38,6 +38,7 @@ namespace CtrEditor.Convertidores
|
|||
if (parameter != null)
|
||||
if (parameter.ToString() == "0.5") factor = 0.5f;
|
||||
else if (parameter.ToString() == "-0.5") factor = -0.5f;
|
||||
else if (parameter.ToString() == "1.5") factor = 1.5f;
|
||||
|
||||
return PixelToMeter.Instance.calc.MetersToPixels(meters) * factor;
|
||||
}
|
||||
|
@ -49,6 +50,7 @@ namespace CtrEditor.Convertidores
|
|||
if (parameter != null)
|
||||
if (parameter.ToString() == "0.5") factor = 0.5f;
|
||||
else if (parameter.ToString() == "-0.5") factor = -0.5f;
|
||||
else if (parameter.ToString() == "1.5") factor = 1.5f;
|
||||
|
||||
return PixelToMeter.Instance.calc.PixelsToMeters(pixels) * factor;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace CtrEditor
|
|||
|
||||
// Inicializa el PLCViewModel
|
||||
_plcViewModelData = new PLCViewModel();
|
||||
_plcViewModelData.RefreshEvent += OnRefreshEvent;
|
||||
|
||||
InitializeTipoSimulableList();
|
||||
|
||||
|
@ -143,11 +144,7 @@ namespace CtrEditor
|
|||
{
|
||||
|
||||
foreach (var objetoSimulable in ObjetosSimulables)
|
||||
{
|
||||
if (_plcViewModelData.IsConnected)
|
||||
objetoSimulable.UpdatePLC(_plcViewModelData.PLCInterface);
|
||||
objetoSimulable.UpdateGeometryStep();
|
||||
}
|
||||
|
||||
simulationManager.Step();
|
||||
|
||||
|
@ -156,6 +153,15 @@ namespace CtrEditor
|
|||
|
||||
}
|
||||
|
||||
private void OnRefreshEvent(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var objetoSimulable in ObjetosSimulables)
|
||||
{
|
||||
if (_plcViewModelData.IsConnected)
|
||||
objetoSimulable.UpdatePLC(_plcViewModelData.PLCInterface);
|
||||
}
|
||||
}
|
||||
|
||||
//protected virtual void OnTickSimulacion(TickSimulacionEventArgs e)
|
||||
//{
|
||||
// TickSimulacion?.Invoke(this, e);
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:Siemens="clr-namespace:CtrEditor.Siemens" x:Class="CtrEditor.MainWindow"
|
||||
xmlns:Siemens="clr-namespace:CtrEditor.Siemens"
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
|
||||
xmlns:ObjetosSim="clr-namespace:CtrEditor.ObjetosSim" x:Class="CtrEditor.MainWindow"
|
||||
Height="900" Width="1600"
|
||||
ResizeMode="CanResize" Title="{Binding directorioTrabajo}">
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
|||
using TextBox = System.Windows.Controls.TextBox;
|
||||
using UserControl = System.Windows.Controls.UserControl;
|
||||
using CheckBox = System.Windows.Controls.CheckBox;
|
||||
using Orientation = System.Windows.Controls.Orientation;
|
||||
//using OpenCvSharp;
|
||||
|
||||
|
||||
|
@ -417,13 +418,25 @@ namespace CtrEditor
|
|||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
var horizontalPanel = new StackPanel { Orientation = Orientation.Horizontal };
|
||||
var grid = new Grid();
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
||||
|
||||
var label = new Label { Content = property.Name };
|
||||
var label = new Label
|
||||
{
|
||||
Content = property.Name + ":",
|
||||
Margin = new Thickness(0, 0, 5, 0),
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
if (property.PropertyType == typeof(float) || property.PropertyType == typeof(string) || property.PropertyType == typeof(int))
|
||||
{
|
||||
var textBox = new TextBox { Width = 200, Margin = new Thickness(0) };
|
||||
var textBox = new TextBox
|
||||
{
|
||||
Margin = new Thickness(0),
|
||||
MinWidth = 200,
|
||||
VerticalContentAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
|
@ -432,7 +445,6 @@ namespace CtrEditor
|
|||
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
|
||||
};
|
||||
|
||||
// Aplicar el convertidor solo a propiedades float
|
||||
if (property.PropertyType == typeof(float))
|
||||
{
|
||||
binding.Converter = (FloatToFormattedStringConverter)Resources["floatFormatter"];
|
||||
|
@ -440,12 +452,19 @@ namespace CtrEditor
|
|||
|
||||
textBox.SetBinding(TextBox.TextProperty, binding);
|
||||
|
||||
horizontalPanel.Children.Add(label);
|
||||
horizontalPanel.Children.Add(textBox);
|
||||
Grid.SetColumn(label, 0);
|
||||
Grid.SetColumn(textBox, 1);
|
||||
|
||||
grid.Children.Add(label);
|
||||
grid.Children.Add(textBox);
|
||||
}
|
||||
else if (property.PropertyType == typeof(bool))
|
||||
{
|
||||
var checkBox = new CheckBox { Margin = new Thickness(5, 0, 0, 0) };
|
||||
var checkBox = new CheckBox
|
||||
{
|
||||
Margin = new Thickness(5, 0, 0, 0),
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
var binding = new Binding(property.Name)
|
||||
{
|
||||
|
@ -455,17 +474,17 @@ namespace CtrEditor
|
|||
|
||||
checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
|
||||
|
||||
horizontalPanel.Children.Add(label);
|
||||
horizontalPanel.Children.Add(checkBox);
|
||||
Grid.SetColumn(label, 0);
|
||||
Grid.SetColumn(checkBox, 1);
|
||||
|
||||
grid.Children.Add(label);
|
||||
grid.Children.Add(checkBox);
|
||||
}
|
||||
|
||||
PanelEdicion.Children.Add(horizontalPanel);
|
||||
PanelEdicion.Children.Add(grid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void MainWindow_Closed(object sender, EventArgs e)
|
||||
{
|
||||
if (DataContext is MainViewModel viewModel)
|
||||
|
|
|
@ -25,6 +25,8 @@ namespace CtrEditor.ObjetosSim
|
|||
// return new ucTransporteCurva();
|
||||
if (tipoObjeto == typeof(osVMmotorSim ))
|
||||
return new ucVMmotorSim();
|
||||
if (tipoObjeto == typeof(osBoton))
|
||||
return new ucBoton();
|
||||
|
||||
// Puedes añadir más condiciones para otros tipos
|
||||
|
||||
|
@ -45,6 +47,8 @@ namespace CtrEditor.ObjetosSim
|
|||
// return new osTransporteCurva();
|
||||
if (tipoObjeto == typeof(osVMmotorSim))
|
||||
return new osVMmotorSim();
|
||||
if (tipoObjeto == typeof(osBoton))
|
||||
return new osBoton();
|
||||
|
||||
|
||||
// Puedes añadir más condiciones para otros tipos
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetosSim.ucBoton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:ei="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<UserControl.Resources>
|
||||
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Rectangle x:Name="BackgroundRectangle"
|
||||
Fill="LightGray"
|
||||
Width="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Height="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=1.5}"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
/>
|
||||
<Button Content="Button"
|
||||
Width="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Height="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
|
||||
Background="{Binding Color}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Bottom"
|
||||
MouseLeftButtonDown="Button_MouseLeftButtonDown"
|
||||
MouseLeftButtonUp="Button_MouseLeftButtonUp">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="MouseLeftButtonDown">
|
||||
<ei:InvokeCommandAction Command="{Binding ButtonDownCommand}" />
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="MouseLeftButtonUp">
|
||||
<ei:InvokeCommandAction Command="{Binding ButtonUpCommand}" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Button.Template>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Grid>
|
||||
<Ellipse Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="2"/>
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Button.Template>
|
||||
</Button>
|
||||
</Grid>
|
||||
</UserControl>
|
|
@ -0,0 +1,216 @@
|
|||
using CtrEditor.Convertidores;
|
||||
using CtrEditor.Siemens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ucBoton.xaml
|
||||
/// </summary>
|
||||
public class osBoton : osBase
|
||||
{
|
||||
// Otros datos y métodos relevantes para la simulación
|
||||
|
||||
private string _nombre = "Boton";
|
||||
private float _tamano;
|
||||
private float _left;
|
||||
private float _top;
|
||||
private bool _estado;
|
||||
private string _tag;
|
||||
|
||||
private Brush _color;
|
||||
public Brush Color
|
||||
{
|
||||
get => _color;
|
||||
set
|
||||
{
|
||||
_color = value;
|
||||
OnPropertyChanged(nameof(Color));
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand ButtonClickCommand { get; }
|
||||
public ICommand ButtonDownCommand { get; }
|
||||
public ICommand ButtonUpCommand { get; }
|
||||
|
||||
public override float Left
|
||||
{
|
||||
get => _left;
|
||||
set
|
||||
{
|
||||
_left = value;
|
||||
CanvasSetLeftinMeter(value);
|
||||
OnPropertyChanged(nameof(Left));
|
||||
}
|
||||
}
|
||||
public override float Top
|
||||
{
|
||||
get => _top;
|
||||
set
|
||||
{
|
||||
_top = value;
|
||||
CanvasSetTopinMeter(value);
|
||||
OnPropertyChanged(nameof(Top));
|
||||
}
|
||||
}
|
||||
public float Tamano
|
||||
{
|
||||
get => _tamano;
|
||||
set
|
||||
{
|
||||
_tamano = value;
|
||||
OnPropertyChanged(nameof(Tamano));
|
||||
}
|
||||
}
|
||||
public bool Estado
|
||||
{
|
||||
get => _estado;
|
||||
set
|
||||
{
|
||||
_estado = value;
|
||||
OnPropertyChanged(nameof(Estado));
|
||||
}
|
||||
}
|
||||
|
||||
public override string Nombre
|
||||
{
|
||||
get => _nombre;
|
||||
set
|
||||
{
|
||||
if (_nombre != value)
|
||||
{
|
||||
_nombre = value;
|
||||
OnPropertyChanged(nameof(Nombre));
|
||||
}
|
||||
}
|
||||
}
|
||||
public string Tag
|
||||
{
|
||||
get => _tag;
|
||||
set
|
||||
{
|
||||
if (_tag != value)
|
||||
{
|
||||
_tag = value;
|
||||
OnPropertyChanged(nameof(Tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnButtonClick()
|
||||
{
|
||||
// Handle the click event here
|
||||
// Example: Change color on click
|
||||
Color = Brushes.LightGreen;
|
||||
|
||||
}
|
||||
|
||||
private void OnButtonDown()
|
||||
{
|
||||
Estado = true;
|
||||
}
|
||||
|
||||
private void OnButtonUp()
|
||||
{
|
||||
Estado = false;
|
||||
}
|
||||
|
||||
public osBoton()
|
||||
{
|
||||
Tamano = 0.30f;
|
||||
Estado = false;
|
||||
Tag = "M50.0";
|
||||
// Set initial color
|
||||
Color = Brushes.LightBlue;
|
||||
|
||||
// Initialize the command
|
||||
ButtonClickCommand = new RelayCommand(OnButtonClick);
|
||||
ButtonDownCommand = new RelayCommand(OnButtonDown);
|
||||
ButtonUpCommand = new RelayCommand(OnButtonUp);
|
||||
}
|
||||
|
||||
public override void UpdateGeometryStart()
|
||||
{
|
||||
// Se llama antes de la simulacion
|
||||
|
||||
}
|
||||
public override void UpdateGeometryStep()
|
||||
{
|
||||
}
|
||||
public override void UpdatePLC(PLCModel plc)
|
||||
{
|
||||
plc.EscribirTagBool(Tag, Estado);
|
||||
}
|
||||
|
||||
public override void UpdateControl()
|
||||
{
|
||||
|
||||
}
|
||||
public override void ucLoaded()
|
||||
{
|
||||
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
||||
// crear el objeto de simulacion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class ucBoton : UserControl, IDataContainer
|
||||
{
|
||||
public osBase? Datos { get; set; }
|
||||
|
||||
public ucBoton()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Loaded += OnLoaded;
|
||||
}
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Datos?.ucLoaded();
|
||||
}
|
||||
private void Button_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Datos is osBoton osBotonData)
|
||||
{
|
||||
osBotonData.ButtonDownCommand.Execute(null);
|
||||
Mouse.Capture((UIElement)sender);
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Datos is osBoton osBotonData)
|
||||
{
|
||||
osBotonData.ButtonUpCommand.Execute(null);
|
||||
Mouse.Capture(null); // Release mouse capture
|
||||
}
|
||||
}
|
||||
public void Resize(float width, float 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) { }
|
||||
public void Highlight(bool State) { }
|
||||
public int ZIndex()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,8 @@ namespace CtrEditor.Siemens
|
|||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public event EventHandler RefreshEvent;
|
||||
|
||||
public PLCViewModel()
|
||||
{
|
||||
IsConnected = false;
|
||||
|
@ -119,7 +121,6 @@ namespace CtrEditor.Siemens
|
|||
private void Instance_OnSoftwareConfigurationChanged(IInstance instance, SOnSoftwareConfigChangedParameter event_param)
|
||||
{
|
||||
PLCInterface.UpdateTagList();
|
||||
|
||||
}
|
||||
|
||||
private void Disconnect()
|
||||
|
@ -134,10 +135,12 @@ namespace CtrEditor.Siemens
|
|||
{
|
||||
if (PLCInterface.Instance != null)
|
||||
{
|
||||
|
||||
CpuTime = PLCInterface.LeerTagInt16("\"DB HMI\".CPU_Scan_Time")?.ToString() ?? "N/A";
|
||||
CpuTime = PLCInterface.LeerTagInt16("\"DB HMI\".CPU_Scan_Time")?.ToString() ?? "N/A";
|
||||
LastError = PLCInterface.LastError;
|
||||
}
|
||||
|
||||
// Disparar el evento RefreshEvent
|
||||
RefreshEvent?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
|
|
Loading…
Reference in New Issue