void ScriptNode::deleteNodes( Node *parent, const Set *filter, bool reconnect ) { parent = parent ? parent : this; // because children are stored as a vector, it's // much more efficient to delete those at the end before // those at the beginning. int i = (int)(parent->children().size()) - 1; while( i >= 0 ) { Node *node = parent->getChild<Node>( i ); if( node && ( !filter || filter->contains( node ) ) ) { // reconnect the inputs and outputs as though the node was disabled DependencyNode *dependencyNode = IECore::runTimeCast<DependencyNode>( node ); if( reconnect && dependencyNode ) { for( OutputPlugIterator it( node ); it != it.end(); ++it ) { Plug *inPlug = dependencyNode->correspondingInput( it->get() ); if ( !inPlug ) { continue; } Plug *srcPlug = inPlug->getInput<Plug>(); if ( !srcPlug ) { continue; } // record this plug's current outputs, and reconnect them. This is a copy of (*it)->outputs() rather // than a reference, as reconnection can modify (*it)->outputs()... Plug::OutputContainer outputs = (*it)->outputs(); for ( Plug::OutputContainer::const_iterator oIt = outputs.begin(); oIt != outputs.end(); ) { Plug *dstPlug = *oIt; if ( dstPlug && dstPlug->acceptsInput( srcPlug ) && this->isAncestorOf( dstPlug ) ) { oIt++; dstPlug->setInput( srcPlug ); } else { oIt++; } } } } parent->removeChild( node ); } i--; } }
void ScriptNode::deleteNodes( Node *parent, const Set *filter, bool reconnect ) { parent = parent ? parent : this; // because children are stored as a vector, it's // much more efficient to delete those at the end before // those at the beginning. int i = (int)(parent->children().size()) - 1; while( i >= 0 ) { Node *node = parent->getChild<Node>( i ); if( node && ( !filter || filter->contains( node ) ) ) { // reconnect the inputs and outputs as though the node was disabled DependencyNode *dependencyNode = IECore::runTimeCast<DependencyNode>( node ); if( reconnect && dependencyNode ) { for( RecursiveOutputPlugIterator it( node ); !it.done(); ++it ) { Plug *inPlug = nullptr; try { inPlug = dependencyNode->correspondingInput( it->get() ); } catch( const std::exception &e ) { msg( IECore::Msg::Warning, boost::str( boost::format( "correspondingInput error while deleting - cannot reconnect \"%s\"" ) % it->get()->fullName() ), e.what() ); } if ( !inPlug ) { continue; } Plug *srcPlug = inPlug->getInput(); if ( !srcPlug ) { continue; } // record this plug's current outputs, and reconnect them. This is a copy of (*it)->outputs() rather // than a reference, as reconnection can modify (*it)->outputs()... Plug::OutputContainer outputs = (*it)->outputs(); for ( Plug::OutputContainer::const_iterator oIt = outputs.begin(); oIt != outputs.end(); ++oIt ) { Plug *dstPlug = *oIt; if ( dstPlug && dstPlug->acceptsInput( srcPlug ) && this->isAncestorOf( dstPlug ) ) { dstPlug->setInput( srcPlug ); } } } } parent->removeChild( node ); } i--; } }