2024-05-02 11:06:45 -03:00
|
|
|
|
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;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
using Microsoft.Xna.Framework;
|
2024-05-11 11:58:55 -03:00
|
|
|
|
using CtrEditor.Convertidores;
|
2024-05-11 15:55:44 -03:00
|
|
|
|
using CtrEditor.Siemens;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
using CtrEditor.Simulacion;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
2024-05-02 11:06:45 -03:00
|
|
|
|
|
2024-05-04 06:00:52 -03:00
|
|
|
|
namespace CtrEditor.ObjetosSim
|
2024-05-02 11:06:45 -03:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-05-04 06:00:52 -03:00
|
|
|
|
/// Interaction logic for ucBotella.xaml
|
2024-05-02 11:06:45 -03:00
|
|
|
|
/// </summary>
|
2024-05-04 06:00:52 -03:00
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
public class osBotella : osBase
|
2024-05-02 11:06:45 -03:00
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
private float _diametro;
|
|
|
|
|
private float _mass;
|
|
|
|
|
private Vector2 _centro = new Vector2(); // Centro
|
|
|
|
|
private string _nombre = "Botella";
|
2024-05-18 09:58:41 -03:00
|
|
|
|
private simBotella Simulacion_Botella;
|
2024-05-06 12:31:45 -03:00
|
|
|
|
|
2024-05-04 06:00:52 -03:00
|
|
|
|
// Otros datos y métodos relevantes para la simulación
|
|
|
|
|
|
2024-05-06 12:31:45 -03:00
|
|
|
|
|
|
|
|
|
public float Diametro {
|
2024-05-14 03:15:54 -03:00
|
|
|
|
get => _diametro;
|
2024-05-06 12:31:45 -03:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
_diametro = value;
|
|
|
|
|
Simulacion_Botella?.SetDiameter(Diametro);
|
2024-05-06 12:31:45 -03:00
|
|
|
|
OnPropertyChanged(nameof(Diametro));
|
2024-05-08 03:00:31 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 12:31:45 -03:00
|
|
|
|
public float Mass {
|
2024-05-14 03:15:54 -03:00
|
|
|
|
get => _mass;
|
2024-05-06 12:31:45 -03:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
_mass = value;
|
|
|
|
|
Simulacion_Botella?.SetMass(value);
|
2024-05-06 12:31:45 -03:00
|
|
|
|
OnPropertyChanged(nameof(Mass));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public override float Left
|
2024-05-08 04:15:28 -03:00
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
get => _centro.X-Diametro/2;
|
2024-05-08 04:15:28 -03:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
_centro.X = value+Diametro/2;
|
|
|
|
|
CanvasSetLeftinMeter(value);
|
2024-05-18 09:58:41 -03:00
|
|
|
|
OnPropertyChanged(nameof(CenterX));
|
2024-05-14 03:15:54 -03:00
|
|
|
|
OnPropertyChanged(nameof(Left));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public override float Top
|
|
|
|
|
{
|
|
|
|
|
get => _centro.Y - Diametro / 2;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_centro.Y = value + Diametro / 2;
|
|
|
|
|
CanvasSetTopinMeter(value);
|
2024-05-18 09:58:41 -03:00
|
|
|
|
OnPropertyChanged(nameof(CenterY));
|
2024-05-14 03:15:54 -03:00
|
|
|
|
OnPropertyChanged(nameof(Top));
|
2024-05-08 04:15:28 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public float CenterX
|
2024-05-08 03:00:31 -03:00
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
get => _centro.X;
|
2024-05-08 03:00:31 -03:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
_centro.X = value;
|
|
|
|
|
CanvasSetLeftinMeter(Left);
|
|
|
|
|
OnPropertyChanged(nameof(CenterX));
|
2024-05-06 12:31:45 -03:00
|
|
|
|
OnPropertyChanged(nameof(Left));
|
|
|
|
|
}
|
2024-05-03 05:13:25 -03:00
|
|
|
|
}
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public float CenterY
|
2024-05-06 12:31:45 -03:00
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
get => _centro.Y;
|
2024-05-06 12:31:45 -03:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
_centro.Y = value;
|
|
|
|
|
CanvasSetTopinMeter(Top);
|
|
|
|
|
OnPropertyChanged(nameof(CenterY));
|
2024-05-06 12:31:45 -03:00
|
|
|
|
OnPropertyChanged(nameof(Top));
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-08 03:00:31 -03:00
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
private void ActualizarGeometrias()
|
|
|
|
|
{
|
|
|
|
|
if (Simulacion_Botella != null)
|
|
|
|
|
{
|
|
|
|
|
Simulacion_Botella.SetDiameter(Diametro);
|
|
|
|
|
Simulacion_Botella.SetPosition(CenterX, CenterY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 03:00:31 -03:00
|
|
|
|
public override string Nombre
|
|
|
|
|
{
|
|
|
|
|
get => _nombre;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_nombre != value)
|
|
|
|
|
{
|
|
|
|
|
_nombre = value;
|
|
|
|
|
OnPropertyChanged(nameof(Nombre));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public osBotella()
|
|
|
|
|
{
|
2024-05-08 08:41:26 -03:00
|
|
|
|
Diametro = 0.10f;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
Mass = 1;
|
2024-05-08 03:00:31 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public override void UpdateGeometryStart()
|
2024-05-06 12:31:45 -03:00
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
// Se llama antes de la simulacion
|
|
|
|
|
ActualizarGeometrias();
|
2024-05-06 12:31:45 -03:00
|
|
|
|
}
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public override void UpdateGeometryStep()
|
2024-05-10 20:40:51 -03:00
|
|
|
|
{
|
|
|
|
|
// Se llama antes de la simulacion
|
2024-05-14 03:15:54 -03:00
|
|
|
|
ActualizarGeometrias();
|
2024-05-10 20:40:51 -03:00
|
|
|
|
}
|
2024-05-14 03:15:54 -03:00
|
|
|
|
|
2024-05-14 12:10:32 -03:00
|
|
|
|
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { }
|
2024-05-06 12:31:45 -03:00
|
|
|
|
|
2024-05-16 13:45:14 -03:00
|
|
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
2024-05-06 12:31:45 -03:00
|
|
|
|
{
|
2024-05-14 03:15:54 -03:00
|
|
|
|
CenterX = Simulacion_Botella.CenterX;
|
|
|
|
|
CenterY = Simulacion_Botella.CenterY;
|
2024-05-18 09:58:41 -03:00
|
|
|
|
|
|
|
|
|
if (Simulacion_Botella.Descartar) // Ha sido marcada para remover
|
|
|
|
|
RemoverDesdeSimulacion = true;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public override void ucLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
|
|
|
// crear el objeto de simulacion
|
2024-05-18 06:49:02 -03:00
|
|
|
|
ActualizarLeftTop();
|
2024-05-14 03:15:54 -03:00
|
|
|
|
Simulacion_Botella = simulationManager.AddCircle(Diametro, _centro, Mass);
|
2024-05-06 12:31:45 -03:00
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
public override void ucUnLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl se esta eliminando
|
|
|
|
|
// eliminar el objeto de simulacion
|
|
|
|
|
simulationManager.Remove(Simulacion_Botella);
|
|
|
|
|
}
|
2024-05-14 03:15:54 -03:00
|
|
|
|
|
2024-05-02 11:06:45 -03:00
|
|
|
|
}
|
2024-05-03 03:58:21 -03:00
|
|
|
|
|
2024-05-04 15:35:06 -03:00
|
|
|
|
public partial class ucBotella : UserControl, IDataContainer
|
2024-05-04 06:00:52 -03:00
|
|
|
|
{
|
2024-05-04 15:35:06 -03:00
|
|
|
|
public osBase? Datos { get; set; }
|
|
|
|
|
|
2024-05-04 06:00:52 -03:00
|
|
|
|
public ucBotella()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-14 03:15:54 -03:00
|
|
|
|
this.Loaded += OnLoaded;
|
2024-05-18 09:58:41 -03:00
|
|
|
|
this.Unloaded += OnUnloaded;
|
2024-05-14 03:15:54 -03:00
|
|
|
|
}
|
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos?.ucLoaded();
|
2024-05-04 06:00:52 -03:00
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos?.ucUnLoaded();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 12:31:45 -03:00
|
|
|
|
public void Resize(float width, float height) { }
|
2024-05-08 03:00:31 -03:00
|
|
|
|
public void Move(float LeftPixels, float TopPixels)
|
2024-05-04 15:35:06 -03:00
|
|
|
|
{
|
|
|
|
|
if (Datos != null)
|
|
|
|
|
{
|
2024-05-08 08:41:26 -03:00
|
|
|
|
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
|
|
|
|
|
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
|
2024-05-04 15:35:06 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-06 12:31:45 -03:00
|
|
|
|
public void Rotate(float Angle) { }
|
2024-05-04 16:27:04 -03:00
|
|
|
|
public void Highlight(bool State) { }
|
2024-05-08 03:00:31 -03:00
|
|
|
|
public int ZIndex()
|
|
|
|
|
{
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
2024-05-04 06:00:52 -03:00
|
|
|
|
}
|
2024-05-02 11:06:45 -03:00
|
|
|
|
}
|