Example #1
0
 def __call_getter_function__(self, obj):
     f = self.__get_getter_function__(obj)
     value = f(ElementList())
     if value is None:
         raise IpkissException("Function '%s' returned None : this is invalid." %(f.__name__))
     new_value = self.__cache_property_value_on_object__(obj, value)
     return new_value        
Example #2
0
 def __parse_record__(self):
     try:
         b1 = self.__istream__.read(2)
         datalen = int (b2a_hex(b1), 16) - 4
         b2 = self.__istream__.read(2)
         rtype = int (b2a_hex(b2), 16)
     except Exception, e:
         msg = "Could not read record : %s" %str(e)
         from ipkiss.exceptions.exc import IpkissException
         raise IpkissException(msg)
Example #3
0
 def __init__(self, layer_map, **kwargs):
     super(GdsiiLayerInputMap, self).__init__(layer_map=layer_map, **kwargs)
     # check if the input map doesn't contain any duplicates on the "source side" (duplicates may exist on the target size)
     ln = []
     for L in self.layer_map.keys():
         ln.append((L.number, L.datatype))
     if len(ln) != len(list(set(ln))):
         raise IpkissException(
             "layer_map may not contain duplicate layer number on the source-side."
         )
Example #4
0
 def __layers_to_material(self, layers):
     """ For a given combination of layers (list or tuple), return the corresponding material"""
     layers = LayerList(layers)
     try:
         mat = self.layer_to_material_map[layers]
     except KeyError:
         from ipkiss.exceptions.exc import IpkissException
         raise IpkissException(
             "The following superposition of layers does not have a corresponding material : %s"
             % layers)
     return mat
Example #5
0
 def __processes_to_material(self, processes):
     """ For a given combination of processes (list or tuple), return the corresponding material"""
     p = tuple(processes)
     try:
         mat = self.process_to_material_map[p]
     except KeyError:
         from ipkiss.exceptions.exc import IpkissException
         raise IpkissException(
             "The following superposition of prcoesses does not have a corresponding material : %s"
             % p)
     return mat
Example #6
0
 def read(self):
     if os.path.exists(self.filename):
         F = open(self.filename,"rb")
         input = InputGdsii(F)
         input.layer_map = self.layermap
         input.prefix = self.name + "_"
         L = input.read()
         F.close()
     else:
         raise IpkissException("ImportLayout::read : Could not find " + self.filename + " for import.")
     return L
Example #7
0
    def __parse_box_element__(self):
        # read parameters
        layer_number = 0
        boxtype = 0
        coords = []
        while 1:
            r = self.__parse_record__()
            t = r.rtype  #type
            l = r.length  #datalength

            if t == gds_records.Layer:
                layer_number = self.__parse_int2__()
            elif t == gds_records.BoxType:
                boxtype = self.__parse_int2__()
            elif t == gds_records.XY:
                nxy = l / 8
                coords = self.__parse_shape__(nxy)
            elif t == gds_records.EndEl:
                break
            elif t == gds_records.ElFlags:
                LOG.warning(
                    "ELFLAGS in BOX is not supported. This will be ignored")
                self.__istream__.read(l)
            elif t == gds_records.Plex:
                LOG.warning(
                    "PLEX in BOX is not supported. This will be ignored")
                self.__istream__.read(l)
            else:
                LOG.error("Unsupported type in BOX: %s" % hex(t))
                raise SystemExit
        c = coords[0]
        xmin = c[0]
        ymin = c[1]
        xmax = c[0]
        ymax = c[1]
        for c in coords:
            xmin = min(xmin, c[0])
            ymin = min(ymin, c[1])
            xmax = max(xmax, c[0])
            ymax = max(ymax, c[1])
        layer = GdsiiLayer(number=layer_number, datatype=0)
        L = self.map_layer(layer)
        if L is None:
            err_msg = "Could not map GDS layer %s in InputGdsii." % str(layer)
            if self.__stop_on_unknown_gds_layer__:
                raise IpkissException(err_msg)
            else:
                return LOG.error(err_msg)
        else:
            return Box(L, (0.5 * (xmin + xmax), 0.5 * (ymin + ymax)),
                       (xmax - xmin, ymax - ymin))
Example #8
0
 def get_header_only(self):
     from ipkiss.io.input_gdsii import InputGdsiiHeader
     if os.path.exists(self.filename):
         if self.gzipped:
             from gzip import GzipFile
             F = GzipFile(self.filename, mode = "rb")
         else:
             F = open(self.filename,"rb")
         input = InputGdsiiHeader(F)
         input.layer_map = self.layer_map
         input.prefix = self.prefix
         L = input.read()
         F.close()
     else:
         raise IpkissException("ImportStructure:: Could not find " + self.filename + " for import.") #FIXME - should be PicazzoException
     return L
Example #9
0
 def __parse_path_element__(self):
     # read parameters
     layer_number = 0
     datatype = 0
     pathtype = constants.PATH_TYPE_NORMAL
     width = 0
     coords = []
     while 1:
         r = self.__parse_record__()
         t = r.rtype  #type
         l = r.length  #datalength
         if t == gds_records.Layer:
             layer_number = self.__parse_int2__()
         elif t == gds_records.DataType:
             datatype = self.__parse_int2__()
         elif t == gds_records.PathType:
             pathtype = self.__parse_int2__()
         elif t == gds_records.Width:
             width = self.__parse_length__()
         elif t == gds_records.XY:
             nxy = l / 8
             coords = self.__parse_shape__(nxy)
         elif t == gds_records.EndEl:
             self.__istream__.read(l)
             break
         elif t == gds_records.ElFlags:
             LOG.warning(
                 "ELFLAGS in PATH is not supported. This will be ignored.")
             self.__istream__.read(l)
         elif t == gds_records.Plex:
             LOG.warning(
                 "PLEX in PATH is not supported. This will be ignored.")
             self.__istream__.read(l)
         else:
             LOG.error("Unsupported type in PATH: %s" % hex(t))
             raise SystemExit
     layer = GdsiiLayer(number=layer_number, datatype=datatype)
     L = self.map_layer(layer)
     if L is None:
         err_msg = "Could not map GDS layer %s in InputGdsii." % str(layer)
         if self.__stop_on_unknown_gds_layer__:
             raise IpkissException(err_msg)
         else:
             return LOG.error(err_msg)
     else:
         return Path(L, coords, width, pathtype)
Example #10
0
 def get_file_library(self):
     LOG.info("Importing %s " %  self.filename )
     filesize = os.path.getsize(self.filename)
     LOG.info("size: %d KB"%(filesize/1024))
     if os.path.exists(self.filename):
         if self.gzipped:
             from gzip import GzipFile
             F = GzipFile(self.filename, mode = "rb")
         else:
             F = open(self.filename,"rb")
         input = self.input_handler(F, stop_on_unknown_gds_layer=False, log_bufsize = filesize)
         input.layer_map = self.layer_map
         input.prefix = self.prefix
         L = input.read()
         F.close()
     else:
         raise IpkissException("ImportStructure:: Could not find " + self.filename + " for import.") #FIXME - should be PicazzoException
     return L
Example #11
0
 def add_element(self, e):
     if not isinstance(e, __ShapeElement__):
         raise IpkissException(
             "Wrong parameter. Expected object of type __ShapeElement__")
     if (isinstance(e, Path)):
         grid = TECH.METRICS.GRID
         filter = PathCutFilter(
             max_path_length=int(constants.GDSII_MAX_COORDINATES / 2),
             grids_per_unit=int(1.0 / grid),
             overlap=1)
         filter += PathToBoundaryFilter()
         elems = filter(e)
         for e2 in elems:
             if not isinstance(e2, __LayerElement__):
                 continue
             self.add_element(e2)
     else:
         shape = Shape(e.shape).transform(e.transformation)
         self.add_shape(shape)
Example #12
0
 def __parse_boundary_element__(self):
     # read parameters
     layer_number = 0
     datatype = 0
     coords = []
     while 1:
         r = self.__parse_record__()
         t = r.rtype  #type
         l = r.length  #datalength
         if t == gds_records.Layer:
             layer_number = self.__parse_int2__()
         elif t == gds_records.DataType:
             datatype = self.__parse_int2__()
         elif t == gds_records.XY:
             nxy = l / 8
             coords = self.__parse_shape__(nxy)
             coords.close()
         elif t == gds_records.EndEl:
             break
         elif t == gds_records.ElFlags:
             LOG.warning(
                 "ELFLAGS in BOUNDARY is not supported (structure %s). This will be ignored."
                 % self.__current_structure__.name)
             self.__istream__.read(l)
         elif t == gds_records.Plex:
             LOG.warning(
                 "PLEX in BOUNDARY is not supported (structure %s). This will be ignored."
                 % self.__current_structure__.name)
             self.__istream__.read(l)
         else:
             LOG.error("Unsupported type in BOUNDARY: %s" % hex(t))
             raise SystemExit
     layer = GdsiiLayer(number=layer_number, datatype=datatype)
     L = self.map_layer(layer)
     if L is None:
         err_msg = "Could not map GDS layer %d:%d in InputGdsii." % (
             layer.number, layer.datatype)
         if self.__stop_on_unknown_gds_layer__:
             raise IpkissException(err_msg)
         else:
             return LOG.warning(err_msg)
     else:
         return Boundary(L, coords)
Example #13
0
 def __parse_label_element__(self):
     # read parameters
     transform = NoDistortTransform()
     layer_number = 0
     texttype = 0
     font = fonts.TEXT_FONT_DEFAULT
     ver_alignment = constants.TEXT_ALIGN_TOP
     hor_alignment = constants.TEXT_ALIGN_LEFT
     text = ""
     width = 1.0
     coords = []
     height = 1.0
     while 1:
         r = self.__parse_record__()
         t = r.rtype #type
         l = r.length #datatype
         if t == gds_records.Layer:
             layer_number = self.__parse_int2__()
         elif t == gds_records.TextType:
             datatype = self.__parse_int2__()
         elif t == gds_records.PathType:
             pathtype = self.__parse_int2__()
         elif t == gds_records.Presentation:
             presentation = self.__parse_int2__()
             hor_alignment = presentation % 4
             ver_alignment = (presentation - hor_alignment) % 16 / 4
             font = (presentation - hor_alignment - 4 * ver_alignment) % 64 / 16
         elif t == gds_records.Width:
             width = self.__parse_length__()
         elif t == gds_records.XY:
             nxy = l/8
             if not nxy == 1:
                 LOG.error("TEXT (Label) only supports a single coordinate. ")
                 raise SystemExit
             coord = self.__parse_coordinate__()
         elif t == gds_records.String:
             text = self.__parse_string__(l)
         elif t == gds_records.EndEl:
             break
         elif t == gds_records.ElFlags:
             LOG.warning("ELFLAGS in TEXT (Label) is not supported. This will be ignored.")
             self.__istream__.read(l)
         elif t == gds_records.Plex:
             LOG.warning("PLEX in TEXT (Label) is not supported. This will be ignored.")
             self.__istream__.read(l)
         elif t == gds_records.STrans:
             self.__parse_transformation__(transform)
         elif t == gds_records.Mag:
             self.__parse_magnification__(transform)
         elif t == gds_records.Angle:
             self.__parse_rotation__(transform)
         else:
             LOG.error("Unsupported type in TEXT (label): %s" % hex(t))
             raise SystemExit
     if layer_number != None:    
         layer = GdsiiLayer(number = layer_number, datatype = 0)
         L = self.map_layer(layer)
         if L is None:
             err_msg = "Could not map GDS layer %s in InputGdsii." %str(layer)
             if self.__stop_on_unknown_gds_layer__:
                 raise IpkissException(err_msg)
             else:
                 return LOG.error(err_msg)
         else:
             return Label (L, text, coord, (hor_alignment, ver_alignment) , font, 1.0, transform)
     else:
         return None
Example #14
0
 def __getitem__(self, layer):
     for key, value in self.layer_map.items():
         if (layer == key):
             return value
     raise IpkissException(
         "GdsiiLayerOutputMap::No valid mapping found for layer %s" % layer)