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