Actualizado a CommunityToolkit.Mvvm.ComponentModel para todos los UserControl

This commit is contained in:
Miguel 2024-05-22 19:21:39 +02:00
parent 260362dc24
commit 0e174fc308
29 changed files with 629 additions and 1562 deletions

View File

@ -11,25 +11,6 @@ using System.Windows.Media;
namespace CtrEditor.Convertidores 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 class HalfWidthConverter : IValueConverter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

View File

@ -11,7 +11,6 @@
<ItemGroup> <ItemGroup>
<Compile Remove="ObjetosSim\ucBasicExample.xaml.cs" /> <Compile Remove="ObjetosSim\ucBasicExample.xaml.cs" />
<Compile Remove="ObjetosSim\ucTransporteCurva.xaml.cs" /> <Compile Remove="ObjetosSim\ucTransporteCurva.xaml.cs" />
<Compile Remove="ObjetosSim\UserControls\ucBasicExample.xaml.cs" />
<Compile Remove="Simulacion\GeometrySimulator.cs" /> <Compile Remove="Simulacion\GeometrySimulator.cs" />
</ItemGroup> </ItemGroup>
@ -44,12 +43,9 @@
<ItemGroup> <ItemGroup>
<Page Remove="ObjetosSim\ucBasicExample.xaml" /> <Page Remove="ObjetosSim\ucBasicExample.xaml" />
<Page Remove="ObjetosSim\ucTransporteCurva.xaml" /> <Page Remove="ObjetosSim\ucTransporteCurva.xaml" />
<Page Remove="ObjetosSim\UserControls\ucBasicExample.xaml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="ObjetosSim\UserControls\ucBasicExample.xaml" />
<None Include="ObjetosSim\UserControls\ucBasicExample.xaml.cs" />
<None Include="Simulacion\GeometrySimulator.cs" /> <None Include="Simulacion\GeometrySimulator.cs" />
</ItemGroup> </ItemGroup>

View File

@ -389,6 +389,8 @@ namespace CtrEditor
private void StartSimulation() private void StartSimulation()
{ {
IsSimulationRunning = true;
foreach (var objetoSimulable in ObjetosSimulables) foreach (var objetoSimulable in ObjetosSimulables)
objetoSimulable.UpdateGeometryStart(); objetoSimulable.UpdateGeometryStart();
@ -399,11 +401,15 @@ namespace CtrEditor
_timerSimulacion.Start(); _timerSimulacion.Start();
simulationManager.stopwatch.Start(); simulationManager.stopwatch.Start();
stopwatch_SimRefresh.Start(); stopwatch_SimRefresh.Start();
IsSimulationRunning = true;
} }
private void StopSimulation() private void StopSimulation()
{ {
IsSimulationRunning = false;
foreach (var objetoSimulable in ObjetosSimulables)
objetoSimulable.SimulationStop();
if (Debug_SimulacionCreado) if (Debug_SimulacionCreado)
{ {
simulationManager.Debug_ClearSimulationShapes(); simulationManager.Debug_ClearSimulationShapes();
@ -412,7 +418,6 @@ namespace CtrEditor
_timerSimulacion.Stop(); _timerSimulacion.Stop();
simulationManager.stopwatch.Stop(); simulationManager.stopwatch.Stop();
stopwatch_SimRefresh.Stop(); stopwatch_SimRefresh.Stop();
IsSimulationRunning = false;
} }
private void OnTickSimulacion(object sender, EventArgs e) private void OnTickSimulacion(object sender, EventArgs e)

View File

@ -1,17 +1,6 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CtrEditor.ObjetosSim.UserControls namespace CtrEditor.ObjetosSim.UserControls
{ {

View File

@ -5,20 +5,33 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osBasicExample />
</UserControl.DataContext>
<Grid> <Grid>
<Image Source="/motor2.png" <Grid.RowDefinitions>
Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" <RowDefinition Height="Auto" />
Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}" <RowDefinition Height="*" />
Stretch="Uniform"> </Grid.RowDefinitions>
<Image.RenderTransform>
<RotateTransform Angle="{Binding Angulo}" /> <Label Grid.Row="0" Content="{Binding Nombre}"
</Image.RenderTransform> HorizontalAlignment="Center"
</Image> VerticalAlignment="Center"
Background="Transparent"
Foreground="Black"/>
<Image Grid.Row="1" Source="{Binding ImageSource_oculta}"
Width="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
Height="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
Stretch="Uniform"/>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -1,135 +1,104 @@
using CtrEditor.Convertidores; using CtrEditor.Convertidores;
using CtrEditor.Siemens; 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;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using Newtonsoft.Json;
using System.Windows.Navigation; using CommunityToolkit.Mvvm.ComponentModel;
using System.Windows.Shapes;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucBasicExample.xaml /// Interaction logic for ucBasicExample.xaml
/// </summary> /// </summary>
public class osBasicExample : osBase, IosBase ///
public partial class osBasicExample : 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 = "Ejemplo"; public static string NombreClase()
private float _ancho;
private float _alto;
private float _angulo;
private float _left;
private float _top;
public override float Left
{ {
get => _left; return "Ejemplo";
set
{
_left = value;
CanvasSetLeftinMeter(value);
OnPropertyChanged(nameof(Left));
} }
} private string nombre = NombreClase();
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 override string Nombre public override string Nombre
{ {
get => _nombre; get => nombre;
set set => SetProperty(ref nombre, value);
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
} }
[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() public osBasicExample()
{ {
Ancho = 0.30f; Tamano = 0.30f;
Alto = 0.30f; PLC_NumeroMotor = 31;
MaxRatedHz = 100;
TiempoRampa = 3;
ImageSource_oculta = ImageFromPath("/imagenes/motor2.png");
} }
public override void UpdateGeometryStart() public override void UpdateGeometryStart()
{ {
// Se llama antes de la simulacion // Se llama antes de la simulacion
}
public override void UpdateGeometryStep()
{
} }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
} }
public override void UpdateControl(int elapsedMilliseconds) public override void UpdateControl(int elapsedMilliseconds)
{ {
// Calculamos la velocidad
} }
public override void ucLoaded() public override void ucLoaded()
{ {
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion // crear el objeto de simulacion
ActualizarLeftTop(); ActualizarLeftTop();
}
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
}
} }
}
public partial class ucBasicExample : UserControl, IDataContainer public partial class ucBasicExample : UserControl, IDataContainer
{ {
@ -149,13 +118,7 @@ namespace CtrEditor.ObjetosSim
{ {
Datos?.ucUnLoaded(); Datos?.ucUnLoaded();
} }
public void Resize(float width, float height) { 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 Move(float LeftPixels, float TopPixels) public void Move(float LeftPixels, float TopPixels)
{ {
if (Datos != null) if (Datos != null)
@ -164,12 +127,7 @@ namespace CtrEditor.ObjetosSim
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels); Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
} }
} }
public void Rotate(float Angle) public void Rotate(float Angle) { }
{
if (Datos != null)
if (Datos is osBasicExample datos)
datos.Angulo = Angle;
}
public void Highlight(bool State) { } public void Highlight(bool State) { }
public int ZIndex() public int ZIndex()
{ {

View File

@ -1,22 +1,10 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; 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 Microsoft.Xna.Framework;
using CtrEditor.Convertidores; using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using Newtonsoft.Json.Linq; using CommunityToolkit.Mvvm.ComponentModel;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
@ -25,13 +13,9 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
/// ///
public class osBotella : osBase, IosBase public partial class osBotella : osBase, IosBase
{ {
private float _diametro; private simBotella SimGeometria;
private float _mass;
private Vector2 _centro = new Vector2(); // Centro
private string _nombre = NombreClase();
private simBotella Simulacion_Botella;
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
@ -39,92 +23,48 @@ namespace CtrEditor.ObjetosSim
{ {
return "Botella"; return "Botella";
} }
private string nombre = NombreClase();
public float Diametro { public override string Nombre
get => _diametro;
set
{ {
_diametro = value; get => nombre;
Simulacion_Botella?.SetDiameter(Diametro); set => SetProperty(ref nombre, value);
OnPropertyChanged(nameof(Diametro));
}
} }
public float Mass { [ObservableProperty]
get => _mass; private float diametro;
set
partial void OnDiametroChanged(float value)
{ {
_mass = value; SimGeometria?.SetDiameter(Diametro);
Simulacion_Botella?.SetMass(value);
OnPropertyChanged(nameof(Mass));
}
} }
public override float Left [ObservableProperty]
private float mass;
partial void OnMassChanged(float value)
{ {
get => _centro.X-Diametro/2; SimGeometria?.SetMass(value);
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));
}
} }
public float CenterX public Vector2 GetCentro()
{ {
get => _centro.X; return new Vector2 (Left+Diametro/2,Top+Diametro/2);
set
{
_centro.X = value;
CanvasSetLeftinMeter(Left);
OnPropertyChanged(nameof(CenterX));
OnPropertyChanged(nameof(Left));
} }
}
public float CenterY public void SetCentro(float x, float y)
{ Left = x; Top = y; }
public void SetCentro(Vector2 centro)
{ {
get => _centro.Y; Left = centro.X - Diametro / 2;
set Top = centro.Y - Diametro / 2;
{
_centro.Y = value;
CanvasSetTopinMeter(Top);
OnPropertyChanged(nameof(CenterY));
OnPropertyChanged(nameof(Top));
}
} }
private void ActualizarGeometrias() private void ActualizarGeometrias()
{ {
if (Simulacion_Botella != null) if (SimGeometria != null)
{ {
Simulacion_Botella.SetDiameter(Diametro); SimGeometria.SetDiameter(Diametro);
Simulacion_Botella.SetPosition(CenterX, CenterY); SimGeometria.SetPosition(GetCentro());
}
}
public override string Nombre
{
get => _nombre;
set
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
} }
} }
@ -139,6 +79,11 @@ namespace CtrEditor.ObjetosSim
// Se llama antes de la simulacion // Se llama antes de la simulacion
ActualizarGeometrias(); ActualizarGeometrias();
} }
public override void SimulationStop()
{
// Se llama al detener la simulacion. Util para detener Storyboards
}
public override void UpdateGeometryStep() public override void UpdateGeometryStep()
{ {
// Se llama antes de la simulacion // Se llama antes de la simulacion
@ -149,10 +94,9 @@ namespace CtrEditor.ObjetosSim
public override void UpdateControl(int elapsedMilliseconds) public override void UpdateControl(int elapsedMilliseconds)
{ {
CenterX = Simulacion_Botella.CenterX; SetCentro(SimGeometria.Center);
CenterY = Simulacion_Botella.CenterY;
if (Simulacion_Botella.Descartar) // Ha sido marcada para remover if (SimGeometria.Descartar) // Ha sido marcada para remover
RemoverDesdeSimulacion = true; RemoverDesdeSimulacion = true;
} }
@ -161,13 +105,13 @@ namespace CtrEditor.ObjetosSim
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion // crear el objeto de simulacion
ActualizarLeftTop(); ActualizarLeftTop();
Simulacion_Botella = simulationManager.AddCircle(Diametro, _centro, Mass); SimGeometria = simulationManager.AddCircle(Diametro, GetCentro(), Mass);
} }
public override void ucUnLoaded() public override void ucUnLoaded()
{ {
// El UserControl se esta eliminando // El UserControl se esta eliminando
// eliminar el objeto de simulacion // eliminar el objeto de simulacion
simulationManager.Remove(Simulacion_Botella); simulationManager.Remove(SimGeometria);
} }
} }

View File

@ -6,12 +6,17 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:convert="clr-namespace:CtrEditor.Convertidores" xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osBoton Color="#FFADE6C0" ColorButton_oculto="#FFC72323"/>
</UserControl.DataContext>
<Grid> <Grid>
<Border x:Name="BackgroundRectangle" <Border x:Name="BackgroundRectangle"
BorderBrush="Black" BorderBrush="Black"
@ -22,7 +27,7 @@
VerticalAlignment="Top" VerticalAlignment="Top"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Background="Gray"/> Background="Gray"/>
<Ellipse Fill="{Binding ColorButton}" <Ellipse Fill="{Binding ColorButton_oculto}"
Stroke="Black" Stroke="Black"
StrokeThickness="2" StrokeThickness="2"
Width="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}" Width="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"

View File

@ -1,4 +1,5 @@
using CtrEditor.Convertidores; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -10,114 +11,41 @@ namespace CtrEditor.ObjetosSim
/// <summary> /// <summary>
/// Interaction logic for ucBoton.xaml /// Interaction logic for ucBoton.xaml
/// </summary> /// </summary>
public class osBoton : osBase, IosBase public partial class osBoton : 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 = "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() public static string NombreClase()
{ {
return "Boton"; return "Boton";
} }
private string nombre = NombreClase();
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));
}
}
public override string Nombre public override string Nombre
{ {
get => _nombre; get => nombre;
set set => SetProperty(ref nombre, value);
}
[ObservableProperty]
private Brush color;
[ObservableProperty]
private Brush colorButton_oculto;
[ObservableProperty]
public float tamano;
[ObservableProperty]
public bool estado;
partial void OnEstadoChanged(bool value)
{ {
if (_nombre != value) if (value)
{ ColorButton_oculto = Brushes.LightGreen;
_nombre = value; else
OnPropertyChanged(nameof(Nombre)); ColorButton_oculto = Color;
}
}
}
public string Tag
{
get => _tag;
set
{
if (_tag != value)
{
_tag = value;
OnPropertyChanged(nameof(Tag));
}
}
} }
[ObservableProperty]
public string tag;
public void ButtonDownCommand() public void ButtonDownCommand()
{ {
Estado = true; Estado = true;
@ -140,13 +68,10 @@ namespace CtrEditor.ObjetosSim
{ {
// Se llama antes de la simulacion // Se llama antes de la simulacion
}
public override void UpdateGeometryStep()
{
} }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
plc.EscribirTagBool(_tag, Estado); plc.EscribirTagBool(Tag, Estado);
} }
public override void UpdateControl(int elapsedMilliseconds) public override void UpdateControl(int elapsedMilliseconds)

View File

@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
@ -20,6 +21,10 @@
</Storyboard> </Storyboard>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osDescarte/>
</UserControl.DataContext>
<Grid> <Grid>
<Ellipse <Ellipse
Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Diametro, Converter={StaticResource MeterToPixelConverter}}"

View File

@ -5,101 +5,67 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
using CommunityToolkit.Mvvm.ComponentModel;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucDescarte.xaml /// Interaction logic for ucDescarte.xaml
/// </summary> /// </summary>
public class osDescarte : osBase, IosBase public partial class osDescarte : osBase, IosBase
{ {
// Otros datos y métodos relevantes para la simulación // 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() public static string NombreClase()
{ {
return "Descarte"; return "Descarte";
} }
public override float Left private string nombre = NombreClase();
{
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));
}
}
public override string Nombre public override string Nombre
{ {
get => _nombre; get => nombre;
set set => SetProperty(ref nombre, value);
}
[ObservableProperty]
private float diametro;
partial void OnDiametroChanged(float value)
{ {
if (_nombre != value) SimGeometria?.SetDiameter(Diametro);
}
public Vector2 GetCentro()
{ {
_nombre = value; return new Vector2(Left + Diametro / 2, Top + Diametro / 2);
OnPropertyChanged(nameof(Nombre));
} }
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() private void ActualizarGeometrias()
{ {
if (AreaDeDescarte != null) if (SimGeometria != null)
{ {
AreaDeDescarte.SetDiameter(Diametro); SimGeometria.SetDiameter(Diametro);
AreaDeDescarte.SetPosition(CenterX, CenterY); SimGeometria.SetPosition(GetCentro());
} }
} }
@ -129,13 +95,13 @@ namespace CtrEditor.ObjetosSim
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion // crear el objeto de simulacion
ActualizarLeftTop(); ActualizarLeftTop();
AreaDeDescarte = simulationManager.AddDescarte(Diametro, _centro); SimGeometria = simulationManager.AddDescarte(Diametro, GetCentro());
} }
public override void ucUnLoaded() public override void ucUnLoaded()
{ {
// El UserControl se esta eliminando // El UserControl se esta eliminando
// eliminar el objeto de simulacion // eliminar el objeto de simulacion
simulationManager.Remove(AreaDeDescarte); simulationManager.Remove(SimGeometria);
} }
} }

View File

@ -5,12 +5,17 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> xmlns:convert="clr-namespace:CtrEditor.Convertidores"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osFiller/>
</UserControl.DataContext>
<Grid> <Grid>
<Image Source="/imagenes/filler.png" <Image Source="/imagenes/filler.png"
Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}"

View File

@ -1,180 +1,53 @@
using CtrEditor.Convertidores; using CtrEditor.Convertidores;
using CtrEditor.Siemens; 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;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using CommunityToolkit.Mvvm.ComponentModel;
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;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucFiller.xaml /// Interaction logic for ucFiller.xaml
/// </summary> /// </summary>
public class osFiller : osBase, IosBase public partial class osFiller : 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 = "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 TiempoRestante;
private float _leftSalida;
private float _topSalida;
private osBotella UltimaBotella; private osBotella UltimaBotella;
public static string NombreClase() public static string NombreClase()
{ {
return "Filler"; return "Filler";
} }
public float OffsetLeftSalida private string nombre = NombreClase();
{
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));
}
}
public override string Nombre public override string Nombre
{ {
get => _nombre; get => nombre;
set set => SetProperty(ref nombre, value);
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
}
} }
[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() public osFiller()
{ {
Ancho = 0.30f; Ancho = 0.30f;
@ -185,14 +58,6 @@ namespace CtrEditor.ObjetosSim
Botellas_hora = 10000; 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) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
Consenso = LeerBitTag(plc, Tag_consenso); Consenso = LeerBitTag(plc, Tag_consenso);
@ -249,11 +114,6 @@ namespace CtrEditor.ObjetosSim
// crear el objeto de simulacion // crear el objeto de simulacion
ActualizarLeftTop(); ActualizarLeftTop();
} }
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
}
} }

View File

@ -1,24 +1,9 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; 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 CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores; using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
@ -39,26 +24,6 @@ namespace CtrEditor.ObjetosSim
get => nombre; get => nombre;
set => SetProperty(ref nombre, value); 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] [ObservableProperty]
public float ancho; public float ancho;

View File

@ -5,12 +5,17 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls" xmlns:local="clr-namespace:CtrEditor.ObjetosSim.UserControls"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim.UserControls"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osPhotocell Color="#FFCA1C1C"/>
</UserControl.DataContext>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
@ -26,7 +31,9 @@
</Grid.RenderTransform> </Grid.RenderTransform>
<!-- Label en la primera columna --> <!-- Label en la primera columna -->
<Label Content="{Binding Nombre}" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="0"/> <Label Content="{Binding Nombre}" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="0" Foreground="{Binding Color}" >
</Label>
<Image Source="/Icons/fotocelula.png" <Image Source="/Icons/fotocelula.png"
Width="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=3}" Width="{Binding Alto, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=3}"

View File

@ -4,6 +4,7 @@ using CtrEditor.Siemens;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel;
namespace CtrEditor.ObjetosSim.UserControls namespace CtrEditor.ObjetosSim.UserControls
@ -11,145 +12,73 @@ namespace CtrEditor.ObjetosSim.UserControls
/// <summary> /// <summary>
/// Interaction logic for ucPhotocell.xaml /// Interaction logic for ucPhotocell.xaml
/// </summary> /// </summary>
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; private simBarrera Simulation_Photocell;
public static string NombreClase() public static string NombreClase()
{ {
return "Photocell"; return "Photocell";
} }
private string nombre = NombreClase();
public override string Nombre
{
get => nombre;
set => SetProperty(ref nombre, value);
}
public Brush Color [ObservableProperty]
public Brush color;
[ObservableProperty]
public bool luzCortada;
partial void OnLuzCortadaChanged(bool value)
{ {
get => _color; if (LuzCortada)
set
{
_color = value;
OnPropertyChanged(nameof(Color));
}
}
public bool LuzCortada
{
get => _luzCortada;
set
{
if (_luzCortada != value)
{
_luzCortada = value;
if (_luzCortada)
Color = Brushes.Blue; Color = Brushes.Blue;
else else
Color = Brushes.Green; Color = Brushes.Green;
OnPropertyChanged(nameof(LuzCortada));
}
}
} }
public bool Tipo_NC [ObservableProperty]
{ public bool tipo_NC;
get => _tipoNC;
set
{
if (_tipoNC != value)
{
_tipoNC = value;
OnPropertyChanged(nameof(Tipo_NC));
}
}
}
public string TagPhotocell_OUT [ObservableProperty]
{ public string tagPhotocell_OUT;
get => _tagPhotocellOUT;
set
{
if (_tagPhotocellOUT != value)
{
_tagPhotocellOUT = value;
OnPropertyChanged(nameof(TagPhotocell_OUT));
}
}
}
public override float Left
public override void LeftChanged(float value)
{ {
get => _left;
set
{
_left = value;
ActualizarGeometrias(); ActualizarGeometrias();
CanvasSetLeftinMeter(value);
OnPropertyChanged(nameof(Left));
}
}
public override float Top
{
get => _top;
set
{
_top = value;
ActualizarGeometrias();
CanvasSetTopinMeter(value);
OnPropertyChanged(nameof(Top));
}
} }
public float Ancho public override void TopChanged(float value)
{ {
get => _ancho;
set
{
_ancho = value;
ActualizarGeometrias(); ActualizarGeometrias();
OnPropertyChanged(nameof(Ancho));
}
} }
public float Alto [ObservableProperty]
public float ancho;
partial void OnAnchoChanged(float value)
{ {
get => _altoPhotocell;
set
{
_altoPhotocell = value;
ActualizarGeometrias(); ActualizarGeometrias();
OnPropertyChanged(nameof(Alto));
}
} }
public float Angulo [ObservableProperty]
public float alto;
partial void OnAltoChanged(float value)
{ {
get => _angulo;
set
{
_angulo = value;
ActualizarGeometrias(); ActualizarGeometrias();
OnPropertyChanged(nameof(Angulo));
}
} }
public override string Nombre [ObservableProperty]
public float angulo;
partial void OnAnguloChanged(float value)
{ {
get => _nombre; ActualizarGeometrias();
set
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
}
} }
private void ActualizarGeometrias() private void ActualizarGeometrias()

View File

@ -5,11 +5,17 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osSensTemperatura />
</UserControl.DataContext>
<Grid> <Grid>
<Border x:Name="BackgroundRectangle" <Border x:Name="BackgroundRectangle"
BorderBrush="Black" BorderBrush="Black"

View File

@ -1,149 +1,44 @@
using CtrEditor.Convertidores; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using Siemens.Simatic.Simulation.Runtime;
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.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 namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucSensTemperatura.xaml /// Interaction logic for ucSensTemperatura.xaml
/// </summary> /// </summary>
public class osSensTemperatura : osBase, IosBase public partial class osSensTemperatura : 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 = "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() public static string NombreClase()
{ {
return "Temperatura"; return "Temperatura";
} }
public string Tag private string nombre = NombreClase();
{
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));
}
}
public override string Nombre public override string Nombre
{ {
get => _nombre; get => nombre;
set set => SetProperty(ref nombre, value);
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
}
} }
[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() public osSensTemperatura()
{ {
Ancho = 0.4f; Ancho = 0.4f;
@ -152,23 +47,11 @@ namespace CtrEditor.ObjetosSim
Min_OUT_Scaled = 0; 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) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
EscribirWordTagScaled(plc, Tag, Value, 0, 100, Min_OUT_Scaled, Max_OUT_Scaled); EscribirWordTagScaled(plc, Tag, Value, 0, 100, Min_OUT_Scaled, Max_OUT_Scaled);
} }
public override void UpdateControl(int elapsedMilliseconds)
{
}
public override void ucLoaded() public override void ucLoaded()
{ {
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para
@ -176,11 +59,6 @@ namespace CtrEditor.ObjetosSim
ActualizarLeftTop(); ActualizarLeftTop();
} }
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
}
} }

View File

@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources> <UserControl.Resources>
@ -13,6 +14,10 @@
<convert:WidthPercentageConverter x:Key="WidthPercentageConverter"/> <convert:WidthPercentageConverter x:Key="WidthPercentageConverter"/>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osTanque Alto="1" Ancho="1" Angulo="-4" />
</UserControl.DataContext>
<Grid> <Grid>
<Image x:Name="TankImage" <Image x:Name="TankImage"
Source="/imagenes/tank.png" Source="/imagenes/tank.png"

View File

@ -1,253 +1,58 @@
using CtrEditor.Convertidores; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using Newtonsoft.Json.Linq;
using Siemens.Simatic.Simulation.Runtime;
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.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 static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucTanque.xaml /// Interaction logic for ucTanque.xaml
/// </summary> /// </summary>
public class osTanque : osBase, IosBase public partial class osTanque : 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 = "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() public static string NombreClase()
{ {
return "Tanque"; return "Tanque";
} }
public float Capacidad_Litros private string nombre = NombreClase();
{
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));
}
}
public override string Nombre public override string Nombre
{ {
get => _nombre; get => nombre;
set set => SetProperty(ref nombre, value);
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
}
} }
[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() public osTanque()
{ {
Ancho = 0.30f; Ancho = 0.30f;
@ -256,20 +61,11 @@ namespace CtrEditor.ObjetosSim
Min_OUT_Scaled = 0; 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) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
EscribirWordTagScaled(plc, TagNivel_Word, Level, 0, 100, Min_OUT_Scaled, Max_OUT_Scaled); EscribirWordTagScaled(plc, TagNivel_Word, Level, 0, 100, Min_OUT_Scaled, Max_OUT_Scaled);
Ingreso_Abierto = LeerBitTag(plc, _tagIngresoAbierto_Bool); Ingreso_Abierto = LeerBitTag(plc, TagIngresoAbierto_Bool);
Salida_Abierta = LeerBitTag(plc, _tagSalidaAbierta_Bool); Salida_Abierta = LeerBitTag(plc, TagSalidaAbierta_Bool);
} }
public override void UpdateControl(int elapsedMilliseconds) public override void UpdateControl(int elapsedMilliseconds)
@ -294,12 +90,6 @@ namespace CtrEditor.ObjetosSim
ActualizarLeftTop(); ActualizarLeftTop();
} }
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
}
} }
public partial class ucTanque : UserControl, IDataContainer public partial class ucTanque : UserControl, IDataContainer

View File

@ -1,5 +1,4 @@
using System.Configuration; using System.Windows;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores; using CtrEditor.Convertidores;
@ -36,27 +35,6 @@ namespace CtrEditor.ObjetosSim
set => SetProperty(ref nombre, value); 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] [ObservableProperty]
private float radioExterno; private float radioExterno;
[ObservableProperty] [ObservableProperty]
@ -115,9 +93,6 @@ namespace CtrEditor.ObjetosSim
// Se llama antes de la simulacion // Se llama antes de la simulacion
ActualizarGeometrias(); ActualizarGeometrias();
} }
public override void UpdateGeometryStep()
{
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
if (_osMotor != null) if (_osMotor != null)
@ -129,9 +104,6 @@ namespace CtrEditor.ObjetosSim
_osMotor = ObtenerLink(_motor, typeof(osVMmotorSim)); _osMotor = ObtenerLink(_motor, typeof(osVMmotorSim));
} }
public override void UpdateControl(int elapsedMilliseconds)
{
}
public override void ucLoaded() public override void ucLoaded()
{ {
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para

View File

@ -3,14 +3,34 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores" xmlns:convert="clr-namespace:CtrEditor.Convertidores"
mc:Ignorable="d"> mc:Ignorable="d">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<convert:DistanceToMarginConverter x:Key="DistanceToMarginConverter"/> <convert:DistanceToMarginConverter x:Key="DistanceToMarginConverter"/>
<!-- Define the VisualBrush for the conveyor belt pattern -->
<VisualBrush x:Key="BeltBrush" TileMode="Tile" Viewport="0,0,20,10" ViewportUnits="Absolute" Viewbox="0,0,20,10" ViewboxUnits="Absolute">
<VisualBrush.Transform>
<TransformGroup>
<TranslateTransform/>
</TransformGroup>
</VisualBrush.Transform>
<VisualBrush.Visual>
<Canvas>
<Rectangle Fill="Gray" Width="10" Height="10"/>
<Rectangle Fill="DarkGray" Width="10" Height="10" Canvas.Left="10"/>
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osTransporteGuias/>
</UserControl.DataContext>
<Grid> <Grid>
<Canvas> <Canvas>
<StackPanel x:Name="RectanglesContainer"> <StackPanel x:Name="RectanglesContainer">
@ -19,8 +39,9 @@
</StackPanel.RenderTransform> </StackPanel.RenderTransform>
<Rectangle x:Name="GuiaSuperior" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter}}" Fill="Blue" <Rectangle x:Name="GuiaSuperior" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter}}" Fill="Blue"
Margin="{Binding Distance, Converter={StaticResource DistanceToMarginConverter}}"/> Margin="{Binding Distance, Converter={StaticResource DistanceToMarginConverter}}"/>
<Rectangle x:Name="Transporte" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}" Fill="Gray" <Rectangle x:Name="Transporte" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}"
Margin="{Binding Distance, Converter={StaticResource DistanceToMarginConverter}}"/> Margin="{Binding Distance, Converter={StaticResource DistanceToMarginConverter}}"
Fill="{StaticResource BeltBrush}"/>
<Rectangle x:Name="GuiaInferior" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter}}" Fill="Blue"/> <Rectangle x:Name="GuiaInferior" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding AltoGuia, Converter={StaticResource MeterToPixelConverter}}" Fill="Blue"/>
</StackPanel> </StackPanel>
</Canvas> </Canvas>

View File

@ -1,49 +1,20 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using CommunityToolkit.Mvvm.ComponentModel;
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.Convertidores; using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
/// <summary> /// <summary>
/// Interaction logic for ucTransporteGuias.xaml /// Interaction logic for ucTransporteGuias.xaml
/// </summary> /// </summary>
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 osBase _osMotor = null;
private string _motor;
private simTransporte? TransporteCentral; private simTransporte? SimGeometria;
private simGuia? Guia_Superior; private simGuia? Guia_Superior;
private simGuia? Guia_Inferior; private simGuia? Guia_Inferior;
@ -52,133 +23,63 @@ namespace CtrEditor.ObjetosSim
{ {
return "Transporte Guias"; return "Transporte Guias";
} }
public string Motor private string nombre = NombreClase();
{
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));
}
}
public override string Nombre public override string Nombre
{ {
get => _nombre; get => nombre;
set => SetProperty(ref nombre, value);
}
private float velocidadActual;
public float VelocidadActual
{
get => velocidadActual;
set set
{ {
if (_nombre != value) if (value != velocidadActual)
{ {
_nombre = value; velocidadActual = value;
OnPropertyChanged(nameof(Nombre)); 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() private void ActualizarGeometrias()
{ {
if (_visualRepresentation is ucTransporteGuias uc) 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_Superior, uc.GuiaSuperior);
UpdateOrCreateLine(Guia_Inferior, uc.GuiaInferior) ; 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() public osTransporteGuias()
{ {
@ -193,11 +94,10 @@ namespace CtrEditor.ObjetosSim
// Se llama antes de la simulacion // Se llama antes de la simulacion
ActualizarGeometrias(); ActualizarGeometrias();
} }
public override void UpdateGeometryStep() public override void SimulationStop()
{
}
public override void UpdateControl(int elapsedMilliseconds)
{ {
// Se llama al detener la simulacion
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
} }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
@ -207,7 +107,7 @@ namespace CtrEditor.ObjetosSim
VelocidadActual = motor.Velocidad; VelocidadActual = motor.Velocidad;
} }
else else
_osMotor = ObtenerLink(_motor, typeof(osVMmotorSim)); _osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
} }
public override void ucLoaded() public override void ucLoaded()
@ -216,17 +116,15 @@ namespace CtrEditor.ObjetosSim
// crear el objeto de simulacion // crear el objeto de simulacion
ActualizarLeftTop(); 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 // El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion // crear el objeto de simulacion
if (_visualRepresentation is ucTransporteGuias uc) 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_Superior = AddLine(simulationManager, uc.GuiaSuperior);
Guia_Inferior = AddLine(simulationManager, uc.GuiaInferior); Guia_Inferior = AddLine(simulationManager, uc.GuiaInferior);
CrearAnimacionStoryBoardTrasnporte(uc.Transporte);
} }
Motor = Motor; // Forzar la busqueda Motor = Motor; // Forzar la busqueda
} }
@ -234,7 +132,7 @@ namespace CtrEditor.ObjetosSim
{ {
// El UserControl se esta eliminando // El UserControl se esta eliminando
// eliminar el objeto de simulacion // eliminar el objeto de simulacion
simulationManager.Remove(TransporteCentral); simulationManager.Remove(SimGeometria);
simulationManager.Remove(Guia_Superior); simulationManager.Remove(Guia_Superior);
simulationManager.Remove(Guia_Inferior); simulationManager.Remove(Guia_Inferior);
} }

View File

@ -3,19 +3,20 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores" xmlns:convert="clr-namespace:CtrEditor.Convertidores">
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
<convert:SpeedAndWidthToDurationConverter x:Key="SpeedAndWidthToDurationConverter"/>
<!-- Define the VisualBrush for the conveyor belt pattern --> <!-- Define the VisualBrush for the conveyor belt pattern -->
<VisualBrush x:Key="BeltBrush" TileMode="Tile" Viewport="0,0,0.1,1" ViewportUnits="RelativeToBoundingBox" Viewbox="0,0,20,10" ViewboxUnits="Absolute"> <VisualBrush x:Key="BeltBrush" TileMode="Tile" Viewport="0,0,20,10" ViewportUnits="Absolute" Viewbox="0,0,20,10" ViewboxUnits="Absolute">
<VisualBrush.Transform> <VisualBrush.Transform>
<TranslateTransform x:Name="BrushTransform"/> <TransformGroup>
<TranslateTransform/>
</TransformGroup>
</VisualBrush.Transform> </VisualBrush.Transform>
<VisualBrush.Visual> <VisualBrush.Visual>
<Canvas> <Canvas>
@ -38,28 +39,6 @@
<Rectangle.RenderTransform> <Rectangle.RenderTransform>
<RotateTransform Angle="{Binding Angulo}"/> <RotateTransform Angle="{Binding Angulo}"/>
</Rectangle.RenderTransform> </Rectangle.RenderTransform>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Rectangle.Fill).(VisualBrush.Transform).(TranslateTransform.X)"
From="0" To="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}">
<DoubleAnimation.Duration>
<MultiBinding Converter="{StaticResource SpeedAndWidthToDurationConverter}">
<Binding Path="VelocidadActual"/>
<Binding Path="Ancho"/>
</MultiBinding>
</DoubleAnimation.Duration>
<DoubleAnimation.RepeatBehavior>Forever</DoubleAnimation.RepeatBehavior>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle> </Rectangle>
</Canvas> </Canvas>
</UserControl> </UserControl>

View File

@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Convertidores; using CtrEditor.Convertidores;
using CtrEditor.Siemens; using CtrEditor.Siemens;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Windows.Input;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
@ -19,7 +20,7 @@ namespace CtrEditor.ObjetosSim
{ {
private osBase _osMotor = null; private osBase _osMotor = null;
private simTransporte Simulation_Transporte; private simTransporte SimGeometria;
public static string NombreClase() public static string NombreClase()
{ {
@ -32,36 +33,19 @@ namespace CtrEditor.ObjetosSim
set => SetProperty(ref nombre, value); 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; private float velocidadActual;
public float VelocidadActual public float VelocidadActual
{ {
get => velocidadActual; get => velocidadActual;
set set
{
if (value != velocidadActual)
{ {
velocidadActual = value; velocidadActual = value;
Simulation_Transporte?.SetSpeed(value); SimGeometria?.SetSpeed(value);
SetProperty(ref velocidadActual, value); SetProperty(ref velocidadActual, value);
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
}
} }
} }
@ -82,30 +66,34 @@ namespace CtrEditor.ObjetosSim
[ObservableProperty] [ObservableProperty]
public bool esMarcha; public bool esMarcha;
private void ActualizarGeometrias() private void ActualizarGeometrias()
{ {
if (_visualRepresentation is ucTransporteTTop uc) if (_visualRepresentation is ucTransporteTTop uc)
{ {
UpdateRectangle(Simulation_Transporte, uc.Transporte,Alto,Ancho,Angulo); UpdateRectangle(SimGeometria, uc.Transporte,Alto,Ancho,Angulo);
Simulation_Transporte.Speed = VelocidadActual; SimGeometria.Speed = VelocidadActual;
} }
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
} }
public osTransporteTTop() public osTransporteTTop()
{ {
Ancho = 1; Ancho = 1;
Alto = 0.10f; Alto = 0.10f;
} }
public override void SimulationStop()
{
// Se llama al detener la simulacion
ActualizarAnimacionStoryBoardTransporte(VelocidadActual);
}
public override void UpdateGeometryStart() public override void UpdateGeometryStart()
{ {
// Se llama antes de la simulacion // Se llama antes de la simulacion
ActualizarGeometrias(); ActualizarGeometrias();
} }
public override void UpdateGeometryStep()
{
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds)
{ {
if (_osMotor != null) if (_osMotor != null)
@ -117,9 +105,6 @@ namespace CtrEditor.ObjetosSim
_osMotor = ObtenerLink(Motor, typeof(osVMmotorSim)); _osMotor = ObtenerLink(Motor, typeof(osVMmotorSim));
} }
public override void UpdateControl(int elapsedMilliseconds)
{
}
public override void ucLoaded() public override void ucLoaded()
{ {
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para
@ -127,13 +112,16 @@ namespace CtrEditor.ObjetosSim
ActualizarLeftTop(); ActualizarLeftTop();
if (_visualRepresentation is ucTransporteTTop uc) 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() public override void ucUnLoaded()
{ {
// El UserControl se esta eliminando // El UserControl se esta eliminando
// eliminar el objeto de simulacion // eliminar el objeto de simulacion
simulationManager.Remove(Simulation_Transporte); simulationManager.Remove(SimGeometria);
} }
} }

View File

@ -5,14 +5,30 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CtrEditor.ObjetosSim" xmlns:local="clr-namespace:CtrEditor.ObjetosSim"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
xmlns:convert="clr-namespace:CtrEditor.Convertidores"> xmlns:convert="clr-namespace:CtrEditor.Convertidores">
<UserControl.Resources> <UserControl.Resources>
<convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/> <convert:MeterToPixelConverter x:Key="MeterToPixelConverter"/>
</UserControl.Resources> </UserControl.Resources>
<UserControl.DataContext>
<vm:osVMmotorSim ImageSource_oculta="/imagenes/motorNegro.png" />
</UserControl.DataContext>
<Grid> <Grid>
<Image Source="{Binding ImageSource}" <Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Nombre}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Transparent"
Foreground="Black"/>
<Image Grid.Row="1" Source="{Binding ImageSource_oculta}"
Width="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}" Width="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
Height="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Tamano, Converter={StaticResource MeterToPixelConverter}}"
Stretch="Uniform"/> Stretch="Uniform"/>

View File

@ -1,21 +1,10 @@
using CtrEditor.Convertidores; using CtrEditor.Convertidores;
using CtrEditor.Siemens; 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;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CtrEditor.Simulacion;
using Newtonsoft.Json; using Newtonsoft.Json;
using CommunityToolkit.Mvvm.ComponentModel;
namespace CtrEditor.ObjetosSim namespace CtrEditor.ObjetosSim
{ {
@ -24,148 +13,59 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
/// ///
public class osVMmotorSim : osBase, IosBase public partial 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 = 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(); private VMSimMotor motState = new VMSimMotor();
public static string NombreClase() public static string NombreClase()
{ {
return "VetroMeccanica Motor"; return "VetroMeccanica Motor";
} }
private string nombre = NombreClase();
public override string Nombre
{
get => nombre;
set => SetProperty(ref nombre, value);
}
[Hidden]
[JsonIgnore] [JsonIgnore]
public ImageSource ImageSource [ObservableProperty]
{ public ImageSource imageSource_oculta;
get { return _imageSource; }
set
{
_imageSource = value;
OnPropertyChanged(nameof(ImageSource));
}
}
public float Tamano [ObservableProperty]
{ public float tamano;
get => _tamano; [ObservableProperty]
set public float maxRatedHz;
{
_tamano = value;
OnPropertyChanged(nameof(Tamano));
}
}
public float MaxRatedHz [ObservableProperty]
{ public float tiempoRampa;
get => _maxHz;
set
{
_maxHz = value;
OnPropertyChanged(nameof(Tamano));
}
}
public float TiempoRampa partial void OnTiempoRampaChanged(float value)
{
get => _rampaSegundos;
set
{ {
if (value < 0.1f) if (value < 0.1f)
value = 0.1f; value = 0.1f;
_rampaSegundos = value; tiempoRampa = value;
OnPropertyChanged(nameof(Tamano));
}
} }
public bool Encendido [ObservableProperty]
{ public bool encendido;
get => _encendido; [ObservableProperty]
set public int pLC_NumeroMotor;
{ [ObservableProperty]
_encendido = value; public float ratio;
OnPropertyChanged(nameof(Encendido));
}
}
public int PLC_NumeroMotor [ObservableProperty]
{ public float velocidad;
get => _numeroMotor;
set
{
_numeroMotor = value;
OnPropertyChanged(nameof(PLC_NumeroMotor));
}
}
partial void OnVelocidadChanged(float 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 override string Nombre
{
get => _nombre;
set
{
if (_nombre != value)
{
_nombre = value;
OnPropertyChanged(nameof(Nombre));
}
}
}
public float Ratio {
get => _ratio;
set {
_ratio = value;
OnPropertyChanged(nameof(Ratio));
}
}
public float Velocidad {
get => _velocidad;
set {
_velocidad = value;
if (value > 0) if (value > 0)
ImageSource = ImageFromPath("/imagenes/motorVerde.png"); ImageSource_oculta = ImageFromPath("/imagenes/motorVerde.png");
else else
ImageSource = ImageFromPath("/imagenes/motorNegro.png"); ImageSource_oculta = ImageFromPath("/imagenes/motorNegro.png");
OnPropertyChanged(nameof(Velocidad));
}
} }
public osVMmotorSim() public osVMmotorSim()
@ -174,16 +74,13 @@ namespace CtrEditor.ObjetosSim
PLC_NumeroMotor = 31; PLC_NumeroMotor = 31;
MaxRatedHz = 100; MaxRatedHz = 100;
TiempoRampa = 3; TiempoRampa = 3;
ImageSource = ImageFromPath("/imagenes/motor2.png"); ImageSource_oculta = ImageFromPath("/imagenes/motor2.png");
} }
public override void UpdateGeometryStart() public override void UpdateGeometryStart()
{ {
// Se llama antes de la simulacion // Se llama antes de la simulacion
}
public override void UpdateGeometryStep()
{
} }
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) {
@ -206,11 +103,6 @@ namespace CtrEditor.ObjetosSim
ActualizarLeftTop(); ActualizarLeftTop();
} }
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
}
} }
public partial class ucVMmotorSim : UserControl, IDataContainer public partial class ucVMmotorSim : UserControl, IDataContainer

View File

@ -21,6 +21,7 @@ using Siemens.Simatic.Simulation.Runtime;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Input; using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using System.Windows.Media.Animation;
namespace CtrEditor.ObjetosSim 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"; 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 Inicializado = false;
public bool AutoCreated = false; public bool AutoCreated = false;
@ -82,12 +104,25 @@ namespace CtrEditor.ObjetosSim
[JsonIgnore] [JsonIgnore]
protected UserControl? _visualRepresentation = null; protected UserControl? _visualRepresentation = null;
public abstract void UpdateControl(int elapsedMilliseconds); public virtual void UpdateControl(int elapsedMilliseconds) { }
public abstract void UpdateGeometryStart(); public virtual void UpdateGeometryStart()
public abstract void UpdateGeometryStep(); {
public abstract void UpdatePLC(PLCModel plc, int elapsedMilliseconds); // Se llama antes de la simulacion
public abstract void ucLoaded(); }
public abstract void ucUnLoaded(); 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] [JsonIgnore]
public MainViewModel _mainViewModel; public MainViewModel _mainViewModel;
@ -129,10 +164,41 @@ namespace CtrEditor.ObjetosSim
return null; 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() public void ActualizarLeftTop()
{ {
Left = Left; CanvasSetLeftinMeter(Left);
Top = Top; CanvasSetTopinMeter(Top);
} }
public bool LeerBitTag(PLCModel plc, string Tag) public bool LeerBitTag(PLCModel plc, string Tag)

View File

@ -34,7 +34,10 @@ namespace CtrEditor.Simulacion
{ {
Body.SetTransform(new Vector2(x, y), Body.Rotation); Body.SetTransform(new Vector2(x, y), Body.Rotation);
} }
public void SetPosition(Vector2 centro)
{
Body.SetTransform(centro, Body.Rotation);
}
} }
public class simCurve : simBase public class simCurve : simBase