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): ...@@ -360,8 +360,46 @@ class Signalroute(Connection):
def update_completion_list(self, pr_text): def update_completion_list(self, pr_text):
''' Called after text has been edited ''' ''' Called after text has been edited '''
# TODO - call parseSingleElement, check sdlSymbols for examples from sdlSymbols import CONTEXT
pass ast, _, _, _, _ = self.parser.parseSingleElement('signalroute',
pr_text)
# 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']]
all_sigs.extend(sigs)
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:
process.output_signals.append(get_sig(sig))
else:
# 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:
process.input_signals.append(get_sig(sig))
existing = [sig['name'].lower() for sig in CONTEXT.signals]
for each in all_sigs:
if each['name'].lower() not in existing:
CONTEXT.signals.append(each)
def resize_item(self, new_rect): def resize_item(self, new_rect):
''' Called after signallist text has been edited ''' ''' Called after signallist text has been edited '''
......
...@@ -2143,6 +2143,7 @@ class OG_MainWindow(QtGui.QMainWindow, object): ...@@ -2143,6 +2143,7 @@ class OG_MainWindow(QtGui.QMainWindow, object):
QtGui.QTreeWidgetItem(self.datadict, ["Input signals"]) QtGui.QTreeWidgetItem(self.datadict, ["Input signals"])
QtGui.QTreeWidgetItem(self.datadict, ["Output signals"]) QtGui.QTreeWidgetItem(self.datadict, ["Output signals"])
QtGui.QTreeWidgetItem(self.datadict, ["States"]) QtGui.QTreeWidgetItem(self.datadict, ["States"])
QtGui.QTreeWidgetItem(self.datadict, ["Labels"])
QtGui.QTreeWidgetItem(self.datadict, ["Variables"]) QtGui.QTreeWidgetItem(self.datadict, ["Variables"])
QtGui.QTreeWidgetItem(self.datadict, ["Timers"]) QtGui.QTreeWidgetItem(self.datadict, ["Timers"])
self.view.update_datadict.connect(self.update_datadict_window) self.view.update_datadict.connect(self.update_datadict_window)
...@@ -2228,8 +2229,8 @@ class OG_MainWindow(QtGui.QMainWindow, object): ...@@ -2228,8 +2229,8 @@ class OG_MainWindow(QtGui.QMainWindow, object):
''' Update the tree in the data dictionary based on the AST ''' ''' Update the tree in the data dictionary based on the AST '''
# currently the ast is a global in sdlSymbols.CONTEXT # currently the ast is a global in sdlSymbols.CONTEXT
# it should be attached to the current scene instead TODO # it should be attached to the current scene instead TODO
in_sig, out_sig, states, dcl, timers = [self.datadict.topLevelItem(i) (in_sig, out_sig, states, labels,
for i in range(2, 7)] dcl, timers) = [self.datadict.topLevelItem(i) for i in range(2, 8)]
context = sdlSymbols.CONTEXT context = sdlSymbols.CONTEXT
def change_state(item, state): def change_state(item, state):
item.setDisabled(state) item.setDisabled(state)
...@@ -2237,14 +2238,29 @@ class OG_MainWindow(QtGui.QMainWindow, object): ...@@ -2237,14 +2238,29 @@ class OG_MainWindow(QtGui.QMainWindow, object):
if self.view.scene().context == 'block': if self.view.scene().context == 'block':
map(lambda elem: change_state(elem, True), 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': elif self.view.scene().context == 'process':
map(lambda elem: change_state(elem, False), 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()): for each in sorted(context.mapping.viewkeys()):
QtGui.QTreeWidgetItem(states, [each,]) 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': 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)) map(lambda elem: change_state(elem, True), (in_sig, states))
self.datadict.resizeColumnToContents(0) self.datadict.resizeColumnToContents(0)
......
...@@ -820,6 +820,10 @@ class TextSymbol(HorizontalSymbol): ...@@ -820,6 +820,10 @@ class TextSymbol(HorizontalSymbol):
def update_completion_list(self, pr_text): def update_completion_list(self, pr_text):
''' When text was entered, update list of variables/FPAR/Timers ''' ''' 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 # Get AST for the symbol
ast, _, _, _, _ = self.parser.parseSingleElement('text_area', pr_text) ast, _, _, _, _ = self.parser.parseSingleElement('text_area', pr_text)
try: try:
...@@ -840,6 +844,7 @@ class TextSymbol(HorizontalSymbol): ...@@ -840,6 +844,7 @@ class TextSymbol(HorizontalSymbol):
try: try:
Signalroute.completion_list |= set(sig['name'] Signalroute.completion_list |= set(sig['name']
for sig in ast.signals) for sig in ast.signals)
CONTEXT.signals += ast.signals
except AttributeError: except AttributeError:
# no AST, e.g. in case of syntax errors in the text area # no AST, e.g. in case of syntax errors in the text area
pass pass
......
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