Source code for viiapackage.pictures.model_pictures.model_pictures

### ===================================================================================================================
###  FUNCTION: Creating model pictures
### ===================================================================================================================
# Copyright ©VIIA 2024

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

# General imports
from __future__ import annotations
import json
from typing import TYPE_CHECKING, List

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.shape_geometries import ReferencePoint
from rhdhv_fem.general import Direction
from rhdhv_fem.shapes import Reinforcements
from rhdhv_fem.plotting import fem_set_colour_lists
from rhdhv_fem.pictures import ModelPicture

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.pictures.model_pictures.helper_functions import viia_get_model_picture_name
from viiapackage.pictures.model_pictures.helper_functions import viia_model_picture_legend_data


### ===================================================================================================================
###    2. User function to create the default VIIA model pictures
### ===================================================================================================================

[docs]def viia_create_model_pictures(project: ViiaProject, backside: bool = False) -> List[ModelPicture]: """ This function creates the model pictures for VIIA. The instances of ModelPicture class are created and added to project. The images will only be created when this function is used in DIANA (in development for ABAQUS) and when the model is created and meshed. The images are saved to the image folder set in ViiaStatus. .. warning:: Currently piles and reinforcements are not supported. Backside input argument is not available yet. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - backside(bool): If set to True, also the pictures in the opposite direction are created. Output: - Returns list of instances of ModelPicture class with all model pictures required for VIIA. - The images are created in the model picture folder with the current time stamp and version, in the software where script is running. """ # Set up the picture list pictures = [] # Start with the model picture of the elements # First get all the layers layers = project.viia_get_layers() # Set all the colors list fem_set_colour_lists(project=project) # Set up the legend data for model pictures model_pics_legend_data = {} for i, _ in enumerate([item for item in [True, backside] if item]): view = None name_suffix = None # Create normal view name_suffix = '' view = None if i == 0: view = project.create_view(name='ISO1') # Collect viewpoint information and create backside view if backside view if i == 1: current_view_point = list(project.rhdhvDIANA.currentViewPoint()) viewpoint, upward_direction, focal_point, view_angle, parallel_scale_factor = \ ReferencePoint([current_view_point[1], current_view_point[0], current_view_point[2]]), \ Direction(current_view_point[3:6]), ReferencePoint(current_view_point[6:9]), current_view_point[9], \ current_view_point[10] view = project.create_view( name='ISO1-back', viewpoint=viewpoint, focal_point=focal_point, upward_direction=upward_direction, view_angle=view_angle, parallel_scale_factor=parallel_scale_factor) name_suffix = '_backside' # create renders render_building = project.create_render( name=f'render_model_pic_building', geometry=None, mesh='solid shading with free face edge') render_element = project.create_render( name=f'render_model_pic_element', geometry=None, mesh='solid shading with feature edge') render_reinforcement = project.create_render( name=f'render_model_pic_reinforcement', geometry=None, mesh='solid shading with feature edge', mesh_reinforcements='solid shading with feature edge') # Single colour for all shapes and reinforcements that are present. shape_colours = [ project.diana_settings.picture_settings['background_shape_colour'] for shape in project.collections.shapes if not isinstance(shape, Reinforcements)] reinforcement_colours = [ project.diana_settings.picture_settings['background_shape_colour'] for reinforcement in project.collections.reinforcements] # Create model picture for the complete building pictures.append(project.create_model_picture( name=f'BUILDING{name_suffix}', view=view, render=render_building, shapes=[shape for shape in project.collections.shapes if not isinstance(shape, Reinforcements)], reinforcements=project.collections.reinforcements, shape_colours=shape_colours, reinforcement_colours=reinforcement_colours)) # Get all the shapes and reinforcement before excluding shapes layer by layer plot_shapes = [shape for shape in project.collections.shapes if not isinstance(shape, Reinforcements)] plot_reinforcements = [reinforcement for reinforcement in project.collections.reinforcements] # Set background color background_shape_colour = project.diana_settings.picture_settings['background_shape_colour'] # Start from top layer for layer in reversed(layers): # Surface reinforcements of the layer if layer.surface_reinforcements: reinforcements = [] reinforcement_colours = [] shapes = [] shape_colours = [] for reinforcement in plot_reinforcements: if reinforcement in layer.surface_reinforcements: reinforcement_colours.append( project.surface_reinforcement_colour_dictionary[reinforcement.material][ reinforcement.geometry]) else: reinforcement_colours.append(background_shape_colour) reinforcements.append(reinforcement) for shape in plot_shapes: shape_colours.append(background_shape_colour) shapes.append(shape) picture_name = viia_get_model_picture_name(layer=layer, element='SurfaceReinforcement') legend_data = viia_model_picture_legend_data( project=project, model_picture_name=picture_name, json_dir=project.current_analysis_folder, shape_colours=shape_colours, shapes=shapes, element='surface_reinforcement') if legend_data: model_pics_legend_data.update(legend_data) # Create model picture surface reinforcements pictures.append(project.create_model_picture( name=picture_name + name_suffix, view=view, render=render_reinforcement, shapes=shapes, reinforcements=reinforcements, shape_colours=shape_colours, reinforcement_colours=reinforcement_colours)) # Remove surface reinforcements from plot reinforcements plot_reinforcements = [reinforcement for reinforcement in plot_reinforcements if reinforcement not in layer.surface_reinforcements] # Walls of the layer if layer.walls: shapes = [] shape_colours = [] for shape in plot_shapes: if shape in layer.walls: thickness = shape.geometry.geometry_model.thickness shape_colours.append(project.wall_colour_dictionary[shape.material][thickness]) else: shape_colours.append(background_shape_colour) shapes.append(shape) # Remove walls from plot shapes plot_shapes = [shape for shape in plot_shapes if shape not in layer.walls] if layer.lintels: for shape in plot_shapes: if shape in layer.lintels: shape_colours.append(project.beam_colour_dictionary[shape.material][shape.geometry]) else: shape_colours.append(background_shape_colour) shapes.append(shape) # Remove lintels from plot shapes plot_shapes = [shape for shape in plot_shapes if shape not in layer.lintels] picture_name = viia_get_model_picture_name(layer=layer, element='WANDEN') legend_data = viia_model_picture_legend_data( project=project, model_picture_name=picture_name, json_dir=project.current_analysis_folder, shape_colours=shape_colours, shapes=shapes, element='wall') if legend_data: model_pics_legend_data.update(legend_data) # Create model picture walls pictures.append(project.create_model_picture( name=picture_name + name_suffix, view=view, render=render_element, shapes=shapes, shape_colours=shape_colours, shapes_with_mesh_thickness=layer.lintels)) # Roofs of the layer if layer.roofs: shapes = [] shape_colours = [] for shape in plot_shapes: if shape in layer.roofs: thickness = shape.geometry.geometry_model.thickness shape_colours.append(project.roof_colour_dictionary[shape.material][thickness]) else: shape_colours.append(background_shape_colour) shapes.append(shape) picture_name = viia_get_model_picture_name(layer=layer, element='DAKEN') legend_data = viia_model_picture_legend_data( project=project, model_picture_name=picture_name, json_dir=project.current_analysis_folder, shape_colours=shape_colours, shapes=shapes, element='roof') if legend_data: model_pics_legend_data.update(legend_data) # Create model picture roofs pictures.append(project.create_model_picture( name=picture_name + name_suffix, view=view, render=render_element, shapes=shapes, shape_colours=shape_colours)) # Remove roofs from plot shapes plot_shapes = [shape for shape in plot_shapes if shape not in layer.roofs] # Floors of the layer if layer.floors: shapes = [] shape_colours = [] for shape in plot_shapes: if shape in layer.floors: thickness = shape.geometry.geometry_model.thickness shape_colours.append(project.floor_colour_dictionary[shape.material][thickness]) else: shape_colours.append(background_shape_colour) shapes.append(shape) picture_name = viia_get_model_picture_name(layer=layer, element='VLOEREN') legend_data = viia_model_picture_legend_data( project=project, model_picture_name=picture_name, json_dir=project.current_analysis_folder, shape_colours=shape_colours, shapes=shapes, element='floor') if legend_data: model_pics_legend_data.update(legend_data) # Create model picture floors pictures.append(project.create_model_picture( name=picture_name + name_suffix, view=view, render=render_element, shapes=shapes, shape_colours=shape_colours)) # Remove floors from plot shapes plot_shapes = [shape for shape in plot_shapes if shape not in layer.floors] # Beams of the layer if layer.beams: shapes = [] shape_colours = [] for shape in plot_shapes: if shape in layer.beams: shape_colours.append(project.beam_colour_dictionary[shape.material][shape.geometry]) else: shape_colours.append(background_shape_colour) shapes.append(shape) picture_name = viia_get_model_picture_name(layer=layer, element='BALKEN') legend_data = viia_model_picture_legend_data( project=project, model_picture_name=picture_name, json_dir=project.current_analysis_folder, shape_colours=shape_colours, shapes=shapes, element='beam') if legend_data: model_pics_legend_data.update(legend_data) # Create model picture beams pictures.append(project.create_model_picture( name=picture_name + name_suffix, view=view, render=render_element, shapes=shapes, shape_colours=shape_colours, shapes_with_mesh_thickness=layer.beams)) # Remove beams from plot shapes plot_shapes = [shape for shape in plot_shapes if shape not in layer.beams] # Columns of the layer if layer.columns: shapes = [] shape_colours = [] for shape in plot_shapes: if shape in layer.columns: shape_colours.append(project.beam_colour_dictionary[shape.material][shape.geometry]) else: shape_colours.append(background_shape_colour) shapes.append(shape) picture_name = viia_get_model_picture_name(layer=layer, element='KOLOMMEN') legend_data = viia_model_picture_legend_data( project=project, model_picture_name=picture_name, json_dir=project.current_analysis_folder, shape_colours=shape_colours, shapes=shapes, element='column') if legend_data: model_pics_legend_data.update(legend_data) # Create model picture columns pictures.append(project.create_model_picture( name=picture_name + name_suffix, view=view, render=render_element, shapes=shapes, shape_colours=shape_colours, shapes_with_mesh_thickness=layer.columns)) # Remove columns from plot shapes plot_shapes = [shape for shape in plot_shapes if shape not in layer.columns] # Foundation strips of the layer if layer.fstrips: shapes = [] shape_colours = [] for shape in plot_shapes: if shape in layer.fstrips: thickness = shape.geometry.geometry_model.thickness shape_colours.append(project.fstrip_colour_dictionary[shape.material][thickness]) else: shape_colours.append(background_shape_colour) shapes.append(shape) picture_name = viia_get_model_picture_name(layer=layer, element='STROKEN') legend_data = viia_model_picture_legend_data( project=project, model_picture_name=picture_name, json_dir=project.current_analysis_folder, shape_colours=shape_colours, shapes=shapes, element='fstrip') if legend_data: model_pics_legend_data.update(legend_data) # Create model picture foundation strips pictures.append(project.create_model_picture( name=picture_name + name_suffix, view=view, render=render_element, shapes=shapes, shape_colours=shape_colours)) # Remove fstrips from plot shapes plot_shapes = [shape for shape in plot_shapes if shape not in layer.fstrips] # Piles of the layer if layer.piles: shapes = [] shape_colours = [] reinforcements = [] reinforcement_colours = [] for shape in project.collections.piles: shape_colours.append(project.pile_colour_dictionary[shape.material][shape.geometry]) shapes.append(shape) if shape.parent: for reinforcement in shape.parent.reinforcements: reinforcement_colours.append( project.line_reinforcement_colour_dictionary[reinforcement.material][ reinforcement.geometry]) reinforcements.append(reinforcement) picture_name = viia_get_model_picture_name(layer=layer, element='PALEN') # Create model picture piles pictures.append(project.create_model_picture( name=picture_name + name_suffix, view=view, render=render_element, shapes=shapes, shape_colours=shape_colours, shapes_with_mesh_thickness=shapes)) # Create the top view specifically for pile picture top_view = project.create_view(name='TOP') pictures.append(project.create_model_picture( name=picture_name + '_top_view', view=top_view, render=render_element, shapes=shapes, shape_colours=shape_colours, shapes_with_mesh_thickness=shapes)) for name in [picture_name, f'{picture_name}_top_view']: legend_data = viia_model_picture_legend_data( project=project, model_picture_name=name, json_dir=project.current_analysis_folder, shape_colours=shape_colours, shapes=shapes, element='pile') if legend_data: model_pics_legend_data.update(legend_data) plot_shapes = [shape for shape in plot_shapes if shape not in shapes] plot_reinforcements = [reinforcement for reinforcement in plot_reinforcements if reinforcement not in reinforcements] # Remove all the other shapes and reinforcements in this layer plot_shapes = [shape for shape in plot_shapes if shape not in layer.shapes] plot_reinforcements = [reinforcement for reinforcement in plot_reinforcements if reinforcement not in layer.reinforcements] # Write the json file of legend info json_name = project.current_analysis_folder / 'legend_info.json' with json_name.open('a+') as f: json.dump(model_pics_legend_data, f, indent=2) project.write_log(f"Output the legend info is done. File saved: {json_name.as_posix()}.") # Create the images if project.rhdhvDIANA.model_created: # Create the images in DIANA for picture in pictures: picture.to_diana(folder=project.current_analysis_folder) # Set the view back the default view view.to_diana() render_building.to_diana( shapes=[shape for shape in project.collections.shapes if not isinstance(shape, Reinforcements)], reinforcements=project.collections.reinforcements, shape_colours=[ project.diana_settings.picture_settings['background_shape_colour'] for shape in project.collections.shapes if not isinstance(shape, Reinforcements)], reinforcement_colours=[ project.diana_settings.picture_settings['background_shape_colour'] for reinforcement in project.collections.reinforcements]) # Set viewpoint back to ISO1 project.rhdhvDIANA.setViewPoint('ISO1') # Notifications for user and return the created model pictures project.write_log(f"{len(pictures)} model pictures for {project.name} are created in DIANA.") elif project.software == 'abaqus': # Create the images in ABAQUS for picture in pictures: picture.to_abaqus(folder=project.current_analysis_folder) # Return the created instances of ModelPicture class return pictures
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================