add mandatory properties is more conveniant
This commit is contained in:
@ -75,17 +75,13 @@ class SpaceAnnotator:
|
||||
"""
|
||||
def __init__(self, objectspace, eosfunc_file):
|
||||
self.objectspace = objectspace
|
||||
self.force_not_mandatory = []
|
||||
GroupAnnotator(objectspace)
|
||||
ServiceAnnotator(objectspace)
|
||||
VariableAnnotator(objectspace)
|
||||
ConstraintAnnotator(objectspace,
|
||||
eosfunc_file,
|
||||
self.force_not_mandatory,
|
||||
)
|
||||
FamilyAnnotator(objectspace,
|
||||
self.force_not_mandatory,
|
||||
)
|
||||
FamilyAnnotator(objectspace)
|
||||
PropertyAnnotator(objectspace)
|
||||
|
||||
|
||||
@ -597,14 +593,12 @@ class ConstraintAnnotator:
|
||||
def __init__(self,
|
||||
objectspace,
|
||||
eosfunc_file,
|
||||
force_not_mandatory,
|
||||
):
|
||||
if not hasattr(objectspace.space, 'constraints'):
|
||||
return
|
||||
self.objectspace = objectspace
|
||||
self.eosfunc = imp.load_source('eosfunc', eosfunc_file)
|
||||
self.valid_enums = {}
|
||||
self.force_not_mandatory = force_not_mandatory
|
||||
if hasattr(self.objectspace.space.constraints, 'check'):
|
||||
self.check_check()
|
||||
self.check_replace_text()
|
||||
@ -974,7 +968,6 @@ class ConstraintAnnotator:
|
||||
if param.name == 'mini':
|
||||
variable.min_number = int(param.text)
|
||||
elif param.name == 'maxi':
|
||||
print('pppp', param.text)
|
||||
variable.max_number = int(param.text)
|
||||
else:
|
||||
raise DictConsistencyError(_(f'unknown parameter {param.text} in check "valid_entier" for variable {check.target}'))
|
||||
@ -1074,9 +1067,10 @@ class ConstraintAnnotator:
|
||||
|
||||
|
||||
class FamilyAnnotator:
|
||||
def __init__(self, objectspace, force_not_mandatory):
|
||||
def __init__(self,
|
||||
objectspace,
|
||||
):
|
||||
self.objectspace = objectspace
|
||||
self.force_not_mandatory = force_not_mandatory
|
||||
self.remove_empty_families()
|
||||
self.change_variable_mode()
|
||||
self.change_family_mode()
|
||||
@ -1126,23 +1120,36 @@ class FamilyAnnotator:
|
||||
def annotate_variable(self, variable, family_mode, path, is_follower=False):
|
||||
# if the variable is mandatory and doesn't have any value
|
||||
# then the variable's mode is set to 'basic'
|
||||
has_value = hasattr(variable, 'value')
|
||||
if variable.mandatory is True and (not has_value or is_follower):
|
||||
variable.mode = modes_level[0]
|
||||
if variable.mode != None and modes[variable.mode] < modes[family_mode] and (not is_follower or variable.mode != modes_level[0]):
|
||||
variable.mode = family_mode
|
||||
if has_value and path not in self.force_not_mandatory:
|
||||
variable.mandatory = True
|
||||
if variable.hidden is True:
|
||||
variable.frozen = True
|
||||
if not variable.auto_save is True and 'force_default_on_freeze' not in vars(variable):
|
||||
variable.force_default_on_freeze = True
|
||||
if not has_value and variable.type == 'boolean':
|
||||
if not hasattr(variable, 'value') and variable.type == 'boolean':
|
||||
new_value = self.objectspace.value()
|
||||
new_value.name = True
|
||||
new_value.type = 'boolean'
|
||||
variable.value = [new_value]
|
||||
variable.mandatory = True
|
||||
if hasattr(variable, 'value') and variable.value:
|
||||
has_value = True
|
||||
for value in variable.value:
|
||||
if value.type == 'calculation':
|
||||
has_value = False
|
||||
has_variable = False
|
||||
if hasattr(value, 'param'):
|
||||
for param in value.param:
|
||||
if param.type == 'variable':
|
||||
has_variable = True
|
||||
break
|
||||
if not has_variable:
|
||||
# if one parameter is a variable, let variable choice if it's mandatory
|
||||
variable.mandatory = True
|
||||
if has_value:
|
||||
# if has value but without any calculation
|
||||
variable.mandatory = True
|
||||
if variable.mandatory is True and (not hasattr(variable, 'value') or is_follower):
|
||||
variable.mode = modes_level[0]
|
||||
if variable.mode != None and modes[variable.mode] < modes[family_mode] and (not is_follower or variable.mode != modes_level[0]):
|
||||
variable.mode = family_mode
|
||||
if variable.hidden is True:
|
||||
variable.frozen = True
|
||||
if not variable.auto_save is True and 'force_default_on_freeze' not in vars(variable):
|
||||
variable.force_default_on_freeze = True
|
||||
|
||||
def change_variable_mode(self): # pylint: disable=C0111
|
||||
if not hasattr(self.objectspace.space, 'variables'):
|
||||
|
@ -337,8 +337,10 @@ class Variable(Common):
|
||||
for key in self.get_attributes(self.elt):
|
||||
value = getattr(self.elt, key)
|
||||
if key in FORCE_INFORMATIONS:
|
||||
if key == 'test' and self.object_type == 'IntOption':
|
||||
value = int(value)
|
||||
if key == 'test':
|
||||
value = value.split(',')
|
||||
if self.object_type == 'IntOption':
|
||||
value = [int(v) for v in value]
|
||||
self.informations[key] = value
|
||||
else:
|
||||
self.attrib[key] = value
|
||||
|
Reference in New Issue
Block a user