# Path: nord/utils.py
# def setv(g2param, val):
#   '''setv(g2param, val) - set all variations to val.'''
#   g2param.variations = [ val ] * 9
# 
# def getv(nmparam, variation=0):
#   '''getv(nmparam) - get variations[variation].'''
#   return nmparam.variations[variation]
# 
# Path: nord/g2/colors.py

# 
# Path: nord/nm1/colors.py

# 
# Path: nord/units.py
# def nm2g2val(nm1midival, nm1vals, g2vals):
#   nm1val = nm1vals[nm1midival]
#   g2min = 1000000 # nothing here will never be that big
#   g2midival = 0
#   for midival in xrange(128):
#     g2val = g2vals[midival]
#     if abs(g2val-nm1val) < g2min:
#       g2min = abs(g2val-nm1val)
#       g2midival = midival
#   return g2midival
# 
# Path: nord/utils.py
# def toascii(s):
#   # conversion strings for 192-255
#   s161 = '!cL#Y|S"Ca<^-R-o+23\'uP.10>%%%?' \
#          'AAAAAAACEEEEIIIIDNOOOOOOXOUUUUYpBaaaaaaaceeeeeiiiienooooo/ouuuuypy'
#   def conv(c):
#     o = ord(c)
#     if o < 128:
#       return c
#     elif o < 161:
#       return chr(c-64)
#     else:
#       return s161[o-161]
#     return ''
#   return ''.join([ conv(c) for c in s ])
# 
# Path: nord/convert/table.py



from nord.utils import setv, getv
from nord.g2.colors import g2cablecolors
from nord.nm1.colors import nm1conncolors
from nord.units import nm2g2val
from nord.utils import toascii
from nord.convert.table import kbttable
    create a convert object from a nm1 module in nmarea to g2area.
    '''
    self.nmarea = nmarea
    self.g2area = g2area
    nmm = self.nmmodule = nmmodule
    nmm.conv = self # to get back here when needed (cables)
    self.options = options
    # use for cabling
    for output in nmmodule.outputs:
      output.conv = self 
    for input in nmmodule.inputs:
      input.conv = self 
    self.g2modules = []
    self.params = []
    self.outputs = []
    self.inputs = []

    # create main module and setup size requirements
    g2m = self.g2module = g2area.add_module(self.maing2module)
    g2m.name = toascii(nmm.name)
    self.horiz = g2m.horiz = nmm.horiz
    self.height = g2m.type.height

    # setup parameters from parammap static member of convert module class
    self.params = [ None ] * len(self.parammap)
    for i, param in enumerate(self.parammap):
      if type(param) == type(''):
        setv(getattr(g2m.params, param), getv(getattr(nmm.params, param)))
        self.params[i] = getattr(g2m.params, param)
      elif type(param) == type([]):

# Path: nord/utils.py
# def setv(g2param, val):
#   '''setv(g2param, val) - set all variations to val.'''
#   g2param.variations = [ val ] * 9
# 
# def getv(nmparam, variation=0):
#   '''getv(nmparam) - get variations[variation].'''
#   return nmparam.variations[variation]
# 
# Path: nord/g2/colors.py

# 
# Path: nord/nm1/colors.py

# 
# Path: nord/units.py
# def nm2g2val(nm1midival, nm1vals, g2vals):
#   nm1val = nm1vals[nm1midival]
#   g2min = 1000000 # nothing here will never be that big
#   g2midival = 0
#   for midival in xrange(128):
#     g2val = g2vals[midival]
#     if abs(g2val-nm1val) < g2min:
#       g2min = abs(g2val-nm1val)
#       g2midival = midival
#   return g2midival
# 
# Path: nord/utils.py
# def toascii(s):
#   # conversion strings for 192-255
#   s161 = '!cL#Y|S"Ca<^-R-o+23\'uP.10>%%%?' \
#          'AAAAAAACEEEEIIIIDNOOOOOOXOUUUUYpBaaaaaaaceeeeeiiiienooooo/ouuuuypy'
#   def conv(c):
#     o = ord(c)
#     if o < 128:
#       return c
#     elif o < 161:
#       return chr(c-64)
#     else:
#       return s161[o-161]
#     return ''
#   return ''.join([ conv(c) for c in s ])
# 
# Path: nord/convert/table.py



# Path: nord/convert/convert.py
from nord.utils import setv, getv
from nord.g2.colors import g2cablecolors
from nord.nm1.colors import nm1conncolors
from nord.units import nm2g2val
from nord.utils import toascii
from nord.convert.table import kbttable

    create a convert object from a nm1 module in nmarea to g2area.
    '''
    self.nmarea = nmarea
    self.g2area = g2area
    nmm = self.nmmodule = nmmodule
    nmm.conv = self # to get back here when needed (cables)
    self.options = options
    # use for cabling
    for output in nmmodule.outputs:
      output.conv = self 
    for input in nmmodule.inputs:
      input.conv = self 
    self.g2modules = []
    self.params = []
    self.outputs = []
    self.inputs = []

    # create main module and setup size requirements
    g2m = self.g2module = g2area.add_module(self.maing2module)
    g2m.name = toascii(nmm.name)
    self.horiz = g2m.horiz = nmm.horiz
    self.height = g2m.type.height

    # setup parameters from parammap static member of convert module class
    self.params = [ None ] * len(self.parammap)
    for i, param in enumerate(self.parammap):
      if type(param) == type(''):
        setv(getattr(g2m.params, param), getv(getattr(nmm.params, param)))
        self.params[i] = getattr(g2m.params, param)
      elif type(param) == type([]):

        setv(getattr(g2m.params, param[0]), getv(getattr(nmm.params, param[1])))