Cleanup: Nodes: deduplicate logic to get zone for node
Since nodes are not uniquely assigned to zones (some nodes are in two zones at the same time), it's better not to expose this detail in multiple APIs. This avoids having to explain the behavior multiple times. Now one just has to use `get_zone_by_node/socket` and can then use a seperate method to get the zone stack for that zone like before.
This commit is contained in:
@@ -74,12 +74,6 @@ class bNodeTreeZones {
|
||||
*/
|
||||
const bNodeTreeZone *get_zone_by_node(const int32_t node_id) const;
|
||||
|
||||
/**
|
||||
* Get a sorted list of zones that the node is in. First comes the root zone and last the most
|
||||
* nested zone. For nodes that are at the root level, the returned list is empty.
|
||||
*/
|
||||
Vector<const bNodeTreeZone *> get_zone_stack_for_node(const int32_t node_id) const;
|
||||
|
||||
/**
|
||||
* Check if a link from the first zone to a socket in the second zone is allowed. Either zone
|
||||
* input may also be null which represents the root tree outside of any zone. Generally, a link
|
||||
@@ -94,6 +88,11 @@ class bNodeTreeZones {
|
||||
Vector<const bNodeTreeZone *> get_zones_to_enter(const bNodeTreeZone *outer_zone,
|
||||
const bNodeTreeZone *inner_zone) const;
|
||||
|
||||
/**
|
||||
* Same as #get_zones_to_enter but starts at the top level of the node tree.
|
||||
*/
|
||||
Vector<const bNodeTreeZone *> get_zones_to_enter_from_root(const bNodeTreeZone *zone) const;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const bNodeTreeZones &zones);
|
||||
};
|
||||
|
||||
|
||||
@@ -420,20 +420,6 @@ const bNodeTreeZone *bNodeTreeZones::get_zone_by_node(const int32_t node_id) con
|
||||
return this->zones[zone_i];
|
||||
}
|
||||
|
||||
Vector<const bNodeTreeZone *> bNodeTreeZones::get_zone_stack_for_node(const int node_id) const
|
||||
{
|
||||
const bNodeTreeZone *zone = this->get_zone_by_node(node_id);
|
||||
if (zone == nullptr) {
|
||||
return {};
|
||||
}
|
||||
Vector<const bNodeTreeZone *> zone_stack;
|
||||
for (; zone; zone = zone->parent_zone) {
|
||||
zone_stack.append(zone);
|
||||
}
|
||||
std::reverse(zone_stack.begin(), zone_stack.end());
|
||||
return zone_stack;
|
||||
}
|
||||
|
||||
bool bNodeTreeZones::link_between_zones_is_allowed(const bNodeTreeZone *from_zone,
|
||||
const bNodeTreeZone *to_zone) const
|
||||
{
|
||||
@@ -460,6 +446,12 @@ Vector<const bNodeTreeZone *> bNodeTreeZones::get_zones_to_enter(
|
||||
return zones_to_enter;
|
||||
}
|
||||
|
||||
Vector<const bNodeTreeZone *> bNodeTreeZones::get_zones_to_enter_from_root(
|
||||
const bNodeTreeZone *zone) const
|
||||
{
|
||||
return this->get_zones_to_enter(nullptr, zone);
|
||||
}
|
||||
|
||||
const bNode *bNodeZoneType::get_corresponding_input(const bNodeTree &tree,
|
||||
const bNode &output_bnode) const
|
||||
{
|
||||
|
||||
@@ -444,7 +444,8 @@ static std::optional<const ComputeContext *> compute_context_for_tree_path(
|
||||
return std::nullopt;
|
||||
}
|
||||
const Vector<const blender::bke::bNodeTreeZone *> zone_stack =
|
||||
tree_zones->get_zone_stack_for_node(group_node->identifier);
|
||||
tree_zones->get_zones_to_enter_from_root(
|
||||
tree_zones->get_zone_by_node(group_node->identifier));
|
||||
current = compute_context_for_zones(zone_stack, compute_context_cache, current);
|
||||
if (!current) {
|
||||
return std::nullopt;
|
||||
|
||||
@@ -126,8 +126,8 @@ static void viewer_path_for_geometry_node(const SpaceNode &snode,
|
||||
if (!tree_zones) {
|
||||
return;
|
||||
}
|
||||
const Vector<const bNodeTreeZone *> zone_stack = tree_zones->get_zone_stack_for_node(
|
||||
node->identifier);
|
||||
const Vector<const bNodeTreeZone *> zone_stack = tree_zones->get_zones_to_enter_from_root(
|
||||
tree_zones->get_zone_by_node(node->identifier));
|
||||
for (const bNodeTreeZone *zone : zone_stack) {
|
||||
ViewerPathElem *zone_elem = viewer_path_elem_for_zone(*zone);
|
||||
if (!zone_elem) {
|
||||
@@ -147,8 +147,8 @@ static void viewer_path_for_geometry_node(const SpaceNode &snode,
|
||||
if (!tree_zones) {
|
||||
return;
|
||||
}
|
||||
const Vector<const bNodeTreeZone *> zone_stack = tree_zones->get_zone_stack_for_node(
|
||||
node.identifier);
|
||||
const Vector<const bNodeTreeZone *> zone_stack = tree_zones->get_zones_to_enter_from_root(
|
||||
tree_zones->get_zone_by_node(node.identifier));
|
||||
for (const bNodeTreeZone *zone : zone_stack) {
|
||||
ViewerPathElem *zone_elem = viewer_path_elem_for_zone(*zone);
|
||||
if (!zone_elem) {
|
||||
|
||||
Reference in New Issue
Block a user