OMC::Node_Coordinates Class Reference

Detailed Description

Represents and provides the methods for the coordinates of a node in the node view.

The node coordinates refer to the placement of the node within the node view. Each group in the node view contains its own node-graph, and the position of these nodes are dictated by the position of the node (OMC::Node::position).
Aligning Nodes

import random
from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
proj = sess.project #Get the active session's currently loaded project.
scene = proj.scene #Get the top scene in the project.
proj.history.begin( "Ordering Nodes" )
horizontal_separation = 225
vertical_separation = 125
generator_types = [ "READ", "COLOURCARD", "GROUP", "GRADIENT"]
#A recursive method used to identify all generator type-nodes. We'll only keep the topmost generator found in any path.
def recursive_collector( node, previous_collector, collector, depth ):
if node.type.upper() in generator_types: #Is the node a 'generator' type? We will organize around these node types.
if previous_collector:
collector["generators"].remove( previous_collector )
if not node in collector["generators"]:
collector["generators"].append( node )
previous_collector = node
srcnodes = 0
for port in node.ports_in:
srcnode = port.source_node
if srcnode:
collector = recursive_collector( srcnode, previous_collector, collector, depth+1 )
srcnodes = srcnodes + 1
if previous_collector:
try:
collector["controller_count"][ previous_collector.path ] = max( srcnodes, collector["controller_count"][ previous_collector.path ] )
except:
collector["controller_count"][ previous_collector.path ] = srcnodes
#Gather some information on these nodes.
collector["x"] = collector["x"]+node.position.x
collector["y"] = collector["y"]+node.position.y
collector["maxx"] = max( collector["maxx"], node.position.x)
collector["count"] = collector["count"]+1
collector["max_effects"] = max(depth, collector["max_effects"])
return collector
#Align controllers above in a recursive fashion.
def recursive_align( node, aligned ):
tposition = node.position
for x,port in enumerate(node.ports_in):
srcnode = port.source_node
if srcnode:
srcnode.position.y = min( srcnode.position.y, tposition.y - vertical_separation )
if not srcnode.path in aligned:
srcnode.position.x = tposition.x + ( x * horizontal_separation )
collector = recursive_align( srcnode, aligned )
aligned[srcnode.path] = True
return aligned
#Align FX below the generators by centering them on their sources.
def recursive_align_fx( node, aligned, generators ):
tposition = node.position
src_average = 0
src_count = 0
for x,port in enumerate(node.ports_in):
srcnode = port.source_node
if srcnode:
if not srcnode.path in aligned and not srcnode in generators:
collector = recursive_align_fx( srcnode, aligned, generators )
src_average = src_average + srcnode.position.x
src_count = src_count+1
if not node.path in aligned:
node.position.x = src_average/src_count
node.position.y = tposition.y - vertical_separation
aligned[node.path] = True
return aligned
display_node = scene.display
#Working from the current display, organize around that.
if display_node:
#Collect the Generator Details
collector = {"x":0, "y":0, "maxx":0, "count":0, "generators":[], "controller_count":{}, "max_effects":0 }
collector = recursive_collector( display_node, None, collector, 0 )
average_x = collector["x"] / collector["count"]
average_y = collector["y"] / collector["count"]
aligned_list = {}
next_offset = 0
#Align the generators.
for x,node in enumerate( collector["generators"] ):
node.position.x = collector["maxx"] - next_offset
node.position.y = average_y
next_offset = next_offset + ( max( collector["controller_count"][node.path]-1, 0) * horizontal_separation ) + horizontal_separation
#Align the controls above the generators.
aligned_list = recursive_align( node, aligned_list )
display_node.position.x = average_x
display_node.position.y = average_y + ( collector["max_effects"] * vertical_separation )
#Align the FX below the generations
recursive_align_fx( display_node, aligned_list, collector["generators"] )
#Move all siblings to the display
src_port = display_node.ports_in[0].source
for x,destination_node in enumerate(src_port.destination_nodes):
if not destination_node == display_node:
destination_node.position.x = display_node.position.x - ( (x+1)*horizontal_separation/2.0 )
destination_node.position.y = display_node.position.y
else:
print( "No Active Display" )
proj.history.end()

Public Member Functions

virtual std::string __str__ () const override
 

Public Attributes

int x
 Get and set the horizontal coordinate of the node in the node view.
 
int y
 Get and set the vertical coordinate of the node in the node view.
 
int z
 Get and set the depth coordinate of the node in the node view.
 

Protected Member Functions

void validate () const override
 
Inheritance diagram for OMC::Node_Coordinates:
Collaboration diagram for OMC::Node_Coordinates: