From 25166110367160996b55df7ab7e8b74b2b8f1333 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 6 Aug 2024 16:51:22 +0100 Subject: [PATCH 1/2] DotNodeGadget : Use ContextTracker to evaluate custom label This also fixes a bug where in the past we didn't update context-sensitive labels when the global context changed. --- Changes.md | 5 ++++- include/GafferUI/DotNodeGadget.h | 3 +++ src/GafferUI/DotNodeGadget.cpp | 19 +++++++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Changes.md b/Changes.md index 6a75fb00abc..2c044764140 100644 --- a/Changes.md +++ b/Changes.md @@ -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. @@ -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). diff --git a/include/GafferUI/DotNodeGadget.h b/include/GafferUI/DotNodeGadget.h index e58f31d277d..4a50aad3fec 100644 --- a/include/GafferUI/DotNodeGadget.h +++ b/include/GafferUI/DotNodeGadget.h @@ -43,6 +43,7 @@ namespace Gaffer { +IE_CORE_FORWARDDECLARE( Context ) IE_CORE_FORWARDDECLARE( Plug ) } // namespace Gaffer @@ -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 : @@ -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; diff --git a/src/GafferUI/DotNodeGadget.cpp b/src/GafferUI/DotNodeGadget.cpp index 06a35fe150e..19958d9834f 100644 --- a/src/GafferUI/DotNodeGadget.cpp +++ b/src/GafferUI/DotNodeGadget.cpp @@ -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() @@ -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( node() ); @@ -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 ); } } } From a3a76edf8a0119ede9459811c3dd5f49145d8612 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 7 Aug 2024 10:19:59 +0100 Subject: [PATCH 2/2] Context : Add clarifying comment --- include/Gaffer/Context.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/Gaffer/Context.h b/include/Gaffer/Context.h index c9842164aca..b9bf6ce713d 100644 --- a/include/Gaffer/Context.h +++ b/include/Gaffer/Context.h @@ -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();