dynamic variable and calculation
This commit is contained in:
@ -1021,18 +1021,22 @@ class ConstraintAnnotator:
|
||||
|
||||
namespace = fill.namespace
|
||||
# let's replace the target by the path
|
||||
fill.target = self.objectspace.paths.get_variable_path(fill.target,
|
||||
namespace,
|
||||
)
|
||||
|
||||
fill.target, suffix = self.objectspace.paths.get_variable_path(fill.target,
|
||||
namespace,
|
||||
with_suffix=True,
|
||||
)
|
||||
if suffix is not None:
|
||||
raise DictConsistencyError(_(f'Cannot add fill function to "{fill.target}" only with the suffix "{suffix}"'))
|
||||
value = self.objectspace.value()
|
||||
value.type = 'calculation'
|
||||
value.name = fill.name
|
||||
if hasattr(fill, 'param'):
|
||||
param_to_delete = []
|
||||
for fill_idx, param in enumerate(fill.param):
|
||||
if param.type != 'string' and not hasattr(param, 'text'):
|
||||
raise DictConsistencyError(_(f"All '{param.type}' variables shall have a value in order to calculate {fill.target}"))
|
||||
if param.type not in ['suffix', 'string'] and not hasattr(param, 'text'):
|
||||
raise DictConsistencyError(_(f"All '{param.type}' variables must have a value in order to calculate {fill.target}"))
|
||||
if param.type == 'suffix' and hasattr(param, 'text'):
|
||||
raise DictConsistencyError(_(f"All '{param.type}' variables must not have a value in order to calculate {fill.target}"))
|
||||
if param.type == 'variable':
|
||||
try:
|
||||
param.text, suffix = self.objectspace.paths.get_variable_path(param.text,
|
||||
@ -1135,9 +1139,9 @@ class FamilyAnnotator:
|
||||
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 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
|
||||
|
@ -141,7 +141,7 @@
|
||||
<!ATTLIST group description CDATA #IMPLIED>
|
||||
|
||||
<!ELEMENT param (#PCDATA)>
|
||||
<!ATTLIST param type (string|number|variable|information) "string">
|
||||
<!ATTLIST param type (string|number|variable|information|suffix) "string">
|
||||
<!ATTLIST param name CDATA #IMPLIED>
|
||||
<!ATTLIST param notraisepropertyerror (True|False) "False">
|
||||
<!ATTLIST param optional (True|False) "False">
|
||||
|
@ -191,12 +191,16 @@ class Path:
|
||||
if name not in self.variables:
|
||||
for var_name, variable in self.variables.items():
|
||||
if variable['is_dynamic'] and name.startswith(var_name):
|
||||
if not with_suffix:
|
||||
raise Exception('This option is dynamic, should use "with_suffix" attribute')
|
||||
return variable, name[len(var_name):]
|
||||
if '.' not in name:
|
||||
for var_name, path in self.full_paths.items():
|
||||
if name.startswith(var_name):
|
||||
variable = self.variables[self.full_paths[var_name]]
|
||||
if variable['is_dynamic']:
|
||||
if not with_suffix:
|
||||
raise Exception('This option is dynamic, should use "with_suffix" attribute')
|
||||
return variable, name[len(var_name):]
|
||||
raise DictConsistencyError(_('unknown option {}').format(name))
|
||||
if with_suffix:
|
||||
|
@ -423,7 +423,9 @@ class Variable(Common):
|
||||
value['suffix'] = param.suffix
|
||||
return self.build_param(value)
|
||||
elif param.type == 'information':
|
||||
return f'ParamInformation("{param.text}")'
|
||||
return f'ParamInformation("{param.text}", None)'
|
||||
elif param.type == 'suffix':
|
||||
return f'ParamSuffix()'
|
||||
raise LoaderError(_('unknown param type {}').format(param.type))
|
||||
|
||||
def populate_value(self,
|
||||
|
Reference in New Issue
Block a user