Commit 5924721b authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Update data dictionary with signals

parent d1428672
......@@ -360,8 +360,46 @@ class Signalroute(Connection):
def update_completion_list(self, pr_text):
''' Called after text has been edited '''
# TODO - call parseSingleElement, check sdlSymbols for examples
from sdlSymbols import CONTEXT
ast, _, _, _, _ = self.parser.parseSingleElement('signalroute',
# ast is a dict:
# {'routes': [{'dest': str, 'source': str', 'signals': [str]}],
# 'name': u'c'} - dest and source can be 'ENV'
all_sigs = []
for each in ast['routes']:
source = each['source']
dest = each['dest']
sigs = [{'name': name} for name in each['signals']]
def get_sig(signal):
''' If signal is declared, return the signature '''
for sig in CONTEXT.signals:
if sig['name'].lower() == signal['name'].lower():
return sig
return signal
if each['dest'] == 'ENV':
# output signals of process 'source'
process, = [p for p in CONTEXT.processes
if p.processName.lower() == each['source'].lower()]
existing = [sig['name'].lower()
for sig in process.output_signals]
for sig in sigs:
if sig['name'].lower() not in existing:
# input signals of process 'source'
process, = [p for p in CONTEXT.processes
if p.processName.lower() == each['dest'].lower()]
existing = [sig['name'].lower()
for sig in process.input_signals]
for sig in sigs:
if sig['name'].lower() not in existing:
existing = [sig['name'].lower() for sig in CONTEXT.signals]
for each in all_sigs:
if each['name'].lower() not in existing:
def resize_item(self, new_rect):
''' Called after signallist text has been edited '''
......@@ -2143,6 +2143,7 @@ class OG_MainWindow(QtGui.QMainWindow, object):
QtGui.QTreeWidgetItem(self.datadict, ["Input signals"])
QtGui.QTreeWidgetItem(self.datadict, ["Output signals"])
QtGui.QTreeWidgetItem(self.datadict, ["States"])
QtGui.QTreeWidgetItem(self.datadict, ["Labels"])
QtGui.QTreeWidgetItem(self.datadict, ["Variables"])
QtGui.QTreeWidgetItem(self.datadict, ["Timers"])
......@@ -2228,8 +2229,8 @@ class OG_MainWindow(QtGui.QMainWindow, object):
''' Update the tree in the data dictionary based on the AST '''
# currently the ast is a global in sdlSymbols.CONTEXT
# it should be attached to the current scene instead TODO
in_sig, out_sig, states, dcl, timers = [self.datadict.topLevelItem(i)
for i in range(2, 7)]
(in_sig, out_sig, states, labels,
dcl, timers) = [self.datadict.topLevelItem(i) for i in range(2, 8)]
context = sdlSymbols.CONTEXT
def change_state(item, state):
......@@ -2237,14 +2238,29 @@ class OG_MainWindow(QtGui.QMainWindow, object):
if self.view.scene().context == 'block':
map(lambda elem: change_state(elem, True),
(in_sig, out_sig, states, dcl, timers))
(in_sig, out_sig, states, labels, dcl, timers))
elif self.view.scene().context == 'process':
map(lambda elem: change_state(elem, False),
(in_sig, out_sig, states, dcl, timers))
(in_sig, out_sig, states, labels, dcl, timers))
for each in context.input_signals:
QtGui.QTreeWidgetItem(in_sig, [each['name'],
each.get('type', '')])
for each in context.output_signals:
QtGui.QTreeWidgetItem(out_sig, [each['name'],
each.get('type', '')])
for each in sorted(context.mapping.viewkeys()):
QtGui.QTreeWidgetItem(states, [each,])
for each in context.labels:
QtGui.QTreeWidgetItem(labels, [each.inputString,])
for var, (sort, _) in context.variables.viewitems():
QtGui.QTreeWidgetItem(dcl, [var, sort.ReferencedTypeName])
for each in context.timers:
QtGui.QTreeWidgetItem(timers, [each,])
elif self.view.scene().context == 'procedure':
map(lambda elem: change_state(elem, False), (dcl, timers, out_sig))
map(lambda elem: change_state(elem, False),
(dcl, timers, labels, out_sig))
map(lambda elem: change_state(elem, True), (in_sig, states))
......@@ -820,6 +820,10 @@ class TextSymbol(HorizontalSymbol):
def update_completion_list(self, pr_text):
''' When text was entered, update list of variables/FPAR/Timers '''
# note, on standalone systems, if the textbox contains a
# USE Dataview comment 'file.asn'. this file is parsed when leaving
# the textbox. This gives the impression that this function is slow,
# it it is not! - no need to investigate performance issues here
# Get AST for the symbol
ast, _, _, _, _ = self.parser.parseSingleElement('text_area', pr_text)
......@@ -840,6 +844,7 @@ class TextSymbol(HorizontalSymbol):
Signalroute.completion_list |= set(sig['name']
for sig in ast.signals)
CONTEXT.signals += ast.signals
except AttributeError:
# no AST, e.g. in case of syntax errors in the text area
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