Commit 37d3e143 authored by Maxime Perrotin's avatar Maxime Perrotin

fix standalone editor for optional fields

parent 19a504fc
......@@ -908,9 +908,9 @@ class asn1Editor(QTreeView):
constraint = QStandardItem('(%d..%d)' % (elem["minR"], elem["maxR"]))
constraint.setData(QBrush(QColor("gray")), Qt.ForegroundRole)
present = QStandardItem()
present.setData (elem['isOptional'], OPTIONAL)
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
present.setData (elem.get('isOptional', False), OPTIONAL)
present.setData (elem.get('alwaysPresent', True), ALWAYS_PRESENT)
present.setData (elem.get('alwaysAbsent', False), ALWAYS_ABSENT)
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
# add a checkbox for optionals which presence is not forced
......
......@@ -90,7 +90,7 @@ def import_DV(asnFile=''): # type: str -> Module
sys.exit(1)
def asn1sccToasn1ValueEditorTypes(dataview, name, asntype):
''' Convert an ASN.1 type from the Python AST of asn1scc v3
''' Convert an ASN.1 type from the Python AST of asn1scc v4
to the AST of the value editor '''
assert DV is not None
result = {'nodeTypename': name}
......@@ -98,6 +98,11 @@ def asn1sccToasn1ValueEditorTypes(dataview, name, asntype):
# find basic type
while t.kind == 'ReferenceType':
t = dataview[t.ReferencedTypeName].type
# set default values for isOptional because asn1-value-editor looks for
# them irrespective of the type kind
result['isOptional'] = False
result['alwaysPresent'] = True
result['alwaysAbsent'] = False
if t.kind == 'IntegerType':
result['type'] = 'INTEGER'
result['id'] = name
......@@ -117,8 +122,14 @@ def asn1sccToasn1ValueEditorTypes(dataview, name, asntype):
result['id'] = name
result['children'] = []
for child, childtype in t.Children.viewitems():
result['children'].append(
asn1sccToasn1ValueEditorTypes(dataview, child, childtype.type))
c = asn1sccToasn1ValueEditorTypes(dataview, child, childtype.type)
is_optional = getattr(childtype, 'Optional', "False")
c['isOptional'] = str(is_optional) == 'True'
c['alwaysPresent'] = getattr(childtype, 'alwaysPresent', True)
c['alwaysAbsent'] = getattr(childtype, 'alwaysAbsent', False)
result['children'].append(c)
elif t.kind == 'SequenceOfType':
result['type'] = 'SEQOF'
result['id'] = name
......@@ -344,7 +355,11 @@ def main():
s = SingleValueEditor(options.asn)
# Open the value editor and retrieve the value, if Cancel has not been pressed
result = s.editParam(options.asnType, options.asnValue)
try:
result = s.editParam(options.asnType, options.asnValue)
except AttributeError as err:
logger.error(str(err))
sys.exit(1)
if result is not None:
print result
sys.exit(0)
......
Markdown is supported
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