121 lines
3.2 KiB
C#
121 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json.Serialization;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
{
|
|
|
|
public interface IosBase
|
|
{
|
|
string Nombre { get; }
|
|
|
|
void ConnectSimManager(SimulationManager simulationManager);
|
|
void UpdateControl();
|
|
}
|
|
|
|
public interface IDataContainer
|
|
{
|
|
osBase? Datos { get; set; }
|
|
void Resize(float width, float height);
|
|
void Move(float Left, float Top);
|
|
void Rotate(float Angle);
|
|
void Highlight(bool State);
|
|
int ZIndex();
|
|
}
|
|
|
|
public abstract class osBase : INotifyPropertyChanged, IosBase
|
|
{
|
|
public abstract float LeftPixels { get; set; }
|
|
public abstract float TopPixels { get; set; }
|
|
public abstract float Left { get; set; }
|
|
public abstract float Top { get; set; }
|
|
|
|
public bool Inicializado = false;
|
|
|
|
protected UserControl? _visualRepresentation = null;
|
|
|
|
public abstract string Nombre { get; set; }
|
|
|
|
public abstract void ConnectSimManager(SimulationManager simulationManager);
|
|
public abstract void UpdateControl();
|
|
|
|
[JsonIgnore]
|
|
public UserControl? VisualRepresentation
|
|
{
|
|
get => _visualRepresentation;
|
|
set => _visualRepresentation = value;
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
protected virtual void OnPropertyChanged(string propertyName)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
}
|
|
|
|
public class PixelToMeter
|
|
{
|
|
// Instancia privada estática, parte del patrón Singleton
|
|
private static PixelToMeter? _instance;
|
|
public UnitConverter calc = new UnitConverter(0.01f);
|
|
|
|
// Propiedad pública estática para acceder a la instancia
|
|
public static PixelToMeter Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = new PixelToMeter();
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class UnitConverter
|
|
{
|
|
// La escala representa cuántos metros hay en un píxel
|
|
public float Scale { get; private set; }
|
|
|
|
|
|
public UnitConverter(float scale)
|
|
{
|
|
if (scale <= 0)
|
|
throw new ArgumentException("Scale must be greater than zero.");
|
|
|
|
Scale = scale;
|
|
}
|
|
|
|
// Convierte una distancia en metros a píxeles
|
|
public float MetersToPixels(float meters)
|
|
{
|
|
return meters / Scale;
|
|
}
|
|
|
|
// Convierte una distancia en píxeles a metros
|
|
public float PixelsToMeters(float pixels)
|
|
{
|
|
return pixels * Scale;
|
|
}
|
|
|
|
// Configurar o ajustar la escala
|
|
public void SetScale(float newScale)
|
|
{
|
|
if (newScale <= 0)
|
|
throw new ArgumentException("Scale must be greater than zero.");
|
|
|
|
Scale = newScale;
|
|
}
|
|
}
|
|
|
|
|
|
}
|