objdictgen/nodemanager.py
author edouard
Fri, 10 Sep 2010 13:43:17 +0200
changeset 625 5482b98e82a3
parent 584 e23359f62023
child 762 4b60a0d313b0
permissions -rwxr-xr-x
Fix non freed windows handle. (thx to jaroslav.fojtik)
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
    """
258
8f7725451453 Some bugs fixed:
lbessard
parents: 254
diff changeset
   153
    def __init__(self):
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
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   159
        self.UndoBuffers = {}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
#                         Type and Map Variable Lists
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
#-------------------------------------------------------------------------------
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
    Return the list of types defined for the current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
    def GetCurrentTypeList(self):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   169
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   170
            return self.CurrentNode.GetTypeList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   171
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   172
            return ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
    Return the list of variables that can be mapped for the current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
    def GetCurrentMapList(self):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   178
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   179
            return self.CurrentNode.GetMapList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   180
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   181
            return ""
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
#                        Create Load and Save Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
    Create a new node and add a new buffer for storing it
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   190
    def CreateNewNode(self, name, id, type, description, profile, filepath, NMT, options):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
        # Create a new node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
        node = Node()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
        # Try to load profile given
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
        result = self.LoadProfile(profile, filepath, node)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   195
        if not result:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
            # if success, initialising node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
            self.CurrentNode = node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
            self.CurrentNode.SetNodeName(name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
            self.CurrentNode.SetNodeID(id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
            self.CurrentNode.SetNodeType(type)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   201
            self.CurrentNode.SetNodeDescription(description)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
            AddIndexList = self.GetMandatoryIndexes()
492
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   203
            AddSubIndexList = []
0
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":
258
8f7725451453 Some bugs fixed:
lbessard
parents: 254
diff changeset
   210
                    DS302Path = os.path.join(os.path.split(__file__)[0], "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:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   218
                            return _("Problem with DS-302! Syntax Error.")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
                    else:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   220
                        return _("Couldn't find DS-302 in 'config' folder!")
0
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])
487
7292e686f1ab Automatic SDO server added when creating new slave node.
etisserant
parents: 485
diff changeset
   229
            if type == "slave":
7292e686f1ab Automatic SDO server added when creating new slave node.
etisserant
parents: 485
diff changeset
   230
                # add default SDO server
492
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   231
                AddIndexList.append(0x1200)
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   232
                # add default 4 receive and 4 transmit PDO
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   233
                for comm, mapping in [(0x1400, 0x1600),(0x1800, 0x1A00)]:
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   234
                    firstparamindex = self.GetLineFromIndex(comm)
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   235
                    firstmappingindex = self.GetLineFromIndex(mapping)
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   236
                    AddIndexList.extend(range(firstparamindex, firstparamindex + 4))
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   237
                    for idx in range(firstmappingindex, firstmappingindex + 4):
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   238
                        AddIndexList.append(idx)
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   239
                        AddSubIndexList.append((idx, 8))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
            # Add a new buffer 
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 239
diff changeset
   241
            index = self.AddNodeBuffer(self.CurrentNode.Copy(), False)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
            self.SetCurrentFilePath("")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
            # Add Mandatory indexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
            self.ManageEntriesOfCurrent(AddIndexList, [])
492
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   245
            for idx, num in AddSubIndexList:
b919a24a45cb Fixed automatic SDO server creation for slave
etisserant
parents: 490
diff changeset
   246
                self.AddSubentriesToCurrent(idx, num)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   247
            return index
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
            return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
    Load a profile in node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
    def LoadProfile(self, profile, filepath, node):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
        if profile != "None":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
            # Try to charge the profile given
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
            try:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
                execfile(filepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
                node.SetProfileName(profile)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
                node.SetProfile(Mapping)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
                node.SetSpecificMenu(AddMenuEntries)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   262
                return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
            except:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   264
                return _("Syntax Error\nBad OD Profile file!")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
            # Default profile
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
            node.SetProfileName("None")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
            node.SetProfile({})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
            node.SetSpecificMenu([])
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   270
            return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
    Open a file and store it in a new buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
    def OpenFileInCurrent(self, filepath):
268
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   276
        try:
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   277
            # Open and load file
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   278
            file = open(filepath, "r")
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   279
            node = load(file)
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   280
            file.close()
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   281
            self.CurrentNode = node
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   282
            self.CurrentNode.SetNodeID(0)
268
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   283
            # Add a new buffer and defining current state
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   284
            index = self.AddNodeBuffer(self.CurrentNode.Copy(), True)
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   285
            self.SetCurrentFilePath(filepath)
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   286
            return index
8a21eb5bdedc Bug on Load Project fixed
lbessard
parents: 258
diff changeset
   287
        except:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   288
            return _("Unable to load file \"%s\"!")%filepath
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
    Save current node in  a file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
    def SaveCurrentInFile(self, filepath = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
        # if no filepath given, verify if current node has a filepath defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
        if not filepath:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
            filepath = self.GetCurrentFilePath()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
            if filepath == "":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
                return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
        # Save node in file
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
        file = open(filepath, "w")
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
        dump(self.CurrentNode, file)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
        file.close()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
        self.SetCurrentFilePath(filepath)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
        # Update saved state in buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
        self.UndoBuffers[self.NodeIndex].CurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
        return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
    Close current state
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
    def CloseCurrent(self, ignore = False):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
        # Verify if it's not forced that the current node is saved before closing it
490
305d75028630 Adding support for modification in CanFestival eds_utils
lbessard
parents: 487
diff changeset
   313
        if self.NodeIndex in self.UndoBuffers and (self.UndoBuffers[self.NodeIndex].IsCurrentSaved() or ignore):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
            self.RemoveNodeBuffer(self.NodeIndex)
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   315
            if len(self.UndoBuffers) > 0:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   316
                previousindexes = [idx for idx in self.UndoBuffers.keys() if idx < self.NodeIndex]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   317
                nextindexes = [idx for idx in self.UndoBuffers.keys() if idx > self.NodeIndex]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   318
                if len(previousindexes) > 0:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   319
                    previousindexes.sort()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   320
                    self.NodeIndex = previousindexes[-1]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   321
                elif len(nextindexes) > 0:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   322
                    nextindexes.sort()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   323
                    self.NodeIndex = nextindexes[0]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   324
                else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   325
                    self.NodeIndex = None
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   326
            else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   327
                self.NodeIndex = None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
            return True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   332
    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
   333
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   334
    def ImportCurrentFromEDSFile(self, filepath):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
        # Generate node from definition in a xml file
258
8f7725451453 Some bugs fixed:
lbessard
parents: 254
diff changeset
   336
        result = eds_utils.GenerateNode(filepath)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   337
        if isinstance(result, Node):
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   338
            self.CurrentNode = result
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 239
diff changeset
   339
            index = self.AddNodeBuffer(self.CurrentNode.Copy(), False)
223
461f5516176b Bug on Domain data writing in gen_cfile fixed
lbessard
parents: 220
diff changeset
   340
            self.SetCurrentFilePath("")
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   341
            return index
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   342
        else:
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   343
            return result
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   344
    
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   345
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   346
    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
   347
    """
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   348
    def ExportCurrentToEDSFile(self, filepath):
490
305d75028630 Adding support for modification in CanFestival eds_utils
lbessard
parents: 487
diff changeset
   349
        return eds_utils.GenerateEDSFile(filepath, self.CurrentNode)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
    Build the C definition of Object Dictionary for current node 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
    """
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   354
    def ExportCurrentToCFile(self, filepath):
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 244
diff changeset
   355
        if self.CurrentNode:
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 244
diff changeset
   356
            return gen_cfile.GenerateFile(filepath, self.CurrentNode)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
#                        Add Entries to Current Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
    Add the specified number of subentry for the given entry. Verify that total
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
    number of subentry (except 0) doesn't exceed nbmax defined
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
    """
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   366
    def AddSubentriesToCurrent(self, index, number, node = None):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 245
diff changeset
   367
        disable_buffer = node != None
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   368
        if node == None:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 245
diff changeset
   369
            node = self.CurrentNode
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
        # Informations about entry
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   371
        length = node.GetEntry(index, 0)
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   372
        infos = node.GetEntryInfos(index)
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   373
        subentry_infos = node.GetSubentryInfos(index, 1)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
        # Get default value for subindex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
        if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
            default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
            default = self.GetTypeDefaultValue(subentry_infos["type"])   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
        # First case entry is record
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   380
        if infos["struct"] & OD_IdenticalSubindexes: 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
            for i in xrange(1, min(number,subentry_infos["nbmax"]-length) + 1):
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   382
                node.AddEntry(index, length + i, default)
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   383
            if not disable_buffer:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 244
diff changeset
   384
                self.BufferCurrentNode()
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   385
            return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
        # Second case entry is array, only possible for manufacturer specific
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
        elif infos["struct"] & OD_MultipleSubindexes and 0x2000 <= index <= 0x5FFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
            values = {"name" : "Undefined", "type" : 5, "access" : "rw", "pdo" : True}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
            for i in xrange(1, min(number,0xFE-length) + 1):
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   390
                node.AddMappingEntry(index, length + i, values = values.copy())
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   391
                node.AddEntry(index, length + i, 0)
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   392
            if not disable_buffer:
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 244
diff changeset
   393
                self.BufferCurrentNode()
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   394
            return None
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   395
            
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
    Remove the specified number of subentry for the given entry. Verify that total
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
    number of subentry (except 0) isn't less than 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
    def RemoveSubentriesFromCurrent(self, index, number):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
        # Informations about entry
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
        infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
        length = self.CurrentNode.GetEntry(index, 0)
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   405
        if "nbmin" in infos:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   406
            nbmin = infos["nbmin"]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   407
        else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   408
            nbmin = 1
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
        # Entry is a record, or is an array of manufacturer specific
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
        if infos["struct"] & OD_IdenticalSubindexes or 0x2000 <= index <= 0x5FFF and infos["struct"] & OD_IdenticalSubindexes:
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   411
            for i in xrange(min(number, length - nbmin)):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
                self.RemoveCurrentVariable(index, length - i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
    Add a SDO Server to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
    def AddSDOServerToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
        # An SDO Server is already defined at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
        if self.CurrentNode.IsEntry(0x1200):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
            indexlist = [self.GetLineFromIndex(0x1201)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
            if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
                self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
        # Add an SDO Server at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
            self.ManageEntriesOfCurrent([0x1200], [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
    Add a SDO Server to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
    def AddSDOClientToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
        indexlist = [self.GetLineFromIndex(0x1280)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
    Add a Transmit PDO to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
    def AddPDOTransmitToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
        indexlist = [self.GetLineFromIndex(0x1800),self.GetLineFromIndex(0x1A00)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
    Add a Receive PDO to current node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   446
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
    def AddPDOReceiveToCurrent(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
        indexlist = [self.GetLineFromIndex(0x1400),self.GetLineFromIndex(0x1600)]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
    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
   454
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
    def AddSpecificEntryToCurrent(self, menuitem):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
        indexlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
        for menu, indexes in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
            if menuitem == menu:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
                for index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
                    indexlist.append(self.GetLineFromIndex(index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
        if None not in indexlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
            self.ManageEntriesOfCurrent(indexlist, [])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
    Search the first index available for a pluri entry from base_index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
    def GetLineFromIndex(self, base_index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
        found = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
        index = base_index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
        infos = self.GetEntryInfos(base_index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
        while index < base_index + infos["incr"]*infos["nbmax"] and not found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
            if not self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
                found = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
                index += infos["incr"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
        if found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
            return index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
    Add entries specified in addinglist and remove entries specified in removinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
    """
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   483
    def ManageEntriesOfCurrent(self, addinglist, removinglist, node = None):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 245
diff changeset
   484
        disable_buffer = node != None
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   485
        if node == None:
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   486
            node = self.CurrentNode
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
        # Add all the entries in addinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
        for index in addinglist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
            infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
            if infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
                # First case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
                if infos["struct"] & OD_IdenticalSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
                    subentry_infos = self.GetSubentryInfos(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   494
                    if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   495
                        default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   496
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   497
                        default = self.GetTypeDefaultValue(subentry_infos["type"])
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   498
                    node.AddEntry(index, value = [])
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   499
                    if "nbmin" in subentry_infos:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   500
                        for i in xrange(subentry_infos["nbmin"]):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   501
                            node.AddEntry(index, i + 1, default)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   502
                    else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   503
                        node.AddEntry(index, 1, default)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
                # Second case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
                    i = 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
                    subentry_infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
                    while subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
                        if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
                            default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   511
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   512
                            default = self.GetTypeDefaultValue(subentry_infos["type"])
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   513
                        node.AddEntry(index, i, default)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   514
                        i += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
                        subentry_infos = self.GetSubentryInfos(index, i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
            # Third case entry is a record
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
                subentry_infos = self.GetSubentryInfos(index, 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
                if "default" in subentry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
                    default = subentry_infos["default"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
                    default = self.GetTypeDefaultValue(subentry_infos["type"])
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   523
                node.AddEntry(index, 0, default)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
        # Remove all the entries in removinglist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
        for index in removinglist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
            self.RemoveCurrentVariable(index)
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   527
        if not disable_buffer:
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   528
            self.BufferCurrentNode()
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   529
        return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   530
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   531
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
    """
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   533
    Reset an subentry from current node to its default value
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   534
    """
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   535
    def SetCurrentEntryToDefault(self, index, subindex, node = None):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   536
        disable_buffer = node != None
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   537
        if node == None:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   538
            node = self.CurrentNode
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   539
        if node.IsEntry(index, subindex):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   540
            subentry_infos = self.GetSubentryInfos(index, subindex)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   541
            if "default" in subentry_infos:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   542
                default = subentry_infos["default"]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   543
            else:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   544
                default = self.GetTypeDefaultValue(subentry_infos["type"])
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   545
            node.SetEntry(index, subindex, default)
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   546
            if not disable_buffer:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   547
                self.BufferCurrentNode()
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   548
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   549
    """
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
    Remove an entry from current node. Analize the index to perform the correct
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
    method
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
    """
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
    def RemoveCurrentVariable(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
        Mappings = self.CurrentNode.GetMappings()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
        if index < 0x1000 and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
            type = self.CurrentNode.GetEntry(index, 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
            for i in Mappings[-1]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   558
                for value in Mappings[-1][i]["values"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
                    if value["type"] == index:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
                        value["type"] = type
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
            self.CurrentNode.RemoveMappingEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
            self.CurrentNode.RemoveEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
        elif index == 0x1200 and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   564
            self.CurrentNode.RemoveEntry(0x1200)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
        elif 0x1201 <= index <= 0x127F and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   566
            self.CurrentNode.RemoveLine(index, 0x127F)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   567
        elif 0x1280 <= index <= 0x12FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
            self.CurrentNode.RemoveLine(index, 0x12FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
        elif 0x1400 <= index <= 0x15FF or 0x1600 <= index <= 0x17FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   570
            if 0x1600 <= index <= 0x17FF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   571
                index -= 0x200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   572
            self.CurrentNode.RemoveLine(index, 0x15FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   573
            self.CurrentNode.RemoveLine(index + 0x200, 0x17FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   574
        elif 0x1800 <= index <= 0x19FF or 0x1A00 <= index <= 0x1BFF and subIndex == None:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   575
            if 0x1A00 <= index <= 0x1BFF:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   576
                index -= 0x200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   577
            self.CurrentNode.RemoveLine(index, 0x19FF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   578
            self.CurrentNode.RemoveLine(index + 0x200, 0x1BFF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   579
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   580
            found = False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   581
            for menu,list in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   582
                for i in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   583
                    iinfos = self.GetEntryInfos(i)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   584
                    indexes = [i + incr * iinfos["incr"] for incr in xrange(iinfos["nbmax"])] 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   585
                    if index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
                        found = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
                        diff = index - i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
                        for j in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   589
                            jinfos = self.GetEntryInfos(j)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   590
                            self.CurrentNode.RemoveLine(j + diff, j + jinfos["incr"]*jinfos["nbmax"], jinfos["incr"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   591
            self.CurrentNode.RemoveMapVariable(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   592
            if not found:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
                infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
                if not infos["need"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
                    self.CurrentNode.RemoveEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
            if index in Mappings[-1]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
                self.CurrentNode.RemoveMappingEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   599
    def AddMapVariableToCurrent(self, index, name, struct, number, node = None):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
        if 0x2000 <= index <= 0x5FFF:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 245
diff changeset
   601
            disable_buffer = node != None
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   602
            if node == None:
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   603
                node = self.CurrentNode
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   604
            if not node.IsEntry(index):
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   605
                node.AddMappingEntry(index, name = name, struct = struct)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
                if struct == var:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   607
                    values = {"name" : name, "type" : 0x05, "access" : "rw", "pdo" : True}
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   608
                    node.AddMappingEntry(index, 0, values = values)
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   609
                    node.AddEntry(index, 0, 0)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   610
                else:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   611
                    values = {"name" : "Number of Entries", "type" : 0x05, "access" : "ro", "pdo" : False}
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   612
                    node.AddMappingEntry(index, 0, values = values)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   613
                    if struct == rec:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   614
                        values = {"name" : name + " %d[(sub)]", "type" : 0x05, "access" : "rw", "pdo" : True, "nbmax" : 0xFE}
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   615
                        node.AddMappingEntry(index, 1, values = values)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   616
                        for i in xrange(number):
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   617
                            node.AddEntry(index, i + 1, 0)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   618
                    else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   619
                        for i in xrange(number):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   620
                            values = {"name" : "Undefined", "type" : 0x05, "access" : "rw", "pdo" : True}
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   621
                            node.AddMappingEntry(index, i + 1, values = values)
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   622
                            node.AddEntry(index, i + 1, 0)
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   623
                if not disable_buffer:
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   624
                    self.BufferCurrentNode()
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
                return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   626
            else:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   627
                return _("Index 0x%04X already defined!")%index
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   628
        else:
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   629
            return _("Index 0x%04X isn't a valid index for Map Variable!")%index
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   630
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   631
    def AddUserTypeToCurrent(self, type, min, max, length):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   632
        index = 0xA0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
        while index < 0x100 and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   634
            index += 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   635
        if index < 0x100:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   636
            customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   637
            name, valuetype = customisabletypes[type]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
            size = self.GetEntryInfos(type)["size"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
            default = self.GetTypeDefaultValue(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   640
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
                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
   642
                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
   643
                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
   644
                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
   645
                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
   646
                self.CurrentNode.AddEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
                self.CurrentNode.AddEntry(index, 2, min)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
                self.CurrentNode.AddEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
            elif valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
                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
   651
                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
   652
                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
   653
                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
   654
                self.CurrentNode.AddEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   655
                self.CurrentNode.AddEntry(index, 2, length)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
            self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
            return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   658
        else:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   659
            return _("Too many User Types have already been defined!")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   660
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   661
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   662
#                      Modify Entry and Mapping Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   663
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   664
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
    def SetCurrentEntryCallbacks(self, index, value):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
        if self.CurrentNode and self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
            entry_infos = self.GetEntryInfos(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
            if "callback" not in entry_infos:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
                self.CurrentNode.SetParamsEntry(index, None, callback = value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
                self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   671
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   672
    def SetCurrentEntry(self, index, subIndex, value, name, editor, node = None):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 245
diff changeset
   673
        disable_buffer = node != None
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   674
        if node == None:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 245
diff changeset
   675
            node = self.CurrentNode
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   676
        if node and node.IsEntry(index):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
            if name == "value":
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 239
diff changeset
   678
                if editor == "map":
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   679
                    value = node.GetMapValue(value)
545
ff692766e5e9 Remove deletion PDO when mapping undefined in export to EDS
lbessard
parents: 512
diff changeset
   680
                    if value is not None:
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   681
                        node.SetEntry(index, subIndex, value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   682
                elif editor == "bool":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   683
                    value = value == "True"
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   684
                    node.SetEntry(index, subIndex, value)
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   685
                elif editor == "time":
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   686
                    node.SetEntry(index, subIndex, value)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   687
                elif editor == "number":
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   688
                    try:
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   689
                        node.SetEntry(index, subIndex, int(value))
188
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   690
                    except:
00245bc2e6fe Bugs on C File generating corrected
lbessard
parents: 182
diff changeset
   691
                        pass
453
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 418
diff changeset
   692
                elif editor == "float":
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 418
diff changeset
   693
                    try:
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 418
diff changeset
   694
                        node.SetEntry(index, subIndex, float(value))
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 418
diff changeset
   695
                    except:
c74a73474cce Problem with Real types unsupported fixed
lbessard
parents: 418
diff changeset
   696
                        pass
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   697
                elif editor == "domain":
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   698
                    try:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   699
                        if len(value) % 2 != 0:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   700
                            value = "0" + value
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   701
                        value = value.decode('hex_codec')
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   702
                        node.SetEntry(index, subIndex, value)
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   703
                    except:
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
   704
                        pass
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
   705
                elif editor == "dcf":
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
   706
                    node.SetEntry(index, subIndex, value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   707
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   708
                    subentry_infos = self.GetSubentryInfos(index, subIndex)
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   709
                    type = subentry_infos["type"]
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   710
                    dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   711
                    for typeindex, typevalue in CustomisableTypes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   712
                        dic[typeindex] = typevalue
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   713
                    if type not in dic:
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   714
                        type = node.GetEntry(type)[1]
30
a5dd050b28cb Some bugs found corrected
lbessard
parents: 0
diff changeset
   715
                    if dic[type] == 0:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   716
                        try:
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   717
                            if value.startswith("$NODEID"):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   718
                                value = "\"%s\""%value
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   719
                            elif value.startswith("0x"):
233
6f2936f7fb3f Permitting user to type decimal or hexadecimal for integer values
lbessard
parents: 223
diff changeset
   720
                                value = int(value, 16)
6f2936f7fb3f Permitting user to type decimal or hexadecimal for integer values
lbessard
parents: 223
diff changeset
   721
                            else:
6f2936f7fb3f Permitting user to type decimal or hexadecimal for integer values
lbessard
parents: 223
diff changeset
   722
                                value = int(value)
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   723
                            node.SetEntry(index, subIndex, value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   724
                        except:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   725
                            pass
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   726
                    else:
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   727
                        node.SetEntry(index, subIndex, value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   728
            elif name in ["comment", "save"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   729
                if editor == "option":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   730
                    value = value == "Yes"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   731
                if name == "save":
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   732
                    node.SetParamsEntry(index, subIndex, save = value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   733
                elif name == "comment":
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   734
                    node.SetParamsEntry(index, subIndex, comment = value)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   735
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   736
                if editor == "type":
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   737
                    value = self.GetTypeIndex(value)
63
2be18e405e40 Bug on map variable type changing and on comments with special characters corrected
lbessard
parents: 59
diff changeset
   738
                    size = self.GetEntryInfos(value)["size"]
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   739
                    node.UpdateMapVariable(index, subIndex, size)
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   740
                elif editor in ["access","raccess"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   741
                    dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   742
                    for abbrev,access in AccessType.iteritems():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   743
                        dic[access] = abbrev
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   744
                    value = dic[value]
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   745
                    if editor == "raccess" and not node.IsMappingEntry(index):
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
   746
                        entry_infos = self.GetEntryInfos(index)
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
   747
                        subIndex0_infos = self.GetSubentryInfos(index, 0, False).copy()
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
   748
                        subIndex1_infos = self.GetSubentryInfos(index, 1, False).copy()
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   749
                        node.AddMappingEntry(index, name = entry_infos["name"], struct = 7)
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
   750
                        node.AddMappingEntry(index, 0, values = subIndex0_infos)
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
   751
                        node.AddMappingEntry(index, 1, values = subIndex1_infos)
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   752
                node.SetMappingEntry(index, subIndex, values = {name : value})
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   753
            if not disable_buffer:
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   754
                self.BufferCurrentNode()
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   755
            return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   756
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   757
    def SetCurrentEntryName(self, index, name):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   758
        self.CurrentNode.SetMappingEntry(index, name=name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   759
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   760
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   761
    def SetCurrentUserType(self, index, type, min, max, length):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   762
        customisabletypes = self.GetCustomisableTypes()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   763
        values, valuetype = self.GetCustomisedTypeValues(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   764
        name, new_valuetype = customisabletypes[type]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   765
        size = self.GetEntryInfos(type)["size"]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   766
        default = self.GetTypeDefaultValue(type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   767
        if new_valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   768
            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
   769
            if valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   770
                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
   771
                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
   772
            self.CurrentNode.SetEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   773
            self.CurrentNode.SetEntry(index, 2, min)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   774
            if valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   775
                self.CurrentNode.AddEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   776
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   777
                self.CurrentNode.SetEntry(index, 3, max)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   778
        elif new_valuetype == 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   779
            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
   780
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   781
                self.CurrentNode.SetMappingEntry(index, 2, values = {"name" : "Length", "type" : 0x02, "access" : "ro", "pdo" : False})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   782
                self.CurrentNode.RemoveMappingEntry(index, 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   783
            self.CurrentNode.SetEntry(index, 1, type)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   784
            self.CurrentNode.SetEntry(index, 2, length)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   785
            if valuetype == 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   786
                self.CurrentNode.RemoveEntry(index, 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   787
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   788
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   789
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   790
#                      Current Buffering Management Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   791
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   792
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   793
    def BufferCurrentNode(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   794
        self.UndoBuffers[self.NodeIndex].Buffering(self.CurrentNode.Copy())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   795
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   796
    def CurrentIsSaved(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   797
        return self.UndoBuffers[self.NodeIndex].IsCurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   798
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   799
    def OneFileHasChanged(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   800
        result = False
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   801
        for buffer in self.UndoBuffers.values():
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   802
            result |= not buffer.IsCurrentSaved()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   803
        return result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   804
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   805
    def GetBufferNumber(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   806
        return len(self.UndoBuffers)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   807
485
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   808
    def GetBufferIndexes(self):
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   809
        return self.UndoBuffers.keys()
24b506ea314b Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents: 453
diff changeset
   810
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   811
    def LoadCurrentPrevious(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   812
        self.CurrentNode = self.UndoBuffers[self.NodeIndex].Previous().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   813
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   814
    def LoadCurrentNext(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   815
        self.CurrentNode = self.UndoBuffers[self.NodeIndex].Next().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   816
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   817
    def AddNodeBuffer(self, currentstate = None, issaved = False):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   818
        self.NodeIndex = GetNewId()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   819
        self.UndoBuffers[self.NodeIndex] = UndoBuffer(currentstate, issaved)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   820
        self.FilePaths[self.NodeIndex] = ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   821
        self.FileNames[self.NodeIndex] = ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   822
        return self.NodeIndex
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   823
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   824
    def ChangeCurrentNode(self, index):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   825
        if index in self.UndoBuffers.keys():
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   826
            self.NodeIndex = index
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   827
            self.CurrentNode = self.UndoBuffers[self.NodeIndex].Current().Copy()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   828
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   829
    def RemoveNodeBuffer(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   830
        self.UndoBuffers.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   831
        self.FilePaths.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   832
        self.FileNames.pop(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   833
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   834
    def GetCurrentNodeIndex(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   835
        return self.NodeIndex
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   836
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   837
    def GetCurrentFilename(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   838
        return self.GetFilename(self.NodeIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   839
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   840
    def GetAllFilenames(self):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   841
        indexes = self.UndoBuffers.keys()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   842
        indexes.sort()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   843
        return [self.GetFilename(idx) for idx in indexes]
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   844
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   845
    def GetFilename(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   846
        if self.UndoBuffers[index].IsCurrentSaved():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   847
            return self.FileNames[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   848
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   849
            return "~%s~"%self.FileNames[index]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   850
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   851
    def SetCurrentFilePath(self, filepath):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   852
        self.FilePaths[self.NodeIndex] = filepath
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   853
        if filepath == "":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   854
            self.LastNewIndex += 1
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 545
diff changeset
   855
            self.FileNames[self.NodeIndex] = _("Unnamed%d")%self.LastNewIndex
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   856
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   857
            self.FileNames[self.NodeIndex] = os.path.splitext(os.path.basename(filepath))[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   858
                
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   859
    def GetCurrentFilePath(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   860
        if len(self.FilePaths) > 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   861
            return self.FilePaths[self.NodeIndex]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   862
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   863
            return ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   864
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   865
    def GetCurrentBufferState(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   866
        first = self.UndoBuffers[self.NodeIndex].IsFirst()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   867
        last = self.UndoBuffers[self.NodeIndex].IsLast()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   868
        return not first, not last
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   869
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   870
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   871
#                         Profiles Management Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   872
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   873
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   874
    def GetCurrentCommunicationLists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   875
        list = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   876
        for index in MappingDictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   877
            if 0x1000 <= index < 0x1200:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   878
                list.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   879
        return self.GetProfileLists(MappingDictionary, list)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   880
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   881
    def GetCurrentDS302Lists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   882
        return self.GetSpecificProfileLists(self.CurrentNode.GetDS302Profile())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   883
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   884
    def GetCurrentProfileLists(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   885
        return self.GetSpecificProfileLists(self.CurrentNode.GetProfile())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   886
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   887
    def GetSpecificProfileLists(self, mappingdictionary):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   888
        validlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   889
        exclusionlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   890
        for name, list in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   891
            exclusionlist.extend(list)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   892
        for index in mappingdictionary.iterkeys():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   893
            if index not in exclusionlist:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   894
                validlist.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   895
        return self.GetProfileLists(mappingdictionary, validlist)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   896
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   897
    def GetProfileLists(self, mappingdictionary, list):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   898
        dictionary = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   899
        current = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   900
        for index in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   901
            dictionary[index] = (mappingdictionary[index]["name"], mappingdictionary[index]["need"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   902
            if self.CurrentNode.IsEntry(index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   903
                current.append(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   904
        return dictionary, current
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   905
39
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   906
    def GetCurrentNextMapIndex(self):
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   907
        if self.CurrentNode:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   908
            index = 0x2000
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   909
            while self.CurrentNode.IsEntry(index) and index < 0x5FFF:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   910
                index += 1
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   911
            if index < 0x6000:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   912
                return index
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   913
            else:
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   914
                return None
3e94ee906bc6 Add incremented index in Add Map Variable
lbessard
parents: 30
diff changeset
   915
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   916
    def CurrentDS302Defined(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   917
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   918
            return len(self.CurrentNode.GetDS302Profile()) > 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   919
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   920
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   921
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   922
#                         Node State and Values Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   923
#-------------------------------------------------------------------------------
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   924
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   925
    def GetCurrentNodeName(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   926
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   927
            return self.CurrentNode.GetNodeName()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   928
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   929
            return ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   930
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   931
    def GetCurrentNodeCopy(self):
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   932
        if self.CurrentNode:
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   933
            return self.CurrentNode.Copy()
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   934
        else:
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   935
            return None
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   936
    
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
   937
    def GetCurrentNodeID(self, node = None):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   938
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   939
            return self.CurrentNode.GetNodeID()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   940
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
   941
            return None
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   942
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   943
    def GetCurrentNodeInfos(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   944
        name = self.CurrentNode.GetNodeName()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   945
        id = self.CurrentNode.GetNodeID()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   946
        type = self.CurrentNode.GetNodeType()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   947
        description = self.CurrentNode.GetNodeDescription()
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   948
        return name, id, type, description
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   949
    
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   950
    def SetCurrentNodeInfos(self, name, id, type, description):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   951
        self.CurrentNode.SetNodeName(name)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   952
        self.CurrentNode.SetNodeID(id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   953
        self.CurrentNode.SetNodeType(type)
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
   954
        self.CurrentNode.SetNodeDescription(description)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   955
        self.BufferCurrentNode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   956
418
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   957
    def GetCurrentNodeDefaultStringSize(self):
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   958
        if self.CurrentNode:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   959
            return self.CurrentNode.GetDefaultStringSize()
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   960
        else:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   961
            return Node.DefaultStringSize
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   962
    
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   963
    def SetCurrentNodeDefaultStringSize(self, size):
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   964
        if self.CurrentNode:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   965
            self.CurrentNode.SetDefaultStringSize(size)
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   966
        else:
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   967
            Node.DefaultStringSize = size
64a8c24b61a5 Problem with String size in C file generated fixed
lbessard
parents: 338
diff changeset
   968
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   969
    def GetCurrentProfileName(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   970
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   971
            return self.CurrentNode.GetProfileName()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   972
        return ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   973
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   974
    def IsCurrentEntry(self, index):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   975
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   976
            return self.CurrentNode.IsEntry(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   977
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   978
    
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   979
    def GetCurrentEntry(self, index, subIndex = None, compute = True):
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   980
        if self.CurrentNode:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
   981
            return self.CurrentNode.GetEntry(index, subIndex, compute)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   982
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   983
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   984
    def GetCurrentParamsEntry(self, index, subIndex = None):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   985
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   986
            return self.CurrentNode.GetParamsEntry(index, subIndex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   987
        return None
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   988
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   989
    def GetCurrentValidIndexes(self, min, max):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   990
        validindexes = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   991
        for index in self.CurrentNode.GetIndexes():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   992
            if min <= index <= max:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   993
                validindexes.append((self.GetEntryName(index), index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   994
        return validindexes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   995
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   996
    def GetCurrentValidChoices(self, min, max):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   997
        validchoices = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   998
        exclusionlist = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   999
        for menu, indexes in self.CurrentNode.GetSpecificMenu():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1000
            exclusionlist.extend(indexes)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1001
            good = True
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1002
            for index in indexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1003
                good &= min <= index <= max
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1004
            if good:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1005
                validchoices.append((menu, None))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1006
        list = [index for index in MappingDictionary.keys() if index >= 0x1000]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1007
        profiles = self.CurrentNode.GetMappings(False)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1008
        for profile in profiles:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1009
            list.extend(profile.keys())
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1010
        list.sort()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1011
        for index in list:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1012
            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
  1013
                validchoices.append((self.GetEntryName(index), index))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1014
        return validchoices
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1015
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1016
    def HasCurrentEntryCallbacks(self, index):
245
d43ebbed895f Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents: 244
diff changeset
  1017
        if self.CurrentNode:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1018
            return self.CurrentNode.HasEntryCallbacks(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1019
        return False
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1020
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1021
    def GetCurrentEntryValues(self, index):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1022
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1023
            return self.GetNodeEntryValues(self.CurrentNode, index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1024
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1025
    def GetNodeEntryValues(self, node, index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1026
        if node and node.IsEntry(index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1027
            entry_infos = node.GetEntryInfos(index)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1028
            data = []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1029
            editors = []
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
  1030
            values = node.GetEntry(index, compute = False)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1031
            params = node.GetParamsEntry(index)
512
e84806c0ada4 Some instance type test improved
lbessard
parents: 492
diff changeset
  1032
            if isinstance(values, ListType):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1033
                for i, value in enumerate(values):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1034
                    data.append({"value" : value})
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1035
                    data[-1].update(params[i])      
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1036
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1037
                data.append({"value" : values})
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1038
                data[-1].update(params)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1039
            for i, dic in enumerate(data):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1040
                infos = node.GetSubentryInfos(index, i)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1041
                dic["subindex"] = "0x%02X"%i
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1042
                dic["name"] = infos["name"]
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1043
                dic["type"] = node.GetTypeName(infos["type"])
582
e297491483ea Adding support for displaying 'unknown' while datatype is not supported by CanFestival
laurent
parents: 580
diff changeset
  1044
                if dic["type"] is None:
e297491483ea Adding support for displaying 'unknown' while datatype is not supported by CanFestival
laurent
parents: 580
diff changeset
  1045
                    dic["type"] = "Unknown"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1046
                dic["access"] = AccessType[infos["access"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1047
                dic["save"] = OptionType[dic["save"]]
582
e297491483ea Adding support for displaying 'unknown' while datatype is not supported by CanFestival
laurent
parents: 580
diff changeset
  1048
                editor = {"subindex" : None, "name" : None, 
e297491483ea Adding support for displaying 'unknown' while datatype is not supported by CanFestival
laurent
parents: 580
diff changeset
  1049
                          "type" : None, "value" : None,
e297491483ea Adding support for displaying 'unknown' while datatype is not supported by CanFestival
laurent
parents: 580
diff changeset
  1050
                          "access" : None, "save" : "option", 
e297491483ea Adding support for displaying 'unknown' while datatype is not supported by CanFestival
laurent
parents: 580
diff changeset
  1051
                          "callback" : "option", "comment" : "string"}
512
e84806c0ada4 Some instance type test improved
lbessard
parents: 492
diff changeset
  1052
                if isinstance(values, ListType) and i == 0:
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1053
                    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
  1054
                        editor["access"] = "raccess"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1055
                else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1056
                    if infos["user_defined"]:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1057
                        if entry_infos["struct"] & OD_IdenticalSubindexes:
582
e297491483ea Adding support for displaying 'unknown' while datatype is not supported by CanFestival
laurent
parents: 580
diff changeset
  1058
                            if i == 0:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1059
                                editor["type"] = "type"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1060
                                editor["access"] = "access"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1061
                        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1062
                            if entry_infos["struct"] & OD_MultipleSubindexes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1063
                                editor["name"] = "string"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1064
                            editor["type"] = "type"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1065
                            editor["access"] = "access"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1066
                    if index < 0x260:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1067
                        if i == 1:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1068
                            dic["value"] = node.GetTypeName(dic["value"])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1069
                    elif 0x1600 <= index <= 0x17FF or 0x1A00 <= index <= 0x1C00:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1070
                        editor["value"] = "map"
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1071
                        dic["value"] = node.GetMapName(dic["value"])
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1072
                    else:
333
7e553315ef46 Bug on OCTET_STRING display fixed
lbessard
parents: 327
diff changeset
  1073
                        if dic["type"].startswith("VISIBLE_STRING") or dic["type"].startswith("OCTET_STRING"):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1074
                            editor["value"] = "string"
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1075
                        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
  1076
                            editor["value"] = "time"
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1077
                        elif dic["type"] == "DOMAIN":
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1078
                            if index == 0x1F22:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1079
                                editor["value"] = "dcf"
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1080
                            else:
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1081
                                editor["value"] = "domain"
176
5d57fe1e3a5b Support for DCF (DS-302)
greg
parents: 171
diff changeset
  1082
                            dic["value"] = dic["value"].encode('hex_codec')
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1083
                        elif dic["type"] == "BOOLEAN":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1084
                            editor["value"] = "bool"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1085
                            dic["value"] = BoolType[dic["value"]]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1086
                        result = type_model.match(dic["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1087
                        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1088
                            values = result.groups()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1089
                            if values[0] == "UNSIGNED":
299
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
  1090
                                try:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
  1091
                                    format = "0x%0" + str(int(values[1])/4) + "X"
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
  1092
                                    dic["value"] = format%dic["value"]
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
  1093
                                except:
506f9700b9fb Allowing user to type formulas
lbessard
parents: 268
diff changeset
  1094
                                    pass
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1095
                                editor["value"] = "string"
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1096
                            if values[0] == "INTEGER":
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1097
                                editor["value"] = "number"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1098
                            elif values[0] == "REAL":
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1099
                                editor["value"] = "float"
333
7e553315ef46 Bug on OCTET_STRING display fixed
lbessard
parents: 327
diff changeset
  1100
                            elif values[0] in ["VISIBLE_STRING", "OCTET_STRING"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1101
                                editor["length"] = values[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1102
                        result = range_model.match(dic["type"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1103
                        if result:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1104
                            values = result.groups()
182
988f2b302aa6 Adding support for importing and exporting EDS files
lbessard
parents: 176
diff changeset
  1105
                            if values[0] in ["UNSIGNED", "INTEGER", "REAL"]:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1106
                                editor["min"] = values[2]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1107
                                editor["max"] = values[3]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1108
                editors.append(editor)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1109
            return data, editors
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1110
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1111
            return None
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1112
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1113
    def AddToDCF(self, node_id, index, subindex, size, value):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1114
        if self.CurrentNode.IsEntry(0x1F22, node_id):
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1115
            dcf_value = self.CurrentNode.GetEntry(0x1F22, node_id)
338
9ba9f4f7d080 Bug on DCF edition fixed
lbessard
parents: 333
diff changeset
  1116
            if dcf_value != "":
9ba9f4f7d080 Bug on DCF edition fixed
lbessard
parents: 333
diff changeset
  1117
                nbparams = BE_to_LE(dcf_value[:4])
9ba9f4f7d080 Bug on DCF edition fixed
lbessard
parents: 333
diff changeset
  1118
            else:
9ba9f4f7d080 Bug on DCF edition fixed
lbessard
parents: 333
diff changeset
  1119
                nbparams = 0
327
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1120
            new_value = LE_to_BE(nbparams + 1, 4) + dcf_value[4:]
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1121
            new_value += LE_to_BE(index, 2) + LE_to_BE(subindex, 1) + LE_to_BE(size, 4) + LE_to_BE(value, size)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1122
            self.CurrentNode.SetEntry(0x1F22, node_id, new_value)
b904d9a99e28 Adding DCFEditor Dialog to networkedit
lbessard
parents: 299
diff changeset
  1123
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1124
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1125
#                         Node Informations Functions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1126
#-------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1127
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1128
    def GetCustomisedTypeValues(self, index):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1129
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1130
            values = self.CurrentNode.GetEntry(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1131
            customisabletypes = self.GetCustomisableTypes()
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1132
            return values, customisabletypes[values[1]][1]
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1133
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1134
            return None, None
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1135
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1136
    def GetEntryName(self, index, compute=True):
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1137
        if self.CurrentNode:
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1138
            return self.CurrentNode.GetEntryName(index, compute)
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1139
        else:
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1140
            return FindEntryName(index, MappingDictionary, compute)
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1141
    
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1142
    def GetEntryInfos(self, index, compute=True):
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1143
        if self.CurrentNode:
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1144
            return self.CurrentNode.GetEntryInfos(index, compute)
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1145
        else:
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1146
            return FindEntryInfos(index, MappingDictionary, compute)
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1147
    
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1148
    def GetSubentryInfos(self, index, subindex, compute=True):
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1149
        if self.CurrentNode:
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1150
            return self.CurrentNode.GetSubentryInfos(index, subindex, compute)
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1151
        else:
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1152
            result = FindSubentryInfos(index, subindex, MappingDictionary, compute)
68
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1153
            if result:
234dad27b398 Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents: 63
diff changeset
  1154
                result["user_defined"] = False
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1155
            return result
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1156
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1157
    def GetTypeIndex(self, typename):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1158
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1159
            return self.CurrentNode.GetTypeIndex(typename)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1160
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1161
            return FindTypeIndex(typename, MappingDictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1162
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1163
    def GetTypeName(self, typeindex):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1164
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1165
            return self.CurrentNode.GetTypeName(typeindex)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1166
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1167
            return FindTypeName(typeindex, MappingDictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1168
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1169
    def GetTypeDefaultValue(self, typeindex):
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1170
        if self.CurrentNode:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1171
            return self.CurrentNode.GetTypeDefaultValue(typeindex)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1172
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1173
            return FindTypeDefaultValue(typeindex, MappingDictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1174
    
584
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1175
    def GetMapVariableList(self, compute=True):
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1176
        if self.CurrentNode:
e23359f62023 Bug with in access value translation and modification on subindex 0 of PDOmapping entries fixed
laurent
parents: 582
diff changeset
  1177
            return self.CurrentNode.GetMapVariableList(compute)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1178
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1179
            return []
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1180
244
da4245399655 nodemanager to work with masternode copy
greg
parents: 242
diff changeset
  1181
    def GetMandatoryIndexes(self):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1182
        if self.CurrentNode:
220
b7fb826c66d9 Bug on NodeManager corrected :
lbessard
parents: 205
diff changeset
  1183
            return self.CurrentNode.GetMandatoryIndexes()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1184
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents: 188
diff changeset
  1185
            return FindMandatoryIndexes(MappingDictionary)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1186
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1187
    def GetCustomisableTypes(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1188
        dic = {}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1189
        for index, valuetype in CustomisableTypes:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1190
            name = self.GetTypeName(index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1191
            dic[index] = [name, valuetype]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1192
        return dic
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1193
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1194
    def GetCurrentSpecificMenu(self):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1195
        if self.CurrentNode:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1196
            return self.CurrentNode.GetSpecificMenu()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1197
        return []
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1198