Esempio n. 1
0
NodulePtr StandardNodeGadget::addNodule( Gaffer::PlugPtr plug )
{
	if( plug->getName().string().compare( 0, 2, "__" )==0 )
	{
		return 0;
	}
	
	NodulePtr nodule = Nodule::create( plug );
	if( !nodule )
	{
		return 0;
	}
	
	if( plug->direction()==Gaffer::Plug::In )
	{
		inputNoduleContainer()->addChild( nodule );
	}
	else
	{
		outputNoduleContainer()->addChild( nodule );
	}
	
	m_nodules[plug.get()] = nodule.get();
	
	return nodule;
}
Esempio n. 2
0
void StandardNodeGadget::updateNodules( std::vector<Nodule *> &nodules, std::vector<Nodule *> &added, std::vector<NodulePtr> &removed )
{
	// Update the nodules for all our plugs, and build a vector
	// of IndexAndNodule to sort ready for layout.
	vector<IndexAndNodule> sortedNodules;
	for( PlugIterator plugIt( node() ); plugIt != plugIt.end(); ++plugIt )
	{
		Plug *plug = plugIt->get();
		if( plug->getName().string().compare( 0, 2, "__" )==0 )
		{
			continue;
		}

		IECore::ConstStringDataPtr typeData = Metadata::plugValue<IECore::StringData>( plug, g_noduleTypeKey );
		IECore::InternedString type = typeData ? typeData->readable() : "GafferUI::StandardNodule";

		Nodule *nodule = NULL;
		NoduleMap::iterator it = m_nodules.find( plug );
		if( it != m_nodules.end() && it->second.type == type )
		{
			nodule = it->second.nodule.get();
		}
		else
		{
			if( it != m_nodules.end() && it->second.nodule )
			{
				removed.push_back( it->second.nodule );
			}
			NodulePtr n = Nodule::create( plug );
			m_nodules[plug] = TypeAndNodule( type, n );
			if( n )
			{
				added.push_back( n.get() );
				nodule = n.get();
			}
		}

		if( nodule )
		{
			int index = sortedNodules.size();
			if( IECore::ConstIntDataPtr indexData = Metadata::plugValue<IECore::IntData>( plug, g_noduleIndexKey ) )
			{
				index = indexData->readable();
			}
			sortedNodules.push_back( IndexAndNodule( index, nodule ) );
		}
	}

	// Remove any nodules for which a plug no longer exists.
	for( NoduleMap::iterator it = m_nodules.begin(); it != m_nodules.end(); )
	{
		NoduleMap::iterator next = it; next++;
		if( it->first->parent<Node>() != node() )
		{
			if( it->second.nodule )
			{
				removed.push_back( it->second.nodule );
			}
			m_nodules.erase( it );
		}
		it = next;
	}

	// Sort ready for layout.
	sort( sortedNodules.begin(), sortedNodules.end() );
	for( vector<IndexAndNodule>::const_iterator it = sortedNodules.begin(), eIt = sortedNodules.end(); it != eIt; ++it )
	{
		nodules.push_back( it->nodule );
	}
}