本文整理汇总了C++中PlugPtr类的典型用法代码示例。如果您正苦于以下问题:C++ PlugPtr类的具体用法?C++ PlugPtr怎么用?C++ PlugPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlugPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fullName
void Plug::setInput( PlugPtr input )
{
if( input.get()==m_input )
{
return;
}
if( input && !acceptsInput( input ) )
{
std::string what = boost::str(
boost::format( "Plug \"%s\" rejects input \"%s\"." )
% fullName()
% input->fullName()
);
throw IECore::Exception( what );
}
if( refCount() )
{
// someone is referring to us, so we're definitely fully constructed and we may have a ScriptNode
// above us, so we should do things in a way compatible with the undo system.
Action::enact(
this,
boost::bind( &Plug::setInputInternal, PlugPtr( this ), input, true ),
boost::bind( &Plug::setInputInternal, PlugPtr( this ), PlugPtr( m_input ), true )
);
}
else
{
// noone is referring to us. we're probably still constructing, and undo is impossible anyway (we
// have no ScriptNode ancestor), so we can't make a smart pointer
// to ourselves (it will result in double destruction). so we just set the input directly.
setInputInternal( input, false );
}
}
示例2: Plug
ArrayPlug::ArrayPlug( const std::string &name, Direction direction, PlugPtr element, size_t minSize, size_t maxSize, unsigned flags )
: Plug( name, direction, flags ), m_minSize( std::max( minSize, size_t( 1 ) ) ), m_maxSize( std::max( maxSize, m_minSize ) )
{
if( direction == Plug::Out )
{
throw IECore::Exception( "Output ArrayPlugs are currently unsupported." );
}
if( element )
{
// If we're dynamic ourselves, then serialisations will include a constructor
// for us, but it will have element==None. In this case we make sure the first
// element is dynamic, so that it too will have a constructor written out. But
// if we're not dynamic, we expect to be passed the element again upon reconstruction,
// so we don't need a constructor to be serialised for the element, and therefore
// we must set it to be non-dynamic.
element->setFlags( Gaffer::Plug::Dynamic, getFlags( Gaffer::Plug::Dynamic ) );
addChild( element );
for( size_t i = 1; i < m_minSize; ++i )
{
PlugPtr p = element->createCounterpart( element->getName(), Plug::In );
addChild( p );
}
}
parentChangedSignal().connect( boost::bind( &ArrayPlug::parentChanged, this ) );
}
示例3: removeChildren
void Expression::updatePlug( ValuePlug *parentPlug, size_t childIndex, ValuePlug *plug )
{
if( parentPlug->children().size() > childIndex )
{
// See if we can reuse the existing plug
Plug *existingChildPlug = parentPlug->getChild<Plug>( childIndex );
if(
( existingChildPlug->direction() == Plug::In && existingChildPlug->getInput<Plug>() == plug ) ||
( existingChildPlug->direction() == Plug::Out && plug->getInput<Plug>() == existingChildPlug )
)
{
return;
}
}
// Existing plug not OK, so we need to create one. First we must remove all
// plugs from childIndex onwards, so that when we add the new plug it gets
// the right index.
removeChildren( parentPlug, childIndex );
// Finally we can add the plug we need.
PlugPtr childPlug = plug->createCounterpart( "p0", parentPlug->direction() );
childPlug->setFlags( Plug::Dynamic, true );
parentPlug->addChild( childPlug );
if( childPlug->direction() == Plug::In )
{
childPlug->setInput( plug );
}
else
{
plug->setInput( childPlug );
}
}
示例4: addPlug
void Expression::addPlug( ValuePlug *parentPlug, const std::string &plugPath )
{
Node *p = parent<Node>();
if( !p )
{
throw IECore::Exception( "No parent" );
}
ValuePlug *plug = p->descendant<ValuePlug>( plugPath );
if( !plug )
{
throw IECore::Exception( boost::str( boost::format( "Plug \"%s\" does not exist" ) % plugPath ) );
}
PlugPtr childPlug = plug->createCounterpart( "p0", parentPlug->direction() );
childPlug->setFlags( Plug::Dynamic, true );
parentPlug->addChild( childPlug );
if( childPlug->direction() == Plug::In )
{
childPlug->setInput( plug );
}
else
{
plug->setInput( childPlug );
}
}
示例5: inputChanged
void ArrayPlug::inputChanged( Gaffer::Plug *plug )
{
if( plug->parent<ArrayPlug>() != this )
{
return;
}
if( getInput() )
{
// When we ourselves have an input, we don't do any automatic addition or
// removal of children, because the Plug base class itself manages
// children to maintain the connection.
return;
}
if( const ScriptNode *script = ancestor<ScriptNode>() )
{
if( script->currentActionStage() == Action::Undo ||
script->currentActionStage() == Action::Redo
)
{
// If we're currently in an undo or redo, we don't
// need to do anything, because our previous actions
// will be in the undo queue and will be being replayed
// for us automatically.
return;
}
}
if( plug->getInput() )
{
// Connection made. If it's the last plug
// then we need to add one more.
if( plug == children().back() && children().size() < m_maxSize )
{
PlugPtr p = getChild<Plug>( 0 )->createCounterpart( getChild<Plug>( 0 )->getName(), Plug::In );
p->setFlags( Gaffer::Plug::Dynamic, true );
addChild( p );
MetadataAlgo::copyColors( getChild<Plug>( 0 ) , p.get() , /* overwrite = */ false );
}
}
else
{
// Connection broken. We need to remove any
// unneeded unconnected plugs so that we have
// only one unconnected plug at the end.
for( size_t i = children().size() - 1; i > m_minSize - 1; --i )
{
if( !getChild<Plug>( i )->getInput() && !getChild<Plug>( i - 1 )->getInput() )
{
removeChild( getChild<Plug>( i ) );
}
else
{
break;
}
}
}
}
示例6: MemberPlug
PlugPtr CompoundDataPlug::MemberPlug::createCounterpart( const std::string &name, Direction direction ) const
{
PlugPtr result = new MemberPlug( name, direction, getFlags() );
for( PlugIterator it( this ); it != it.end(); it++ )
{
result->addChild( (*it)->createCounterpart( (*it)->getName(), direction ) );
}
return result;
}
示例7: ValuePlug
PlugPtr ValuePlug::createCounterpart( const std::string &name, Direction direction ) const
{
PlugPtr result = new ValuePlug( name, direction, getFlags() );
for( PlugIterator it( this ); !it.done(); ++it )
{
result->addChild( (*it)->createCounterpart( (*it)->getName(), direction ) );
}
return result;
}
示例8: validatePromotability
Plug *Box::promotePlug( Plug *descendantPlug )
{
validatePromotability( descendantPlug, /* throwExceptions = */ true );
PlugPtr externalPlug = descendantPlug->createCounterpart( promotedCounterpartName( descendantPlug ), descendantPlug->direction() );
externalPlug->setFlags( Plug::Dynamic, true );
// Flags are not automatically propagated to the children of compound plugs,
// so we need to do that ourselves. We don't want to propagate them to the
// children of plug types which create the children themselves during
// construction though, hence the typeId checks for the base classes
// which add no children during construction. I'm not sure this approach is
// necessarily the best - the alternative would be to set everything dynamic
// unconditionally and then implement Serialiser::childNeedsConstruction()
// for types like CompoundNumericPlug that create children in their constructors.
const Gaffer::TypeId compoundTypes[] = { PlugTypeId, ValuePlugTypeId, CompoundPlugTypeId, ArrayPlugTypeId };
const Gaffer::TypeId *compoundTypesEnd = compoundTypes + 4;
if( find( compoundTypes, compoundTypesEnd, (Gaffer::TypeId)externalPlug->typeId() ) != compoundTypesEnd )
{
for( RecursivePlugIterator it( externalPlug.get() ); it != it.end(); ++it )
{
(*it)->setFlags( Plug::Dynamic, true );
if( find( compoundTypes, compoundTypesEnd, (Gaffer::TypeId)(*it)->typeId() ) != compoundTypesEnd )
{
it.prune();
}
}
}
if( externalPlug->direction() == Plug::In )
{
if( ValuePlug *externalValuePlug = IECore::runTimeCast<ValuePlug>( externalPlug.get() ) )
{
externalValuePlug->setFrom( static_cast<ValuePlug *>( descendantPlug ) );
}
}
// Copy over the metadata for nodule position, so the nodule appears in the expected spot.
// This must be done before parenting the new plug, as the nodule is created from childAddedSignal().
copyMetadata( descendantPlug, externalPlug.get() );
addChild( externalPlug );
if( externalPlug->direction() == Plug::In )
{
descendantPlug->setInput( externalPlug );
}
else
{
externalPlug->setInput( descendantPlug );
}
return externalPlug.get();
}
示例9: Node
ExecutableNode::ExecutableNode( const std::string &name )
: Node( name )
{
storeIndexOfNextChild( g_firstPlugIndex );
addChild( new ArrayPlug( "requirements", Plug::In, new RequirementPlug( "requirement0" ) ) );
addChild( new RequirementPlug( "requirement", Plug::Out ) );
PlugPtr dispatcherPlug = new Plug( "dispatcher", Plug::In );
addChild( dispatcherPlug );
Dispatcher::setupPlugs( dispatcherPlug.get() );
}
示例10: DependencyNode
TaskNode::TaskNode( const std::string &name )
: DependencyNode( name )
{
storeIndexOfNextChild( g_firstPlugIndex );
addChild( new ArrayPlug( "preTasks", Plug::In, new TaskPlug( "preTask0" ) ) );
addChild( new ArrayPlug( "postTasks", Plug::In, new TaskPlug( "postTask0" ) ) );
addChild( new TaskPlug( "task", Plug::Out ) );
PlugPtr dispatcherPlug = new Plug( "dispatcher", Plug::In );
addChild( dispatcherPlug );
Dispatcher::setupPlugs( dispatcherPlug.get() );
}
示例11: fullName
void CompoundPlug::setInput( PlugPtr input )
{
if( input.get() == getInput<Plug>() )
{
return;
}
// unfortunately we have to duplicate the check in Plug::setInput()
// ourselves as we delay calling Plug::setInput() until we've connected
// the children, but need to do the check first.
/// \todo I think there's a case for not having CompoundPlug at all,
/// and having Plug have all its functionality.
if( input && !acceptsInput( input ) )
{
std::string what = boost::str(
boost::format( "Plug \"%s\" rejects input \"%s\"." )
% fullName()
% input->fullName()
);
throw IECore::Exception( what );
}
{
// we use the plugInputChangedConnection to trigger calls to updateInputFromChildInputs()
// when child inputs are changed by code elsewhere. it would be counterproductive for
// us to call updateInputFromChildInputs() while we ourselves are changing those inputs,
// so we temporarily block the connection.
BlockedConnection block( m_plugInputChangedConnection );
if( !input )
{
for( ChildContainer::const_iterator it = children().begin(); it!=children().end(); it++ )
{
IECore::staticPointerCast<Plug>( *it )->setInput( 0 );
}
}
else
{
CompoundPlugPtr p = IECore::staticPointerCast<CompoundPlug>( input );
ChildContainer::const_iterator it1, it2;
for( it1 = children().begin(), it2 = p->children().begin(); it1!=children().end(); it1++, it2++ )
{
IECore::staticPointerCast<Plug>( *it1 )->setInput( IECore::staticPointerCast<Plug>( *it2 ) );
}
}
}
// we connect ourselves last, so that all our child plugs are correctly connected
// before we signal our own connection change.
ValuePlug::setInput( input );
}
示例12: loadCoshaderParameter
static void loadCoshaderParameter( Gaffer::CompoundPlug *parametersPlug, const std::string &name )
{
Plug *existingPlug = parametersPlug->getChild<Plug>( name );
if( existingPlug && existingPlug->typeId() == Plug::staticTypeId() )
{
return;
}
PlugPtr plug = new Plug( name, Plug::In, Plug::Default | Plug::Dynamic );
if( existingPlug && existingPlug->getInput<Plug>() )
{
plug->setInput( existingPlug->getInput<Plug>() );
}
parametersPlug->setChild( name, plug );
}
示例13: removeChild
void Expression::updatePlugs( const std::string &dstPlugPath, std::vector<std::string> &srcPlugPaths )
{
Node *p = parent<Node>();
// if the expression was invalid, remove our plugs
if( !dstPlugPath.size() )
{
Plug *in = getChild<Plug>( "in" );
if( in )
{
removeChild( in );
}
Plug *out = getChild<Plug>( "out" );
if( out )
{
removeChild( out );
}
return;
}
// otherwise try to create connections to the plugs the expression wants
ValuePlug *dstPlug = p->descendant<ValuePlug>( dstPlugPath );
if( !dstPlug )
{
throw IECore::Exception( boost::str( boost::format( "Destination plug \"%s\" does not exist" ) % dstPlugPath ) );
}
CompoundPlugPtr inPlugs = new CompoundPlug( "in", Plug::In, Plug::Default | Plug::Dynamic );
setChild( "in", inPlugs );
for( std::vector<std::string>::const_iterator it = srcPlugPaths.begin(); it!=srcPlugPaths.end(); it++ )
{
ValuePlug *srcPlug = p->descendant<ValuePlug>( *it );
if( !srcPlug )
{
throw IECore::Exception( boost::str( boost::format( "Source plug \"%s\" does not exist" ) % *it ) );
}
PlugPtr inPlug = srcPlug->createCounterpart( "plug", Plug::In );
inPlugs->addChild( inPlug );
inPlug->setInput( srcPlug );
}
PlugPtr outPlug = dstPlug->createCounterpart( "out", Plug::Out );
setChild( "out", outPlug );
dstPlug->setInput( outPlug );
}
示例14: plugName
static Plug *loadClosureParameter( const OSLQuery::Parameter *parameter, Gaffer::CompoundPlug *parent )
{
const string name = plugName( parameter );
Plug *existingPlug = parent->getChild<Plug>( name );
if( existingPlug && existingPlug->typeId() == Plug::staticTypeId() )
{
return existingPlug;
}
PlugPtr plug = new Plug( name, parent->direction(), Plug::Default | Plug::Dynamic );
transferConnectionOrValue( existingPlug, plug.get() );
parent->setChild( name, plug );
return plug;
}
示例15: addError
void addError( PlugPtr plug, const std::string &error )
{
PlugEntry &entry = m_errors[plug];
entry.error = error;
if( !entry.parentChangedConnection.connected() )
{
entry.parentChangedConnection = plug->parentChangedSignal().connect( boost::bind( &ErrorGadget::parentChanged, this, ::_1 ) );
}
m_image->setVisible( true );
}