Source code for viiapackage.supports.shallow_foundation.collect_supported_shapes

### ===================================================================================================================
###   Collect supported shapes for shallow foundations
### ===================================================================================================================
# Copyright ©VIIA 2024

### ===================================================================================================================
###   1. Import modules
### ===================================================================================================================

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, List, Union, Optional

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.shapes import Floor, Wall, Fstrip, Beam, Column, Points, Shapes

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject


### ===================================================================================================================
###   2. Helper functions for filtering and validating input
### ===================================================================================================================

def _viia_filter_excluded_surfaces(
        project: ViiaProject, input_list: List[Union[str, Fstrip]]) -> List[Fstrip]:
    """ Helper function to filter the list for excluded surfaces. Filtering to convert shape-names to object
    references and check class."""
    collected = []
    for shape in input_list:
        if isinstance(shape, str):
            conv_shape = project.find(description=shape, collection='fstrips')
            if conv_shape:
                shape = conv_shape
            else:
                project.write_log(
                    f"WARNING: The shape {shape} in the list excluded surfaces input for shallow foundations could not "
                    f"be converted. This function only accepts foundations strips in the project (name or object "
                    f"reference). Input is ignored.")
        if isinstance(shape, Fstrip):
            collected.append(shape)
        else:
            if hasattr(shape, 'name'):
                project.write_log(
                    f"WARNING: The shape {shape.name} in the list excluded surfaces input for shallow foundations "
                    f"could not be converted. This function only accepts foundations strips in the project (name or "
                    f"object reference). Input is ignored.")
            else:
                project.write_log(
                    f"WARNING: The shape {shape} in the list excluded surfaces input for shallow foundations "
                    f"could not be converted. This function only accepts foundations strips in the project (name or "
                    f"object reference). Input is ignored.")
    return collected


def _viia_filter_additional_shapes(
        project: ViiaProject, input_list: List[Union[str, Shapes]]) -> \
        List[Union[Floor, Wall, Fstrip, Beam, Column, Points]]:
    """ Helper function to filter the list for additional shapes. Filtering to convert shape-names to object
    references and check class."""
    collected = []
    for shape in input_list:
        if isinstance(shape, str):
            conv_shape = project.find(description=shape, collection='shapes')
            if conv_shape:
                shape = conv_shape
            else:
                project.write_log(
                    f"WARNING: The shape {shape} in the list additional shapes input for shallow foundations could not "
                    f"be converted. Input is ignored.")
        if isinstance(shape, (Floor, Wall, Beam, Column, Points)) and not isinstance(shape, Fstrip):
            collected.append(shape)
        elif isinstance(shape, Fstrip):
            project.write_log(
                f"WARNING: You should not provide a fstrip shape {shape.name} in the list additional shapes input "
                f"as the foundation strips are added by default. Input is ignored.")
        else:
            if hasattr(shape, 'name'):
                project.write_log(
                    f"WARNING: The shape {shape.name} in the list additional shapes input for shallow foundations "
                    f"could not be converted. Input is ignored.")
            else:
                project.write_log(
                    f"WARNING: The shape {shape} in the list additional shapes input for shallow foundations "
                    f"could not be converted. Input is ignored.")
    return collected


### ===================================================================================================================
###   3. Function to collect supported shapes for shallow foundation
### ===================================================================================================================

[docs]def viia_collect_supported_shapes( project: ViiaProject, excluded_supported_surfaces: Optional[List[Fstrip]] = None, additional_supported_shapes: Optional[List[Union[Floor, Wall, Fstrip, Beam, Column, Points]]] = None) -> \ List[Union[Fstrip, Floor, Wall, Fstrip, Beam, Column, Points]]: """ This function collects the list of supported surfaces for shallow foundations. This list contains all the foundation strip shapes in the project, except for the foundation strips provided in the excluded surfaces list. Additional shapes that need to be supported can be added to the list in additional supported shapes input list. The combined list of shapes is returned. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - excluded_supported_surfaces (list with obj): List with object references or names of shapes which have to be excluded from the supported shapes list. Default input is None, no foundation strips are excluded. - additional_supported_shapes (list with obj): List with object references of shapes which have to be supported in addition to shapes of class 'Fstrip'. Default input is None, no shapes are added. Output: - Returns list of shapes that supports will be applied on. """ # Convert input lists if excluded_supported_surfaces: excluded_supported_surfaces = _viia_filter_excluded_surfaces( project=project, input_list=excluded_supported_surfaces) else: excluded_supported_surfaces = [] if additional_supported_shapes: additional_supported_shapes = _viia_filter_additional_shapes( project=project, input_list=additional_supported_shapes) else: additional_supported_shapes = [] # Collect the supported surfaces in list return \ [fstrip for fstrip in project.collections.fstrips if fstrip not in excluded_supported_surfaces] + \ additional_supported_shapes
### =================================================================================================================== ### 4. End of script ### ===================================================================================================================