From 1d7738271a25a2bc504dd524b9208e63a842fc22 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Mon, 22 Oct 2018 12:31:15 -0700 Subject: [PATCH] Address comments. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- prjxray/roi.py | 77 ++++++++++++++++++++++++++-------------------- prjxray/util.py | 4 ++- utils/fasm2pips.py | 6 +++- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/prjxray/roi.py b/prjxray/roi.py index e195c60a..c99c9816 100644 --- a/prjxray/roi.py +++ b/prjxray/roi.py @@ -1,48 +1,59 @@ -import json - - class Roi(object): - def __init__(self, tilegrid_file, x1, x2, y1, y2): - self.tilegrid_file = tilegrid_file - self.tilegrid = None + """ Object that represents a Project X-ray ROI. + + Can be used to iterate over tiles and sites within an ROI. + + """ + def __init__(self, db, x1, x2, y1, y2): + self.grid = db.grid() self.x1 = x1 self.x2 = x2 self.y1 = y1 self.y2 = y2 - def tile_in_roi(self, tilej): - x = int(tilej['grid_x']) - y = int(tilej['grid_y']) + def tile_in_roi(self, grid_loc): + """ Returns true if grid_loc (GridLoc tuple) is within the ROI. """ + x = grid_loc.grid_x + y = grid_loc.grid_y return self.x1 <= x and x <= self.x2 and self.y1 <= y and y <= self.y2 - def read_tilegrid(self): - if not self.tilegrid: - with open(self.tilegrid_file) as f: - self.tilegrid = json.load(f) - def gen_tiles(self, tile_types=None): - ''' + ''' Yield tile names within ROI. + tile_types: list of tile types to keep, or None for all ''' - self.read_tilegrid() + for tile_name in self.grid.tiles(): + loc = self.grid.loc_of_tilename(tile_name) - for tile_name, tilej in self.tilegrid.items(): - if self.tile_in_roi(tilej) and (tile_types is None - or tilej['type'] in tile_types): - yield (tile_name, tilej) - - def gen_sites(self, site_types=None): - ''' - site_types: list of site types to keep, or None for all - ''' - - self.read_tilegrid() - - for tile_name, tilej in self.tilegrid.items(): - if not self.tile_in_roi(tilej): + if not self.tile_in_roi(loc): continue - for site_name, site_type in tilej['sites'].items(): - if site_types is None or site_type in site_types: - yield (tile_name, site_name, site_type) + gridinfo = self.grid.gridinfo_at_loc(loc) + + if tile_types is not None and gridinfo.tile_type not in tile_types: + continue + + yield tile_name + + def gen_sites(self, site_types=None): + ''' Yield (tile_name, site_name, site_type) within ROI. + + site_types: list of site types to keep, or None for all + + ''' + + for tile_name in self.grid.tiles(): + loc = self.grid.loc_of_tilename(tile_name) + + if not self.tile_in_roi(loc): + continue + + gridinfo = self.grid.gridinfo_at_loc(loc) + + + for site_name, site_type in gridinfo.sites.items(): + if site_types is not None and site_type not in site_types: + continue + + yield (tile_name, site_name, site_type) diff --git a/prjxray/util.py b/prjxray/util.py index ae600121..9e7518ef 100644 --- a/prjxray/util.py +++ b/prjxray/util.py @@ -1,6 +1,7 @@ import os import re from .roi import Roi +from .db import Database def get_db_root(): @@ -30,8 +31,9 @@ def slice_xy(): def get_roi(): (x1, x2), (y1, y2) = roi_xy() + db = Database(get_db_root()) return Roi( - tilegrid_file=os.path.join(get_db_root(), 'tilegrid.json'), + db=db, x1=x1, x2=x2, y1=y1, diff --git a/utils/fasm2pips.py b/utils/fasm2pips.py index 9044c640..4c4ddc0d 100644 --- a/utils/fasm2pips.py +++ b/utils/fasm2pips.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +""" Tool for generating Vivavo commands to highlight objects from a FASM file. + +Currently this tool only highlights pips directly referenced in the FASM file. +""" from __future__ import print_function import os.path @@ -9,7 +13,7 @@ from prjxray import db def main(): import argparse - parser = argparse.ArgumentParser(description='Convert FASM to pip list') + parser = argparse.ArgumentParser(description='Outputs a Vivavo highlight_objects command from a FASM file.') database_dir = os.getenv("XRAY_DATABASE_DIR") database = os.getenv("XRAY_DATABASE")