From 10ceff7c70b304e0f057cdff7ae4ba141c266658 Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 11 Apr 2024 11:51:12 +0200 Subject: [PATCH] Add project files. --- App.xaml | 9 + App.xaml.cs | 14 ++ AssemblyInfo.cs | 10 + DatabaseManager.cs | 113 +++++++++++ ImagenEstado.cs | 81 ++++++++ MainWindow.xaml | 89 ++++++++ MainWindow.xaml.cs | 490 +++++++++++++++++++++++++++++++++++++++++++++ ROI.cs | 229 +++++++++++++++++++++ ROIEditor.csproj | 16 ++ ROIEditor.sln | 25 +++ roiseditor.db | Bin 0 -> 12288 bytes roiseditor.sqbpro | 14 ++ 12 files changed, 1090 insertions(+) create mode 100644 App.xaml create mode 100644 App.xaml.cs create mode 100644 AssemblyInfo.cs create mode 100644 DatabaseManager.cs create mode 100644 ImagenEstado.cs create mode 100644 MainWindow.xaml create mode 100644 MainWindow.xaml.cs create mode 100644 ROI.cs create mode 100644 ROIEditor.csproj create mode 100644 ROIEditor.sln create mode 100644 roiseditor.db create mode 100644 roiseditor.sqbpro diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..fe3cec2 --- /dev/null +++ b/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..723039d --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace ROIEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } + +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/DatabaseManager.cs b/DatabaseManager.cs new file mode 100644 index 0000000..c0a5989 --- /dev/null +++ b/DatabaseManager.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text.Json; +using Microsoft.Data.Sqlite; +using System.ComponentModel; + +namespace ROIEditor +{ + + public class DatabaseManager + { + private readonly string connectionString; + private readonly string tableName; + private List data = new List(); + + public void Add(T item) + { + data.Add(item); + } + + public void Clear() + { + data.Clear(); + } + + public List GetList() + { + return data; + } + + public int Count => data.Count; + + public DatabaseManager(string dbPath, string tableName) + { + connectionString = $"Data Source={dbPath}"; + this.tableName = tableName; + InitializeDatabase(); + } + + private void InitializeDatabase() + { + using (var connection = new SqliteConnection(connectionString)) + { + connection.Open(); + + var command = connection.CreateCommand(); + command.CommandText = $@" + CREATE TABLE IF NOT EXISTS {tableName} ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + Clave TEXT, + SerializeData TEXT + )"; + command.ExecuteNonQuery(); + } + } + + public void SaveData(string clave) + { + + using (var connection = new SqliteConnection(connectionString)) + { + connection.Open(); + + var deleteCommand = connection.CreateCommand(); + deleteCommand.CommandText = @"DELETE FROM Roi WHERE Clave = $Clave"; + deleteCommand.Parameters.AddWithValue("$Clave", clave); + deleteCommand.ExecuteNonQuery(); + + foreach (var elemento in data) + { + string serializedData = JsonSerializer.Serialize(elemento); + + var command = connection.CreateCommand(); + command.CommandText = $"INSERT INTO {tableName} (Clave, SerializeData) VALUES ($Clave, $SerializedData)"; + command.Parameters.AddWithValue("$Clave", clave); + command.Parameters.AddWithValue("$SerializedData", serializedData); + command.ExecuteNonQuery(); + } + } + } + + public List LoadData(string clave) + { + var dataList = new List(); + + using (var connection = new SqliteConnection(connectionString)) + { + connection.Open(); + + var command = connection.CreateCommand(); + command.CommandText = $"SELECT SerializeData FROM {tableName} WHERE Clave = $Clave"; + command.Parameters.AddWithValue("$Clave", clave); + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + string serializedData = reader.GetString(0); + List data = JsonSerializer.Deserialize>(serializedData); + dataList.AddRange(data); + } + } + } + + return dataList; + } + } + +} diff --git a/ImagenEstado.cs b/ImagenEstado.cs new file mode 100644 index 0000000..ba19995 --- /dev/null +++ b/ImagenEstado.cs @@ -0,0 +1,81 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace ROIEditor +{ + public class ImagenEstado + { + public double ZoomScaleX { get; set; } + public double ZoomScaleY { get; set; } + public double HorizontalOffset { get; set; } + public double VerticalOffset { get; set; } + public string NombreImagen; + + + // Constructor sin parámetros + public ImagenEstado() + { + + } + public ImagenEstado(string imageNameActual) + { + NombreImagen = imageNameActual; + + } + + public string PathPlantillasJson() + { + string jsonPath = Path.ChangeExtension(NombreImagen, ".json"); + var imagePath = Path.Combine(Directory.GetCurrentDirectory(), "Plantillas", jsonPath); + return imagePath; + } + public string PathPlantillasPNG() + { + string jsonPath = Path.ChangeExtension(NombreImagen, ".png"); + var imagePath = Path.Combine(Directory.GetCurrentDirectory(), "Plantillas", jsonPath); + return imagePath; + } + + public void SalvarEstadoJSON() + { + // Cambia la extensión del archivo de imagen a .json + string jsonPath = PathPlantillasJson(); + + // Serializa el estado de la imagen a JSON + string json = JsonConvert.SerializeObject(NombreImagen, Formatting.Indented); + + // Escribe el JSON en un archivo + File.WriteAllText(jsonPath, json); + } + + public void CargarEstadoJSON() + { + string jsonPath = PathPlantillasJson(); + + if (File.Exists(jsonPath)) + { + string json = File.ReadAllText(jsonPath); + ImagenEstado estadoCargado = JsonConvert.DeserializeObject(json); + + // Usar reflexión para copiar todas las propiedades + foreach (PropertyInfo prop in typeof(ImagenEstado).GetProperties()) + { + if (prop.CanRead && prop.CanWrite) + { + prop.SetValue(this, prop.GetValue(estadoCargado, null), null); + } + } + } + } + + + } + +} diff --git a/MainWindow.xaml b/MainWindow.xaml new file mode 100644 index 0000000..130232b --- /dev/null +++ b/MainWindow.xaml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + +