本文整理汇总了C++中GraphComponentPtr类的典型用法代码示例。如果您正苦于以下问题:C++ GraphComponentPtr类的具体用法?C++ GraphComponentPtr怎么用?C++ GraphComponentPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphComponentPtr类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeChildInternal
void GraphComponent::removeChildInternal( GraphComponentPtr child, bool emitParentChanged )
{
if( emitParentChanged )
{
child->parentChanging( 0 );
}
ChildContainer::iterator it = std::find( m_children.begin(), m_children.end(), child );
if( it == m_children.end() || child->m_parent != this )
{
// the public removeChild() method protects against this case, but it's still possible to
// arrive here if an Action (which has a direct binding to removeChildInternal) is being replayed
// from the undo queue, and just prior to that something called the public removeChild() method.
// this can occur if a slot calls removeChild() from a signal triggered during the replay of the
// undo queue. the onus is on such slots to not reperform their work when ScriptNode::currentActionStage()
// is Action::Redo - instead they should rely on the fact that their actions will have been
// recorded and replayed automatically.
throw Exception( boost::str( boost::format( "GraphComponent::removeChildInternal : \"%s\" is not a child of \"%s\"." ) % child->fullName() % fullName() ) );
}
m_children.erase( it );
child->m_parent = 0;
childRemovedSignal()( this, child.get() );
if( emitParentChanged )
{
child->parentChangedSignal()( child.get(), this );
}
}
示例2: throwIfChildRejected
void GraphComponent::addChild( GraphComponentPtr child )
{
if( child->m_parent==this )
{
return;
}
throwIfChildRejected( child.get() );
if( refCount() )
{
// someone is pointing to us, so we may have a ScriptNode ancestor and we should do things
// in an undoable way. figure out what our undo function should be - it varies based on what
// the previous parent was.
Action::Function undoFn;
if( child->m_parent )
{
if( child->m_parent->isInstanceOf( (IECore::TypeId)ScriptNodeTypeId ) )
{
// use raw pointer to avoid circular reference between script and undo queue
undoFn = boost::bind( &GraphComponent::addChildInternal, child->m_parent, child, child->index() );
}
else
{
// use smart pointer to ensure parent remains alive, even if something unscrupulous
// messes it with non-undoable actions that aren't stored in the undo queue.
undoFn = boost::bind( &GraphComponent::addChildInternal, GraphComponentPtr( child->m_parent ), child, child->index() );
}
}
else
{
// no previous parent.
undoFn = boost::bind( &GraphComponent::removeChildInternal, this, child, true );
}
Action::enact(
this,
// ok to use raw pointer for this - lifetime of subject guaranteed.
boost::bind( &GraphComponent::addChildInternal, this, child, m_children.size() ),
undoFn
);
}
else
{
// we have no references to us - chances are we're in construction still. adding ourselves to an
// undo queue is impossible, and creating temporary smart pointers to ourselves (as above) will
// cause our destruction before construction completes. just do the work directly.
addChildInternal( child, m_children.size() );
}
}
示例3: removeChild
void GraphComponent::removeChild( GraphComponentPtr child )
{
if( child->m_parent!=this )
{
throw Exception( "Object is not a child." );
}
if( refCount() )
{
// someone is pointing to us, so we may have a ScriptNode ancestor and we should do things
// in an undoable way.
Action::enact(
this,
// ok to bind raw pointers to this, because enact() guarantees
// the lifetime of the subject.
boost::bind( &GraphComponent::removeChildInternal, this, child, true ),
boost::bind( &GraphComponent::addChildInternal, this, child, child->index() )
);
}
else
{
// we have no references to us - chances are we're in construction still. adding ourselves to an
// undo queue is impossible, and creating temporary smart pointers to ourselves (as above) will
// cause our destruction before construction completes. just do the work directly.
removeChildInternal( child, true );
}
}
示例4: addChildInternal
void GraphComponent::addChildInternal( GraphComponentPtr child )
{
child->parentChanging( this );
GraphComponent *previousParent = child->m_parent;
if( previousParent )
{
// remove the child from the previous parent, but don't emit parentChangedSignal.
// this prevents a parent changed signal with new parent 0 followed by a parent
// changed signal with the new parent.
previousParent->removeChildInternal( child, false );
}
m_children.push_back( child );
child->m_parent = this;
child->setName( child->m_name.value() ); // to force uniqueness
childAddedSignal()( this, child.get() );
child->parentChangedSignal()( child.get(), previousParent );
}
示例5: setChild
void GraphComponent::setChild( const IECore::InternedString &name, GraphComponentPtr child )
{
GraphComponentPtr existingChild = getChild<GraphComponent>( name );
if( existingChild && existingChild == child )
{
return;
}
throwIfChildRejected( child.get() );
if( existingChild )
{
removeChild( existingChild );
}
child->setName( name );
addChild( child );
}
示例6: addChildInternal
void GraphComponent::addChildInternal( GraphComponentPtr child, size_t index )
{
child->parentChanging( this );
GraphComponent *previousParent = child->m_parent;
if( previousParent )
{
// remove the child from the previous parent, but don't emit parentChangedSignal.
// this prevents a parent changed signal with new parent null followed by a parent
// changed signal with the new parent.
previousParent->removeChildInternal( child, false );
}
m_children.insert( m_children.begin() + min( index, m_children.size() ), child );
child->m_parent = this;
child->setName( child->m_name.value() ); // to force uniqueness
Signals::emitLazily( m_signals.get(), &Signals::childAddedSignal, this, child.get() );
child->parentChanged( previousParent );
Signals::emitLazily( child->m_signals.get(), &Signals::parentChangedSignal, child.get(), previousParent );
}
示例7: undoEnabler
bool SplinePlugGadget::keyPress( GadgetPtr gadget, const KeyEvent &event )
{
if( event.key=="BackSpace" && m_selection->size() )
{
Plug *firstPlug = static_cast<Plug *>( m_selection->member( 0 ) );
UndoContext undoEnabler( firstPlug->ancestor<ScriptNode>() );
for( size_t i = 0, e = m_selection->size(); i < e ; i++ )
{
Plug *pointPlug = static_cast<Plug *>( m_selection->member( i ) );
GraphComponentPtr parent = pointPlug->parent<GraphComponent>();
if( parent )
{
parent->removeChild( pointPlug );
}
}
}
return true;
}
示例8: SimpleAction
SimpleAction( const GraphComponentPtr subject, const Function &doFn, const Function &undoFn )
: m_subject( subject.get() ), m_doFn( doFn ), m_undoFn( undoFn )
{
// In the documentation for Action::enact(), we promise that we'll keep
// the subject alive for as long as the Functions are in use. If the subject
// is a ScriptNode, that is taken care of for us, as the ScriptNode has ownership
// of the SimpleAction. If the subject is not a ScriptNode, we must increment
// the reference count and decrement it again in our destructor.
if( !m_subject->isInstanceOf( Gaffer::ScriptNode::staticTypeId() ) )
{
m_subject->addRef();
}
}