objdictgen/nodemanager.py
author frdupin
Tue, 30 Jan 2007 11:18:20 +0100
changeset 86 683702a46416
parent 68 234dad27b398
child 171 db7a030babb2
permissions -rwxr-xr-x
big endian bogue : nodeIdServer in now in 32 bits
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
#This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
#See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
#modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
#Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
#You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
from gnosis.xml.pickle import *
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
from gnosis.xml.pickle.util import setParanoia
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
setParanoia(0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
from node import *
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
import xml_in, gen_cfile
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
from types import *
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
import os, re
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
UndoBufferLength = 20
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
type_model = re.compile('([\_A-Z]*)([0-9]*)')
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
range_model = re.compile('([\_A-Z]*)([0-9]*)\[([\-0-9]*)-([\-0-9]*)\]')
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
name_model = re.compile('(.*)\[(.*)\]')
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
def IsOfType(object, typedef):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
    return type(object) == typedef
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
#                           Formating Name of an Entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
Format the text given with the index and subindex defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
def StringFormat(text, idx, sub):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
    result = name_model.match(text)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
    if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
        format = result.groups()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
        return format[0]%eval(format[1])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
        return text
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
#                         Search in a Mapping Dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
Return the index of the informations in the Object Dictionary in case of identical
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
indexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
def FindIndex(index, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
    if index in mappingdictionary:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
        return index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
        listpluri = [idx for idx in mappingdictionary.keys() if mappingdictionary[idx]["struct"] & OD_IdenticalIndexes]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
        listpluri.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
        for idx in listpluri:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
            nb_max = mappingdictionary[idx]["nbmax"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
            incr = mappingdictionary[idx]["incr"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
            if idx < index < idx + incr * nb_max and (index - idx)%incr == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
                return idx
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
Return the index of the typename given by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
def FindTypeIndex(typename, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
    testdic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
    for index, values in mappingdictionary.iteritems():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
        if index < 0x1000:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
            testdic[values["name"]] = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
    if typename in testdic:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
        return testdic[typename]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
Return the name of the type by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
def FindTypeName(typeindex, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
    if typeindex < 0x1000 and typeindex in mappingdictionary:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
        return mappingdictionary[typeindex]["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
Return the default value of the type by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
def FindTypeDefaultValue(typeindex, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
    if typeindex < 0x1000 and typeindex in mappingdictionary:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
        return mappingdictionary[typeindex]["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
Return the list of types defined in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
def FindTypeList(mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
    list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
    for index in mappingdictionary.keys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
        if index < 0x1000:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
            list.append((index, mappingdictionary[index]["name"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
    return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
Return the name of an entry by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
def FindEntryName(index, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
    base_index = FindIndex(index, mappingdictionary)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
    if base_index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
        infos = mappingdictionary[base_index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
        if infos["struct"] & OD_IdenticalIndexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
            return StringFormat(infos["name"], (index - base_index) / infos["incr"] + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
            return infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
Return the informations of one entry by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
def FindEntryInfos(index, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
    base_index = FindIndex(index, mappingdictionary)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
    if base_index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
        copy = mappingdictionary[base_index].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
        if copy["struct"] & OD_IdenticalIndexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
            copy["name"] = StringFormat(copy["name"], (index - base_index) / copy["incr"] + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
        copy.pop("values")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
        return copy
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
Return the informations of one subentry of an entry by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
def FindSubentryInfos(index, subIndex, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
    base_index = FindIndex(index, mappingdictionary)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
    if base_index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
        struct = mappingdictionary[base_index]["struct"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
        if struct & OD_Subindex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
            if struct & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
                if struct & OD_IdenticalIndexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
                    incr = mappingdictionary[base_index]["incr"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
                    incr = 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
                if subIndex == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
                    return mappingdictionary[base_index]["values"][0].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
                elif 0 < subIndex <= mappingdictionary[base_index]["values"][1]["nbmax"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
                    copy = mappingdictionary[base_index]["values"][1].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
                    copy["name"] = StringFormat(copy["name"], (index - base_index) / incr + 1, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
                    return copy
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
            elif struct & OD_MultipleSubindexes and 0 <= subIndex < len(mappingdictionary[base_index]["values"]):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
                return mappingdictionary[base_index]["values"][subIndex].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
            elif subIndex == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
                return mappingdictionary[base_index]["values"][0].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
Return the list of variables that can be mapped defined in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
def FindMapVariableList(mappingdictionary, Manager):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
    list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
    for index in mappingdictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
        if Manager.IsCurrentEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
            for subIndex, values in enumerate(mappingdictionary[index]["values"]):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
                if mappingdictionary[index]["values"][subIndex]["pdo"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
                    infos = Manager.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
                    if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
                        values = Manager.GetCurrentEntry(index)
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   181
                        for i in xrange(len(values) - 1):
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   182
                            list.append((index, i + 1, infos["size"], StringFormat(mappingdictionary[index]["values"][subIndex]["name"],1,i+1)))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
                        list.append((index, subIndex, infos["size"], mappingdictionary[index]["values"][subIndex]["name"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
    return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
Return the list of mandatory indexes defined in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
def FindMandatoryIndexes(mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
    list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
    for index in mappingdictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
        if index >= 0x1000 and mappingdictionary[index]["need"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
            list.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
    return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
Class implementing a buffer of changes made on the current editing Object Dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
class UndoBuffer:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
    Constructor initialising buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
    def __init__(self, currentstate, issaved = False):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
        self.Buffer = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
        self.CurrentIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
        self.MinIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
        self.MaxIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
        # if current state is defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
        if currentstate:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
            self.CurrentIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
            self.MinIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
            self.MaxIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
        # Initialising buffer with currentstate at the first place
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
        for i in xrange(UndoBufferLength):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
            if i == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
                self.Buffer.append(currentstate)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
                self.Buffer.append(None)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
        # Initialising index of state saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
        if issaved:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
            self.LastSave = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
            self.LastSave = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
    Add a new state in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
    def Buffering(self, currentstate):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
        self.CurrentIndex = (self.CurrentIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
        self.Buffer[self.CurrentIndex] = currentstate
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
        # Actualising buffer limits
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
        self.MaxIndex = self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
        if self.MinIndex == self.CurrentIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
            # If the removed state was the state saved, there is no state saved in the buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
            if self.LastSave == self.MinIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
                self.LastSave = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
            self.MinIndex = (self.MinIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
        self.MinIndex = max(self.MinIndex, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
    Return current state of buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
    def Current(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
        return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
    Change current state to previous in buffer and return new current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
    def Previous(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
        if self.CurrentIndex != self.MinIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
            self.CurrentIndex = (self.CurrentIndex - 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
            return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
    Change current state to next in buffer and return new current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
    def Next(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
        if self.CurrentIndex != self.MaxIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
            self.CurrentIndex = (self.CurrentIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
            return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
    Return True if current state is the first in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
    def IsFirst(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
        return self.CurrentIndex == self.MinIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
    Return True if current state is the last in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
    def IsLast(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
        return self.CurrentIndex == self.MaxIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
    Note that current state is saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
    def CurrentSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
        self.LastSave = self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
    Return True if current state is saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
    def IsCurrentSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
        return self.LastSave == self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
Class which control the operations made on the node and answer to view requests
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
class NodeManager:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
    Constructor
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
    def __init__(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
        self.LastNewIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
        self.FilePaths = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
        self.FileNames = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
        self.NodeIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
        self.CurrentNode = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
        self.UndoBuffers = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
#                         Type and Map Variable Lists
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
    Generate the list of types defined for the current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
    def GenerateTypeList(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
        self.TypeList = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
        self.TypeTranslation = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
        list = self.GetTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
        sep = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
        for index, name in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
            self.TypeList += "%s%s"%(sep,name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
            self.TypeTranslation[name] = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
            sep = ","
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
    Generate the list of variables that can be mapped for the current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
    def GenerateMapList(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
        self.MapList = "None"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
        self.NameTranslation = {"None" : "00000000"}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
        self.MapTranslation = {"00000000" : "None"}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
        list = self.GetMapVariableList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
        for index, subIndex, size, name in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
            self.MapList += ",%s"%name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
            map = "%04X%02X%02X"%(index,subIndex,size)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
            self.NameTranslation[name] = map
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
            self.MapTranslation[map] = name
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
    Return the list of types defined for the current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
    def GetCurrentTypeList(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
        return self.TypeList
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
    Return the list of variables that can be mapped for the current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
    def GetCurrentMapList(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
        return self.MapList
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
#                        Create Load and Save Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
    Create a new node and add a new buffer for storing it
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
    def CreateNewNode(self, name, id, type, profile, filepath, NMT, options):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
        # Create a new node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
        node = Node()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
        # Try to load profile given
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
        result = self.LoadProfile(profile, filepath, node)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
        if not IsOfType(result, StringType):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
            # if success, initialising node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
            self.CurrentNode = node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
            self.CurrentNode.SetNodeName(name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
            self.CurrentNode.SetNodeID(id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
            self.CurrentNode.SetNodeType(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
            AddIndexList = self.GetMandatoryIndexes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
            if NMT == "NodeGuarding":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
                AddIndexList.extend([0x100C, 0x100D])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
            elif NMT == "Heartbeat":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
                AddIndexList.append(0x1017)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
            for option in options:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
                if option == "DS302":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
                    # Charging DS-302 profile if choosen by user
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
                    if os.path.isfile("config/DS-302.prf"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
                        try:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
                            Mapping = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
                            AddMenuEntries = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
                            execfile("config/DS-302.prf")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
                            self.CurrentNode.SetDS302Profile(Mapping)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
                            self.CurrentNode.ExtendSpecificMenu(AddMenuEntries)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
                        except:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
                            return "Problem with DS-302! Syntax Error."
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
                        return "Couldn't find DS-302 in 'config' folder!"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
                elif option == "GenSYNC":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
                    AddIndexList.extend([0x1005, 0x1006])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
                elif option == "Emergency":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
                    AddIndexList.append(0x1014)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
                elif option == "SaveConfig":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
                    AddIndexList.extend([0x1010, 0x1011, 0x1020])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
                elif option == "StoreEDS":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
                    AddIndexList.extend([0x1021, 0x1022])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
            # Add a new buffer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
            self.AddNodeBuffer()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
            self.SetCurrentFilePath("")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
            # Add Mandatory indexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
            self.ManageEntriesOfCurrent(AddIndexList, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
            # Regenerate lists
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
            self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
            self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
            return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
            return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
    Load a profile in node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
    def LoadProfile(self, profile, filepath, node):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
        if profile != "None":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
            # Try to charge the profile given
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
            try:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
                execfile(filepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
                node.SetProfileName(profile)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
                node.SetProfile(Mapping)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
                node.SetSpecificMenu(AddMenuEntries)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
                return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
            except:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
                return "Bad OD Profile file!\nSyntax Error."
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
            # Default profile
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
            node.SetProfileName("None")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
            node.SetProfile({})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
            node.SetSpecificMenu([])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
            return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
    Open a file and store it in a new buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
    def OpenFileInCurrent(self, filepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
        # Open and load file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
        file = open(filepath, "r")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
        node = load(file)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
        file.close()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
        self.CurrentNode = node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
        # Add a new buffer and defining current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
        self.AddNodeBuffer(self.CurrentNode.Copy(), True)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
        self.SetCurrentFilePath(filepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
        # Regenerate lists
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
        self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   446
        self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
        return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
    Save current node in  a file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
    def SaveCurrentInFile(self, filepath = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
        # if no filepath given, verify if current node has a filepath defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
        if not filepath:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
            filepath = self.GetCurrentFilePath()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
            if filepath == "":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
                return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
        # Save node in file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
        file = open(filepath, "w")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
        dump(self.CurrentNode, file)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
        file.close()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
        self.SetCurrentFilePath(filepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
        # Update saved state in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
        self.UndoBuffers[self.NodeIndex].CurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
        return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
    Close current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
    def CloseCurrent(self, ignore = False):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
        # Verify if it's not forced that the current node is saved before closing it
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
        if self.UndoBuffers[self.NodeIndex].IsCurrentSaved() or ignore:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
            self.RemoveNodeBuffer(self.NodeIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
            return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
    Import a xml file and store it in a new buffer if no node edited
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
    def ImportCurrentFromFile(self, filepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
        # Generate node from definition in a xml file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
        node = xml_in.GenerateNode(filepath, self)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   483
        if node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
            self.CurrentNode = node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   485
            self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
            self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
            if len(self.UndoBuffers) == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
                self.AddNodeBuffer()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
                self.SetCurrentFilePath("")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   494
    Build the C definition of Object Dictionary for current node 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   495
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   496
    def ExportCurrentToFile(self, filepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   497
        return gen_cfile.GenerateFile(filepath, self)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   498
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   499
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   500
#                        Add Entries to Current Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   501
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
    Add the specified number of subentry for the given entry. Verify that total
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
    number of subentry (except 0) doesn't exceed nbmax defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
    def AddSubentriesToCurrent(self, index, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
        # Informations about entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
        length = self.CurrentNode.GetEntry(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
        infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   511
        subentry_infos = self.GetSubentryInfos(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   512
        # Get default value for subindex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   513
        if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   514
            default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
            default = self.GetTypeDefaultValue(subentry_infos["type"])   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
        # First case entry is record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
        if infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
            for i in xrange(1, min(number,subentry_infos["nbmax"]-length) + 1):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
                self.CurrentNode.AddEntry(index, length + i, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
        # Second case entry is array, only possible for manufacturer specific
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
        elif infos["struct"] & OD_MultipleSubindexes and 0x2000 <= index <= 0x5FFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
            values = {"name" : "Undefined", "type" : 5, "access" : "rw", "pdo" : True}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
            for i in xrange(1, min(number,0xFE-length) + 1):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
                self.CurrentNode.AddMappingEntry(index, length + i, values = values.copy())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   527
                self.CurrentNode.AddEntry(index, length + i, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   528
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   529
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   530
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   531
    Remove the specified number of subentry for the given entry. Verify that total
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
    number of subentry (except 0) isn't less than 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   533
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   534
    def RemoveSubentriesFromCurrent(self, index, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   535
        # Informations about entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   536
        infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   537
        length = self.CurrentNode.GetEntry(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
        # Entry is a record, or is an array of manufacturer specific
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   539
        if infos["struct"] & OD_IdenticalSubindexes or 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
            for i in xrange(min(number, length - 1)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
                self.RemoveCurrentVariable(index, length - i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   542
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
    Add a SDO Server to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   547
    def AddSDOServerToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   548
        # An SDO Server is already defined at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   549
        if self.CurrentNode.IsEntry(0x1200):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
            indexlist = [self.GetLineFromIndex(0x1201)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
            if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
                self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
        # Add an SDO Server at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
            self.ManageEntriesOfCurrent([0x1200], [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   558
    Add a SDO Server to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
    def AddSDOClientToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
        indexlist = [self.GetLineFromIndex(0x1280)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   564
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   566
    Add a Transmit PDO to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   567
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
    def AddPDOTransmitToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
        indexlist = [self.GetLineFromIndex(0x1800),self.GetLineFromIndex(0x1A00)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   570
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   571
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   572
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   573
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   574
    Add a Receive PDO to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   575
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   576
    def AddPDOReceiveToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   577
        indexlist = [self.GetLineFromIndex(0x1400),self.GetLineFromIndex(0x1600)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   578
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   579
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   580
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   581
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   582
    Add a list of entries defined in profile for menu item selected to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   583
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   584
    def AddSpecificEntryToCurrent(self, menuitem):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   585
        indexlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
        for menu, indexes in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
            if menuitem == menu:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
                for index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   589
                    indexlist.append(self.GetLineFromIndex(index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   590
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   591
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   592
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
    Search the first index available for a pluri entry from base_index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
    def GetLineFromIndex(self, base_index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
        found = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
        index = base_index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   599
        infos = self.GetEntryInfos(base_index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
        while index < base_index + infos["incr"]*infos["nbmax"] and not found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   601
            if not self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   602
                found = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   603
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   604
                index += infos["incr"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   605
        if found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
            return index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   607
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   608
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   609
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   610
    Add entries specified in addinglist and remove entries specified in removinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   611
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   612
    def ManageEntriesOfCurrent(self, addinglist, removinglist):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   613
        # Add all the entries in addinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   614
        for index in addinglist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   615
            infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   616
            if infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   617
                # First case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   618
                if infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   619
                    subentry_infos = self.GetSubentryInfos(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   620
                    if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   621
                        default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   622
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   623
                        default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   624
                    self.CurrentNode.AddEntry(index, 1, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
                # Second case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   626
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   627
                    i = 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   628
                    subentry_infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   629
                    while subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   630
                        if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   631
                            default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   632
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
                            default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   634
                        self.CurrentNode.AddEntry(index, i, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   635
                        i += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   636
                        subentry_infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   637
            # Third case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
                subentry_infos = self.GetSubentryInfos(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   640
                if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
                    default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   642
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   643
                    default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   644
                self.CurrentNode.AddEntry(index, 0, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   645
        # Remove all the entries in removinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   646
        for index in removinglist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
            self.RemoveCurrentVariable(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   651
    Remove an entry from current node. Analize the index to perform the correct
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   652
    method
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   653
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   654
    def RemoveCurrentVariable(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   655
        Mappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
        if index < 0x1000 and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
            type = self.CurrentNode.GetEntry(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   658
            for i in Mappings[-1]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   659
                for value in Mappings[-1][i]["values"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   660
                    if value["type"] == index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   661
                        value["type"] = type
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   662
            self.CurrentNode.RemoveMappingEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   663
            self.CurrentNode.RemoveEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   664
        elif index == 0x1200 and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
            self.CurrentNode.RemoveEntry(0x1200)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
        elif 0x1201 <= index <= 0x127F and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
            self.CurrentNode.RemoveLine(index, 0x127F)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
        elif 0x1280 <= index <= 0x12FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
            self.CurrentNode.RemoveLine(index, 0x12FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
        elif 0x1400 <= index <= 0x15FF or 0x1600 <= index <= 0x17FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   671
            if 0x1600 <= index <= 0x17FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   672
                index -= 0x200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   673
            self.CurrentNode.RemoveLine(index, 0x15FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   674
            self.CurrentNode.RemoveLine(index + 0x200, 0x17FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   675
        elif 0x1800 <= index <= 0x19FF or 0x1A00 <= index <= 0x1BFF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   676
            if 0x1A00 <= index <= 0x1BFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
                index -= 0x200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   678
            self.CurrentNode.RemoveLine(index, 0x19FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   679
            self.CurrentNode.RemoveLine(index + 0x200, 0x1BFF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   680
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   681
            found = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   682
            for menu,list in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   683
                for i in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   684
                    iinfos = self.GetEntryInfos(i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   685
                    indexes = [i + incr * iinfos["incr"] for incr in xrange(iinfos["nbmax"])] 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   686
                    if index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   687
                        found = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   688
                        diff = index - i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   689
                        for j in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   690
                            jinfos = self.GetEntryInfos(j)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   691
                            self.CurrentNode.RemoveLine(j + diff, j + jinfos["incr"]*jinfos["nbmax"], jinfos["incr"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   692
            self.CurrentNode.RemoveMapVariable(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   693
            if not found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   694
                infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   695
                if not infos["need"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   696
                    self.CurrentNode.RemoveEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   697
            if index in Mappings[-1]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   698
                self.CurrentNode.RemoveMappingEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   699
            self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   700
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   701
    def AddMapVariableToCurrent(self, index, name, struct, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   702
        if 0x2000 <= index <= 0x5FFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   703
            if not self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   704
                self.CurrentNode.AddMappingEntry(index, name = name, struct = struct)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   705
                if struct == var:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   706
                    values = {"name" : name, "type" : 5, "access" : "rw", "pdo" : True}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   707
                    self.CurrentNode.AddMappingEntry(index, 0, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   708
                    self.CurrentNode.AddEntry(index, 0, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   709
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   710
                    values = {"name" : "Number of Entries", "type" : 2, "access" : "ro", "pdo" : False}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   711
                    self.CurrentNode.AddMappingEntry(index, 0, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   712
                    if struct == rec:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   713
                        values = {"name" : name + " %d[(sub)]", "type" : 5, "access" : "rw", "pdo" : True, "nbmax" : 0xFE}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   714
                        self.CurrentNode.AddMappingEntry(index, 1, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   715
                        for i in xrange(number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   716
                            self.CurrentNode.AddEntry(index, i + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   717
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   718
                        for i in xrange(number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   719
                            values = {"name" : "Undefined", "type" : 5, "access" : "rw", "pdo" : True}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   720
                            self.CurrentNode.AddMappingEntry(index, i + 1, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   721
                            self.CurrentNode.AddEntry(index, i + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   722
                self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   723
                self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   724
                return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   725
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   726
                return "Index 0x%04X already defined!"%index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   727
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   728
            return "Index 0x%04X isn't a valid index for Map Variable!"%index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   729
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   730
    def AddUserTypeToCurrent(self, type, min, max, length):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   731
        index = 0xA0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   732
        while index < 0x100 and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   733
            index += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   734
        if index < 0x100:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   735
            customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   736
            name, valuetype = customisabletypes[type]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   737
            size = self.GetEntryInfos(type)["size"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   738
            default = self.GetTypeDefaultValue(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   739
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   740
                self.CurrentNode.AddMappingEntry(index, name = "%s[%d-%d]"%(name, min, max), struct = 3, size = size, default = default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   741
                self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   742
                self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   743
                self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   744
                self.CurrentNode.AddMappingEntry(index, 3, values = {"name" : "Maximum Value", "type" : type, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   745
                self.CurrentNode.AddEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   746
                self.CurrentNode.AddEntry(index, 2, min)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   747
                self.CurrentNode.AddEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   748
            elif valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   749
                self.CurrentNode.AddMappingEntry(index, name = "%s%d"%(name, length), struct = 3, size = length * size, default = default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   750
                self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   751
                self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   752
                self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   753
                self.CurrentNode.AddEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   754
                self.CurrentNode.AddEntry(index, 2, length)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   755
            self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   756
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   757
            return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   758
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   759
            return "Too many User Types have already been defined!"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   760
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   761
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   762
#                      Modify Entry and Mapping Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   763
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   764
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   765
    def SetCurrentEntryCallbacks(self, index, value):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   766
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   767
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   768
            if "callback" not in entry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   769
                self.CurrentNode.SetParamsEntry(index, None, callback = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   770
                self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   771
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   772
    def SetCurrentEntry(self, index, subIndex, value, name, editor):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   773
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   774
            if name == "value":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   775
                if editor == "map":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   776
                    value = eval("0x%s"%self.NameTranslation[value])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   777
                    self.CurrentNode.SetEntry(index, subIndex, value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   778
                elif editor == "bool":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   779
                    value = value == "True"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   780
                    self.CurrentNode.SetEntry(index, subIndex, value)
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   781
                elif editor == "time":
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   782
                    self.CurrentNode.SetEntry(index, subIndex, value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   783
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   784
                    subentry_infos = self.GetSubentryInfos(index, subIndex)
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   785
                    type = subentry_infos["type"]
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   786
                    dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   787
                    for typeindex, typevalue in CustomisableTypes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   788
                        dic[typeindex] = typevalue
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   789
                    if type not in dic:
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   790
                        type = self.CurrentNode.GetEntry(type)[1]
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   791
                    if dic[type] == 0:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   792
                        try:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   793
                            value = eval(value, {})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   794
                            self.CurrentNode.SetEntry(index, subIndex, value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   795
                        except:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   796
                            pass
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   797
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   798
                        self.CurrentNode.SetEntry(index, subIndex, value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   799
            elif name in ["comment", "save"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   800
                if editor == "option":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   801
                    value = value == "Yes"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   802
                if name == "save":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   803
                    self.CurrentNode.SetParamsEntry(index, subIndex, save = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   804
                elif name == "comment":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   805
                    self.CurrentNode.SetParamsEntry(index, subIndex, comment = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   806
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   807
                if editor == "type":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   808
                    value = self.TypeTranslation[value]
63
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 59
diff changeset
   809
                    size = self.GetEntryInfos(value)["size"]
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 59
diff changeset
   810
                    self.CurrentNode.UpdateMapVariable(index, subIndex, size)
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   811
                elif editor in ["access","raccess"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   812
                    dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   813
                    for abbrev,access in AccessType.iteritems():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   814
                        dic[access] = abbrev
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   815
                    value = dic[value]
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   816
                    if editor == "raccess" and not self.CurrentNode.IsMappingEntry(index):
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   817
                        entry_infos = self.GetEntryInfos(index)
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   818
                        self.CurrentNode.AddMappingEntry(index, name = entry_infos["name"], struct = 7)
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   819
                        self.CurrentNode.AddMappingEntry(index, 0, values = self.GetSubentryInfos(index, 0, False).copy())
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   820
                        self.CurrentNode.AddMappingEntry(index, 1, values = self.GetSubentryInfos(index, 1, False).copy())
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   821
                self.CurrentNode.SetMappingEntry(index, subIndex, values = {name : value})
63
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 59
diff changeset
   822
                if name == "name" or editor == "type":
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   823
                    self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   824
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   825
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   826
    def SetCurrentEntryName(self, index, name):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   827
        self.CurrentNode.SetMappingEntry(index, name=name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   828
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   829
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   830
    def SetCurrentUserType(self, index, type, min, max, length):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   831
        customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   832
        values, valuetype = self.GetCustomisedTypeValues(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   833
        name, new_valuetype = customisabletypes[type]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   834
        size = self.GetEntryInfos(type)["size"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   835
        default = self.GetTypeDefaultValue(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   836
        if new_valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   837
            self.CurrentNode.SetMappingEntry(index, name = "%s[%d-%d]"%(name, min, max), struct = 3, size = size, default = default) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   838
            if valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   839
                self.CurrentNode.SetMappingEntry(index, 2, values = {"name" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   840
                self.CurrentNode.AddMappingEntry(index, 3, values = {"name" : "Maximum Value", "type" : type, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   841
            self.CurrentNode.SetEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   842
            self.CurrentNode.SetEntry(index, 2, min)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   843
            if valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   844
                self.CurrentNode.AddEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   845
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   846
                self.CurrentNode.SetEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   847
        elif new_valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   848
            self.CurrentNode.SetMappingEntry(index, name = "%s%d"%(name, length), struct = 3, size = size, default = default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   849
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   850
                self.CurrentNode.SetMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   851
                self.CurrentNode.RemoveMappingEntry(index, 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   852
            self.CurrentNode.SetEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   853
            self.CurrentNode.SetEntry(index, 2, length)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   854
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   855
                self.CurrentNode.RemoveEntry(index, 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   856
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   857
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   858
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   859
#                      Current Buffering Management Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   860
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   861
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   862
    def BufferCurrentNode(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   863
        self.UndoBuffers[self.NodeIndex].Buffering(self.CurrentNode.Copy())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   864
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   865
    def CurrentIsSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   866
        return self.UndoBuffers[self.NodeIndex].IsCurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   867
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   868
    def OneFileHasChanged(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   869
        result = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   870
        for buffer in self.UndoBuffers:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   871
            result |= not buffer.IsCurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   872
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   873
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   874
    def GetBufferNumber(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   875
        return len(self.UndoBuffers)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   876
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   877
    def LoadCurrentPrevious(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   878
        self.CurrentNode = self.UndoBuffers[self.NodeIndex].Previous().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   879
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   880
    def LoadCurrentNext(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   881
        self.CurrentNode = self.UndoBuffers[self.NodeIndex].Next().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   882
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   883
    def AddNodeBuffer(self, currentstate = None, issaved = False):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   884
        self.NodeIndex = len(self.UndoBuffers)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   885
        self.UndoBuffers.append(UndoBuffer(currentstate, issaved))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   886
        self.FilePaths.append("")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   887
        self.FileNames.append("")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   888
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   889
    def ChangeCurrentNode(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   890
        if index < len(self.UndoBuffers):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   891
            self.NodeIndex = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   892
            self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   893
            self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   894
            self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   895
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   896
    def RemoveNodeBuffer(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   897
        self.UndoBuffers.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   898
        self.FilePaths.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   899
        self.FileNames.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   900
        self.NodeIndex = min(self.NodeIndex, len(self.UndoBuffers) - 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   901
        if len(self.UndoBuffers) > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   902
            self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   903
            self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   904
            self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   905
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   906
            self.CurrentNode = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   907
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   908
    def GetCurrentNodeIndex(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   909
        return self.NodeIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   910
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   911
    def GetCurrentFilename(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   912
        return self.GetFilename(self.NodeIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   913
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   914
    def GetAllFilenames(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   915
        filenames = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   916
        for i in xrange(len(self.UndoBuffers)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   917
            filenames.append(self.GetFilename(i))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   918
        return filenames
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   919
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   920
    def GetFilename(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   921
        if self.UndoBuffers[index].IsCurrentSaved():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   922
            return self.FileNames[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   923
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   924
            return "~%s~"%self.FileNames[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   925
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   926
    def SetCurrentFilePath(self, filepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   927
        self.FilePaths[self.NodeIndex] = filepath
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   928
        if filepath == "":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   929
            self.LastNewIndex += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   930
            self.FileNames[self.NodeIndex] = "Unnamed%d"%self.LastNewIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   931
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   932
            self.FileNames[self.NodeIndex] = os.path.splitext(os.path.basename(filepath))[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   933
                
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   934
    def GetCurrentFilePath(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   935
        if len(self.FilePaths) > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   936
            return self.FilePaths[self.NodeIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   937
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   938
            return ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   939
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   940
    def GetCurrentBufferState(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   941
        first = self.UndoBuffers[self.NodeIndex].IsFirst()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   942
        last = self.UndoBuffers[self.NodeIndex].IsLast()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   943
        return not first, not last
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   944
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   945
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   946
#                         Profiles Management Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   947
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   948
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   949
    def GetCurrentCommunicationLists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   950
        list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   951
        for index in MappingDictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   952
            if 0x1000 <= index < 0x1200:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   953
                list.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   954
        return self.GetProfileLists(MappingDictionary, list)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   955
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   956
    def GetCurrentDS302Lists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   957
        return self.GetSpecificProfileLists(self.CurrentNode.GetDS302Profile())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   958
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   959
    def GetCurrentProfileLists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   960
        return self.GetSpecificProfileLists(self.CurrentNode.GetProfile())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   961
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   962
    def GetSpecificProfileLists(self, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   963
        validlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   964
        exclusionlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   965
        for name, list in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   966
            exclusionlist.extend(list)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   967
        for index in mappingdictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   968
            if index not in exclusionlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   969
                validlist.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   970
        return self.GetProfileLists(mappingdictionary, validlist)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   971
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   972
    def GetProfileLists(self, mappingdictionary, list):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   973
        dictionary = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   974
        current = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   975
        for index in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   976
            dictionary[index] = (mappingdictionary[index]["name"], mappingdictionary[index]["need"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   977
            if self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   978
                current.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   979
        return dictionary, current
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   980
39
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   981
    def GetCurrentNextMapIndex(self):
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   982
        if self.CurrentNode:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   983
            index = 0x2000
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   984
            while self.CurrentNode.IsEntry(index) and index < 0x5FFF:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   985
                index += 1
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   986
            if index < 0x6000:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   987
                return index
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   988
            else:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   989
                return None
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   990
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   991
    def CurrentDS302Defined(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   992
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   993
            return len(self.CurrentNode.GetDS302Profile()) > 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   994
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   995
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   996
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   997
#                         Node State and Values Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   998
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   999
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1000
    def GetCurrentNodeInfos(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1001
        name = self.CurrentNode.GetNodeName()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1002
        id = self.CurrentNode.GetNodeID()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1003
        type = self.CurrentNode.GetNodeType()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1004
        return name, id, type
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1005
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1006
    def SetCurrentNodeInfos(self, name, id, type):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1007
        self.CurrentNode.SetNodeName(name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1008
        self.CurrentNode.SetNodeID(id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1009
        self.CurrentNode.SetNodeType(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1010
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1011
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1012
    def GetCurrentProfileName(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1013
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1014
            return self.CurrentNode.GetProfileName()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1015
        return ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1016
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1017
    def IsCurrentEntry(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1018
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1019
            return self.CurrentNode.IsEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1020
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1021
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1022
    def GetCurrentEntry(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1023
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1024
            return self.CurrentNode.GetEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1025
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1026
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1027
    def GetCurrentParamsEntry(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1028
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1029
            return self.CurrentNode.GetParamsEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1030
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1031
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1032
    def GetCurrentValidIndexes(self, min, max):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1033
        validindexes = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1034
        for index in self.CurrentNode.GetIndexes():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1035
            if min <= index <= max:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1036
                validindexes.append((self.GetEntryName(index), index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1037
        return validindexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1038
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1039
    def GetCurrentValidChoices(self, min, max):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1040
        validchoices = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1041
        exclusionlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1042
        for menu, indexes in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1043
            exclusionlist.extend(indexes)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1044
            good = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1045
            for index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1046
                good &= min <= index <= max
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1047
            if good:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1048
                validchoices.append((menu, None))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1049
        list = [index for index in MappingDictionary.keys() if index >= 0x1000]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1050
        profiles = self.CurrentNode.GetMappings(False)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1051
        for profile in profiles:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1052
            list.extend(profile.keys())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1053
        list.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1054
        for index in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1055
            if min <= index <= max and not self.CurrentNode.IsEntry(index) and index not in exclusionlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1056
                validchoices.append((self.GetEntryName(index), index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1057
        return validchoices
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1058
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1059
    def HasCurrentEntryCallbacks(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1060
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1061
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1062
            if "callback" in entry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1063
                return entry_infos["callback"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1064
            return self.CurrentNode.HasEntryCallbacks(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1065
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1066
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1067
    def GetCurrentEntryValues(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1068
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1069
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1070
            data = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1071
            editors = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1072
            values = self.CurrentNode.GetEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1073
            params = self.CurrentNode.GetParamsEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1074
            if type(values) == ListType:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1075
                for i, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1076
                    data.append({"value" : value})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1077
                    data[-1].update(params[i])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1078
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1079
                data.append({"value" : values})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1080
                data[-1].update(params)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1081
            for i, dic in enumerate(data):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1082
                infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1083
                dic["subindex"] = "0x%02X"%i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1084
                dic["name"] = infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1085
                dic["type"] = self.GetTypeName(infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1086
                dic["access"] = AccessType[infos["access"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1087
                dic["save"] = OptionType[dic["save"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1088
                editor = {"subindex" : None, "save" : "option", "callback" : "option", "comment" : "string"}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1089
                if type(values) == ListType and i == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1090
                    editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1091
                    editor["type"] = None
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1092
                    if 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1093
                        editor["access"] = "raccess"
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1094
                    else:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1095
                        editor["access"] = None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1096
                    editor["value"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1097
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1098
                    if infos["user_defined"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1099
                        if entry_infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1100
                            editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1101
                            if i > 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1102
                                editor["type"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1103
                                editor["access"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1104
                            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1105
                                editor["type"] = "type"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1106
                                editor["access"] = "access"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1107
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1108
                            if entry_infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1109
                                editor["name"] = "string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1110
                            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1111
                                editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1112
                            editor["type"] = "type"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1113
                            editor["access"] = "access"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1114
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1115
                        editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1116
                        editor["type"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1117
                        editor["access"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1118
                    if index < 0x260:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1119
                        editor["value"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1120
                        if i == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1121
                            dic["value"] = self.GetTypeName(dic["value"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1122
                    elif 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1123
                        editor["value"] = "map"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1124
                        dic["value"] = self.MapTranslation["%08X"%dic["value"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1125
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1126
                        if dic["type"].startswith("VISIBLE_STRING"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1127
                            editor["value"] = "string"
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1128
                        if dic["type"] in ["TIME_OF_DAY","TIME_DIFFERENCE"]:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1129
                            editor["value"] = "time"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1130
                        elif dic["type"] == "BOOLEAN":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1131
                            editor["value"] = "bool"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1132
                            dic["value"] = BoolType[dic["value"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1133
                        result = type_model.match(dic["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1134
                        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1135
                            values = result.groups()
59
3a553c789116 Some bugs reported by Francis Dupin corrected.
lbessard
parents: 39
diff changeset
  1136
                            if values[0] in ["INTEGER", "UNSIGNED"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1137
                                format = "0x%0" + str(int(values[1])/4) + "X"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1138
                                dic["value"] = format%dic["value"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1139
                                editor["value"] = "string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1140
                            elif values[0] == "REAL":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1141
                                editor["value"] = "float"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1142
                            elif values[0] == "VISIBLE_STRING":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1143
                                editor["length"] = values[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1144
                        result = range_model.match(dic["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1145
                        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1146
                            values = result.groups()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1147
                            if values[0] in ("UNSIGNED", "REAL"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1148
                                editor["min"] = values[2]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1149
                                editor["max"] = values[3]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1150
                editors.append(editor)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1151
            return data, editors
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1152
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1153
            return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1154
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1155
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1156
#                         Node Informations Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1157
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1158
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1159
    def GetCustomisedTypeValues(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1160
        values = self.CurrentNode.GetEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1161
        customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1162
        return values, customisabletypes[values[1]][1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1163
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1164
    def GetEntryName(self, index, node = True):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1165
        result = None
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1166
        if node:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1167
            NodeMappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1168
            i = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1169
            while not result and i < len(NodeMappings):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1170
                result = FindEntryName(index, NodeMappings[i])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1171
                i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1172
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1173
            result = FindEntryName(index, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1174
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1175
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1176
    def GetEntryInfos(self, index, node = True):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1177
        result = None
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1178
        if node:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1179
            NodeMappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1180
            i = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1181
            while not result and i < len(NodeMappings):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1182
                result = FindEntryInfos(index, NodeMappings[i])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1183
                i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1184
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1185
            result = FindEntryInfos(index, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1186
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1187
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1188
    def GetSubentryInfos(self, index, subIndex, node = True):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1189
        result = None
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1190
        if node:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1191
            NodeMappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1192
            i = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1193
            while not result and i < len(NodeMappings):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1194
                result = FindSubentryInfos(index, subIndex, NodeMappings[i])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1195
                if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1196
                    result["user_defined"] = i == len(NodeMappings) - 1 and index >= 0x1000
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1197
                i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1198
        if result == None:    
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1199
            result = FindSubentryInfos(index, subIndex, MappingDictionary)
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1200
            if result:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1201
                result["user_defined"] = False
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1202
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1203
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1204
    def GetTypeIndex(self, typename, node = True):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1205
        result = None
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1206
        if node:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1207
            NodeMappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1208
            i = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1209
            while not result and i < len(NodeMappings):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1210
                result = FindTypeIndex(typename, NodeMappings[i])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1211
                i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1212
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1213
            result = FindTypeIndex(typename, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1214
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1215
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1216
    def GetTypeName(self, typeindex, node = True):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1217
        result = None
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1218
        if node:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1219
            NodeMappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1220
            i = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1221
            while not result and i < len(NodeMappings):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1222
                result = FindTypeName(typeindex, NodeMappings[i])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1223
                i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1224
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1225
            result = FindTypeName(typeindex, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1226
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1227
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1228
    def GetTypeDefaultValue(self, typeindex, node = True):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1229
        result = None
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1230
        if node:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1231
            NodeMappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1232
            i = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1233
            while not result and i < len(NodeMappings):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1234
                result = FindTypeDefaultValue(typeindex, NodeMappings[i])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1235
                i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1236
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1237
            result = FindTypeDefaultValue(typeindex, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1238
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1239
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1240
    def GetTypeList(self, node = True):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1241
        list = FindTypeList(MappingDictionary)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1242
        if node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1243
            for NodeMapping in self.CurrentNode.GetMappings():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1244
                list.extend(FindTypeList(NodeMapping))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1245
        list.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1246
        return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1247
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1248
    def GetMapVariableList(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1249
        list = FindMapVariableList(MappingDictionary, self)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1250
        for NodeMapping in self.CurrentNode.GetMappings():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1251
            list.extend(FindMapVariableList(NodeMapping, self))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1252
        list.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1253
        return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1254
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1255
    def GetMandatoryIndexes(self, node = True):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1256
        list = FindMandatoryIndexes(MappingDictionary)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1257
        if node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1258
            for NodeMapping in self.CurrentNode.GetMappings():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1259
                list.extend(FindMandatoryIndexes(NodeMapping))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1260
        return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1261
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1262
    def GetCustomisableTypes(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1263
        dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1264
        for index, valuetype in CustomisableTypes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1265
            name = self.GetTypeName(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1266
            dic[index] = [name, valuetype]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1267
        return dic
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1268
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1269
    def GetCurrentSpecificMenu(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1270
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1271
            return self.CurrentNode.GetSpecificMenu()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1272
        return []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1273
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1274