Node Wrangler: Improved accuracy on Align Nodes operator #104551
@ -2375,6 +2375,10 @@ class NWAlignNodes(Operator, NWBase):
|
|||||||
# Somehow hidden nodes would come out 10 units higher that non-hidden nodes when aligned, so this offset has to exist
|
# Somehow hidden nodes would come out 10 units higher that non-hidden nodes when aligned, so this offset has to exist
|
||||||
weird_offset = 10
|
weird_offset = 10
|
||||||
|
|
||||||
|
# node.dimensions for reroutes indicate (16.0, 16.0) but using that in calculations puts reroutes off-center
|
||||||
|
# At least on a purely visual basis, the dimensions of a reroute node seem to be closer to 10 units. (At least for 1.0 unit scale)
|
||||||
|
reroute_width = 10
|
||||||
|
|
||||||
with temporary_unframe(nodes=selection):
|
with temporary_unframe(nodes=selection):
|
||||||
active_loc = None
|
active_loc = None
|
||||||
if active_node in selection:
|
if active_node in selection:
|
||||||
@ -2390,10 +2394,6 @@ class NWAlignNodes(Operator, NWBase):
|
|||||||
y_range = max(y_locs) - min(y_locs)
|
y_range = max(y_locs) - min(y_locs)
|
||||||
horizontal = x_range > y_range
|
horizontal = x_range > y_range
|
||||||
|
|
||||||
# Undo corrective offsets for hidden nodes if alignment is horizontal
|
|
||||||
if not horizontal:
|
|
||||||
y_locs = [n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
|
||||||
|
|
||||||
mid_x = 0.5 * (max(x_locs) + min(x_locs))
|
mid_x = 0.5 * (max(x_locs) + min(x_locs))
|
||||||
mid_y = 0.5 * (max(y_locs) + min(y_locs))
|
mid_y = 0.5 * (max(y_locs) + min(y_locs))
|
||||||
|
|
||||||
@ -2411,36 +2411,49 @@ class NWAlignNodes(Operator, NWBase):
|
|||||||
|
|
||||||
if horizontal:
|
if horizontal:
|
||||||
for node in selection:
|
for node in selection:
|
||||||
|
if node.type != 'REROUTE':
|
||||||
node.location.x = current_pos
|
node.location.x = current_pos
|
||||||
node.location.y = (mid_y + weird_offset) if node.hide else mid_y + (0.5 * node.dimensions.y)
|
node.location.y = (mid_y + weird_offset) if node.hide else mid_y + (0.5 * node.dimensions.y)
|
||||||
|
|
||||||
current_pos += margin_x + node.dimensions.x
|
current_pos += margin_x + node.dimensions.x
|
||||||
|
else:
|
||||||
|
node.location.x = current_pos + (0.5 * reroute_width)
|
||||||
|
node.location.y = mid_y
|
||||||
|
|
||||||
|
current_pos += margin_x + reroute_width
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for node in selection:
|
for node in selection:
|
||||||
|
if node.type != 'REROUTE':
|
||||||
node.location.x = mid_x - (0.5 * node.dimensions.x)
|
node.location.x = mid_x - (0.5 * node.dimensions.x)
|
||||||
node.location.y = (current_pos - (0.5 * node.dimensions.y) + weird_offset) if node.hide else current_pos
|
node.location.y = (current_pos - (0.5 * node.dimensions.y) + weird_offset) if node.hide else current_pos
|
||||||
|
|
||||||
current_pos -= margin_y + node.dimensions.y
|
current_pos -= margin_y + node.dimensions.y
|
||||||
|
else:
|
||||||
|
node.location.x = mid_x
|
||||||
|
node.location.y = current_pos - (0.5 * reroute_width)
|
||||||
|
|
||||||
|
current_pos -= margin_y + reroute_width
|
||||||
|
|
||||||
|
|
||||||
# If active node is selected, center nodes around it
|
# If active node is selected, center nodes around it
|
||||||
if active_loc is not None:
|
if active_loc is not None:
|
||||||
active_loc_diff = active_loc - active_node.location
|
active_loc_diff = active_loc - active_node.location
|
||||||
for node in selection:
|
for node in selection:
|
||||||
node.location += active_loc_diff
|
node.location += active_loc_diff
|
||||||
|
else:
|
||||||
|
new_x_locs = [n.location.x + (0.5 * n.dimensions.x) for n in selection]
|
||||||
|
new_y_locs = [n.location.y - weird_offset if n.hide
|
||||||
|
else n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
||||||
|
|
||||||
elif horizontal: # Position nodes centered around where they used to be
|
new_x_mid = 0.5 * (max(new_x_locs) + min(new_x_locs))
|
||||||
new_locs = [n.location.x + (0.5 * n.dimensions.x) for n in selection]
|
new_y_mid = 0.5 * (max(new_y_locs) + min(new_y_locs))
|
||||||
new_mid = 0.5 * (max(new_locs) + min(new_locs))
|
|
||||||
x_diff = mid_x - new_mid
|
x_diff = mid_x - new_x_mid
|
||||||
|
y_diff = mid_y - new_y_mid
|
||||||
|
|
||||||
for node in selection:
|
for node in selection:
|
||||||
node.location.x += x_diff
|
node.location.x += x_diff
|
||||||
else:
|
|
||||||
new_locs = [n.location.y - (0.5 * n.dimensions.y) for n in selection]
|
|
||||||
new_mid = 0.5 * (max(new_locs) + min(new_locs))
|
|
||||||
y_diff = mid_y - new_mid
|
|
||||||
|
|
||||||
for node in selection:
|
|
||||||
node.location.y += y_diff
|
node.location.y += y_diff
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
Loading…
Reference in New Issue
Block a user