Closed mefistotelis closed 7 years ago
Second patch - allows writing up to 20 defs from the same BXL symbol.
Crude but allowed me to read the TI lib properly. I did not tested whether this regresses any other files.
From ab11cd9e7ba3499907449e2f02b5ad4671b6429f Mon Sep 17 00:00:00 2001 From: mefistotelisDate: Thu, 3 Aug 2017 03:10:53 +0200 Subject: [PATCH 2/2] KiCAD: Conversion from BXL of multiple DEFs. It is now possible to get multiple DEFs from a single BXL file. --- BXLDecoder.java | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/BXLDecoder.java b/BXLDecoder.java index 0204d8f..6e58d4e 100644 --- a/BXLDecoder.java +++ b/BXLDecoder.java @@ -73,14 +73,16 @@ public class BXLDecoder { // some variables for kicad eeschema symbol export String kicadHeader = "EESchema-LIBRARY Version 2.3\n#\n# converted by BXL2text https://github.com/erichVK5/BXL2text"; - String kicadDefs = ""; - String kicadDrawn = "\nDRAW"; - String kicadFPList = "\n$FPLIST"; + String kicadDefs[] = new String[20]; + String kicadDrawn[] = new String[20]; + String kicadFPList[] = new String[20]; + int dfIndex = -1; + String newSymbol = ""; String symAttributes = ""; PadStackList padStacks = new PadStackList(); - PinList pins = new PinList(0); // slots = 0 + PinList pins[] = new PinList[20]; long xOffset = 0; long yOffset = 0; @@ -140,15 +142,16 @@ public class BXLDecoder { String [] tokens = currentLine.split(" "); String SymbolName = tokens[1].replaceAll("[\"]",""); + dfIndex++; // build a kicad symbol header DEF section here - kicadDefs = kicadDefs - + "\n# " + SymbolName + "\n#\n" + kicadDefs[dfIndex] = + "\n# " + SymbolName + "\n#\n" + "DEF " + SymbolName + " U 0 40 Y Y 1 F N\n" + "F0 \"U\" 0 -150 50 H V C CNN\n" + "F1 \"" + SymbolName + "\" 0 150 50 H V C CNN"; - - // PinList pins = new PinList(0); // slots = 0 - pins = new PinList(0); // slots = 0 + kicadDrawn[dfIndex] = "\nDRAW"; + kicadFPList[dfIndex] = "\n$FPLIST"; + pins[dfIndex] = new PinList(0); // slots = 0 while (textBXL.hasNext() && !currentLine.startsWith("EndSymbol")) { currentLine = textBXL.nextLine().trim(); @@ -159,13 +162,13 @@ public class BXLDecoder { textBXL.nextLine().trim() + " " + textBXL.nextLine().trim(); // we combine the 3 lines latestPin.populateBXLElement(currentLine); - pins.addPin(latestPin); + pins[dfIndex].addPin(latestPin); } else if (currentLine.startsWith("Line")) { SymbolPolyline symbolLine = new SymbolPolyline(); symbolLine.populateBXLElement(currentLine); newElement = newElement + "\n" + symbolLine.toString(0,0); - kicadDrawn = kicadDrawn + kicadDrawn[dfIndex] = kicadDrawn[dfIndex] + "\n" + symbolLine.toKicad(0,0); } else if (currentLine.startsWith("Arc (Layer TOP_SILKSCREEN)")) { Arc silkArc = new Arc(); @@ -215,34 +218,40 @@ public class BXLDecoder { String FPAttr = "footprint=" + currentLine; symAttributes = symAttributes + SymbolText.BXLAttributeString(0,0, FPAttr); - kicadFPList = kicadFPList + "\n " + currentLine; + kicadFPList[dfIndex] = kicadFPList[dfIndex] + "\n " + currentLine; } else if (currentLine.startsWith("AlternatePattern")) { currentLine = currentLine.replaceAll(" ", ""); currentLine = currentLine.split("\"")[1]; String AltFPAttr = "alt-footprint=" + currentLine; symAttributes = symAttributes + SymbolText.BXLAttributeString(0,0, AltFPAttr); - kicadFPList = kicadFPList + "\n " + currentLine; + kicadFPList[dfIndex] = kicadFPList[dfIndex] + "\n " + currentLine; } else if (currentLine.startsWith("CompPin ")) { - pins.setBXLPinType(currentLine); + pins[dfIndex].setBXLPinType(currentLine); } } try { File newSym = new File(symbolName + ".sym"); PrintWriter symOutput = new PrintWriter(newSym); - symOutput.println(newSymbol // we now add pins to the - + pins.toString(0,0) // the header, and then + for (int i=0; i < kicadDefs.length; i++) { + if (kicadDefs[i] == null) break; + symOutput.println(newSymbol // we now add pins to the + + pins[i].toString(0,0) // the header, and then + symAttributes); // the final attributes + } symOutput.close(); System.out.println(symbolName + ".sym"); // KiCad symbol export - String kicad = kicadHeader - + kicadDefs - + kicadFPList + "\n$ENDFPLIST" // name says it all - + kicadDrawn // drawn elements here - + pins.toKicad(0,0) // we now add pins + String kicad = kicadHeader; + for (int i=0; i < kicadDefs.length; i++) { + if (kicadDefs[i] == null) break; + kicad += kicadDefs[i] + + kicadFPList[i] + "\n$ENDFPLIST" // name says it all + + kicadDrawn[i] // drawn elements here + + pins[i].toKicad(0,0) // we now add pins + "\nENDDRAW\nENDDEF"; + } File newKicad = new File(symbolName + ".lib"); symOutput = new PrintWriter(newKicad); symOutput.println(kicad); -- 2.7.4
cool, good work, I will look to incorporate the changes.
Can you recommend a test uC BXL to use for testing from TI?
Cheers
Erich.
I used this: http://www.st.com/en/microcontrollers/stm32f427ii.html "STM32F4 CAD Symbol and Footprint files"
The specific file I needed was STM32F4xxH2.bxl.
Here's how the model looks (the 4 big parts are the one chip): https://github.com/mefistotelis/dji-hardware-schematics/blob/master/phantom_3_pro_flight_ctrl_board/phantom_3_pro_flight_ctrl_board.pdf
Thanks, I should have time to do this in the next day or two. The changes make sense for Kicad user purposes.
Thanks for the patches,
Erich.
Thank you for the software; saved me a lot of drawing, and I'm sure it will save me even more in the future.
I have merged the eeschema multi symbol support you provided diffs for and at the same time added gschem multisymbol support.
Thanks for flagging the issues.
Erich.
This fixes reading TI uC schematics.
The schematics are not properly converted with this patch as one symbol there includes multiple drawings. But after this patch, at least the last drawing is properly exported.