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; }
ConnectionGadgetPtr ConnectionGadget::create( NodulePtr srcNodule, NodulePtr dstNodule ) { const Gaffer::Plug *plug = dstNodule->plug(); if( const Gaffer::Node *node = plug->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( srcNodule, dstNodule ); } } } t = IECore::RunTimeTyped::baseTypeId( t ); } } CreatorMap &m = creators(); IECore::TypeId t = plug->typeId(); while( t!=IECore::InvalidTypeId ) { CreatorMap::const_iterator it = m.find( t ); if( it!=m.end() ) { return it->second( srcNodule, dstNodule ); } t = IECore::RunTimeTyped::baseTypeId( t ); } return NULL; }
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 ); } }