Moved ItemExtractors to separate namespace.

This commit is contained in:
AJ
2021-03-21 22:09:31 -04:00
parent b693d8a092
commit 16c9d97e22
6 changed files with 93 additions and 76 deletions

View File

@@ -94,7 +94,10 @@
<Compile Include="DrawingInfo.cs" />
<Compile Include="BomToExcel.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="ItemExtractor.cs" />
<Compile Include="ItemExtractors\AssemblyItemExtractor.cs" />
<Compile Include="ItemExtractors\BomColumnIndices.cs" />
<Compile Include="ItemExtractors\BomItemExtractor.cs" />
<Compile Include="ItemExtractors\ItemExtractor.cs" />
<Compile Include="Forms\ViewFlipDeciderComboboxItem.cs" />
<Compile Include="Item.cs" />
<Compile Include="IViewFlipDecider.cs" />

View File

@@ -1,4 +1,5 @@
using OfficeOpenXml;
using ExportDXF.ItemExtractors;
using OfficeOpenXml;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;

View File

@@ -0,0 +1,64 @@
using SolidWorks.Interop.sldworks;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ExportDXF.ItemExtractors
{
public class AssemblyItemExtractor : ItemExtractor
{
private AssemblyDoc assembly;
public AssemblyItemExtractor(AssemblyDoc assembly)
{
this.assembly = assembly;
}
public bool TopLevelOnly { get; set; }
private string GetComponentName(Component2 component)
{
var filepath = component.GetTitle();
var filename = Path.GetFileNameWithoutExtension(filepath);
var isDefaultConfig = component.ReferencedConfiguration.ToLower() == "default";
return isDefaultConfig ? filename : $"{filename} [{component.ReferencedConfiguration}]";
}
public List<Item> GetItems()
{
var list = new List<Item>();
assembly.ResolveAllLightWeightComponents(false);
var assemblyComponents = ((Array)assembly.GetComponents(TopLevelOnly))
.Cast<Component2>()
.Where(c => !c.IsHidden(true));
var componentGroups = assemblyComponents
.GroupBy(c => c.GetTitle() + c.ReferencedConfiguration);
foreach (var group in componentGroups)
{
var component = group.First();
var model = component.GetModelDoc2() as ModelDoc2;
if (model == null)
continue;
var name = GetComponentName(component);
list.Add(new Item
{
PartName = name,
Quantity = group.Count(),
Component = component,
Configuration = component.ReferencedConfiguration
});
}
return list;
}
}
}

View File

@@ -0,0 +1,13 @@
namespace ExportDXF.ItemExtractors
{
public class BomColumnIndices
{
public int ItemNumber { get; set; } = -1;
public int Quantity { get; set; } = -1;
public int Description { get; set; } = -1;
public int PartNumber { get; set; } = -1;
}
}

View File

@@ -2,16 +2,10 @@
using SolidWorks.Interop.swconst;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ExportDXF
namespace ExportDXF.ItemExtractors
{
public interface ItemExtractor
{
List<Item> GetItems();
}
public class BomItemExtractor : ItemExtractor
{
private BomTableAnnotation bom;
@@ -142,71 +136,4 @@ namespace ExportDXF
return items;
}
}
public class AssemblyItemExtractor : ItemExtractor
{
private AssemblyDoc assembly;
public AssemblyItemExtractor(AssemblyDoc assembly)
{
this.assembly = assembly;
}
public bool TopLevelOnly { get; set; }
private string GetComponentName(Component2 component)
{
var filepath = component.GetTitle();
var filename = Path.GetFileNameWithoutExtension(filepath);
var isDefaultConfig = component.ReferencedConfiguration.ToLower() == "default";
return isDefaultConfig ? filename : $"{filename} [{component.ReferencedConfiguration}]";
}
public List<Item> GetItems()
{
var list = new List<Item>();
assembly.ResolveAllLightWeightComponents(false);
var assemblyComponents = ((Array)assembly.GetComponents(TopLevelOnly))
.Cast<Component2>()
.Where(c => !c.IsHidden(true));
var componentGroups = assemblyComponents
.GroupBy(c => c.GetTitle() + c.ReferencedConfiguration);
foreach (var group in componentGroups)
{
var component = group.First();
var model = component.GetModelDoc2() as ModelDoc2;
if (model == null)
continue;
var name = GetComponentName(component);
list.Add(new Item
{
PartName = name,
Quantity = group.Count(),
Component = component,
Configuration = component.ReferencedConfiguration
});
}
return list;
}
}
public class BomColumnIndices
{
public int ItemNumber { get; set; } = -1;
public int Quantity { get; set; } = -1;
public int Description { get; set; } = -1;
public int PartNumber { get; set; } = -1;
}
}

View File

@@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace ExportDXF.ItemExtractors
{
public interface ItemExtractor
{
List<Item> GetItems();
}
}