from dlubal.api import rfem, common
import app.helpers.print_helper as print_helper

def main():
    # Connect to the RFEM application
    with rfem.Application() as rfem_app:
        # Create a new ULS Configuration for Walls
        print_helper.header1_top(f'ConcreteDesignUlsConfiguration no=2 for Walls')
        concrete_uls_config_no2 = rfem.concrete_design_objects.ConcreteDesignUlsConfiguration(
            no=2,
            name='Walls',
            assigned_to_surfaces=[1, 2, 3, 6],
        )

        # Use empty SettingsSurfaceEc2TreeTable from new ULS Configuration
        settings_surface_ec2_uls_current = concrete_uls_config_no2.settings_surface_ec2
        chapter = 'surface_internal_forces'
        key1 = 'surface_internal_forces_no_optimization'
        design_path = [
            chapter,
            key1,
        ]
        design_value = True
        print(f"{design_path}: {design_value}")
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )
        key1 = 'surface_internal_forces_optimization'
        design_path = [
            chapter,
            key1,
        ]
        design_value = False
        print(f"{design_path}: {design_value}")
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )
        chapter = 'limits_of_reinforcement_areas'
        key1 = 'minimum_longitudinal_reinforcement_acc_to_standard'
        design_path = [
            chapter,
            key1,
        ]
        design_value = common.get_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
        )
        print(f"{design_path}: {design_value}")
        design_value = True
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )
        key2 = 'minimum_longitudinal_reinforcement_for_plates'
        design_path = [
            chapter,
            key1,
            key2,
        ]
        design_value = common.get_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
        )
        print(f"{design_path}: {design_value}")
        design_value = False
        # print(f"{design_path}: {design_value}")
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )
        key2 = 'minimum_longitudinal_reinforcement_for_walls'
        design_path = [
            chapter,
            key1,
            key2,
        ]
        design_value = common.get_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
        )
        print(f"{design_path}: {design_value}")
        design_value = True
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )

        key3 = 'direction_of_main_compression_reinforcement'
        key4 = 'reinforcement_direction_with_the_main_compression_force'
        design_path = [
            chapter,
            key1,
            key2,
            key3,
            key4
        ]
        design_value = common.get_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
        )
        print(f"{design_path}: {design_value}")
        design_value = True
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )
        key4 = 'defined_in_reinforcement_direction'
        design_path = [
            chapter,
            key1,
            key2,
            key3,
            key4
        ]
        design_value = common.get_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
        )
        print(f"{design_path}: {design_value}")
        design_value = False

        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )

        key1 = 'maximum_longitudinal_reinforcement_acc_to_standard'
        design_path = [
            chapter,
            key1,
        ]
        design_value = common.get_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
        )
        print(f"{design_path}: {design_value}")
        design_value = True
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )
        key2 = 'maximum_longitudinal_reinforcement_for_plates'
        design_path = [
            chapter,
            key1,
            key2,
        ]
        design_value = False
        print(f"{design_path}: {design_value}")
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )
        key2 = 'maximum_longitudinal_reinforcement_for_walls'
        design_path = [
            chapter,
            key1,
            key2,
        ]
        design_value = True
        print(f"{design_path}: {design_value}")
        common.set_tree_value(
            tree=settings_surface_ec2_uls_current,
            path=design_path,
            value=design_value
        )
        print_helper.header1_bottom()

        # Create the new ULS Configuration in the model
        rfem_app.create_object(obj=concrete_uls_config_no2)

if __name__ == '__main__':
    main()