Skip to content

Commit

Permalink
StandardNodeGadget : Persistent nodule labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Nov 6, 2024
1 parent c5d6d2e commit 698abee
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Improvements
- Added `inactiveIds` plug for selecting primitive variables to disable some instances.
- Added support for 64 bit integer ids (matching what is loaded from USD).
- DeletePoints : Added modes for deleting points based on a list of ids.
- StandardNodeGadget : Added support for `nodeGadget:inputNoduleLabelsVisible` and `nodeGadget:outputNoduleLabelsVisible` for setting nodule labels always on or off. If the metadata entry is not set, labels will be visible only when they are hovered over.

Fixes
-----
Expand Down
2 changes: 2 additions & 0 deletions include/GafferUI/StandardNodeGadget.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class GAFFERUI_API StandardNodeGadget : public NodeGadget
bool dragMove( GadgetPtr gadget, const DragDropEvent &event );
bool dragLeave( GadgetPtr gadget, const DragDropEvent &event );
bool drop( GadgetPtr gadget, const DragDropEvent &event );
void noduleAdded( Nodule *nodule );

ConnectionCreator *closestDragDestination( const DragDropEvent &event ) const;

Expand All @@ -163,6 +164,7 @@ class GAFFERUI_API StandardNodeGadget : public NodeGadget
bool updateShape();
void updateFocusGadgetVisibility();
void updateTextDimming();
void updatePersistentNoduleLabels();

IE_CORE_FORWARDDECLARE( ErrorGadget );
ErrorGadget *errorGadget( bool createIfMissing = true );
Expand Down
42 changes: 42 additions & 0 deletions python/GafferUITest/StandardNodeGadgetTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,47 @@ def assertMinWidth( gadget, minWidth ) :
Gaffer.Metadata.deregisterValue( n, "nodeGadget:minWidth" )
assertMinWidth( g, 10.0 )

def testNoduleLabelVisibility( self ) :

n = Gaffer.Node()
n.addChild( Gaffer.FloatPlug( "fIn", direction = Gaffer.Plug.Direction.In ) )
n.addChild( Gaffer.FloatPlug( "fOut", direction = Gaffer.Plug.Direction.Out ) )
g = GafferUI.StandardNodeGadget( n )

fIn = g.nodule( n["fIn"] )
fOut = g.nodule( n["fOut"] )

self.assertFalse( fIn.getLabelVisible() )
self.assertFalse( fOut.getLabelVisible() )

Gaffer.Metadata.registerValue( Gaffer.Node, "nodeGadget:inputNoduleLabelsVisible", True )
self.assertTrue( fIn.getLabelVisible() )
self.assertFalse( fOut.getLabelVisible() )

Gaffer.Metadata.registerValue( Gaffer.Node, "nodeGadget:outputNoduleLabelsVisible", True )
self.assertTrue( fIn.getLabelVisible() )
self.assertTrue( fOut.getLabelVisible() )

n.addChild( Gaffer.IntPlug( "iIn", direction = Gaffer.Plug.Direction.In ) )
n.addChild( Gaffer.IntPlug( "iOut", direction = Gaffer.Plug.Direction.Out ) )

iIn = g.nodule( n["iIn"] )
iOut = g.nodule( n["iOut"] )

self.assertTrue( iIn.getLabelVisible() )
self.assertTrue( iOut.getLabelVisible() )

Gaffer.Metadata.registerValue( Gaffer.Node, "nodeGadget:inputNoduleLabelsVisible", False )
self.assertFalse( fIn.getLabelVisible() )
self.assertFalse( iIn.getLabelVisible() )
self.assertTrue( fOut.getLabelVisible() )
self.assertTrue( iOut.getLabelVisible() )

Gaffer.Metadata.registerValue( Gaffer.Node, "nodeGadget:outputNoduleLabelsVisible", False )
self.assertFalse( fIn.getLabelVisible() )
self.assertFalse( iIn.getLabelVisible() )
self.assertFalse( fOut.getLabelVisible() )
self.assertFalse( iOut.getLabelVisible() )

if __name__ == "__main__":
unittest.main()
107 changes: 96 additions & 11 deletions src/GafferUI/StandardNodeGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ static IECore::InternedString g_paddingKey( "nodeGadget:padding" );
static IECore::InternedString g_colorKey( "nodeGadget:color" );
static IECore::InternedString g_shapeKey( "nodeGadget:shape" );
static IECore::InternedString g_focusGadgetVisibleKey( "nodeGadget:focusGadgetVisible" );
static IECore::InternedString g_inputNoduleLabelsVisibleKey( "nodeGadget:inputNoduleLabelsVisible" );
static IECore::InternedString g_outputNoduleLabelsVisibleKey( "nodeGadget:outputNoduleLabelsVisible" );
static IECore::InternedString g_iconKey( "icon" );
static IECore::InternedString g_iconScaleKey( "iconScale" );
static IECore::InternedString g_errorGadgetName( "__error" );
Expand Down Expand Up @@ -700,6 +702,7 @@ StandardNodeGadget::StandardNodeGadget( Gaffer::NodePtr node, bool auxiliary )
dragMoveSignal().connect( boost::bind( &StandardNodeGadget::dragMove, this, ::_1, ::_2 ) );
dragLeaveSignal().connect( boost::bind( &StandardNodeGadget::dragLeave, this, ::_1, ::_2 ) );
dropSignal().connect( boost::bind( &StandardNodeGadget::drop, this, ::_1, ::_2 ) );
noduleAddedSignal().connect( boost::bind( &StandardNodeGadget::noduleAdded, this, ::_2 ) );

for( int e = FirstEdge; e <= LastEdge; e++ )
{
Expand All @@ -722,6 +725,7 @@ StandardNodeGadget::StandardNodeGadget( Gaffer::NodePtr node, bool auxiliary )
updateIcon();
updateShape();
updateFocusGadgetVisibility();
updatePersistentNoduleLabels();
}

StandardNodeGadget::~StandardNodeGadget()
Expand Down Expand Up @@ -1133,9 +1137,24 @@ void StandardNodeGadget::enter( Gadget *gadget )
{
if( m_labelsVisibleOnHover )
{
IECore::ConstBoolDataPtr inputVisibleData = Gaffer::Metadata::value<IECore::BoolData>( node(), g_inputNoduleLabelsVisibleKey );
IECore::ConstBoolDataPtr outputVisibleData = Gaffer::Metadata::value<IECore::BoolData>( node(), g_outputNoduleLabelsVisibleKey );

for( StandardNodule::RecursiveIterator it( gadget ); !it.done(); ++it )
{
(*it)->setLabelVisible( true );
if(
(
(*it)->plug()->direction() == Plug::Direction::In &&
( !inputVisibleData || inputVisibleData->readable() )
) ||
(
(*it)->plug()->direction() == Plug::Direction::Out &&
( !outputVisibleData || outputVisibleData->readable() )
)
)
{
(*it)->setLabelVisible( true );
}
}
}
}
Expand All @@ -1144,9 +1163,24 @@ void StandardNodeGadget::leave( Gadget *gadget )
{
if( m_labelsVisibleOnHover )
{
IECore::ConstBoolDataPtr inputVisibleData = Gaffer::Metadata::value<IECore::BoolData>( node(), g_inputNoduleLabelsVisibleKey );
IECore::ConstBoolDataPtr outputVisibleData = Gaffer::Metadata::value<IECore::BoolData>( node(), g_outputNoduleLabelsVisibleKey );

for( StandardNodule::RecursiveIterator it( gadget ); !it.done(); ++it )
{
(*it)->setLabelVisible( false );
if(
(
(*it)->plug()->direction() == Plug::Direction::In &&
( !inputVisibleData || !inputVisibleData->readable() )
) ||
(
(*it)->plug()->direction() == Plug::Direction::Out &&
( !outputVisibleData || !outputVisibleData->readable() )
)
)
{
(*it)->setLabelVisible( false );
}
}
}
}
Expand All @@ -1158,10 +1192,20 @@ bool StandardNodeGadget::dragEnter( GadgetPtr gadget, const DragDropEvent &event
{
// Display the labels for all the compatible nodules so the
// user can see their options.
IECore::ConstBoolDataPtr inputVisibleData = Gaffer::Metadata::value<IECore::BoolData>( node(), g_inputNoduleLabelsVisibleKey );
IECore::ConstBoolDataPtr outputVisibleData = Gaffer::Metadata::value<IECore::BoolData>( node(), g_outputNoduleLabelsVisibleKey );

for( StandardNodule::RecursiveIterator it( this ); !it.done(); ++it )
{
(*it)->setLabelVisible( canConnect( event, it->get() ) );
if(
( (*it)->plug()->direction() == Plug::Direction::In && !inputVisibleData ) ||
( (*it)->plug()->direction() == Plug::Direction::Out && !outputVisibleData )
)
{
(*it)->setLabelVisible( canConnect( event, it->get() ) );
}
}

return true;
}

Expand Down Expand Up @@ -1202,10 +1246,7 @@ bool StandardNodeGadget::dragLeave( GadgetPtr gadget, const DragDropEvent &event
if( m_dragDestination != event.destinationGadget )
{
m_dragDestination->setHighlighted( false );
for( StandardNodule::RecursiveIterator it( this ); !it.done(); ++it )
{
(*it)->setLabelVisible( false );
}
updatePersistentNoduleLabels();
}
m_dragDestination = nullptr;

Expand All @@ -1222,14 +1263,32 @@ bool StandardNodeGadget::drop( GadgetPtr gadget, const DragDropEvent &event )
connect( event, m_dragDestination );

m_dragDestination->setHighlighted( false );
for( StandardNodule::RecursiveIterator it( this ); !it.done(); ++it )
{
(*it)->setLabelVisible( false );
}
updatePersistentNoduleLabels();

m_dragDestination = nullptr;
return true;
}

void StandardNodeGadget::noduleAdded( Nodule *nodule )
{
if( auto standardNodule = IECore::runTimeCast<StandardNodule>( nodule ) )
{
bool inputVisible = false;
bool outputVisible = false;

if( IECore::ConstBoolDataPtr visibleData = Gaffer::Metadata::value<IECore::BoolData>( node(), g_inputNoduleLabelsVisibleKey ) )
{
inputVisible = visibleData->readable();
}
if( IECore::ConstBoolDataPtr visibleData = Gaffer::Metadata::value<IECore::BoolData>( node(), g_outputNoduleLabelsVisibleKey ) )
{
outputVisible = visibleData->readable();
}

standardNodule->setLabelVisible( standardNodule->plug()->direction() == Plug::Direction::In ? inputVisible : outputVisible );
}
}

ConnectionCreator *StandardNodeGadget::closestDragDestination( const DragDropEvent &event ) const
{
if( event.buttons != DragDropEvent::Left )
Expand Down Expand Up @@ -1303,6 +1362,10 @@ void StandardNodeGadget::nodeMetadataChanged( IECore::InternedString key )
{
updateFocusGadgetVisibility();
}
else if( key == g_inputNoduleLabelsVisibleKey || key == g_outputNoduleLabelsVisibleKey )
{
updatePersistentNoduleLabels();
}
}

bool StandardNodeGadget::updateUserColor()
Expand Down Expand Up @@ -1464,6 +1527,28 @@ void StandardNodeGadget::updateFocusGadgetVisibility()
m_focusGadget->setVisible( !d || d->readable() );
}

void StandardNodeGadget::updatePersistentNoduleLabels()
{
bool inputVisible = false;
if( IECore::ConstBoolDataPtr d = Gaffer::Metadata::value<IECore::BoolData>( node(), g_inputNoduleLabelsVisibleKey ) )
{
inputVisible = d->readable();
}

bool outputVisible = false;
if( IECore::ConstBoolDataPtr d = Gaffer::Metadata::value<IECore::BoolData>( node(), g_outputNoduleLabelsVisibleKey ) )
{
outputVisible = d->readable();
}

for( StandardNodule::RecursiveIterator it( this ); !it.done(); ++it )
{
(*it)->setLabelVisible(
(*it)->plug()->direction() == Plug::Direction::In ? inputVisible : outputVisible
);
}
}

StandardNodeGadget::ErrorGadget *StandardNodeGadget::errorGadget( bool createIfMissing )
{
if( ErrorGadget *result = getChild<ErrorGadget>( g_errorGadgetName ) )
Expand Down
14 changes: 13 additions & 1 deletion src/GafferUI/StandardNodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Nodule::NoduleTypeDescription<StandardNodule> StandardNodule::g_noduleTypeDescri

static IECore::InternedString g_colorKey( "nodule:color" );
static IECore::InternedString g_labelKey( "noduleLayout:label" );
static IECore::InternedString g_inputNoduleLabelsVisibleKey( "nodeGadget:inputNoduleLabelsVisible" );
static IECore::InternedString g_outputNoduleLabelsVisibleKey( "nodeGadget:outputNoduleLabelsVisible" );

StandardNodule::StandardNodule( Gaffer::PlugPtr plug )
: Nodule( plug ), m_labelVisible( false ), m_draggingConnection( false )
Expand Down Expand Up @@ -465,11 +467,21 @@ void StandardNodule::setCompatibleLabelsVisible( const DragDropEvent &event, boo
return;
}

IECore::ConstBoolDataPtr inputVisibleData = Gaffer::Metadata::value<IECore::BoolData>( nodeGadget->node(), g_inputNoduleLabelsVisibleKey );
IECore::ConstBoolDataPtr outputVisibleData = Gaffer::Metadata::value<IECore::BoolData>( nodeGadget->node(), g_outputNoduleLabelsVisibleKey );

for( StandardNodule::RecursiveIterator it( nodeGadget ); !it.done(); ++it )
{
if( creator->canCreateConnection( it->get()->plug() ) )
{
(*it)->setLabelVisible( visible );
if( it->get()->plug()->direction() == Plug::Direction::In )
{
(*it)->setLabelVisible( !inputVisibleData ? visible : inputVisibleData->readable() );
}
if( it->get()->plug()->direction() == Plug::Direction::Out )
{
(*it)->setLabelVisible( !outputVisibleData ? visible : outputVisibleData->readable() );
}
}
}
}
Expand Down

0 comments on commit 698abee

Please sign in to comment.