from dlubal.api import rfem, common

def main():
    with rfem.Application(port=9000) as rfem_app:
        # Check subscription info
        print(rfem_app.get_subscription_info())

        # Get global settings tree table for Steel Design add-on (active model)
        design_settings: rfem.GlobalSettingsTreeTable = rfem_app.get_design_settings(
            addon=rfem.DesignAddons.CONCRETE_DESIGN
        )
        print(f"rfem.DesignAddons.CONCRETE_DESIGN:\n{design_settings}")

        # *************************************************************************
        chapter = 'configuration'
        key1='configuration_uls'
        design_path = [
            chapter,
            key1
        ]
        # get_tree_value is not necessary just for demonstration
        # it is the best way to test the path, if it is wrong None is returned
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=True,
        )
        key2 = 'fatigue'
        design_path = [
            chapter,
            key1,
            key2
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=True,
        )

        key1 = 'configuration_sls'
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f'{design_path}: {design_val}')
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=True,
        )

        key1 = 'detailing_of_reinforcement'
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f'{design_path}: {design_val}')
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=True,
        )

        key1 = 'configuration_fire_resistance'
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=False,
        )

        key1 = 'configuration_seismic'
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=True,
        )

        # *************************************************************************
        chapter = 'interaction_diagram'
        key1 = 'interaction_diagram_vertical_division_in_compression_part' # int=12
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=11,
        )

        key1 = 'interaction_diagram_vertical_division_in_tension_part' # int=6
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=6,
        )

        key1 = 'interaction_diagram_horizontal_quadrant_division'  # int=9
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=8,
        )

        key1 = 'interaction_diagram_stiffness_division'  # int=20
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=19,
        )

        # Set specific value from the global settings
        rfem_app.set_design_settings(
            addon=rfem.DesignAddons.CONCRETE_DESIGN,
            global_settings_tree_table=design_settings
        )

if __name__ == '__main__':
    main()