Terminado el timer
This commit is contained in:
parent
1e30f00c57
commit
101a65ad27
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CtrEditor
|
||||
{
|
||||
public interface ICtrSimulado
|
||||
{
|
||||
string Nombre { get; }
|
||||
void Update();
|
||||
// other common methods and properties
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using CtrEditor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
@ -12,26 +13,71 @@ using System.Windows.Input;
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace CtrEditor
|
||||
{
|
||||
|
||||
public class TickSimulacionEventArgs : EventArgs
|
||||
{
|
||||
// Aquí puedes agregar propiedades o campos para pasar información adicional
|
||||
// en el evento TickSimulacion
|
||||
}
|
||||
|
||||
public class MainViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public DatosDeTrabajo datosDeTrabajo { get; }
|
||||
public ObservableCollection<string> listaImagenes { get; private set; } // Publicación de las claves del diccionario
|
||||
private ObservableCollection<ICtrSimulado> _funciones;
|
||||
private readonly DispatcherTimer _timerSimulacion;
|
||||
private string _selectedImage;
|
||||
|
||||
// Evento que se dispara cuando se selecciona una nueva imagen
|
||||
public event EventHandler<string> ImageSelected;
|
||||
public event EventHandler<TickSimulacionEventArgs> TickSimulacion;
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
OpenWorkDirectoryCommand = new RelayCommand(OpenWorkDirectory);
|
||||
datosDeTrabajo = new DatosDeTrabajo();
|
||||
listaImagenes = new ObservableCollection<string>(datosDeTrabajo.Imagenes.Keys);
|
||||
_funciones = new ObservableCollection<ICtrSimulado>();
|
||||
_funciones.Add(new OSBotella());
|
||||
_funciones.Add(new OSPack());
|
||||
directorioTrabajo = EstadoPersistente.Instance.directorio;
|
||||
|
||||
_timerSimulacion = new DispatcherTimer();
|
||||
_timerSimulacion.Interval = TimeSpan.FromMilliseconds(100); // ajusta el intervalo según sea necesario
|
||||
_timerSimulacion.Tick += OnTickSimulacion;
|
||||
|
||||
StartSimulationCommand = new RelayCommand(StartSimulation);
|
||||
StopSimulationCommand = new RelayCommand(StopSimulation);
|
||||
}
|
||||
|
||||
public ICommand StartSimulationCommand { get; }
|
||||
public ICommand StopSimulationCommand { get; }
|
||||
|
||||
private void StartSimulation()
|
||||
{
|
||||
_timerSimulacion.Start();
|
||||
}
|
||||
|
||||
private void StopSimulation()
|
||||
{
|
||||
_timerSimulacion.Stop();
|
||||
}
|
||||
|
||||
private void OnTickSimulacion(object sender, EventArgs e)
|
||||
{
|
||||
var args = new TickSimulacionEventArgs();
|
||||
OnTickSimulacion(args);
|
||||
}
|
||||
|
||||
protected virtual void OnTickSimulacion(TickSimulacionEventArgs e)
|
||||
{
|
||||
TickSimulacion?.Invoke(this, e);
|
||||
}
|
||||
|
||||
public string directorioTrabajo
|
||||
{
|
||||
|
@ -50,6 +96,12 @@ namespace CtrEditor
|
|||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<ICtrSimulado> CtrSimulado
|
||||
{
|
||||
get { return _funciones; }
|
||||
set { _funciones = value; }
|
||||
}
|
||||
|
||||
public string SelectedImage
|
||||
{
|
||||
get => _selectedImage;
|
||||
|
@ -84,6 +136,7 @@ namespace CtrEditor
|
|||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
<Menu VerticalAlignment="Top" HorizontalAlignment="Stretch">
|
||||
<MenuItem Header="Projecto">
|
||||
<MenuItem Header="Abrir Directorio de trabajo" Command="{Binding OpenWorkDirectoryCommand}" />
|
||||
<MenuItem Header="Iniciar Simulacion" Command="{Binding RunSimCommand}" />
|
||||
<MenuItem Header="Detenet Simulacion" Command="{Binding StopSimCommand}" />
|
||||
<MenuItem Header="Iniciar Simulacion" Command="{Binding StartSimulationCommand}" />
|
||||
<MenuItem Header="Detenet Simulacion" Command="{Binding StopSimulationCommand}" />
|
||||
<MenuItem Header="Guardar" Command="{Binding SaveCommand}" />
|
||||
<MenuItem Header="Salir" Command="{Binding ExitCommand}" />
|
||||
</MenuItem>
|
||||
|
@ -23,9 +23,9 @@
|
|||
<Grid Margin="0,20,0,0">
|
||||
<!-- Margen superior para el menú -->
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="1*" MinWidth="100"/>
|
||||
<ColumnDefinition Width="4*" MinWidth="200"/>
|
||||
<ColumnDefinition Width="1*" MinWidth="100"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Primera Columna -->
|
||||
|
@ -35,23 +35,13 @@
|
|||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox x:Name="ListaImagenes" Grid.Row="0" Margin="5" ItemsSource="{Binding listaImagenes}" SelectedItem="{Binding SelectedImage}" />
|
||||
<ListBox x:Name="ListaFunciones" Grid.Row="1" Margin="5"/>
|
||||
<ListBox x:Name="ListaFunciones" Grid.Row="1" Margin="5" ItemsSource="{Binding CtrSimulado}" DisplayMemberPath="Nombre"/>
|
||||
</Grid>
|
||||
<!-- GridSplitter -->
|
||||
<GridSplitter Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" Width="5" Background="LightGray" />
|
||||
|
||||
<!-- Segunda Columna -->
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<!-- Espacio para el menú -->
|
||||
<RowDefinition Height="*"/>
|
||||
<!-- Espacio restante para el Canvas -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Menu Grid.Row="0" Height="20" VerticalAlignment="Top">
|
||||
<MenuItem Header="Nuevo"/>
|
||||
<MenuItem Header="Eliminar"/>
|
||||
</Menu>
|
||||
|
||||
<ScrollViewer x:Name="ImagenEnTrabajoScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" PanningMode="Both">
|
||||
<Canvas x:Name="ImagenEnTrabajoCanvas" Margin="200">
|
||||
<!-- El Margin puede ser ajustado según el espacio adicional que quieras proporcionar -->
|
||||
|
@ -62,6 +52,8 @@
|
|||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<!-- GridSplitter -->
|
||||
<GridSplitter Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right" Width="5" Background="LightGray" />
|
||||
|
||||
<!-- Tercera Columna -->
|
||||
<Grid Grid.Column="2">
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace CtrEditor
|
|||
if (DataContext is MainViewModel viewModel)
|
||||
{
|
||||
viewModel.ImageSelected += ViewModel_ImageSelected;
|
||||
viewModel.TickSimulacion += MainViewModel_TickSimulacion;
|
||||
}
|
||||
}
|
||||
private void ViewModel_ImageSelected(object sender, string imagePath)
|
||||
|
@ -139,6 +140,20 @@ namespace CtrEditor
|
|||
e.Handled = true; // Evita el procesamiento adicional del evento
|
||||
}
|
||||
|
||||
private void MainViewModel_TickSimulacion(object sender, TickSimulacionEventArgs e)
|
||||
{
|
||||
// aquí puedes agregar la lógica para actualizar tus UserControl
|
||||
// en el ImagenEnTrabajoCanvas
|
||||
foreach (var child in ImagenEnTrabajoCanvas.Children)
|
||||
{
|
||||
if (child is ICtrSimulado uc)
|
||||
{
|
||||
// llama al método Update de cada UserControl
|
||||
uc.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MainWindow_Closed(object sender, EventArgs e)
|
||||
{
|
||||
if (DataContext is MainViewModel viewModel)
|
||||
|
|
|
@ -18,12 +18,17 @@ namespace CtrEditor
|
|||
/// <summary>
|
||||
/// Interaction logic for ObjetoSimuladoBotella.xaml
|
||||
/// </summary>
|
||||
public partial class ObjetoSimuladoBotella : UserControl
|
||||
public partial class OSBotella : UserControl, ICtrSimulado
|
||||
{
|
||||
public ObjetoSimuladoBotella()
|
||||
public OSBotella()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public string Nombre => "Botellas";
|
||||
public void Update()
|
||||
{
|
||||
// implementation of Update method
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetoSimuladoBotella"
|
||||
<UserControl x:Class="CtrEditor.OSBotella"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Width="100" Height="300">
|
|
@ -1,4 +1,4 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetoSimuladoPack"
|
||||
<UserControl x:Class="CtrEditor.OSPack"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Width="200" Height="150">
|
|
@ -18,12 +18,17 @@ namespace CtrEditor
|
|||
/// <summary>
|
||||
/// Interaction logic for ObjetoSimuladoPack.xaml
|
||||
/// </summary>
|
||||
public partial class ObjetoSimuladoPack : UserControl
|
||||
public partial class OSPack : UserControl, ICtrSimulado
|
||||
{
|
||||
public ObjetoSimuladoPack()
|
||||
public OSPack()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public string Nombre => "Packs";
|
||||
public void Update()
|
||||
{
|
||||
// implementation of Update method
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue