Creando los botones de Seleccion multiple
This commit is contained in:
parent
0f34e6cdaa
commit
922a46d616
|
@ -27,22 +27,27 @@
|
|||
<ItemGroup>
|
||||
<None Remove="app2.png" />
|
||||
<None Remove="CtrEditorE.png" />
|
||||
<None Remove="Icons\allselect.png" />
|
||||
<None Remove="Icons\analyze.png" />
|
||||
<None Remove="Icons\app.256x256.ico" />
|
||||
<None Remove="Icons\app.png" />
|
||||
<None Remove="Icons\app2.128x128.ico" />
|
||||
<None Remove="Icons\app2.256x256.ico" />
|
||||
<None Remove="Icons\app2.png" />
|
||||
<None Remove="Icons\borrar.png" />
|
||||
<None Remove="Icons\choose.png" />
|
||||
<None Remove="Icons\connect.png" />
|
||||
<None Remove="Icons\CtrEditorA.png" />
|
||||
<None Remove="Icons\CtrEditorC.png" />
|
||||
<None Remove="Icons\CtrEditorE.png" />
|
||||
<None Remove="Icons\disconnect.png" />
|
||||
<None Remove="Icons\duplicate.png" />
|
||||
<None Remove="Icons\extract.png" />
|
||||
<None Remove="Icons\fotocelula.png" />
|
||||
<None Remove="Icons\save.png" />
|
||||
<None Remove="Icons\start.png" />
|
||||
<None Remove="Icons\stop.png" />
|
||||
<None Remove="Icons\unselect.png" />
|
||||
<None Remove="imagenes\filler.png" />
|
||||
<None Remove="imagenes\gear.png" />
|
||||
<None Remove="imagenes\motorNegro.png" />
|
||||
|
@ -89,19 +94,26 @@
|
|||
<ItemGroup>
|
||||
<Resource Include="app2.png" />
|
||||
<Resource Include="CtrEditorE.png" />
|
||||
<Resource Include="Icons\allselect.png" />
|
||||
<Resource Include="Icons\analyze.png" />
|
||||
<Resource Include="Icons\app.png" />
|
||||
<Resource Include="Icons\app2.png" />
|
||||
<Resource Include="Icons\borrar.png" />
|
||||
<Resource Include="Icons\choose.png" />
|
||||
<Resource Include="Icons\connect.png" />
|
||||
<Resource Include="Icons\CtrEditorA.png" />
|
||||
<Resource Include="Icons\CtrEditorC.png" />
|
||||
<Resource Include="Icons\CtrEditorE.png" />
|
||||
<Resource Include="Icons\disconnect.png" />
|
||||
<Resource Include="Icons\duplicate.png" />
|
||||
<Resource Include="Icons\extract.png">
|
||||
<CopyToOutputDirectory></CopyToOutputDirectory>
|
||||
</Resource>
|
||||
<Resource Include="Icons\fotocelula.png" />
|
||||
<Resource Include="Icons\save.png" />
|
||||
<Resource Include="Icons\start.png" />
|
||||
<Resource Include="Icons\stop.png" />
|
||||
<Resource Include="Icons\unselect.png" />
|
||||
<Resource Include="imagenes\filler.png" />
|
||||
<Resource Include="imagenes\gear.png" />
|
||||
<Resource Include="imagenes\motorNegro.png" />
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
222
MainViewModel.cs
222
MainViewModel.cs
|
@ -17,7 +17,11 @@ 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;
|
||||
|
||||
namespace CtrEditor
|
||||
{
|
||||
|
@ -56,12 +60,21 @@ namespace CtrEditor
|
|||
public ICommand TBSaveCommand { get; }
|
||||
public ICommand TBConnectPLCCommand { get; }
|
||||
public ICommand TBDisconnectPLCCommand { get; }
|
||||
public ICommand TBExtractTagsCommand { get; }
|
||||
|
||||
public ICommand TBEliminarUserControlCommand { get; }
|
||||
public ICommand TBDuplicarUserControlCommand { get; }
|
||||
|
||||
public ICommand OpenWorkDirectoryCommand { get; }
|
||||
|
||||
public ICommand TBEliminarTodosCommand { get; }
|
||||
public ICommand TBEliminarAutoCreatedCommand { get; }
|
||||
public ICommand TBEliminarClonedCommand { get; }
|
||||
public ICommand TBAssingPagesCommand { get; }
|
||||
public ICommand TBMultiPageExtractTagsCommand { get; }
|
||||
public ICommand TBMultiPageAnalizeCommand { get; }
|
||||
|
||||
|
||||
// Evento que se dispara cuando se selecciona una nueva imagen
|
||||
public event EventHandler<string> ImageSelected;
|
||||
public event EventHandler<TickSimulacionEventArgs> TickSimulacion;
|
||||
|
@ -197,6 +210,15 @@ namespace CtrEditor
|
|||
TBEliminarUserControlCommand = new RelayCommand(EliminarUserControl, () => habilitarEliminarUserControl);
|
||||
TBDuplicarUserControlCommand = new RelayCommand(DuplicarUserControl, () => habilitarEliminarUserControl);
|
||||
|
||||
TBExtractTagsCommand = new RelayCommand(ExtraerTags);
|
||||
|
||||
TBEliminarTodosCommand = new RelayCommand(EliminarTodosCommand);
|
||||
TBEliminarAutoCreatedCommand = new RelayCommand(EliminarAutoCreatedCommand);
|
||||
TBEliminarClonedCommand = new RelayCommand(EliminarClonedCommand);
|
||||
TBAssingPagesCommand = new RelayCommand(AssingPagesCommand);
|
||||
TBMultiPageExtractTagsCommand = new RelayCommand(MultiPageExtractTagsCommand);
|
||||
TBMultiPageAnalizeCommand = new RelayCommand(MultiPageAnalizeCommand);
|
||||
|
||||
stopwatch_Sim = new Stopwatch();
|
||||
stopwatch_Sim.Start();
|
||||
}
|
||||
|
@ -252,6 +274,8 @@ namespace CtrEditor
|
|||
// Asignar los datos al UserControl
|
||||
UserControlFactory.AssignDatos(userControl, osObjeto, simulationManager);
|
||||
osObjeto._mainViewModel = this;
|
||||
if (osObjeto.Id == null) // Para los objetos salvados antes de usar UniqueID
|
||||
osObjeto.Id = new UniqueId().ObtenerNuevaID();
|
||||
|
||||
MainWindow.AgregarRegistrarUserControlCanvas(userControl);
|
||||
|
||||
|
@ -316,7 +340,7 @@ namespace CtrEditor
|
|||
}
|
||||
finally
|
||||
{
|
||||
objDuplicar.RestaurarDatosNoSerializables();
|
||||
objDuplicar.RestaurarDatosNoSerializables();
|
||||
}
|
||||
return NuevoObjetoDuplicado;
|
||||
}
|
||||
|
@ -331,6 +355,198 @@ namespace CtrEditor
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void EliminarTodosCommand()
|
||||
{
|
||||
var objetosSimulablesCopy = new List<osBase>(ObjetosSimulables);
|
||||
foreach (var obj in objetosSimulablesCopy)
|
||||
RemoverObjetoSimulable(obj);
|
||||
}
|
||||
|
||||
private void EliminarAutoCreatedCommand()
|
||||
{
|
||||
var objetosSimulablesCopy = new List<osBase>(ObjetosSimulables);
|
||||
foreach (var obj in objetosSimulablesCopy)
|
||||
if (obj.AutoCreated)
|
||||
RemoverObjetoSimulable(obj);
|
||||
}
|
||||
|
||||
private void EliminarClonedCommand()
|
||||
{
|
||||
var objetosSimulablesCopy = new List<osBase>(ObjetosSimulables);
|
||||
foreach (var obj in objetosSimulablesCopy)
|
||||
if (obj is osExtraccionTag TEobj && TEobj.Cloned)
|
||||
RemoverObjetoSimulable(obj);
|
||||
}
|
||||
|
||||
private void AssingPagesCommand()
|
||||
{
|
||||
var assignImagesWindow = new AssignImagesWindow();
|
||||
var assignImagesViewModel = new AssignImagesViewModel();
|
||||
assignImagesViewModel.Initialize(this, assignImagesWindow);
|
||||
assignImagesWindow.DataContext = assignImagesViewModel;
|
||||
assignImagesWindow.ShowDialog();
|
||||
SaveStateObjetosSimulables();
|
||||
}
|
||||
|
||||
private async Task WaitForUIUpdateAsync()
|
||||
{
|
||||
await Task.Yield();
|
||||
Application.Current.Dispatcher.Invoke(() => { }, DispatcherPriority.ApplicationIdle);
|
||||
}
|
||||
|
||||
|
||||
private async void MultiPageExtractTagsCommand()
|
||||
{
|
||||
var ImagenesSeleccionadas = new ObservableCollection<string>();
|
||||
|
||||
StopSimulation();
|
||||
|
||||
var selectPagesWindow = new SelectPages();
|
||||
var selectPagesViewModel = new SelectPagesViewModel();
|
||||
selectPagesViewModel.Initialize(this, selectPagesWindow, ref ImagenesSeleccionadas);
|
||||
selectPagesWindow.DataContext = selectPagesViewModel;
|
||||
selectPagesWindow.ShowDialog();
|
||||
|
||||
foreach (var page in ImagenesSeleccionadas)
|
||||
{
|
||||
SelectedImage = page;
|
||||
await WaitForUIUpdateAsync(); // Espera a que la UI se actualice
|
||||
ExtraerTags();
|
||||
}
|
||||
}
|
||||
|
||||
private async void MultiPageAnalizeCommand()
|
||||
{
|
||||
var ImagenesSeleccionadas = new ObservableCollection<string>();
|
||||
|
||||
StopSimulation();
|
||||
|
||||
var selectPagesWindow = new SelectPages();
|
||||
var selectPagesViewModel = new SelectPagesViewModel();
|
||||
selectPagesViewModel.Initialize(this, selectPagesWindow, ref ImagenesSeleccionadas);
|
||||
selectPagesWindow.DataContext = selectPagesViewModel;
|
||||
selectPagesWindow.ShowDialog();
|
||||
|
||||
SaveStateObjetosSimulables(); // Guarda el estado antes de cambiar la imagen
|
||||
|
||||
foreach (var page in ImagenesSeleccionadas)
|
||||
{
|
||||
SelectedImage = page;
|
||||
await WaitForUIUpdateAsync(); // Espera a que la UI se actualice
|
||||
AnalizePageCommand();
|
||||
await WaitForUIUpdateAsync(); // Espera a que la UI se actualice
|
||||
|
||||
SaveStateObjetosSimulables(); // Guarda el estado antes de cambiar la imagen
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void AnalizePageCommand()
|
||||
{
|
||||
foreach (var obj in ObjetosSimulables)
|
||||
if (obj is osBuscarCoincidencias objBC)
|
||||
objBC.BuscarCoincidencias();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Extrae y formatea las etiquetas de los objetos simulables y las guarda en un archivo Excel.
|
||||
/// </summary>
|
||||
private void ExtraerTags()
|
||||
{
|
||||
// Obtiene la ruta del archivo Excel donde se guardarán los datos.
|
||||
var filePath = DatosDeTrabajo.ObtenerPathAllPages(".xlsx");
|
||||
|
||||
try
|
||||
{
|
||||
int colFix = 0;
|
||||
// Crea o abre un libro de Excel.
|
||||
XLWorkbook workbook = File.Exists(filePath) ? new XLWorkbook(filePath) : new XLWorkbook();
|
||||
var sheetName = "TagsExtracted";
|
||||
// Obtiene o crea la hoja de trabajo "TagsExtracted".
|
||||
var worksheet = workbook.Worksheets.Contains(sheetName) ? workbook.Worksheet(sheetName) : workbook.Worksheets.Add(sheetName);
|
||||
var lastRowUsed = worksheet.LastRowUsed();
|
||||
// Determina la fila en la que se empezarán a escribir los datos.
|
||||
int row = lastRowUsed == null ? 2 : lastRowUsed.RowNumber() + 1;
|
||||
|
||||
// Determina la columna fija más alta.
|
||||
foreach (var obj in ObjetosSimulables)
|
||||
{
|
||||
if (obj is osExtraccionTag objExtraccionTag && (objExtraccionTag.Id_Search_Templates == null || objExtraccionTag.Id_Search_Templates == "") && !objExtraccionTag.Cloned)
|
||||
{
|
||||
colFix = Math.Max(colFix, objExtraccionTag.Collumn_number);
|
||||
}
|
||||
}
|
||||
|
||||
int colNextGroup = 0;
|
||||
|
||||
// Itera sobre los objetos simulables para extraer y guardar las etiquetas.
|
||||
foreach (var obj in ObjetosSimulables)
|
||||
{
|
||||
if (obj is osBuscarCoincidencias objBC)
|
||||
{
|
||||
int maxColGroup = 0;
|
||||
|
||||
foreach (var objchild in ObjetosSimulables)
|
||||
{
|
||||
if (objchild is osExtraccionTag objExtraccionTag && objExtraccionTag.Id_Search_Templates == objBC.Nombre && objExtraccionTag.Cloned)
|
||||
{
|
||||
foreach (var objfix in ObjetosSimulables)
|
||||
{
|
||||
if (objfix is osExtraccionTag objExtraccionTagNoGroup && (objExtraccionTagNoGroup.Id_Search_Templates == null || objExtraccionTagNoGroup.Id_Search_Templates == "") && !objExtraccionTagNoGroup.Cloned)
|
||||
{
|
||||
if (worksheet.Cell(1, objExtraccionTagNoGroup.Collumn_number).IsEmpty())
|
||||
worksheet.Cell(1, objExtraccionTagNoGroup.Collumn_number).Value = objExtraccionTagNoGroup.Collumn_name;
|
||||
objExtraccionTagNoGroup.CaptureImageAreaAndDoOCR();
|
||||
worksheet.Cell(row, objExtraccionTagNoGroup.Collumn_number).Value = objExtraccionTagNoGroup.Tag_extract;
|
||||
}
|
||||
}
|
||||
objExtraccionTag.CaptureImageAreaAndDoOCR();
|
||||
worksheet.Cell(row, objExtraccionTag.Collumn_number + colFix + colNextGroup).Value = objExtraccionTag.Tag_extract;
|
||||
if (worksheet.Cell(1, objExtraccionTag.Collumn_number + colFix + colNextGroup).IsEmpty())
|
||||
worksheet.Cell(1, objExtraccionTag.Collumn_number + colFix + colNextGroup).Value = objExtraccionTag.Collumn_name;
|
||||
|
||||
maxColGroup = Math.Max(maxColGroup, objExtraccionTag.Collumn_number);
|
||||
if (objExtraccionTag.New_Row) row++;
|
||||
}
|
||||
}
|
||||
colNextGroup += maxColGroup;
|
||||
}
|
||||
}
|
||||
|
||||
// Formatear los títulos en la fila 1
|
||||
var titleRow = worksheet.Row(1);
|
||||
titleRow.Style.Font.Bold = true;
|
||||
titleRow.Style.Fill.BackgroundColor = XLColor.LightGray;
|
||||
titleRow.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
|
||||
// Auto dimensionado de las columnas utilizadas
|
||||
worksheet.Columns().AdjustToContents();
|
||||
|
||||
// Guarda el libro de Excel.
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// Muestra un diálogo de error si ocurre una excepción de IO.
|
||||
var dialog = new TaskDialog
|
||||
{
|
||||
WindowTitle = "IOException",
|
||||
MainInstruction = "Error al acceder al archivo",
|
||||
Content = $"El proceso no puede acceder al archivo '{filePath}' porque está siendo utilizado por otro proceso.",
|
||||
ExpandedInformation = ex.ToString(),
|
||||
MainIcon = TaskDialogIcon.Error,
|
||||
ButtonStyle = TaskDialogButtonStyle.Standard
|
||||
};
|
||||
dialog.Buttons.Add(new TaskDialogButton(ButtonType.Ok));
|
||||
dialog.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void InitializeTipoSimulableList()
|
||||
{
|
||||
var baseType = typeof(osBase);
|
||||
|
@ -473,7 +689,7 @@ namespace CtrEditor
|
|||
{
|
||||
// Guardar referencias temporales
|
||||
obj.SalvarDatosNoSerializables();
|
||||
if (!obj.Enable_on_all_pages)
|
||||
if (!obj.Enable_On_All_Pages)
|
||||
_objetosSimulables.Add(obj);
|
||||
else
|
||||
_objetosSimulablesAllPages.Add(obj);
|
||||
|
|
|
@ -91,35 +91,55 @@
|
|||
<Button Command="{Binding TBStartSimulationCommand}" ToolTip="Iniciar Simulación"
|
||||
Style="{StaticResource StartStopButtonStyle}">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/start.png" Width="16" Height="16" />
|
||||
<Image Source="Icons/start.png" Width="24" Height="24" />
|
||||
<TextBlock Text="Iniciar" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBStopSimulationCommand}" ToolTip="Detener Simulación">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/stop.png" Width="16" Height="16" />
|
||||
<Image Source="Icons/stop.png" Width="24" Height="24" />
|
||||
<TextBlock Text="Detener" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBSaveCommand}" ToolTip="Guardar">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/save.png" Width="16" Height="16" />
|
||||
<Image Source="Icons/save.png" Width="24" Height="24" />
|
||||
<TextBlock Text="Guardar" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBConnectPLCCommand}" ToolTip="Conectar PLC"
|
||||
Style="{StaticResource ConnectDisconnectButtonStyle}">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/connect.png" Width="16" Height="16" />
|
||||
<Image Source="Icons/connect.png" Width="24" Height="24" />
|
||||
<TextBlock Text="Conectar" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBDisconnectPLCCommand}" ToolTip="Desconectar PLC">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/disconnect.png" Width="16" Height="16" />
|
||||
<Image Source="Icons/disconnect.png" Width="24" Height="24" />
|
||||
<TextBlock Text="Desconectar" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBExtractTagsCommand}" ToolTip="Extraer Tags">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/extract.png" Width="24" Height="24" />
|
||||
<TextBlock Text="Extraer Tags" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBMultiPageExtractTagsCommand}" ToolTip="Extraer Tags in multiple pages.">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/extract.png" Width="24" Height="24" />
|
||||
<TextBlock Text="Multi Page Extract" />
|
||||
</StackPanel>
|
||||
</Button>a
|
||||
<Button Command="{Binding TBMultiPageAnalizeCommand}"
|
||||
ToolTip="Analyze Tags in multiple pages.">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/analyze.png" Width="24" Height="24" />
|
||||
<TextBlock Text="Multi Page Analyze" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
|
||||
|
@ -143,6 +163,7 @@
|
|||
<!-- Tercera Columna -->
|
||||
<Grid Grid.Column="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" MinHeight="100" />
|
||||
<!-- ListBox1 -->
|
||||
<RowDefinition Height="Auto" />
|
||||
|
@ -153,8 +174,38 @@
|
|||
<!-- ToolBarTray -->
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ToolBarTray Grid.Row="0">
|
||||
<ToolBar>
|
||||
<Button Command="{Binding TBEliminarTodosCommand}" ToolTip="Eliminar Todos">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/borrar.png" Width="16" Height="16" />
|
||||
<TextBlock Text="All Objects" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBEliminarAutoCreatedCommand}" ToolTip="Eliminar Auto">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/borrar.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Auto Created" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBEliminarClonedCommand}" ToolTip="Eliminar Cloned for tag Extraction">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/borrar.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Cloned" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBAssingPagesCommand}" ToolTip="Assing Pages">
|
||||
<StackPanel>
|
||||
<Image Source="Icons/choose.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Assing Pages" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
|
||||
<!-- ListBox -->
|
||||
<ListBox x:Name="ListaOs" Grid.Row="0" Margin="5" ItemsSource="{Binding ObjetosSimulables}"
|
||||
<ListBox x:Name="ListaOs" Grid.Row="1" Margin="5" ItemsSource="{Binding ObjetosSimulables}"
|
||||
SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay}"
|
||||
SelectionChanged="ListaOs_SelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
|
@ -163,10 +214,10 @@
|
|||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Path=Enable_on_all_pages}" Value="True">
|
||||
<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">
|
||||
<DataTrigger Binding="{Binding Path=Enable_On_All_Pages}" Value="False">
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
|
@ -178,11 +229,11 @@
|
|||
</ListBox>
|
||||
|
||||
<!-- GridSplitter -->
|
||||
<GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Background="Gray"
|
||||
<GridSplitter Grid.Row="2" Height="5" HorizontalAlignment="Stretch" Background="Gray"
|
||||
ResizeDirection="Rows" VerticalAlignment="Center" />
|
||||
|
||||
<!-- PanelEdicion -->
|
||||
<xctk:PropertyGrid Grid.Row="2" Margin="5" x:Name="PanelEdicion" AutoGenerateProperties="False"
|
||||
<xctk:PropertyGrid Grid.Row="3" Margin="5" x:Name="PanelEdicion" AutoGenerateProperties="False"
|
||||
ShowDescriptionByTooltip="True">
|
||||
<xctk:PropertyGrid.EditorDefinitions>
|
||||
|
||||
|
@ -282,7 +333,7 @@
|
|||
</xctk:PropertyGrid.EditorDefinitions>
|
||||
</xctk:PropertyGrid>
|
||||
|
||||
<ToolBarTray Grid.Row="3">
|
||||
<ToolBarTray Grid.Row="4">
|
||||
<ToolBar>
|
||||
<Button Command="{Binding TBEliminarUserControlCommand}" ToolTip="Eliminar Control">
|
||||
<StackPanel>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim.Extraccion_Datos" mc:Ignorable="d"
|
||||
Visibility="{Binding Show_on_this_page, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
Visibility="{Binding Show_On_This_Page, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
|
||||
<UserControl.DataContext>
|
||||
<vm:osBuscarCoincidencias />
|
||||
|
|
|
@ -20,6 +20,10 @@ using System.ComponentModel;
|
|||
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;
|
||||
|
||||
namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
||||
{
|
||||
|
@ -143,7 +147,6 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
[property: ReadOnly(true)]
|
||||
float coincidencias;
|
||||
|
||||
|
||||
public osBuscarCoincidencias()
|
||||
{
|
||||
Ancho = 1;
|
||||
|
@ -171,7 +174,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
previewWindow.ShowDialog();
|
||||
}
|
||||
|
||||
private async void BuscarCoincidencias()
|
||||
public async void BuscarCoincidencias()
|
||||
{
|
||||
var progressDialog = new ProgressDialog
|
||||
{
|
||||
|
@ -192,8 +195,6 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
progressDialog.Show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void BuscarCoincidenciasAsync(ProgressDialog progressDialog)
|
||||
{
|
||||
// Reset the Canvas children
|
||||
|
@ -271,13 +272,14 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
int ConteoPositivos = 0;
|
||||
|
||||
// Lista para mantener áreas ya aceptadas
|
||||
List<Rectangle> acceptedRectangles = new List<Rectangle>();
|
||||
|
||||
if (search_rectangles != null)
|
||||
search_rectangles.Clear();
|
||||
else
|
||||
search_rectangles = new List<Rect>();
|
||||
|
||||
// Añadir el rectángulo usado por croppedBitmap a search_rectangles
|
||||
search_rectangles.Add(new Rect(x / scaleFactorX, y / scaleFactorY, width / scaleFactorX, height / scaleFactorY));
|
||||
|
||||
// Obtener los puntos que superan el umbral
|
||||
float[] resultArray = result.GetData(false) as float[];
|
||||
if (resultArray != null)
|
||||
|
@ -309,17 +311,15 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
Canvas.SetTop(matchRect, newRect.Y);
|
||||
|
||||
// Verificar si la coincidencia actual está dentro de algún rectángulo aceptado
|
||||
bool isOverlap = acceptedRectangles.Any(r =>
|
||||
new Rect(Canvas.GetLeft(r), Canvas.GetTop(r), r.Width, r.Height).IntersectsWith(
|
||||
new Rect(Canvas.GetLeft(matchRect), Canvas.GetTop(matchRect), matchRect.Width, matchRect.Height)
|
||||
));
|
||||
bool isOverlap = search_rectangles.Any(r =>
|
||||
r.IntersectsWith(newRect)
|
||||
);
|
||||
|
||||
// Si no hay superposición, agregar el rectángulo al Canvas y a la lista de aceptados
|
||||
if (!isOverlap)
|
||||
{
|
||||
Canvas.SetZIndex(matchRect, 40);
|
||||
_mainViewModel.MainCanvas.Children.Add(matchRect);
|
||||
acceptedRectangles.Add(matchRect);
|
||||
search_rectangles.Add(newRect);
|
||||
|
||||
ConteoPositivos++;
|
||||
|
@ -337,7 +337,8 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
});
|
||||
}
|
||||
|
||||
private void PopularTagExtraction()
|
||||
|
||||
public void PopularTagExtraction()
|
||||
{
|
||||
var objetosSimulablesCopy = new List<osBase>(_mainViewModel.ObjetosSimulables);
|
||||
foreach (var obj in objetosSimulablesCopy)
|
||||
|
@ -346,10 +347,16 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
_mainViewModel.ObjetosSimulables.Remove(objExtraccionTag);
|
||||
|
||||
var objetosSimulables2Copy = new List<osBase>(_mainViewModel.ObjetosSimulables);
|
||||
foreach (var rectangle in search_rectangles)
|
||||
// Saltar el primer rectángulo en el foreach
|
||||
|
||||
|
||||
|
||||
foreach (var rectangle in search_rectangles.Skip(1))
|
||||
{
|
||||
float offsetX = PixelsToMeters((float)rectangle.X) - Left;
|
||||
float offsetY = PixelsToMeters((float)rectangle.Y) - Top;
|
||||
|
||||
osExtraccionTag newObj = null;
|
||||
|
||||
foreach (var eTag in objetosSimulables2Copy)
|
||||
{
|
||||
|
@ -357,16 +364,28 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
{
|
||||
if (objExtraccionTag.Id_Search_Templates == this.Nombre)
|
||||
{
|
||||
osExtraccionTag newObj = (osExtraccionTag)_mainViewModel.DuplicarObjeto(objExtraccionTag, offsetX, offsetY);
|
||||
newObj = (osExtraccionTag)_mainViewModel.DuplicarObjeto(objExtraccionTag, offsetX, offsetY);
|
||||
if (newObj != null)
|
||||
{
|
||||
newObj.Cloned = true;
|
||||
newObj.Enable_On_All_Pages = false;
|
||||
if (newObj.Extraer)
|
||||
objExtraccionTag.CaptureImageAreaAndDoOCR();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newObj != null)
|
||||
newObj.New_Row = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static int FindFirstEmptyRow(IXLWorksheet worksheet)
|
||||
{
|
||||
var lastRowUsed = worksheet.LastRowUsed();
|
||||
return lastRowUsed == null ? 1 : lastRowUsed.RowNumber() + 1;
|
||||
}
|
||||
|
||||
// Método para convertir BitmapSource a Mat
|
||||
private Mat BitmapSourceToMat(BitmapSource bitmapSource)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim.Extraccion_Datos"
|
||||
mc:Ignorable="d"
|
||||
Visibility="{Binding Show_on_this_page, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
Visibility="{Binding Show_On_This_Page, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
|
||||
<UserControl.DataContext>
|
||||
<vm:osExtraccionTag/>
|
||||
|
|
|
@ -6,6 +6,7 @@ using CtrEditor.Simulacion;
|
|||
using Newtonsoft.Json;
|
||||
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
|
||||
using System.ComponentModel;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
||||
{
|
||||
|
@ -37,6 +38,8 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
[property: Category("Tag Extraction:")]
|
||||
bool cloned;
|
||||
|
||||
[ObservableProperty]
|
||||
bool new_Row;
|
||||
|
||||
public override void TopChanged(float value)
|
||||
{
|
||||
|
@ -116,14 +119,19 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
string tag_extract;
|
||||
|
||||
[ObservableProperty]
|
||||
[property: Category("Tag Extraction:")]
|
||||
[property: Category("Export:")]
|
||||
string clase;
|
||||
|
||||
[ObservableProperty]
|
||||
[property: Category("Tag Extraction:")]
|
||||
string tag_name;
|
||||
[property: Category("Export:")]
|
||||
string collumn_name;
|
||||
|
||||
[ObservableProperty]
|
||||
[property: Description("Excel collumn.")]
|
||||
[property: Category("Export:")]
|
||||
int collumn_number;
|
||||
|
||||
[ObservableProperty]
|
||||
float opacity_oculto;
|
||||
|
||||
public osExtraccionTag()
|
||||
|
@ -139,6 +147,14 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
Tag_extract = CaptureImageAreaAndDoOCR(Left, Top, Ancho, Alto);
|
||||
}
|
||||
|
||||
public int ExportToExcel(IXLWorksheet worksheet, int row, int colBase)
|
||||
{
|
||||
// Agregar Tag
|
||||
worksheet.Cell(row + 2, Collumn_number + colBase).Value = Tag_extract;
|
||||
return Collumn_number + colBase;
|
||||
}
|
||||
|
||||
|
||||
public override void ucLoaded()
|
||||
{
|
||||
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
||||
|
|
|
@ -237,66 +237,72 @@ namespace CtrEditor.ObjetosSim
|
|||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// All Pages Objects
|
||||
[NotifyPropertyChangedFor(nameof(Show_on_this_page))]
|
||||
[NotifyPropertyChangedFor(nameof(Show_On_This_Page))]
|
||||
[ObservableProperty]
|
||||
[property: Description("Enable this object to be used in all pages.")]
|
||||
[property: Category("Layout:")]
|
||||
private bool enable_on_all_pages;
|
||||
private bool enable_On_All_Pages;
|
||||
|
||||
partial void OnEnable_on_all_pagesChanged(bool value)
|
||||
partial void OnEnable_On_All_PagesChanged(bool value)
|
||||
{
|
||||
if (!value)
|
||||
Show_on_this_page = true;
|
||||
Show_On_This_Page = true;
|
||||
}
|
||||
|
||||
private List<string> Show_on_this_pages_oculto;
|
||||
[ObservableProperty]
|
||||
[property: Hidden]
|
||||
private List<string> showOnThisPagesList;
|
||||
|
||||
private bool show_on_this_page;
|
||||
private bool show_On_This_Page;
|
||||
[property: Category("Layout:")]
|
||||
public bool Show_on_this_page
|
||||
public bool Show_On_This_Page
|
||||
{
|
||||
get
|
||||
{
|
||||
// Not global object
|
||||
if (!enable_on_all_pages)
|
||||
if (!Enable_On_All_Pages)
|
||||
{
|
||||
if (Show_on_this_pages_oculto != null)
|
||||
Show_on_this_pages_oculto.Clear();
|
||||
Show_on_this_pages_oculto = null;
|
||||
show_on_this_page = true;
|
||||
showOnThisPagesList?.Clear();
|
||||
showOnThisPagesList = null;
|
||||
show_On_This_Page = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Global Object
|
||||
if (Show_on_this_pages_oculto == null)
|
||||
Show_on_this_pages_oculto = new List<string>();
|
||||
if (_mainViewModel == null || _mainViewModel.SelectedImage == null) show_on_this_page = false;
|
||||
else show_on_this_page = Show_on_this_pages_oculto.Contains(_mainViewModel.SelectedImage);
|
||||
if (showOnThisPagesList == null)
|
||||
{
|
||||
showOnThisPagesList = new List<string> { _mainViewModel?.SelectedImage };
|
||||
}
|
||||
show_On_This_Page = _mainViewModel?.SelectedImage != null && showOnThisPagesList.Contains(_mainViewModel.SelectedImage);
|
||||
}
|
||||
return show_on_this_page;
|
||||
return show_On_This_Page;
|
||||
}
|
||||
set
|
||||
{
|
||||
// global object?
|
||||
if (enable_on_all_pages)
|
||||
if (Enable_On_All_Pages)
|
||||
{
|
||||
// Global Object
|
||||
if (Show_on_this_pages_oculto == null)
|
||||
Show_on_this_pages_oculto = new List<string>();
|
||||
if (_mainViewModel == null || _mainViewModel.SelectedImage == null) return;
|
||||
if (showOnThisPagesList == null)
|
||||
{
|
||||
showOnThisPagesList = new List<string>();
|
||||
}
|
||||
if (_mainViewModel?.SelectedImage == null) return;
|
||||
|
||||
if (value && !Show_on_this_pages_oculto.Contains(_mainViewModel.SelectedImage))
|
||||
Show_on_this_pages_oculto.Add(_mainViewModel.SelectedImage);
|
||||
else if (!value && Show_on_this_pages_oculto.Contains(_mainViewModel.SelectedImage))
|
||||
Show_on_this_pages_oculto.Remove(_mainViewModel.SelectedImage);
|
||||
if (value)
|
||||
{
|
||||
if (!showOnThisPagesList.Contains(_mainViewModel.SelectedImage))
|
||||
{
|
||||
showOnThisPagesList.Add(_mainViewModel.SelectedImage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
showOnThisPagesList.Remove(_mainViewModel.SelectedImage);
|
||||
}
|
||||
}
|
||||
SetProperty(ref show_on_this_page, value);
|
||||
SetProperty(ref show_On_This_Page, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async void TimerCallback(object state)
|
||||
{
|
||||
await Task.Delay(500); // Esperar 0.5 segundos antes de ejecutar la función
|
||||
|
@ -392,6 +398,7 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
ActualizarLeftTop();
|
||||
OnGroup_PanelChanged(Group_Panel); // Establece el link y se suscribe a los eventos
|
||||
Show_On_This_Page = Show_On_This_Page; // Update data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<Window x:Class="CtrEditor.PopUps.AssignImagesWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:local="clr-namespace:CtrEditor.PopUps"
|
||||
xmlns:viewModels="clr-namespace:CtrEditor.PopUps" xmlns:i1="http://schemas.microsoft.com/xaml/behaviors"
|
||||
mc:Ignorable="d" Title="Assign Pages to MultiPage Object"
|
||||
Height="450" Width="800">
|
||||
|
||||
<Window.DataContext>
|
||||
<viewModels:AssignImagesViewModel />
|
||||
</Window.DataContext>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ToolBarTray Grid.Column="0" Grid.Row="0">
|
||||
<ToolBar>
|
||||
<Button Command="{Binding TBSelectAllCommand}" ToolTip="Select All">
|
||||
<StackPanel>
|
||||
<Image Source="/Icons/allselect.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Select All Objects" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBUnSelectAllCommand}" ToolTip="Unselect All">
|
||||
<StackPanel>
|
||||
<Image Source="/Icons/unselect.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Unselect All Objects" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
<ToolBarTray Grid.Column="1" Grid.Row="0">
|
||||
<ToolBar>
|
||||
<Button Command="{Binding TBSelectAllIamgesCommand}" ToolTip="Select All Images">
|
||||
<StackPanel>
|
||||
<Image Source="/Icons/allselect.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Select All Images" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBUnSelectAllImagesCommand}" ToolTip="Unselect All">
|
||||
<StackPanel>
|
||||
<Image Source="/Icons/unselect.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Unselect all Images" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
|
||||
<!-- Lista de Objetos -->
|
||||
<ListBox x:Name="ListaObjetosSim" Grid.Column="0" Grid.Row="1" ItemsSource="{Binding ObjetosSimulables}"
|
||||
DisplayMemberPath="Nombre" SelectionMode="Multiple">
|
||||
<i:Interaction.Behaviors>
|
||||
<local:SelectedItemsBehavior SelectedItems="{Binding SelectedObjetosSimulables, Mode=TwoWay}" />
|
||||
</i:Interaction.Behaviors>
|
||||
</ListBox>
|
||||
<DataGrid />
|
||||
<!-- Lista de Imágenes con CheckListBox -->
|
||||
<xctk:CheckListBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding ListaImagenes}" DisplayMemberPath="."
|
||||
SelectedItemsOverride="{Binding SelectedImagenes, Mode=TwoWay}" />
|
||||
|
||||
<!-- Botón para guardar cambios -->
|
||||
<Button Grid.Row="2" Grid.ColumnSpan="2" Content="Save" Command="{Binding AssignImagesCommand}"
|
||||
Margin="10,10,10,10" />
|
||||
<TextBlock Grid.Row="3" Grid.ColumnSpan="2" Text="{Binding SelectedObjetosSimulables.Count}" />
|
||||
|
||||
</Grid>
|
||||
</Window>
|
|
@ -0,0 +1,163 @@
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CtrEditor.ObjetosSim;
|
||||
using CtrEditor;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Collections;
|
||||
using CtrEditor.ObjetosSim.Extraccion_Datos;
|
||||
using Microsoft.Xaml.Behaviors;
|
||||
|
||||
|
||||
namespace CtrEditor.PopUps
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AssignImagesWindow.xaml
|
||||
/// </summary>
|
||||
public partial class AssignImagesWindow : Window
|
||||
{
|
||||
public AssignImagesWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class AssignImagesViewModel : ObservableObject
|
||||
{
|
||||
private MainViewModel _mainViewModel;
|
||||
private Window _window;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<osBase> objetosSimulables;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<string> listaImagenes;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<osBase> selectedObjetosSimulables;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<string> selectedImagenes;
|
||||
|
||||
public AssignImagesViewModel() { }
|
||||
|
||||
public void Initialize(MainViewModel mainViewModel, Window window)
|
||||
{
|
||||
_mainViewModel = mainViewModel;
|
||||
_window = window;
|
||||
ObjetosSimulables = new ObservableCollection<osBase>(_mainViewModel.ObjetosSimulables.Where(
|
||||
o => o.Enable_On_All_Pages && ((o is osExtraccionTag ex && !ex.Cloned) || (o is osBuscarCoincidencias))));
|
||||
|
||||
ListaImagenes = _mainViewModel.ListaImagenes;
|
||||
SelectedObjetosSimulables = new ObservableCollection<osBase>();
|
||||
SelectedImagenes = new ObservableCollection<string>();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AssignImages()
|
||||
{
|
||||
foreach (var objeto in SelectedObjetosSimulables)
|
||||
{
|
||||
objeto.ShowOnThisPagesList = new List<string>(SelectedImagenes);
|
||||
objeto.Show_On_This_Page = objeto.Show_On_This_Page;
|
||||
}
|
||||
|
||||
_window.Close();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void TBSelectAll()
|
||||
{
|
||||
SelectedObjetosSimulables.Clear();
|
||||
foreach (var obj in ObjetosSimulables)
|
||||
{
|
||||
SelectedObjetosSimulables.Add(obj);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void TBUnSelectAll()
|
||||
{
|
||||
SelectedObjetosSimulables.Clear();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void TBSelectAllIamges()
|
||||
{
|
||||
SelectedImagenes.Clear();
|
||||
foreach (var img in ListaImagenes)
|
||||
{
|
||||
SelectedImagenes.Add(img);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void TBUnSelectAllImages()
|
||||
{
|
||||
SelectedImagenes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class SelectedItemsBehavior : Behavior<ListBox>
|
||||
{
|
||||
public IList SelectedItems
|
||||
{
|
||||
get { return (IList)GetValue(SelectedItemsProperty); }
|
||||
set { SetValue(SelectedItemsProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SelectedItemsProperty =
|
||||
DependencyProperty.Register("SelectedItems", typeof(IList), typeof(SelectedItemsBehavior), new PropertyMetadata(null, OnSelectedItemsChanged));
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
AssociatedObject.SelectionChanged += OnSelectionChanged;
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
base.OnDetaching();
|
||||
AssociatedObject.SelectionChanged -= OnSelectionChanged;
|
||||
}
|
||||
|
||||
private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var behavior = d as SelectedItemsBehavior;
|
||||
behavior?.UpdateSelectedItems();
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (SelectedItems != null)
|
||||
{
|
||||
foreach (var item in e.RemovedItems)
|
||||
{
|
||||
SelectedItems.Remove(item);
|
||||
}
|
||||
foreach (var item in e.AddedItems)
|
||||
{
|
||||
SelectedItems.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSelectedItems()
|
||||
{
|
||||
if (SelectedItems != null)
|
||||
{
|
||||
AssociatedObject.SelectionChanged -= OnSelectionChanged;
|
||||
AssociatedObject.SelectedItems.Clear();
|
||||
foreach (var item in SelectedItems)
|
||||
{
|
||||
AssociatedObject.SelectedItems.Add(item);
|
||||
}
|
||||
AssociatedObject.SelectionChanged += OnSelectionChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<Window x:Class="CtrEditor.PopUps.SelectPages" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:local="clr-namespace:CtrEditor.PopUps"
|
||||
xmlns:viewModels="clr-namespace:CtrEditor.PopUps" mc:Ignorable="d" Title="Select Pages to Process..."
|
||||
Height="450" Width="400">
|
||||
|
||||
<Window.DataContext>
|
||||
<viewModels:AssignImagesViewModel />
|
||||
</Window.DataContext>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ToolBarTray Grid.Row="0">
|
||||
<ToolBar>
|
||||
<Button Command="{Binding TBSelectAllCommand}" ToolTip="Select All">
|
||||
<StackPanel>
|
||||
<Image Source="/Icons/allselect.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Select All" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{Binding TBUnSelectAllCommand}" ToolTip="Unselect All">
|
||||
<StackPanel>
|
||||
<Image Source="/Icons/unselect.png" Width="16" Height="16" />
|
||||
<TextBlock Text="Unselect" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
<!-- Lista de Imágenes con CheckListBox -->
|
||||
<xctk:CheckListBox Grid.Row="1" ItemsSource="{Binding ListaImagenes}" DisplayMemberPath="."
|
||||
SelectedItemsOverride="{Binding SelectedImagenes, Mode=TwoWay}" />
|
||||
|
||||
<!-- Botón para guardar cambios -->
|
||||
<Button Grid.Row="2" Grid.ColumnSpan="1" Content="Run" Command="{Binding AssignImagesCommand}"
|
||||
Margin="10,10,10,10" />
|
||||
</Grid>
|
||||
</Window>
|
|
@ -0,0 +1,82 @@
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CtrEditor.ObjetosSim.Extraccion_Datos;
|
||||
using CtrEditor.ObjetosSim;
|
||||
using CtrEditor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace CtrEditor.PopUps
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SelectPages.xaml
|
||||
/// </summary>
|
||||
public partial class SelectPages : Window
|
||||
{
|
||||
public SelectPages()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public partial class SelectPagesViewModel : ObservableObject
|
||||
{
|
||||
private MainViewModel _mainViewModel;
|
||||
private Window _window;
|
||||
private ObservableCollection<string> _imagenesSeleccionadas;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<string> listaImagenes;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<string> selectedImagenes;
|
||||
|
||||
public SelectPagesViewModel() { }
|
||||
|
||||
public void Initialize(MainViewModel mainViewModel, Window window, ref ObservableCollection<string> ImagenesSeleccionadas)
|
||||
{
|
||||
_mainViewModel = mainViewModel;
|
||||
_window = window;
|
||||
_imagenesSeleccionadas = ImagenesSeleccionadas;
|
||||
ListaImagenes = _mainViewModel.ListaImagenes;
|
||||
SelectedImagenes = ImagenesSeleccionadas;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AssignImages()
|
||||
{
|
||||
|
||||
_window.Close();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void TBSelectAll()
|
||||
{
|
||||
SelectedImagenes.Clear();
|
||||
foreach (var img in ListaImagenes)
|
||||
{
|
||||
SelectedImagenes.Add(img);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void TBUnSelectAll()
|
||||
{
|
||||
SelectedImagenes.Clear();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue