### =============================================================================================================== ###
### ###
### viiaConnections.py ###
### ###
### =============================================================================================================== ###
# This module ``viiaConnections`` contains the functions that handle the connections between shapes. Functions are to
# find the connecting points and functions to create functions for relations between two shapes.
# Module is based on:
# VIIA_QE_R376 Basis of Design Retrofit Advice NLTH, v11.0, d.d. 29 August 2024
# VIIA_QE_R376 Basis of Design Step-by-Step MRS, v1.0, d.d. 21 January 2022
# VIIA_QE_R1674 Uitgangspuntenrapport engineering NLPO, v1.0, d.d. 1 August 2019
# This script was based upon the Constitution For Python At VIIA
# For use by VIIA
# Copyright RHDHV
### ===================================================================================================================
### Contents script
### ===================================================================================================================
# 1. Import modules
# 2. Connect shapes
# 3. Create connections
# 4. Remove connections
# 5. End of script
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING, List, Dict, Optional, Union
from datetime import datetime
# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_tools import fem_create_folder
from rhdhv_fem.fem_math import fem_point_on_line
from rhdhv_fem.general import Direction
from rhdhv_fem.shape_geometries import Node, Line
from rhdhv_fem.shapes import Shapes, Lines, Surfaces, Floor
from rhdhv_fem.fem_shapes import fem_connect_shape
from rhdhv_fem.connections import Connections, Tying
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
from viiapackage.viiaSettings import ViiaSettings
from viiapackage.connections import get_connection_data, get_connection_data_diana, get_node_data_diana, \
create_node_data_pdf, get_connection_data_shape, get_shape_node_data_diana, create_shape_data_pdf
from viiapackage.connections.helper_functions import viia_create_hinge_connection, viia_create_non_hinge_connection, \
viia_get_input_for_hinges
from viiapackage.general.file_handling.viia_filename import viia_to_filename
### ===================================================================================================================
### 2. Connect shapes
### ===================================================================================================================
[docs]def _viia_connect_shape(project: ViiaProject, shape: Shapes):
"""
This functions connects the shape with all shapes in the model. For surfaces, it finds lines which completely on the
surface and add those lines to the surface as internal line. It also finds lines which are completely on the contour
of a surface and add the points of the line to the contour. Besides it find nodes which are on the surface and add
those as internal points or add them to the contour.
For lines, it finds nodes which are on the line and add those node as internal point.
.. note:: Function does not run in DIANA if model is created.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- shape (obj): Object reference of shape which should be connected.
Output:
- All surface-shapes are updated with coordinates of other shapes which are on the contour of the surface-shape.
- All surface-shapes are updated with shape-geometry lines of other shapes, which are in the plane of the
surface-shape, as internal lines.
- All surface-shapes are updated with shape-geometry nodes of other shapes, which are in the plane of the
surface-shape, as internal points.
"""
# Check if model is already created, otherwise return
if project.rhdhvDIANA.model_created:
project.write_log(
f"ERROR: Project method viia_connect_shape can only be used before creating the shapes in DIANA. "
f"Shape '{shape.name}' not connected.")
return
# Perform the connecting function in fem-package
fem_connect_shape(shape)
[docs]def _viia_connect_all_shapes(project: ViiaProject, list_of_shapes: Union[str, List[Shapes]] = 'ALL'):
"""
This functions connects all surface- and line-shapes with all volume-, surface-, line- and point-shapes. First, all
lines and nodes in the project will be merged. For surfaces, it finds lines which completly on the surface and
add those lines to the surface as internal line. It also finds lines which are completly on the contour of a surface
and add the points of the line to the contour. Besides it find nodes which are on the surface and add those as
internal points or add them to the contour. For lines, it finds nodes which are on the line and add those node as
internal point.
.. note:: Function will only run in PY-editor, or if model is not created.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- list_of_shapes (list of Obj): List with object references of shapes that will be checked if they are
connecting to the requested shape. Default value is 'ALL', indicating that all shapes present will be checked.
Output:
- No more double Line(ShapeGeometries) and Node(ShapeGeometries) objects.
- All shapes are connected.
"""
# Check if model is already created, otherwise return
if project.rhdhvDIANA.model_created:
project.write_log(
f"ERROR: Project method connect_all_shapes can only be used before creating the shapes in DIANA. "
f"Shapes not connected.")
return
# Merge all nodes
project.merge_all_nodes()
# Merge all lines
project.merge_all_lines()
# Perform the connecting function in fem-package
project.connect_all_shapes(shapes_list=list_of_shapes)
[docs]def _viia_connections_get_mappings(project: ViiaProject, print_to_screen: bool = False):
"""
This function can be used to print a mapping corresponding between geometry pairs and unique ID of the connection.
Function generates mappings for all connections in project.collections.connections that were named using the unique
ID function.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- print_to_screen (bool, optional): bool specified if the mapping list should be printed to screen.
Default value False.
Output:
- Returns a dictionary. A dictionary with frozen sets of shape pairs in the connection as keys and dictionary
as source, target names and unique IDs as values.
"""
dictionary = {}
for connection in project.collections.connections:
source_name = connection.connecting_shapes['source_connecting_shape'].name
target_name = connection.connecting_shapes['target_connecting_shape'].name
unique_id = connection.name.split('[')[-1].split(']')[0]
if '[' in connection.name and ']' in connection.name:
dictionary[frozenset((source_name, target_name))] = {
'source': source_name,
'target': target_name,
'id': unique_id}
project.write_log("============= Geometry shape to connection id mappings =============", print_to_screen, True)
for key in dictionary:
project.write_log(dictionary[key]['id'] + ':', print_to_screen, True)
project.write_log("\tSource shape: " + dictionary[key]['source'], print_to_screen, True)
project.write_log("\tTarget shape: " + dictionary[key]['target'], print_to_screen, True)
project.write_log("==================================================================", print_to_screen)
return dictionary
### ===================================================================================================================
### 3. Create connections
### ===================================================================================================================
[docs]def viia_create_connection(
project: ViiaProject, source: Union[Surfaces, Lines, str], target: Union[Surfaces, Lines, str],
detail: str, is_linear=False, thickness_interface: Optional[float] = None,
area_interface: Optional[float] = None, switch: bool = False, flip: bool = False,
local_x_axis: Optional[list] = None, local_y_axis: Optional[list] = None,
degrees_of_freedom: Optional[List[int]] = None):
"""
Function to connect two shapes with a certain detail as described in Basis of Design (UPR).
.. note:: Before using this function make sure the two shapes are connected. For this the
project.viia_connect_shape function can be used.
.. warning:: Check your result in the model, as there are a lot of exceptions known to cause an error when
applying the function, when meshing or running the model in DIANA.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- source (obj): Object reference of source shape. This might be a surface or line-shape and depends on the
requested detail. Alternative (str): The name of the source shape can be provided.
- target (obj): Object reference of target shape. This might be a surface or line-shape and depends on the
requested detail. Alternative (str): The name of the target shape can be provided.
- detail (str): Detail number as described in the Basis of Design (UPR). For example 'D2.01'. For hinges, it
should be specified as 'HINGE-P' for point hinges and as 'HINGE-L' for line hinges. D2.01C is the same as
D2.01B but the support area is a half (e.g beam supported in perimeter wall).
- is_linear (bool): Select to apply linear material properties, default value is False.
- thickness_interface (float): Option to manually set interface thickness for line interfaces, in [m].
**Required for: D3.03.**
- area_interface (float): Option to manually set interface area for point interfaces, in [m2].
- switch (bool): Option to switch the source and target shapes. If True, shapes are switched. Unlike the flip,
the switch is performed in the geometry model. Default value is false.
- flip (bool): Option to flip the local z-axis of the interface. If neither local_x_axis nor local_y_axis are
defined, then the flip is done *after* the local axes have been corrected after making the model. The flip is
only performed after running viia_create_model(). Default value is False.
- local_x_axis (list): Option for point interfaces to manually define the local x-axis of the interface.
Conversely, it can also be used to specify the local x-axis for hinges. If for hinges, please also specify the
next argument local_y_axis.
- local_y_axis (list): Option for point and line interfaces to manually define the local y-axis of the
interface. **Required for: D3.03.**.
Conversely, it can be used to specify the local y-axis of a hinge. If for hinges, please also specify the
argument local_x_axis.
- degrees_of_freedom (list with 3 integers): List with the rotational degrees of freedom to be tied when
creating a hinge. The list contains the rotational degrees of freedom or rotation about the local x-, y- and
z-axes.
Output:
- The connection is created in PY-memory.
For example:
>>> viia_create_connection(Wall1, Floor1, 'D2.01')
>>> viia_create_connection(Wall1, Floor1, 'HINGE-L')
"""
# Create non-hinged connections
if 'HINGE' not in detail:
return viia_create_non_hinge_connection(
project=project, source=source, target=target, detail=detail, is_linear=is_linear,
thickness_interface=thickness_interface, area_interface=area_interface, switch=switch, flip=flip,
local_x_axis=local_x_axis, local_y_axis=local_y_axis)
# Create hinged connections
else:
return viia_create_hinge_connection(
project=project, source=source, target=target, detail=detail, local_x_axis=local_x_axis,
local_y_axis=local_y_axis, degrees_of_freedom=degrees_of_freedom)
[docs]def viia_create_tying(
project: ViiaProject, source: Union[Surfaces, Lines, str], target: Union[Surfaces, Lines, str],
source_node: Optional[Node] = None, target_node: Optional[Node] = None,
degrees_of_freedom: Optional[List[List[float]]] = None,
axes: Optional[List[Union[str, int, Direction]]] = None) -> List[Tying]:
"""
Function to connect two shapes with a tying. This is not a default approach in the VIIA workflow, but can be applied
in specific situations after consultation with the lead engineer. This function needs to be used to comply to the
naming convention, which is used in the phasing and result handling.
.. note:: Before using this function make sure the two shapes are connected (only in case you want to apply a tying
on a coinciding node). For this the project.viia_connect_shape function can be used.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- source (obj): Object reference of source shape. This might be a surface or line-shape and depends on the
requested detail. Alternative (str): The name of the source shape can be provided.
- target (obj): Object reference of target shape. This might be a surface or line-shape and depends on the
requested detail. Alternative (str): The name of the target shape can be provided.
- source_node (obj): Object reference of source node for the tying. Default value is None, in which case the
source node is retrieved based on the other inputs. For example if the shapes are connecting with a shared
node or nodes, these nodes can be found automatically.
- target_node (obj): Object reference of target node for the tying. Default value is None, in which case the
target node is retrieved based on the other inputs (see also source node).
- degrees_of_freedom (list of 2 lists with 3 integers): Lists with the translational and rotational degrees
of freedom to be tied. The first list contains the translational degrees of freedom in the local x-, y-
and z-axes. The second list contains the rotational degrees of freedom or rotation about the local x-, y-
and z-axes. Default value is [[0, 0, 0], [1, 1, 1]].
- axes (list of obj): List defining the local axes. The directions in the list are instances of the
Direction class. The length of the list should be three in the order of local x, y, z-direction.
Default value is None, which will generate default directions depending on connection type (point, line
or surface connection).
Output:
- Returns the created tying.
"""
# Convert and check input for the source and target
source, target = viia_get_input_for_hinges(project=project, source=source, target=target)
# Select the uppermost level for the connecting shapes
layer = project.viia_get_highest_layer(layer1=source.layer, layer2=target.layer, name=True)
# Create the connecting_shapes for the tying
collected_connecting_shapes = []
# Check if nodes are provided
if source_node or target_node:
if source_node and target_node is None:
target_nodes = target.get_nodes()
if source_node in target_nodes:
target_node = source_node
elif len(target_nodes) == 1:
target_node = target_nodes[0]
else:
raise ValueError(
f"ERROR: The source node {source_node} for the tying was provided, but the target node is missing, "
f"please provide a node on the target shape.")
if target_node and source_node is None:
source_nodes = source.get_nodes()
if target_node in source_nodes:
source_node = target_node
elif len(source_nodes) == 1:
source_node = source_nodes[0]
else:
raise ValueError(
f"ERROR: The target node {target_node} for the tying was provided, but the source node is missing, "
f"please provide a node on the source shape.")
collected_connecting_shapes.append({
'source_connecting_shape': source, 'source_shape_geometry': source_node,
'target_connecting_shape': target, 'target_shape_geometry': target_node})
else:
for con_node in source.get_connecting_nodes(target):
collected_connecting_shapes.append({
'source_connecting_shape': source, 'source_shape_geometry': con_node,
'target_connecting_shape': target, 'target_shape_geometry': con_node})
# Create the tyings
tyings = []
for connecting_shapes in collected_connecting_shapes:
# Create the name for the tying based on the uppermost level for the connecting shapes
name = f"{layer}-Tying-{str(project.find_max_id(collection=project.collections.tyings) + 1).zfill(3)}"
# Create the tying as such in the rhdhv_fem-package
tying = project.create_tying(
connecting_shapes=connecting_shapes, name=name, degrees_of_freedom=degrees_of_freedom, axes=axes)
if tying:
tyings.append(tying)
return tyings
[docs]def viia_disconnect_shape(project: ViiaProject, shape: Shapes, shapes_to_exclude: List[Union[Shapes, str]] = None):
"""
Function to apply NOCON connections to all connecting shapes.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- shape (obj): Shape that need to be disconnect from other shapes
- shapes_to_exclude (list of str/obj): List with shapes that should stay connected to the shape. Can be given as
name of the shape or object reference. Default is None.
Output:
- The connections that are made
"""
connections = []
for connecting_shape in shape.get_connecting_shapes():
if shapes_to_exclude and \
(connecting_shape in shapes_to_exclude or
(isinstance(connecting_shape, Shapes) and connecting_shape.name in shapes_to_exclude)):
continue
if shape.get_connecting_lines(shape=connecting_shape):
detail = 'NOCON-L'
else:
detail = 'NOCON-P'
connections.append(project.viia_create_connection(source=shape, target=connecting_shape, detail=detail))
return connections
### ===================================================================================================================
### 4. Remove connections
### ===================================================================================================================
[docs]def _viia_remove_connection(project: ViiaProject, connection: Connections):
"""
This function removes the Interface or Connection object from the ViiaProject. Function should be operated before
creating model in DIANA. The name of the connection should be aligned with the VIIA name convention.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- connection (obj): The Connections object.
Output:
- Returns a dictionary that contains the information which can be used to recreate the connection.
"""
# Construct the dict for the connection attributes
# Gather all the necessary attributes for the connection
connection_dict = {parameter: getattr(connection, parameter) for parameter in connection.parameters.keys()}
connection_dict.update({'class_': connection.__class__})
# Remove the interface
connection.remove_connection()
# Return the dictionary
return connection_dict
[docs]def _viia_remove_floor_connections(project: ViiaProject, floor: Union['Floor', str]):
"""
This function removes all interfaces of a Floor object completely in the ViiaProject. Function should be operated
before creating model in DIANA. A list of dictionaries with all the removed interfaces will be returned.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- floor (obj): Object reference of floor for which the connections should be removed. Alternative: Name of the
floor.
Output:
- Returns a list of dictionaries containing the information which can be used to recreate the connections that
were connecting to the floor.
"""
# Argument handling
if isinstance(floor, Floor):
pass
elif isinstance(floor, str):
floor = project.viia_get('floors', floor)
else:
raise ValueError("ERROR: The input for removing the interfaces should be floor, please check your input.")
# Construct the list to store all the connection dictionaries
connection_lst = list()
# Loop through the connections to collect the connections connecting to the floor
# also include all the connections where they used the shape geometry of the floor
connection_floor = [connection for connection in floor.connections]
# Avoid searching the connections already in the floor connections
search_connections = [connection
for connection in project.collections.connections if connection not in floor.connections]
# Search through the connections to find if the shape geometry is overlapping
geometry_shape_lst = list()
for connection in floor.connections:
geometry_shape_lst.append(connection.connecting_shapes['source_shape_geometry'])
# Add the target shape geometry if there is one
try:
geometry_shape_lst.append(connection.connecting_shapes['target_shape_geometry'])
except KeyError:
pass
for connection in search_connections:
try:
if connection.connecting_shapes['source_shape_geometry'] in geometry_shape_lst or \
connection.connecting_shapes['target_shape_geometry'] in geometry_shape_lst:
connection_floor.append(connection)
except KeyError:
# Skip the connections without source_shape_geometry or target_shape_geometry
pass
for connection in reversed(connection_floor):
connection = _viia_remove_connection(project, connection)
connection_lst.append(connection)
# Return the list containing the connections dictionaries
return connection_lst
[docs]def _viia_restore_floor_connections(project: ViiaProject, connections: List[Dict]):
"""
This function restores all interfaces of a Floor object removed from the ViiaProject. Function should be operated
before creating model in DIANA.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- connections (list of dictionaries): A list of the dictionaries used to recreate the connections.
Output:
- No output. The interfaces will be created in the ViiaProject.
"""
# Update all the shape geometries by the origin source shape geometry
def update_shape_geometry(shape, line_shape):
# Find all the lines of the shape
shape_lines = shape.get_lines()
# Construct the list to store the updated lines
updated_lines = list()
# Loop over the lines to check if both end nodes of the line are in the original shape geometry
for line in shape_lines:
# Get the coordinates of the shape geometry
line_coordinates = [node.coordinates for node in line_shape.get_nodes()]
# Check the nodes on the original shape line
nodes_on_line = [fem_point_on_line(node.coordinates, line_coordinates)
for node in [line.node_end, line.node_start]]
if all(nodes_on_line):
# Add the line if it is in the original line shape
updated_lines.append(line)
else:
pass
return updated_lines
# Create all the interfaces with the information
for connection in connections:
connecting_shapes = connection['connecting_shapes']
# Retrive the class needed to be initiated
class_ = connection['class_']
# Check if the source shape geometry is a point
if isinstance(connecting_shapes['source_shape_geometry'], Line):
# Update the lines in the source connecting shape
updated_source_lines = update_shape_geometry(connecting_shapes['source_connecting_shape'],
connecting_shapes['source_shape_geometry'])
# Check if target connecting shape is in
target_check = False
if 'target_connecting_shape' in connecting_shapes.keys():
updated_target_lines = update_shape_geometry(connecting_shapes['target_connecting_shape'],
connecting_shapes['target_shape_geometry'])
target_check = True
# Check if all the target lines are the same as the source lines
if all([line in updated_source_lines for line in updated_target_lines]):
pass
else:
raise NotImplementedError(
f"The recreation for open connection {connection['name']} is not implemented yet.")
for line in updated_source_lines:
connecting_shapes = dict(connection['connecting_shapes'])
connecting_shapes['source_shape_geometry'] = line
if target_check:
connecting_shapes['source_anchor_node'] = line.node_start
connecting_shapes['target_anchor_node'] = line.node_start
connecting_shapes['target_shape_geometry'] = line
# Replace the original dict with updated connecting shapes
connection['connecting_shapes'] = connecting_shapes
# Make a new kwarg without class_name
kwarg_dict = dict(connection)
del kwarg_dict['class_']
# Restore the connection using the class
project.restore_connection(class_, **kwarg_dict)
else:
# Make a new kwarg without class_name
kwarg_dict = dict(connection)
del kwarg_dict['class_']
# Restore the connection using the class
project.restore_connection(class_, **kwarg_dict)
project.write_log(
"The connections of the floors for Redis NLPO are removed and recreated, please check your connections "
"in the model.")
[docs]def _viia_reconnect_floor_connecting_shapes(project: ViiaProject, connections: List[Dict]):
"""
This function reconnects all the connecting shapes of a Floor object in the project. Function should be
operated before creating model in DIANA.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- connections (list of dictionaries): A list of the dictionaries used to recreate the connections.
Output:
- No output. Shapes will be connected in the ViiaProject.
"""
# Gather all the shapes in a list
shape_list = list()
# Create all the interfaces with the information
for connection in connections:
connecting_shapes = connection['connecting_shapes']
# Get the source connecting shapes
shape_list.append(connecting_shapes['source_connecting_shape'])
# Also get other shapes that contain the same shape geometry
shape_list.extend(connecting_shapes['target_shape_geometry'].get_shapes())
# Get the target connecting shapes if exist
try:
shape_list.append(connecting_shapes['target_connecting_shape'])
shape_list.extend(connecting_shapes['target_shape_geometry'].get_shapes())
except KeyError:
pass
if isinstance(connecting_shapes['source_connecting_shape'], Floor):
shape_list.extend(connecting_shapes['source_connecting_shape'].get_connecting_shapes())
# Remove the duplicated shapes
shape_list = list(set([shape.name for shape in shape_list]))
# Get the unique shapes
shape_list = [project.viia_get(name=name) for name in shape_list]
# Reconnect all the relevant shapes
project.viia_connect_all_shapes(shape_list)
### ===================================================================================================================
### 5. Collect node information from DIANA model
### ===================================================================================================================
[docs]def viia_node_data_diana(project: ViiaProject, view_nodes: List[Union[Node, List[float]]]) -> List[Path]:
"""
This function creates pdf documents containing the DIANA node/element and connection data at the location of nodes
specified by the user.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- view_nodes (list of node objects or node coordinates): A list that can contain either objects of the class
Node or a sublist containing 3 floats representing the node coordinates in [m] e.g. [1.20, 5.00, 3.50]. For
each node a pdf document is created.
Output:
- A folder called "Node Data" is created in the working folder which contains the pdfs (each pdf corresponding
to each node), which contains the node/element data and connection data.
- Returns list of all generated pdf-files.
"""
# Create the folder to store the model_summary
fem_create_folder(ViiaSettings.DEFAULT_NODE_DATA_FOLDER, ref_folder=project.workfolder_location)
time_reference = datetime.now().strftime('%Y%m%d%H%M%S')
folder = f'{time_reference}-v{str(project.version).zfill(3)}'
fem_create_folder(folder, ref_folder=project.workfolder_location / ViiaSettings.DEFAULT_NODE_DATA_FOLDER)
report_location = project.workfolder_location / ViiaSettings.DEFAULT_NODE_DATA_FOLDER / folder
project.set_standard_units()
# Loop through the list of requested nodes
pdf_files = []
for fem_node in view_nodes:
# Path of the document
if isinstance(fem_node, Node):
node_name = \
f"{fem_node.name} [{fem_node.coordinates[0]},{fem_node.coordinates[1]},{fem_node.coordinates[2]}]"
elif isinstance(fem_node, list) and len(fem_node) == 3 and all(isinstance(n, (float, int)) for n in fem_node):
node_name = f"[{fem_node[0]},{fem_node[1]},{fem_node[2]}]"
else:
raise TypeError(
f"ERROR: The node for which a pdf document should be generated must be a Node instance or a list of 3 "
f"floats representing coordinates. Provided was {fem_node}.")
image_path = report_location / f'{node_name}.png'
pdf_path = report_location / f'{node_name}.pdf'
# Connection data
if isinstance(fem_node, Node):
connection_data = get_connection_data(project=project, node=fem_node)
else:
# Attempt to find a node by coordinates
node_obj = project.find_node(point=fem_node)
if node_obj is not None:
connection_data = get_connection_data(project=project, node=node_obj)
else:
# No node found at the coordinates
connection_data = get_connection_data_diana(project=project, node=fem_node)
# Node data
node_data = get_node_data_diana(project=project, node=fem_node, image_path=image_path)
# Create the pdf
pdf_files.append(create_node_data_pdf(
project=project, image_path=image_path, node_data=node_data, connection_data=connection_data,
node_name=node_name, pdf_path=pdf_path))
# Delete the image and return the pdf
if image_path.exists():
image_path.unlink()
# Return all generated pdf-files as path in list
return pdf_files
def viia_shape_data_diana(project: ViiaProject, view_shapes: List[Union[Shapes, str]] = None) -> List[Path]:
"""
This function creates pdf documents containing the DIANA shape data of the shapes specified by the user.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- view_shapes (list of obj or str): A list of shape objects or shape names. For each shape a pdf document is
created. If None all shapes will be used. Default is None.
Output:
- A folder called "Mesh Check" is created in the working folder which contains the pdfs (each pdf corresponding
to each shape), which contains the shape data.
- Returns list of all generated pdf-files.
"""
# Create the folder to store the shape data
fem_create_folder(ViiaSettings.DEFAULT_SHAPE_DATA_FOLDER, ref_folder=project.workfolder_location)
time_reference = datetime.now().strftime('%Y%m%d%H%M%S')
folder = f'{time_reference}-v{str(project.version).zfill(3)}'
fem_create_folder(folder, ref_folder=project.workfolder_location / ViiaSettings.DEFAULT_SHAPE_DATA_FOLDER)
report_location = project.workfolder_location / 'Mesh Check' / folder
# Loop through the list of requested nodes
pdf_files = []
if not view_shapes:
view_shapes = project.collections.shapes
for shape in view_shapes:
# Path of the document
if isinstance(shape, Shapes):
shape_name = f"{shape.name}"
elif isinstance(shape, str):
shape_name = shape
else:
raise TypeError(
f"ERROR: The shape for which a pdf document should be generated must be an instance of the Shapes class"
f" or a list of string representing the name of the shape. Provided was {shape}")
shape_name_path = viia_to_filename(shape_name)
image_path = report_location / f'{shape_name_path}.png'
pdf_path = report_location / f'{shape_name_path}.pdf'
# Connection data
connection_data = get_connection_data_shape(project=project, shape=shape_name)
# Node data
node_data = get_shape_node_data_diana(project=project, shape=shape_name, image_path=image_path)
# Create the pdf
pdf_files.append(create_shape_data_pdf(
project=project, image_path=image_path, node_data=node_data, connection_data=connection_data,
shape_name=shape_name, pdf_path=pdf_path))
# Delete the image and return the pdf
if image_path.exists():
image_path.unlink()
# Return all generated pdf-files as path in list
return pdf_files
### ===================================================================================================================
### 6. End of script
### ===================================================================================================================