Agregado de filtrado de objetossimulables. Hay mejorarlo.

This commit is contained in:
Miguel 2024-06-13 00:26:02 +02:00
parent dc01704da6
commit f33273bbf6
8 changed files with 123 additions and 44 deletions

View File

@ -1,5 +1,4 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Controls;
using System.Windows.Input;
using Ookii.Dialogs.Wpf;
@ -15,14 +14,11 @@ using System.Diagnostics;
using System.Reflection;
using CommunityToolkit.Mvvm.ComponentModel;
using Xceed.Wpf.Toolkit.PropertyGrid;
using System.Text.RegularExpressions;
using System.Windows.Data;
using CtrEditor.ObjetosSim.Extraccion_Datos;
using ClosedXML.Excel;
using DocumentFormat.OpenXml.Spreadsheet;
using CommunityToolkit.Mvvm.Input;
using CtrEditor.PopUps;
using CtrEditor.ObjetosSim.UserControls;
using System.Windows.Data;
namespace CtrEditor
{
@ -88,6 +84,8 @@ namespace CtrEditor
public MainWindow MainWindow { get => mainWindow; set => mainWindow = value; }
[ObservableProperty]
public ICollectionView vistaFiltrada;
[ObservableProperty]
private float canvasLeft;
@ -123,7 +121,8 @@ namespace CtrEditor
DatosDeTrabajo.CargarImagenes();
ListaImagenes = new ObservableCollection<string>(DatosDeTrabajo.Imagenes.Keys); // Actualizar claves
SelectedImage = null;
if (EstadoPersistente.Instance.imagen != null && EstadoPersistente.Instance.imagen.Length > 0)
var x = ListaImagenes.FirstOrDefault(o => o == EstadoPersistente.Instance.imagen, null);
if (EstadoPersistente.Instance.imagen != null && EstadoPersistente.Instance.imagen.Length > 0 && x != null)
SelectedImage = EstadoPersistente.Instance.imagen;
else if (ListaImagenes.FirstOrDefault() != null)
SelectedImage = ListaImagenes.FirstOrDefault();
@ -154,16 +153,19 @@ namespace CtrEditor
}
[ObservableProperty]
private TreeItemViewModel selectedItemOsList;
private osBase selectedItemOsList;
partial void OnSelectedItemOsListChanged(TreeItemViewModel value)
partial void OnSelectedItemOsListChanged(osBase value)
{
if (value.Item != null)
if (value != null)
habilitarEliminarUserControl = true;
else
habilitarEliminarUserControl = false;
}
[ObservableProperty]
public ObjetosSimulablesFilterTypes osListFilter;
[ObservableProperty]
private TipoSimulable selectedItem;
@ -173,6 +175,12 @@ namespace CtrEditor
[ObservableProperty]
public ObservableCollection<osBase> objetosSimulables;
partial void OnObjetosSimulablesChanged(ObservableCollection<osBase> value)
{
VistaFiltrada = CollectionViewSource.GetDefaultView(ObjetosSimulables);
VistaFiltrada.Filter = FiltrarObjetos;
ObjetosSimulables.CollectionChanged += (s, e) => VistaFiltrada.Refresh();
}
//
// Constructor
@ -183,9 +191,11 @@ namespace CtrEditor
OpenWorkDirectoryCommand = new RelayCommand(OpenWorkDirectory);
datosDeTrabajo = new DatosDeTrabajo();
ObjetosSimulables = new ObservableCollection<osBase>();
TypeDecorationManager.AddExpandableIListConverter<osBase>(objetosSimulables.GetType());
osListFilter = new ObjetosSimulablesFilterTypes();
osListFilter.PropertyChanged += OsListFilter_PropertyChanged;
ObjetosSimulables = new ObservableCollection<osBase>();
ListaOsBase = new ObservableCollection<TipoSimulable>();
@ -226,6 +236,20 @@ namespace CtrEditor
stopwatch_Sim.Start();
}
private void OsListFilter_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
VistaFiltrada.Refresh();
}
private bool FiltrarObjetos(object item)
{
var objeto = item as osBase;
return (objeto.Cloned == osListFilter.Cloned) &&
(objeto.Enable_On_All_Pages == osListFilter.Enable_On_All_Pages) &&
(objeto.Show_On_This_Page == osListFilter.Show_On_This_Page);
}
public void LoadInitialData()
{
// Suponiendo que "SelectedImage" es una propiedad que al establecerse dispara "ImageSelected"
@ -299,7 +323,7 @@ namespace CtrEditor
private void DuplicarUserControl()
{
if (SelectedItemOsList.Item is osBase objDuplicar)
if (SelectedItemOsList is osBase objDuplicar)
DuplicarObjeto(objDuplicar, 0.5f, 0.5f);
}
@ -351,10 +375,9 @@ namespace CtrEditor
private void EliminarUserControl()
{
if (SelectedItemOsList.Item is osBase objEliminar)
if (SelectedItemOsList is osBase objEliminar)
{
RemoverObjetoSimulable(objEliminar);
}
}
@ -368,17 +391,19 @@ namespace CtrEditor
private void EliminarAutoCreatedCommand()
{
var objetosSimulablesCopy = new List<osBase>(ObjetosSimulables);
foreach (var obj in objetosSimulablesCopy)
if (obj.AutoCreated)
var osAutoCreated_List = ObjetosSimulables
.Where(o => o.Show_On_This_Page && o.AutoCreated)
.ToList();
foreach (var obj in osAutoCreated_List)
RemoverObjetoSimulable(obj);
}
private void EliminarClonedCommand()
{
var objetosSimulablesCopy = new List<osBase>(ObjetosSimulables);
foreach (var obj in objetosSimulablesCopy)
if (obj is osExtraccionTag TEobj && TEobj.Cloned)
var osCloned_List = ObjetosSimulables
.Where(o => o.Show_On_This_Page && o.Cloned)
.ToList();
foreach (var obj in osCloned_List)
RemoverObjetoSimulable(obj);
}
@ -489,19 +514,22 @@ namespace CtrEditor
int col = 0;
// Filtrar los objetos de tipo osExtraccionTag y crear una nueva lista
var osBuscarCoincidencias_List = ObjetosSimulables.OfType<osBuscarCoincidencias>().ToList();
var osBuscarCoincidencias_List = ObjetosSimulables
.OfType<osBuscarCoincidencias>()
.Where(tag => tag.Show_On_This_Page)
.ToList();
var osExtraccionTagBaseGrouped_List = ObjetosSimulables
.OfType<osExtraccionTag>()
.Where(tag => !tag.Cloned && tag.Id_Search_Templates != null && tag.Id_Search_Templates != "")
.Where(tag => tag.Show_On_This_Page && !tag.Cloned && tag.Id_Search_Templates != null && tag.Id_Search_Templates != "")
.ToList();
var osExtraccionTagBaseFix_List = ObjetosSimulables
.OfType<osExtraccionTag>()
.Where(tag => !tag.Cloned && (tag.Id_Search_Templates == null || tag.Id_Search_Templates == ""))
.Where(tag => tag.Show_On_This_Page && !tag.Cloned && (tag.Id_Search_Templates == null || tag.Id_Search_Templates == ""))
.ToList();
var osExtraccionTagCloned_List = ObjetosSimulables
.OfType<osExtraccionTag>()
.Where(tag => tag.Cloned)
.Where(tag => tag.Show_On_This_Page && tag.Cloned)
.ToList();
// Columnas Fijas para los Tags no agrupados que no son clonados

View File

@ -164,6 +164,7 @@
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="50" />
<RowDefinition Height="*" MinHeight="100" />
<!-- ListBox1 -->
<RowDefinition Height="Auto" />
@ -203,18 +204,40 @@
</ToolBar>
</ToolBarTray>
<uc:TreeListControlOS x:Name="ListaOS" Grid.Row="1" Margin="5" ItemsSource="{Binding DataContext.ObjetosSimulables,
RelativeSource={RelativeSource AncestorType=Window}}"
SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=Window}}"
SelectionChanged="TreeListControl_SelectionChanged" />
<xctk:PropertyGrid Grid.Row="1" x:Name="PanelFilter" AutoGenerateProperties="True"
ShowDescriptionByTooltip="False" ShowSearchBox="False" ShowSortOptions="False"
ShowSummary="False" ShowTitle="False" SelectedObject="{Binding OsListFilter}">
</xctk:PropertyGrid>
<!-- ListBox -->
<ListBox x:Name="ListaOs" Grid.Row="2" Margin="5" ItemsSource="{Binding VistaFiltrada}"
SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay}"
SelectionChanged="ListaOs_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Nombre}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Enable_On_All_Pages}" Value="True">
<Setter Property="Foreground" Value="Blue" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Enable_On_All_Pages}" Value="False">
<Setter Property="Foreground" Value="Black" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!-- GridSplitter -->
<GridSplitter Grid.Row="2" Height="5" HorizontalAlignment="Stretch" Background="Gray"
<GridSplitter Grid.Row="3" Height="5" HorizontalAlignment="Stretch" Background="Gray"
ResizeDirection="Rows" VerticalAlignment="Center" />
<!-- PanelEdicion -->
<xctk:PropertyGrid Grid.Row="3" Margin="5" x:Name="PanelEdicion" AutoGenerateProperties="False"
<xctk:PropertyGrid Grid.Row="4" Margin="5" x:Name="PanelEdicion" AutoGenerateProperties="False"
ShowDescriptionByTooltip="True">
<xctk:PropertyGrid.EditorDefinitions>
@ -314,7 +337,7 @@
</xctk:PropertyGrid.EditorDefinitions>
</xctk:PropertyGrid>
<ToolBarTray Grid.Row="4">
<ToolBarTray Grid.Row="5">
<ToolBar>
<Button Command="{Binding TBEliminarUserControlCommand}" ToolTip="Eliminar Control">
<StackPanel>

View File

@ -146,7 +146,7 @@ namespace CtrEditor
var viewModel = DataContext as MainViewModel;
if (viewModel != null)
{
ListaOS.SelectedItem = ListaOS.FindViewModelForItem(datos); // Esto desencadenará ListaOs_SelectionChanged
viewModel.SelectedItemOsList = datos; // Esto desencadenará ListaOs_SelectionChanged
}
}
@ -476,12 +476,12 @@ namespace CtrEditor
}
}
private void TreeListControl_SelectionChanged(object sender, ObjetosSim.UserControls.SelectionChangedEventArgs e)
private void ListaOs_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
//PanelEdicion.Children.Clear(); // Limpiar el panel existente
UserControlFactory.LimpiarPropiedadesosDatos(PanelEdicion);
if (e.SelectedItem.Item != null && e.SelectedItem.Item is osBase selectedObject)
if (e.AddedItems.Count > 0 && e.AddedItems[0] is osBase selectedObject)
CargarPropiedadesosDatos(selectedObject);
}
}

View File

@ -344,7 +344,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
foreach (var obj in objetosSimulablesCopy)
if (obj is osExtraccionTag objExtraccionTag)
if (objExtraccionTag.Id_Search_Templates == this.Nombre && objExtraccionTag.Cloned)
_mainViewModel.ObjetosSimulables.Remove(objExtraccionTag);
_mainViewModel.RemoverObjetoSimulable(objExtraccionTag);
var objetosSimulables2Copy = new List<osBase>(_mainViewModel.ObjetosSimulables);
// Saltar el primer rectángulo en el foreach

View File

@ -25,7 +25,12 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
public override string Nombre
{
get => nombre;
set => SetProperty(ref nombre, value);
set
{
if (Collumn_name == null || Collumn_name.Length==0)
Collumn_name = value;
SetProperty(ref nombre, value);
}
}
[ObservableProperty]
@ -38,18 +43,19 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
public override void TopChanged(float value)
{
base.TopChanged(value);
ResetTimer();
if (Extraer) ResetTimer();
}
public override void LeftChanged(float value)
{
base.LeftChanged(value);
ResetTimer();
if (Extraer) ResetTimer();
}
partial void OnExtraerChanged(bool value)
{
ResetTimer();
if (Extraer)
ResetTimer();
}
[ObservableProperty]
@ -58,7 +64,8 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
partial void OnAnchoChanged(float value)
{
ResetTimer();
if (Extraer)
ResetTimer();
}
[ObservableProperty]
@ -67,7 +74,8 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
partial void OnAltoChanged(float value)
{
ResetTimer();
if (Extraer)
ResetTimer();
}
[ObservableProperty]
@ -76,7 +84,8 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
partial void OnAnguloChanged(float value)
{
ResetTimer();
if (Extraer)
ResetTimer();
}
public override void OnTimerAfterMovement() {
@ -84,6 +93,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
if (Extraer)
CaptureImageAreaAndDoOCR();
Extraer = false;
}

View File

@ -39,6 +39,10 @@ namespace CtrEditor.PopUps
public AssignImagesViewModel()
{
SelectedImagenes = new ObservableCollection<string>();
ListaImagenes = new ObservableCollection<string>();
ObjetosSimulables = new ObservableCollection<osBase>();
SelectedObjetosSimulables = new ObservableCollection<osBase>();
SelectedObjetosSimulables.CollectionChanged += SelectedObjetosSimulables_CollectionChanged;
}

View File

@ -12,9 +12,21 @@ using CtrEditor.ObjetosSim;
using System.Collections.ObjectModel;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.Collections;
using CommunityToolkit.Mvvm.ComponentModel;
namespace CtrEditor
{
public partial class ObjetosSimulablesFilterTypes : ObservableObject
{
[ObservableProperty]
public bool cloned;
[ObservableProperty]
public bool enable_On_All_Pages;
[ObservableProperty]
public bool show_On_This_Page;
}
public class ListItemPropertyDescriptor<T> : PropertyDescriptor
{
private readonly IList<T> owner;

View File

@ -24,6 +24,8 @@ namespace CtrEditor
private string _imagen;
private int _id;
public ObjetosSimulablesFilterTypes osListFilter;
// Propiedad pública con get y set para controlar el acceso a _strDirectorioTrabajo
public string directorio
{