private void ConvertComponentLibraries(bool ExtractLibraries) { footprintTable = new k.Project.FootprintTable(); foreach (Library lib in schematic.Drawing.Schematic.Libraries.Library) { if (lib.Name == "frames") { continue; } libraryConverter.ConvertLibrary(lib.Name, lib, schematic.Drawing.Layers.Layer, OutputFolder, ExtractLibraries); //todo: check if any footprints were written footprintTable.Entries.Add(new Kicad_utils.Project.LibEntry(lib.Name, "KiCad", @"$(KIPRJMOD)\\" + lib.Name + ".pretty", "", "")); } // foreach library footprintTable.SaveToFile(Path.Combine(OutputFolder, "fp-lib-table")); // todo boardConv }
public bool ConvertSchematic(string SourceFilename, string DestFolder, string ProjectName, bool ExtractLibraries) { bool result = false; PartMap = new RenameMap(); designRules = new DesignRules(); AllLabels = new List <PinConnection>(); AllComponents = new List <ComponentBase>(); // footprintTable = new k.Project.FootprintTable(); // Trace(string.Format("Reading schematic file {0}", SourceFilename)); schematic = EagleSchematic.LoadFromXmlFile(SourceFilename); OutputFolder = DestFolder; if (schematic != null) { DrawingOffset = new PointF(10.16f, 12.7f); libraryConverter = new LibraryConverter(Parent); // if (Extract... ? ConvertComponentLibraries(ExtractLibraries); Parent.SetLibNames(libraryConverter.LibNames); // foreach (Part part in schematic.Drawing.Schematic.Parts.Part) { k.Symbol.Symbol k_symbol = FindSymbol(part.Deviceset); if ((k_symbol != null) && !k_symbol.PowerSymbol) { PartMap.Add(part.Name); } } PartMap.Annotate(); // k.Schema.SchematicLegacy k_schematic = new SchematicLegacy(); if (schematic.Drawing.Schematic.Sheets.Sheet.Count == 1) { // single sheet is also top level sheet ConvertSheet(k_schematic, 0, ProjectName, true, 1, 1); } else { // create top level CreateMainSheet(k_schematic, schematic.Drawing.Schematic.Sheets.Sheet.Count + 1, ProjectName); for (int sheet_number = 0; sheet_number < schematic.Drawing.Schematic.Sheets.Sheet.Count; sheet_number++) { ConvertSheet(k_schematic, sheet_number, "sheet" + (sheet_number + 1).ToString(), false, sheet_number + 2, schematic.Drawing.Schematic.Sheets.Sheet.Count + 1); } } // Global schematic fixups List <string> labels = new List <string>(); foreach (PinConnection conn in AllLabels) { if (labels.IndexOf(conn.Label.Value) == -1) { labels.Add(conn.Label.Value); } } foreach (string name in labels) { List <PinConnection> instances = AllLabels.FindAll(x => x.Label.Value == name); bool is_global = false; foreach (PinConnection item in instances) { if (item.Sheet != instances[0].Sheet) { is_global = true; break; } } if (is_global) { Trace(String.Format("note: converting {0} to global label", name)); foreach (PinConnection item in instances) { item.Label.Type = "GLabel"; item.Label.Shape = "3State"; item.Label.TextSize = (int)(item.Label.TextSize * 0.75f); if ((item.Label.Orientation % 2) == 0) { item.Label.Orientation = 2 - item.Label.Orientation; } } } } // string filename = Path.Combine(OutputFolder, ProjectName + ".sch"); Trace(string.Format("Writing schematic {0}", filename)); k_schematic.SaveToFile(filename); result = true; } else { result = false; Trace(string.Format("error opening {0}", SourceFilename)); } // return(result); }