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