saar drimer avatar saar drimer committed 26880e9

it is now possible to specifiy a manufacturer so that files are produced accorindg to their specification

Comments (0)

Files changed (5)

                       action='store_true', dest='routing', default=False,
                       help="Extract routing from the 'copper' layer of an SVG file")
      
-    argp.add_argument('-g', '--gerberise',
-                      action='store_true', dest='gerberise', default=False,
-                      help='Generate Gerber files for all layers')
+    argp.add_argument('-fab', '--fab', nargs='?',
+                      dest='fab', default=False,
+                      help='Generate manufacturing files (Gerbers, Excellon, etc.)')
 
-    argp.add_argument('-e', '--make-excellon',
-                      action='store_true', dest='excellon', default=False,
-                      help='Generate and Excellon drill file')
-     
     argp.add_argument('-p', '--make-pngs',
                       action='store_true', dest='pngs', default=False,
                       help='Generate PNGs for the board and layers (requires Inkscape)')
+
+#    argp.add_argument('-z', '--zip',
+#                      action='store_true', dest='zip', default=False,
+#                      help='Zip manufacturing files')    
         
     return argp
 
     if cmdline_args.make is True:
         print "-- creating board"
         board.create_board(cfg) 
+
     
-    if cmdline_args.gerberise is True:
-        print "-- gerberising"
-        gerber.gerberise(cfg)
-     
+    if cmdline_args.fab is not False:
+        if cmdline_args.fab is None:
+            manufacturer = 'default'
+        else:
+            manufacturer = cmdline_args.fab.lower()
+
+        print "-- creating Gerbers"
+        print "files:",
+        gerber_filenames = gerber.gerberise(cfg, manufacturer)
+        print
+        print "-- creating drill file(s)"
+        print "files:",
+        drill_filenames = excellon.make_excellon(cfg, manufacturer)
+        print
+
+        filenames = gerber_filenames + drill_filenames
+
+        # create a readme file
+        readme = open(os.path.join(cfg['base_dir'],
+                                    cfg['pcbmode']['locations']['build'], 
+                                    'production', 'README.txt'), 'w')
+
+        readme.write("The following files are included in this archive:\n")
+        for f in filenames:
+            readme.write("%s\n" % os.path.basename(f))
+        readme.write("\n")
+        readme.write("Please refer to the docoumentation Gerber file for manufacturing instructions.")
+        readme.write("\n")
+        readme.close()
+
+        
+#        if cmdline_args.zip is True:
+# 
+#            filenames = gerber_filenames + drill_filenames
+# 
+#            board_name = cfg['board_name']
+#            board_revision = cfg['board']['meta'].get('board_revision') or 'A'
+#            base_dir = os.path.join(cfg['base_dir'], 
+#                                    cfg['pcbmode']['locations']['build'], 
+#                                    'production')
+#            base_name = "%s_rev_%s" % (board_name, board_revision)
+# 
+#            zip_name = base_name + '.zip'
+# 
+#            print "-- creating zip of manufacturing files"
+#            utils.zip_files(base_dir, zip_name, filenames)
+
+
+
     if cmdline_args.pngs is True:
         print "-- creating PNGs"
         utils.create_pngs(cfg)
      
-    if cmdline_args.excellon is True:
-        print "-- generating Excellon drill file"
-        excellon.make_excellon(cfg)
-     
+    
     if cmdline_args.bom is True:
         print "-- creating BOM (not implemented yet!)"
         pass

pcbmode_config.json

     "fonts": "fonts/",
     "build": "build/",
     "styles": "styles/"
+  },
+  "manufacturers":
+  {
+    "default":
+    {
+      "filenames":
+      {
+        "gerbers":
+        {
+          "top":
+          {
+            "copper": {"ext": "ger"},
+            "soldermask": {"ext": "ger"},
+            "silkscreen": {"ext": "ger"}
+          },
+          "bottom":
+          {
+            "copper": {"ext": "ger"},
+            "soldermask": {"ext": "ger"},
+            "silkscreen": {"ext": "ger"}  
+          },
+          "other":
+   	  {
+            "documentation": {"ext": "ger"},
+            "outline": {"ext": "ger"}
+          }
+        },
+        "drills":
+        {
+          "plated": {"ext": "txt"},
+          "non_plated": {"ext": "txt"}
+        },
+        "text":
+	{
+          "readme": {"ext": "txt"}
+        }
+      }
+    },
+    "hackvana":
+    {
+      "filenames":
+      {
+        "gerbers":
+        {
+          "top":
+          {
+            "copper": {"ext": "gtl"},
+            "soldermask": {"ext": "gts"},
+            "silkscreen": {"ext": "gto"}
+          },
+          "bottom":
+          {
+            "copper": {"ext": "gbl"},
+            "soldermask": {"ext": "gbs"},
+            "silkscreen": {"ext": "gbo"}  
+          },
+          "other":
+   	  {
+            "documentation": {"ext": "gbr"},
+            "outline": {"ext": "gbr"}
+          }
+        },
+        "drills":
+        {
+          "plated": {"ext": "drl"},
+          "non_plated": {"end": "_NPTH", "ext": "drl"}
+        },
+        "text":
+	{
+          "readme": {"ext": "txt"}
+        }
+      }
+    }
   }
 }

utils/excellon.py

 from Point import Point
 
 
-def make_excellon(cfg):
+def make_excellon(cfg, manufacturer='default'):
     """
     Generates an Excellon drill file
     """
     production_path = os.path.join(cfg['base_dir'], cfg['pcbmode']['locations']['build'], 'production')
     utils.create_dir(production_path)
 
-    base_name = cfg['board_name'] + '_rev_' + cfg['board']['meta']['board_revision'] + '_'
-    filename = base_name + 'Excellon_drills.txt'
-    excellon = open(os.path.join(cfg['base_dir'], 
-                                 cfg['pcbmode']['locations']['build'], 
-                                 'production', "%s" % filename), 
-                    'w')
+    pcbmode_version = cfg['pcbmode']['version']
+    board_name = cfg['board_name']
+    board_revision = cfg['board']['meta'].get('board_revision') or 'A'    
+
+    base_dir = os.path.join(cfg['base_dir'], 
+                            cfg['pcbmode']['locations']['build'], 
+                            'production')
+    base_name = "%s_rev_%s" % (board_name, board_revision)
+
+
+    filenames = []
+
+    filename_info = cfg['pcbmode']['manufacturers'][manufacturer]['filenames']['drills']
+    add = '_%s.%s' % ('drills', filename_info['plated'].get('ext') or 'txt')
+    filename = os.path.join(base_dir, base_name + add)
+    print '%s' % base_name + add,
+    filenames.append(filename)
+
+    excellon = open(filename, 'w')
 
     excellon.write('M48\n') # Beginning of a part program header
     excellon.write('METRIC,TZ\n') # Metric, trailing zeros
     excellon.write('M30\n') # End of Program, rewind
 
     excellon.close()
+
+    return filenames
 
 
 
-def gerberise(cfg):
+def gerberise(cfg, manufacturer='default'):
     """
     Generate Gerbers for one or more layers
     """
     board_name = cfg['board_name']
     board_revision = cfg['board']['meta'].get('board_revision') or 'A'
 
-    filename_base = board_name + '_rev_' + board_revision + '_'
 
+    filenames = []
+
+    base_dir = os.path.join(cfg['base_dir'], 
+                            cfg['pcbmode']['locations']['build'], 
+                            'production')
+    base_name = "%s_rev_%s" % (board_name, board_revision)
+
+
+    filename_info = cfg['pcbmode']['manufacturers'][manufacturer]['filenames']['gerbers']
+
+    # outline gerber
+    add = '_%s.%s' % ('outline', 
+                      filename_info['other']['outline'].get('ext'))
+    filename = os.path.join(base_dir, base_name + add)
+    print base_name + add,
+    filenames.append(filename)
     gerberise_layers(svg_in, None, ['outline'], 
-                     os.path.join(cfg['base_dir'], cfg['pcbmode']['locations']['build'], 
-                                  'production', filename_base + 'outline.ger'),
-                     apertures, 30)
+                     filename, apertures, 30)
 
-    gerberise_layers(svg_in, None, ['documentation','measurements'], 
-                     os.path.join(cfg['base_dir'], cfg['pcbmode']['locations']['build'], 
-                                  'production', filename_base + 'documentation.ger'),
-                     apertures)
+    # documentation gerber
+    add = '_%s.%s' % ('documentation', 
+                      filename_info['other']['documentation'].get('ext'))
+    filename = os.path.join(base_dir, base_name + add) 
+    print base_name + add,
+    filenames.append(filename)
+    gerberise_layers(svg_in, None, ['documentation','measurements'],
+                     filename, apertures)
  
+    
     for pcb_layer in utils.get_surface_layers(cfg):
+   
+        add = '_%s_%s.%s' % (pcb_layer, 'copper', 
+                          filename_info[pcb_layer]['copper'].get('ext'))
+        filename = os.path.join(base_dir, base_name + add)
+        print base_name + add,
+        filenames.append(filename)
         gerberise_layers(svg_in, pcb_layer, ['copper'],
-                         os.path.join(cfg['base_dir'], cfg['pcbmode']['locations']['build'], 
-                                      'production', 
-                                      filename_base + pcb_layer + '_copper.ger'),
-                         apertures)
-        gerberise_layers(svg_in, pcb_layer, ['soldermask'], 
-                         os.path.join(cfg['base_dir'], cfg['pcbmode']['locations']['build'], 
-                                      'production', 
-                                      filename_base + pcb_layer + '_soldermask.ger'),
-                         apertures)
+                         filename, apertures)
+
+        add = '_%s_%s.%s' % (pcb_layer, 'soldermask', 
+                          filename_info[pcb_layer]['soldermask'].get('ext'))
+        filename = os.path.join(base_dir, base_name + add) 
+        print base_name + add,
+        filenames.append(filename)
+        gerberise_layers(svg_in, pcb_layer, ['soldermask'],
+                         filename, apertures)
+
+        add = '_%s_%s.%s' % (pcb_layer, 'silkscreen', 
+                          filename_info[pcb_layer]['silkscreen'].get('ext'))
+        filename = os.path.join(base_dir, base_name + add) 
+        print base_name + add,
+        filenames.append(filename)
         gerberise_layers(svg_in, pcb_layer, ['silkscreen'], 
-                         os.path.join(cfg['base_dir'], cfg['pcbmode']['locations']['build'], 
-                                      'production', 
-                                      filename_base + pcb_layer + '_silkscreen.ger'),
-                         apertures)
+                         filename, apertures)
+
 
+    return filenames
 
 import json
 import os
+import zipfile
 import subprocess as subp # for shell commands
 
 # pcbmode modules
     """
 
     return dict((n, d1.get(n, 0)+d2.get(n, 0)) for n in set(d1)|set(d2) )
+
+
+
+
+
+def zip_files(zip_path, zip_name, file_list):
+    """
+    Creates a zip archive
+    """
+
+    z = zipfile.ZipFile(os.path.join(zip_path, zip_name), 'w')
+    #z.write('shimmy_rev_A_drills.drl')
+    for f in file_list:
+        z.write(f)
+
+    return
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.