79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
|
|
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();
|
|
|
|
// 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();
|
|
|
|
|
|
// 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, SimulationManager simulationManager)
|
|
{
|
|
if (userControl is IDataContainer dataContainer)
|
|
{
|
|
dataContainer.Datos = datos;
|
|
userControl.DataContext = datos;
|
|
datos.VisualRepresentation = userControl;
|
|
datos.ConnectSimManager(simulationManager);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|