using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using CtrEditor.Simulacion; namespace CtrEditor.ObjetosSim { public static class UserControlFactory { public static UserControl? GetControlForType(Type tipoObjeto) { if (tipoObjeto == typeof(osBotella)) return new ucBotella(); if (tipoObjeto == typeof(osTransporteTTop)) return new ucTransporteTTop(); if (tipoObjeto == typeof(osGuia)) return new ucGuia(); if (tipoObjeto == typeof(osTransporteGuias)) return new ucTransporteGuias(); //if (tipoObjeto == typeof(osTransporteCurva)) // return new ucTransporteCurva(); if (tipoObjeto == typeof(osVMmotorSim )) return new ucVMmotorSim(); if (tipoObjeto == typeof(osBoton)) return new ucBoton(); if (tipoObjeto == typeof(osTanque)) return new ucTanque(); // Puedes añadir más condiciones para otros tipos return null; } public static osBase? GetInstanceForType(Type tipoObjeto) { if (tipoObjeto == typeof(osBotella)) return new osBotella(); if (tipoObjeto == typeof(osTransporteTTop)) return new osTransporteTTop(); if (tipoObjeto == typeof(osGuia)) return new osGuia(); if (tipoObjeto == typeof(osTransporteGuias)) return new osTransporteGuias(); //if (tipoObjeto == typeof(osTransporteCurva)) // return new osTransporteCurva(); if (tipoObjeto == typeof(osVMmotorSim)) return new osVMmotorSim(); if (tipoObjeto == typeof(osBoton)) return new osBoton(); if (tipoObjeto == typeof(osTanque)) return new osTanque(); // Puedes añadir más condiciones para otros tipos return null; } public static osBase? CreateInstanceAndPopulate(Type tipoObjeto, string jsonString) { osBase? instance = GetInstanceForType(tipoObjeto); if (instance != null) { // Deserializa los datos desde jsonString y popula la instancia JsonConvert.PopulateObject(jsonString, instance); } return instance; } public static void AssignDatos(UserControl userControl, osBase datos, SimulationManagerFP simulationManager) { if (userControl is IDataContainer dataContainer) { dataContainer.Datos = datos; userControl.DataContext = datos; datos.VisualRepresentation = userControl; datos.simulationManager = simulationManager; } } } }