Files
ExportDXF/ExportDXF/Services/BomExtractor.cs
AJ Isaacs 49051b5e64 refactor: replace CutFab API with local file export and database
Remove CutFabApiClient and DrawingSelectionForm - exports no longer
depend on an external API server. DXF/PDF files are saved directly
to a configurable output folder, and export records are persisted
to a local SQL Server database via EF Core.

Replace Color-based progress logging with LogLevel enum across all
services. Redesign MainForm with equipment/drawing filter dropdowns
populated from export history, log row coloring by severity, and
simplified startup flow in Program.cs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 11:27:04 -05:00

66 lines
2.2 KiB
C#

using ExportDXF.Extensions;
using ExportDXF.ItemExtractors;
using ExportDXF.Models;
using SolidWorks.Interop.sldworks;
using System;
using System.Collections.Generic;
namespace ExportDXF.Services
{
/// <summary>
/// Service for extracting items from a Bill of Materials (BOM).
/// </summary>
public interface IBomExtractor
{
/// <summary>
/// Extracts items from all BOM tables in a drawing document.
/// </summary>
/// <param name="drawing">The drawing document containing BOM tables.</param>
/// <param name="progressCallback">Optional callback for progress updates (message, level, file).</param>
/// <returns>A list of extracted items.</returns>
List<Item> ExtractFromDrawing(DrawingDoc drawing, Action<string, LogLevel, string> progressCallback);
}
public class BomExtractor : IBomExtractor
{
public List<Item> ExtractFromDrawing(DrawingDoc drawing, Action<string, LogLevel, string> progressCallback)
{
if (drawing == null)
throw new ArgumentNullException(nameof(drawing));
var bomTables = drawing.GetBomTables();
if (bomTables.Count == 0)
{
progressCallback?.Invoke("Error: Bill of materials not found.", LogLevel.Error, null);
return new List<Item>();
}
progressCallback?.Invoke($"Found {bomTables.Count} BOM table(s)", LogLevel.Info, null);
var allItems = new List<Item>();
foreach (var bom in bomTables)
{
try
{
var extractor = new BomItemExtractor(bom)
{
SkipHiddenRows = true
};
progressCallback?.Invoke($"Fetching components from {bom.BomFeature.Name}", LogLevel.Info, null);
var items = extractor.GetItems();
allItems.AddRange(items);
}
catch (Exception ex)
{
progressCallback?.Invoke($"Failed to extract: {ex.Message}", LogLevel.Error, bom.BomFeature.Name);
}
}
return allItems;
}
}
}