CtrEditor/ObjetosSim/UserControls/ucGuia.xaml.cs

160 lines
4.2 KiB
C#
Raw Normal View History

2024-05-08 08:41:26 -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-22 06:19:31 -03:00
using CommunityToolkit.Mvvm.ComponentModel;
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 FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using static System.Runtime.InteropServices.JavaScript.JSType;
2024-05-08 08:41:26 -03:00
namespace CtrEditor.ObjetosSim
{
/// <summary>
/// Interaction logic for ucGuia.xaml
/// </summary>
2024-05-22 06:19:31 -03:00
public partial class osGuia : osBase, IosBase
2024-05-08 08:41:26 -03:00
{
2024-05-22 06:19:31 -03:00
private simGuia SimGeometria;
2024-05-08 08:41:26 -03:00
public static string NombreClase()
{
return "Guia";
}
2024-05-22 06:19:31 -03:00
private string nombre = "Guia";
public override string Nombre
{
get => nombre;
set => SetProperty(ref nombre, value);
}
private float left;
2024-05-08 08:41:26 -03:00
public override float Left
{
2024-05-22 06:19:31 -03:00
get => left;
2024-05-08 08:41:26 -03:00
set
{
CanvasSetLeftinMeter(value);
2024-05-22 06:19:31 -03:00
SetProperty(ref left, value);
2024-05-08 08:41:26 -03:00
}
}
2024-05-22 06:19:31 -03:00
private float top;
2024-05-08 08:41:26 -03:00
public override float Top
{
2024-05-22 06:19:31 -03:00
get => top;
2024-05-08 08:41:26 -03:00
set
{
CanvasSetTopinMeter(value);
2024-05-22 06:19:31 -03:00
SetProperty(ref top, value);
2024-05-08 08:41:26 -03:00
}
}
2024-05-22 06:19:31 -03:00
[ObservableProperty]
public float ancho;
2024-05-08 08:41:26 -03:00
2024-05-22 06:19:31 -03:00
[ObservableProperty]
public float altoGuia;
2024-05-08 08:41:26 -03:00
2024-05-22 06:19:31 -03:00
[ObservableProperty]
public float angulo;
2024-05-08 08:41:26 -03:00
private void ActualizarGeometrias()
{
if (_visualRepresentation is ucGuia uc)
2024-05-22 06:19:31 -03:00
UpdateOrCreateLine(SimGeometria, uc.Guia);
}
2024-05-08 08:41:26 -03:00
public osGuia()
{
Ancho = 1;
AltoGuia = 0.03f;
2024-05-08 08:41:26 -03:00
}
public override void UpdateGeometryStart()
{
// Se llama antes de la simulacion
ActualizarGeometrias();
}
2024-05-16 13:45:14 -03:00
public override void UpdateControl(int elapsedMilliseconds)
2024-05-08 08:41:26 -03:00
{
}
public override void UpdateGeometryStep()
{
}
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) { }
public override void ucLoaded()
{
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion
ActualizarLeftTop();
if (_visualRepresentation is ucGuia uc)
2024-05-22 06:19:31 -03:00
SimGeometria = AddLine(simulationManager, uc.Guia);
}
public override void ucUnLoaded()
{
// El UserControl se esta eliminando
// eliminar el objeto de simulacion
2024-05-22 06:19:31 -03:00
simulationManager?.Remove(SimGeometria);
}
2024-05-11 15:55:44 -03:00
2024-05-08 08:41:26 -03:00
}
public partial class ucGuia : UserControl, IDataContainer
{
public osBase? Datos { get; set; }
public ucGuia()
{
InitializeComponent();
this.Loaded += OnLoaded;
this.Unloaded += OnUnloaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
Datos?.ucLoaded();
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
Datos?.ucUnLoaded();
2024-05-08 08:41:26 -03:00
}
public void Resize(float width, float height)
{
if (Datos is osGuia datos)
datos.Ancho = PixelToMeter.Instance.calc.PixelsToMeters(width);
}
public void Move(float LeftPixels, float TopPixels)
{
if (Datos != null)
{
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
}
}
public void Rotate(float Angle)
{
if (Datos != null)
if (Datos is osGuia datos)
datos.Angulo = Angle;
}
public void Highlight(bool State) { }
public int ZIndex()
{
return 1;
}
}
}