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

Prepare support for live variable updates

parent c93640df
......@@ -3,6 +3,7 @@
<file>logging.ui</file>
<file>plotDialog.ui</file>
<file>simulation.ui</file>
<file>internalState.ui</file>
<file>singleEditor.ui</file>
<file>tasteLogo_white.png</file>
<file>InterfaceEnum.i</file>
......
......@@ -505,6 +505,41 @@ class asn1Editor(QTreeView):
raw = vn.toASN1ValueNotation(data).strip()
return raw if not use_dash else raw.replace('_', '-')
def to_asn1scc_swig(self, root, dest, ASN1Swig, ASN1_type):
''' Helper API function: read variable and set ASN.1 SWIG variable
Inputs: root: select which variable to parse
dest: Swig variable (will be modified)
ASN1Swig: python module containing SWIG DV access
ASN1_type: AST generated by ASN1SCC for the root type
'''
var = self.getVariable(root).popitem()[1]
print ASN1_type
def rec(inp, outp, sort):
''' Recursively parse the value '''
if isinstance(inp, list):
# SEQUENCE OF
for i in range(len(inp)):
rec(inp[i], outp[i], sort.type.type)
if sort.type.Min != sort.type.Max:
dest.SetLength(len(inp))
elif isinstance(inp, (int, float, bool)):
outp.Set(inp)
elif isinstance(inp, dict):
if 'Enum' in inp:
val = getattr(ASN1Swig.DV, inp['Enum'])
outp.Set(val)
elif 'Choice' in inp:
# We need the _PRESENT string TOOD
pass
else:
for each in inp:
rec(inp, getattr(outp, each))
else:
self.log.error('Unsupported type in to_asn1scc_swig')
rec(var, dest, ASN1_type)
return
def sendTC(self):
''' Encode and send the TC to the main TASTE binary using message queue or UDP '''
data = self.getVariable()
......
This diff is collapsed.
......@@ -146,15 +146,21 @@ class sdlHandler(QObject):
self.running = False
self.dock.hide()
# Dock widget to display the internal state
self.asn1_editor = asn1_value_editor.asn1Editor(self.parent)
ui = QFile(':/internalState.ui')
loader = QUiLoader()
widgets = loader.load(ui, parent=self.parent)
self.asn1_editor = widgets.findChild(asn1_value_editor.asn1Editor,
'ASN1EDITOR')
self.asn1_editor.hideExtraColumns()
apply_button = widgets.findChild(QToolButton, 'applyButton')
apply_button.pressed.connect(self.change_internal_state)
self.dock_state = QDockWidget('Internal state', self.parent)
self.dock_state.setFloating(False)
#self.dock_state.resize(400, 400)
self.dock_state.setObjectName('InternalStateViewer')
self.parent.addDockWidget(Qt.RightDockWidgetArea, self.dock_state)
#self.dock_state.setAllowedAreas(Qt.NoDockWidgetArea)
self.dock_state.setWidget(self.asn1_editor)
self.dock_state.setWidget(widgets)
self.dock_state.show()
self.parent.tabifyDockWidget(self.dock_state, self.dock_simu)
# Add the SDL variables to the ASN.1 editor
......@@ -238,9 +244,22 @@ class sdlHandler(QObject):
state_value = target_state[idx+1]
set_state = getattr(self.dll, "_set_state")
set_state(ctypes.c_char_p(state_value))
#self.current_sdl_state = state_value
self.check_state()
#self.on_event()
def change_internal_state(self):
''' When user press the "Apply" button to change the model's internal
state (variables of the SDL model): Create an undo action that
applies the change.
'''
# Get the variables values from the asn1_value_editor window
for var, (sort, _) in self.proc.variables.viewitems():
#as_pyside = self.asn1_editor.getVariable(root=self.tree_items[var])
typename = sort.ReferencedTypeName.replace('-', '_')
asn1_instance = getattr(ASN1, typename)()
# Fill up the SWIG ASN.1 instance
self.asn1_editor.to_asn1scc_swig(root=self.tree_items[var],
dest=asn1_instance, ASN1Swig=ASN1,
ASN1_type=sort)
def on_event(self, tc_name=None, param=None):
''' Update the list of global states and GUI after a TC has been sent
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>internalStateEditor</class>
<widget class="QDialog" name="internalStateEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>471</width>
<height>425</height>
</rect>
</property>
<property name="windowTitle">
<string>Change model's internal state</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="asn1Editor" name="ASN1EDITOR"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QToolButton" name="applyButton">
<property name="text">
<string>Apply</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>asn1Editor</class>
<extends>QTreeView</extends>
<header>asn1editor.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
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