erichVK5 / BXL2text

A utility to convert huffman encoded BXL schematic and footprint files to plain text, gEDA PCB (.fp) and gschem (.sym), and KiCad (.lib) formats
GNU General Public License v2.0
22 stars 9 forks source link

Float coords and text pin names #5

Closed mefistotelis closed 7 years ago

mefistotelis commented 7 years ago

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.

From 90832d30f30bc4cbc928de03da6d2908f27454eb Mon Sep 17 00:00:00 2001
From: mefistotelis 
Date: Thu, 3 Aug 2017 02:23:33 +0200
Subject: [PATCH] BXL: Loading files with float coords.

The patch enables reading BXL files which include float
coordinates. It also fixes conversion of pin numbers
in case pins have text name prefix or postfix.
---
 PinList.java        |  2 +-
 SymbolPolyline.java | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/PinList.java b/PinList.java
index 12f41b5..ee2c474 100644
--- a/PinList.java
+++ b/PinList.java
@@ -379,7 +379,7 @@ public class PinList {
     //System.out.println("PinDesc:" + pinDesc); 
     pinDesc = pinDesc.replaceAll("\"", "");
     pinDesc = pinDesc.replaceAll(" ", "");
-    int BXLPinNum = Integer.parseInt(pinDesc);
+    int BXLPinNum = Integer.parseInt(pinDesc.replaceAll("\\D+",""));
     //System.out.println("Pin num:" + BXLPinNum);
     indexOne = BXLCompPinDef.indexOf("(PinType");
     indexTwo = BXLCompPinDef.indexOf(")", indexOne);
diff --git a/SymbolPolyline.java b/SymbolPolyline.java
index 3928f11..e3b7d4f 100644
--- a/SymbolPolyline.java
+++ b/SymbolPolyline.java
@@ -67,15 +67,15 @@ public class SymbolPolyline extends SymbolElement
     String [] tokens = BXLLine.split(" ");
     for (int index = 0; index < tokens.length; index++) {
       if (tokens[index].equals("Origin")) {
-        xCoords[0] = Integer.parseInt(tokens[++index]);
-        yCoords[0] = Integer.parseInt(tokens[++index]);
+        xCoords[0] = Math.round(Float.parseFloat(tokens[++index]));
+        yCoords[0] = Math.round(Float.parseFloat(tokens[++index]));
         updateCoords(0);
       } else if (tokens[index].equals("EndPoint")) {
-        xCoords[1] = Integer.parseInt(tokens[++index]);
-        yCoords[1] = Integer.parseInt(tokens[++index]);
+        xCoords[1] = Math.round(Float.parseFloat(tokens[++index]));
+        yCoords[1] = Math.round(Float.parseFloat(tokens[++index]));
         updateCoords(1);
       } else if (tokens[index].equals("Width")) {
-        lineThickness = Integer.parseInt(tokens[++index]);
+        lineThickness = Math.round(Float.parseFloat(tokens[++index]));
       }
     }
     vertices = 2;
-- 
2.7.4
mefistotelis commented 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: mefistotelis 
Date: 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
erichVK5 commented 7 years ago

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.

mefistotelis commented 7 years ago

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

erichVK5 commented 7 years ago

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.

mefistotelis commented 7 years ago

Thank you for the software; saved me a lot of drawing, and I'm sure it will save me even more in the future.

erichVK5 commented 7 years ago

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.