objdictgen/nodemanager.py
author etisserant
Sat, 12 May 2007 22:42:51 +0200
changeset 191 1e6e3d261b8f
parent 188 00245bc2e6fe
child 205 dac0f9b4e3f8
permissions -rwxr-xr-x
CleanUp and minor fixes
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 *
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
    29
import eds_utils, gen_cfile
0
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
def StringFormat(text, idx, sub):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
    result = name_model.match(text)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
    if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
        format = result.groups()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
        return format[0]%eval(format[1])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
        return text
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
#                         Search in a Mapping Dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
#-------------------------------------------------------------------------------
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
Return the index of the informations in the Object Dictionary in case of identical
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
indexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
def FindIndex(index, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
    if index in mappingdictionary:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
        return index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
        listpluri = [idx for idx in mappingdictionary.keys() if mappingdictionary[idx]["struct"] & OD_IdenticalIndexes]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
        listpluri.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
        for idx in listpluri:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
            nb_max = mappingdictionary[idx]["nbmax"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
            incr = mappingdictionary[idx]["incr"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
            if idx < index < idx + incr * nb_max and (index - idx)%incr == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
                return idx
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
Return the index of the typename given by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
def FindTypeIndex(typename, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
    testdic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
    for index, values in mappingdictionary.iteritems():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
        if index < 0x1000:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
            testdic[values["name"]] = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
    if typename in testdic:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
        return testdic[typename]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
Return the name of the type by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
def FindTypeName(typeindex, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
    if typeindex < 0x1000 and typeindex in mappingdictionary:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
        return mappingdictionary[typeindex]["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
Return the default value of the type by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
def FindTypeDefaultValue(typeindex, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
    if typeindex < 0x1000 and typeindex in mappingdictionary:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
        return mappingdictionary[typeindex]["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
Return the list of types defined in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
def FindTypeList(mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
    list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
    for index in mappingdictionary.keys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
        if index < 0x1000:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
            list.append((index, mappingdictionary[index]["name"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
    return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
Return the name of an entry by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
def FindEntryName(index, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
    base_index = FindIndex(index, mappingdictionary)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
    if base_index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
        infos = mappingdictionary[base_index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
        if infos["struct"] & OD_IdenticalIndexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
            return StringFormat(infos["name"], (index - base_index) / infos["incr"] + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
            return infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
Return the informations of one entry by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
def FindEntryInfos(index, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
    base_index = FindIndex(index, mappingdictionary)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
    if base_index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
        copy = mappingdictionary[base_index].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
        if copy["struct"] & OD_IdenticalIndexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
            copy["name"] = StringFormat(copy["name"], (index - base_index) / copy["incr"] + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
        copy.pop("values")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
        return copy
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
Return the informations of one subentry of an entry by searching in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
def FindSubentryInfos(index, subIndex, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
    base_index = FindIndex(index, mappingdictionary)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
    if base_index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
        struct = mappingdictionary[base_index]["struct"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
        if struct & OD_Subindex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
            if struct & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
                if struct & OD_IdenticalIndexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
                    incr = mappingdictionary[base_index]["incr"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
                    incr = 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
                if subIndex == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
                    return mappingdictionary[base_index]["values"][0].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
                elif 0 < subIndex <= mappingdictionary[base_index]["values"][1]["nbmax"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
                    copy = mappingdictionary[base_index]["values"][1].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
                    copy["name"] = StringFormat(copy["name"], (index - base_index) / incr + 1, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
                    return copy
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
            elif struct & OD_MultipleSubindexes and 0 <= subIndex < len(mappingdictionary[base_index]["values"]):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
                return mappingdictionary[base_index]["values"][subIndex].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
            elif subIndex == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
                return mappingdictionary[base_index]["values"][0].copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
    return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
Return the list of variables that can be mapped defined in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
def FindMapVariableList(mappingdictionary, Manager):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
    list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
    for index in mappingdictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
        if Manager.IsCurrentEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
            for subIndex, values in enumerate(mappingdictionary[index]["values"]):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
                if mappingdictionary[index]["values"][subIndex]["pdo"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
                    infos = Manager.GetEntryInfos(mappingdictionary[index]["values"][subIndex]["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
                    if mappingdictionary[index]["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
                        values = Manager.GetCurrentEntry(index)
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   180
                        for i in xrange(len(values) - 1):
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   181
                            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
   182
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
                        list.append((index, subIndex, infos["size"], mappingdictionary[index]["values"][subIndex]["name"]))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
    return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
Return the list of mandatory indexes defined in mappingdictionary 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
def FindMandatoryIndexes(mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
    list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
    for index in mappingdictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
        if index >= 0x1000 and mappingdictionary[index]["need"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
            list.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
    return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
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
Class implementing a buffer of changes made on the current editing Object Dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
class UndoBuffer:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
    Constructor initialising buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
    def __init__(self, currentstate, issaved = False):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
        self.Buffer = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
        self.CurrentIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
        self.MinIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
        self.MaxIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
        # if current state is defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
        if currentstate:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
            self.CurrentIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
            self.MinIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
            self.MaxIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
        # Initialising buffer with currentstate at the first place
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
        for i in xrange(UndoBufferLength):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
            if i == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
                self.Buffer.append(currentstate)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
                self.Buffer.append(None)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
        # Initialising index of state saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
        if issaved:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
            self.LastSave = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
            self.LastSave = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
    Add a new state in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
    def Buffering(self, currentstate):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
        self.CurrentIndex = (self.CurrentIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
        self.Buffer[self.CurrentIndex] = currentstate
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
        # Actualising buffer limits
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
        self.MaxIndex = self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
        if self.MinIndex == self.CurrentIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
            # 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
   238
            if self.LastSave == self.MinIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
                self.LastSave = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
            self.MinIndex = (self.MinIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
        self.MinIndex = max(self.MinIndex, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
    Return current state of buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
    def Current(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
        return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
    Change current state to previous in buffer and return new current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
    def Previous(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
        if self.CurrentIndex != self.MinIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
            self.CurrentIndex = (self.CurrentIndex - 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
            return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
    Change current state to next in buffer and return new current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
    def Next(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
        if self.CurrentIndex != self.MaxIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
            self.CurrentIndex = (self.CurrentIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
            return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
    Return True if current state is the first in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
    def IsFirst(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
        return self.CurrentIndex == self.MinIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
    Return True if current state is the last in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
    def IsLast(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
        return self.CurrentIndex == self.MaxIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
    Note that current state is saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
    def CurrentSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
        self.LastSave = self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
    Return True if current state is saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
    def IsCurrentSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
        return self.LastSave == self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
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
Class which control the operations made on the node and answer to view requests
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
class NodeManager:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
    Constructor
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   302
    def __init__(self, cwd):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
        self.LastNewIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
        self.FilePaths = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
        self.FileNames = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
        self.NodeIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
        self.CurrentNode = None
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   308
        self.ScriptDirectory = cwd
0
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
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   361
    def CreateNewNode(self, name, id, type, description, profile, filepath, NMT, options):
0
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)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   366
        if not result:
0
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)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   372
            self.CurrentNode.SetNodeDescription(description)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
            AddIndexList = self.GetMandatoryIndexes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
            if NMT == "NodeGuarding":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
                AddIndexList.extend([0x100C, 0x100D])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
            elif NMT == "Heartbeat":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
                AddIndexList.append(0x1017)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
            for option in options:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
                if option == "DS302":
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   380
                    DS302Path = os.path.join(self.ScriptDirectory, "config/DS-302.prf")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
                    # Charging DS-302 profile if choosen by user
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   382
                    if os.path.isfile(DS302Path):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
                        try:
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   384
                            execfile(DS302Path)
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   385
                            self.CurrentNode.SetDS302Profile(Mapping)
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   386
                            self.CurrentNode.ExtendSpecificMenu(AddMenuEntries)
0
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)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   422
                return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
            except:
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   424
                return "Syntax Error\nBad OD Profile file!."
0
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([])
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   430
            return None
0
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
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   478
    Import an eds file and store it in a new buffer if no node edited
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   479
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   480
    def ImportCurrentFromEDSFile(self, filepath):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
        # Generate node from definition in a xml file
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   482
        result = eds_utils.GenerateNode(filepath, self, self.ScriptDirectory)
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   483
        if isinstance(result, Node):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   484
            self.CurrentNode = result
0
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()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   491
            return None
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   492
        else:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   493
            return result
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   494
    
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   495
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   496
    Export to an eds file and store it in a new buffer if no node edited
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   497
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   498
    def ExportCurrentToEDSFile(self, filepath):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   499
        return eds_utils.GenerateEDSFile(filepath, self)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   500
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   501
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
    Build the C definition of Object Dictionary for current node 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   504
    def ExportCurrentToCFile(self, filepath):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
        return gen_cfile.GenerateFile(filepath, self)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
#                        Add Entries to Current Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   511
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   512
    Add the specified number of subentry for the given entry. Verify that total
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   513
    number of subentry (except 0) doesn't exceed nbmax defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   514
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
    def AddSubentriesToCurrent(self, index, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
        # Informations about entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
        length = self.CurrentNode.GetEntry(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
        infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
        subentry_infos = self.GetSubentryInfos(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
        # Get default value for subindex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
        if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
            default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
            default = self.GetTypeDefaultValue(subentry_infos["type"])   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
        # First case entry is record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
        if infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   527
            for i in xrange(1, min(number,subentry_infos["nbmax"]-length) + 1):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   528
                self.CurrentNode.AddEntry(index, length + i, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   529
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   530
        # Second case entry is array, only possible for manufacturer specific
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   531
        elif infos["struct"] & OD_MultipleSubindexes and 0x2000 <= index <= 0x5FFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
            values = {"name" : "Undefined", "type" : 5, "access" : "rw", "pdo" : True}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   533
            for i in xrange(1, min(number,0xFE-length) + 1):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   534
                self.CurrentNode.AddMappingEntry(index, length + i, values = values.copy())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   535
                self.CurrentNode.AddEntry(index, length + i, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   536
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   537
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   539
    Remove the specified number of subentry for the given entry. Verify that total
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
    number of subentry (except 0) isn't less than 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   542
    def RemoveSubentriesFromCurrent(self, index, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
        # Informations about entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
        infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
        length = self.CurrentNode.GetEntry(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
        # Entry is a record, or is an array of manufacturer specific
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   547
        if infos["struct"] & OD_IdenticalSubindexes or 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   548
            for i in xrange(min(number, length - 1)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   549
                self.RemoveCurrentVariable(index, length - i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
    Add a SDO Server to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
    def AddSDOServerToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
        # An SDO Server is already defined at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
        if self.CurrentNode.IsEntry(0x1200):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   558
            indexlist = [self.GetLineFromIndex(0x1201)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
            if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
                self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
        # Add an SDO Server at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
            self.ManageEntriesOfCurrent([0x1200], [])
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 SDO Server 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 AddSDOClientToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
        indexlist = [self.GetLineFromIndex(0x1280)]
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 Transmit 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 AddPDOTransmitToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   577
        indexlist = [self.GetLineFromIndex(0x1800),self.GetLineFromIndex(0x1A00)]
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 Receive PDO 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 AddPDOReceiveToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   585
        indexlist = [self.GetLineFromIndex(0x1400),self.GetLineFromIndex(0x1600)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   589
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   590
    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
   591
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   592
    def AddSpecificEntryToCurrent(self, menuitem):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
        indexlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
        for menu, indexes in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
            if menuitem == menu:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
                for index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
                    indexlist.append(self.GetLineFromIndex(index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   599
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   601
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   602
    Search the first index available for a pluri entry from base_index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   603
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   604
    def GetLineFromIndex(self, base_index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   605
        found = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
        index = base_index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   607
        infos = self.GetEntryInfos(base_index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   608
        while index < base_index + infos["incr"]*infos["nbmax"] and not found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   609
            if not self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   610
                found = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   611
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   612
                index += infos["incr"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   613
        if found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   614
            return index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   615
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   616
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   617
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   618
    Add entries specified in addinglist and remove entries specified in removinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   619
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   620
    def ManageEntriesOfCurrent(self, addinglist, removinglist):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   621
        # Add all the entries in addinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   622
        for index in addinglist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   623
            infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   624
            if infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
                # First case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   626
                if infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   627
                    subentry_infos = self.GetSubentryInfos(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   628
                    if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   629
                        default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   630
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   631
                        default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   632
                    self.CurrentNode.AddEntry(index, 1, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
                # Second case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   634
                else:
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
                    while subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
                        if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
                            default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   640
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
                            default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   642
                        self.CurrentNode.AddEntry(index, i, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   643
                        i += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   644
                        subentry_infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   645
            # Third case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   646
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
                subentry_infos = self.GetSubentryInfos(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
                if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
                    default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   651
                    default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   652
                self.CurrentNode.AddEntry(index, 0, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   653
        # Remove all the entries in removinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   654
        for index in removinglist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   655
            self.RemoveCurrentVariable(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   658
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   659
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   660
    Remove an entry from current node. Analize the index to perform the correct
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   661
    method
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   662
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   663
    def RemoveCurrentVariable(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   664
        Mappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
        if index < 0x1000 and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
            type = self.CurrentNode.GetEntry(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
            for i in Mappings[-1]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
                for value in Mappings[-1][i]["values"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
                    if value["type"] == index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
                        value["type"] = type
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   671
            self.CurrentNode.RemoveMappingEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   672
            self.CurrentNode.RemoveEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   673
        elif index == 0x1200 and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   674
            self.CurrentNode.RemoveEntry(0x1200)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   675
        elif 0x1201 <= index <= 0x127F and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   676
            self.CurrentNode.RemoveLine(index, 0x127F)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
        elif 0x1280 <= index <= 0x12FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   678
            self.CurrentNode.RemoveLine(index, 0x12FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   679
        elif 0x1400 <= index <= 0x15FF or 0x1600 <= index <= 0x17FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   680
            if 0x1600 <= index <= 0x17FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   681
                index -= 0x200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   682
            self.CurrentNode.RemoveLine(index, 0x15FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   683
            self.CurrentNode.RemoveLine(index + 0x200, 0x17FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   684
        elif 0x1800 <= index <= 0x19FF or 0x1A00 <= index <= 0x1BFF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   685
            if 0x1A00 <= index <= 0x1BFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   686
                index -= 0x200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   687
            self.CurrentNode.RemoveLine(index, 0x19FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   688
            self.CurrentNode.RemoveLine(index + 0x200, 0x1BFF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   689
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   690
            found = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   691
            for menu,list in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   692
                for i in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   693
                    iinfos = self.GetEntryInfos(i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   694
                    indexes = [i + incr * iinfos["incr"] for incr in xrange(iinfos["nbmax"])] 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   695
                    if index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   696
                        found = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   697
                        diff = index - i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   698
                        for j in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   699
                            jinfos = self.GetEntryInfos(j)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   700
                            self.CurrentNode.RemoveLine(j + diff, j + jinfos["incr"]*jinfos["nbmax"], jinfos["incr"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   701
            self.CurrentNode.RemoveMapVariable(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   702
            if not found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   703
                infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   704
                if not infos["need"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   705
                    self.CurrentNode.RemoveEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   706
            if index in Mappings[-1]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   707
                self.CurrentNode.RemoveMappingEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   708
            self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   709
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   710
    def AddMapVariableToCurrent(self, index, name, struct, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   711
        if 0x2000 <= index <= 0x5FFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   712
            if not self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   713
                self.CurrentNode.AddMappingEntry(index, name = name, struct = struct)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   714
                if struct == var:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   715
                    values = {"name" : name, "type" : 5, "access" : "rw", "pdo" : True}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   716
                    self.CurrentNode.AddMappingEntry(index, 0, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   717
                    self.CurrentNode.AddEntry(index, 0, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   718
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   719
                    values = {"name" : "Number of Entries", "type" : 2, "access" : "ro", "pdo" : False}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   720
                    self.CurrentNode.AddMappingEntry(index, 0, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   721
                    if struct == rec:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   722
                        values = {"name" : name + " %d[(sub)]", "type" : 5, "access" : "rw", "pdo" : True, "nbmax" : 0xFE}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   723
                        self.CurrentNode.AddMappingEntry(index, 1, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   724
                        for i in xrange(number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   725
                            self.CurrentNode.AddEntry(index, i + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   726
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   727
                        for i in xrange(number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   728
                            values = {"name" : "Undefined", "type" : 5, "access" : "rw", "pdo" : True}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   729
                            self.CurrentNode.AddMappingEntry(index, i + 1, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   730
                            self.CurrentNode.AddEntry(index, i + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   731
                self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   732
                self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   733
                return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   734
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   735
                return "Index 0x%04X already defined!"%index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   736
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   737
            return "Index 0x%04X isn't a valid index for Map Variable!"%index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   738
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   739
    def AddUserTypeToCurrent(self, type, min, max, length):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   740
        index = 0xA0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   741
        while index < 0x100 and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   742
            index += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   743
        if index < 0x100:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   744
            customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   745
            name, valuetype = customisabletypes[type]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   746
            size = self.GetEntryInfos(type)["size"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   747
            default = self.GetTypeDefaultValue(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   748
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   749
                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
   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" : "Minimum Value", "type" : type, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   753
                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
   754
                self.CurrentNode.AddEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   755
                self.CurrentNode.AddEntry(index, 2, min)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   756
                self.CurrentNode.AddEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   757
            elif valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   758
                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
   759
                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
   760
                self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   761
                self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   762
                self.CurrentNode.AddEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   763
                self.CurrentNode.AddEntry(index, 2, length)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   764
            self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   765
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   766
            return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   767
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   768
            return "Too many User Types have already been defined!"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   769
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   770
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   771
#                      Modify Entry and Mapping Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   772
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   773
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   774
    def SetCurrentEntryCallbacks(self, index, value):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   775
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   776
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   777
            if "callback" not in entry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   778
                self.CurrentNode.SetParamsEntry(index, None, callback = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   779
                self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   780
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   781
    def SetCurrentEntry(self, index, subIndex, value, name, editor):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   782
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   783
            if name == "value":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   784
                if editor == "map":
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   785
                    try:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   786
                        value = int(self.NameTranslation[value], 16)
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   787
                        self.CurrentNode.SetEntry(index, subIndex, value)
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   788
                    except:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   789
                        pass
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   790
                elif editor == "bool":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   791
                    value = value == "True"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   792
                    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
   793
                elif editor == "time":
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   794
                    self.CurrentNode.SetEntry(index, subIndex, value)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   795
                elif editor == "number":
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   796
                    try:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   797
                        self.CurrentNode.SetEntry(index, subIndex, int(value))
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   798
                    except:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   799
                        pass
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   800
                elif editor == "domain":
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   801
                    try:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   802
                        if len(value) % 2 != 0:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   803
                            value = "0" + value
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   804
                        value = value.decode('hex_codec')
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   805
                        self.CurrentNode.SetEntry(index, subIndex, value)
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   806
                    except:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   807
                        pass
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   808
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   809
                    subentry_infos = self.GetSubentryInfos(index, subIndex)
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   810
                    type = subentry_infos["type"]
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   811
                    dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   812
                    for typeindex, typevalue in CustomisableTypes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   813
                        dic[typeindex] = typevalue
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   814
                    if type not in dic:
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   815
                        type = self.CurrentNode.GetEntry(type)[1]
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   816
                    if dic[type] == 0:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   817
                        try:
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   818
                            value = int(value, 16)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   819
                            self.CurrentNode.SetEntry(index, subIndex, value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   820
                        except:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   821
                            pass
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   822
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   823
                        self.CurrentNode.SetEntry(index, subIndex, value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   824
            elif name in ["comment", "save"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   825
                if editor == "option":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   826
                    value = value == "Yes"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   827
                if name == "save":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   828
                    self.CurrentNode.SetParamsEntry(index, subIndex, save = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   829
                elif name == "comment":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   830
                    self.CurrentNode.SetParamsEntry(index, subIndex, comment = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   831
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   832
                if editor == "type":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   833
                    value = self.TypeTranslation[value]
63
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 59
diff changeset
   834
                    size = self.GetEntryInfos(value)["size"]
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 59
diff changeset
   835
                    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
   836
                elif editor in ["access","raccess"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   837
                    dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   838
                    for abbrev,access in AccessType.iteritems():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   839
                        dic[access] = abbrev
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   840
                    value = dic[value]
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   841
                    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
   842
                        entry_infos = self.GetEntryInfos(index)
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   843
                        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
   844
                        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
   845
                        self.CurrentNode.AddMappingEntry(index, 1, values = self.GetSubentryInfos(index, 1, False).copy())
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   846
                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
   847
                if name == "name" or editor == "type":
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   848
                    self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   849
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   850
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   851
    def SetCurrentEntryName(self, index, name):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   852
        self.CurrentNode.SetMappingEntry(index, name=name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   853
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   854
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   855
    def SetCurrentUserType(self, index, type, min, max, length):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   856
        customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   857
        values, valuetype = self.GetCustomisedTypeValues(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   858
        name, new_valuetype = customisabletypes[type]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   859
        size = self.GetEntryInfos(type)["size"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   860
        default = self.GetTypeDefaultValue(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   861
        if new_valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   862
            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
   863
            if valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   864
                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
   865
                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
   866
            self.CurrentNode.SetEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   867
            self.CurrentNode.SetEntry(index, 2, min)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   868
            if valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   869
                self.CurrentNode.AddEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   870
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   871
                self.CurrentNode.SetEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   872
        elif new_valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   873
            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
   874
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   875
                self.CurrentNode.SetMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   876
                self.CurrentNode.RemoveMappingEntry(index, 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   877
            self.CurrentNode.SetEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   878
            self.CurrentNode.SetEntry(index, 2, length)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   879
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   880
                self.CurrentNode.RemoveEntry(index, 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   881
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   882
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   883
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   884
#                      Current Buffering Management Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   885
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   886
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   887
    def BufferCurrentNode(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   888
        self.UndoBuffers[self.NodeIndex].Buffering(self.CurrentNode.Copy())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   889
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   890
    def CurrentIsSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   891
        return self.UndoBuffers[self.NodeIndex].IsCurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   892
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   893
    def OneFileHasChanged(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   894
        result = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   895
        for buffer in self.UndoBuffers:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   896
            result |= not buffer.IsCurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   897
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   898
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   899
    def GetBufferNumber(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   900
        return len(self.UndoBuffers)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   901
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   902
    def LoadCurrentPrevious(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   903
        self.CurrentNode = self.UndoBuffers[self.NodeIndex].Previous().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   904
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   905
    def LoadCurrentNext(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   906
        self.CurrentNode = self.UndoBuffers[self.NodeIndex].Next().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   907
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   908
    def AddNodeBuffer(self, currentstate = None, issaved = False):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   909
        self.NodeIndex = len(self.UndoBuffers)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   910
        self.UndoBuffers.append(UndoBuffer(currentstate, issaved))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   911
        self.FilePaths.append("")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   912
        self.FileNames.append("")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   913
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   914
    def ChangeCurrentNode(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   915
        if index < len(self.UndoBuffers):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   916
            self.NodeIndex = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   917
            self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   918
            self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   919
            self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   920
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   921
    def RemoveNodeBuffer(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   922
        self.UndoBuffers.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   923
        self.FilePaths.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   924
        self.FileNames.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   925
        self.NodeIndex = min(self.NodeIndex, len(self.UndoBuffers) - 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   926
        if len(self.UndoBuffers) > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   927
            self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   928
            self.GenerateTypeList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   929
            self.GenerateMapList()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   930
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   931
            self.CurrentNode = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   932
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   933
    def GetCurrentNodeIndex(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   934
        return self.NodeIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   935
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   936
    def GetCurrentFilename(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   937
        return self.GetFilename(self.NodeIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   938
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   939
    def GetAllFilenames(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   940
        filenames = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   941
        for i in xrange(len(self.UndoBuffers)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   942
            filenames.append(self.GetFilename(i))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   943
        return filenames
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   944
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   945
    def GetFilename(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   946
        if self.UndoBuffers[index].IsCurrentSaved():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   947
            return self.FileNames[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   948
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   949
            return "~%s~"%self.FileNames[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   950
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   951
    def SetCurrentFilePath(self, filepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   952
        self.FilePaths[self.NodeIndex] = filepath
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   953
        if filepath == "":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   954
            self.LastNewIndex += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   955
            self.FileNames[self.NodeIndex] = "Unnamed%d"%self.LastNewIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   956
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   957
            self.FileNames[self.NodeIndex] = os.path.splitext(os.path.basename(filepath))[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   958
                
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   959
    def GetCurrentFilePath(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   960
        if len(self.FilePaths) > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   961
            return self.FilePaths[self.NodeIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   962
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   963
            return ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   964
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   965
    def GetCurrentBufferState(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   966
        first = self.UndoBuffers[self.NodeIndex].IsFirst()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   967
        last = self.UndoBuffers[self.NodeIndex].IsLast()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   968
        return not first, not last
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   969
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   970
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   971
#                         Profiles Management Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   972
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   973
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   974
    def GetCurrentCommunicationLists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   975
        list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   976
        for index in MappingDictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   977
            if 0x1000 <= index < 0x1200:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   978
                list.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   979
        return self.GetProfileLists(MappingDictionary, list)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   980
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   981
    def GetCurrentDS302Lists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   982
        return self.GetSpecificProfileLists(self.CurrentNode.GetDS302Profile())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   983
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   984
    def GetCurrentProfileLists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   985
        return self.GetSpecificProfileLists(self.CurrentNode.GetProfile())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   986
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   987
    def GetSpecificProfileLists(self, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   988
        validlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   989
        exclusionlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   990
        for name, list in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   991
            exclusionlist.extend(list)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   992
        for index in mappingdictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   993
            if index not in exclusionlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   994
                validlist.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   995
        return self.GetProfileLists(mappingdictionary, validlist)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   996
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   997
    def GetProfileLists(self, mappingdictionary, list):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   998
        dictionary = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   999
        current = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1000
        for index in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1001
            dictionary[index] = (mappingdictionary[index]["name"], mappingdictionary[index]["need"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1002
            if self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1003
                current.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1004
        return dictionary, current
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1005
39
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1006
    def GetCurrentNextMapIndex(self):
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1007
        if self.CurrentNode:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1008
            index = 0x2000
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1009
            while self.CurrentNode.IsEntry(index) and index < 0x5FFF:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1010
                index += 1
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1011
            if index < 0x6000:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1012
                return index
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1013
            else:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1014
                return None
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
  1015
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1016
    def CurrentDS302Defined(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1017
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1018
            return len(self.CurrentNode.GetDS302Profile()) > 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1019
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1020
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1021
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1022
#                         Node State and Values Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1023
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1024
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1025
    def GetCurrentNodeInfos(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1026
        name = self.CurrentNode.GetNodeName()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1027
        id = self.CurrentNode.GetNodeID()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1028
        type = self.CurrentNode.GetNodeType()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1029
        description = self.CurrentNode.GetNodeDescription()
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1030
        return name, id, type, description
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1031
        
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1032
    def SetCurrentNodeInfos(self, name, id, type, description):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1033
        self.CurrentNode.SetNodeName(name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1034
        self.CurrentNode.SetNodeID(id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1035
        self.CurrentNode.SetNodeType(type)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1036
        self.CurrentNode.SetNodeDescription(description)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1037
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1038
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1039
    def GetCurrentProfileName(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1040
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1041
            return self.CurrentNode.GetProfileName()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1042
        return ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1043
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1044
    def IsCurrentEntry(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1045
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1046
            return self.CurrentNode.IsEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1047
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1048
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1049
    def GetCurrentEntry(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1050
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1051
            return self.CurrentNode.GetEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1052
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1053
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1054
    def GetCurrentParamsEntry(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1055
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1056
            return self.CurrentNode.GetParamsEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1057
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1058
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1059
    def GetCurrentValidIndexes(self, min, max):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1060
        validindexes = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1061
        for index in self.CurrentNode.GetIndexes():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1062
            if min <= index <= max:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1063
                validindexes.append((self.GetEntryName(index), index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1064
        return validindexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1065
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1066
    def GetCurrentValidChoices(self, min, max):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1067
        validchoices = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1068
        exclusionlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1069
        for menu, indexes in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1070
            exclusionlist.extend(indexes)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1071
            good = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1072
            for index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1073
                good &= min <= index <= max
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1074
            if good:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1075
                validchoices.append((menu, None))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1076
        list = [index for index in MappingDictionary.keys() if index >= 0x1000]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1077
        profiles = self.CurrentNode.GetMappings(False)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1078
        for profile in profiles:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1079
            list.extend(profile.keys())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1080
        list.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1081
        for index in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1082
            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
  1083
                validchoices.append((self.GetEntryName(index), index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1084
        return validchoices
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1085
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1086
    def HasCurrentEntryCallbacks(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1087
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1088
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1089
            if "callback" in entry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1090
                return entry_infos["callback"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1091
            return self.CurrentNode.HasEntryCallbacks(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1092
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1093
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1094
    def GetCurrentEntryValues(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1095
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1096
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1097
            data = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1098
            editors = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1099
            values = self.CurrentNode.GetEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1100
            params = self.CurrentNode.GetParamsEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1101
            if type(values) == ListType:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1102
                for i, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1103
                    data.append({"value" : value})
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1104
                    data[-1].update(params[i])      
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1105
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1106
                data.append({"value" : values})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1107
                data[-1].update(params)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1108
            for i, dic in enumerate(data):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1109
                infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1110
                dic["subindex"] = "0x%02X"%i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1111
                dic["name"] = infos["name"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1112
                dic["type"] = self.GetTypeName(infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1113
                dic["access"] = AccessType[infos["access"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1114
                dic["save"] = OptionType[dic["save"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1115
                editor = {"subindex" : None, "save" : "option", "callback" : "option", "comment" : "string"}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1116
                if type(values) == ListType and i == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1117
                    editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1118
                    editor["type"] = None
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1119
                    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
  1120
                        editor["access"] = "raccess"
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1121
                    else:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1122
                        editor["access"] = None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1123
                    editor["value"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1124
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1125
                    if infos["user_defined"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1126
                        if entry_infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1127
                            editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1128
                            if i > 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1129
                                editor["type"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1130
                                editor["access"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1131
                            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1132
                                editor["type"] = "type"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1133
                                editor["access"] = "access"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1134
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1135
                            if entry_infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1136
                                editor["name"] = "string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1137
                            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1138
                                editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1139
                            editor["type"] = "type"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1140
                            editor["access"] = "access"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1141
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1142
                        editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1143
                        editor["type"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1144
                        editor["access"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1145
                    if index < 0x260:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1146
                        editor["value"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1147
                        if i == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1148
                            dic["value"] = self.GetTypeName(dic["value"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1149
                    elif 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1150
                        editor["value"] = "map"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1151
                        dic["value"] = self.MapTranslation["%08X"%dic["value"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1152
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1153
                        if dic["type"].startswith("VISIBLE_STRING"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1154
                            editor["value"] = "string"
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1155
                        elif dic["type"] in ["TIME_OF_DAY","TIME_DIFFERENCE"]:
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1156
                            editor["value"] = "time"
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1157
                        elif dic["type"] == "DOMAIN":
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1158
                            editor["value"] = "domain"
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1159
                            dic["value"] = dic["value"].encode('hex_codec')
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1160
                        elif dic["type"] == "BOOLEAN":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1161
                            editor["value"] = "bool"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1162
                            dic["value"] = BoolType[dic["value"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1163
                        result = type_model.match(dic["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1164
                        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1165
                            values = result.groups()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1166
                            if values[0] == "UNSIGNED":
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1167
                                format = "0x%0" + str(int(values[1])/4) + "X"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1168
                                dic["value"] = format%dic["value"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1169
                                editor["value"] = "string"
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1170
                            if values[0] == "INTEGER":
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1171
                                editor["value"] = "number"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1172
                            elif values[0] == "REAL":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1173
                                editor["value"] = "float"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1174
                            elif values[0] == "VISIBLE_STRING":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1175
                                editor["length"] = values[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1176
                        result = range_model.match(dic["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1177
                        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1178
                            values = result.groups()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1179
                            if values[0] in ["UNSIGNED", "INTEGER", "REAL"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1180
                                editor["min"] = values[2]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1181
                                editor["max"] = values[3]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1182
                editors.append(editor)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1183
            return data, editors
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1184
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1185
            return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1186
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1187
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1188
#                         Node Informations Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1189
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1190
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1191
    def GetCustomisedTypeValues(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1192
        values = self.CurrentNode.GetEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1193
        customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1194
        return values, customisabletypes[values[1]][1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1195
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1196
    def GetEntryName(self, index, node = None):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1197
        result = None
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1198
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1199
            node = self.CurrentNode
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1200
        NodeMappings = node.GetMappings()
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1201
        i = 0
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1202
        while not result and i < len(NodeMappings):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1203
            result = FindEntryName(index, NodeMappings[i])
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1204
            i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1205
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1206
            result = FindEntryName(index, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1207
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1208
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1209
    def GetEntryInfos(self, index, node = None):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1210
        result = None
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1211
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1212
            node = self.CurrentNode
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1213
        NodeMappings = node.GetMappings()
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1214
        i = 0
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1215
        while not result and i < len(NodeMappings):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1216
            result = FindEntryInfos(index, NodeMappings[i])
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1217
            i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1218
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1219
            result = FindEntryInfos(index, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1220
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1221
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1222
    def GetSubentryInfos(self, index, subIndex, node = None):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1223
        result = None
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1224
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1225
            node = self.CurrentNode
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1226
        NodeMappings = node.GetMappings()
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1227
        i = 0
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1228
        while not result and i < len(NodeMappings):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1229
            result = FindSubentryInfos(index, subIndex, NodeMappings[i])
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1230
            if result:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1231
                result["user_defined"] = i == len(NodeMappings) - 1 and index >= 0x1000
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1232
            i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1233
        if result == None:    
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1234
            result = FindSubentryInfos(index, subIndex, MappingDictionary)
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1235
            if result:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1236
                result["user_defined"] = False
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1237
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1238
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1239
    def GetTypeIndex(self, typename, node = None):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1240
        result = None
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1241
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1242
            node = self.CurrentNode
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1243
        NodeMappings = node.GetMappings()
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1244
        i = 0
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1245
        while not result and i < len(NodeMappings):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1246
            result = FindTypeIndex(typename, NodeMappings[i])
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1247
            i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1248
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1249
            result = FindTypeIndex(typename, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1250
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1251
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1252
    def GetTypeName(self, typeindex, node = None):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1253
        result = None
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1254
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1255
            node = self.CurrentNode
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1256
        NodeMappings = node.GetMappings()
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1257
        i = 0
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1258
        while not result and i < len(NodeMappings):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1259
            result = FindTypeName(typeindex, NodeMappings[i])
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1260
            i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1261
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1262
            result = FindTypeName(typeindex, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1263
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1264
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1265
    def GetTypeDefaultValue(self, typeindex, node = None):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1266
        result = None
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1267
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1268
            node = self.CurrentNode
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1269
        if node:
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1270
            NodeMappings = node.GetMappings()
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1271
            i = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1272
            while not result and i < len(NodeMappings):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1273
                result = FindTypeDefaultValue(typeindex, NodeMappings[i])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1274
                i += 1
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1275
        if result == None:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1276
            result = FindTypeDefaultValue(typeindex, MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1277
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1278
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1279
    def GetTypeList(self, node = None):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1280
        list = FindTypeList(MappingDictionary)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1281
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1282
            node = self.CurrentNode
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1283
        for NodeMapping in self.CurrentNode.GetMappings():
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1284
            list.extend(FindTypeList(NodeMapping))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1285
        list.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1286
        return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1287
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1288
    def GetMapVariableList(self, node = None):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1289
        list = FindMapVariableList(MappingDictionary, self)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1290
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1291
            node = self.CurrentNode
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1292
        for NodeMapping in node.GetMappings():
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1293
            list.extend(FindMapVariableList(NodeMapping, self))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1294
        list.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1295
        return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1296
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1297
    def GetMandatoryIndexes(self, node = None):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1298
        list = FindMandatoryIndexes(MappingDictionary)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1299
        if node == None:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1300
            node = self.CurrentNode
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1301
        for NodeMapping in node.GetMappings():
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1302
            list.extend(FindMandatoryIndexes(NodeMapping))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1303
        return list
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1304
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1305
    def GetCustomisableTypes(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1306
        dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1307
        for index, valuetype in CustomisableTypes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1308
            name = self.GetTypeName(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1309
            dic[index] = [name, valuetype]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1310
        return dic
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1311
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1312
    def GetCurrentSpecificMenu(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1313
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1314
            return self.CurrentNode.GetSpecificMenu()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1315
        return []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1316