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; }
void StandardNodule::connection( const DragDropEvent &event, Gaffer::PlugPtr &input, Gaffer::PlugPtr &output ) { Gaffer::PlugPtr dropPlug = IECore::runTimeCast<Gaffer::Plug>( event.data ); if( dropPlug ) { Gaffer::PlugPtr thisPlug = plug(); if( thisPlug->node() != dropPlug->node() && thisPlug->direction()!=dropPlug->direction() ) { if( thisPlug->direction()==Gaffer::Plug::In ) { input = thisPlug; output = dropPlug; } else { input = dropPlug; output = thisPlug; } if( input->acceptsInput( output.get() ) ) { // success return; } } } input = output = 0; return; }
void Dot::setup( const Plug *plug ) { const Plug *originalPlug = plug; if( const Plug *inputPlug = plug->getInput() ) { // We'd prefer to set up based on an input plug if possible - see comments // in DotNodeGadgetTest.testCustomNoduleTangentsPreferInputIfAvailable(). plug = inputPlug; } Gaffer::PlugPtr in = plug->createCounterpart( g_inPlugName, Plug::In ); Gaffer::PlugPtr out = plug->createCounterpart( g_outPlugName, Plug::Out ); MetadataAlgo::copyColors( originalPlug , in.get() , /* overwrite = */ false ); MetadataAlgo::copyColors( originalPlug , out.get() , /* overwrite = */ false ); in->setFlags( Plug::Serialisable, true ); out->setFlags( Plug::Serialisable, true ); // Set up Metadata so our plugs appear in the right place. We must do this now rather // than later because the GraphEditor will add a Nodule for the plug as soon as the plug // is added as a child. ConstStringDataPtr sectionData; for( const Plug *metadataPlug = plug; metadataPlug; metadataPlug = metadataPlug->parent<Plug>() ) { if( ( sectionData = Metadata::value<StringData>( metadataPlug, g_sectionName ) ) ) { break; } } if( sectionData ) { const std::string §ion = sectionData->readable(); std::string oppositeSection; if( section == "left" ) { oppositeSection = "right"; } else if( section == "right" ) { oppositeSection = "left"; } else if( section == "bottom" ) { oppositeSection = "top"; } else { oppositeSection = "bottom"; } Metadata::registerValue( plug->direction() == Plug::In ? in.get() : out.get(), g_sectionName, sectionData ); Metadata::registerValue( plug->direction() == Plug::In ? out.get() : in.get(), g_sectionName, new StringData( oppositeSection ) ); } setChild( g_inPlugName, in ); setChild( g_outPlugName, out ); out->setInput( in ); }
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; }