Modificando BuscarCoincidencias

This commit is contained in:
Miguel 2024-06-10 11:07:25 +02:00
parent 77c9f3db5e
commit 0f34e6cdaa
4 changed files with 136 additions and 65 deletions

View File

@ -65,6 +65,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Aether.Physics2D" Version="2.1.0" /> <PackageReference Include="Aether.Physics2D" Version="2.1.0" />
<PackageReference Include="ClosedXML" Version="0.104.0-preview2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Emgu.CV" Version="4.9.0.5494" /> <PackageReference Include="Emgu.CV" Version="4.9.0.5494" />
<PackageReference Include="Emgu.CV.runtime.windows" Version="4.9.0.5494" /> <PackageReference Include="Emgu.CV.runtime.windows" Version="4.9.0.5494" />

View File

@ -109,7 +109,7 @@ namespace CtrEditor
DatosDeTrabajo.CargarImagenes(); DatosDeTrabajo.CargarImagenes();
ListaImagenes = new ObservableCollection<string>(DatosDeTrabajo.Imagenes.Keys); // Actualizar claves ListaImagenes = new ObservableCollection<string>(DatosDeTrabajo.Imagenes.Keys); // Actualizar claves
SelectedImage = null; SelectedImage = null;
if (EstadoPersistente.Instance.imagen != null && EstadoPersistente.Instance.imagen.Length>0) if (EstadoPersistente.Instance.imagen != null && EstadoPersistente.Instance.imagen.Length > 0)
SelectedImage = EstadoPersistente.Instance.imagen; SelectedImage = EstadoPersistente.Instance.imagen;
else if (ListaImagenes.FirstOrDefault() != null) else if (ListaImagenes.FirstOrDefault() != null)
SelectedImage = ListaImagenes.FirstOrDefault(); SelectedImage = ListaImagenes.FirstOrDefault();
@ -273,10 +273,16 @@ namespace CtrEditor
private void DuplicarUserControl() private void DuplicarUserControl()
{ {
if (SelectedItemOsList is osBase objDuplicar) if (SelectedItemOsList is osBase objDuplicar)
DuplicarObjeto(objDuplicar, 0.5f, 0.5f);
}
public osBase DuplicarObjeto(osBase objDuplicar, float OffsetX, float OffsetY)
{ {
StopSimulation(); StopSimulation();
DisconnectPLC(); DisconnectPLC();
osBase? NuevoObjetoDuplicado = null;
objDuplicar.SalvarDatosNoSerializables(); objDuplicar.SalvarDatosNoSerializables();
var settings = new JsonSerializerSettings var settings = new JsonSerializerSettings
@ -291,33 +297,15 @@ namespace CtrEditor
// Serializar // Serializar
var serializedData = JsonConvert.SerializeObject(objDuplicar, settings); var serializedData = JsonConvert.SerializeObject(objDuplicar, settings);
// Duplicar // Duplicar
var NuevoObjetoDuplicado = JsonConvert.DeserializeObject<osBase>(serializedData, settings); NuevoObjetoDuplicado = JsonConvert.DeserializeObject<osBase>(serializedData, settings);
if (NuevoObjetoDuplicado != null) if (NuevoObjetoDuplicado != null)
{ {
string nombre = NuevoObjetoDuplicado.Nombre; NuevoObjetoDuplicado.Id.ObtenerNuevaID();
string nombre = NuevoObjetoDuplicado.Nombre + "_" + NuevoObjetoDuplicado.Id.Value;
// Expresión regular para identificar un nombre que termina con _número
Regex regex = new Regex(@"_(\d+)$");
if (regex.IsMatch(nombre))
{
// Extraer el número actual y sumarle 1
var match = regex.Match(nombre);
int numeroActual = int.Parse(match.Groups[1].Value);
int nuevoNumero = numeroActual + 1;
// Reemplazar el número en el nombre
nombre = regex.Replace(nombre, $"_{nuevoNumero}");
}
else
{
// Si no termina con _número, añadir _1
nombre += "_1";
}
NuevoObjetoDuplicado.Nombre = nombre; NuevoObjetoDuplicado.Nombre = nombre;
NuevoObjetoDuplicado.Left += 0.5f; NuevoObjetoDuplicado.Left += OffsetX;
NuevoObjetoDuplicado.Top += 0.5f; NuevoObjetoDuplicado.Top += OffsetY;
ObjetosSimulables.Add(NuevoObjetoDuplicado); ObjetosSimulables.Add(NuevoObjetoDuplicado);
CrearUserControlDesdeObjetoSimulable(NuevoObjetoDuplicado); CrearUserControlDesdeObjetoSimulable(NuevoObjetoDuplicado);
} }
@ -330,8 +318,9 @@ namespace CtrEditor
{ {
objDuplicar.RestaurarDatosNoSerializables(); objDuplicar.RestaurarDatosNoSerializables();
} }
return NuevoObjetoDuplicado;
} }
}
private void EliminarUserControl() private void EliminarUserControl()
{ {

View File

@ -18,6 +18,8 @@ using Ookii.Dialogs.Wpf;
using Rect = System.Windows.Rect; using Rect = System.Windows.Rect;
using System.ComponentModel; using System.ComponentModel;
using Newtonsoft.Json; using Newtonsoft.Json;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.ComponentModel;
namespace CtrEditor.ObjetosSim.Extraccion_Datos namespace CtrEditor.ObjetosSim.Extraccion_Datos
{ {
@ -49,6 +51,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
} }
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
bool search_templates; bool search_templates;
partial void OnSearch_templatesChanged(bool oldValue, bool newValue) partial void OnSearch_templatesChanged(bool oldValue, bool newValue)
@ -59,9 +62,11 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
} }
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
bool export_ocr; bool export_ocr;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
string text_export_ocr; string text_export_ocr;
partial void OnExport_ocrChanged(bool value) partial void OnExport_ocrChanged(bool value)
@ -98,36 +103,44 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
[ObservableProperty] [ObservableProperty]
[property: Description("Width of the object.")] [property: Description("Width of the object.")]
[property: Category("Position:")] [property: Category("Layout:")]
public float ancho; public float ancho;
[ObservableProperty] [ObservableProperty]
[property: Description("Height of the object.")] [property: Description("Height of the object.")]
[property: Category("Position:")] [property: Category("Layout:")]
public float alto; public float alto;
[ObservableProperty] [ObservableProperty]
[property: Category("Layout:")]
public float angulo; public float angulo;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
string tag_extract; string tag_extract;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
string clase; string clase;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
string tag_name; string tag_name;
[ObservableProperty] [ObservableProperty]
float opacity_oculto; float opacity_oculto;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
bool show_debug_ocr; bool show_debug_ocr;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
float threshold; float threshold;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
[property: ReadOnly(true)]
float coincidencias; float coincidencias;
@ -317,12 +330,43 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
} }
} }
} }
PopularTagExtraction();
} }
} }
} }
}); });
} }
private void PopularTagExtraction()
{
var objetosSimulablesCopy = new List<osBase>(_mainViewModel.ObjetosSimulables);
foreach (var obj in objetosSimulablesCopy)
if (obj is osExtraccionTag objExtraccionTag)
if (objExtraccionTag.Id_Search_Templates == this.Nombre && objExtraccionTag.Cloned)
_mainViewModel.ObjetosSimulables.Remove(objExtraccionTag);
var objetosSimulables2Copy = new List<osBase>(_mainViewModel.ObjetosSimulables);
foreach (var rectangle in search_rectangles)
{
float offsetX = PixelsToMeters((float)rectangle.X) - Left;
float offsetY = PixelsToMeters((float)rectangle.Y) - Top;
foreach (var eTag in objetosSimulables2Copy)
{
if (eTag is osExtraccionTag objExtraccionTag)
{
if (objExtraccionTag.Id_Search_Templates == this.Nombre)
{
osExtraccionTag newObj = (osExtraccionTag)_mainViewModel.DuplicarObjeto(objExtraccionTag, offsetX, offsetY);
if (newObj != null)
newObj.Cloned = true;
}
}
}
}
}
// Método para convertir BitmapSource a Mat // Método para convertir BitmapSource a Mat
private Mat BitmapSourceToMat(BitmapSource bitmapSource) private Mat BitmapSourceToMat(BitmapSource bitmapSource)

View File

@ -4,7 +4,8 @@ using System.Windows.Navigation;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using Newtonsoft.Json; using Newtonsoft.Json;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.ComponentModel;
namespace CtrEditor.ObjetosSim.Extraccion_Datos namespace CtrEditor.ObjetosSim.Extraccion_Datos
{ {
@ -15,10 +16,6 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
public partial class osExtraccionTag : osBase, IosBase public partial class osExtraccionTag : osBase, IosBase
{ {
private osBase _osMotor = null;
private simTransporte SimGeometria;
public static string NombreClase() public static string NombreClase()
{ {
return "Extraccion Tags"; return "Extraccion Tags";
@ -31,8 +28,16 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
} }
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
bool extraer; bool extraer;
[ObservableProperty]
[property: Description("Autocreated and cloned with Search Templates")]
[property: Category("Tag Extraction:")]
bool cloned;
public override void TopChanged(float value) public override void TopChanged(float value)
{ {
base.TopChanged(value); base.TopChanged(value);
@ -51,6 +56,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
} }
[ObservableProperty] [ObservableProperty]
[property: Category("Layout:")]
public float ancho; public float ancho;
partial void OnAnchoChanged(float value) partial void OnAnchoChanged(float value)
@ -59,6 +65,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
} }
[ObservableProperty] [ObservableProperty]
[property: Category("Layout:")]
public float alto; public float alto;
partial void OnAltoChanged(float value) partial void OnAltoChanged(float value)
@ -71,19 +78,49 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
CaptureImageAreaAndDoOCR(); CaptureImageAreaAndDoOCR();
} }
[ObservableProperty]
osBuscarCoincidencias search_Templates; private osBuscarCoincidencias Search_Templates;
[ObservableProperty] [ObservableProperty]
[property: Description("Link to Search Templates")]
[property: Category("Tag Extraction:")]
[property: ItemsSource(typeof(osBaseItemsSource<osBuscarCoincidencias>))]
string id_Search_Templates;
partial void OnId_Search_TemplatesChanged(string value)
{
if (Search_Templates != null)
Search_Templates.PropertyChanged -= OnMotorPropertyChanged;
if (_mainViewModel != null && value != null && value.Length > 0)
{
Search_Templates = (osBuscarCoincidencias)_mainViewModel.ObjetosSimulables.FirstOrDefault(s => (s is osBuscarCoincidencias && s.Nombre == value), null);
if (Search_Templates != null)
Search_Templates.PropertyChanged += OnMotorPropertyChanged;
}
}
private void OnMotorPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(osBuscarCoincidencias.Nombre))
{
Id_Search_Templates = ((osBuscarCoincidencias)sender).Nombre;
}
}
[ObservableProperty]
[property: Category("Layout:")]
public float angulo; public float angulo;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
string tag_extract; string tag_extract;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
string clase; string clase;
[ObservableProperty] [ObservableProperty]
[property: Category("Tag Extraction:")]
string tag_name; string tag_name;
[ObservableProperty] [ObservableProperty]
@ -107,7 +144,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
// El UserControl ya se ha cargado y podemos obtener las coordenadas para // El UserControl ya se ha cargado y podemos obtener las coordenadas para
// crear el objeto de simulacion // crear el objeto de simulacion
base.ucLoaded(); base.ucLoaded();
OnId_Search_TemplatesChanged(Id_Search_Templates); // Actualizar Link
} }
} }