Cambiado Path de teseract a absoluto en la carpeta de la aplicacion

This commit is contained in:
Miguel 2025-03-01 23:28:29 +01:00
parent 3d70992b1a
commit f264efd9ce
6 changed files with 247 additions and 58 deletions

View File

@ -1,5 +1,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel; // Add this for PropertyChangedEventHandler and PropertyChangedEventArgs
using System.Reflection;
using System.Text.Json.Serialization;
using System.Windows;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
@ -7,6 +9,16 @@ using CtrEditor.ObjetosSim;
namespace CtrEditor.Controls
{
public class FilterChangedEventArgs : EventArgs
{
public osVisFilterViewModel FilterViewModel { get; private set; }
public FilterChangedEventArgs(osVisFilterViewModel viewModel)
{
FilterViewModel = viewModel;
}
}
/// <summary>
/// Interaction logic for osVisFilter.xaml
/// </summary>
@ -15,11 +27,18 @@ namespace CtrEditor.Controls
public osVisFilter()
{
InitializeComponent();
DataContext = FilterViewModel = new osVisFilterViewModel();
DataContext = FilterViewModel = new osVisFilterViewModel { Parent = this }; // Set the Parent property
}
public osVisFilterViewModel FilterViewModel { get; private set; }
public event EventHandler<FilterChangedEventArgs> FilterChanged;
public virtual void OnFilterChanged() // Changed from protected to public
{
FilterChanged?.Invoke(this, new FilterChangedEventArgs(FilterViewModel));
}
/// <summary>
/// Updates the type filters based on the provided types
/// </summary>
@ -52,9 +71,66 @@ namespace CtrEditor.Controls
[ObservableProperty]
private ObservableCollection<TypeFilterItem> typeFilters = new ObservableCollection<TypeFilterItem>();
partial void OnShowAllChanged(bool value)
{
NotifyFilterChanged();
}
partial void OnShowClonedChanged(bool value)
{
NotifyFilterChanged();
}
partial void OnShowAutoCreatedChanged(bool value)
{
NotifyFilterChanged();
}
partial void OnShowEnableOnAllPagesChanged(bool value)
{
NotifyFilterChanged();
}
partial void OnShowOnThisPageChanged(bool value)
{
NotifyFilterChanged();
}
partial void OnTypeFiltersChanged(ObservableCollection<TypeFilterItem> value)
{
if (value != null)
{
foreach (var filter in value)
{
filter.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(TypeFilterItem.IsSelected))
{
NotifyFilterChanged();
}
};
}
}
}
private void NotifyFilterChanged()
{
if (this.Parent is osVisFilter filter)
{
filter.OnFilterChanged();
}
}
[JsonIgnore]
public osVisFilter Parent { get; set; }
public osVisFilterViewModel()
{
// PropertyChanged listeners could be added here if needed
if (this.Parent is osVisFilter filter)
{
filter.OnFilterChanged();
}
}
/// <summary>
@ -69,6 +145,7 @@ namespace CtrEditor.Controls
foreach (var item in typesToRemove)
{
UnsubscribeFromTypeFilter(item);
TypeFilters.Remove(item);
}
@ -77,15 +154,35 @@ namespace CtrEditor.Controls
{
if (!TypeFilters.Any(tf => tf.Type == type))
{
TypeFilters.Add(new TypeFilterItem(type)
var newFilter = new TypeFilterItem(type)
{
DisplayName = GetTypeDisplayName(type),
IsSelected = true
});
};
SubscribeToTypeFilter(newFilter);
TypeFilters.Add(newFilter);
}
}
}
private void SubscribeToTypeFilter(TypeFilterItem filter)
{
filter.PropertyChanged += TypeFilter_PropertyChanged;
}
private void UnsubscribeFromTypeFilter(TypeFilterItem filter)
{
filter.PropertyChanged -= TypeFilter_PropertyChanged;
}
private void TypeFilter_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(TypeFilterItem.IsSelected))
{
NotifyFilterChanged();
}
}
/// <summary>
/// Gets the display name for a type, using the NombreClase static method if available
/// </summary>
@ -117,5 +214,10 @@ namespace CtrEditor.Controls
Type = type;
DisplayName = type?.Name ?? "Unknown Type";
}
partial void OnIsSelectedChanged(bool value)
{
OnPropertyChanged(nameof(IsSelected));
}
}
}

View File

@ -22,6 +22,7 @@ using CommunityToolkit.Mvvm.Input;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
using CtrEditor.Serialization; // Add this line
using CtrEditor.Controls; // Add this using directive
namespace CtrEditor
{
@ -127,6 +128,11 @@ namespace CtrEditor
{
mainWindow = value;
_objectManager = mainWindow._objectManager; // Initialize _objectManager
// Add the filter changed event handler here instead of in constructor
if (mainWindow.VisFilter != null)
{
mainWindow.VisFilter.FilterChanged += (s, e) => OnVisFilterChanged(e.FilterViewModel);
}
}
}
@ -292,9 +298,22 @@ namespace CtrEditor
partial void OnObjetosSimulablesChanged(ObservableCollection<osBase> value)
{
if (value != null)
{
value.CollectionChanged += ObjetosSimulables_CollectionChanged;
UpdateVisFilterTypes();
}
}
private void ObjetosSimulables_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
UpdateVisFilterTypes();
}
private void UpdateVisFilterTypes()
{
MainWindow?.VisFilter?.UpdateAvailableTypes(ObjetosSimulables.Select(o => o.GetType()).Distinct());
}
//
// Constructor
@ -366,9 +385,47 @@ namespace CtrEditor
_stateManager = new StateManager(EstadoPersistente.Instance.directorio, this);
_stateSerializer = new StateSerializer(this, datosDeTrabajo, simulationManager);
}
private void OnVisFilterChanged(osVisFilterViewModel filter) // Changed signature to accept viewmodel directly
{
foreach (var obj in ObjetosSimulables)
{
bool isVisible = true;
// Apply Show All filter
if (!filter.ShowAll)
{
// Check type filter
var typeFilter = filter.TypeFilters.FirstOrDefault(tf => tf.Type == obj.GetType());
if (typeFilter == null || !typeFilter.IsSelected)
{
isVisible = false;
}
// Check other filters
if (filter.ShowCloned && !obj.Cloned)
isVisible = false;
if (filter.ShowAutoCreated && !obj.AutoCreated)
isVisible = false;
if (filter.ShowEnableOnAllPages && !obj.Enable_On_All_Pages)
isVisible = false;
if (filter.ShowOnThisPage && !obj.Show_On_This_Page)
isVisible = false;
}
obj.IsVisFilter = isVisible;
// Update Canvas object visibility
if (obj.VisualRepresentation != null)
{
obj.VisualRepresentation.Visibility = isVisible ? Visibility.Visible : Visibility.Collapsed;
}
}
}
public void LoadStateObjetosSimulables()
{
@ -376,11 +433,10 @@ namespace CtrEditor
{
_stateSerializer.LoadState(SelectedImage);
// Restaurar visibilidad según el filtro actual
foreach (var obj in ObjetosSimulables)
// Aplicar los filtros actuales a los objetos recién cargados
if (MainWindow?.VisFilter?.FilterViewModel != null)
{
if (obj.VisualRepresentation != null)
obj.VisualRepresentation.Visibility = Visibility.Visible;
OnVisFilterChanged(MainWindow.VisFilter.FilterViewModel);
}
}
}

View File

@ -217,19 +217,12 @@
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="50" />
<!-- ListBox1 -->
<RowDefinition Height="*" MinHeight="50" />
<!-- GridSplitter -->
<RowDefinition Height="Auto" />
<!-- Tree -->
<RowDefinition Height="*" MinHeight="100" />
<!-- GridSplitter -->
<RowDefinition Height="Auto" />
<RowDefinition Height="*" MinHeight="200" />
<!-- StackPanel -->
<RowDefinition Height="Auto" />
<!-- ToolBarTray -->
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ToolBarTray Grid.Row="0">
@ -262,8 +255,17 @@
</ToolBar>
</ToolBarTray>
<!-- Filter Control -->
<Expander Grid.Row="1" Header="Filters" IsExpanded="False">
<controls:osVisFilter x:Name="VisFilter" Margin="5"/>
</Expander>
<!-- ListBox -->
<ListBox x:Name="ListaOs" Grid.Row="2" Margin="5" ItemsSource="{Binding ObjetosSimulables}"
<Expander Grid.Row="2" Header="Objects List" IsExpanded="False">
<ListBox x:Name="ListaOs"
Margin="5"
MinHeight="100"
MaxHeight="300"
ItemsSource="{Binding ObjetosSimulables}"
SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay}"
SelectionChanged="ListaOs_SelectionChanged">
<ListBox.ItemTemplate>
@ -278,6 +280,9 @@
<DataTrigger Binding="{Binding Path=Enable_On_All_Pages}" Value="False">
<Setter Property="Foreground" Value="Black" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsVisFilter}" Value="False">
<Setter Property="Opacity" Value="0.5" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
@ -285,20 +290,29 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Expander>
<!-- Object Hierarchy -->
<Expander Grid.Row="3" Header="Object Hierarchy" IsExpanded="True">
<controls:ObjectHierarchyView x:Name="ObjectHierarchy"
Margin="5"
MinHeight="100"
MaxHeight="300"/>
</Expander>
<!-- GridSplitter -->
<GridSplitter Grid.Row="3" Height="5" HorizontalAlignment="Stretch" Background="Gray"
ResizeDirection="Rows" VerticalAlignment="Center" />
<controls:ObjectHierarchyView x:Name="ObjectHierarchy" Grid.Row="4" Margin="5" />
<!-- GridSplitter -->
<GridSplitter Grid.Row="5" Height="5" HorizontalAlignment="Stretch" Background="Gray"
ResizeDirection="Rows" VerticalAlignment="Center" />
<GridSplitter Grid.Row="4" Height="5"
HorizontalAlignment="Stretch"
Background="Gray"
ResizeDirection="Rows"
VerticalAlignment="Center" />
<!-- PanelEdicion -->
<controls:PanelEdicionControl Grid.Row="6"
<controls:PanelEdicionControl Grid.Row="5"
x:Name="PanelEdicion"
Margin="5"/>
<ToolBarTray Grid.Row="7">
<ToolBarTray Grid.Row="6">
<ToolBar>
<Button Command="{Binding TBEliminarUserControlCommand}" ToolTip="Eliminar Control">
<StackPanel>

View File

@ -221,7 +221,7 @@ namespace CtrEditor
foreach (var obj in selectedObjects)
{
if (obj.VisualRepresentation != null && obj.Show_On_This_Page)
if (obj.VisualRepresentation != null)
{
// Obtener el bounding box del objeto actual
Rect objectBounds = VisualTreeHelper.GetDescendantBounds(obj.VisualRepresentation);
@ -244,6 +244,12 @@ namespace CtrEditor
private Rectangle CreateSelectionRectangle(FuncionesBase.MutableRect rectBox, double rectHighlightSize)
{
if (double.IsInfinity(rectBox.Width) || double.IsInfinity(rectBox.Height) ||
double.IsNaN(rectBox.Width) || double.IsNaN(rectBox.Height))
{
throw new ArgumentException("Invalid dimensions for selection rectangle.");
}
var rect = new Rectangle
{
Width = rectBox.Width + (rectHighlightSize * 2),
@ -263,6 +269,7 @@ namespace CtrEditor
return rect;
}
private void AddResizeHandles(FuncionesBase.MutableRect rectBox, double defaultRectSize,
Cursor rotationCursorRx, Cursor rotationCursorSx)
{

View File

@ -160,6 +160,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
Opacity_oculto = 0.1f;
Idioma_Extraccion = Idiomas.DEFAULT_LANGUAGE;
Pattern_Type = TagPattern.DEFAULT_PATTERN;
Eliminar_enters = true;
}
public void CaptureImageAreaAndDoOCR()

View File

@ -69,6 +69,11 @@ namespace CtrEditor.ObjetosSim
[JsonIgnore]
private System.Threading.Timer timer = null;
[JsonIgnore]
[ObservableProperty]
[property: Hidden]
public bool isVisFilter;
public UniqueId Id { get; set; }
[ObservableProperty]
@ -402,7 +407,10 @@ namespace CtrEditor.ObjetosSim
msResized.Seek(0, SeekOrigin.Begin);
using (var img = Pix.LoadFromMemory(msResized.ToArray()))
using (var engine = new TesseractEngine(@"./Tesseract", "eng", EngineMode.Default))
{
// Use AppDomain.CurrentDomain.BaseDirectory to ensure we find Tesseract in the application directory
string tesseractPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tesseract");
using (var engine = new TesseractEngine(tesseractPath, "eng", EngineMode.Default))
{
// Configuraciones para mejorar el OCR de una sola letra
engine.SetVariable("tessedit_char_whitelist", " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-."); // Lista blanca de caracteres
@ -414,6 +422,7 @@ namespace CtrEditor.ObjetosSim
}
}
}
}
return "";
}