@@ -241,6 +241,8 @@ def __init__(self,
241
241
# List to store GeoJSON dicts of seeding commands
242
242
self .seed_geojson = []
243
243
244
+ self .required_variables = self .required_variables .copy () # Avoid modifying the class variable
245
+
244
246
self .env = Environment (self .required_variables , self ._config )
245
247
246
248
# Make copies of dictionaries so that they are private to each instance
@@ -1807,6 +1809,16 @@ def run(self,
1807
1809
if self .steps_calculation >= 1 :
1808
1810
self .steps_calculation = 0
1809
1811
1812
+ ###################################################################################
1813
+ # Remove variables from required_variables based on configuration and conditionals
1814
+ ###################################################################################
1815
+ for vn , var in self .required_variables .copy ().items ():
1816
+ if 'skip_if' in var :
1817
+ skip = self .evaluate_conditional (* var ['skip_if' ])
1818
+ if skip is True :
1819
+ logger .info (f'Skipping environment variable { vn } because of condition { var ["skip_if" ]} ' )
1820
+ self .required_variables .pop (vn )
1821
+
1810
1822
########################
1811
1823
# Simulation time step
1812
1824
########################
@@ -4755,3 +4767,34 @@ def center_of_gravity(self, onlysurface=False):
4755
4767
def gui_postproc (self ):
4756
4768
'''To be overloaded by subclasses'''
4757
4769
pass
4770
+
4771
+ def evaluate_conditional (self , key , operator , value ):
4772
+ """Evaluate a condition as True or False
4773
+
4774
+ This can be used to:
4775
+ - skip required_variables that are not required, based on config setting
4776
+ - store previous value of element property or environment variable, based on config setting
4777
+ - disable a config setting based on another setting (for dynamic menus)
4778
+
4779
+ key: config key string
4780
+ operator: one from operator_map below
4781
+ value: the provided value to be matched with operator against actual config setting
4782
+
4783
+ Returns: True or False
4784
+ """
4785
+
4786
+ operator_map = {
4787
+ '==' : lambda x , y : x == y ,
4788
+ '!=' : lambda x , y : x != y ,
4789
+ '<' : lambda x , y : x < y ,
4790
+ '<=' : lambda x , y : x <= y ,
4791
+ '>' : lambda x , y : x > y ,
4792
+ '>=' : lambda x , y : x >= y ,
4793
+ 'is' : lambda x , y : x is y ,
4794
+ 'is not' : lambda x , y : x is not y ,
4795
+ }
4796
+
4797
+ # Presently assuming that key is a config key
4798
+ key = self .get_config (key )
4799
+
4800
+ return operator_map [operator ](key , value )
0 commit comments