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.Collections.ObjectModel;
using System.ComponentModel; // Add this for PropertyChangedEventHandler and PropertyChangedEventArgs
using System.Reflection; using System.Reflection;
using System.Text.Json.Serialization;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@ -7,6 +9,16 @@ using CtrEditor.ObjetosSim;
namespace CtrEditor.Controls namespace CtrEditor.Controls
{ {
public class FilterChangedEventArgs : EventArgs
{
public osVisFilterViewModel FilterViewModel { get; private set; }
public FilterChangedEventArgs(osVisFilterViewModel viewModel)
{
FilterViewModel = viewModel;
}
}
/// <summary> /// <summary>
/// Interaction logic for osVisFilter.xaml /// Interaction logic for osVisFilter.xaml
/// </summary> /// </summary>
@ -15,11 +27,18 @@ namespace CtrEditor.Controls
public osVisFilter() public osVisFilter()
{ {
InitializeComponent(); InitializeComponent();
DataContext = FilterViewModel = new osVisFilterViewModel(); DataContext = FilterViewModel = new osVisFilterViewModel { Parent = this }; // Set the Parent property
} }
public osVisFilterViewModel FilterViewModel { get; private set; } 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> /// <summary>
/// Updates the type filters based on the provided types /// Updates the type filters based on the provided types
/// </summary> /// </summary>
@ -52,9 +71,66 @@ namespace CtrEditor.Controls
[ObservableProperty] [ObservableProperty]
private ObservableCollection<TypeFilterItem> typeFilters = new ObservableCollection<TypeFilterItem>(); 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() public osVisFilterViewModel()
{ {
// PropertyChanged listeners could be added here if needed // PropertyChanged listeners could be added here if needed
if (this.Parent is osVisFilter filter)
{
filter.OnFilterChanged();
}
} }
/// <summary> /// <summary>
@ -69,6 +145,7 @@ namespace CtrEditor.Controls
foreach (var item in typesToRemove) foreach (var item in typesToRemove)
{ {
UnsubscribeFromTypeFilter(item);
TypeFilters.Remove(item); TypeFilters.Remove(item);
} }
@ -77,15 +154,35 @@ namespace CtrEditor.Controls
{ {
if (!TypeFilters.Any(tf => tf.Type == type)) if (!TypeFilters.Any(tf => tf.Type == type))
{ {
TypeFilters.Add(new TypeFilterItem(type) var newFilter = new TypeFilterItem(type)
{ {
DisplayName = GetTypeDisplayName(type), DisplayName = GetTypeDisplayName(type),
IsSelected = true 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> /// <summary>
/// Gets the display name for a type, using the NombreClase static method if available /// Gets the display name for a type, using the NombreClase static method if available
/// </summary> /// </summary>
@ -117,5 +214,10 @@ namespace CtrEditor.Controls
Type = type; Type = type;
DisplayName = type?.Name ?? "Unknown 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.Text.RegularExpressions;
using System.Collections.Specialized; using System.Collections.Specialized;
using CtrEditor.Serialization; // Add this line using CtrEditor.Serialization; // Add this line
using CtrEditor.Controls; // Add this using directive
namespace CtrEditor namespace CtrEditor
{ {
@ -127,6 +128,11 @@ namespace CtrEditor
{ {
mainWindow = value; mainWindow = value;
_objectManager = mainWindow._objectManager; // Initialize _objectManager _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) 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 // Constructor
@ -366,9 +385,47 @@ namespace CtrEditor
_stateManager = new StateManager(EstadoPersistente.Instance.directorio, this); _stateManager = new StateManager(EstadoPersistente.Instance.directorio, this);
_stateSerializer = new StateSerializer(this, datosDeTrabajo, simulationManager); _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() public void LoadStateObjetosSimulables()
{ {
@ -376,11 +433,10 @@ namespace CtrEditor
{ {
_stateSerializer.LoadState(SelectedImage); _stateSerializer.LoadState(SelectedImage);
// Restaurar visibilidad según el filtro actual // Aplicar los filtros actuales a los objetos recién cargados
foreach (var obj in ObjetosSimulables) if (MainWindow?.VisFilter?.FilterViewModel != null)
{ {
if (obj.VisualRepresentation != null) OnVisFilterChanged(MainWindow.VisFilter.FilterViewModel);
obj.VisualRepresentation.Visibility = Visibility.Visible;
} }
} }
} }

View File

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

View File

@ -221,7 +221,7 @@ namespace CtrEditor
foreach (var obj in selectedObjects) 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 // Obtener el bounding box del objeto actual
Rect objectBounds = VisualTreeHelper.GetDescendantBounds(obj.VisualRepresentation); Rect objectBounds = VisualTreeHelper.GetDescendantBounds(obj.VisualRepresentation);
@ -244,6 +244,12 @@ namespace CtrEditor
private Rectangle CreateSelectionRectangle(FuncionesBase.MutableRect rectBox, double rectHighlightSize) 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 var rect = new Rectangle
{ {
Width = rectBox.Width + (rectHighlightSize * 2), Width = rectBox.Width + (rectHighlightSize * 2),
@ -263,6 +269,7 @@ namespace CtrEditor
return rect; return rect;
} }
private void AddResizeHandles(FuncionesBase.MutableRect rectBox, double defaultRectSize, private void AddResizeHandles(FuncionesBase.MutableRect rectBox, double defaultRectSize,
Cursor rotationCursorRx, Cursor rotationCursorSx) Cursor rotationCursorRx, Cursor rotationCursorSx)
{ {

View File

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

View File

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