Commit 19a504fc authored by Maxime Perrotin's avatar Maxime Perrotin

Basic support of alwaysPresent/Absent fields

Still need to
* update the HideUnused fields in case of alwaysAbsent fields
* validate when DMT is updated with the complete support of subtypes
parent dd074fea
......@@ -34,6 +34,7 @@ LICENSE: LGPL - see LICENSE file
CHANGELOG:
1.7.2 - Enable support for always Present/always Absent fields
1.7.1 - Enable support for optional fields
1.7.0 - Optional fields and fix segfaults when updating CHOICE fields
1.6.9 - Add basic support for optional fields
......
......@@ -16,7 +16,7 @@
__author__ = "Maxime Perrotin"
__license__ = "LGPLv3"
__version__ = "1.7.1"
__version__ = "1.7.2"
__url__ = "https://taste.tools"
import sys
......@@ -33,13 +33,15 @@ except ImportError as err:
import vn
MIN_RANGE = Qt.UserRole + 1
MAX_RANGE = Qt.UserRole + 2
CHOICE_LIST = Qt.UserRole + 1 # list of strings (enumerants)
INTMAP = Qt.UserRole + 5 # for enum/choice: map string-numerical value
PLOTTERS = Qt.UserRole + 4
ASN1TYPE = Qt.UserRole
OPTIONAL = Qt.UserRole + 6
MIN_RANGE = Qt.UserRole + 1
MAX_RANGE = Qt.UserRole + 2
CHOICE_LIST = Qt.UserRole + 1 # list of strings (enumerants)
INTMAP = Qt.UserRole + 5 # for enum/choice: map string-numerical value
PLOTTERS = Qt.UserRole + 4
ASN1TYPE = Qt.UserRole
OPTIONAL = Qt.UserRole + 6
ALWAYS_PRESENT = Qt.UserRole + 7
ALWAYS_ABSENT = Qt.UserRole + 8
class myTextEdit(QTextEdit):
......@@ -420,14 +422,20 @@ class asn1Editor(QTreeView):
dest.Reset(stateBefore)
# Check if field is optional and set the .exist.field
# accordingly
#field_root = root.child(i)
field_name = \
root.child(i, 0).text().replace('-', '_')
field_optionality = root.child(i, 4)
if field_optionality.data(OPTIONAL) \
and field_optionality.isCheckable():
isOptional = field_optionality.data(OPTIONAL)
isAlwaysPresent = field_optionality.data(ALWAYS_PRESENT)
isAlwaysAbsent = field_optionality.data(ALWAYS_ABSENT)
if isAlwaysPresent:
present = True
elif isAlwaysAbsent:
present = False
elif isOptional:
#present = field_optionality.isCheckable()
present = field_optionality.checkState() == Qt.Checked
print field_name, "SET" if present else "UNSET"
if isOptional:
# Set the "exist" value for optional fields
ptr = getattr(dest, "exist")
ptr = getattr(ptr, field_name)
......@@ -578,13 +586,16 @@ class asn1Editor(QTreeView):
field_name = \
root.child(i, 0).text().replace('-', '_')
field_optionality = root.child(i, 4)
if field_optionality.data(OPTIONAL) \
and field_optionality.isCheckable():
# Set the "exist" value for optional fields
isOptional = field_optionality.data(OPTIONAL)
isAlwaysPresent = field_optionality.data(ALWAYS_PRESENT)
isAlwaysAbsent = field_optionality.data(ALWAYS_ABSENT)
if isOptional \
and not isAlwaysPresent and not isAlwaysAbsent :
# Read the "exist" value for optional fields
ptr = getattr(ptr, "exist")
ptr = getattr(ptr, field_name)
present = ptr.Get()
print field_name, field_optionality.data(OPTIONAL), present
print field_name, present, isAlwaysPresent, isAlwaysPresent
field_optionality.setCheckState (Qt.Checked if present
else Qt.Unchecked)
ptr.Reset(stateBefore)
......@@ -898,7 +909,11 @@ class asn1Editor(QTreeView):
constraint.setData(QBrush(QColor("gray")), Qt.ForegroundRole)
present = QStandardItem()
present.setData (elem['isOptional'], OPTIONAL)
if elem['isOptional']:
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
# add a checkbox for optionals which presence is not forced
present.setCheckState(Qt.Checked)
present.setCheckable(True)
return {"value": val, "constraint": constraint, "present": present}
......@@ -921,10 +936,13 @@ class asn1Editor(QTreeView):
constraint = QStandardItem('(%.2f..%.2f)' % (elem["minR"], elem["maxR"]))
constraint.setData(QBrush(QColor("gray")), Qt.ForegroundRole)
present = QStandardItem()
if elem['isOptional']:
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
present.setCheckState (Qt.Checked)
present.setCheckable(True)
present.setData (elem['isOptional'], OPTIONAL)
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
return {"value": val, "constraint": constraint, "present": present}
def addEnum(self, elem):
......@@ -936,10 +954,13 @@ class asn1Editor(QTreeView):
val.setData(elem["valuesInt"], INTMAP) # mapping name - value
constraint = QStandardItem()
present = QStandardItem()
if elem['isOptional']:
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
present.setCheckState (Qt.Checked)
present.setCheckable(True)
present.setData (elem['isOptional'], OPTIONAL)
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
return {"value": val, "constraint": constraint, "present" : present}
def addString(self, elem):
......@@ -961,10 +982,13 @@ class asn1Editor(QTreeView):
constraint = QStandardItem(constraintStr)
constraint.setData(QBrush(QColor("gray")), Qt.ForegroundRole)
present = QStandardItem()
if elem['isOptional']:
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
present.setCheckState (Qt.Checked)
present.setCheckable(True)
present.setData (elem['isOptional'], OPTIONAL)
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
return {"value": val, "constraint": constraint, "present": present}
def addBool(self, elem):
......@@ -975,10 +999,13 @@ class asn1Editor(QTreeView):
val.setData(['True', 'False'], CHOICE_LIST) # enum values
constraint = QStandardItem()
present = QStandardItem()
if elem['isOptional']:
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
present.setCheckState (Qt.Checked)
present.setCheckable(True)
present.setData (elem['isOptional'], OPTIONAL)
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
return {"value": val, "constraint": constraint, "present": present}
def addSequence(self, elem, parent):
......@@ -1003,11 +1030,13 @@ class asn1Editor(QTreeView):
constraint = QStandardItem()
val = QStandardItem()
present = QStandardItem()
if elem['isOptional']:
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
present.setCheckState (Qt.Checked)
present.setCheckable(True)
present.setData (elem['isOptional'], OPTIONAL)
present.setCheckable (elem['isOptional'])
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
return {"value": val, "constraint": constraint, "present": present}
def addSeqOf(self, elem, parent):
......@@ -1041,7 +1070,10 @@ class asn1Editor(QTreeView):
val.setData(elem["maxSize"], MAX_RANGE) # max number of elements
present = QStandardItem()
present.setData (elem['isOptional'], OPTIONAL)
if elem['isOptional']:
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
present.setCheckState (Qt.Checked)
present.setCheckable(True)
return {"value": val, "constraint": constraint, "present": present}
......@@ -1074,10 +1106,13 @@ class asn1Editor(QTreeView):
val.setData(elem["choiceIdx"], INTMAP) # mapping name - DV value
constraint = QStandardItem()
present = QStandardItem()
if elem['isOptional']:
if elem['isOptional'] and not elem['alwaysPresent'] \
and not elem['alwaysAbsent']:
present.setCheckState (Qt.Checked)
present.setCheckable(True)
present.setData (elem['isOptional'], OPTIONAL)
present.setData (elem['alwaysPresent'], ALWAYS_PRESENT)
present.setData (elem['alwaysAbsent'], ALWAYS_ABSENT)
return {"value": val, "constraint": constraint, "present": present}
def addItem(self, elem):
......
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