Excellon coordinate parsing.

Issue #94 resolved
Juan Pablo Caram repo owner created an issue

There seems to be ambiguity in the Excellon specification regarding coordinate number format, and the parser so far still seems to have trouble dealing with all cases correctly.

Here is the whole number parser as of version 8:

def parse_number(self, number_str):
    """
    Parses coordinate numbers without period.

    :param number_str: String representing the numerical value.
    :type number_str: str
    :return: Floating point representation of the number
    :rtype: foat
    """
    if self.zeros == "L":
        # With leading zeros, when you type in a coordinate,
        # the leading zeros must always be included.  Trailing zeros
        # are unneeded and may be left off. The CNC-7 will automatically add them.
        # r'^[-\+]?(0*)(\d*)'
        # 6 digits are divided by 10^4
        # If less than size digits, they are automatically added,
        # 5 digits then are divided by 10^3 and so on.
        match = self.leadingzeros_re.search(number_str)
        return float(number_str)/(10**(len(match.group(1)) + len(match.group(2)) - 2))

    else:  # Trailing
        # You must show all zeros to the right of the number and can omit
        # all zeros to the left of the number. The CNC-7 will count the number
        # of digits you typed and automatically fill in the missing zeros.
        if self.units.lower() == "in":  # Inches is 00.0000
            return float(number_str)/10000

        return float(number_str)/1000  # Metric is 000.000

The comments come straight from http://www.excellon.com/manuals/program.htm

Comments (24)

  1. Per Byrgren

    Hi JP. I've just checked and you're right about Metric, there's many different formats, but the Inch format of Exellon has only one format 00.0000 .... with the option for dropping leading zeros. Oh well, time to change to Metric in my Exellon files. You should probably ad info to the documentation section about the Exellon format now used in FlatCam. Best wishes Per

  2. Per Byrgren

    Hi JP Well that did not work, neither in 000.000 nor in 0000.00 Metric. It's strange but I get the same result, no matter if I load an Exellon file generated in Inch 00.000 or a Metric in 00.0000 , 000.000 or 0000.00 all four are 10 times the size of the Gerber file in FlatCam. The Gerber file loads perfectly and the size is right in FlatCam but none of the Exellon are - even though I can see that they are correct in the text file - so what is happening ? Best wishes Per

  3. Juan Pablo Caram reporter

    Beginning of drill file (by Per):

    M48
    M72
    T1C.02362F197S550
    T2C.03543F197S550
    T3C.04331F139S550
    T4C.05512F107S550
    T5C.0748F81S550
    M95
    T1
    X9000Y11750
    X30250Y10500
    X31250Y10100
    X7750Y15750
    T2
    X26500Y11250
    X26500Y12250
    
  4. Per Byrgren

    Hi JP Thank you for your reply, although I am not sure what the message is - have I made any errors I can't spot myself ? I tried to load the files from you back into FlatCam, just to confirm them and the Gerber loads fine, but not the Exellon file, the program is stuck around 20% and I can't see why - it didn't do that before I posted it above and I can't spot the error in the file. Best wishes Per

  5. Per Byrgren

    The above is a straight paste into <> as txt as you suggested and I can't see any errors. It's in Inch format - how does FlatCam spot the format - are you using the M72 command for instance ? I'm thinking about my problem with Metric too - how does FlatCam place the decimal point - do you place it by incrementing the pointer 3 places from the left or the right, so to speak ? Best wishes Per

  6. Juan Pablo Caram reporter

    The file is missing the % to separate the head from the body. Should read like:

    ...
    T4C.05512F107S550
    T5C.0748F81S550
    M95
    %
    T1
    X9000Y11750
    X30250Y10500
    ...
    
  7. Juan Pablo Caram reporter

    The first comment on this thread shows how FlatCAM parses the numbers. Id does not do any detection of file type. It just assumes it's an Excellon when you do File->Open Excellon.

  8. Per Byrgren

    Hi JP I'm sorry and feel like fool now - I have seen that part of your code before, but for some reason I just noticed that it was in an unfamiliar language, so instead of actually reading it I just skimmed it some. I just added the zeros to make it X003000 and not something like X3000 and that cured the placement part. Now it's just the size of the holes that are wrong, so T1C.9F197S550 ends up with a hole that is 0.9" and not 0.9mm. in a Metric file and I have a sneaking feeling that it goes for the federate too. Sorry for being a pain. Best wishes Per

  9. Per Byrgren

    Hi JP

    I just tried the Inch format with leading zeros and it works fine - just thought that you should know.

    Best wishes Per

  10. Juan Pablo Caram reporter

    The files previously uploaded were not loading because there were garbage character in the file. This must have happened because I copied and pasted from the comment in the browser. This first line in the Excelon file as reported by the debugger read:

    '\xef\xbb\xbfM48'
    
  11. Juan Pablo Caram reporter

    FlatCAM is expecting the number format, which is missing. Should say INCH,TZ, INCH,LZ, METRIC,TZ or METRIC,LZ.

    At this time M71 and M72 are ignored.

    FlatCAM is defaulting to leading zeros (L) and in such case it ignores the units. Will always divide by 10000 if it has 6 digits, by 1000 if 5, etc. The trailing zeros case does the inch/mm distinction correctly.

    Additionally, self.units only gets defined if a units declaration in the file is found. There is no default. This should be corrected.

  12. Juan Pablo Caram reporter

    Action plan:

    • Set default units to inches.
    • Make distinction between units when leading zeros are used.
    • Detect M7(1|2)

    Inches will default to 00.0000 and metric to 000.000.

  13. Juan Pablo Caram reporter

    About the "End of Header" command. It can be M95 or %. Note that % has a different meaning if within the body. Therefore the parser must make a distinction depending of where it finds it.

  14. trenton carr

    Same issues this side, using M7? codes, files display correctly in GerbV.

    I use metric tools but eagle plots in imp so I've set METRIC,TZ in header and INCH,TZ in program.

    It looks OK but the scaling is off. Dropping the [TZ] causes it to plot incorrectly scaling and position.

    Excellon file attached. File

  15. Per Byrgren

    Hi JP

    The two files in the zip file are Emma_ML-1_r0.73_Bottom.pho + Emma_ML-1_r073_Drill.drl and they are from the same project. I'm only giving you the solderside and the drill file (no interesting stuff) and they worked in FlatCam 7.2 but not in version 8.0.

    After I made a new drill file with the leading zero's, that file is read correctly in FlatCam 8.0 - except from the two slotted holes for the transformer :

    X16415Y1882G85X15785Y1882

    X16415Y12118G85X15785Y12118

    They are drill commands + when drill is plunged down, move to next position.

    Hope this helps.

    Best wishes Per

  16. trenton carr

    If your Drill file is not scales correctly try 2.54 as per hint somewhere else around here.

    Works spot on now.

    Well done

  17. Per Byrgren

    Hi JP

    Gladly - but the source code doesn't help me ....

    Do you have a compiled file I could try ?

    Best wishes Per

  18. Juan Pablo Caram reporter

    I'm seeing files that use M71/72 but are written using trailing zeros.

    I've added the default excellon_zeros which can be changed using the shell. It defaults to "L" but can be changed to default to "T":

    set_sys excellon_zeros T
    
  19. Log in to comment