Example #1
0
NodeGadget *GraphGadget::addNodeGadget( Gaffer::Node *node )
{	
	NodeGadgetPtr nodeGadget = NodeGadget::create( node );
	if( !nodeGadget )
	{
		return NULL;
	}
	
	addChild( nodeGadget );
	
	NodeGadgetEntry nodeGadgetEntry;
	nodeGadgetEntry.inputChangedConnection = node->plugInputChangedSignal().connect( boost::bind( &GraphGadget::inputChanged, this, ::_1 ) );
	nodeGadgetEntry.plugSetConnection = node->plugSetSignal().connect( boost::bind( &GraphGadget::plugSet, this, ::_1 ) );	
	nodeGadgetEntry.gadget = nodeGadget.get();
	
	m_nodeGadgets[node] = nodeGadgetEntry;
	
	// place it if it's not placed already.	
	if( !node->getChild<Gaffer::V2fPlug>( "__uiPosition" ) )
	{
		m_layout->positionNode( this, node );
	}
	
	updateNodeGadgetTransform( nodeGadget.get() );
	
	return nodeGadget;
}
Example #2
0
NodeGadget *GraphGadget::addNodeGadget( Gaffer::Node *node )
{
	NodeGadgetPtr nodeGadget = NodeGadget::create( node );
	if( !nodeGadget )
	{
		return NULL;
	}

	addChild( nodeGadget );

	NodeGadgetEntry &nodeGadgetEntry = m_nodeGadgets[node];
	nodeGadgetEntry.inputChangedConnection = node->plugInputChangedSignal().connect( boost::bind( &GraphGadget::inputChanged, this, ::_1 ) );
	nodeGadgetEntry.plugSetConnection = node->plugSetSignal().connect( boost::bind( &GraphGadget::plugSet, this, ::_1 ) );
	nodeGadgetEntry.gadget = nodeGadget.get();

	// highlight to reflect selection status
	if( m_scriptNode && m_scriptNode->selection()->contains( node ) )
	{
		nodeGadget->setHighlighted( true );
	}

	// place it if it's not placed already.
	if( !node->getChild<Gaffer::V2fPlug>( g_positionPlugName ) )
	{
		setNodePosition( node, V2f( 0 ) );
	}

	updateNodeGadgetTransform( nodeGadget.get() );

	return nodeGadget.get();
}
Example #3
0
bool GraphGadget::dragEnd( GadgetPtr gadget, const DragDropEvent &event )
{
	DragMode dragMode = m_dragMode;
	m_dragMode = None;
	Pointer::set( 0 );
	
	if( !m_scriptNode )
	{
		return false;
	}
	
	V3f i;
	if( !event.line.intersect( Plane3f( V3f( 0, 0, 1 ), 0 ), i ) )
	{
		return false;
	}
	
	if( dragMode == Moving )
	{
		if ( m_dragReconnectCandidate )
		{
			if ( m_dragReconnectDstNodule || m_dragReconnectSrcNodule )
			{
				Gaffer::Plug *srcPlug = m_dragReconnectCandidate->srcNodule()->plug();
				Gaffer::Plug *dstPlug = m_dragReconnectCandidate->dstNodule()->plug();
				
				Gaffer::UndoContext undoContext( m_scriptNode );
				
				if ( m_dragReconnectDstNodule )
				{
					m_dragReconnectDstNodule->plug()->setInput( srcPlug );
					dstPlug->setInput( 0 );
				}

				if ( m_dragReconnectSrcNodule )
				{
					dstPlug->setInput( m_dragReconnectSrcNodule->plug() );
				}
			}
		}
		
		m_dragReconnectCandidate = 0;
		renderRequestSignal()( this );
	}
	else if( dragMode == Selecting )
	{
		Box2f selectionBound;
		selectionBound.extendBy( m_dragStartPosition );
		selectionBound.extendBy( m_lastDragPosition );
	
		for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ )
		{
			NodeGadgetPtr nodeGadget = runTimeCast<NodeGadget>( *it );
			if( nodeGadget )
			{
				Box3f nodeBound3 = nodeGadget->transformedBound();
				Box2f nodeBound2( V2f( nodeBound3.min.x, nodeBound3.min.y ), V2f( nodeBound3.max.x, nodeBound3.max.y ) );
				if( boxContains( selectionBound, nodeBound2 ) )
				{
					m_scriptNode->selection()->add( nodeGadget->node() );
				}
			}
		}
	
		renderRequestSignal()( this );
	}

	return true;
}