CtrEditor/ObjetosSim/ucBotella.xaml.cs

188 lines
4.9 KiB
C#
Raw Normal View History

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;
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;
using CtrEditor.Simulacion;
using Newtonsoft.Json.Linq;
2024-05-02 11:06:45 -03:00
namespace CtrEditor.ObjetosSim
2024-05-02 11:06:45 -03:00
{
/// <summary>
/// Interaction logic for ucBotella.xaml
2024-05-02 11:06:45 -03:00
/// </summary>
///
public class osBotella : osBase
2024-05-02 11:06:45 -03:00
{
private float _diametro;
private float _mass;
private Vector2 _centro = new Vector2(); // Centro
private string _nombre = "Botella";
private simCircle Simulacion_Botella;
2024-05-06 12:31:45 -03:00
// Otros datos y métodos relevantes para la simulación
2024-05-06 12:31:45 -03:00
public float Diametro {
get => _diametro;
2024-05-06 12:31:45 -03:00
set
{
_diametro = value;
Simulacion_Botella?.SetDiameter(Diametro);
2024-05-06 12:31:45 -03:00
OnPropertyChanged(nameof(Diametro));
}
}
2024-05-06 12:31:45 -03:00
public float Mass {
get => _mass;
2024-05-06 12:31:45 -03:00
set
{
_mass = value;
Simulacion_Botella?.SetMass(value);
2024-05-06 12:31:45 -03:00
OnPropertyChanged(nameof(Mass));
}
}
public override float Left
{
get => _centro.X-Diametro/2;
set
{
_centro.X = value+Diametro/2;
CanvasSetLeftinMeter(value);
OnPropertyChanged(nameof(Left));
}
}
public override float Top
{
get => _centro.Y - Diametro / 2;
set
{
_centro.Y = value + Diametro / 2;
CanvasSetTopinMeter(value);
OnPropertyChanged(nameof(Top));
}
}
public float CenterX
{
get => _centro.X;
set
{
_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
}
public float CenterY
2024-05-06 12:31:45 -03:00
{
get => _centro.Y;
2024-05-06 12:31:45 -03:00
set
{
_centro.Y = value;
CanvasSetTopinMeter(Top);
OnPropertyChanged(nameof(CenterY));
2024-05-06 12:31:45 -03:00
OnPropertyChanged(nameof(Top));
}
}
private void ActualizarGeometrias()
{
if (Simulacion_Botella != 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));
}
}
}
public osBotella()
{
2024-05-08 08:41:26 -03:00
Diametro = 0.10f;
Mass = 1;
}
public override void UpdateGeometryStart()
2024-05-06 12:31:45 -03:00
{
// Se llama antes de la simulacion
ActualizarGeometrias();
2024-05-06 12:31:45 -03:00
}
public override void UpdateGeometryStep()
{
// Se llama antes de la simulacion
ActualizarGeometrias();
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { }
2024-05-06 12:31:45 -03:00
public override void UpdateControl()
{
CenterX = Simulacion_Botella.CenterX;
CenterY = Simulacion_Botella.CenterY;
}
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
Simulacion_Botella = simulationManager.AddCircle(Diametro, _centro, Mass);
2024-05-06 12:31:45 -03:00
}
2024-05-02 11:06:45 -03:00
}
public partial class ucBotella : UserControl, IDataContainer
{
public osBase? Datos { get; set; }
public ucBotella()
{
InitializeComponent();
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Datos?.ucLoaded();
}
2024-05-06 12:31:45 -03:00
public void Resize(float width, float height) { }
public void Move(float LeftPixels, float TopPixels)
{
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-06 12:31:45 -03:00
public void Rotate(float Angle) { }
2024-05-04 16:27:04 -03:00
public void Highlight(bool State) { }
public int ZIndex()
{
return 10;
}
}
2024-05-02 11:06:45 -03:00
}