private void CreateMainSheet(SchematicLegacy k_schematic, int NumSheets, string ProjectName) { List <string> Timestamps = new List <string>(); SheetLegacy k_sheet = new SheetLegacy(); k_sheet.Filename = ProjectName; k_sheet.LibNames = libraryConverter.LibNames; k_sheet.SheetNumber = 1; k_sheet.SheetCount = NumSheets; k_sheet.SubSheets = new List <SheetSpecLegacy>(); PointF cur_pos = new PointF(1000, 1000); for (int sheet_number = 0; sheet_number < schematic.Drawing.Schematic.Sheets.Sheet.Count; sheet_number++) { k.Schema.SheetSpecLegacy sheet_spec = new SheetSpecLegacy(); sheet_spec.Name = new LegacyField("sheet" + (sheet_number + 1).ToString(), 50); sheet_spec.Filename = new LegacyField(sheet_spec.Name.Value + ".sch", 50); sheet_spec.Position = cur_pos; sheet_spec.Size = new PointF(1600, 1000); sheet_spec.Timestamp = GetUniqueTimeStamp(Timestamps); k_sheet.SubSheets.Add(sheet_spec); cur_pos.X += 2000; if (cur_pos.X + 1600 > k_sheet.PageSize.Width * Common.mm_to_mil) { cur_pos.X = 1000; cur_pos.Y += 1500; } } k_schematic.Sheets.Add(k_sheet); k_schematic.MainSheet = k_sheet; }
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); }