buggy import of gerber macro aperture

Issue #245 new
a_goodwin created an issue

Hello! I tried to import attached gerber file from Mentor Graphics DxDesigner PCB Suite and failed. As I think, problem is hiding in macro apperture substitution AMVB_RCRECTANGLE from the attached file. traceback is below:

[DEBUG][MainThread] button=1, x=195, y=202, xdata=-0.730174, ydata=0.342360
[DEBUG][MainThread] on_fileopengerber()
[DEBUG][Dummy-2] Running task: {'params': [u'/mnt/work/CNC/Board_Denis_R/Gerber/TOP.gdo'], 'fcn': <bound method App.open_gerber of <FlatCAMApp.App object at 0x7fd4a53db770>>}
[DEBUG][Dummy-2] Task ignored.
[DEBUG][Dummy-3] Running task: {'params': [u'/mnt/work/CNC/Board_Denis_R/Gerber/TOP.gdo'], 'fcn': <bound method App.open_gerber of <FlatCAMApp.App object at 0x7fd4a53db770>>}
[DEBUG][Dummy-3] open_gerber()
[DEBUG][Dummy-3] FCVisibleProcessContainer.on_change()
[DEBUG][Dummy-3] new_object()
[DEBUG][Dummy-3] Calling object constructor...
[DEBUG][Dummy-3] 0.003019 seconds before initialize().
[WARNING] Line ignored (1): *
[WARNING] Line ignored (7): %ICAS*%
[DEBUG] Geometry.convert_units()
[WARNING] Line ignored (10): %OFA0.0000B0.0000*%
[DEBUG] Starting macro. Line 13: %AMVB_RECTANGLE*
[DEBUG] Continuing macro. Line 14.
[DEBUG] Continuing macro. Line 15.
[DEBUG] End of macro. Line 15.
[DEBUG] Starting macro. Line 16: %AMVB_RCRECTANGLE*
[DEBUG] Continuing macro. Line 17.
[DEBUG] Continuing macro. Line 18.
[DEBUG] Continuing macro. Line 19.
[DEBUG] Continuing macro. Line 20.
[DEBUG] Continuing macro. Line 21.
[DEBUG] Continuing macro. Line 22.
[DEBUG] Continuing macro. Line 23.
[DEBUG] Continuing macro. Line 24.
[DEBUG] Continuing macro. Line 25.
[DEBUG] Continuing macro. Line 26.
[DEBUG] Continuing macro. Line 27.
[DEBUG] Continuing macro. Line 28.
[DEBUG] Continuing macro. Line 29.
[DEBUG] End of macro. Line 29.
[INFO] Found aperture definition. Line 30: %ADD10C,0.00500*%
[INFO] Found aperture definition. Line 31: %ADD12C,1.00000X0.99000*%
[INFO] Found aperture definition. Line 32: %ADD14C,1.20000*%
[INFO] Found aperture definition. Line 33: %ADD13C,1.40000*%
[INFO] Found aperture definition. Line 34: %ADD15C,1.60000X1.00000*%
[INFO] Found aperture definition. Line 35: %ADD11C,2.00000*%
[INFO] Found aperture definition. Line 36: %ADD17R,1.50000X1.50000*%
[INFO] Found aperture definition. Line 37: %ADD16R,1.25000X1.25000*%
[DEBUG] I: 0.050000  J: 0.000000
[DEBUG] ARC START: 0.900000, 17.550000  CENTER: 0.950000, 17.550000  STOP: 0.950000, 17.600000
[DEBUG] START Ang: -180.000000, STOP Ang: 90.000000, DIR: cw, ABS: 90.000000000000 <= 90.000000000000: True
[DEBUG] ########## ACCEPTING ARC ############
[DEBUG] I: 0.050000  J: 0.000000
[DEBUG] ARC START: 14.900000, 24.450000  CENTER: 14.950000, 24.450000  STOP: 14.950000, 24.500000
[DEBUG] START Ang: -180.000000, STOP Ang: 90.000000, DIR: cw, ABS: 90.000000000000 <= 90.000000000000: True
[DEBUG] ########## ACCEPTING ARC ############
[DEBUG] I: 0.500000  J: 0.000000

... here was long log of successfuly accepted arcs :)

[DEBUG] ########## ACCEPTING ARC ############
[DEBUG] Line 268: Aperture change to (10)
[DEBUG] {'type': 'C', 'size': 0.005}
[DEBUG] Line 278: Aperture change to (11)
[DEBUG] {'type': 'C', 'size': 2.0}
[DEBUG] Flashing @POINT (36.9 14.55), Aperture: {'type': 'C', 'size': 2.0}
[DEBUG] Line 280: Aperture change to (12)
[DEBUG] {'type': 'C', 'size': 1.0}
[DEBUG] Line 333: Aperture change to (13)
[DEBUG] {'type': 'C', 'size': 1.4}
[DEBUG] Line 337: Aperture change to (14)
[DEBUG] {'type': 'C', 'size': 1.2}
[DEBUG] Line 354: Aperture change to (15)
[DEBUG] {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (0.9 7.2), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (0.9 9.73), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (0.9 12.27), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (0.9 14.81), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (2.8 5.4), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (2.8 17.6), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (5.34 5.37), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (5.34 17.6), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (7.880000000000001 17.6), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (10.42 17.6), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (36.9 14.55), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Line 366: Aperture change to (16)
[DEBUG] {'width': 1.25, 'size': 1.7677669529663689, 'type': 'R', 'height': 1.25}
[DEBUG] Flashing @POINT (21.355 2.07), Aperture: {'width': 1.25, 'size': 1.7677669529663689, 'type': 'R', 'height': 1.25}
[DEBUG] Flashing @POINT (23.405 2.07), Aperture: {'width': 1.25, 'size': 1.7677669529663689, 'type': 'R', 'height': 1.25}
[DEBUG] Line 369: Aperture change to (17)
[DEBUG] {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (18 9.025), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (18 12.275), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (18 15.525), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (18 18.775), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (21.35 4.65), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (21.375 21.15), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (24.6 4.65), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (24.625 21.15), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (27.85 4.65), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (27.875 21.15), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (31.1 4.65), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (31.125 21.15), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (34.5 8.025), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (34.5 11.275), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (34.5 14.525), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[DEBUG] Flashing @POINT (34.5 17.775), Aperture: {'width': 1.5, 'size': 2.1213203435596424, 'type': 'R', 'height': 1.5}
[WARNING] Joining 66 polygons.
[DEBUG] Union by buffer...
[WARNING] Union(buffer) done.
[DEBUG][Dummy-3] 0.301163 seconds executing initialize().
[DEBUG] Geometry.convert_units()
[DEBUG][Dummy-3] 0.006787 seconds converting units.
[DEBUG][Dummy-3] Moving new object back to main thread.
[DEBUG][MainThread] on_object_created()
[DEBUG][Dummy-3] FCVisibleProcessContainer.on_done()
[DEBUG][Dummy-3] FCVisibleProcessContainer.on_done()
[DEBUG][MainThread] on_object_created --> OC.append()
[DEBUG][MainThread] append --> OC.get_names()
[DEBUG][MainThread] FlatCAMGerber.set_ui()
[DEBUG][Dummy-1] A new object is available. Should plot it!
[DEBUG][MainThread] on_object_created --> FlatCAMGerber.plot()
[DEBUG][MainThread] plot --> FlatCAMObj.plot()
[DEBUG][Dummy-1] Canvas update requested: [0, 0, 0, 0, 0]
[DEBUG][Dummy-1] Size: (1522.4391534391534, 524.0) [px]
[DEBUG][Dummy-1] Density: (0.0019253425823918036, 0.0019083969465648854) [units/px]
[DEBUG][MainThread] on_zoom_fit--> OC.get_bounds()
[DEBUG] Geometry->bounds()
[DEBUG][MainThread] 0.265793 seconds adding object and plotting.
[DEBUG][Dummy-1] Canvas update requested: [0, 0, 0, 0, 0]
[DEBUG][Dummy-1] Size: (1522.4391534391534, 524.0) [px]
[DEBUG][MainThread] register_recent()
[DEBUG][Dummy-1] Density: (0.0020849413543298327, 0.0020665910320370258) [units/px]
[DEBUG][MainThread]    gerber
[DEBUG][MainThread]    /mnt/work/CNC/Board_Denis_R/Gerber/TOP.gdo
[DEBUG][MainThread] setup_recent_items()
[DEBUG][MainThread] Cache updated the screen!
[DEBUG][MainThread] Cache updated the screen!
[DEBUG][MainThread] on_list_selection_change()
[DEBUG][MainThread] Current: <PyQt4.QtGui.QItemSelection object at 0x7fd4a052a8c0>, Previous <PyQt4.QtGui.QItemSelection object at 0x7fd4a052a938>
[DEBUG][MainThread] on_list_selection_change--> FlatCAMObj.build_ui()
[DEBUG][MainThread] build_ui--> FlatCAMObj.to_form()
[DEBUG][MainThread] Radio toggled
[WARNING][MainThread] Tried to set an option or field that does not exist: use_buffer_for_union
[DEBUG][MainThread] Mouse button pressed on list
[DEBUG][MainThread] Mouse button pressed on list
[DEBUG][MainThread] on_delete()
[DEBUG][Dummy-1] Canvas update requested: [0, 0, 0, 0, 0]
[DEBUG][Dummy-1] Size: (1522.4391534391534, 524.0) [px]
[DEBUG][Dummy-1] Density: (0.0020849413543298327, 0.0020665910320370258) [units/px]
[DEBUG][MainThread] on_list_selection_change()
[DEBUG][MainThread] Current: <PyQt4.QtGui.QItemSelection object at 0x7fd4a052aa28>, Previous <PyQt4.QtGui.QItemSelection object at 0x7fd4a052aaa0>
[DEBUG][MainThread] on_list_selection_change(): Index Error (Nothing selected?)
[DEBUG][MainThread] Cache updated the screen!
[DEBUG][MainThread] on_fileopengerber()
[DEBUG][Dummy-2] Running task: {'params': [u'/mnt/work/CNC/Board_Denis_R1/Gerber/TOP.gdo'], 'fcn': <bound method App.open_gerber of <FlatCAMApp.App object at 0x7fd4a53db770>>}
[DEBUG][Dummy-2] Task ignored.
[DEBUG][Dummy-3] Running task: {'params': [u'/mnt/work/CNC/Board_Denis_R1/Gerber/TOP.gdo'], 'fcn': <bound method App.open_gerber of <FlatCAMApp.App object at 0x7fd4a53db770>>}
[DEBUG][Dummy-3] open_gerber()
[DEBUG][Dummy-3] FCVisibleProcessContainer.on_change()
[DEBUG][Dummy-3] new_object()
[DEBUG][Dummy-3] Calling object constructor...
[DEBUG][Dummy-3] 0.000268 seconds before initialize().
[WARNING] Line ignored (1): *
[WARNING] Line ignored (7): %ICAS*%
[DEBUG] Geometry.convert_units()
[WARNING] Line ignored (10): %OFA0.0000B0.0000*%
[DEBUG] Starting macro. Line 13: %AMVB_RECTANGLE*
[DEBUG] Continuing macro. Line 14.
[DEBUG] Continuing macro. Line 15.
[DEBUG] End of macro. Line 15.
[DEBUG] Starting macro. Line 16: %AMVB_RCRECTANGLE*
[DEBUG] Continuing macro. Line 17.
[DEBUG] Continuing macro. Line 18.
[DEBUG] Continuing macro. Line 19.
[DEBUG] Continuing macro. Line 20.
[DEBUG] Continuing macro. Line 21.
[DEBUG] Continuing macro. Line 22.
[DEBUG] Continuing macro. Line 23.
[DEBUG] Continuing macro. Line 24.
[DEBUG] Continuing macro. Line 25.
[DEBUG] Continuing macro. Line 26.
[DEBUG] Continuing macro. Line 27.
[DEBUG] Continuing macro. Line 28.
[DEBUG] Continuing macro. Line 29.
[DEBUG] End of macro. Line 29.
[INFO] Found aperture definition. Line 30: %ADD10C,0.00500*%
[INFO] Found aperture definition. Line 31: %ADD12C,1.00000*%
[INFO] Found aperture definition. Line 32: %ADD14C,1.20000*%
[INFO] Found aperture definition. Line 33: %ADD13C,1.40000*%
[INFO] Found aperture definition. Line 34: %ADD15C,1.60000*%
[INFO] Found aperture definition. Line 35: %ADD11C,2.00000*%
[INFO] Found aperture definition. Line 36: %ADD17VB_RECTANGLE,1.50000X1.50000X0.00000*%
[INFO] Found aperture definition. Line 37: %ADD16VB_RCRECTANGLE,1.25000X1.25000X0.10000*%
[DEBUG] I: 0.050000  J: 0.000000
[DEBUG] ARC START: 0.900000, 17.550000  CENTER: 0.950000, 17.550000  STOP: 0.950000, 17.600000
[DEBUG] START Ang: -180.000000, STOP Ang: 90.000000, DIR: cw, ABS: 90.000000000000 <= 90.000000000000: True
[DEBUG] ########## ACCEPTING ARC ############
[DEBUG] I: 0.050000  J: 0.000000
[DEBUG] ARC START: 14.900000, 24.450000  CENTER: 14.950000, 24.450000  STOP: 14.950000, 24.500000
[DEBUG] START Ang: -180.000000, STOP Ang: 90.000000, DIR: cw, ABS: 90.000000000000 <= 90.000000000000: True

... here was another one block of accepted arcs

[DEBUG] Line 268: Aperture change to (10)
[DEBUG] {'type': 'C', 'size': 0.005}
[DEBUG] Line 278: Aperture change to (11)
[DEBUG] {'type': 'C', 'size': 2.0}
[DEBUG] Flashing @POINT (36.9 14.55), Aperture: {'type': 'C', 'size': 2.0}
[DEBUG] Line 280: Aperture change to (12)
[DEBUG] {'type': 'C', 'size': 1.0}
[DEBUG] Line 333: Aperture change to (13)
[DEBUG] {'type': 'C', 'size': 1.4}
[DEBUG] Line 337: Aperture change to (14)
[DEBUG] {'type': 'C', 'size': 1.2}
[DEBUG] Line 354: Aperture change to (15)
[DEBUG] {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (0.9 7.2), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (0.9 9.73), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (0.9 12.27), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (0.9 14.81), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (2.8 5.4), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (2.8 17.6), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (5.34 5.37), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (5.34 17.6), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (7.880000000000001 17.6), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (10.42 17.6), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Flashing @POINT (36.9 14.55), Aperture: {'type': 'C', 'size': 1.6}
[DEBUG] Line 366: Aperture change to (16)
[DEBUG] {'macro': <camlib.ApertureMacro instance at 0x7fd4a04daa70>, 'modifiers': ['1.25000', '1.25000', '0.10000'], 'type': 'AM'}
[DEBUG] Flashing @POINT (21.355 2.07), Aperture: {'macro': <camlib.ApertureMacro instance at 0x7fd4a04daa70>, 'modifiers': ['1.25000', '1.25000', '0.10000'], 'type': 'AM'}
  File "/home/goodwin/src/flatcam/camlib.py", line 1960, in parse_lines
    self.apertures[current_aperture])
  File "/home/goodwin/src/flatcam/camlib.py", line 2424, in create_flash_geometry
    flash_geo = aperture['macro'].make_geometry(aperture['modifiers'])
  File "/home/goodwin/src/flatcam/camlib.py", line 1404, in make_geometry
    self.parse_content()
  File "/home/goodwin/src/flatcam/camlib.py", line 1153, in parse_content
    self.locvars[var] = eval(val)
[ERROR] PARSING FAILED. Line 367: X213550Y20700D03*
[ERROR][Dummy-3] ('Line 367: X213550Y20700D03*', "SyntaxError('invalid syntax', ('<string>', 1, 1, '$3*2'))")
[ERROR][Dummy-3] Abnormal termination of process!
[ERROR][Dummy-3] <class 'camlib.ParseError'>
[ERROR][Dummy-3] ('Line 367: X213550Y20700D03*', "SyntaxError('invalid syntax', ('<string>', 1, 1, '$3*2'))")
[ERROR][Dummy-3] <traceback object at 0x7fd4a04612d8>
[DEBUG][Dummy-3] FCVisibleProcessContainer.on_done()
[DEBUG][Dummy-3] FCVisibleProcessContainer.on_done()
Traceback (most recent call last):
  File "/home/goodwin/src/flatcam/FlatCAMWorker.py", line 62, in do_worker_task
    raise e
camlib.ParseError: ('Line 367: X213550Y20700D03*', "SyntaxError('invalid syntax', ('<string>', 1, 1, '$3*2'))")

Please help me with this, if it is a trouble of FlatCam Thank you for your product anyway!

Comments (1)

  1. Marius Stanciu

    @a_goodwin thanks for the attached file. Using it I was able to find that for some reason the following code in parse_content() function found in ApertureMacro class from camlib.py is not doing what was intended to do:

    # Replace variables in value
    for v in self.locvars:
          val = re.sub(r'\$'+str(v)+r'(?![0-9a-zA-Z])', str(self.locvars[v]), val)
    

    and

    ## Replace all variables
    for v in self.locvars:
          part = re.sub(r'\$' + str(v) + r'(?![0-9a-zA-Z])', str(self.locvars[v]), part)
    

    I was able to fix it by using the replace function like this:

    for v in self.locvars:
          val = val.replace('$' + str(v), str(self.locvars[v])
    

    I've implemented this change (and some other in the Gerber parsing) in my fork of FlatCAM and then your file could be opened successfully.

  2. Log in to comment