Commit ca025faa authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Use ctypes a bit more

Work in progress
parent c34011bf
......@@ -361,7 +361,6 @@ class asn1Editor(QTreeView):
ptr.kind.Set(getattr(self.backend.DV,
value.replace('-', '_')+'_PRESENT'))
elif asnType == 'INTEGER':
resValue[name] = int(value)
ptr.Set(int(value))
elif asnType == 'REAL':
ptr.Set(float(value))
......@@ -422,47 +421,63 @@ class asn1Editor(QTreeView):
self.parseModel(root, dest=dest)
def updateModel(self, root, ptr, nbRows=-1):
''' Parse the model and update values '''
''' Recursive update of the values in the GUI from ASN.1 instance '''
if root.hasChildren():
seqOf = False
if nbRows == -1:
nbRows = root.rowCount()
else:
seqOf = True
destState = dest.GetState()
def parseRow(root, i, dest, choice=False):
destState = ptr.GetState()
def fillRow(root, i, dest, choice=False):
name = root.child(i, 0).text()
asnType = root.child(i, 1).text()
child = root.child(i, 3)
if not choice:
dest.Reset(destState)
ptr = getattr(dest, name)
if seqOf:
value = var[i]
else:
if name in var:
value = var.get(name, var[name])
else:
continue
ptr = ptr[i]
if asnType in ('INTEGER', 'REAL', 'SEQOF'):
plotters = root.child(i, 3).data(PLOTTERS)
# XXX plotter: TODO
plotters = child.data(PLOTTERS)
if plotters is not None:
self.log.debug("updateModel - updatePlot call")
for plotter in plotters:
self.plotterBackend.updatePlot(plotter, value)
self.log.debug("updateModel - updatePlot end")
if asnType in ('INTEGER', 'REAL', 'BOOLEAN', 'STRING'):
child.setText(str(value))
if asnType in ('INTEGER', 'REAL', 'BOOLEAN'):
child.setText(str(ptr.Get()))
elif asnType == 'STRING':
child.setText(ptr.GetFromPyString())
elif asnType == 'ENUMERATED':
child.setText(value['Enum'])
value = ptr.Get()
intMappings = child.data(INTMAP)
for enumerant, num in intMappings.viewitems():
if num == value:
child.setText(enumerant)
break
else:
print("ERROR = ENUMERATED value not found")
elif asnType in ('SEQUENCE', 'SET'):
self.updateModel(root.child(i), value) # update recursively
self.updateModel(root.child(i), ptr)
elif asnType == 'CHOICE':
child.setText(str(value['Choice']))
self.updateModel(root.child(i), value) # update recursively
value = ptr.kind.Get()
intMappings = child.data(INTMAP)
for enumerant, num in intMappings.viewitems():
if num == value:
child.setText(str(enumerant))
# is num really the row of this choice ? XXX
fillRow(root.child(i), num, dest=ptr, choice=True)
break
elif asnType == 'SEQOF':
child.setText(str(len(value)))
self.updateModel(root.child(i), value, nbRows=len(value))
size = ptr.GetLength()
child.setText(str(size))
self.updateModel(root.child(i), ptr, nbRows=size)
for i in range(nbRows):
parseRow(root, i, dest)
for i in xrange(nbRows):
fillRow(root, i, ptr)
def updateVariable(self, root=None):
''' Update the variable value (when loading a TC or receiving a TM) '''
......
......@@ -377,8 +377,10 @@ class sdlHandler(QObject):
stnames = list(opengeode.Helper.statenames(context, sep=UNICODE_SEP))
stnames.extend(list(opengeode.Helper.rec_findstates(context)))
states = {'id': 'Current SDL state', 'type': 'ENUMERATED',
'values': stnames}
states = {'id': 'Current SDL state',
'type': 'ENUMERATED',
'values': stnames,
'valuesInt': {a: b for b, a in enumerate(stnames)}}
self.tree_items['_states'] = self.asn1_editor.setAsn1Model(states, row)
# Add state variables for parallel states in aggregations
......@@ -390,14 +392,17 @@ class sdlHandler(QObject):
states = {'id': 'Substate {}.{}'.format(CleanName(agg),
each.statename),
'type': 'ENUMERATED',
'values': subst} #stnames}
'values': subst,
'valuesInt': {a: b for b, a in enumerate(subst)}}
self.tree_items['substate_{}'.format(each.statename)] = \
self.asn1_editor.setAsn1Model(states, row)
# Add the SDL variables to the ASN.1 editor
row += 1
for var, (sort, _) in self.proc.variables.viewitems():
item = asn1sccToasn1ValueEditorTypes(self.proc.dataview, var, sort)
sortName = sort.ReferencedTypeName
item = asn1sccToasn1ValueEditorTypes(self.proc.dataview,
sortName, sort)
self.tree_items[var] = self.asn1_editor.setAsn1Model(item, row)
row += 1
# In the simulation panel, set the buttons to send paramless TC/timers
......@@ -593,21 +598,25 @@ class sdlHandler(QObject):
get_value = getattr(self.dll, "{}_value".format(var))
get_value.restype = ctypes.c_void_p # ctypes.POINTER(ctypes.c_char) # CHECKME
value = get_value()
asn1_instance = getattr(ASN1, typename)()
asn1_instance.SetData(value)
gser = asn1_instance.GSER()
as_pyside = vn.fromValueNotationToPySide(var, gser)
self.asn1_editor.updateVariable(as_pyside,
root=self.tree_items[var])
complete_state.append(asn1_instance) # not gser
#asn1_instance = getattr(ASN1, typename)()
#asn1_instance.SetData(value)
if not self.asn1_editor.asn1Instance:
print 'Creating instance of type ', self.asn1_editor.item['nodeTypename']
self.asn1_editor.asn1Instance = getattr(ASN1, self.asn1_editor.item['nodeTypename'])()
self.asn1_editor.asn1Instance.SetData(value)
#gser = asn1_instance.GSER()
#as_pyside = vn.fromValueNotationToPySide(var, gser)
self.asn1_editor.updateVariable(root=self.tree_items[var])
complete_state.append(self.asn1_editor.asn1Instance) #asn1_instance)
# Add the SDL state to the new global state
complete_state.append(self.current_sdl_state)
# Update the SDL state in the global state panel
readable_state = self.current_sdl_state.replace(UNICODE_SEP, '--')
state_as_pyside = vn.fromValueNotationToPySide('Current SDL state',
readable_state.lower().replace('_', '-'))
self.asn1_editor.updateVariable(state_as_pyside,
root=self.tree_items['_states'])
# XXX UPDATE THE STATE IN THE GUI TODO
# state_as_pyside = vn.fromValueNotationToPySide('Current SDL state',
# readable_state.lower().replace('_', '-'))
# self.asn1_editor.updateVariable(state_as_pyside,
# root=self.tree_items['_states'])
# And save this new state in the graph, if it was not there yet
new_hash = hash(frozenset(complete_state))
# Set a flag indicating a new state was added
......
......@@ -114,6 +114,8 @@ def asn1sccToasn1ValueEditorTypes(dataview, name, asntype):
result['type'] = 'ENUMERATED'
result['id'] = name
result['values'] = t.EnumValues.keys()
result['valuesInt'] = {val: num.IntValue
for val, num in t.EnumValues.viewitems()}
elif t.kind == 'ChoiceType':
result['type'] = 'CHOICE'
result['id'] = name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment