Estado inicial

This commit is contained in:
Miguel 2024-05-02 16:06:45 +02:00
parent ed7ed0c036
commit a0de744182
14 changed files with 412 additions and 12 deletions

View File

@ -4,6 +4,6 @@
xmlns:local="clr-namespace:CtrEditor" xmlns:local="clr-namespace:CtrEditor"
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
</Application.Resources> </Application.Resources>
</Application> </Application>

View File

@ -4,11 +4,12 @@ using System.Windows;
namespace CtrEditor namespace CtrEditor
{ {
/// <summary> public partial class App : System.Windows.Application
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{ {
public App()
{
InitializeComponent();
}
}
} }
}

View File

@ -8,4 +8,9 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
</ItemGroup>
</Project> </Project>

96
MainViewModel.cs Normal file
View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using Ookii.Dialogs.Wpf;
using System.Windows.Input;
namespace CtrEditor
{
public class MainViewModel : INotifyPropertyChanged
{
private double _zoomFactor = 1.0;
private string _directorioTrabajo;
public MainViewModel()
{
OpenWorkDirectoryCommand = new RelayCommand(OpenWorkDirectory);
LoadImageCommand = new RelayCommand(LoadImage);
}
public string DirectorioTrabajo
{
get => _directorioTrabajo;
set
{
_directorioTrabajo = value;
OnPropertyChanged(nameof(DirectorioTrabajo)); // Notificar el cambio de propiedad
EstadoPersistente.Instance.DirectorioTrabajo = value; // Actualizar el estado persistente
EstadoPersistente.Instance.GuardarEstado(); // Guardar el estado actualizado
}
}
public ICommand OpenWorkDirectoryCommand { get; }
private void OpenWorkDirectory()
{
var dialog = new VistaFolderBrowserDialog();
if (dialog.ShowDialog() == true) // Mostrar el diálogo y comprobar si el resultado es positivo
{
DirectorioTrabajo = dialog.SelectedPath; // Actualizar la propiedad que también actualiza el estado persistente
}
}
// Ejemplo de propiedad para gestionar el UserControl activo
private UserControl _activeControl;
public UserControl ActiveControl
{
get => _activeControl;
set { _activeControl = value; OnPropertyChanged(); }
}
// Comando para cargar una imagen
public ICommand LoadImageCommand { get; private set; }
private void LoadImage()
{
// Implementar lógica de carga de imagen
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public double ZoomFactor
{
get => _zoomFactor;
set { _zoomFactor = value; OnPropertyChanged(); }
}
private double _offsetX = 0;
private double _offsetY = 0;
public double OffsetX
{
get => _offsetX;
set { _offsetX = value; OnPropertyChanged(); }
}
public double OffsetY
{
get => _offsetY;
set { _offsetY = value; OnPropertyChanged(); }
}
// Implementación de INotifyPropertyChanged...
}
}

View File

@ -1,12 +1,77 @@
<Window x:Class="CtrEditor.MainWindow" <Window x:Class="CtrEditor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" Height="450" Width="800"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" ResizeMode="CanResize" Title="C:/">
xmlns:local="clr-namespace:CtrEditor"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid>
<!-- Menú Principal sobre toda la ventana -->
<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="Guardar" Command="{Binding SaveCommand}" />
<MenuItem Header="Salir" Command="{Binding ExitCommand}" />
</MenuItem>
</Menu>
<Grid Margin="0,20,0,0">
<!-- Margen superior para el menú -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<!-- Primera Columna -->
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<ListBox x:Name="ListaImagenes" Grid.Row="0" Margin="5" ItemsSource="{Binding ImageList}" SelectedItem="{Binding SelectedImage}" />
<ListBox x:Name="ListaFunciones" Grid.Row="1" Margin="5"/>
</Grid>
<!-- 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 Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Canvas x:Name="ImagenEnTrabajoCanvas" Background="Beige" Margin="5">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding ZoomFactor}" ScaleY="{Binding ZoomFactor}"/>
<TranslateTransform X="{Binding OffsetX}" Y="{Binding OffsetY}"/>
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
</ScrollViewer>
</Grid>
<!-- Tercera Columna -->
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<ListBox x:Name="ListaROIs" Grid.Row="0" Margin="5"/>
<StackPanel x:Name="PanelEdicion" Grid.Row="1" Margin="5">
<!-- Aquí puedes agregar los controles para editar propiedades -->
</StackPanel>
</Grid>
</Grid>
</Grid> </Grid>
</Window> </Window>

View File

@ -20,5 +20,7 @@ namespace CtrEditor
{ {
InitializeComponent(); InitializeComponent();
} }
} }
} }

View File

@ -0,0 +1,6 @@
<UserControl x:Class="CtrEditor.ObjetoSimuladoBotella"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="100" Height="300">
<Border Background="Brown" CornerRadius="10" Height="10" Width="10"/>
</UserControl>

View File

@ -0,0 +1,28 @@
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
{
/// <summary>
/// Interaction logic for ObjetoSimuladoBotella.xaml
/// </summary>
public partial class ObjetoSimuladoBotella : UserControl
{
public ObjetoSimuladoBotella()
{
InitializeComponent();
}
}
}

6
ObjetoSimuladoPack.xaml Normal file
View File

@ -0,0 +1,6 @@
<UserControl x:Class="CtrEditor.ObjetoSimuladoPack"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="150">
<Border Background="Gray" CornerRadius="2" Height="10" Width="10"/>
</UserControl>

View File

@ -0,0 +1,28 @@
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
{
/// <summary>
/// Interaction logic for ObjetoSimuladoPack.xaml
/// </summary>
public partial class ObjetoSimuladoPack : UserControl
{
public ObjetoSimuladoPack()
{
InitializeComponent();
}
}
}

42
RelayCommand.cs Normal file
View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace CtrEditor
{
public class RelayCommand : ICommand
{
private readonly Action _execute;
private readonly Func<bool> _canExecute;
public RelayCommand(Action execute, Func<bool> canExecute = null)
{
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute == null || _canExecute();
}
public void Execute(object parameter)
{
_execute();
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void RaiseCanExecuteChanged()
{
CommandManager.InvalidateRequerySuggested();
}
}
}

24
SimulationState.cs Normal file
View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CtrEditor
{
public class SimulationState
{
// public List<SimulatedObject> Objects { get; set; } = new List<SimulatedObject>();
public void SaveState(string path)
{
// Serializar estado a JSON
}
public void LoadState(string path)
{
// Deserializar estado desde JSON
}
}
}

29
SimulationViewModel.cs Normal file
View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CtrEditor
{
//public class SimulationViewModel : INotifyPropertyChanged
//{
// private ObservableCollection<UserControl> _simulatedObjects;
// public ObservableCollection<UserControl> SimulatedObjects
// {
// get => _simulatedObjects;
// set { _simulatedObjects = value; OnPropertyChanged(); }
// }
// public SimulationViewModel()
// {
// SimulatedObjects = new ObservableCollection<UserControl>
// {
// new ObjetoSimuladoBotella(), // Suponiendo que estos controles no requieren parámetros en el constructor
// new ObjetoSimuladoPack()
// };
// }
// // Implementación de INotifyPropertyChanged aquí
//}
}

68
estadoPersistente.cs Normal file
View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System;
using System.IO;
namespace CtrEditor
{
internal class EstadoPersistente
{
// Ruta donde se guardará el estado
private static readonly string _filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "estado.json");
// Instancia privada estática, parte del patrón Singleton
private static EstadoPersistente _instance;
// Propiedad privada para el directorio de trabajo
private string _strDirectorioTrabajo;
// Propiedad pública con get y set para controlar el acceso a _strDirectorioTrabajo
public string DirectorioTrabajo
{
get { return _strDirectorioTrabajo; }
set { _strDirectorioTrabajo = value; }
}
// Constructor privado para evitar la instanciación externa
private EstadoPersistente()
{
_strDirectorioTrabajo = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
}
// Propiedad pública estática para acceder a la instancia
public static EstadoPersistente Instance
{
get
{
if (_instance == null)
{
_instance = CargarEstado();
}
return _instance;
}
}
// Método para guardar el estado en un archivo JSON
public void GuardarEstado()
{
string json = JsonConvert.SerializeObject(this);
File.WriteAllText(_filePath, json);
}
// Método estático para cargar el estado desde un archivo JSON
private static EstadoPersistente CargarEstado()
{
if (File.Exists(_filePath))
{
string json = File.ReadAllText(_filePath);
return JsonConvert.DeserializeObject<EstadoPersistente>(json);
}
return new EstadoPersistente(); // Devuelve una nueva instancia si no existe el archivo
}
}
}