Skip to content

Commit

Permalink
Merge pull request #5994 from johnhaddon/dotContextTracker
Browse files Browse the repository at this point in the history
DotNodeGadget : Use ContextTracker to evaluate custom label
  • Loading branch information
johnhaddon authored Aug 7, 2024
2 parents e5d1448 + a3a76ed commit 9599500
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Improvements
- Improved highlighting of active nodes, with more accurate tracking of Loop node iterations.
- Annotation `{plug}` substitutions are now evaluated in a context determined relative to the focus node.
- The strike-through for disabled nodes is now evaluated in a context determined relative to the focus node.
- Custom dot labels are now evaluated in a context determined relative to the focus node.
- LightEditor :
- Improved formatting of column headers containing whitespace.
- The "Double-click to toggle" tooltip is no longer displayed while hovering over non-editable cells, and a "Double-click to edit" tooltip is now displayed while hovering over other non-toggleable but editable cells.
Expand All @@ -29,7 +30,9 @@ Fixes
- Scene Editors : Fixed update when ScenePlugs are added to or removed from the node being viewed.
- PrimitiveInspector : Fixed failure to update when the location being viewed ceases to exist, or is recreated.
- Shuffle, ShuffleAttributes, ShufflePrimitiveVariables : Fixed some special cases where shuffling a source to itself would fail to have the expected effect.
- GraphEditor : Fixed dimming of labels for BoxIn and BoxOut nodes.
- GraphEditor :
- Fixed dimming of labels for BoxIn and BoxOut nodes.
- Fixed update of custom context-sensitive labels on Dot nodes.
- GafferCortexUI : Removed usage of legacy PlugValueWidget API.
- Dispatcher : Fixed crashes caused by a dispatcher's `SetupPlugsFn` attempting to access the TaskNode it was being called for. Dispatchers may now introspect the TaskNode and add different plugs based on type (#915).

Expand Down
1 change: 1 addition & 0 deletions include/Gaffer/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class GAFFER_API Context : public IECore::RefCounted
public :

/// Constructing the Scope pushes the current context.
/// If context is `nullptr` then this is a no-op.
Scope( const Context *context );
/// Destruction of the Scope pops the previously pushed context.
~Scope();
Expand Down
3 changes: 3 additions & 0 deletions include/GafferUI/DotNodeGadget.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
namespace Gaffer
{

IE_CORE_FORWARDDECLARE( Context )
IE_CORE_FORWARDDECLARE( Plug )

} // namespace Gaffer
Expand All @@ -65,6 +66,7 @@ class GAFFERUI_API DotNodeGadget : public StandardNodeGadget
protected :

void renderLayer( Layer layer, const Style *style, RenderReason reason ) const override;
void updateFromContextTracker( const ContextTracker *contextTracker ) override;

private :

Expand All @@ -82,6 +84,7 @@ class GAFFERUI_API DotNodeGadget : public StandardNodeGadget

Gaffer::Signals::ScopedConnection m_upstreamNameChangedConnection;

Gaffer::ConstContextPtr m_labelContext;
std::string m_label;
Imath::V2f m_labelPosition;

Expand Down
19 changes: 13 additions & 6 deletions src/GafferUI/DotNodeGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ DotNodeGadget::DotNodeGadget( Gaffer::NodePtr node )
dropSignal().connect( boost::bind( &DotNodeGadget::drop, this, ::_2 ) );

updateUpstreamNameChangedConnection();
updateLabel();
// Don't need to call `updateLabel()` explicitly, because GraphGadget will
// call `updateFromContextTracker()` immediately after construction, and we'll
// update there.
}

DotNodeGadget::~DotNodeGadget()
Expand Down Expand Up @@ -116,6 +118,13 @@ void DotNodeGadget::renderLayer( Layer layer, const Style *style, RenderReason r
}
}

void DotNodeGadget::updateFromContextTracker( const ContextTracker *contextTracker )
{
StandardNodeGadget::updateFromContextTracker( contextTracker );
m_labelContext = contextTracker->context( node() );
updateLabel();
}

Gaffer::Dot *DotNodeGadget::dotNode()
{
return static_cast<Dot *>( node() );
Expand Down Expand Up @@ -186,13 +195,11 @@ void DotNodeGadget::updateLabel()
}
else
{
const auto script = dot->scriptNode();
const Context *context = script ? script->context() : nullptr;
Context::Scope scope( context );
Context::Scope scope( m_labelContext.get() );
m_label = dot->labelPlug()->getValue();
if( context )
if( m_labelContext )
{
m_label = context->substitute( m_label );
m_label = m_labelContext->substitute( m_label );
}
}
}
Expand Down

0 comments on commit 9599500

Please sign in to comment.