Exemple #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();
}
Exemple #2
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;
	}
}