Compare commits

...

2 Commits

23 changed files with 464 additions and 45 deletions

View File

@ -10,6 +10,22 @@ using System.Windows.Media;
namespace CtrEditor.Convertidores namespace CtrEditor.Convertidores
{ {
public class HalfWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double width)
{
return (width / 2.0) - (double.Parse(parameter.ToString()) / 2.0);
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class WidthPercentageConverter : IValueConverter public class WidthPercentageConverter : IValueConverter
{ {
@ -107,24 +123,55 @@ namespace CtrEditor.Convertidores
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
float meters = (float)value; if (value == null) return 0; // Aseguramos que el valor no sea nulo
float factor = 1;
if (parameter != null)
if (parameter.ToString() == "0.5") factor = 0.5f;
else if (parameter.ToString() == "-0.5") factor = -0.5f;
else if (parameter.ToString() == "1.5") factor = 1.5f;
// Convertimos el valor de entrada en un número flotante
float meters = System.Convert.ToSingle(value);
float factor = 1; // Valor por defecto del factor
// Si el parámetro no es nulo, intentamos convertirlo a float
if (parameter != null)
{
string paramStr = parameter.ToString();
// Normalizamos el parámetro para asegurar que el punto sea el separador decimal
paramStr = paramStr.Replace(',', '.');
// Utilizamos CultureInfo.InvariantCulture para evitar problemas con el separador decimal
if (float.TryParse(paramStr, NumberStyles.Any, CultureInfo.InvariantCulture, out float parsedFactor))
{
factor = parsedFactor; // Asignamos el factor parseado si la conversión es exitosa
}
}
// Calculamos los píxeles llamando a la instancia de PixelToMeter y multiplicamos por el factor
return PixelToMeter.Instance.calc.MetersToPixels(meters) * factor; return PixelToMeter.Instance.calc.MetersToPixels(meters) * factor;
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ {
float pixels = (float)value; if (value == null) return 0; // Aseguramos que el valor no sea nulo
float factor = 1;
// Convertimos el valor de entrada en un número flotante
float pixels = System.Convert.ToSingle(value);
float factor = 1; // Valor por defecto del factor
// Si el parámetro no es nulo, intentamos convertirlo a float
if (parameter != null) if (parameter != null)
if (parameter.ToString() == "0.5") factor = 0.5f; {
else if (parameter.ToString() == "-0.5") factor = -0.5f; string paramStr = parameter.ToString();
else if (parameter.ToString() == "1.5") factor = 1.5f;
// Normalizamos el parámetro para asegurar que el punto sea el separador decimal
paramStr = paramStr.Replace(',', '.');
// Utilizamos CultureInfo.InvariantCulture para evitar problemas con el separador decimal
if (float.TryParse(paramStr, NumberStyles.Any, CultureInfo.InvariantCulture, out float parsedFactor))
{
factor = parsedFactor; // Asignamos el factor parseado si la conversión es exitosa
}
}
return PixelToMeter.Instance.calc.PixelsToMeters(pixels) * factor; return PixelToMeter.Instance.calc.PixelsToMeters(pixels) * factor;
} }

View File

@ -17,8 +17,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Remove="Icons\borrar.png" />
<None Remove="Icons\connect.png" /> <None Remove="Icons\connect.png" />
<None Remove="Icons\disconnect.png" /> <None Remove="Icons\disconnect.png" />
<None Remove="Icons\fotocelula.png" />
<None Remove="Icons\save.png" /> <None Remove="Icons\save.png" />
<None Remove="Icons\start.png" /> <None Remove="Icons\start.png" />
<None Remove="Icons\stop.png" /> <None Remove="Icons\stop.png" />
@ -59,8 +61,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="Icons\borrar.png" />
<Resource Include="Icons\connect.png" /> <Resource Include="Icons\connect.png" />
<Resource Include="Icons\disconnect.png" /> <Resource Include="Icons\disconnect.png" />
<Resource Include="Icons\fotocelula.png" />
<Resource Include="Icons\save.png" /> <Resource Include="Icons\save.png" />
<Resource Include="Icons\start.png" /> <Resource Include="Icons\start.png" />
<Resource Include="Icons\stop.png" /> <Resource Include="Icons\stop.png" />

BIN
Icons/borrar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
Icons/fotocelula.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -28,6 +28,7 @@ using CtrEditor.Convertidores;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Diagnostics; using System.Diagnostics;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Reflection;
namespace CtrEditor namespace CtrEditor
{ {
@ -56,6 +57,8 @@ namespace CtrEditor
public ICommand TBConnectPLCCommand { get; } public ICommand TBConnectPLCCommand { get; }
public ICommand TBDisconnectPLCCommand { get; } public ICommand TBDisconnectPLCCommand { get; }
public ICommand TBEliminarUserControlCommand { get; }
public ICommand OpenWorkDirectoryCommand { get; } public ICommand OpenWorkDirectoryCommand { get; }
// Evento que se dispara cuando se selecciona una nueva imagen // Evento que se dispara cuando se selecciona una nueva imagen
@ -66,6 +69,7 @@ namespace CtrEditor
private bool isSimulationRunning; private bool isSimulationRunning;
private bool isConnected; private bool isConnected;
private bool habilitarEliminarUserControl;
public PLCViewModel plcViewModelData; public PLCViewModel plcViewModelData;
private osBase _selectedItemOsList; private osBase _selectedItemOsList;
private string _selectedImage = null; private string _selectedImage = null;
@ -173,6 +177,11 @@ namespace CtrEditor
{ {
if (_selectedItemOsList != value) if (_selectedItemOsList != value)
{ {
if (value != null)
habilitarEliminarUserControl = true;
else
habilitarEliminarUserControl = false;
_selectedItemOsList = value; _selectedItemOsList = value;
OnPropertyChanged(nameof(SelectedItemOsList)); OnPropertyChanged(nameof(SelectedItemOsList));
} }
@ -224,7 +233,7 @@ namespace CtrEditor
ItemDoubleClickCommand = new ParameterizedRelayCommand(ExecuteDoubleClick); ItemDoubleClickCommand = new ParameterizedRelayCommand(ExecuteDoubleClick);
_timerSimulacion = new DispatcherTimer(); _timerSimulacion = new DispatcherTimer();
_timerSimulacion.Interval = TimeSpan.FromMilliseconds(16); // ajusta el intervalo según sea necesario _timerSimulacion.Interval = TimeSpan.FromMilliseconds(1); // ajusta el intervalo según sea necesario
_timerSimulacion.Tick += OnTickSimulacion; _timerSimulacion.Tick += OnTickSimulacion;
StartSimulationCommand = new RelayCommand(StartSimulation); StartSimulationCommand = new RelayCommand(StartSimulation);
@ -236,6 +245,8 @@ namespace CtrEditor
TBConnectPLCCommand = new RelayCommand(ConnectPLC, () => !IsConnected); TBConnectPLCCommand = new RelayCommand(ConnectPLC, () => !IsConnected);
TBDisconnectPLCCommand = new RelayCommand(DisconnectPLC, () => IsConnected); TBDisconnectPLCCommand = new RelayCommand(DisconnectPLC, () => IsConnected);
TBEliminarUserControlCommand = new RelayCommand(EliminarUserControl, () => habilitarEliminarUserControl);
stopwatch_PLCRefresh = new Stopwatch(); stopwatch_PLCRefresh = new Stopwatch();
stopwatch_SimRefresh = new Stopwatch(); stopwatch_SimRefresh = new Stopwatch();
} }
@ -309,19 +320,29 @@ namespace CtrEditor
} }
} }
private void EliminarUserControl()
{
if (SelectedItemOsList is osBase objEliminar)
RemoverObjetoSimulable(objEliminar);
}
private void InitializeTipoSimulableList() private void InitializeTipoSimulableList()
{ {
var baseType = typeof(osBase); var baseType = typeof(osBase);
var types = AppDomain.CurrentDomain.GetAssemblies() var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes()) .SelectMany(assembly => assembly.GetTypes())
.Where(type => type.IsSubclassOf(baseType) && !type.IsAbstract); .Where(type => type.IsSubclassOf(baseType) && !type.IsAbstract && typeof(IosBase).IsAssignableFrom(type));
foreach (var type in types) foreach (var type in types)
{ {
ListaOsBase.Add(new TipoSimulable { Nombre = type.Name, Tipo = type }); var methodInfo = type.GetMethod("NombreClase", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
string nombre = methodInfo != null ? methodInfo.Invoke(null, null)?.ToString() : "Nombre no encontrado";
ListaOsBase.Add(new TipoSimulable { Nombre = nombre, Tipo = type });
} }
} }
private void StartSimulation() private void StartSimulation()
{ {
foreach (var objetoSimulable in ObjetosSimulables) foreach (var objetoSimulable in ObjetosSimulables)

View File

@ -6,7 +6,7 @@
xmlns:Siemens="clr-namespace:CtrEditor.Siemens" xmlns:Siemens="clr-namespace:CtrEditor.Siemens"
xmlns:convert="clr-namespace:CtrEditor.Convertidores" xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:ObjetosSim="clr-namespace:CtrEditor.ObjetosSim" x:Class="CtrEditor.MainWindow" xmlns:ObjetosSim="clr-namespace:CtrEditor.ObjetosSim" x:Class="CtrEditor.MainWindow"
Height="900" Width="1600" Height="900" Width="1600" WindowState="Maximized"
ResizeMode="CanResize" Title="{Binding directorioTrabajo}"> ResizeMode="CanResize" Title="{Binding directorioTrabajo}">
<Window.DataContext> <Window.DataContext>
@ -142,6 +142,7 @@
<!-- Espacio para el GridSplitter --> <!-- Espacio para el GridSplitter -->
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<!-- Altura ajustable para el PanelEdicion --> <!-- Altura ajustable para el PanelEdicion -->
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- ListBox --> <!-- ListBox -->
@ -167,6 +168,18 @@
<!-- Aquí puedes agregar los controles para editar propiedades --> <!-- Aquí puedes agregar los controles para editar propiedades -->
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
<ToolBarTray Grid.Row="3">
<ToolBar>
<Button Command="{Binding TBEliminarUserControlCommand}" ToolTip="Eliminar Control">
<StackPanel>
<Image Source="Icons/borrar.png" Width="16" Height="16"/>
<TextBlock Text="Eliminar"/>
</StackPanel>
</Button>
</ToolBar>
</ToolBarTray>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -20,7 +20,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucBasicExample.xaml /// Interaction logic for ucBasicExample.xaml
/// </summary> /// </summary>
public class osBasicExample : osBase public class osBasicExample : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación

View File

@ -25,16 +25,20 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
/// ///
public class osBotella : osBase public class osBotella : osBase, IosBase
{ {
private float _diametro; private float _diametro;
private float _mass; private float _mass;
private Vector2 _centro = new Vector2(); // Centro private Vector2 _centro = new Vector2(); // Centro
private string _nombre = "Botella"; private string _nombre = NombreClase();
private simBotella Simulacion_Botella; private simBotella Simulacion_Botella;
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
public static string NombreClase()
{
return "Botella";
}
public float Diametro { public float Diametro {
get => _diametro; get => _diametro;

View File

@ -20,7 +20,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucBoton.xaml /// Interaction logic for ucBoton.xaml
/// </summary> /// </summary>
public class osBoton : osBase public class osBoton : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -34,6 +34,11 @@ namespace CtrEditor.ObjetosSim
private Brush _color; private Brush _color;
private Brush _colorButton; private Brush _colorButton;
public static string NombreClase()
{
return "Boton";
}
public Brush Color public Brush Color
{ {
get => _color; get => _color;

View File

@ -10,7 +10,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucDescarte.xaml /// Interaction logic for ucDescarte.xaml
/// </summary> /// </summary>
public class osDescarte : osBase public class osDescarte : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -18,7 +18,10 @@ namespace CtrEditor.ObjetosSim
private float _diametro; private float _diametro;
private Vector2 _centro = new Vector2(); // Centro private Vector2 _centro = new Vector2(); // Centro
private simDescarte AreaDeDescarte; private simDescarte AreaDeDescarte;
public static string NombreClase()
{
return "Descarte";
}
public override float Left public override float Left
{ {
get => _centro.X - Diametro / 2; get => _centro.X - Diametro / 2;

View File

@ -22,7 +22,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucFiller.xaml /// Interaction logic for ucFiller.xaml
/// </summary> /// </summary>
public class osFiller : osBase public class osFiller : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -42,6 +42,10 @@ namespace CtrEditor.ObjetosSim
private float _topSalida; private float _topSalida;
private List<osBotella> Botellas = new List<osBotella>(); private List<osBotella> Botellas = new List<osBotella>();
public static string NombreClase()
{
return "Filler";
}
public float OffsetLeftSalida public float OffsetLeftSalida
{ {
get => _leftSalida; get => _leftSalida;

View File

@ -24,7 +24,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucGuia.xaml /// Interaction logic for ucGuia.xaml
/// </summary> /// </summary>
public class osGuia : osBase public class osGuia : osBase, IosBase
{ {
private float _ancho; private float _ancho;
private float _altoGuia; private float _altoGuia;
@ -35,6 +35,10 @@ namespace CtrEditor.ObjetosSim
private simGuia Simulation_Guia; private simGuia Simulation_Guia;
public static string NombreClase()
{
return "Guia";
}
public override float Left public override float Left
{ {
get => _left; get => _left;

View File

@ -0,0 +1,44 @@
<UserControl x:Class="CtrEditor.ObjetosSim.UserControls.ucPhotocell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls"
mc:Ignorable="d"
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<convert:HalfWidthConverter x:Key="HalfWidthConverter"/>
</UserControl.Resources>
<Canvas>
<!-- Contenedor para la imagen y el rectángulo que permite rotación conjunta -->
<Canvas x:Name="RotatingContainer">
<Image Source="/Icons/fotocelula.png"
Width="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=3}"
Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=3}"
Canvas.Top="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=-1}"
Canvas.Left="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=-3}"/>
<Rectangle x:Name="Photocell" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}">
<Rectangle.Fill>
<VisualBrush x:Name="MovingPattern" TileMode="Tile" Viewport="0,0,3,3" ViewportUnits="Absolute" Viewbox="0,0,3,3" ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Canvas>
<Ellipse Width="2" Height="2" Fill="Green"/>
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
</Rectangle.Fill>
<!-- No se aplica la transformación aquí -->
</Rectangle>
</Canvas>
<!-- Transformación de rotación aplicada al contenedor -->
<Canvas.RenderTransform>
<RotateTransform Angle="{Binding Angulo}" CenterX="0" CenterY="0"/>
</Canvas.RenderTransform>
</Canvas>
</UserControl>

View File

@ -0,0 +1,243 @@
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
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.ObjetosSim.UserControls
{
/// <summary>
/// Interaction logic for ucPhotocell.xaml
/// </summary>
public class osPhotocell : osBase, IosBase
{
private float _ancho;
private float _altoPhotocell;
private float _left;
private float _top;
private float _angulo;
private string _nombre = NombreClase();
private bool _luzCortada;
private string _tagPhotocellOUT;
private bool _tipoNC;
private simBarrera Simulation_Photocell;
public static string NombreClase()
{
return "Photocell";
}
public bool LuzCortada
{
get => _luzCortada;
set
{
if (_luzCortada != value)
{
_luzCortada = value;
OnPropertyChanged(nameof(LuzCortada));
}
}
}
public bool Tipo_NC
{
get => _tipoNC;
set
{
if (_tipoNC != value)
{
_tipoNC = value;
OnPropertyChanged(nameof(Tipo_NC));
}
}
}
public string TagPhotocell_OUT
{
get => _tagPhotocellOUT;
set
{
if (_tagPhotocellOUT != value)
{
_tagPhotocellOUT = value;
OnPropertyChanged(nameof(TagPhotocell_OUT));
}
}
}
public override float Left
{
get => _left;
set
{
_left = value;
ActualizarGeometrias();
CanvasSetLeftinMeter(value);
OnPropertyChanged(nameof(Left));
}
}
public override float Top
{
get => _top;
set
{
_top = value;
ActualizarGeometrias();
CanvasSetTopinMeter(value);
OnPropertyChanged(nameof(Top));
}
}
public float Ancho
{
get => _ancho;
set
{
_ancho = value;
ActualizarGeometrias();
OnPropertyChanged(nameof(Ancho));
}
}
public float Alto
{
get => _altoPhotocell;
set
{
_altoPhotocell = value;
ActualizarGeometrias();
OnPropertyChanged(nameof(Alto));
}
}
public float Angulo
{
get => _angulo;
set
{
_angulo = value;
ActualizarGeometrias();
OnPropertyChanged(nameof(Angulo));
}
}
public override string Nombre
{
get => _nombre;
set
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
}
}
private void ActualizarGeometrias()
{
if (_visualRepresentation is ucPhotocell uc)
UpdateRectangle(Simulation_Photocell, uc.Photocell, Alto, Ancho, Angulo);
}
public osPhotocell()
{
Ancho = 1;
Alto = 0.03f;
}
public override void UpdateGeometryStart()
{
// Se llama antes de la simulacion
ActualizarGeometrias();
}
public override void UpdateControl(int elapsedMilliseconds)
{
LuzCortada = Simulation_Photocell.LuzCortada;
}
public override void UpdateGeometryStep()
{
Simulation_Photocell.LuzCortada = false;
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) {
EscribirBitTag(plc, TagPhotocell_OUT, LuzCortada);
}
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
ActualizarLeftTop();
if (_visualRepresentation is ucPhotocell uc)
Simulation_Photocell = AddBarrera(simulationManager, uc.Photocell, Alto, Ancho, Angulo);
}
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
simulationManager.Remove(Simulation_Photocell);
}
}
public partial class ucPhotocell : UserControl, IDataContainer
{
public osBase? Datos { get; set; }
public ucPhotocell()
{
InitializeComponent();
this.Loaded += OnLoaded;
this.Unloaded += OnUnloaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Datos?.ucLoaded();
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
Datos?.ucUnLoaded();
}
public void Resize(float width, float height)
{
if (width == 0) return;
if (Datos is osPhotocell datos)
datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
}
public void Move(float LeftPixels, float TopPixels)
{
if (Datos != null)
{
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
}
}
public void Rotate(float Angle)
{
if (Datos != null)
if (Datos is osPhotocell datos)
datos.Angulo = Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
{
return 1;
}
}
}

View File

@ -21,7 +21,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucSensTemperatura.xaml /// Interaction logic for ucSensTemperatura.xaml
/// </summary> /// </summary>
public class osSensTemperatura : osBase public class osSensTemperatura : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -36,6 +36,10 @@ namespace CtrEditor.ObjetosSim
private float _max_OUT_Scaled; private float _max_OUT_Scaled;
private float _min_OUT_Scaled; private float _min_OUT_Scaled;
public static string NombreClase()
{
return "Temperatura";
}
public string Tag public string Tag
{ {
get => _tag; get => _tag;

View File

@ -23,7 +23,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucTanque.xaml /// Interaction logic for ucTanque.xaml
/// </summary> /// </summary>
public class osTanque : osBase public class osTanque : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -45,6 +45,10 @@ namespace CtrEditor.ObjetosSim
private bool _SalidaAbierta_Bool; private bool _SalidaAbierta_Bool;
private float _capacidadLitros; private float _capacidadLitros;
public static string NombreClase()
{
return "Tanque";
}
public float Capacidad_Litros public float Capacidad_Litros
{ {
get => _capacidadLitros; get => _capacidadLitros;

View File

@ -21,7 +21,7 @@ namespace CtrEditor.ObjetosSim.UserControls
/// <summary> /// <summary>
/// Interaction logic for ucTransporteCurva.xaml /// Interaction logic for ucTransporteCurva.xaml
/// </summary> /// </summary>
public class osTransporteCurva : osBase public class osTransporteCurva : osBase, IosBase
{ {
private string _nombre = "Transporte Curva"; private string _nombre = "Transporte Curva";

View File

@ -22,7 +22,7 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucTransporteGuias.xaml /// Interaction logic for ucTransporteGuias.xaml
/// </summary> /// </summary>
public class osTransporteGuias : osBase public class osTransporteGuias : osBase, IosBase
{ {
private string _nombre = "Transporte Guias"; private string _nombre = "Transporte Guias";
@ -48,7 +48,10 @@ namespace CtrEditor.ObjetosSim
private simGuia? Guia_Inferior; private simGuia? Guia_Inferior;
public static string NombreClase()
{
return "Transporte Guias";
}
public string Motor public string Motor
{ {
get => _motor; get => _motor;

View File

@ -12,7 +12,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
/// ///
public class osTransporteTTop : osBase public class osTransporteTTop : osBase, IosBase
{ {
private string _nombre = "Transporte TTOP"; private string _nombre = "Transporte TTOP";
@ -32,6 +32,10 @@ namespace CtrEditor.ObjetosSim
private simTransporte Simulation_Transporte; private simTransporte Simulation_Transporte;
public static string NombreClase()
{
return "Transporte";
}
public string Motor public string Motor
{ {
get => _motor; get => _motor;

View File

@ -24,12 +24,12 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
/// ///
public class osVMmotorSim : osBase public class osVMmotorSim : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
private string _nombre = "VetroMeccanica Motor"; private string _nombre = NombreClase();
private float _tamano; private float _tamano;
private float _left; private float _left;
private float _top; private float _top;
@ -43,6 +43,11 @@ namespace CtrEditor.ObjetosSim
private VMSimMotor motState = new VMSimMotor(); private VMSimMotor motState = new VMSimMotor();
public static string NombreClase()
{
return "VetroMeccanica Motor";
}
[Hidden] [Hidden]
[JsonIgnore] [JsonIgnore]
public ImageSource ImageSource public ImageSource ImageSource

View File

@ -27,9 +27,7 @@ namespace CtrEditor.ObjetosSim
public interface IosBase public interface IosBase
{ {
string Nombre { get; } static abstract string NombreClase();
void UpdateControl(int elapsedMilliseconds);
} }
public interface IDataContainer public interface IDataContainer
@ -43,8 +41,10 @@ namespace CtrEditor.ObjetosSim
int ZIndex(); int ZIndex();
} }
public abstract class osBase : INotifyPropertyChanged, IosBase public abstract class osBase : INotifyPropertyChanged
{ {
public virtual string Nombre { get; set; } = "osBase";
public abstract float Left { get; set; } public abstract float Left { get; set; }
public abstract float Top { get; set; } public abstract float Top { get; set; }
@ -55,8 +55,6 @@ namespace CtrEditor.ObjetosSim
[JsonIgnore] [JsonIgnore]
protected UserControl? _visualRepresentation = null; protected UserControl? _visualRepresentation = null;
public abstract string Nombre { get; set; }
public abstract void UpdateControl(int elapsedMilliseconds); public abstract void UpdateControl(int elapsedMilliseconds);
public abstract void UpdateGeometryStart(); public abstract void UpdateGeometryStart();
public abstract void UpdateGeometryStep(); public abstract void UpdateGeometryStep();
@ -76,7 +74,6 @@ namespace CtrEditor.ObjetosSim
[JsonIgnore] [JsonIgnore]
public SimulationManagerFP simulationManager; public SimulationManagerFP simulationManager;
protected osBase ObtenerLink(string NameLink, Type tipoOsBase) protected osBase ObtenerLink(string NameLink, Type tipoOsBase)
{ {
if (!string.IsNullOrEmpty(NameLink) && _mainViewModel != null) if (!string.IsNullOrEmpty(NameLink) && _mainViewModel != null)
@ -231,11 +228,22 @@ namespace CtrEditor.ObjetosSim
simRect.Create(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo); simRect.Create(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo);
} }
public void UpdateRectangle(simBarrera simRect, System.Windows.Shapes.Rectangle wpfRect, float Alto, float Ancho, float Angulo)
{
if (simRect != null)
simRect.Create(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo);
}
public simTransporte AddRectangle(SimulationManagerFP simulationManager, System.Windows.Shapes.Rectangle wpfRect, float Alto, float Ancho, float Angulo) public simTransporte AddRectangle(SimulationManagerFP simulationManager, System.Windows.Shapes.Rectangle wpfRect, float Alto, float Ancho, float Angulo)
{ {
return simulationManager.AddRectangle(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo); return simulationManager.AddRectangle(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo);
} }
public simBarrera AddBarrera(SimulationManagerFP simulationManager, System.Windows.Shapes.Rectangle wpfRect, float Alto, float Ancho, float Angulo)
{
return simulationManager.AddBarrera(Ancho, Alto, GetRectangleCenter(wpfRect), Angulo);
}
public void UpdateOrCreateLine(simGuia simGuia, System.Windows.Shapes.Rectangle wpfRect) public void UpdateOrCreateLine(simGuia simGuia, System.Windows.Shapes.Rectangle wpfRect)
{ {
if (simGuia != null) if (simGuia != null)

View File

@ -42,7 +42,7 @@ namespace CtrEditor.Siemens
{ {
IsConnected = false; IsConnected = false;
PLCInterface = new PLCModel(); PLCInterface = new PLCModel();
_timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) }; _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(1) };
_timer.Tick += (s, e) => Refresh(); _timer.Tick += (s, e) => Refresh();
ConnectCommand = new RelayCommand(Connect, () => true); ConnectCommand = new RelayCommand(Connect, () => true);

View File

@ -223,7 +223,7 @@ namespace CtrEditor.Simulacion
// Restablecer manejador de eventos de colisión // Restablecer manejador de eventos de colisión
Body.OnCollision += HandleCollision; Body.OnCollision += HandleCollision;
Body.OnSeparation += HandleOnSeparation; //Body.OnSeparation += HandleOnSeparation;
Body.UserData = this; // Importante para la identificación durante la colisión Body.UserData = this; // Importante para la identificación durante la colisión
@ -295,8 +295,7 @@ namespace CtrEditor.Simulacion
private void HandleOnSeparation(Fixture fixtureA, Fixture fixtureB) private void HandleOnSeparation(Fixture fixtureA, Fixture fixtureB)
{ {
if (fixtureB.Body.UserData is simBarrera Sensor)
Sensor.LuzCortada = false;
} }
private void ApplyConveyorEffect(simTransporte conveyor, Fixture circleFixture, float porcentajeCompartido) private void ApplyConveyorEffect(simTransporte conveyor, Fixture circleFixture, float porcentajeCompartido)
@ -365,9 +364,9 @@ namespace CtrEditor.Simulacion
return rectangle; return rectangle;
} }
public simTransporte AddBarrera(float width, float height, Vector2 position, float angle) public simBarrera AddBarrera(float width, float height, Vector2 position, float angle)
{ {
simTransporte rectangle = new simTransporte(world, width, height, position, angle); simBarrera rectangle = new simBarrera(world, width, height, position, angle);
Cuerpos.Add(rectangle); Cuerpos.Add(rectangle);
return rectangle; return rectangle;
} }