Skip to content

Commit

Permalink
SetEditor : Add custom columns to display Members and Selection
Browse files Browse the repository at this point in the history
This is in order to define header and cell tooltips, maybe in the future we'll be able to do this directly for header tooltips via StandardPathColumn.
  • Loading branch information
murraystevenson authored and johnhaddon committed Dec 12, 2023
1 parent ef1e574 commit 6791bee
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/GafferSceneUI/SetEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def __init__( self, scriptNode, **kw ) :
GafferUI.BasicPathFilterWidget( emptySetFilter )
GafferUI.BasicPathFilterWidget( emptySelectionFilter )

self.__setMembersColumn = GafferUI.StandardPathColumn( "Members", "setPath:memberCount" )
self.__selectedSetMembersColumn = GafferUI.StandardPathColumn( "Selection", "setPath:selectedMemberCount" )
self.__setMembersColumn = _GafferSceneUI._SetEditor.SetMembersColumn()
self.__selectedSetMembersColumn = _GafferSceneUI._SetEditor.SetSelectionColumn()
self.__includedSetMembersColumn = _GafferSceneUI._SetEditor.VisibleSetInclusionsColumn( scriptNode.context() )
self.__excludedSetMembersColumn = _GafferSceneUI._SetEditor.VisibleSetExclusionsColumn( scriptNode.context() )
self.__pathListing = GafferUI.PathListingWidget(
Expand Down
96 changes: 96 additions & 0 deletions src/GafferSceneUIModule/SetEditorBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#include "boost/bind/bind.hpp"
#include "boost/container/flat_set.hpp"

#include "fmt/format.h"

using namespace std;
using namespace boost::placeholders;
using namespace boost::python;
Expand Down Expand Up @@ -432,6 +434,92 @@ class SetNameColumn : public StandardPathColumn

};

//////////////////////////////////////////////////////////////////////////
// SetMembersColumn
//////////////////////////////////////////////////////////////////////////

class SetMembersColumn : public StandardPathColumn
{

public :

IE_CORE_DECLAREMEMBERPTR( SetMembersColumn )

SetMembersColumn()
: StandardPathColumn( "Members", g_memberCountPropertyName )
{
}

CellData cellData( const Gaffer::Path &path, const IECore::Canceller *canceller ) const override
{
CellData result = StandardPathColumn::cellData( path, canceller );
if( const auto setName = runTimeCast<const IECore::StringData>( path.property( g_setNamePropertyName, canceller ) ) )
{
const auto memberCount = runTimeCast<const IECore::IntData>( path.property( g_memberCountPropertyName, canceller ) );
const auto count = memberCount ? memberCount->readable() : 0;
result.toolTip = new IECore::StringData(
fmt::format( "{} scene location{} of {}",
count, count == 1 ? " is a member" : "s are members", setName->readable()
)
);
}

return result;
}

CellData headerData( const IECore::Canceller *canceller ) const override
{
CellData result = StandardPathColumn::headerData( canceller );
result.toolTip = new IECore::StringData( "The number of scene locations that are set members" );

return result;
}

};

//////////////////////////////////////////////////////////////////////////
// SetSelectionColumn
//////////////////////////////////////////////////////////////////////////

class SetSelectionColumn : public StandardPathColumn
{

public :

IE_CORE_DECLAREMEMBERPTR( SetSelectionColumn )

SetSelectionColumn()
: StandardPathColumn( "Selection", g_selectedMemberCountPropertyName )
{
}

CellData cellData( const Gaffer::Path &path, const IECore::Canceller *canceller ) const override
{
CellData result = StandardPathColumn::cellData( path, canceller );
if( const auto setName = runTimeCast<const IECore::StringData>( path.property( g_setNamePropertyName, canceller ) ) )
{
const auto selectedMemberCount = runTimeCast<const IECore::IntData>( path.property( g_selectedMemberCountPropertyName, canceller ) );
const auto count = selectedMemberCount ? selectedMemberCount->readable() : 0;
result.toolTip = new IECore::StringData(
fmt::format( "{} selected scene location{} of {}",
count, count == 1 ? " is a member or descendant" : "s are members and/or descendants", setName->readable()
)
);
}

return result;
}

CellData headerData( const IECore::Canceller *canceller ) const override
{
CellData result = StandardPathColumn::headerData( canceller );
result.toolTip = new IECore::StringData( "The number of selected scene locations that are set members, or their descendants" );

return result;
}

};

//////////////////////////////////////////////////////////////////////////
// VisibleSetInclusionsColumn - displays and modifies inclusions membership
// of the VisibleSet in the provided context.
Expand Down Expand Up @@ -1060,6 +1148,14 @@ void GafferSceneUIModule::bindSetEditor()
.def( init<>() )
;

RefCountedClass<SetMembersColumn, GafferUI::PathColumn>( "SetMembersColumn" )
.def( init<>() )
;

RefCountedClass<SetSelectionColumn, GafferUI::PathColumn>( "SetSelectionColumn" )
.def( init<>() )
;

RefCountedClass<VisibleSetInclusionsColumn, GafferUI::PathColumn>( "VisibleSetInclusionsColumn" )
.def( init< ContextPtr >() )
;
Expand Down

0 comments on commit 6791bee

Please sign in to comment.