diff --git a/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs b/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs index c9fb51c..d932b63 100644 --- a/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs @@ -4,6 +4,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using CtrEditor.Convertidores; using CtrEditor.Siemens; using CtrEditor.Simulacion; +using Newtonsoft.Json.Linq; namespace CtrEditor.ObjetosSim @@ -13,16 +14,12 @@ namespace CtrEditor.ObjetosSim /// public partial class osTransporteCurva : osBase, IosBase { - private float frictionCoefficient; - private float velMax50hz; // en metros por minuto - private float tiempoRampa; - private bool esMarcha; - - private float _velocidadActual; private osBase _osMotor = null; private simCurve Simulation_TransporteCurva; + private float _velocidadActual; + public static string NombreClase() { return "Transporte Curva 90"; @@ -34,6 +31,30 @@ namespace CtrEditor.ObjetosSim set => SetProperty(ref nombre, value); } + [ObservableProperty] + public float velocidadActual; + + partial void OnVelocidadActualChanged(float value) + { + SetSpeed(); + } + + [ObservableProperty] + bool invertirDireccion; + + partial void OnInvertirDireccionChanged(bool value) + { + SetSpeed(); + } + + void SetSpeed() + { + if (InvertirDireccion) + Simulation_TransporteCurva?.SetSpeed(-VelocidadActual); + else + Simulation_TransporteCurva?.SetSpeed(VelocidadActual); + } + [ObservableProperty] private float radioExterno; [ObservableProperty] @@ -55,30 +76,23 @@ namespace CtrEditor.ObjetosSim get => Angulo+Arco_en_grados; } - public float VelocidadActual - { - get => _velocidadActual; - set - { - _velocidadActual = value; - Simulation_TransporteCurva?.SetSpeed(value); - OnPropertyChanged(nameof(VelocidadActual)); - } - } - private void ActualizarGeometrias() { if (_visualRepresentation is ucTransporteCurva uc) { UpdateCurve(Simulation_TransporteCurva, RadioInterno, RadioExterno, Angulo, Angulo+Arco_en_grados); - Simulation_TransporteCurva.Speed = VelocidadActual; + SetSpeed(); } } - public float FrictionCoefficient { get => frictionCoefficient; set => frictionCoefficient = value; } - public float VelMax50hz { get => velMax50hz; set => velMax50hz = value; } - public float TiempoRampa { get => tiempoRampa; set => tiempoRampa = value; } - public bool EsMarcha { get => esMarcha; set => esMarcha = value; } + [ObservableProperty] + public float frictionCoefficient; + [ObservableProperty] + public float velMax50hz; + [ObservableProperty] + public float tiempoRampa; + [ObservableProperty] + public bool esMarcha; public osTransporteCurva() { diff --git a/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs b/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs index 3906139..c1009a1 100644 --- a/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteGuias.xaml.cs @@ -31,14 +31,36 @@ namespace CtrEditor.ObjetosSim } [ObservableProperty] - private float velocidadActual; + public float velocidadActual; partial void OnVelocidadActualChanged(float value) { - SimGeometria?.SetSpeed(value); + SetSpeed(); + } + + [ObservableProperty] + bool invertirDireccion; + + partial void OnInvertirDireccionChanged(bool value) + { + SetSpeed(); + if (_visualRepresentation is ucTransporteGuias uc) + { + CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); + ActualizarAnimacionStoryBoardTransporte(VelocidadActual); + } + } + + void SetSpeed() + { + if (InvertirDireccion) + SimGeometria?.SetSpeed(-VelocidadActual); + else + SimGeometria?.SetSpeed(VelocidadActual); ActualizarAnimacionStoryBoardTransporte(VelocidadActual); } + [ObservableProperty] public string motor; @@ -141,7 +163,7 @@ namespace CtrEditor.ObjetosSim Guia_Superior = AddLine(simulationManager, uc.GuiaSuperior); Guia_Inferior = AddLine(simulationManager, uc.GuiaInferior); - CrearAnimacionStoryBoardTrasnporte(uc.Transporte); + CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); } Motor = Motor; // Forzar la busqueda } diff --git a/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs b/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs index 6cf177b..a6cbf21 100644 --- a/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteTTop.xaml.cs @@ -33,22 +33,37 @@ namespace CtrEditor.ObjetosSim set => SetProperty(ref nombre, value); } - private float velocidadActual; - public float VelocidadActual + [ObservableProperty] + public float velocidadActual; + + partial void OnVelocidadActualChanged(float value) { - get => velocidadActual; - set + SetSpeed(); + } + + [ObservableProperty] + bool invertirDireccion; + + partial void OnInvertirDireccionChanged(bool value) + { + SetSpeed(); + if (_visualRepresentation is ucTransporteTTop uc) { - if (value != velocidadActual) - { - velocidadActual = value; - SimGeometria?.SetSpeed(value); - SetProperty(ref velocidadActual, value); - ActualizarAnimacionStoryBoardTransporte(VelocidadActual); - } + CrearAnimacionStoryBoardTrasnporte(uc.Transporte, InvertirDireccion); + ActualizarAnimacionStoryBoardTransporte(VelocidadActual); } } + void SetSpeed() + { + if (InvertirDireccion) + SimGeometria?.SetSpeed(-VelocidadActual); + else + SimGeometria?.SetSpeed(VelocidadActual); + ActualizarAnimacionStoryBoardTransporte(VelocidadActual); + } + + [ObservableProperty] public string motor; @@ -78,7 +93,7 @@ namespace CtrEditor.ObjetosSim if (_visualRepresentation is ucTransporteTTop uc) { UpdateRectangle(SimGeometria, uc.Transporte,Alto,Ancho,Angulo); - SimGeometria.Speed = VelocidadActual; + SetSpeed(); } ActualizarAnimacionStoryBoardTransporte(VelocidadActual); } @@ -120,7 +135,7 @@ namespace CtrEditor.ObjetosSim if (_visualRepresentation is ucTransporteTTop uc) { SimGeometria = AddRectangle(simulationManager, uc.Transporte, Alto, Ancho, Angulo); - CrearAnimacionStoryBoardTrasnporte(uc.Transporte); + CrearAnimacionStoryBoardTrasnporte(uc.Transporte,InvertirDireccion); } } public override void ucUnLoaded() diff --git a/ObjetosSim/osBase.cs b/ObjetosSim/osBase.cs index 4144ecf..5fcc788 100644 --- a/ObjetosSim/osBase.cs +++ b/ObjetosSim/osBase.cs @@ -23,6 +23,7 @@ using System.Windows.Input; using CommunityToolkit.Mvvm.ComponentModel; using System.Windows.Media.Animation; using System.Diagnostics; +using HarfBuzzSharp; namespace CtrEditor.ObjetosSim { @@ -245,16 +246,23 @@ namespace CtrEditor.ObjetosSim return null; } - protected void CrearAnimacionStoryBoardTrasnporte(System.Windows.Shapes.Rectangle transporte) + protected void CrearAnimacionStoryBoardTrasnporte(System.Windows.Shapes.Rectangle transporte, bool invertirDireccion) { if (_visualRepresentation == null) return; if (transporte == null) return; + // Detener y eliminar el storyboard existente si hay uno + if (_storyboard != null) + { + _storyboard.Stop(); + _storyboard.Children.Clear(); + } + _storyboard = new Storyboard(); var animation = new DoubleAnimation { - From = 0, - To = 20, // Total Pixels Brush + From = invertirDireccion ? 20 : 0, + To = invertirDireccion ? 0 : 20, // Total Pixels Brush Duration = TimeSpan.FromSeconds(PixelToMeter.Instance.calc.PixelsToMeters(20) * 60), RepeatBehavior = RepeatBehavior.Forever };