Exemplo n.º 1
0
    def __call__(self, sm, cur, cmd, inputs):
        """ process GLAS command for fictitious, catalog glass or mirror"""

        if cmd == "GCAT":
            inputs = inputs.split()
            # Check catalog names, only add those we recognize
            for gc in inputs:
                try:
                    gfact.get_glass_catalog(gc)
                except glasserror.GlassCatalogNotFoundError:
                    continue
                else:
                    self.glass_catalogs.append(gc)
            # If no catalogs were recognized, use the default set
            if len(self.glass_catalogs) == 0:
                self.glass_catalogs = gfact._cat_names
            self.track_contents["GCAT"] = inputs
            return True
        elif cmd == "GLAS":
            g = sm.gaps[cur]
            inputs = inputs.split()
            name = inputs[0]
            medium = None
            if name == 'MIRROR':
                sm.ifcs[cur].interact_mode = 'reflect'
                g.medium = sm.gaps[cur - 1].medium
                self.track_contents[name] += 1
                return True
            elif name == '___BLANK':
                nd = float(inputs[3])
                vd = float(inputs[4])
                g.medium = Glass(nd=nd, vd=vd, mat=glass_encode(nd, vd))
                self.track_contents[name] += 1
                return True
            elif isanumber(name):
                # process as a 6 digit code, no decimal point
                m = self.find_6_digit_code(name)
                if m is not None:
                    g.medium = m
                    self.track_contents['6 digit code'] += 1
                    return True
            else:  # must be a glass type
                medium = self.find_glass(name, '')
                g.medium = medium
                return True

        else:
            return False
Exemplo n.º 2
0
    def find_substitute_glass(self, name):
        """Try to find a similar glass to ``name``."""

        # create a list of catalogs
        # the original lookup didn't find anything so
        # look in all of our catalogs
        cat_names = [gc.upper() for gc in self.glass_catalogs]
        for gc in gfact._cat_names_uc:
            if gc not in cat_names:
                cat_names.append(gc)

        # create a glass list for the given catalogs
        glist = []
        for glass_cat in cat_names:
            try:
                glass_cat = gfact.get_glass_catalog(glass_cat)
            except glasserror.GlassCatalogNotFoundError:
                pass
            else:
                glist += glass_cat.glass_list

        # Add legacy glasses
        glist += cat_glass.Robb1983Catalog().glass_list

        # decode the input name
        gn_decode = cat_glass.decode_glass_name(name)
        # build an uppercase version for comparisons
        gn_decode_uc = gn_decode[0][0].upper() + gn_decode[0][1]

        subs_glasses = []
        for g in glist:
            gn_decode, gn, gc = g
            if gn_decode_uc == gn_decode[0][0].upper() + gn_decode[0][1]:
                subs_glasses.append(g)

        if len(subs_glasses):
            possibilities = [gn for gn_decode, gn, gc in subs_glasses]
            matches = difflib.get_close_matches(name, possibilities)
            if len(matches) > 0:
                gn = matches[0]
                gc = next((g[2] for g in subs_glasses if g[1] == gn), None)
            else:
                gn_decode, gn, gc = subs_glasses[0]
            medium = create_glass(gn, gc)
            self.glasses_not_found[name] = gn, gc
            return medium
        else:
            return None
Exemplo n.º 3
0
    def find_substitute_glass(self, name):
        """Try to find a similar glass to ``name``."""

        # create a list of catalogs
        if len(self.glass_catalogs) > 0:
            cat_names = self.glass_catalogs
        else:
            cat_names = gfact._cat_names

        # create a glass list for the given catalogs
        glist = []
        for glass_cat in cat_names:
            try:
                glass_cat = gfact.get_glass_catalog(glass_cat)
            except glasserror.GlassCatalogNotFoundError:
                pass
            else:
                glist += glass_cat.glass_list

        # Add legacy glasses
        glist += cat_glass.Robb1983Catalog().glass_list

        # decode the input name
        gn_decode = cat_glass.decode_glass_name(name)
        # build an uppercase version for comparisons
        gn_decode_uc = gn_decode[0][0].upper() + gn_decode[0][1]

        subs_glasses = []
        for g in glist:
            gn_decode, gn, gc = g
            if gn_decode_uc == gn_decode[0][0].upper() + gn_decode[0][1]:
                subs_glasses.append(g)

        if len(subs_glasses):
            gn_decode, gn, gc = subs_glasses[0]
            medium = gfact.create_glass(gn, gc)
            eval_str = "create_glass('{:s}','{:s}')".format(gn, gc)
            self.glasses_not_found[name] = eval_str
            return medium
        else:
            return None