objdictgen/nodemanager.py
author lbessard
Fri, 29 Jun 2007 17:24:27 +0200
changeset 233 6f2936f7fb3f
parent 223 461f5516176b
child 237 5dcfc996e563
permissions -rwxr-xr-x
Permitting user to type decimal or hexadecimal for integer values
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]*)\]')
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    38
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    39
# ID for the file viewed
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    40
CurrentID = 0
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    41
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    42
# Returns a new id
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    43
def GetNewId():
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    44
    global CurrentID
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    45
    CurrentID += 1
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
    46
    return CurrentID
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
Class implementing a buffer of changes made on the current editing Object Dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
class UndoBuffer:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
    Constructor initialising buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
    def __init__(self, currentstate, issaved = False):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
        self.Buffer = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
        self.CurrentIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
        self.MinIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
        self.MaxIndex = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
        # if current state is defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
        if currentstate:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
            self.CurrentIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
            self.MinIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
            self.MaxIndex = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
        # Initialising buffer with currentstate at the first place
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
        for i in xrange(UndoBufferLength):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
            if i == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
                self.Buffer.append(currentstate)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
                self.Buffer.append(None)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
        # Initialising index of state saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
        if issaved:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
            self.LastSave = 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
            self.LastSave = -1
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
    Add a new state in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
    def Buffering(self, currentstate):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
        self.CurrentIndex = (self.CurrentIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
        self.Buffer[self.CurrentIndex] = currentstate
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
        # Actualising buffer limits
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
        self.MaxIndex = self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
        if self.MinIndex == self.CurrentIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
            # 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
    89
            if self.LastSave == self.MinIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
                self.LastSave = -1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
            self.MinIndex = (self.MinIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
        self.MinIndex = max(self.MinIndex, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
    Return current state of buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
    def Current(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
        return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
    Change current state to previous in buffer and return new current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
    def Previous(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
        if self.CurrentIndex != self.MinIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
            self.CurrentIndex = (self.CurrentIndex - 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
            return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
    Change current state to next in buffer and return new current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
    def Next(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
        if self.CurrentIndex != self.MaxIndex:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
            self.CurrentIndex = (self.CurrentIndex + 1) % UndoBufferLength
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
            return self.Buffer[self.CurrentIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
    Return True if current state is the first in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
    def IsFirst(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
        return self.CurrentIndex == self.MinIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
    Return True if current state is the last in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
    def IsLast(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
        return self.CurrentIndex == self.MaxIndex
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
    Note that current state is saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
    def CurrentSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
        self.LastSave = self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
    Return True if current state is saved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
    def IsCurrentSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
        return self.LastSave == self.CurrentIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
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
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
Class which control the operations made on the node and answer to view requests
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
"""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
class NodeManager:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
    Constructor
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   153
    def __init__(self, cwd):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
        self.LastNewIndex = 0
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   155
        self.FilePaths = {}
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   156
        self.FileNames = {}
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   157
        self.NodeIndex = None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
        self.CurrentNode = None
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   159
        self.ScriptDirectory = cwd
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   160
        self.UndoBuffers = {}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
#                         Type and Map Variable Lists
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
    Return the list of types defined for the current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
    def GetCurrentTypeList(self):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   170
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   171
            return self.CurrentNode.GetTypeList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   172
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   173
            return ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
    Return the list of variables that can be mapped for the current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
    def GetCurrentMapList(self):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   179
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   180
            return self.CurrentNode.GetMapList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   181
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   182
            return ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
#                        Create Load and Save Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
    Create a new node and add a new buffer for storing it
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   191
    def CreateNewNode(self, name, id, type, description, profile, filepath, NMT, options):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
        # Create a new node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
        node = Node()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
        # Try to load profile given
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
        result = self.LoadProfile(profile, filepath, node)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   196
        if not result:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
            # if success, initialising node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
            self.CurrentNode = node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
            self.CurrentNode.SetNodeName(name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
            self.CurrentNode.SetNodeID(id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
            self.CurrentNode.SetNodeType(type)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   202
            self.CurrentNode.SetNodeDescription(description)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
            AddIndexList = self.GetMandatoryIndexes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
            if NMT == "NodeGuarding":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
                AddIndexList.extend([0x100C, 0x100D])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
            elif NMT == "Heartbeat":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
                AddIndexList.append(0x1017)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
            for option in options:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
                if option == "DS302":
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   210
                    DS302Path = os.path.join(self.ScriptDirectory, "config/DS-302.prf")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
                    # Charging DS-302 profile if choosen by user
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   212
                    if os.path.isfile(DS302Path):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
                        try:
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   214
                            execfile(DS302Path)
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   215
                            self.CurrentNode.SetDS302Profile(Mapping)
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   216
                            self.CurrentNode.ExtendSpecificMenu(AddMenuEntries)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
                        except:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
                            return "Problem with DS-302! Syntax Error."
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
                        return "Couldn't find DS-302 in 'config' folder!"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
                elif option == "GenSYNC":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
                    AddIndexList.extend([0x1005, 0x1006])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
                elif option == "Emergency":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
                    AddIndexList.append(0x1014)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
                elif option == "SaveConfig":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
                    AddIndexList.extend([0x1010, 0x1011, 0x1020])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
                elif option == "StoreEDS":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
                    AddIndexList.extend([0x1021, 0x1022])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
            # Add a new buffer 
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   230
            index = self.AddNodeBuffer()
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
            self.SetCurrentFilePath("")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
            # Add Mandatory indexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
            self.ManageEntriesOfCurrent(AddIndexList, [])
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   234
            return index
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
            return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
    Load a profile in node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
    def LoadProfile(self, profile, filepath, node):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
        if profile != "None":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
            # Try to charge the profile given
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
            try:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
                execfile(filepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
                node.SetProfileName(profile)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
                node.SetProfile(Mapping)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
                node.SetSpecificMenu(AddMenuEntries)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   249
                return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
            except:
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   251
                return "Syntax Error\nBad OD Profile file!."
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
            # Default profile
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
            node.SetProfileName("None")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
            node.SetProfile({})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
            node.SetSpecificMenu([])
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   257
            return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
    Open a file and store it in a new buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
    def OpenFileInCurrent(self, filepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
        # Open and load file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
        file = open(filepath, "r")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
        node = load(file)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
        file.close()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
        self.CurrentNode = node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
        # Add a new buffer and defining current state
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   269
        index = self.AddNodeBuffer(self.CurrentNode.Copy(), True)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
        self.SetCurrentFilePath(filepath)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   271
        return index
0
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
    Save current node in  a file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
    def SaveCurrentInFile(self, filepath = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
        # if no filepath given, verify if current node has a filepath defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
        if not filepath:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
            filepath = self.GetCurrentFilePath()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
            if filepath == "":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
                return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
        # Save node in file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
        file = open(filepath, "w")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
        dump(self.CurrentNode, file)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
        file.close()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
        self.SetCurrentFilePath(filepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
        # Update saved state in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
        self.UndoBuffers[self.NodeIndex].CurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
        return True
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
    Close current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
    def CloseCurrent(self, ignore = False):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
        # 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
   296
        if self.UndoBuffers[self.NodeIndex].IsCurrentSaved() or ignore:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
            self.RemoveNodeBuffer(self.NodeIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
            return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
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
    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
   303
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   304
    def ImportCurrentFromEDSFile(self, filepath):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
        # Generate node from definition in a xml file
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   306
        result = eds_utils.GenerateNode(filepath, self.ScriptDirectory)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   307
        if isinstance(result, Node):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   308
            self.CurrentNode = result
223
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 220
diff changeset
   309
            index = self.AddNodeBuffer()
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 220
diff changeset
   310
            self.SetCurrentFilePath("")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
            self.BufferCurrentNode()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   312
            return index
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   313
        else:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   314
            return result
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   315
    
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   316
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   317
    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
   318
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   319
    def ExportCurrentToEDSFile(self, filepath):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   320
        return eds_utils.GenerateEDSFile(filepath, self)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
    Build the C definition of Object Dictionary for current node 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   325
    def ExportCurrentToCFile(self, filepath):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
        return gen_cfile.GenerateFile(filepath, self)
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
#                        Add Entries to Current Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
    Add the specified number of subentry for the given entry. Verify that total
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
    number of subentry (except 0) doesn't exceed nbmax defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
    def AddSubentriesToCurrent(self, index, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
        # Informations about entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
        length = self.CurrentNode.GetEntry(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
        infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
        subentry_infos = self.GetSubentryInfos(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
        # Get default value for subindex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
        if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
            default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
            default = self.GetTypeDefaultValue(subentry_infos["type"])   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
        # First case entry is record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
        if infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
            for i in xrange(1, min(number,subentry_infos["nbmax"]-length) + 1):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
                self.CurrentNode.AddEntry(index, length + i, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
        # Second case entry is array, only possible for manufacturer specific
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
        elif infos["struct"] & OD_MultipleSubindexes and 0x2000 <= index <= 0x5FFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
            values = {"name" : "Undefined", "type" : 5, "access" : "rw", "pdo" : True}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
            for i in xrange(1, min(number,0xFE-length) + 1):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
                self.CurrentNode.AddMappingEntry(index, length + i, values = values.copy())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
                self.CurrentNode.AddEntry(index, length + i, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
    Remove the specified number of subentry for the given entry. Verify that total
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
    number of subentry (except 0) isn't less than 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
    def RemoveSubentriesFromCurrent(self, index, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
        # Informations about entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
        infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
        length = self.CurrentNode.GetEntry(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
        # Entry is a record, or is an array of manufacturer specific
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
        if infos["struct"] & OD_IdenticalSubindexes or 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
            for i in xrange(min(number, length - 1)):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
                self.RemoveCurrentVariable(index, length - i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
    Add a SDO Server to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
    def AddSDOServerToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
        # An SDO Server is already defined at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
        if self.CurrentNode.IsEntry(0x1200):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
            indexlist = [self.GetLineFromIndex(0x1201)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
            if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
                self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
        # Add an SDO Server at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
            self.ManageEntriesOfCurrent([0x1200], [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
    Add a SDO Server to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
    def AddSDOClientToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
        indexlist = [self.GetLineFromIndex(0x1280)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
    Add a Transmit PDO to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
    def AddPDOTransmitToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
        indexlist = [self.GetLineFromIndex(0x1800),self.GetLineFromIndex(0x1A00)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
    Add a Receive PDO to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
    def AddPDOReceiveToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
        indexlist = [self.GetLineFromIndex(0x1400),self.GetLineFromIndex(0x1600)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
    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
   412
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
    def AddSpecificEntryToCurrent(self, menuitem):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
        indexlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
        for menu, indexes in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
            if menuitem == menu:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
                for index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
                    indexlist.append(self.GetLineFromIndex(index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
    Search the first index available for a pluri entry from base_index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
    def GetLineFromIndex(self, base_index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
        found = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
        index = base_index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
        infos = self.GetEntryInfos(base_index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
        while index < base_index + infos["incr"]*infos["nbmax"] and not found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
            if not self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
                found = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
                index += infos["incr"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
        if found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
            return index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
    Add entries specified in addinglist and remove entries specified in removinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
    def ManageEntriesOfCurrent(self, addinglist, removinglist):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
        # Add all the entries in addinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
        for index in addinglist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
            infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
            if infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   446
                # First case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
                if infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
                    subentry_infos = self.GetSubentryInfos(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
                    if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
                        default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
                        default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
                    self.CurrentNode.AddEntry(index, 1, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
                # Second case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
                    i = 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
                    subentry_infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
                    while subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
                        if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
                            default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
                            default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
                        self.CurrentNode.AddEntry(index, i, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
                        i += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
                        subentry_infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
            # Third case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
                subentry_infos = self.GetSubentryInfos(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
                if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
                    default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
                    default = self.GetTypeDefaultValue(subentry_infos["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
                self.CurrentNode.AddEntry(index, 0, default)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
        # Remove all the entries in removinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
        for index in removinglist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
            self.RemoveCurrentVariable(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   479
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
    Remove an entry from current node. Analize the index to perform the correct
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
    method
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   483
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
    def RemoveCurrentVariable(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   485
        Mappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
        if index < 0x1000 and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
            type = self.CurrentNode.GetEntry(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
            for i in Mappings[-1]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
                for value in Mappings[-1][i]["values"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
                    if value["type"] == index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
                        value["type"] = type
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
            self.CurrentNode.RemoveMappingEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
            self.CurrentNode.RemoveEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   494
        elif index == 0x1200 and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   495
            self.CurrentNode.RemoveEntry(0x1200)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   496
        elif 0x1201 <= index <= 0x127F and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   497
            self.CurrentNode.RemoveLine(index, 0x127F)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   498
        elif 0x1280 <= index <= 0x12FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   499
            self.CurrentNode.RemoveLine(index, 0x12FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   500
        elif 0x1400 <= index <= 0x15FF or 0x1600 <= index <= 0x17FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   501
            if 0x1600 <= index <= 0x17FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
                index -= 0x200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
            self.CurrentNode.RemoveLine(index, 0x15FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
            self.CurrentNode.RemoveLine(index + 0x200, 0x17FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
        elif 0x1800 <= index <= 0x19FF or 0x1A00 <= index <= 0x1BFF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
            if 0x1A00 <= index <= 0x1BFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
                index -= 0x200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
            self.CurrentNode.RemoveLine(index, 0x19FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
            self.CurrentNode.RemoveLine(index + 0x200, 0x1BFF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   511
            found = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   512
            for menu,list in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   513
                for i in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   514
                    iinfos = self.GetEntryInfos(i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
                    indexes = [i + incr * iinfos["incr"] for incr in xrange(iinfos["nbmax"])] 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
                    if index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
                        found = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
                        diff = index - i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
                        for j in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
                            jinfos = self.GetEntryInfos(j)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
                            self.CurrentNode.RemoveLine(j + diff, j + jinfos["incr"]*jinfos["nbmax"], jinfos["incr"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
            self.CurrentNode.RemoveMapVariable(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
            if not found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
                infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
                if not infos["need"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
                    self.CurrentNode.RemoveEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   527
            if index in Mappings[-1]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   528
                self.CurrentNode.RemoveMappingEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   529
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   530
    def AddMapVariableToCurrent(self, index, name, struct, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   531
        if 0x2000 <= index <= 0x5FFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
            if not self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   533
                self.CurrentNode.AddMappingEntry(index, name = name, struct = struct)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   534
                if struct == var:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   535
                    values = {"name" : name, "type" : 0x05, "access" : "rw", "pdo" : True}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   536
                    self.CurrentNode.AddMappingEntry(index, 0, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   537
                    self.CurrentNode.AddEntry(index, 0, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
                else:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   539
                    values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
                    self.CurrentNode.AddMappingEntry(index, 0, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
                    if struct == rec:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   542
                        values = {"name" : name + " %d[(sub)]", "type" : 0x05, "access" : "rw", "pdo" : True, "nbmax" : 0xFE}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
                        self.CurrentNode.AddMappingEntry(index, 1, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
                        for i in xrange(number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
                            self.CurrentNode.AddEntry(index, i + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   547
                        for i in xrange(number):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   548
                            values = {"name" : "Undefined", "type" : 0x05, "access" : "rw", "pdo" : True}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   549
                            self.CurrentNode.AddMappingEntry(index, i + 1, values = values)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
                            self.CurrentNode.AddEntry(index, i + 1, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
                self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
                return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
                return "Index 0x%04X already defined!"%index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
            return "Index 0x%04X isn't a valid index for Map Variable!"%index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   558
    def AddUserTypeToCurrent(self, type, min, max, length):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
        index = 0xA0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
        while index < 0x100 and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
            index += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
        if index < 0x100:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
            customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   564
            name, valuetype = customisabletypes[type]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
            size = self.GetEntryInfos(type)["size"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   566
            default = self.GetTypeDefaultValue(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   567
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
                self.CurrentNode.AddMappingEntry(index, name = "%s[%d-%d]"%(name, min, max), struct = 3, size = size, default = default)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   569
                self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False})
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   570
                self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x05, "access" : "ro", "pdo" : False})
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   571
                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
   572
                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
   573
                self.CurrentNode.AddEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   574
                self.CurrentNode.AddEntry(index, 2, min)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   575
                self.CurrentNode.AddEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   576
            elif valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   577
                self.CurrentNode.AddMappingEntry(index, name = "%s%d"%(name, length), struct = 3, size = length * size, default = default)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   578
                self.CurrentNode.AddMappingEntry(index, 0, values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False})
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   579
                self.CurrentNode.AddMappingEntry(index, 1, values = {"name" : "Type", "type" : 0x05, "access" : "ro", "pdo" : False})
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   580
                self.CurrentNode.AddMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x05, "access" : "ro", "pdo" : False})
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   581
                self.CurrentNode.AddEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   582
                self.CurrentNode.AddEntry(index, 2, length)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   583
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   584
            return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   585
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
            return "Too many User Types have already been defined!"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   589
#                      Modify Entry and Mapping Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   590
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   591
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   592
    def SetCurrentEntryCallbacks(self, index, value):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
            if "callback" not in entry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
                self.CurrentNode.SetParamsEntry(index, None, callback = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
                self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   599
    def SetCurrentEntry(self, index, subIndex, value, name, editor):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   601
            if name == "value":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   602
                if editor == "map":
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   603
                    value = self.CurrentNode.GetMapValue(value)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   604
                    if value:
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   605
                        self.CurrentNode.SetEntry(index, subIndex, value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
                elif editor == "bool":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   607
                    value = value == "True"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   608
                    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
   609
                elif editor == "time":
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   610
                    self.CurrentNode.SetEntry(index, subIndex, value)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   611
                elif editor == "number":
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   612
                    try:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   613
                        self.CurrentNode.SetEntry(index, subIndex, int(value))
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   614
                    except:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   615
                        pass
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   616
                elif editor == "domain":
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   617
                    try:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   618
                        if len(value) % 2 != 0:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   619
                            value = "0" + value
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   620
                        value = value.decode('hex_codec')
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   621
                        self.CurrentNode.SetEntry(index, subIndex, value)
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   622
                    except:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   623
                        pass
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   624
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
                    subentry_infos = self.GetSubentryInfos(index, subIndex)
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   626
                    type = subentry_infos["type"]
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   627
                    dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   628
                    for typeindex, typevalue in CustomisableTypes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   629
                        dic[typeindex] = typevalue
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   630
                    if type not in dic:
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   631
                        type = self.CurrentNode.GetEntry(type)[1]
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   632
                    if dic[type] == 0:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
                        try:
233
6f2936f7fb3f Permitting user to type decimal or hexadecimal for integer values
lbessard
parents: 223
diff changeset
   634
                            if value.startswith("0x"):
6f2936f7fb3f Permitting user to type decimal or hexadecimal for integer values
lbessard
parents: 223
diff changeset
   635
                                value = int(value, 16)
6f2936f7fb3f Permitting user to type decimal or hexadecimal for integer values
lbessard
parents: 223
diff changeset
   636
                            else:
6f2936f7fb3f Permitting user to type decimal or hexadecimal for integer values
lbessard
parents: 223
diff changeset
   637
                                value = int(value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
                            self.CurrentNode.SetEntry(index, subIndex, value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
                        except:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   640
                            pass
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   642
                        self.CurrentNode.SetEntry(index, subIndex, value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   643
            elif name in ["comment", "save"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   644
                if editor == "option":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   645
                    value = value == "Yes"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   646
                if name == "save":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
                    self.CurrentNode.SetParamsEntry(index, subIndex, save = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
                elif name == "comment":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
                    self.CurrentNode.SetParamsEntry(index, subIndex, comment = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   651
                if editor == "type":
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   652
                    value = self.GetTypeIndex(value)
63
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 59
diff changeset
   653
                    size = self.GetEntryInfos(value)["size"]
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 59
diff changeset
   654
                    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
   655
                elif editor in ["access","raccess"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
                    dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
                    for abbrev,access in AccessType.iteritems():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   658
                        dic[access] = abbrev
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   659
                    value = dic[value]
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   660
                    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
   661
                        entry_infos = self.GetEntryInfos(index)
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   662
                        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
   663
                        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
   664
                        self.CurrentNode.AddMappingEntry(index, 1, values = self.GetSubentryInfos(index, 1, False).copy())
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
                self.CurrentNode.SetMappingEntry(index, subIndex, values = {name : value})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
    def SetCurrentEntryName(self, index, name):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
        self.CurrentNode.SetMappingEntry(index, name=name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   671
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   672
    def SetCurrentUserType(self, index, type, min, max, length):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   673
        customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   674
        values, valuetype = self.GetCustomisedTypeValues(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   675
        name, new_valuetype = customisabletypes[type]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   676
        size = self.GetEntryInfos(type)["size"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
        default = self.GetTypeDefaultValue(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   678
        if new_valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   679
            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
   680
            if valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   681
                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
   682
                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
   683
            self.CurrentNode.SetEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   684
            self.CurrentNode.SetEntry(index, 2, min)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   685
            if valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   686
                self.CurrentNode.AddEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   687
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   688
                self.CurrentNode.SetEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   689
        elif new_valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   690
            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
   691
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   692
                self.CurrentNode.SetMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   693
                self.CurrentNode.RemoveMappingEntry(index, 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   694
            self.CurrentNode.SetEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   695
            self.CurrentNode.SetEntry(index, 2, length)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   696
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   697
                self.CurrentNode.RemoveEntry(index, 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   698
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   699
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   700
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   701
#                      Current Buffering Management Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   702
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   703
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   704
    def BufferCurrentNode(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   705
        self.UndoBuffers[self.NodeIndex].Buffering(self.CurrentNode.Copy())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   706
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   707
    def CurrentIsSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   708
        return self.UndoBuffers[self.NodeIndex].IsCurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   709
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   710
    def OneFileHasChanged(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   711
        result = False
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   712
        for buffer in self.UndoBuffers.values():
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   713
            result |= not buffer.IsCurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   714
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   715
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   716
    def GetBufferNumber(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   717
        return len(self.UndoBuffers)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   718
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   719
    def LoadCurrentPrevious(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   720
        self.CurrentNode = self.UndoBuffers[self.NodeIndex].Previous().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   721
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   722
    def LoadCurrentNext(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   723
        self.CurrentNode = self.UndoBuffers[self.NodeIndex].Next().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   724
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   725
    def AddNodeBuffer(self, currentstate = None, issaved = False):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   726
        self.NodeIndex = GetNewId()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   727
        self.UndoBuffers[self.NodeIndex] = UndoBuffer(currentstate, issaved)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   728
        self.FilePaths[self.NodeIndex] = ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   729
        self.FileNames[self.NodeIndex] = ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   730
        return self.NodeIndex
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   731
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   732
    def ChangeCurrentNode(self, index):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   733
        if index in self.UndoBuffers.keys():
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   734
            self.NodeIndex = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   735
            self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   736
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   737
    def RemoveNodeBuffer(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   738
        self.UndoBuffers.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   739
        self.FilePaths.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   740
        self.FileNames.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   741
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   742
    def GetCurrentNodeIndex(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   743
        return self.NodeIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   744
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   745
    def GetCurrentFilename(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   746
        return self.GetFilename(self.NodeIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   747
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   748
    def GetAllFilenames(self):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   749
        indexes = self.UndoBuffers.keys()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   750
        indexes.sort()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   751
        return [self.GetFilename(idx) for idx in indexes]
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   752
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   753
    def GetFilename(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   754
        if self.UndoBuffers[index].IsCurrentSaved():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   755
            return self.FileNames[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   756
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   757
            return "~%s~"%self.FileNames[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   758
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   759
    def SetCurrentFilePath(self, filepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   760
        self.FilePaths[self.NodeIndex] = filepath
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   761
        if filepath == "":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   762
            self.LastNewIndex += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   763
            self.FileNames[self.NodeIndex] = "Unnamed%d"%self.LastNewIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   764
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   765
            self.FileNames[self.NodeIndex] = os.path.splitext(os.path.basename(filepath))[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   766
                
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   767
    def GetCurrentFilePath(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   768
        if len(self.FilePaths) > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   769
            return self.FilePaths[self.NodeIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   770
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   771
            return ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   772
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   773
    def GetCurrentBufferState(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   774
        first = self.UndoBuffers[self.NodeIndex].IsFirst()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   775
        last = self.UndoBuffers[self.NodeIndex].IsLast()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   776
        return not first, not last
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   777
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   778
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   779
#                         Profiles Management Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   780
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   781
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   782
    def GetCurrentCommunicationLists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   783
        list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   784
        for index in MappingDictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   785
            if 0x1000 <= index < 0x1200:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   786
                list.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   787
        return self.GetProfileLists(MappingDictionary, list)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   788
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   789
    def GetCurrentDS302Lists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   790
        return self.GetSpecificProfileLists(self.CurrentNode.GetDS302Profile())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   791
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   792
    def GetCurrentProfileLists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   793
        return self.GetSpecificProfileLists(self.CurrentNode.GetProfile())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   794
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   795
    def GetSpecificProfileLists(self, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   796
        validlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   797
        exclusionlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   798
        for name, list in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   799
            exclusionlist.extend(list)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   800
        for index in mappingdictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   801
            if index not in exclusionlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   802
                validlist.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   803
        return self.GetProfileLists(mappingdictionary, validlist)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   804
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   805
    def GetProfileLists(self, mappingdictionary, list):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   806
        dictionary = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   807
        current = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   808
        for index in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   809
            dictionary[index] = (mappingdictionary[index]["name"], mappingdictionary[index]["need"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   810
            if self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   811
                current.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   812
        return dictionary, current
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   813
39
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   814
    def GetCurrentNextMapIndex(self):
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   815
        if self.CurrentNode:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   816
            index = 0x2000
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   817
            while self.CurrentNode.IsEntry(index) and index < 0x5FFF:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   818
                index += 1
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   819
            if index < 0x6000:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   820
                return index
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   821
            else:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   822
                return None
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   823
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   824
    def CurrentDS302Defined(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   825
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   826
            return len(self.CurrentNode.GetDS302Profile()) > 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   827
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   828
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   829
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   830
#                         Node State and Values Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   831
#-------------------------------------------------------------------------------
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   832
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   833
    def GetCurrentNodeName(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   834
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   835
            return self.CurrentNode.GetNodeName()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   836
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   837
            return ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   838
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   839
    def GetCurrentNodeID(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   840
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   841
            return self.CurrentNode.GetNodeID()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   842
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   843
            return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   844
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   845
    def GetCurrentNodeInfos(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   846
        name = self.CurrentNode.GetNodeName()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   847
        id = self.CurrentNode.GetNodeID()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   848
        type = self.CurrentNode.GetNodeType()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   849
        description = self.CurrentNode.GetNodeDescription()
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   850
        return name, id, type, description
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   851
        
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   852
    def SetCurrentNodeInfos(self, name, id, type, description):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   853
        self.CurrentNode.SetNodeName(name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   854
        self.CurrentNode.SetNodeID(id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   855
        self.CurrentNode.SetNodeType(type)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   856
        self.CurrentNode.SetNodeDescription(description)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   857
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   858
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   859
    def GetCurrentProfileName(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   860
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   861
            return self.CurrentNode.GetProfileName()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   862
        return ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   863
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   864
    def IsCurrentEntry(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   865
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   866
            return self.CurrentNode.IsEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   867
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   868
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   869
    def GetCurrentEntry(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   870
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   871
            return self.CurrentNode.GetEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   872
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   873
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   874
    def GetCurrentParamsEntry(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   875
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   876
            return self.CurrentNode.GetParamsEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   877
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   878
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   879
    def GetCurrentValidIndexes(self, min, max):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   880
        validindexes = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   881
        for index in self.CurrentNode.GetIndexes():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   882
            if min <= index <= max:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   883
                validindexes.append((self.GetEntryName(index), index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   884
        return validindexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   885
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   886
    def GetCurrentValidChoices(self, min, max):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   887
        validchoices = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   888
        exclusionlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   889
        for menu, indexes in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   890
            exclusionlist.extend(indexes)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   891
            good = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   892
            for index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   893
                good &= min <= index <= max
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   894
            if good:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   895
                validchoices.append((menu, None))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   896
        list = [index for index in MappingDictionary.keys() if index >= 0x1000]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   897
        profiles = self.CurrentNode.GetMappings(False)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   898
        for profile in profiles:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   899
            list.extend(profile.keys())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   900
        list.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   901
        for index in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   902
            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
   903
                validchoices.append((self.GetEntryName(index), index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   904
        return validchoices
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   905
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   906
    def HasCurrentEntryCallbacks(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   907
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   908
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   909
            if "callback" in entry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   910
                return entry_infos["callback"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   911
            return self.CurrentNode.HasEntryCallbacks(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   912
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   913
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   914
    def GetCurrentEntryValues(self, index):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   915
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   916
            return self.GetNodeEntryValues(self.CurrentNode, index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   917
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   918
    def GetNodeEntryValues(self, node, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   919
        if node and node.IsEntry(index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   920
            entry_infos = node.GetEntryInfos(index)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   921
            data = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   922
            editors = []
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   923
            values = node.GetEntry(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   924
            params = node.GetParamsEntry(index)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   925
            if type(values) == ListType:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   926
                for i, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   927
                    data.append({"value" : value})
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   928
                    data[-1].update(params[i])      
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   929
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   930
                data.append({"value" : values})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   931
                data[-1].update(params)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   932
            for i, dic in enumerate(data):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   933
                infos = node.GetSubentryInfos(index, i)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   934
                dic["subindex"] = "0x%02X"%i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   935
                dic["name"] = infos["name"]
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   936
                dic["type"] = node.GetTypeName(infos["type"])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   937
                dic["access"] = AccessType[infos["access"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   938
                dic["save"] = OptionType[dic["save"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   939
                editor = {"subindex" : None, "save" : "option", "callback" : "option", "comment" : "string"}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   940
                if type(values) == ListType and i == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   941
                    editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   942
                    editor["type"] = None
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   943
                    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
   944
                        editor["access"] = "raccess"
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   945
                    else:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   946
                        editor["access"] = None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   947
                    editor["value"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   948
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   949
                    if infos["user_defined"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   950
                        if entry_infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   951
                            editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   952
                            if i > 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   953
                                editor["type"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   954
                                editor["access"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   955
                            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   956
                                editor["type"] = "type"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   957
                                editor["access"] = "access"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   958
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   959
                            if entry_infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   960
                                editor["name"] = "string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   961
                            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   962
                                editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   963
                            editor["type"] = "type"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   964
                            editor["access"] = "access"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   965
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   966
                        editor["name"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   967
                        editor["type"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   968
                        editor["access"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   969
                    if index < 0x260:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   970
                        editor["value"] = None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   971
                        if i == 1:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   972
                            dic["value"] = node.GetTypeName(dic["value"])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   973
                    elif 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   974
                        editor["value"] = "map"
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   975
                        dic["value"] = node.GetMapName(dic["value"])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   976
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   977
                        if dic["type"].startswith("VISIBLE_STRING"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   978
                            editor["value"] = "string"
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   979
                        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
   980
                            editor["value"] = "time"
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   981
                        elif dic["type"] == "DOMAIN":
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   982
                            editor["value"] = "domain"
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   983
                            dic["value"] = dic["value"].encode('hex_codec')
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   984
                        elif dic["type"] == "BOOLEAN":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   985
                            editor["value"] = "bool"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   986
                            dic["value"] = BoolType[dic["value"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   987
                        result = type_model.match(dic["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   988
                        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   989
                            values = result.groups()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   990
                            if values[0] == "UNSIGNED":
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   991
                                format = "0x%0" + str(int(values[1])/4) + "X"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   992
                                dic["value"] = format%dic["value"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   993
                                editor["value"] = "string"
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   994
                            if values[0] == "INTEGER":
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   995
                                editor["value"] = "number"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   996
                            elif values[0] == "REAL":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   997
                                editor["value"] = "float"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   998
                            elif values[0] == "VISIBLE_STRING":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   999
                                editor["length"] = values[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1000
                        result = range_model.match(dic["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1001
                        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1002
                            values = result.groups()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1003
                            if values[0] in ["UNSIGNED", "INTEGER", "REAL"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1004
                                editor["min"] = values[2]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1005
                                editor["max"] = values[3]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1006
                editors.append(editor)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1007
            return data, editors
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1008
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1009
            return None
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1010
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1011
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1012
#                         Node Informations Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1013
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1014
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1015
    def GetCustomisedTypeValues(self, index):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1016
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1017
            values = self.CurrentNode.GetEntry(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1018
            customisabletypes = self.GetCustomisableTypes()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1019
            return values, customisabletypes[values[1]][1]
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1020
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1021
            return None, None
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1022
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1023
    def GetEntryName(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1024
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1025
            return self.CurrentNode.GetEntryName(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1026
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1027
            return FindEntryName(index, MappingDictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1028
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1029
    def GetEntryInfos(self, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1030
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1031
            return self.CurrentNode.GetEntryInfos(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1032
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1033
            return FindEntryInfos(index, MappingDictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1034
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1035
    def GetSubentryInfos(self, index, subindex):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1036
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1037
            return self.CurrentNode.GetSubentryInfos(index, subindex)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1038
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1039
            result = FindSubentryInfos(index, subindex, MappingDictionary)
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1040
            if result:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1041
                result["user_defined"] = False
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1042
            return result
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1043
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1044
    def GetTypeIndex(self, typename):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1045
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1046
            return self.CurrentNode.GetTypeIndex(typename)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1047
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1048
            return FindTypeIndex(typename, MappingDictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1049
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1050
    def GetTypeName(self, typeindex):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1051
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1052
            return self.CurrentNode.GetTypeName(typeindex)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1053
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1054
            return FindTypeName(typeindex, MappingDictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1055
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1056
    def GetTypeDefaultValue(self, typeindex):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1057
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1058
            return self.CurrentNode.GetTypeDefaultValue(typeindex)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1059
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1060
            return FindTypeDefaultValue(typeindex, MappingDictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1061
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1062
    def GetMapVariableList(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1063
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1064
            return self.CurrentNode.GetMapVariableList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1065
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1066
            return []
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1067
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1068
    def GetMandatoryIndexes(self, node = None):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1069
        if self.CurrentNode:
220
b7fb826c66d9 Bug on NodeManager corrected :
lbessard
parents: 205
diff changeset
  1070
            return self.CurrentNode.GetMandatoryIndexes()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1071
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1072
            return FindMandatoryIndexes(MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1073
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1074
    def GetCustomisableTypes(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1075
        dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1076
        for index, valuetype in CustomisableTypes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1077
            name = self.GetTypeName(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1078
            dic[index] = [name, valuetype]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1079
        return dic
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1080
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1081
    def GetCurrentSpecificMenu(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1082
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1083
            return self.CurrentNode.GetSpecificMenu()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1084
        return []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1085