diff --git a/Convertidores/Converters.cs b/Convertidores/Converters.cs
index d5a34b1..6a3c41f 100644
--- a/Convertidores/Converters.cs
+++ b/Convertidores/Converters.cs
@@ -11,25 +11,6 @@ using System.Windows.Media;
namespace CtrEditor.Convertidores
{
- public class SpeedAndWidthToDurationConverter : IMultiValueConverter
- {
- public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
- {
- if (values.Length == 2 && values[0] is double speed && values[1] is double width && speed > 0)
- {
- // Convert speed (meters per minute) to duration (seconds)
- double durationInSeconds = (width * 60) / speed;
- return new Duration(TimeSpan.FromSeconds(durationInSeconds));
- }
- return DependencyProperty.UnsetValue;
- }
-
- public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
-
public class HalfWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
diff --git a/CtrEditor.csproj b/CtrEditor.csproj
index 84e6647..ea917eb 100644
--- a/CtrEditor.csproj
+++ b/CtrEditor.csproj
@@ -11,7 +11,6 @@
-
@@ -44,12 +43,9 @@
-
-
-
diff --git a/MainViewModel.cs b/MainViewModel.cs
index ead3a47..c5ba0b5 100644
--- a/MainViewModel.cs
+++ b/MainViewModel.cs
@@ -389,6 +389,8 @@ namespace CtrEditor
private void StartSimulation()
{
+ IsSimulationRunning = true;
+
foreach (var objetoSimulable in ObjetosSimulables)
objetoSimulable.UpdateGeometryStart();
@@ -399,11 +401,15 @@ namespace CtrEditor
_timerSimulacion.Start();
simulationManager.stopwatch.Start();
stopwatch_SimRefresh.Start();
- IsSimulationRunning = true;
}
private void StopSimulation()
{
+ IsSimulationRunning = false;
+
+ foreach (var objetoSimulable in ObjetosSimulables)
+ objetoSimulable.SimulationStop();
+
if (Debug_SimulacionCreado)
{
simulationManager.Debug_ClearSimulationShapes();
@@ -412,7 +418,6 @@ namespace CtrEditor
_timerSimulacion.Stop();
simulationManager.stopwatch.Stop();
stopwatch_SimRefresh.Stop();
- IsSimulationRunning = false;
}
private void OnTickSimulacion(object sender, EventArgs e)
diff --git a/ObjetosSim/UserControls/CircularSegment.xaml.cs b/ObjetosSim/UserControls/CircularSegment.xaml.cs
index 9f38c9d..26ffb33 100644
--- a/ObjetosSim/UserControls/CircularSegment.xaml.cs
+++ b/ObjetosSim/UserControls/CircularSegment.xaml.cs
@@ -1,17 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+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
{
diff --git a/ObjetosSim/UserControls/ucBasicExample.xaml b/ObjetosSim/UserControls/ucBasicExample.xaml
index 4da0235..1aa5709 100644
--- a/ObjetosSim/UserControls/ucBasicExample.xaml
+++ b/ObjetosSim/UserControls/ucBasicExample.xaml
@@ -5,20 +5,33 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
+ xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/ObjetosSim/UserControls/ucBasicExample.xaml.cs b/ObjetosSim/UserControls/ucBasicExample.xaml.cs
index 84d6443..e17073b 100644
--- a/ObjetosSim/UserControls/ucBasicExample.xaml.cs
+++ b/ObjetosSim/UserControls/ucBasicExample.xaml.cs
@@ -1,134 +1,103 @@
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
-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;
+using Newtonsoft.Json;
+using CommunityToolkit.Mvvm.ComponentModel;
namespace CtrEditor.ObjetosSim
{
///
/// Interaction logic for ucBasicExample.xaml
///
- public class osBasicExample : osBase, IosBase
+ ///
+
+ public partial class osBasicExample : osBase, IosBase
{
+
// Otros datos y métodos relevantes para la simulación
- private string _nombre = "Ejemplo";
- private float _ancho;
- private float _alto;
- private float _angulo;
- private float _left;
- private float _top;
-
- public override float Left
+ public static string NombreClase()
{
- get => _left;
- set
- {
- _left = value;
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(Left));
- }
+ return "Ejemplo";
}
- public override float Top
- {
- get => _top;
- set
- {
- _top = value;
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(Top));
- }
- }
-
- public float Ancho
- {
- get => _ancho;
- set
- {
- _ancho = value;
- OnPropertyChanged(nameof(Ancho));
- }
- }
- public float Alto
- {
- get => _alto;
- set
- {
- _alto = value;
- OnPropertyChanged(nameof(Alto));
- }
- }
-
- public float Angulo
- {
- get => _angulo;
- set
- {
- _angulo = value;
- OnPropertyChanged(nameof(Angulo));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
- }
+ get => nombre;
+ set => SetProperty(ref nombre, value);
+ }
+
+ [JsonIgnore]
+ [ObservableProperty]
+ public ImageSource imageSource_oculta;
+
+ [ObservableProperty]
+ public float tamano;
+ [ObservableProperty]
+ public float maxRatedHz;
+
+ [ObservableProperty]
+ public float tiempoRampa;
+
+ partial void OnTiempoRampaChanged(float value)
+ {
+ if (value < 0.1f)
+ value = 0.1f;
+ tiempoRampa = value;
+ }
+
+ [ObservableProperty]
+ public bool encendido;
+ [ObservableProperty]
+ public int pLC_NumeroMotor;
+ [ObservableProperty]
+ public float ratio;
+
+ [ObservableProperty]
+ public float velocidad;
+
+ partial void OnVelocidadChanged(float value)
+ {
+ if (value > 0)
+ ImageSource_oculta = ImageFromPath("/imagenes/motorVerde.png");
+ else
+ ImageSource_oculta = ImageFromPath("/imagenes/motorNegro.png");
}
public osBasicExample()
{
- Ancho = 0.30f;
- Alto = 0.30f;
+ Tamano = 0.30f;
+ PLC_NumeroMotor = 31;
+ MaxRatedHz = 100;
+ TiempoRampa = 3;
+ ImageSource_oculta = ImageFromPath("/imagenes/motor2.png");
}
public override void UpdateGeometryStart()
{
// Se llama antes de la simulacion
- }
- public override void UpdateGeometryStep()
- {
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
+
}
public override void UpdateControl(int elapsedMilliseconds)
{
+ // Calculamos la velocidad
}
+
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
ActualizarLeftTop();
- }
- public override void ucUnLoaded()
- {
- // El UserControl se esta eliminando
- // eliminar el objeto de simulacion
- }
-
+ }
}
public partial class ucBasicExample : UserControl, IDataContainer
@@ -149,13 +118,7 @@ namespace CtrEditor.ObjetosSim
{
Datos?.ucUnLoaded();
}
- public void Resize(float width, float height) {
- if (Datos is osBasicExample datos)
- {
- datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
- datos.Alto = PixelToMeter.Instance.calc.PixelsToMeters(width);
- }
- }
+ public void Resize(float width, float height) { }
public void Move(float LeftPixels, float TopPixels)
{
if (Datos != null)
@@ -164,12 +127,7 @@ namespace CtrEditor.ObjetosSim
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
}
}
- public void Rotate(float Angle)
- {
- if (Datos != null)
- if (Datos is osBasicExample datos)
- datos.Angulo = Angle;
- }
+ public void Rotate(float Angle) { }
public void Highlight(bool State) { }
public int ZIndex()
{
diff --git a/ObjetosSim/UserControls/ucBotella.xaml.cs b/ObjetosSim/UserControls/ucBotella.xaml.cs
index 2264017..b42291f 100644
--- a/ObjetosSim/UserControls/ucBotella.xaml.cs
+++ b/ObjetosSim/UserControls/ucBotella.xaml.cs
@@ -1,22 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+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;
using Microsoft.Xna.Framework;
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
-using Newtonsoft.Json.Linq;
+using CommunityToolkit.Mvvm.ComponentModel;
namespace CtrEditor.ObjetosSim
{
@@ -25,13 +13,9 @@ namespace CtrEditor.ObjetosSim
///
///
- public class osBotella : osBase, IosBase
+ public partial class osBotella : osBase, IosBase
{
- private float _diametro;
- private float _mass;
- private Vector2 _centro = new Vector2(); // Centro
- private string _nombre = NombreClase();
- private simBotella Simulacion_Botella;
+ private simBotella SimGeometria;
// Otros datos y métodos relevantes para la simulación
@@ -39,92 +23,48 @@ namespace CtrEditor.ObjetosSim
{
return "Botella";
}
-
- public float Diametro {
- get => _diametro;
- set
- {
- _diametro = value;
- Simulacion_Botella?.SetDiameter(Diametro);
- OnPropertyChanged(nameof(Diametro));
- }
+ private string nombre = NombreClase();
+ public override string Nombre
+ {
+ get => nombre;
+ set => SetProperty(ref nombre, value);
}
- public float Mass {
- get => _mass;
- set
- {
- _mass = value;
- Simulacion_Botella?.SetMass(value);
- OnPropertyChanged(nameof(Mass));
- }
+ [ObservableProperty]
+ private float diametro;
+
+ partial void OnDiametroChanged(float value)
+ {
+ SimGeometria?.SetDiameter(Diametro);
}
- public override float Left
+ [ObservableProperty]
+ private float mass;
+ partial void OnMassChanged(float value)
{
- get => _centro.X-Diametro/2;
- set
- {
- _centro.X = value+Diametro/2;
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(CenterX));
- OnPropertyChanged(nameof(Left));
- }
- }
- public override float Top
- {
- get => _centro.Y - Diametro / 2;
- set
- {
- _centro.Y = value + Diametro / 2;
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(CenterY));
- OnPropertyChanged(nameof(Top));
- }
+ SimGeometria?.SetMass(value);
}
- public float CenterX
+ public Vector2 GetCentro()
{
- get => _centro.X;
- set
- {
- _centro.X = value;
- CanvasSetLeftinMeter(Left);
- OnPropertyChanged(nameof(CenterX));
- OnPropertyChanged(nameof(Left));
- }
+ return new Vector2 (Left+Diametro/2,Top+Diametro/2);
}
- public float CenterY
- {
- get => _centro.Y;
- set
- {
- _centro.Y = value;
- CanvasSetTopinMeter(Top);
- OnPropertyChanged(nameof(CenterY));
- OnPropertyChanged(nameof(Top));
- }
+
+ public void SetCentro(float x, float y)
+ { Left = x; Top = y; }
+
+ public void SetCentro(Vector2 centro)
+ {
+ Left = centro.X - Diametro / 2;
+ Top = centro.Y - Diametro / 2;
}
private void ActualizarGeometrias()
{
- if (Simulacion_Botella != null)
+ if (SimGeometria != null)
{
- Simulacion_Botella.SetDiameter(Diametro);
- Simulacion_Botella.SetPosition(CenterX, CenterY);
- }
- }
-
- public override string Nombre
- {
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
+ SimGeometria.SetDiameter(Diametro);
+ SimGeometria.SetPosition(GetCentro());
}
}
@@ -139,6 +79,11 @@ namespace CtrEditor.ObjetosSim
// Se llama antes de la simulacion
ActualizarGeometrias();
}
+ public override void SimulationStop()
+ {
+ // Se llama al detener la simulacion. Util para detener Storyboards
+ }
+
public override void UpdateGeometryStep()
{
// Se llama antes de la simulacion
@@ -149,10 +94,9 @@ namespace CtrEditor.ObjetosSim
public override void UpdateControl(int elapsedMilliseconds)
{
- CenterX = Simulacion_Botella.CenterX;
- CenterY = Simulacion_Botella.CenterY;
+ SetCentro(SimGeometria.Center);
- if (Simulacion_Botella.Descartar) // Ha sido marcada para remover
+ if (SimGeometria.Descartar) // Ha sido marcada para remover
RemoverDesdeSimulacion = true;
}
@@ -161,13 +105,13 @@ namespace CtrEditor.ObjetosSim
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
ActualizarLeftTop();
- Simulacion_Botella = simulationManager.AddCircle(Diametro, _centro, Mass);
+ SimGeometria = simulationManager.AddCircle(Diametro, GetCentro(), Mass);
}
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
- simulationManager.Remove(Simulacion_Botella);
+ simulationManager.Remove(SimGeometria);
}
}
diff --git a/ObjetosSim/UserControls/ucBoton.xaml b/ObjetosSim/UserControls/ucBoton.xaml
index 7c15b83..b83f3d1 100644
--- a/ObjetosSim/UserControls/ucBoton.xaml
+++ b/ObjetosSim/UserControls/ucBoton.xaml
@@ -6,12 +6,17 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
+ xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d">
+
+
+
+
-
/// Interaction logic for ucBoton.xaml
///
- public class osBoton : osBase, IosBase
+ public partial class osBoton : osBase, IosBase
{
// Otros datos y métodos relevantes para la simulación
- private string _nombre = "Boton";
- private float _tamano;
- private float _left;
- private float _top;
- private bool _estado;
- private string _tag;
-
- private Brush _color;
- private Brush _colorButton;
-
public static string NombreClase()
{
return "Boton";
}
-
- public Brush Color
- {
- get => _color;
- set
- {
- _color = value;
- OnPropertyChanged(nameof(Color));
- }
- }
-
- [Hidden]
- public Brush ColorButton
- {
- get => _colorButton;
- set
- {
- _colorButton = value;
- OnPropertyChanged(nameof(ColorButton));
- }
- }
-
- public override float Left
- {
- get => _left;
- set
- {
- _left = value;
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(Left));
- }
- }
- public override float Top
- {
- get => _top;
- set
- {
- _top = value;
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(Top));
- }
- }
- public float Tamano
- {
- get => _tamano;
- set
- {
- _tamano = value;
- OnPropertyChanged(nameof(Tamano));
- }
- }
- public bool Estado
- {
- get => _estado;
- set
- {
- _estado = value;
- if (value)
- ColorButton = Brushes.LightGreen;
- else
- ColorButton = Color;
- OnPropertyChanged(nameof(Estado));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
- }
+ get => nombre;
+ set => SetProperty(ref nombre, value);
}
- public string Tag
+
+ [ObservableProperty]
+ private Brush color;
+ [ObservableProperty]
+ private Brush colorButton_oculto;
+ [ObservableProperty]
+ public float tamano;
+ [ObservableProperty]
+ public bool estado;
+
+ partial void OnEstadoChanged(bool value)
{
- get => _tag;
- set
- {
- if (_tag != value)
- {
- _tag = value;
- OnPropertyChanged(nameof(Tag));
- }
- }
+ if (value)
+ ColorButton_oculto = Brushes.LightGreen;
+ else
+ ColorButton_oculto = Color;
}
+ [ObservableProperty]
+ public string tag;
+
public void ButtonDownCommand()
{
Estado = true;
@@ -140,13 +68,10 @@ namespace CtrEditor.ObjetosSim
{
// Se llama antes de la simulacion
- }
- public override void UpdateGeometryStep()
- {
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
- plc.EscribirTagBool(_tag, Estado);
+ plc.EscribirTagBool(Tag, Estado);
}
public override void UpdateControl(int elapsedMilliseconds)
diff --git a/ObjetosSim/UserControls/ucDescarte.xaml b/ObjetosSim/UserControls/ucDescarte.xaml
index 26cb01f..595978f 100644
--- a/ObjetosSim/UserControls/ucDescarte.xaml
+++ b/ObjetosSim/UserControls/ucDescarte.xaml
@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
+ xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
@@ -20,6 +21,10 @@
+
+
+
+
/// Interaction logic for ucDescarte.xaml
///
- public class osDescarte : osBase, IosBase
+ public partial class osDescarte : osBase, IosBase
{
// Otros datos y métodos relevantes para la simulación
+ private simDescarte SimGeometria;
- private string _nombre = "Descarte";
- private float _diametro;
- private Vector2 _centro = new Vector2(); // Centro
- private simDescarte AreaDeDescarte;
public static string NombreClase()
{
return "Descarte";
}
- public override float Left
- {
- get => _centro.X - Diametro / 2;
- set
- {
- _centro.X = value + Diametro / 2;
- ActualizarGeometrias();
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(CenterX));
- OnPropertyChanged(nameof(Left));
- }
- }
- public override float Top
- {
- get => _centro.Y - Diametro / 2;
- set
- {
- _centro.Y = value + Diametro / 2;
- ActualizarGeometrias();
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(CenterY));
- OnPropertyChanged(nameof(Top));
- }
- }
-
- public float CenterX
- {
- get => _centro.X;
- set
- {
- _centro.X = value;
- CanvasSetLeftinMeter(Left);
- OnPropertyChanged(nameof(CenterX));
- OnPropertyChanged(nameof(Left));
- }
- }
- public float CenterY
- {
- get => _centro.Y;
- set
- {
- _centro.Y = value;
- CanvasSetTopinMeter(Top);
- OnPropertyChanged(nameof(CenterY));
- OnPropertyChanged(nameof(Top));
- }
- }
-
- public float Diametro
- {
- get => _diametro;
- set
- {
- _diametro = value;
- AreaDeDescarte?.SetDiameter(Diametro);
- OnPropertyChanged(nameof(Diametro));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
- }
+ get => nombre;
+ set => SetProperty(ref nombre, value);
}
+ [ObservableProperty]
+ private float diametro;
+
+ partial void OnDiametroChanged(float value)
+ {
+ SimGeometria?.SetDiameter(Diametro);
+ }
+
+ public Vector2 GetCentro()
+ {
+ return new Vector2(Left + Diametro / 2, Top + Diametro / 2);
+ }
+
+ public void SetCentro(float x, float y)
+ { Left = x; Top = y; }
+
+ public void SetCentro(Vector2 centro)
+ {
+ Left = centro.X - Diametro / 2;
+ Top = centro.Y - Diametro / 2;
+ }
+
+ public override void LeftChanged(float value)
+ {
+ ActualizarGeometrias();
+ }
+
+ public override void TopChanged(float value)
+ {
+ ActualizarGeometrias();
+ }
+
+
private void ActualizarGeometrias()
{
- if (AreaDeDescarte != null)
+ if (SimGeometria != null)
{
- AreaDeDescarte.SetDiameter(Diametro);
- AreaDeDescarte.SetPosition(CenterX, CenterY);
+ SimGeometria.SetDiameter(Diametro);
+ SimGeometria.SetPosition(GetCentro());
}
}
@@ -129,13 +95,13 @@ namespace CtrEditor.ObjetosSim
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
ActualizarLeftTop();
- AreaDeDescarte = simulationManager.AddDescarte(Diametro, _centro);
+ SimGeometria = simulationManager.AddDescarte(Diametro, GetCentro());
}
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
- simulationManager.Remove(AreaDeDescarte);
+ simulationManager.Remove(SimGeometria);
}
}
diff --git a/ObjetosSim/UserControls/ucFiller.xaml b/ObjetosSim/UserControls/ucFiller.xaml
index f39e039..c5a66aa 100644
--- a/ObjetosSim/UserControls/ucFiller.xaml
+++ b/ObjetosSim/UserControls/ucFiller.xaml
@@ -5,12 +5,17 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
- xmlns:convert="clr-namespace:CtrEditor.Convertidores">
+ xmlns:convert="clr-namespace:CtrEditor.Convertidores"
+ xmlns:vm="clr-namespace:CtrEditor.ObjetosSim">
-
+
+
+
+
+
/// Interaction logic for ucFiller.xaml
///
- public class osFiller : osBase, IosBase
+ public partial class osFiller : osBase, IosBase
{
// Otros datos y métodos relevantes para la simulación
- private string _nombre = "Filler";
- private float _ancho;
- private float _alto;
- private float _left;
- private float _top;
- private float _angulo;
- private float _botellas_hora;
- private float _velocidad_actual;
- private float _diametro_botella;
- private string _tag_consenso;
- private bool _consenso;
private float TiempoRestante;
- private float _leftSalida;
- private float _topSalida;
private osBotella UltimaBotella;
public static string NombreClase()
{
return "Filler";
}
- public float OffsetLeftSalida
- {
- get => _leftSalida;
- set
- {
- _leftSalida = value;
- OnPropertyChanged(nameof(OffsetLeftSalida));
- }
- }
- public float OffsetTopSalida
- {
- get => _topSalida;
- set
- {
- _topSalida = value;
- OnPropertyChanged(nameof(OffsetTopSalida));
- }
- }
-
- public bool Consenso
- {
- get => _consenso;
- set
- {
- _consenso = value;
- OnPropertyChanged(nameof(Consenso));
- }
- }
-
- public float Botellas_hora
- {
- get => _botellas_hora;
- set
- {
- _botellas_hora = value;
- OnPropertyChanged(nameof(Botellas_hora));
- }
- }
- public float Velocidad_actual_percentual
- {
- get => _velocidad_actual;
- set
- {
- _velocidad_actual = value;
- OnPropertyChanged(nameof(Velocidad_actual_percentual));
- }
- }
- public float Diametro_botella
- {
- get => _diametro_botella;
- set
- {
- _diametro_botella = value;
- OnPropertyChanged(nameof(Diametro_botella));
- }
- }
- public string Tag_consenso
- {
- get => _tag_consenso;
- set
- {
- _tag_consenso = value;
- OnPropertyChanged(nameof(Tag_consenso));
- }
- }
-
- public override float Left
- {
- get => _left;
- set
- {
- _left = value;
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(Left));
- }
- }
- public override float Top
- {
- get => _top;
- set
- {
- _top = value;
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(Top));
- }
- }
-
- public float Ancho
- {
- get => _ancho;
- set
- {
- _ancho = value;
- OnPropertyChanged(nameof(Ancho));
- }
- }
- public float Alto
- {
- get => _alto;
- set
- {
- _alto = value;
- OnPropertyChanged(nameof(Alto));
- }
- }
-
- public float Angulo
- {
- get => _angulo;
- set
- {
- _angulo = value;
- OnPropertyChanged(nameof(Angulo));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
- }
+ get => nombre;
+ set => SetProperty(ref nombre, value);
}
+ [ObservableProperty]
+ public float offsetLeftSalida;
+ [ObservableProperty]
+ public float offsetTopSalida;
+ [ObservableProperty]
+ public bool consenso;
+ [ObservableProperty]
+ public float botellas_hora;
+ [ObservableProperty]
+ public float velocidad_actual_percentual;
+ [ObservableProperty]
+ public float diametro_botella;
+ [ObservableProperty]
+ public string tag_consenso;
+ [ObservableProperty]
+ public float ancho;
+ [ObservableProperty]
+ public float alto;
+ [ObservableProperty]
+ public float angulo;
+
public osFiller()
{
Ancho = 0.30f;
@@ -185,14 +58,6 @@ namespace CtrEditor.ObjetosSim
Botellas_hora = 10000;
}
- public override void UpdateGeometryStart()
- {
- // Se llama antes de la simulacion
-
- }
- public override void UpdateGeometryStep()
- {
- }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
Consenso = LeerBitTag(plc, Tag_consenso);
@@ -249,11 +114,6 @@ namespace CtrEditor.ObjetosSim
// crear el objeto de simulacion
ActualizarLeftTop();
}
- public override void ucUnLoaded()
- {
- // El UserControl se esta eliminando
- // eliminar el objeto de simulacion
- }
}
diff --git a/ObjetosSim/UserControls/ucGuia.xaml.cs b/ObjetosSim/UserControls/ucGuia.xaml.cs
index 57ef364..021c9a4 100644
--- a/ObjetosSim/UserControls/ucGuia.xaml.cs
+++ b/ObjetosSim/UserControls/ucGuia.xaml.cs
@@ -1,24 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+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;
using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
-using FarseerPhysics.Dynamics;
-using Microsoft.Xna.Framework;
-using static System.Runtime.InteropServices.JavaScript.JSType;
namespace CtrEditor.ObjetosSim
{
@@ -39,26 +24,6 @@ namespace CtrEditor.ObjetosSim
get => nombre;
set => SetProperty(ref nombre, value);
}
- private float left;
- public override float Left
- {
- get => left;
- set
- {
- CanvasSetLeftinMeter(value);
- SetProperty(ref left, value);
- }
- }
- private float top;
- public override float Top
- {
- get => top;
- set
- {
- CanvasSetTopinMeter(value);
- SetProperty(ref top, value);
- }
- }
[ObservableProperty]
public float ancho;
diff --git a/ObjetosSim/UserControls/ucPhotocell.xaml b/ObjetosSim/UserControls/ucPhotocell.xaml
index c6892f9..afbd8d8 100644
--- a/ObjetosSim/UserControls/ucPhotocell.xaml
+++ b/ObjetosSim/UserControls/ucPhotocell.xaml
@@ -5,12 +5,17 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls"
mc:Ignorable="d"
+ xmlns:vm="clr-namespace:CtrEditor.ObjetosSim.UserControls"
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
+
+
+
+
@@ -26,8 +31,10 @@
-
-
+
+
/// Interaction logic for ucPhotocell.xaml
///
- public class osPhotocell : osBase, IosBase
+ public partial 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 Brush _color;
-
private simBarrera Simulation_Photocell;
public static string NombreClase()
{
return "Photocell";
}
-
- public Brush Color
- {
- get => _color;
- set
- {
- _color = value;
- OnPropertyChanged(nameof(Color));
- }
- }
- public bool LuzCortada
- {
- get => _luzCortada;
- set
- {
- if (_luzCortada != value)
- {
- _luzCortada = value;
- if (_luzCortada)
- Color = Brushes.Blue;
- else
- Color = Brushes.Green;
- 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));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
- }
+ get => nombre;
+ set => SetProperty(ref nombre, value);
+ }
+
+ [ObservableProperty]
+ public Brush color;
+ [ObservableProperty]
+ public bool luzCortada;
+
+ partial void OnLuzCortadaChanged(bool value)
+ {
+ if (LuzCortada)
+ Color = Brushes.Blue;
+ else
+ Color = Brushes.Green;
+ }
+
+ [ObservableProperty]
+ public bool tipo_NC;
+
+ [ObservableProperty]
+ public string tagPhotocell_OUT;
+
+
+ public override void LeftChanged(float value)
+ {
+ ActualizarGeometrias();
+ }
+
+ public override void TopChanged(float value)
+ {
+ ActualizarGeometrias();
+ }
+
+ [ObservableProperty]
+ public float ancho;
+
+ partial void OnAnchoChanged(float value)
+ {
+ ActualizarGeometrias();
+ }
+
+ [ObservableProperty]
+ public float alto;
+
+ partial void OnAltoChanged(float value)
+ {
+ ActualizarGeometrias();
+ }
+
+ [ObservableProperty]
+ public float angulo;
+
+ partial void OnAnguloChanged(float value)
+ {
+ ActualizarGeometrias();
}
private void ActualizarGeometrias()
diff --git a/ObjetosSim/UserControls/ucSensTemperatura.xaml b/ObjetosSim/UserControls/ucSensTemperatura.xaml
index 287ccfc..d3be414 100644
--- a/ObjetosSim/UserControls/ucSensTemperatura.xaml
+++ b/ObjetosSim/UserControls/ucSensTemperatura.xaml
@@ -5,11 +5,17 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
+ xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
+
+
+
+
+
/// Interaction logic for ucSensTemperatura.xaml
///
- public class osSensTemperatura : osBase, IosBase
+ public partial class osSensTemperatura : osBase, IosBase
{
// Otros datos y métodos relevantes para la simulación
- private string _nombre = "Temperatura";
- private float _ancho;
- private float _alto;
- private float _left;
- private float _top;
- private float _angulo;
- private string _tag;
- private float _value;
- private float _max_OUT_Scaled;
- private float _min_OUT_Scaled;
-
public static string NombreClase()
{
return "Temperatura";
}
- public string Tag
- {
- get => _tag;
- set
- {
- if (_tag != value)
- {
- _tag = value;
- OnPropertyChanged(nameof(Tag));
- }
- }
- }
-
- public float Min_OUT_Scaled
- {
- get => _min_OUT_Scaled;
- set
- {
- _min_OUT_Scaled = value;
- OnPropertyChanged(nameof(Min_OUT_Scaled));
- }
- }
- public float Max_OUT_Scaled
- {
- get => _max_OUT_Scaled;
- set
- {
- _max_OUT_Scaled = value;
- OnPropertyChanged(nameof(Max_OUT_Scaled));
- }
- }
-
- public float Value
- {
- get => _value;
- set
- {
- _value = value;
- OnPropertyChanged(nameof(Value));
- }
- }
- public override float Left
- {
- get => _left;
- set
- {
- _left = value;
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(Left));
- }
- }
- public override float Top
- {
- get => _top;
- set
- {
- _top = value;
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(Top));
- }
- }
-
- public float Ancho
- {
- get => _ancho;
- set
- {
- _ancho = value;
- OnPropertyChanged(nameof(Ancho));
- }
- }
- public float Alto
- {
- get => _alto;
- set
- {
- _alto = value;
- OnPropertyChanged(nameof(Alto));
- }
- }
-
- public float Angulo
- {
- get => _angulo;
- set
- {
- _angulo = value;
- OnPropertyChanged(nameof(Angulo));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
- }
+ get => nombre;
+ set => SetProperty(ref nombre, value);
}
+ [ObservableProperty]
+ public string tag;
+ [ObservableProperty]
+ public float min_OUT_Scaled;
+ [ObservableProperty]
+ public float max_OUT_Scaled;
+ [ObservableProperty]
+ public float value;
+ [ObservableProperty]
+ public float ancho;
+ [ObservableProperty]
+ public float alto;
+ [ObservableProperty]
+ public float angulo;
+
public osSensTemperatura()
{
Ancho = 0.4f;
@@ -152,23 +47,11 @@ namespace CtrEditor.ObjetosSim
Min_OUT_Scaled = 0;
}
- public override void UpdateGeometryStart()
- {
- // Se llama antes de la simulacion
-
- }
- public override void UpdateGeometryStep()
- {
- }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
EscribirWordTagScaled(plc, Tag, Value, 0, 100, Min_OUT_Scaled, Max_OUT_Scaled);
}
- public override void UpdateControl(int elapsedMilliseconds)
- {
-
- }
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
@@ -176,11 +59,6 @@ namespace CtrEditor.ObjetosSim
ActualizarLeftTop();
}
- public override void ucUnLoaded()
- {
- // El UserControl se esta eliminando
- // eliminar el objeto de simulacion
- }
}
diff --git a/ObjetosSim/UserControls/ucTanque.xaml b/ObjetosSim/UserControls/ucTanque.xaml
index f8e0cd6..48a449e 100644
--- a/ObjetosSim/UserControls/ucTanque.xaml
+++ b/ObjetosSim/UserControls/ucTanque.xaml
@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
+ xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
@@ -13,6 +14,10 @@
+
+
+
+
/// Interaction logic for ucTanque.xaml
///
- public class osTanque : osBase, IosBase
+ public partial class osTanque : osBase, IosBase
{
// Otros datos y métodos relevantes para la simulación
- private string _nombre = "Tanque";
- private float _ancho;
- private float _alto;
- private float _left;
- private float _top;
- private float _angulo;
- private float _level;
- private string _tagNivel_Word;
- private float _max_OUT_Scaled;
- private float _min_OUT_Scaled;
- private float _velocidadIngreso;
- private float _velocidadSalida;
- private string _tagIngresoAbierto_Bool;
- private string _tagSalidaAbierta_Bool;
- private bool _IngresoAbierto_Bool;
- private bool _SalidaAbierta_Bool;
- private float _capacidadLitros;
-
public static string NombreClase()
{
return "Tanque";
}
- public float Capacidad_Litros
- {
- get => _capacidadLitros;
- set
- {
- if (_capacidadLitros != value)
- {
- _capacidadLitros = value;
- OnPropertyChanged(nameof(Capacidad_Litros));
- }
- }
- }
-
- public bool Ingreso_Abierto
- {
- get => _IngresoAbierto_Bool;
- set
- {
- if (_IngresoAbierto_Bool != value)
- {
- _IngresoAbierto_Bool = value;
- OnPropertyChanged(nameof(Ingreso_Abierto));
- }
- }
- }
-
- public bool Salida_Abierta
- {
- get => _SalidaAbierta_Bool;
- set
- {
- if (_SalidaAbierta_Bool != value)
- {
- _SalidaAbierta_Bool = value;
- OnPropertyChanged(nameof(Salida_Abierta));
- }
- }
- }
-
- public string TagNivel_Word
- {
- get => _tagNivel_Word;
- set
- {
- if (_tagNivel_Word != value)
- {
- _tagNivel_Word = value;
- OnPropertyChanged(nameof(TagNivel_Word));
- }
- }
- }
-
- public string TagIngresoAbierto_Bool
- {
- get => _tagIngresoAbierto_Bool;
- set
- {
- if (_tagIngresoAbierto_Bool != value)
- {
- _tagIngresoAbierto_Bool = value;
- OnPropertyChanged(nameof(TagIngresoAbierto_Bool));
- }
- }
- }
-
- public string TagSalidaAbierta_Bool
- {
- get => _tagSalidaAbierta_Bool;
- set
- {
- if (_tagSalidaAbierta_Bool != value)
- {
- _tagSalidaAbierta_Bool = value;
- OnPropertyChanged(nameof(TagSalidaAbierta_Bool));
- }
- }
- }
-
- public float Velocidad_Ingreso
- {
- get => _velocidadIngreso;
- set
- {
- if (_velocidadIngreso != value)
- {
- _velocidadIngreso = value;
- OnPropertyChanged(nameof(Velocidad_Ingreso));
- }
- }
- }
-
- public float Velocidad_Salida
- {
- get => _velocidadSalida;
- set
- {
- if (_velocidadSalida != value)
- {
- _velocidadSalida = value;
- OnPropertyChanged(nameof(Velocidad_Salida));
- }
- }
- }
-
-
-
- public float Min_OUT_Scaled
- {
- get => _min_OUT_Scaled;
- set
- {
- _min_OUT_Scaled = value;
- OnPropertyChanged(nameof(Min_OUT_Scaled));
- }
- }
-
- public float Max_OUT_Scaled
- {
- get => _max_OUT_Scaled;
- set
- {
- _max_OUT_Scaled = value;
- OnPropertyChanged(nameof(Max_OUT_Scaled));
- }
- }
-
- public float Level
- {
- get => _level;
- set
- {
- _level = value;
- OnPropertyChanged(nameof(Level));
- }
- }
-
- public override float Left
- {
- get => _left;
- set
- {
- _left = value;
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(Left));
- }
- }
- public override float Top
- {
- get => _top;
- set
- {
- _top = value;
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(Top));
- }
- }
-
- public float Ancho
- {
- get => _ancho;
- set
- {
- _ancho = value;
- OnPropertyChanged(nameof(Ancho));
- }
- }
- public float Alto
- {
- get => _alto;
- set
- {
- _alto = value;
- OnPropertyChanged(nameof(Alto));
- }
- }
-
- public float Angulo
- {
- get => _angulo;
- set
- {
- _angulo = value;
- OnPropertyChanged(nameof(Angulo));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
- }
+ get => nombre;
+ set => SetProperty(ref nombre, value);
}
+ [ObservableProperty]
+ public float capacidad_Litros;
+ [ObservableProperty]
+ public bool ingreso_Abierto;
+ [ObservableProperty]
+ public bool salida_Abierta;
+ [ObservableProperty]
+ public string tagNivel_Word;
+ [ObservableProperty]
+ public string tagIngresoAbierto_Bool;
+ [ObservableProperty]
+ public string tagSalidaAbierta_Bool;
+ [ObservableProperty]
+ public float velocidad_Ingreso;
+ [ObservableProperty]
+ public float velocidad_Salida;
+ [ObservableProperty]
+ public float min_OUT_Scaled;
+ [ObservableProperty]
+ public float max_OUT_Scaled;
+ [ObservableProperty]
+ public float level;
+ [ObservableProperty]
+ public float ancho;
+ [ObservableProperty]
+ public float alto;
+ [ObservableProperty]
+ public float angulo;
+
public osTanque()
{
Ancho = 0.30f;
@@ -256,20 +61,11 @@ namespace CtrEditor.ObjetosSim
Min_OUT_Scaled = 0;
}
- public override void UpdateGeometryStart()
- {
- // Se llama antes de la simulacion
-
- }
- public override void UpdateGeometryStep()
- {
- }
-
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
EscribirWordTagScaled(plc, TagNivel_Word, Level, 0, 100, Min_OUT_Scaled, Max_OUT_Scaled);
- Ingreso_Abierto = LeerBitTag(plc, _tagIngresoAbierto_Bool);
- Salida_Abierta = LeerBitTag(plc, _tagSalidaAbierta_Bool);
+ Ingreso_Abierto = LeerBitTag(plc, TagIngresoAbierto_Bool);
+ Salida_Abierta = LeerBitTag(plc, TagSalidaAbierta_Bool);
}
public override void UpdateControl(int elapsedMilliseconds)
@@ -294,12 +90,6 @@ namespace CtrEditor.ObjetosSim
ActualizarLeftTop();
}
- public override void ucUnLoaded()
- {
- // El UserControl se esta eliminando
- // eliminar el objeto de simulacion
- }
-
}
public partial class ucTanque : UserControl, IDataContainer
diff --git a/ObjetosSim/UserControls/ucTransporteCurva.xaml.cs b/ObjetosSim/UserControls/ucTransporteCurva.xaml.cs
index 7314f9f..bb139e6 100644
--- a/ObjetosSim/UserControls/ucTransporteCurva.xaml.cs
+++ b/ObjetosSim/UserControls/ucTransporteCurva.xaml.cs
@@ -1,5 +1,4 @@
-using System.Configuration;
-using System.Windows;
+using System.Windows;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
@@ -36,27 +35,6 @@ namespace CtrEditor.ObjetosSim
set => SetProperty(ref nombre, value);
}
- private float left;
- public override float Left
- {
- get => left;
- set
- {
- CanvasSetLeftinMeter(value);
- SetProperty(ref left, value);
- }
- }
- private float top;
- public override float Top
- {
- get => top;
- set
- {
- CanvasSetTopinMeter(value);
- SetProperty(ref top, value);
- }
- }
-
[ObservableProperty]
private float radioExterno;
[ObservableProperty]
@@ -115,9 +93,6 @@ namespace CtrEditor.ObjetosSim
// Se llama antes de la simulacion
ActualizarGeometrias();
}
- public override void UpdateGeometryStep()
- {
- }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
if (_osMotor != null)
@@ -129,9 +104,6 @@ namespace CtrEditor.ObjetosSim
_osMotor = ObtenerLink(_motor, typeof(osVMmotorSim));
}
- public override void UpdateControl(int elapsedMilliseconds)
- {
- }
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
diff --git a/ObjetosSim/UserControls/ucTransporteGuias.xaml b/ObjetosSim/UserControls/ucTransporteGuias.xaml
index a9ba9ff..68a0486 100644
--- a/ObjetosSim/UserControls/ucTransporteGuias.xaml
+++ b/ObjetosSim/UserControls/ucTransporteGuias.xaml
@@ -3,14 +3,34 @@
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:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"
mc:Ignorable="d">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ObjetosSim/UserControls/ucTransporteGuias.xaml.cs b/ObjetosSim/UserControls/ucTransporteGuias.xaml.cs
index 14d9a3a..27df54b 100644
--- a/ObjetosSim/UserControls/ucTransporteGuias.xaml.cs
+++ b/ObjetosSim/UserControls/ucTransporteGuias.xaml.cs
@@ -1,49 +1,20 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+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;
+using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
-using static System.Runtime.InteropServices.JavaScript.JSType;
namespace CtrEditor.ObjetosSim
{
///
/// Interaction logic for ucTransporteGuias.xaml
///
- public class osTransporteGuias : osBase, IosBase
+ public partial class osTransporteGuias : osBase, IosBase
{
- private string _nombre = "Transporte Guias";
-
- private float _distance;
- private float _altoGuia;
-
- private float frictionCoefficient;
- private float velMax50hz; // en metros por minuto
- private float tiempoRampa;
- private bool esMarcha;
-
- private float _ancho;
- private float _alto;
- private float _left;
- private float _top;
- private float _angulo;
- private float _velocidadActual;
private osBase _osMotor = null;
- private string _motor;
- private simTransporte? TransporteCentral;
+ private simTransporte? SimGeometria;
private simGuia? Guia_Superior;
private simGuia? Guia_Inferior;
@@ -52,133 +23,63 @@ namespace CtrEditor.ObjetosSim
{
return "Transporte Guias";
}
- public string Motor
- {
- get => _motor;
- set
- {
- if (_motor != value)
- {
- _motor = value;
- OnPropertyChanged(nameof(Motor));
- }
- }
- }
-
- public override float Left
- {
- get => _left;
- set
- {
- _left = value;
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(Left));
- }
- }
- public override float Top
- {
- get => _top;
- set
- {
- _top = value;
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(Top));
- }
- }
-
- public float Ancho
- {
- get => _ancho;
- set
- {
- _ancho = value;
- OnPropertyChanged(nameof(Ancho));
- }
- }
- public float Alto
- {
- get => _alto;
- set
- {
- _alto = value;
- OnPropertyChanged(nameof(Alto));
- }
- }
-
- public float Angulo
- {
- get => _angulo;
- set
- {
- _angulo = value;
- OnPropertyChanged(nameof(Angulo));
- }
- }
-
- public float VelocidadActual
- {
- get => _velocidadActual;
- set
- {
- _velocidadActual = value;
- TransporteCentral?.SetSpeed(value);
- OnPropertyChanged(nameof(VelocidadActual));
- }
- }
-
- public float Distance
- {
- get { return _distance; }
- set
- {
- if (_distance != value)
- {
- _distance = value;
- OnPropertyChanged(nameof(Distance));
- }
- }
- }
-
- public float AltoGuia
- {
- get => _altoGuia;
- set
- {
- _altoGuia = value;
- OnPropertyChanged(nameof(AltoGuia));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
+ get => nombre;
+ set => SetProperty(ref nombre, value);
+ }
+
+ private float velocidadActual;
+ public float VelocidadActual
+ {
+ get => velocidadActual;
set
{
- if (_nombre != value)
+ if (value != velocidadActual)
{
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
+ velocidadActual = value;
+ SimGeometria?.SetSpeed(value);
+ SetProperty(ref velocidadActual, value);
+ ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
}
}
}
+ [ObservableProperty]
+ public string motor;
+ [ObservableProperty]
+ public float ancho;
+ [ObservableProperty]
+ public float alto;
+ [ObservableProperty]
+ public float angulo;
+ [ObservableProperty]
+ public float frictionCoefficient;
+ [ObservableProperty]
+ public float velMax50hz;
+ [ObservableProperty]
+ public float tiempoRampa;
+ [ObservableProperty]
+ public bool esMarcha;
+ [ObservableProperty]
+ private float distance;
+ [ObservableProperty]
+ private float altoGuia;
+
private void ActualizarGeometrias()
{
if (_visualRepresentation is ucTransporteGuias uc)
{
- UpdateRectangle(TransporteCentral, uc.Transporte, Alto, Ancho, Angulo);
+ UpdateRectangle(SimGeometria, uc.Transporte, Alto, Ancho, Angulo);
UpdateOrCreateLine(Guia_Superior, uc.GuiaSuperior);
UpdateOrCreateLine(Guia_Inferior, uc.GuiaInferior) ;
- TransporteCentral.Speed = VelocidadActual;
+ SimGeometria.Speed = VelocidadActual;
+ ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
}
}
- public float FrictionCoefficient { get => frictionCoefficient; set => frictionCoefficient = value; }
- public float VelMax50hz { get => velMax50hz; set => velMax50hz = value; }
- public float TiempoRampa { get => tiempoRampa; set => tiempoRampa = value; }
- public bool EsMarcha { get => esMarcha; set => esMarcha = value; }
-
public osTransporteGuias()
{
@@ -193,11 +94,10 @@ namespace CtrEditor.ObjetosSim
// Se llama antes de la simulacion
ActualizarGeometrias();
}
- public override void UpdateGeometryStep()
- {
- }
- public override void UpdateControl(int elapsedMilliseconds)
+ public override void SimulationStop()
{
+ // Se llama al detener la simulacion
+ ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
@@ -207,7 +107,7 @@ namespace CtrEditor.ObjetosSim
VelocidadActual = motor.Velocidad;
}
else
- _osMotor = ObtenerLink(_motor, typeof(osVMmotorSim));
+ _osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
}
public override void ucLoaded()
@@ -216,17 +116,15 @@ namespace CtrEditor.ObjetosSim
// crear el objeto de simulacion
ActualizarLeftTop();
- //simulationManager.rectangles.Add(TransporteCentral);
- //simulationManager.lines.Add(Guia_Superior);
- //simulationManager.lines.Add(Guia_Inferior);
-
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
if (_visualRepresentation is ucTransporteGuias uc)
{
- TransporteCentral = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo);
+ SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo);
Guia_Superior = AddLine(simulationManager, uc.GuiaSuperior);
Guia_Inferior = AddLine(simulationManager, uc.GuiaInferior);
+
+ CrearAnimacionStoryBoardTrasnporte(uc.Transporte);
}
Motor = Motor; // Forzar la busqueda
}
@@ -234,7 +132,7 @@ namespace CtrEditor.ObjetosSim
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
- simulationManager.Remove(TransporteCentral);
+ simulationManager.Remove(SimGeometria);
simulationManager.Remove(Guia_Superior);
simulationManager.Remove(Guia_Inferior);
}
diff --git a/ObjetosSim/UserControls/ucTransporteTTop.xaml b/ObjetosSim/UserControls/ucTransporteTTop.xaml
index 9d7416f..a9118b4 100644
--- a/ObjetosSim/UserControls/ucTransporteTTop.xaml
+++ b/ObjetosSim/UserControls/ucTransporteTTop.xaml
@@ -1,21 +1,22 @@
+ xmlns:convert="clr-namespace:CtrEditor.Convertidores">
-
-
+
-
+
+
+
-
+
\ No newline at end of file
diff --git a/ObjetosSim/UserControls/ucTransporteTTop.xaml.cs b/ObjetosSim/UserControls/ucTransporteTTop.xaml.cs
index 7be8c88..b9677d2 100644
--- a/ObjetosSim/UserControls/ucTransporteTTop.xaml.cs
+++ b/ObjetosSim/UserControls/ucTransporteTTop.xaml.cs
@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
using CtrEditor.Simulacion;
+using System.Windows.Input;
namespace CtrEditor.ObjetosSim
@@ -19,7 +20,7 @@ namespace CtrEditor.ObjetosSim
{
private osBase _osMotor = null;
- private simTransporte Simulation_Transporte;
+ private simTransporte SimGeometria;
public static string NombreClase()
{
@@ -32,36 +33,19 @@ namespace CtrEditor.ObjetosSim
set => SetProperty(ref nombre, value);
}
- private float left;
- public override float Left
- {
- get => left;
- set
- {
- CanvasSetLeftinMeter(value);
- SetProperty(ref left, value);
- }
- }
- private float top;
- public override float Top
- {
- get => top;
- set
- {
- CanvasSetTopinMeter(value);
- SetProperty(ref top, value);
- }
- }
-
private float velocidadActual;
public float VelocidadActual
{
get => velocidadActual;
set
{
- velocidadActual = value;
- Simulation_Transporte?.SetSpeed(value);
- SetProperty(ref velocidadActual, value);
+ if (value != velocidadActual)
+ {
+ velocidadActual = value;
+ SimGeometria?.SetSpeed(value);
+ SetProperty(ref velocidadActual, value);
+ ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
+ }
}
}
@@ -82,30 +66,34 @@ namespace CtrEditor.ObjetosSim
[ObservableProperty]
public bool esMarcha;
+
private void ActualizarGeometrias()
{
if (_visualRepresentation is ucTransporteTTop uc)
{
- UpdateRectangle(Simulation_Transporte, uc.Transporte,Alto,Ancho,Angulo);
- Simulation_Transporte.Speed = VelocidadActual;
+ UpdateRectangle(SimGeometria, uc.Transporte,Alto,Ancho,Angulo);
+ SimGeometria.Speed = VelocidadActual;
}
+ ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
}
-
public osTransporteTTop()
- {
+ {
Ancho = 1;
Alto = 0.10f;
}
+ public override void SimulationStop()
+ {
+ // Se llama al detener la simulacion
+ ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
+ }
public override void UpdateGeometryStart()
{
// Se llama antes de la simulacion
ActualizarGeometrias();
}
- public override void UpdateGeometryStep()
- {
- }
+
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{
if (_osMotor != null)
@@ -117,9 +105,6 @@ namespace CtrEditor.ObjetosSim
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
}
- public override void UpdateControl(int elapsedMilliseconds)
- {
- }
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
@@ -127,13 +112,16 @@ namespace CtrEditor.ObjetosSim
ActualizarLeftTop();
if (_visualRepresentation is ucTransporteTTop uc)
- Simulation_Transporte = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo);
+ {
+ SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo);
+ CrearAnimacionStoryBoardTrasnporte(uc.Transporte);
+ }
}
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
- simulationManager.Remove(Simulation_Transporte);
+ simulationManager.Remove(SimGeometria);
}
}
diff --git a/ObjetosSim/UserControls/ucVMmotorSim.xaml b/ObjetosSim/UserControls/ucVMmotorSim.xaml
index 6297680..a185e42 100644
--- a/ObjetosSim/UserControls/ucVMmotorSim.xaml
+++ b/ObjetosSim/UserControls/ucVMmotorSim.xaml
@@ -5,17 +5,33 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"
+ xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores">
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
diff --git a/ObjetosSim/UserControls/ucVMmotorSim.xaml.cs b/ObjetosSim/UserControls/ucVMmotorSim.xaml.cs
index b2930ba..20ad600 100644
--- a/ObjetosSim/UserControls/ucVMmotorSim.xaml.cs
+++ b/ObjetosSim/UserControls/ucVMmotorSim.xaml.cs
@@ -1,21 +1,10 @@
using CtrEditor.Convertidores;
using CtrEditor.Siemens;
-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;
-using CtrEditor.Simulacion;
using Newtonsoft.Json;
+using CommunityToolkit.Mvvm.ComponentModel;
namespace CtrEditor.ObjetosSim
{
@@ -24,148 +13,59 @@ namespace CtrEditor.ObjetosSim
///
///
- public class osVMmotorSim : osBase, IosBase
+ public partial class osVMmotorSim : osBase, IosBase
{
// Otros datos y métodos relevantes para la simulación
-
- private string _nombre = NombreClase();
- private float _tamano;
- private float _left;
- private float _top;
- private int _numeroMotor;
- private float _ratio;
- private float _velocidad;
- private bool _encendido;
- private float _rampaSegundos;
- private float _maxHz;
- private ImageSource _imageSource;
-
+
private VMSimMotor motState = new VMSimMotor();
public static string NombreClase()
{
return "VetroMeccanica Motor";
}
-
- [Hidden]
- [JsonIgnore]
- public ImageSource ImageSource
- {
- get { return _imageSource; }
- set
- {
- _imageSource = value;
- OnPropertyChanged(nameof(ImageSource));
- }
- }
-
- public float Tamano
- {
- get => _tamano;
- set
- {
- _tamano = value;
- OnPropertyChanged(nameof(Tamano));
- }
- }
-
- public float MaxRatedHz
- {
- get => _maxHz;
- set
- {
- _maxHz = value;
- OnPropertyChanged(nameof(Tamano));
- }
- }
-
- public float TiempoRampa
- {
- get => _rampaSegundos;
- set
- {
- if (value < 0.1f)
- value = 0.1f;
- _rampaSegundos = value;
- OnPropertyChanged(nameof(Tamano));
- }
- }
-
- public bool Encendido
- {
- get => _encendido;
- set
- {
- _encendido = value;
- OnPropertyChanged(nameof(Encendido));
- }
- }
-
- public int PLC_NumeroMotor
- {
- get => _numeroMotor;
- set
- {
- _numeroMotor = value;
- OnPropertyChanged(nameof(PLC_NumeroMotor));
- }
- }
-
-
- public override float Left
- {
- get => _left;
- set
- {
- _left = value;
- CanvasSetLeftinMeter(value);
- OnPropertyChanged(nameof(Left));
- }
- }
- public override float Top
- {
- get => _top;
- set
- {
- _top = value;
- CanvasSetTopinMeter(value);
- OnPropertyChanged(nameof(Top));
- }
- }
-
+ private string nombre = NombreClase();
public override string Nombre
{
- get => _nombre;
- set
- {
- if (_nombre != value)
- {
- _nombre = value;
- OnPropertyChanged(nameof(Nombre));
- }
- }
+ get => nombre;
+ set => SetProperty(ref nombre, value);
}
- public float Ratio {
- get => _ratio;
- set {
- _ratio = value;
- OnPropertyChanged(nameof(Ratio));
- }
+ [JsonIgnore]
+ [ObservableProperty]
+ public ImageSource imageSource_oculta;
+
+ [ObservableProperty]
+ public float tamano;
+ [ObservableProperty]
+ public float maxRatedHz;
+
+ [ObservableProperty]
+ public float tiempoRampa;
+
+ partial void OnTiempoRampaChanged(float value)
+ {
+ if (value < 0.1f)
+ value = 0.1f;
+ tiempoRampa = value;
}
- public float Velocidad {
- get => _velocidad;
- set {
- _velocidad = value;
- if (value > 0)
- ImageSource = ImageFromPath("/imagenes/motorVerde.png");
- else
- ImageSource = ImageFromPath("/imagenes/motorNegro.png");
+ [ObservableProperty]
+ public bool encendido;
+ [ObservableProperty]
+ public int pLC_NumeroMotor;
+ [ObservableProperty]
+ public float ratio;
- OnPropertyChanged(nameof(Velocidad));
- }
+ [ObservableProperty]
+ public float velocidad;
+
+ partial void OnVelocidadChanged(float value)
+ {
+ if (value > 0)
+ ImageSource_oculta = ImageFromPath("/imagenes/motorVerde.png");
+ else
+ ImageSource_oculta = ImageFromPath("/imagenes/motorNegro.png");
}
public osVMmotorSim()
@@ -174,16 +74,13 @@ namespace CtrEditor.ObjetosSim
PLC_NumeroMotor = 31;
MaxRatedHz = 100;
TiempoRampa = 3;
- ImageSource = ImageFromPath("/imagenes/motor2.png");
+ ImageSource_oculta = ImageFromPath("/imagenes/motor2.png");
}
public override void UpdateGeometryStart()
{
// Se llama antes de la simulacion
- }
- public override void UpdateGeometryStep()
- {
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) {
@@ -206,11 +103,6 @@ namespace CtrEditor.ObjetosSim
ActualizarLeftTop();
}
- public override void ucUnLoaded()
- {
- // El UserControl se esta eliminando
- // eliminar el objeto de simulacion
- }
}
public partial class ucVMmotorSim : UserControl, IDataContainer
diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs
index 91edf45..254ef1a 100644
--- a/ObjetosSim/osBase.cs
+++ b/ObjetosSim/osBase.cs
@@ -21,6 +21,7 @@ using Siemens.Simatic.Simulation.Runtime;
using System.Windows.Media.Imaging;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
+using System.Windows.Media.Animation;
namespace CtrEditor.ObjetosSim
{
@@ -65,12 +66,33 @@ namespace CtrEditor.ObjetosSim
}
- public abstract class osBase : ObservableObject
+ public abstract partial class osBase : ObservableObject
{
public virtual string Nombre { get; set; } = "osBase";
+ [JsonIgnore]
+ private Storyboard _storyboard;
+
+ [ObservableProperty]
+ private float left;
+
+ partial void OnLeftChanged(float value)
+ {
+ CanvasSetLeftinMeter(value);
+ LeftChanged(value);
+ }
+ public virtual void LeftChanged(float value) { }
+
+ [ObservableProperty]
+ private float top;
+
+ partial void OnTopChanged(float value)
+ {
+ CanvasSetTopinMeter(value);
+ TopChanged(value);
+ }
+
+ public virtual void TopChanged(float value) { }
- public abstract float Left { get; set; }
- public abstract float Top { get; set; }
public bool Inicializado = false;
public bool AutoCreated = false;
@@ -82,12 +104,25 @@ namespace CtrEditor.ObjetosSim
[JsonIgnore]
protected UserControl? _visualRepresentation = null;
- public abstract void UpdateControl(int elapsedMilliseconds);
- public abstract void UpdateGeometryStart();
- public abstract void UpdateGeometryStep();
- public abstract void UpdatePLC(PLCModel plc, int elapsedMilliseconds);
- public abstract void ucLoaded();
- public abstract void ucUnLoaded();
+ public virtual void UpdateControl(int elapsedMilliseconds) { }
+ public virtual void UpdateGeometryStart()
+ {
+ // Se llama antes de la simulacion
+ }
+ public virtual void SimulationStop() { }
+ public virtual void UpdateGeometryStep() { }
+ public virtual void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { }
+ public virtual void ucLoaded()
+ {
+ // El UserControl ya se ha cargado y podemos obtener las coordenadas para
+ // crear el objeto de simulacion
+ ActualizarLeftTop();
+ }
+ public virtual void ucUnLoaded()
+ {
+ // El UserControl se esta eliminando
+ // eliminar el objeto de simulacion
+ }
[JsonIgnore]
public MainViewModel _mainViewModel;
@@ -129,10 +164,41 @@ namespace CtrEditor.ObjetosSim
return null;
}
+ protected void CrearAnimacionStoryBoardTrasnporte(System.Windows.Shapes.Rectangle transporte)
+ {
+ if (_visualRepresentation == null) return;
+ if (transporte == null) return;
+
+ _storyboard = new Storyboard();
+ var animation = new DoubleAnimation
+ {
+ From = 0,
+ To = 20, // Total Pixels Brush
+ Duration = TimeSpan.FromSeconds(PixelToMeter.Instance.calc.PixelsToMeters(20) * 60),
+ RepeatBehavior = RepeatBehavior.Forever
+ };
+ Storyboard.SetTarget(animation, transporte);
+ Storyboard.SetTargetProperty(animation, new PropertyPath("(Rectangle.Fill).(VisualBrush.Transform).(TransformGroup.Children)[0].(TranslateTransform.X)"));
+ _storyboard.Children.Add(animation);
+ _storyboard.Begin();
+ _storyboard.SetSpeedRatio(0);
+ }
+
+ protected void ActualizarAnimacionStoryBoardTransporte(float velocidadActual)
+ {
+ if (_visualRepresentation == null) return;
+ if (_storyboard == null) return;
+
+ if (!_mainViewModel.IsSimulationRunning)
+ _storyboard.SetSpeedRatio(0);
+ else
+ _storyboard.SetSpeedRatio(velocidadActual);
+ }
+
public void ActualizarLeftTop()
{
- Left = Left;
- Top = Top;
+ CanvasSetLeftinMeter(Left);
+ CanvasSetTopinMeter(Top);
}
public bool LeerBitTag(PLCModel plc, string Tag)
diff --git a/Simulacion/FPhysics.cs b/Simulacion/FPhysics.cs
index 011d7a1..ef55062 100644
--- a/Simulacion/FPhysics.cs
+++ b/Simulacion/FPhysics.cs
@@ -34,7 +34,10 @@ namespace CtrEditor.Simulacion
{
Body.SetTransform(new Vector2(x, y), Body.Rotation);
}
-
+ public void SetPosition(Vector2 centro)
+ {
+ Body.SetTransform(centro, Body.Rotation);
+ }
}
public class simCurve : simBase