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