using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Linq; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using static System.Runtime.InteropServices.JavaScript.JSType; using CtrEditor.Convertidores; 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 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(); public abstract void UpdateGeometry(); [JsonIgnore] public UserControl? VisualRepresentation { get => _visualRepresentation; set => _visualRepresentation = value; } public void CanvasSetLeftinMeter(float left) { if (_visualRepresentation != null) Canvas.SetLeft(_visualRepresentation, PixelToMeter.Instance.calc.MetersToPixels(left)); } public float CanvasGetLeftinMeter() { if (_visualRepresentation != null) return PixelToMeter.Instance.calc.PixelsToMeters((float)Canvas.GetLeft(_visualRepresentation)); else return 0f; } public void CanvasSetTopinMeter(float top) { if (_visualRepresentation != null) Canvas.SetTop(_visualRepresentation, PixelToMeter.Instance.calc.MetersToPixels(top)); } public float CanvasGetTopinMeter() { if (_visualRepresentation != null) return PixelToMeter.Instance.calc.PixelsToMeters((float)Canvas.GetTop(_visualRepresentation)); else return 0f; } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }