From 515c242cd2af60e3c3be89d634a6c13f94e28eb6 Mon Sep 17 00:00:00 2001 From: Oskar von Heideken Date: Wed, 27 Mar 2024 22:45:26 -0700 Subject: [PATCH 1/2] Changed import_stackup to not assume a default location, instead use a default argumetn --- src/gerber2ems/importer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gerber2ems/importer.py b/src/gerber2ems/importer.py index 9f4d054..5d03aaa 100644 --- a/src/gerber2ems/importer.py +++ b/src/gerber2ems/importer.py @@ -200,9 +200,8 @@ def get_vias() -> List[List[float]]: return vias -def import_stackup(): +def import_stackup(filename = "fab/stackup.json"): """Import stackup information from `fab/stackup.json` file and load it into config object.""" - filename = "fab/stackup.json" with open(filename, "r", encoding="utf-8") as file: try: stackup = json.load(file) From 8cf17f73b0ec23e624d7bc390d62180d7bcd08d9 Mon Sep 17 00:00:00 2001 From: Oskar von Heideken Date: Thu, 28 Mar 2024 21:32:25 -0700 Subject: [PATCH 2/2] Added some more overrideable paths in the importer.py file --- src/gerber2ems/importer.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/gerber2ems/importer.py b/src/gerber2ems/importer.py index 5d03aaa..3ec0e4f 100644 --- a/src/gerber2ems/importer.py +++ b/src/gerber2ems/importer.py @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) -def process_gbrs_to_pngs(): +def process_gbrs_to_pngs(fab_file_dir: str = "", geometry_dir: str = ""): """Process all gerber files to PNG's. Finds edge cuts gerber as well as copper gerbers in `fab` directory. @@ -34,8 +34,9 @@ def process_gbrs_to_pngs(): Output is saved to `ems/geometry` folder """ logger.info("Processing gerber files") - - files = os.listdir(os.path.join(os.getcwd(), "fab")) + if len(fab_file_dir) == 0: + fab_file_dir = os.path.join(os.getcwd(), "fab") + files = os.listdir(fab_file_dir) edge = next(filter(lambda name: "Edge_Cuts.gbr" in name, files), None) if edge is None: @@ -45,13 +46,14 @@ def process_gbrs_to_pngs(): layers = list(filter(lambda name: "_Cu.gbr" in name, files)) if len(layers) == 0: logger.warning("No copper gerbers found") - + if len(geometry_dir) == 0: + geometry_dir = os.path.join(os.getcwd(), GEOMETRY_DIR) for name in layers: output = name.split("-")[-1].split(".")[0] + ".png" gbr_to_png( - os.path.join(os.getcwd(), "fab", name), - os.path.join(os.getcwd(), "fab", edge), - os.path.join(os.getcwd(), GEOMETRY_DIR, output), + os.path.join(fab_file_dir, name), + os.path.join(fab_file_dir, edge), + os.path.join(geometry_dir, output), ) @@ -153,13 +155,16 @@ def image_to_board_coordinates(point: np.ndarray) -> np.ndarray: return (point * PIXEL_SIZE) - [BORDER_THICKNESS / 2, BORDER_THICKNESS / 2] -def get_vias() -> List[List[float]]: +def get_vias(file_dir: str = "") -> List[List[float]]: """Get via information from excellon file. Looks for excellon file in `fab` directory. Its filename should end with `-PTH.drl` It then processes it to find all vias. """ - files = os.listdir(os.path.join(os.getcwd(), "fab")) + if len(file_dir) == 0: + file_dir = os.path.join(os.getcwd(), "fab") + + files = os.listdir(file_dir) drill_filename = next(filter(lambda name: "-PTH.drl" in name, files), None) if drill_filename is None: logger.error("Couldn't find drill file") @@ -168,7 +173,7 @@ def get_vias() -> List[List[float]]: drills = {0: 0.0} # Drills are numbered from 1. 0 is added as a "no drill" option current_drill = 0 vias: List[List[float]] = [] - with open(os.path.join(os.getcwd(), "fab", drill_filename), "r", encoding="utf-8") as drill_file: + with open(os.path.join(file_dir, drill_filename), "r", encoding="utf-8") as drill_file: for line in drill_file.readlines(): # Regex for finding drill sizes (in mm) match = re.fullmatch("T([0-9]+)C([0-9]+.[0-9]+)\\n", line) @@ -202,6 +207,7 @@ def get_vias() -> List[List[float]]: def import_stackup(filename = "fab/stackup.json"): """Import stackup information from `fab/stackup.json` file and load it into config object.""" + with open(filename, "r", encoding="utf-8") as file: try: stackup = json.load(file)