Ejemplo n.º 1
0
void GraphGadget::addConnectionGadget( Gaffer::Plug *dstPlug )
{
	Gaffer::Plug *srcPlug = dstPlug->getInput<Gaffer::Plug>();
	if( !srcPlug )
	{
		// there is no connection
		return;
	}
	
	Gaffer::Node *dstNode = dstPlug->node();
	NodeGadget *dstNodeGadget = findNodeGadget( dstNode );
	if( !dstNodeGadget )
	{
		return;
	}
	
	Nodule *dstNodule = dstNodeGadget->nodule( dstPlug );
	if( !dstNodule )
	{
		// the destination connection point is not represented in the graph
		return;
	}
	
	Gaffer::Node *srcNode = srcPlug->node();
	if( srcNode == dstNode )
	{
		// we don't want to visualise connections between plugs
		// on the same node.
		return;
	}
	
	// find the input nodule for the connection if there is one
	NodeGadget *srcNodeGadget = findNodeGadget( srcNode );
	Nodule *srcNodule = 0;
	if( srcNodeGadget )
	{
		srcNodule = srcNodeGadget->nodule( srcPlug );
	}
		
	ConnectionGadgetPtr connection = new ConnectionGadget( srcNodule, dstNodule );
	updateConnectionGadgetMinimisation( connection.get() );
	addChild( connection );

	m_connectionGadgets[dstPlug] = connection.get();
}
Ejemplo n.º 2
0
void GraphGadget::addConnectionGadgets( Gaffer::GraphComponent *plugParent )
{
	/// \todo I think this could be faster if we could iterate over just the nodules rather than all the plugs. Perhaps
	/// we could make it easy to recurse over all the Nodules of a NodeGadget if we had a RecursiveChildIterator for GraphComponents?
	Gaffer::Node *node = plugParent->isInstanceOf( Gaffer::Node::staticTypeId() ) ? static_cast<Gaffer::Node *>( plugParent ) : plugParent->ancestor<Gaffer::Node>();
	
	NodeGadget *nodeGadget = findNodeGadget( node );
	if( !nodeGadget )
	{
		return;
	}

	for( Gaffer::PlugIterator pIt( plugParent->children().begin(), plugParent->children().end() ); pIt!=pIt.end(); pIt++ )
	{
		if( (*pIt)->direction() == Gaffer::Plug::In )
		{
			// add connections for input plugs
			if( !findConnectionGadget( pIt->get() ) )
			{
				addConnectionGadget( pIt->get() );
			}
		}
		else
		{
			// reconnect any old output connections which may have been dangling
			Nodule *srcNodule = nodeGadget->nodule( *pIt );
			if( srcNodule )
			{
				for( Gaffer::Plug::OutputContainer::const_iterator oIt( (*pIt)->outputs().begin() ); oIt!= (*pIt)->outputs().end(); oIt++ )
				{
					ConnectionGadget *connection = findConnectionGadget( *oIt );
					if( connection && !connection->srcNodule() )
					{
						assert( connection->dstNodule()->plug()->getInput<Gaffer::Plug>() == *pIt ); 
						connection->setNodules( srcNodule, connection->dstNodule() );
					}
				}
			}
		}
		
		if( (*pIt)->isInstanceOf( Gaffer::CompoundPlug::staticTypeId() ) )
		{
			addConnectionGadgets( pIt->get() );
		}
	}
	
}
Ejemplo n.º 3
0
void GraphGadget::updateDragReconnectCandidate( const DragDropEvent &event )
{
	m_dragReconnectCandidate = 0;
	m_dragReconnectSrcNodule = 0;
	m_dragReconnectDstNodule = 0;
	
	if ( m_scriptNode->selection()->size() != 1 )
	{
		return;
	}
	
	// make sure the connection applies to this node.
	Gaffer::Node *node = IECore::runTimeCast<Gaffer::Node>( m_scriptNode->selection()->member( 0 ) );
	NodeGadget *selNodeGadget = nodeGadget( node );
	if ( !node || !selNodeGadget )
	{
		return;
	}
	
	m_dragReconnectCandidate = reconnectionGadgetAt( selNodeGadget, event.line );
	if ( !m_dragReconnectCandidate )
	{
		return;
	}
	
	// we don't want to reconnect the selected node to itself
	Gaffer::Plug *srcPlug = m_dragReconnectCandidate->srcNodule()->plug();
	Gaffer::Plug *dstPlug = m_dragReconnectCandidate->dstNodule()->plug();
	if ( srcPlug->node() == node || dstPlug->node() == node )
	{
		m_dragReconnectCandidate = 0;
		return;
	}
	
	Gaffer::DependencyNode *depNode = IECore::runTimeCast<Gaffer::DependencyNode>( node );
	for ( Gaffer::RecursiveOutputPlugIterator cIt( node ); cIt != cIt.end(); ++cIt )
	{
		// must be compatible
		Gaffer::Plug *p = cIt->get();
		if ( !dstPlug->acceptsInput( p ) )
		{
			continue;
		}
		
		// must have a nodule
		m_dragReconnectSrcNodule = selNodeGadget->nodule( p );
		if ( !m_dragReconnectSrcNodule )
		{
			continue;
		}
		
		// must not be connected to a nodule
		for ( Gaffer::Plug::OutputContainer::const_iterator oIt = p->outputs().begin(); oIt != p->outputs().end(); ++oIt )
		{
			NodeGadget *oNodeGadget = nodeGadget( (*oIt)->node() );
			if ( oNodeGadget && oNodeGadget->nodule( *oIt ) )
			{
				m_dragReconnectSrcNodule = 0;
				break;
			}
		}
		
		if ( !m_dragReconnectSrcNodule )
		{
			continue;
		}
		
		if ( !depNode )
		{
			// found the best option
			break;
		}
		
		// make sure its corresponding input is also free
		if ( Gaffer::Plug *in = depNode->correspondingInput( p ) )
		{
			if ( in->getInput<Gaffer::Plug>() )
			{
				m_dragReconnectSrcNodule = 0;
				continue;
			}
			
			m_dragReconnectDstNodule = selNodeGadget->nodule( in );
			if ( m_dragReconnectDstNodule )
			{
				break;
			}
		}
	}
	
	// check input plugs on non-dependencyNodes
	if ( !depNode && !m_dragReconnectDstNodule )
	{
		for ( Gaffer::RecursiveInputPlugIterator cIt( node ); cIt != cIt.end(); ++cIt )
		{
			Gaffer::Plug *p = cIt->get();
			if ( !p->getInput<Gaffer::Plug>() && p->acceptsInput( srcPlug ) )
			{
				m_dragReconnectDstNodule = selNodeGadget->nodule( p );
				if ( m_dragReconnectDstNodule )
				{
					break;
				}
			}
		}
	}
	
	if ( !m_dragReconnectSrcNodule && !m_dragReconnectDstNodule )
	{
		m_dragReconnectCandidate = 0;
	}
}