summaryrefslogtreecommitdiff
path: root/cad/src/files/mmp/mmp_dispnames.py
blob: 5429a8979828d1b49fd3d8f94aa9cbbdf3c686ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright 2008-2009 Nanorex, Inc. See LICENSE file for details.
"""
mmp_dispnames.py

@author: Bruce
@version: $Id$
@copyright: 2008-2009 Nanorex, Inc.  See LICENSE file for details.

History:

bruce 090116 split this out of constants.py
"""

from utilities.GlobalPreferences import debug_pref_write_new_display_names
from utilities.GlobalPreferences import debug_pref_read_new_display_names

### TODO: refile these global variables:
from utilities.constants import new_dispNames, dispNames, remap_atom_dispdefs

from utilities.constants import diDEFAULT, diTUBES 
    # our use of diTUBES under that name is a KLUGE

def get_dispName_for_writemmp(display): #bruce 080324, revised 080328
    """
    Turn a display-style code integer (e.g. diDEFAULT; as stored in
    Atom.display or Chunk.display) into a display-style code string 
    as used in the current writing format for mmp files.
    """
    if debug_pref_write_new_display_names():
        return new_dispNames[display]
    return dispNames[display]

def interpret_dispName(dispname, defaultValue = diDEFAULT, atom = True): 
    """
    Turn a display-style code string (a short string constant used in mmp files
    for encoding atom and chunk display styles) into the corresponding
    display-style code integer (its index in dispNames, as extended at runtime).

    If dispname is not a valid display-style code string, return defaultValue,
    which is diDEFAULT by default.

    If atom is true (the default), only consider "atom display styles" to be
    valid; otherwise, also permit "chunk display styles".
    """
    #bruce 080324
    def _return(res):
        "(how to return res from interpret_dispName)"
        if res > diTUBES and atom and remap_atom_dispdefs.has_key(res):
            # note: the initial res > diTUBES is an optimization kluge
            return defaultValue
        return res

    try:
        res = dispNames.index(dispname)
    except ValueError:
        # not found, in first array (the one with old names, 
        # i.e. the one which gets extended)
        pass
    else:
        return _return(res)

    if debug_pref_read_new_display_names():
        try:
            res = new_dispNames.index(dispname)
        except ValueError:
            # not found, in 2nd array (the one with new names, 
            # which are aliases for old ones)
            pass
        else:
            return _return(res)

    return defaultValue # from interpret_dispName

# end