Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions kibom/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ class Component

static List<DefaultComp> default_list = new List<DefaultComp>();

public Component(string reference, string value, string footprint)
{
this.reference = reference;
this.value = value;
this.designator = this.reference.Substring (0, this.reference.IndexOfAny ("0123456789".ToCharArray ()));
this.numeric_value = Component.ValueToNumeric(this.value);

// normalized footprint
if (footprint == null) {
Console.Error.WriteLine("No footprint defined on node '" + this.reference + "." + this.value);
this.footprint = "no part";
this.footprint_normalized = "no part";
}
else {
this.footprint_normalized = Footprint.substitute(footprint, true, true);
if (footprint.Contains (':')) { // contrains library name
this.footprint = footprint.Substring (footprint.IndexOf (':') + 1);
}
else {
this.footprint = footprint;
}
}
this.no_part = (this.footprint_normalized == "no part");
}

static public DefaultComp FindDefaultComp(string designator)
{
foreach (DefaultComp d in default_list)
Expand Down
30 changes: 12 additions & 18 deletions kibom/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ static bool ParseArgs(string[] args,

if (!File.Exists(filename))
{
Console.WriteLine("File not found.");
Console.WriteLine("File not found: " + filename);
return false;
}
path = Path.GetDirectoryName(Path.GetFullPath(filename));
if (!path.EndsWith("\\"))
path += "\\";
filename = Path.GetFileName(filename);
String pathSep = Char.ToString (Path.DirectorySeparatorChar);
path = Path.GetDirectoryName (Path.GetFullPath (filename));
if (!path.EndsWith (pathSep, StringComparison.Ordinal))
path += pathSep;
filename = Path.GetFileName (filename);

return true;
}
Expand Down Expand Up @@ -199,19 +200,12 @@ static List<Component> ParseComponents(XmlDocument doc)
XmlNodeList comp_nodes = components_node.SelectNodes("comp");
foreach (XmlNode node in comp_nodes)
{
var comp = new Component();
comp.reference = node.Attributes["ref"].Value;
comp.designator = comp.reference.Substring(0, comp.reference.IndexOfAny("0123456789".ToCharArray()));
comp.value = node.SelectSingleNode("value").InnerText;
comp.numeric_value = Component.ValueToNumeric(comp.value);
comp.footprint = node.SelectSingleNode("footprint").InnerText;

// normalized footprint
comp.footprint_normalized = Footprint.substitute(comp.footprint, true, true);
if (comp.footprint_normalized == "no part")
comp.no_part = true;
if (comp.footprint.Contains(':')) // contrains library name
comp.footprint = comp.footprint.Substring(comp.footprint.IndexOf(':') + 1);
XmlNode footprintNode = node.SelectSingleNode("footprint");
var comp = new Component(
node.Attributes["ref"].Value,
node.SelectSingleNode ("value").InnerText,
(footprintNode != null) ? footprintNode.InnerText : null
);

// custom BOM fields
XmlNode fields = node.SelectSingleNode("fields");
Expand Down