Agregada la funcion de crear el archivo base.png si no hay imagenes en el directorio elegido

This commit is contained in:
Miguel 2024-09-12 16:43:39 +02:00
parent 261fe679d8
commit 353b4b99e6
12 changed files with 173 additions and 94 deletions

View File

@ -130,7 +130,7 @@
<Resource Include="imagenes\motorNegro.png" />
<Resource Include="imagenes\motorVerde.png" />
<Resource Include="imagenes\tank.png" />
<Resource Include="Images\base.png" />
<EmbeddedResource Include="Images\base.png" />
</ItemGroup>
<ItemGroup>

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CtrEditor.FuncionesBase
namespace CtrEditor.FuncionesBase
{
public enum ZIndexEnum
{

View File

@ -119,6 +119,15 @@ namespace CtrEditor
EstadoPersistente.Instance.GuardarEstado(); // Guardar el estado actualizado
DatosDeTrabajo.CargarImagenes();
ListaImagenes = new ObservableCollection<string>(DatosDeTrabajo.Imagenes.Keys); // Actualizar claves
// Si no hay imágenes en el directorio, copiar base.png desde los recursos
if (!ListaImagenes.Any())
{
CopiarImagenBase(value);
// Recargar las imágenes después de copiar la imagen base
DatosDeTrabajo.CargarImagenes();
ListaImagenes = new ObservableCollection<string>(DatosDeTrabajo.Imagenes.Keys); // Actualizar claves nuevamente
}
SelectedImage = null;
var x = ListaImagenes.FirstOrDefault(o => o == EstadoPersistente.Instance.imagen, null);
if (EstadoPersistente.Instance.imagen != null && EstadoPersistente.Instance.imagen.Length > 0 && x != null)
@ -132,6 +141,34 @@ namespace CtrEditor
}
}
// Función para copiar la imagen base desde los recursos
private void CopiarImagenBase(string directorio)
{
try
{
// Obtener el path del archivo base.png desde los recursos (dentro del ensamblado)
var assembly = Assembly.GetExecutingAssembly();
var resourcePath = "CtrEditor.Images.base.png"; // Ajusta el namespace y el path según tu proyecto
using (Stream resourceStream = assembly.GetManifestResourceStream(resourcePath))
{
if (resourceStream != null)
{
string destino = Path.Combine(directorio, "base.png");
using (FileStream fileStream = new FileStream(destino, FileMode.Create, FileAccess.Write))
{
resourceStream.CopyTo(fileStream);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show($"Error al copiar la imagen base: {ex.Message}");
}
}
[RelayCommand]
public void DebugWindow()
{
@ -209,7 +246,7 @@ namespace CtrEditor
PLCViewModel = new PLCViewModel();
_timerPLCUpdate = new DispatcherTimer();
_timerPLCUpdate.Interval = TimeSpan.FromMilliseconds(100); // ajusta el intervalo según sea necesario
_timerPLCUpdate.Interval = TimeSpan.FromMilliseconds(2); // ajusta el intervalo según sea necesario
_timerPLCUpdate.Tick += OnRefreshEvent;
InitializeTipoSimulableList();

View File

@ -60,12 +60,7 @@ namespace CtrEditor.ObjetosSim
private float inercia_desde_simulacion;
[ObservableProperty]
bool test;
partial void OnTestChanged(bool value)
{
SimGeometria.Body.LinearVelocity = new Vector2(1,1);
}
private bool preserve_Outside_Transport;
[ObservableProperty]
private float porcentaje_Traccion;
@ -93,9 +88,8 @@ namespace CtrEditor.ObjetosSim
private void ActualizarGeometrias()
{
if (SimGeometria != null)
if (SimGeometria != null && !RemoverDesdeSimulacion)
{
SimGeometria.SetPosition(GetCentro());
}
}
@ -108,10 +102,13 @@ namespace CtrEditor.ObjetosSim
}
public void UpdateAfterMove()
{
if (!RemoverDesdeSimulacion)
{
ActualizarGeometrias();
SimGeometria?.SetDiameter(Diametro);
}
}
public override void UpdateGeometryStart()
{
@ -126,6 +123,7 @@ namespace CtrEditor.ObjetosSim
}
public override void UpdateControl(int elapsedMilliseconds)
{
SetCentro(SimGeometria.Center);
if (SimGeometria.isRestricted)
ColorButton_oculto = Brushes.Yellow;
@ -136,8 +134,15 @@ namespace CtrEditor.ObjetosSim
else
ColorButton_oculto = Brushes.Gray;
}
if (SimGeometria.Descartar) // Ha sido marcada para remover
// Ha sido marcada para remover
if (SimGeometria.Descartar)
RemoverDesdeSimulacion = true;
// Eliminar la botella si esta fuera de un transporte
if (!Preserve_Outside_Transport && Porcentaje_Traccion == 0 && Math.Abs(SimGeometria.Body.LinearVelocity.X) <= 0.001 && Math.Abs(SimGeometria.Body.LinearVelocity.Y) <= 0.001)
RemoverDesdeSimulacion = true;
Velocidad_desde_simulacion = SimGeometria.Body.LinearVelocity.ToString();
Inercia_desde_simulacion = SimGeometria.Body.Inertia;
Porcentaje_Traccion = SimGeometria.OverlapPercentage;

View File

@ -4,6 +4,7 @@ using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Diagnostics;
using CtrEditor.FuncionesBase;
using System.ComponentModel;
namespace CtrEditor.ObjetosSim
{
@ -34,9 +35,15 @@ namespace CtrEditor.ObjetosSim
[ObservableProperty]
private float offsetTopSalida;
[ObservableProperty]
[property: Description("PLC tag for consense to run. 1 => always")]
[property: Category("Enable to Run:")]
private string tag_consenso;
[ObservableProperty]
[property: Description("Consense to run.")]
[property: Category("Enable to Run:")]
private bool consenso;
partial void OnConsensoChanged(bool value)
@ -44,11 +51,25 @@ namespace CtrEditor.ObjetosSim
_TON_TOFF.Senal = value;
}
[ObservableProperty]
[property: Description("Consense is Normally close.")]
[property: Category("Enable to Run:")]
private bool consenso_NC;
[ObservableProperty]
[property: Description("Enable filter.")]
[property: Category("Enable to Run:")]
private bool consenso_Filtrado;
[ObservableProperty]
float filtro_consenso_s;
[property: Description("Time ON in s.")]
[property: Category("Enable to Run:")]
float filtro_consenso_ON_s;
[ObservableProperty]
[property: Description("Time OFF in s.")]
[property: Category("Enable to Run:")]
float filtro_consenso_OFF_s;
[ObservableProperty]
[property: Description("Filter OUT signal.")]
[property: Category("Enable to Run:")]
bool filter_Output;
[ObservableProperty]
private float botellas_hora;
@ -77,10 +98,11 @@ namespace CtrEditor.ObjetosSim
Ancho = 0.30f;
Alto = 0.30f;
Angulo = 0;
Velocidad_actual_percentual = 0;
Velocidad_actual_percentual = 100;
Diametro_botella = 0.1f;
Botellas_hora = 10000;
Filtro_consenso_s = 1;
Filtro_consenso_ON_s = 1;
Filtro_consenso_OFF_s = 0.1f;
}
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
@ -95,20 +117,22 @@ namespace CtrEditor.ObjetosSim
{
bool habilitado;
_TON_TOFF.Tiempo_ON_s = _TON_TOFF.Tiempo_OFF_s = Filtro_consenso_s;
_TON_TOFF.Tiempo_ON_s = Filtro_consenso_ON_s;
_TON_TOFF.Tiempo_OFF_s = Filtro_consenso_OFF_s;
if (Consenso_Filtrado)
habilitado = _TON_TOFF.SenalFiltrada();
else
habilitado = Consenso;
Filter_Output = habilitado;
if (habilitado && Velocidad_actual_percentual > 0)
{
TiempoRestante -= elapsedMilliseconds / 1000.0f;
if (TiempoRestante <= 0)
{
TiempoRestante += 3600 / (Botellas_hora * (Velocidad_actual_percentual / 100.0f));
bool BotellaCreada = false;
var X = Left + OffsetLeftSalida;
var Y = Top + OffsetTopSalida;
@ -122,21 +146,26 @@ namespace CtrEditor.ObjetosSim
((osBotella)nuevaBotella).Diametro = Diametro_botella;
nuevaBotella.AutoCreated = true;
UltimaBotella = (osBotella)nuevaBotella;
BotellaCreada = true;
}
else
{
// Calcular la distancia entre el centro de la última botella y la nueva posición
float distancia = (float)Math.Sqrt(Math.Pow(UltimaBotella.Left - X, 2) + Math.Pow(UltimaBotella.Top - Y, 2));
float distanciaMinima = Diametro_botella / 2; // Asumiendo que el diámetro de la nueva botella es similar
float distanciaMinima = Diametro_botella / 4; // Asumiendo que el diámetro de la nueva botella es similar
if (distancia > distanciaMinima)
{
var nuevaBotella = _mainViewModel.CrearObjetoSimulable(typeof(osBotella), X, Y);
((osBotella)nuevaBotella).Diametro = Diametro_botella;
osBotella nuevaBotella = (osBotella)_mainViewModel.CrearObjetoSimulable(typeof(osBotella), X, Y);
nuevaBotella.Diametro = Diametro_botella;
nuevaBotella.AutoCreated = true;
UltimaBotella = (osBotella)nuevaBotella;
UltimaBotella = nuevaBotella;
BotellaCreada = true;
}
}
if (BotellaCreada)
TiempoRestante += 3600 / (Botellas_hora * (Velocidad_actual_percentual / 100.0f));
}
}
else

View File

@ -131,10 +131,10 @@ namespace CtrEditor.ObjetosSim
if (distancia > distanciaMinima)
{
var nuevaBotella = _mainViewModel.CrearObjetoSimulable(typeof(osBotella), X, Y);
((osBotella)nuevaBotella).Diametro = Diametro_botella;
osBotella nuevaBotella = (osBotella)_mainViewModel.CrearObjetoSimulable(typeof(osBotella), X, Y);
nuevaBotella.Diametro = Diametro_botella;
nuevaBotella.AutoCreated = true;
UltimaBotella = (osBotella)nuevaBotella;
UltimaBotella = nuevaBotella;
}
}
}

View File

@ -1,11 +1,11 @@

using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.FuncionesBase;
using LibS7Adv;
using Newtonsoft.Json;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Newtonsoft.Json;
using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.FuncionesBase;
namespace CtrEditor.ObjetosSim
{
@ -45,7 +45,7 @@ namespace CtrEditor.ObjetosSim
}
[ObservableProperty]
public float proporcionalSpeed;
public float proporcional_Speed;
[ObservableProperty]
public float max_Speed_for_Ramp;
@ -98,7 +98,7 @@ namespace CtrEditor.ObjetosSim
{
Tamano = 0.30f;
PLC_NumeroMotor = 31;
ProporcionalSpeed = 100;
Proporcional_Speed = 100;
Max_Speed_for_Ramp = 100;
TiempoRampa = 3;
ImageSource_oculta = ImageFromPath("/imagenes/motor2.png");
@ -112,7 +112,7 @@ namespace CtrEditor.ObjetosSim
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
{
motState.UpdatePLC(plc, this, elapsedMilliseconds);
Velocidad = (ProporcionalSpeed / 100) * (motState.STATUS_VFD_ACT_Speed_Hz / 10);
Velocidad = (Proporcional_Speed / 100) * (motState.STATUS_VFD_ACT_Speed_Hz / 10);
}
public override void UpdateControl(int elapsedMilliseconds)

View File

@ -2,16 +2,12 @@
using System.Windows.Controls;
using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Simulacion;
using System.IO;
using System.Windows.Media.Imaging;
using Tesseract;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV;
using System.Drawing;
using Image = System.Windows.Controls.Image;
using Point = System.Drawing.Point;
using Rectangle = System.Windows.Shapes.Rectangle;
using Size = System.Drawing.Size;
using Ookii.Dialogs.Wpf;
@ -21,9 +17,7 @@ using Newtonsoft.Json;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.ComponentModel;
using ClosedXML.Excel;
using DocumentFormat.OpenXml.Spreadsheet;
using Colors = System.Windows.Media.Colors;
using DocumentFormat.OpenXml.Drawing.Charts;
using CtrEditor.FuncionesBase;
namespace CtrEditor.ObjetosSim.Extraccion_Datos

View File

@ -1,13 +1,10 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using ClosedXML.Excel;
using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Simulacion;
using Newtonsoft.Json;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.ComponentModel;
using ClosedXML.Excel;
using CtrEditor.FuncionesBase;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
namespace CtrEditor.ObjetosSim.Extraccion_Datos
{
@ -76,7 +73,8 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
ResetTimer();
}
public override void OnTimerAfterMovement() {
public override void OnTimerAfterMovement()
{
Angulo = (float)Math.Round(Angulo / 90) * 90;
if (Extraer)

View File

@ -39,7 +39,7 @@
VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2,2,2,2" Grid.Column="1"/>
<Rectangle x:Name="Photocell" Grid.Column="2" Width="{Binding Ancho, Converter={StaticResource MeterToPixelConverter}, ConverterParameter=0.9}"
Height="{Binding Alto, Converter={StaticResource MeterToPixelConverter}}">
Height="{Binding Ancho_Haz_De_Luz, Converter={StaticResource MeterToPixelConverter}}">
<Rectangle.Fill>
<VisualBrush x:Name="MovingPattern" TileMode="Tile" Viewport="0,0,3,3" ViewportUnits="Absolute" Viewbox="0,0,3,3" ViewboxUnits="Absolute">
<VisualBrush.Visual>

View File

@ -7,7 +7,9 @@ using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Diagnostics;
using CtrEditor.FuncionesBase;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute;
using System.ComponentModel;
namespace CtrEditor.ObjetosSim
{
@ -33,8 +35,13 @@ namespace CtrEditor.ObjetosSim
}
[ObservableProperty]
[property: Description("Color")]
[property: Category("Layout:")]
Brush color;
[ObservableProperty]
[property: Description("Light cut")]
[property: Category("Debug:")]
bool luzCortada;
partial void OnLuzCortadaChanged(bool value)
@ -67,9 +74,18 @@ namespace CtrEditor.ObjetosSim
}
[ObservableProperty]
[property: Description("Size of the Light.")]
[property: Category("Setup:")]
float ancho_Haz_De_Luz;
[ObservableProperty]
[property: Description("Distance to the neck.")]
[property: Category("Debug:")]
float distancia_cuello;
[ObservableProperty]
[property: Description("Type of detection: Neck of the bottle or Complete bottle.")]
[property: Category("Setup:")]
bool detectarCuello;
partial void OnDetectarCuelloChanged(bool value)
@ -81,6 +97,8 @@ namespace CtrEditor.ObjetosSim
[ObservableProperty]
[property: Description("Filter signal.")]
[property: Category("Setup:")]
float filter_Frecuency;
partial void OnFilter_FrecuencyChanged(float value)
@ -90,18 +108,24 @@ namespace CtrEditor.ObjetosSim
}
[ObservableProperty]
[property: Category("Debug:")]
float frecuency;
[ObservableProperty]
[property: Category("Debug:")]
float lenght_positive_pulse;
[ObservableProperty]
[property: Category("Debug:")]
float lenght_negative_pulse;
[ObservableProperty]
[property: Category("Debug:")]
float lenght_FP_to_FP;
[ObservableProperty]
[property: Description("Type Filter signal.")]
[property: Category("Setup:")]
public bool tipo_NC;
partial void OnTipo_NCChanged(bool value)
@ -142,13 +166,14 @@ namespace CtrEditor.ObjetosSim
private void ActualizarGeometrias()
{
if (_visualRepresentation is ucPhotocell uc)
UpdateRectangle(Simulation_Photocell, uc.Photocell, Alto, Ancho, Angulo);
UpdateRectangle(Simulation_Photocell, uc.Photocell, Ancho_Haz_De_Luz, Ancho, Angulo);
}
public osPhotocell()
{
Ancho = 1;
Alto = 0.03f;
Ancho_Haz_De_Luz = 0.01f;
Frecuency = 0;
timer = new Stopwatch();
timer.Start();

View File

@ -1,29 +1,22 @@

using System.Text.Json.Serialization;
using System.Windows;
using LibS7Adv;
using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.FuncionesBase;
using CtrEditor.Simulacion;
using System.Windows.Media;
using LibS7Adv;
using nkast.Aether.Physics2D.Common;
using Siemens.Simatic.Simulation.Runtime;
using System.Windows.Media.Imaging;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Windows.Media.Animation;
using System.Diagnostics;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.ComponentModel;
using System.Configuration;
using System.Windows.Threading;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Tesseract;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using Newtonsoft.Json;
using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute;
using System.Collections.ObjectModel;
using ItemCollection = Xceed.Wpf.Toolkit.PropertyGrid.Attributes.ItemCollection;
using nkast.Aether.Physics2D.Dynamics.Joints;
using CtrEditor.FuncionesBase;
using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute;
namespace CtrEditor.ObjetosSim
{
@ -1068,12 +1061,12 @@ namespace CtrEditor.ObjetosSim
if (value)
{
ReiniciarTimer(_stopwatch_ON);
_stopwatch_OFF.Reset();
StopTimer(_stopwatch_OFF);
}
else
{
_stopwatch_ON.Reset();
ReiniciarTimer(_stopwatch_OFF);
StopTimer(_stopwatch_ON);
}
}
}
@ -1097,9 +1090,13 @@ namespace CtrEditor.ObjetosSim
void ReiniciarTimer(Stopwatch timer)
{
timer.Reset();
timer.Start();
}
void StopTimer(Stopwatch timer)
{
timer.Reset();
timer.Stop();
}
}