Blender V5.0
versioning_common.cc File Reference
#include <cstring>
#include "DNA_node_types.h"
#include "DNA_screen_types.h"
#include "DNA_sequence_types.h"
#include "BLI_listbase.h"
#include "BLI_map.hh"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "BLI_string_utf8.h"
#include "BKE_animsys.h"
#include "BKE_grease_pencil_legacy_convert.hh"
#include "BKE_idprop.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_override.hh"
#include "BKE_library.hh"
#include "BKE_main.hh"
#include "BKE_main_namemap.hh"
#include "BKE_mesh_legacy_convert.hh"
#include "BKE_node.hh"
#include "BKE_node_legacy_types.hh"
#include "BKE_node_runtime.hh"
#include "BKE_node_tree_update.hh"
#include "BKE_report.hh"
#include "BKE_screen.hh"
#include "ANIM_versioning.hh"
#include "NOD_socket.hh"
#include "BLT_translation.hh"
#include "SEQ_sequencer.hh"
#include "MEM_guardedalloc.h"
#include "BLO_readfile.hh"
#include "readfile.hh"
#include "versioning_common.hh"

Go to the source code of this file.

Macros

#define DNA_DEPRECATED_ALLOW

Functions

short do_versions_new_to_old_idcode_get (const short id_code_new)
ARegiondo_versions_add_region_if_not_found (ListBase *regionbase, int region_type, const char *, int link_after_region_type)
ARegiondo_versions_ensure_region (ListBase *regionbase, int region_type, const char *, int link_after_region_type)
IDdo_versions_rename_id (Main *bmain, const short id_type, const char *name_src, const char *name_dst)
static void change_node_socket_name (ListBase *sockets, const char *old_name, const char *new_name)
bool version_node_socket_is_used (bNodeSocket *sock)
void version_node_socket_id_delim (bNodeSocket *socket)
void version_node_socket_name (bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
void version_node_input_socket_name (bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
void version_node_output_socket_name (bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
StringRef legacy_socket_idname_to_socket_type (StringRef idname)
bNodeversion_node_add_empty (bNodeTree &ntree, const char *idname)
void version_node_remove (bNodeTree &ntree, bNode &node)
bNodeSocketversion_node_add_socket (bNodeTree &ntree, bNode &node, const eNodeSocketInOut in_out, const char *idname, const char *identifier)
bNodeLinkversion_node_add_link (bNodeTree &ntree, bNode &node_a, bNodeSocket &socket_a, bNode &node_b, bNodeSocket &socket_b)
bNodeSocketversion_node_add_socket_if_not_exist (bNodeTree *ntree, bNode *node, int in_out, int type, int subtype, const char *identifier, const char *name)
void version_node_tree_clear_interface (bNodeTree &ntree)
void version_node_id (bNodeTree *ntree, const int node_type, const char *new_name)
void version_node_socket_index_animdata (Main *bmain, const int node_tree_type, const int node_type, const int socket_index_orig, const int socket_index_offset, const int total_number_of_sockets)
void version_socket_update_is_used (bNodeTree *ntree)
ARegiondo_versions_add_region (int regiontype, const char *)
void node_tree_relink_with_socket_id_map (bNodeTree &ntree, bNode &old_node, bNode &new_node, const Map< std::string, std::string > &map)
static blender::Vector< bNodeLink * > find_connected_links (bNodeTree *ntree, bNodeSocket *in_socket)
void add_realize_instances_before_socket (bNodeTree *ntree, bNode *node, bNodeSocket *geometry_socket)
floatversion_cycles_node_socket_float_value (bNodeSocket *socket)
floatversion_cycles_node_socket_rgba_value (bNodeSocket *socket)
floatversion_cycles_node_socket_vector_value (bNodeSocket *socket)
IDPropertyversion_cycles_properties_from_ID (ID *id)
IDPropertyversion_cycles_properties_from_view_layer (ViewLayer *view_layer)
IDPropertyversion_cycles_properties_from_render_layer (SceneRenderLayer *render_layer)
float version_cycles_property_float (IDProperty *idprop, const char *name, float default_value)
int version_cycles_property_int (IDProperty *idprop, const char *name, int default_value)
void version_cycles_property_int_set (IDProperty *idprop, const char *name, int value)
bool version_cycles_property_boolean (IDProperty *idprop, const char *name, bool default_value)
void version_cycles_property_boolean_set (IDProperty *idprop, const char *name, bool value)
IDPropertyversion_cycles_visibility_properties_from_ID (ID *id)
void version_update_node_input (bNodeTree *ntree, FunctionRef< bool(bNode *)> check_node, const char *socket_identifier, FunctionRef< void(bNode *, bNodeSocket *)> update_input, FunctionRef< void(bNode *, bNodeSocket *, bNode *, bNodeSocket *)> update_input_link)
bNodeversion_eevee_output_node_get (bNodeTree *ntree, int16_t node_type)
bool all_scenes_use (Main *bmain, const blender::Span< const char * > engines)
bNodeTreeversion_get_scene_compositor_node_tree (Main *bmain, Scene *scene)
static bool blendfile_or_libraries_versions_atleast (Main *bmain, const short versionfile, const short subversionfile)
void do_versions_after_setup (Main *new_bmain, BlendfileLinkAppendContext *lapp_context, BlendFileReadReport *reports)

Macro Definition Documentation

◆ DNA_DEPRECATED_ALLOW

#define DNA_DEPRECATED_ALLOW

Definition at line 9 of file versioning_common.cc.

Function Documentation

◆ add_realize_instances_before_socket()

◆ all_scenes_use()

bool all_scenes_use ( Main * bmain,
const blender::Span< const char * > engines )

◆ blendfile_or_libraries_versions_atleast()

bool blendfile_or_libraries_versions_atleast ( Main * bmain,
const short versionfile,
const short subversionfile )
static

◆ change_node_socket_name()

void change_node_socket_name ( ListBase * sockets,
const char * old_name,
const char * new_name )
static

◆ do_versions_add_region()

ARegion * do_versions_add_region ( int regiontype,
const char * name )

◆ do_versions_add_region_if_not_found()

ARegion * do_versions_add_region_if_not_found ( ListBase * regionbase,
int region_type,
const char * allocname,
int link_after_region_type )

Check if a region of type region_type exists in regionbase. Otherwise add it after the first region of type link_after_region_type.

Returns
null if a region of the given type already existed, otherwise the newly added region.

Definition at line 67 of file versioning_common.cc.

References BKE_area_region_new(), BLI_insertlinkafter(), LISTBASE_FOREACH, and ARegion::regiontype.

Referenced by add_image_editor_asset_shelf(), blo_do_versions_290(), blo_do_versions_300(), blo_do_versions_400(), blo_do_versions_500(), and version_ensure_missing_regions().

◆ do_versions_after_setup()

◆ do_versions_ensure_region()

ARegion * do_versions_ensure_region ( ListBase * regionbase,
int region_type,
const char * allocname,
int link_after_region_type )

Check if a region of type region_type exists in regionbase. Otherwise add it after the first region of type link_after_region_type.

Returns
either a new, or already existing region.

Definition at line 88 of file versioning_common.cc.

References BKE_area_region_new(), BLI_insertlinkafter(), LISTBASE_FOREACH, and ARegion::regiontype.

Referenced by version_ensure_missing_regions().

◆ do_versions_new_to_old_idcode_get()

short do_versions_new_to_old_idcode_get ( short id_code_new)

Mapping from new ID types to old converted ID types.

This is used by linking code, when a directly linked data comes from a library where it exists as an older, different type of ID.

Since the current blend-file will convert that older ID type to the new one as part of its versioning process, when saved, it will store a reference to that linked ID using the new ID type, which will not be found on next blend-file opening/reloading when searching for that ID in the library blend-file.

Returns
The old, deprecated ID type code if any matches the given id_code_new one, otherwise ID_LINK_PLACEHOLDER.

Definition at line 56 of file versioning_common.cc.

References ID_GD_LEGACY, ID_GP, and ID_LINK_PLACEHOLDER.

Referenced by find_bhead_from_idname().

◆ do_versions_rename_id()

ID * do_versions_rename_id ( Main * bmain,
short id_type,
const char * name_src,
const char * name_dst )

Rename if the ID doesn't exist.

Returns
the ID (if found).

Definition at line 109 of file versioning_common.cc.

References BKE_libblock_rename(), ID_IS_LINKED, LISTBASE_FOREACH, STREQ, and which_libbase().

Referenced by blo_do_versions_300(), BLO_update_defaults_startup_blend(), and do_versions_after_linking_280().

◆ find_connected_links()

◆ legacy_socket_idname_to_socket_type()

StringRef legacy_socket_idname_to_socket_type ( blender::StringRef idname)

Find the base socket name for an idname that may include a subtype.

Definition at line 209 of file versioning_common.cc.

Referenced by legacy_socket_move_to_interface(), and versioning_fix_socket_subtype_idnames().

◆ node_tree_relink_with_socket_id_map()

◆ version_cycles_node_socket_float_value()

◆ version_cycles_node_socket_rgba_value()

◆ version_cycles_node_socket_vector_value()

◆ version_cycles_properties_from_ID()

◆ version_cycles_properties_from_render_layer()

IDProperty * version_cycles_properties_from_render_layer ( SceneRenderLayer * render_layer)

Definition at line 520 of file versioning_common.cc.

References IDP_GetPropertyTypeFromGroup(), and IDP_GROUP.

Referenced by blo_do_versions_290().

◆ version_cycles_properties_from_view_layer()

IDProperty * version_cycles_properties_from_view_layer ( ViewLayer * view_layer)

◆ version_cycles_property_boolean()

bool version_cycles_property_boolean ( IDProperty * idprop,
const char * name,
bool default_value )

◆ version_cycles_property_boolean_set()

void version_cycles_property_boolean_set ( IDProperty * idprop,
const char * name,
bool value )

Definition at line 553 of file versioning_common.cc.

References name, and version_cycles_property_int_set().

Referenced by blo_do_versions_290(), and blo_do_versions_440().

◆ version_cycles_property_float()

float version_cycles_property_float ( IDProperty * idprop,
const char * name,
float default_value )

◆ version_cycles_property_int()

◆ version_cycles_property_int_set()

void version_cycles_property_int_set ( IDProperty * idprop,
const char * name,
int value )

◆ version_cycles_visibility_properties_from_ID()

IDProperty * version_cycles_visibility_properties_from_ID ( ID * id)

◆ version_eevee_output_node_get()

◆ version_get_scene_compositor_node_tree()

bNodeTree * version_get_scene_compositor_node_tree ( Main * bmain,
Scene * scene )

◆ version_node_add_empty()

bNode & version_node_add_empty ( bNodeTree & ntree,
const char * idname )

Adds a new node for versioning purposes. This is intended to be used to create raw DNA that might have been read from a file. The created node does not have storage or sockets. Both have to be added manually afterwards.

This may seem redundant because the set of sockets is already part of the node declaration. However, the declaration should not be used here, because it changes over time. The versioning code generally expects to get the sockets that the node had at the time of writing the versioning code. Changing the declaration later can break the versioning code in ways that are hard to detect.

When adding new nodes in versioning code that replace or belong to existing nodes, they should be positioned so that it overlaps the existing node with just a slight offset. This is better than putting them next to each other they way one would do it manually, because it messes up more complex node trees significantly. In simple tests, putting the nodes next to each other looks better, but in actual user-files it looks way worse and makes it less obvious what was changed by versioning code.

Definition at line 237 of file versioning_common.cc.

References BKE_ntree_update_tag_node_new(), BLI_addtail(), bNode::color, DATA_, bNode::flag, blender::bke::bNodeType::height, bNode::height, bNode::idname, MEM_callocN(), bNode::name, NODE_INIT, NODE_OPTIONS, NODE_SELECT, blender::bke::node_type_find(), blender::bke::node_unique_id(), blender::bke::node_unique_name(), bNodeTree::nodes, bNode::runtime, STRNCPY(), blender::bke::bNodeType::type_legacy, bNode::type_legacy, blender::bke::bNodeType::ui_name, blender::bke::bNodeType::width, and bNode::width.

Referenced by clamp_subdivision_node_level_input(), do_version_bokeh_blur_pixel_size(), do_version_map_value_node(), do_version_material_remove_use_nodes(), do_version_node_curve_to_mesh_scale_input(), do_version_texture_gradient_clamp(), do_version_world_remove_use_nodes(), hide_simulation_node_skip_socket_value(), remove_triangulate_node_min_size_input(), version_geometry_nodes_extrude_smooth_propagation(), and version_geometry_nodes_primitive_uv_maps().

◆ version_node_add_link()

bNodeLink & version_node_add_link ( bNodeTree & ntree,
bNode & node_a,
bNodeSocket & socket_a,
bNode & node_b,
bNodeSocket & socket_b )

◆ version_node_add_socket()

bNodeSocket & version_node_add_socket ( bNodeTree & ntree,
bNode & node,
const eNodeSocketInOut in_out,
const char * idname,
const char * identifier )

Definition at line 270 of file versioning_common.cc.

References BKE_ntree_update_tag_socket_new(), BLI_addtail(), bNodeSocket::default_value, bNodeSocket::identifier, bNodeSocket::idname, bNodeSocket::in_out, bNode::inputs, bNodeSocket::limit, MEM_callocN(), bNodeSocket::name, node_socket_init_default_value_data(), blender::bke::node_socket_type_find(), bNode::outputs, bNodeSocket::runtime, SOCK_IN, STRNCPY_UTF8, blender::bke::bNodeSocketType::subtype, blender::bke::bNodeSocketType::type, and bNodeSocket::type.

Referenced by clamp_subdivision_node_level_input(), do_version_blur_menus_to_inputs(), do_version_bokeh_blur_pixel_size(), do_version_box_mask_menus_to_inputs(), do_version_channel_matte_menus_to_inputs(), do_version_color_balance_menus_to_inputs(), do_version_color_spill_menus_to_inputs(), do_version_convert_alpha_menus_to_inputs(), do_version_corner_pin_menus_to_inputs(), do_version_denoise_menus_to_inputs(), do_version_dilate_menus_to_inputs(), do_version_displace_menus_to_inputs(), do_version_distance_matte_menus_to_inputs(), do_version_distribute_points_in_volume_options_to_inputs(), do_version_double_edge_mask_options_to_inputs(), do_version_ellipse_mask_menus_to_inputs(), do_version_fill_curve_options_to_inputs(), do_version_fillet_curve_options_to_inputs(), do_version_filter_menus_to_inputs(), do_version_glare_menus_to_inputs(), do_version_keying_menus_to_inputs(), do_version_kuwahara_menus_to_inputs(), do_version_lens_distortion_menus_to_inputs(), do_version_levels_menus_to_inputs(), do_version_map_uv_menus_to_inputs(), do_version_map_value_node(), do_version_mask_menus_to_inputs(), do_version_match_string_options_to_inputs(), do_version_material_remove_use_nodes(), do_version_merge_by_distance_options_to_inputs(), do_version_mesh_to_volume_options_to_inputs(), do_version_movie_distortion_menus_to_inputs(), do_version_points_to_volume_options_to_inputs(), do_version_raycast_options_to_inputs(), do_version_remove_attribute_options_to_inputs(), do_version_resample_curve_options_to_inputs(), do_version_rotate_menus_to_inputs(), do_version_sample_grid_options_to_inputs(), do_version_scale_elements_options_to_inputs(), do_version_scale_menus_to_inputs(), do_version_set_alpha_menus_to_inputs(), do_version_set_curve_normal_options_to_inputs(), do_version_stabilize_2d_menus_to_inputs(), do_version_subdivision_surface_options_to_inputs(), do_version_texture_gradient_clamp(), do_version_tone_map_menus_to_inputs(), do_version_track_position_menus_to_inputs(), do_version_transform_geometry_options_to_inputs(), do_version_transform_menus_to_inputs(), do_version_translate_menus_to_inputs(), do_version_triangulate_options_to_inputs(), do_version_uv_pack_islands_options_to_inputs(), do_version_uv_unwrap_options_to_inputs(), do_version_volume_to_mesh_options_to_inputs(), do_version_world_remove_use_nodes(), hide_simulation_node_skip_socket_value(), version_geometry_nodes_extrude_smooth_propagation(), and version_geometry_nodes_primitive_uv_maps().

◆ version_node_add_socket_if_not_exist()

◆ version_node_id()

void version_node_id ( bNodeTree * ntree,
int node_type,
const char * new_name )

Replace the ID name of all nodes in the tree with the given type with the new name.

Definition at line 346 of file versioning_common.cc.

References STREQ, and STRNCPY().

Referenced by blo_do_versions_300().

◆ version_node_input_socket_name()

◆ version_node_output_socket_name()

void version_node_output_socket_name ( bNodeTree * ntree,
const int node_type,
const char * old_name,
const char * new_name )

◆ version_node_remove()

void version_node_remove ( bNodeTree & ntree,
bNode & node )

Removes a node for versioning purposes:

  • Animation data (AnimData) are not removed, because they might be using bAction.id which is not be available before linking.
  • User count is not updated. This is ensured after blend file reading is done.

Definition at line 261 of file versioning_common.cc.

References blender::bke::node_free_node(), blender::bke::node_rebuild_id_vector(), blender::bke::node_unlink_attached(), and blender::bke::node_unlink_node().

Referenced by do_version_composite_node_in_scene_tree(), do_version_map_value_node(), do_version_normal_node_dot_product(), do_version_sun_beams(), do_version_texture_gradient_clamp(), and do_versions_after_linking_500().

◆ version_node_socket_id_delim()

void version_node_socket_id_delim ( bNodeSocket * socket)

Convert SocketName.001 unique name format to SocketName_001. Previously both were used.

Definition at line 151 of file versioning_common.cc.

References blender::StringRef::drop_known_prefix(), bNodeSocket::identifier, blender::StringRefBase::is_empty(), bNodeSocket::name, name, and blender::StringRefBase::startswith().

Referenced by version_node_tree_socket_id_delim().

◆ version_node_socket_index_animdata()

void version_node_socket_index_animdata ( Main * bmain,
int node_tree_type,
int node_type,
int socket_index_orig,
int socket_index_offset,
int total_number_of_sockets )

Adjust animation data for newly added node sockets.

Node sockets are addressed by their index (in their RNA path, and thus FCurves/drivers), and thus when a new node is added in the middle of the list, existing animation data needs to be adjusted.

Since this is about animation data, it only concerns input sockets.

Parameters
node_tree_typeNode tree type that has these nodes, for example NTREE_SHADER.
node_typeNode type to adjust, for example SH_NODE_BSDF_PRINCIPLED.
socket_index_origThe original index of the moved socket; when socket 4 moved to 6, pass 4 here.
socket_index_offsetThe offset of the nodes, so when socket 4 moved to 6, pass 2 here.
total_number_of_socketsThe total number of sockets in the node.

Definition at line 357 of file versioning_common.cc.

References BKE_animdata_fix_paths_rename_all_ex(), BLI_sprintfN(), BLI_str_escape(), FOREACH_NODETREE_BEGIN, FOREACH_NODETREE_END, and MEM_freeN().

Referenced by do_versions_after_linking_290(), do_versions_after_linking_300(), do_versions_after_linking_420(), do_versions_after_linking_430(), do_versions_after_linking_440(), and do_versions_after_linking_450().

◆ version_node_socket_is_used()

◆ version_node_socket_name()

void version_node_socket_name ( bNodeTree * ntree,
const int node_type,
const char * old_name,
const char * new_name )

◆ version_node_tree_clear_interface()

void version_node_tree_clear_interface ( bNodeTree & ntree)

Definition at line 341 of file versioning_common.cc.

References bNodeTree::tree_interface.

◆ version_socket_update_is_used()

◆ version_update_node_input()

void version_update_node_input ( bNodeTree * ntree,
FunctionRef< bool(bNode *)> check_node,
const char * socket_identifier,
FunctionRef< void(bNode *, bNodeSocket *)> update_input,
FunctionRef< void(bNode *, bNodeSocket *, bNode *, bNodeSocket *)> update_input_link )