diff --git a/CtrEditor.csproj b/CtrEditor.csproj index cfbdb43..b4f024b 100644 --- a/CtrEditor.csproj +++ b/CtrEditor.csproj @@ -75,14 +75,14 @@ - - + + - - - + + + diff --git a/MainViewModel.cs b/MainViewModel.cs index 4438746..dab564c 100644 --- a/MainViewModel.cs +++ b/MainViewModel.cs @@ -704,6 +704,7 @@ namespace CtrEditor Debug_SimulacionCreado = true; _timerSimulacion.Start(); + simulationManager.Start(); } private void StopSimulation() diff --git a/ObjetosSim/Decorativos/ucFramePlate.xaml b/ObjetosSim/Decorativos/ucFramePlate.xaml new file mode 100644 index 0000000..ad11775 --- /dev/null +++ b/ObjetosSim/Decorativos/ucFramePlate.xaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ObjetosSim/Decorativos/ucFramePlate.xaml.cs b/ObjetosSim/Decorativos/ucFramePlate.xaml.cs new file mode 100644 index 0000000..7a69442 --- /dev/null +++ b/ObjetosSim/Decorativos/ucFramePlate.xaml.cs @@ -0,0 +1,153 @@ +using System.ComponentModel; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using CommunityToolkit.Mvvm.ComponentModel; +using CtrEditor.FuncionesBase; +using DocumentFormat.OpenXml.Spreadsheet; +using Newtonsoft.Json; +using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; +using Color = System.Windows.Media.Color; +using Colors = System.Windows.Media.Colors; +using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute; + +namespace CtrEditor.ObjetosSim +{ + /// + /// Interaction logic for ucFramePlate.xaml + /// + /// + + public partial class osFramePlate : osBase, IosBase + { + [JsonIgnore] + public float offsetY; + [JsonIgnore] + public float offsetX; + + public static string NombreClase() + { + return "Frame Plate"; + } + private string nombre = NombreClase(); + public override string Nombre + { + get => nombre; + set => SetProperty(ref nombre, value); + } + + [ObservableProperty] + Color color; + [ObservableProperty] + Color color_Titulo; + + [ObservableProperty] + string titulo; + [ObservableProperty] + public float alto_Titulo; + + // Encoder + [ObservableProperty] + [property: Description("This is a link to a Encoder for X.")] + [property: Category("Encoders:")] + [property: ItemsSource(typeof(osBaseItemsSource))] + private string encoder_X; + + [ObservableProperty] + [property: Description("K Pulses per meter for Moving")] + [property: Category("Encoders:")] + public float k_encoder_X; + + [ObservableProperty] + [property: Description("X in meter offset Left. Position when the encoder is 0")] + [property: Category("Encoders:")] + public float offset_encoder_X; + + [JsonIgnore] + private osEncoderMotorLineal EncoderX; + + [JsonIgnore] + private float EncoderXValue; + + partial void OnEncoder_XChanged(string value) + { + if (_mainViewModel != null && value != null && value.Length > 0) + { + EncoderX = (osEncoderMotorLineal)_mainViewModel.ObjetosSimulables.FirstOrDefault(s => (s is osEncoderMotorLineal && s.Nombre == value), null); + } + } + + public override void UpdateControl(int elapsedMilliseconds) + { + if (EncoderX == null) + return; + if (K_encoder_X == 0) + return; + if (EncoderXValue != EncoderX.Valor_Actual) + Left = (EncoderX.Valor_Actual / k_encoder_X) + offset_encoder_X; + EncoderXValue = EncoderX.Valor_Actual; + } + + public override void TopChanging(float oldValue, float newValue) + { + offsetY = newValue - oldValue; + } + public override void LeftChanging(float oldValue, float newValue) + { + offsetX = newValue - oldValue; + } + + public osFramePlate() + { + Ancho = 0.5f; + Alto = 0.5f; + Alto_Titulo = 0.2f; + Color = Colors.WhiteSmoke; + Titulo = "Frame"; + } + + public override void ucLoaded() + { + base.ucLoaded(); + // El UserControl se ha cargado + OnEncoder_XChanged(Encoder_X); + } + + public override void ucUnLoaded() + { + base.ucUnLoaded(); + // El UserControl se esta eliminando + // eliminar el objeto de simulacion + } + + } + + public partial class ucFramePlate : UserControl, IDataContainer + { + public osBase? Datos { get; set; } + + public ucFramePlate() + { + 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(); + } + public void Highlight(bool State) { } + public ZIndexEnum ZIndex() + { + return ZIndexEnum.Decorativos; + } + + } +} + + + diff --git a/ObjetosSim/Dinamicos/ucBotella.xaml.cs b/ObjetosSim/Dinamicos/ucBotella.xaml.cs index 6471a52..8cb15f3 100644 --- a/ObjetosSim/Dinamicos/ucBotella.xaml.cs +++ b/ObjetosSim/Dinamicos/ucBotella.xaml.cs @@ -99,6 +99,7 @@ namespace CtrEditor.ObjetosSim Diametro = 0.10f; Mass = 1; ColorButton_oculto = Brushes.Gray; + Preserve_Outside_Transport = true; } public void UpdateAfterMove() diff --git a/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs b/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs index 90d1347..246e2eb 100644 --- a/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs +++ b/ObjetosSim/Emuladores/ucBottGenerator.xaml.cs @@ -35,6 +35,10 @@ namespace CtrEditor.ObjetosSim [ObservableProperty] private float offsetTopSalida; + [ObservableProperty] + [property: Description("The bottle will be destroyed if fall outside transport.")] + [property: Category("Enable to Run:")] + private bool preserve_Outside_Transport; [ObservableProperty] [property: Description("PLC tag for consense to run. 1 => always")] @@ -103,6 +107,7 @@ namespace CtrEditor.ObjetosSim Botellas_hora = 10000; Filtro_consenso_ON_s = 1; Filtro_consenso_OFF_s = 0.1f; + Preserve_Outside_Transport = false; } public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds) @@ -144,6 +149,8 @@ namespace CtrEditor.ObjetosSim // No hay botellas, se puede crear una nueva directamente var nuevaBotella = _mainViewModel.CrearObjetoSimulable(typeof(osBotella), X, Y); ((osBotella)nuevaBotella).Diametro = Diametro_botella; + ((osBotella)nuevaBotella).Preserve_Outside_Transport = Preserve_Outside_Transport; + ((osBotella)nuevaBotella).AutoCreated = true; nuevaBotella.AutoCreated = true; UltimaBotella = (osBotella)nuevaBotella; BotellaCreada = true; @@ -158,6 +165,7 @@ namespace CtrEditor.ObjetosSim { osBotella nuevaBotella = (osBotella)_mainViewModel.CrearObjetoSimulable(typeof(osBotella), X, Y); nuevaBotella.Diametro = Diametro_botella; + ((osBotella)nuevaBotella).Preserve_Outside_Transport = Preserve_Outside_Transport; nuevaBotella.AutoCreated = true; UltimaBotella = nuevaBotella; BotellaCreada = true; diff --git a/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs b/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs index c486aa4..2371717 100644 --- a/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs +++ b/ObjetosSim/Estaticos/ucTransporteCurva.xaml.cs @@ -110,6 +110,11 @@ namespace CtrEditor.ObjetosSim } } + public override void OnMoveResizeRotate() + { + ActualizarGeometrias(); + } + [ObservableProperty] public float frictionCoefficient; [ObservableProperty] diff --git a/ObjetosSim/Estaticos/ucTransporteGuias.xaml b/ObjetosSim/Estaticos/ucTransporteGuias.xaml index 2e4b7ea..83334eb 100644 --- a/ObjetosSim/Estaticos/ucTransporteGuias.xaml +++ b/ObjetosSim/Estaticos/ucTransporteGuias.xaml @@ -16,8 +16,8 @@ - - + + @@ -55,7 +55,7 @@ Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}}" Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}" Stretch="Uniform"> -