Beispiel #1
0
void ScriptNode::paste( Node *parent )
{
	ApplicationRoot *app = applicationRoot();
	if( !app )
	{
		throw( "ScriptNode has no ApplicationRoot" );
	}

	IECore::ConstStringDataPtr s = IECore::runTimeCast<const IECore::StringData>( app->getClipboardContents() );
	if( s )
	{
		parent = parent ? parent : this;
		// set up something to catch all the newly created nodes
		StandardSetPtr newNodes = new StandardSet;
		parent->childAddedSignal().connect( boost::bind( (bool (StandardSet::*)( IECore::RunTimeTypedPtr ) )&StandardSet::add, newNodes.get(), ::_2 ) );

			// do the paste
			execute( s->readable(), parent );

		// transfer the newly created nodes into the selection
		selection()->clear();
		for( size_t i = 0, e = newNodes->size(); i < e; i++ )
		{
			StandardSet::Member *member = newNodes->member( i );
			if( member->isInstanceOf( Node::staticTypeId() ) )
			{
				selection()->add( member );
			}
		}
	}
}
Beispiel #2
0
NodulePtr Nodule::create( Gaffer::PlugPtr plug )
{
	IECore::ConstStringDataPtr noduleType = Gaffer::Metadata::plugValue<IECore::StringData>( plug.get(), "nodule:type" );
	if( noduleType )
	{
		if( noduleType->readable() == "" )
		{
			return NULL;
		}
		const TypeNameCreatorMap &m = typeNameCreators();
		TypeNameCreatorMap::const_iterator it = m.find( noduleType->readable() );
		if( it != m.end() )
		{
			return it->second( plug );
		}
		else
		{
			IECore::msg( IECore::Msg::Warning, "Nodule::create", boost::format( "Nonexistent nodule type \"%s\" requested for plug \"%s\"" ) % noduleType->readable() % plug->fullName() );
		}
	}

	const Gaffer::Node *node = plug->node();
	if( node )
	{
		std::string plugPath = plug->relativeName( node );
		const NamedCreatorMap &m = namedCreators();
		IECore::TypeId t = node->typeId();
		while( t!=IECore::InvalidTypeId )
		{
			NamedCreatorMap::const_iterator it = m.find( t );
			if( it!=m.end() )
			{
				for( RegexAndCreatorVector::const_reverse_iterator nIt = it->second.rbegin(); nIt!=it->second.rend(); nIt++ )
				{
					if( boost::regex_match( plugPath, nIt->first ) )
					{
						return nIt->second( plug );
					}
				}
			}
			t = IECore::RunTimeTyped::baseTypeId( t );
		}
	}

	const PlugCreatorMap &m = plugCreators();
	IECore::TypeId t = plug->typeId();
	while( t!=IECore::InvalidTypeId )
	{
		PlugCreatorMap::const_iterator it = m.find( t );
		if( it!=m.end() )
		{
			return it->second( plug );
		}
		t = IECore::RunTimeTyped::baseTypeId( t );
	}

	return 0;
}
bool MatchPatternPathFilter::remove( PathPtr path ) const
{
	if( m_leafOnly && !path->isLeaf() )
	{
		return false;
	}

	IECore::ConstStringDataPtr propertyData;
	const std::string *propertyValue = NULL;
	if( m_propertyName == g_namePropertyName )
	{
		if( !path->names().size() )
		{
			return invert( true );
		}
		// quicker to retrieve the value from the path than as a property
		propertyValue = &(path->names().back().string());
	}
	else
	{
		propertyData = IECore::runTimeCast<const IECore::StringData>( path->property( m_propertyName ) );
		if( !propertyData )
		{
			throw IECore::Exception( "Expected StringData" );
		}
		propertyValue = &propertyData->readable();
	}

	for( std::vector<StringAlgo::MatchPattern>::const_iterator it = m_patterns.begin(), eIt = m_patterns.end(); it != eIt; ++it )
	{
		if( StringAlgo::match( propertyValue->c_str(), *it ) )
		{
			return invert( false );
		}
	}
	return invert( true );
}
Beispiel #4
0
NodeGadgetPtr NodeGadget::create( Gaffer::NodePtr node )
{
	IECore::ConstStringDataPtr nodeGadgetType = Gaffer::Metadata::value<IECore::StringData>( node.get(), "nodeGadget:type" );
	if( nodeGadgetType )
	{
		if( nodeGadgetType->readable() == "" )
		{
			return nullptr;
		}
		const TypeCreatorMap &m = typeCreators();
		TypeCreatorMap::const_iterator it = m.find( nodeGadgetType->readable() );
		if( it != m.end() )
		{
			return it->second( node );
		}
		else
		{
			IECore::msg( IECore::Msg::Warning, "NodeGadget::create", boost::format( "Nonexistent type \"%s\" requested for node \"%s\"" ) % nodeGadgetType->readable() % node->fullName() );
		}
	}

	const NodeCreatorMap &cr = nodeCreators();

	IECore::TypeId typeId = node->typeId();
	while( typeId != IECore::InvalidTypeId )
	{
		const NodeCreatorMap::const_iterator it = cr.find( typeId );
		if( it != cr.end() )
		{
			return it->second( node );
		}
		typeId = IECore::RunTimeTyped::baseTypeId( typeId );
	}

	return nullptr;
}
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 );
	}
}