Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RenderPassEditor : Add Select Affected Objects to context menu #5899

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Improvements
------------

- ColorChooser : Added channel names to identify sliders.
- RenderPassEditor : Added "Select Affected Objects" popup menu item.

Fixes
-----
Expand Down
57 changes: 57 additions & 0 deletions python/GafferSceneUI/RenderPassEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,53 @@ def __disableEdits( self, pathListing ) :
if isinstance( source, ( Gaffer.TweakPlug, Gaffer.NameValuePlug ) ) :
source["enabled"].setValue( False )

def __selectedSetExpressions( self, pathListing ) :

# A dictionary of the form :
# { renderPass1 : set( setExpression1, setExpression2 ), renderPass2 : set( setExpression1 ), ... }
result = {}

renderPassPath = pathListing.getPath().copy()
for columnSelection, column in zip( pathListing.getSelection(), pathListing.getColumns() ) :
if (
not columnSelection.isEmpty() and (
not isinstance( column, _GafferSceneUI._RenderPassEditor.OptionInspectorColumn ) or
not (
Gaffer.Metadata.value( "option:" + column.inspector().name(), "ui:scene:acceptsSetName" ) or
Gaffer.Metadata.value( "option:" + column.inspector().name(), "ui:scene:acceptsSetNames" ) or
Gaffer.Metadata.value( "option:" + column.inspector().name(), "ui:scene:acceptsSetExpression" )
)
)
) :
# We only return set expressions if all selected paths are in
# columns that accept set names or set expressions.
return {}

for path in columnSelection.paths() :
renderPassPath.setFromString( path )
cellValue = column.cellData( renderPassPath ).value
if cellValue is not None :
result.setdefault( renderPassPath.property( "renderPassPath:name" ), set() ).add( cellValue )
else :
# We only return set expressions if all selected paths are render passes.
return {}

return result

def __selectAffected( self, pathListing ) :

result = IECore.PathMatcher()
johnhaddon marked this conversation as resolved.
Show resolved Hide resolved

with Gaffer.Context( self.getContext() ) as context :
for renderPass, setExpressions in self.__selectedSetExpressions( pathListing ).items() :
# Evaluate set expressions within their render pass in the context
# as set membership could vary based on the render pass.
context["renderPass"] = renderPass
for setExpression in setExpressions :
result.addPaths( GafferScene.SetAlgo.evaluateSetExpression( setExpression, self.__settingsNode["in"] ) )

GafferSceneUI.ContextAlgo.setSelectedPaths( self.getContext(), result )

def __buttonPress( self, pathListing, event ) :

if event.button != event.Buttons.Right or event.modifiers != event.Modifiers.None_ :
Expand Down Expand Up @@ -673,6 +720,16 @@ def __buttonPress( self, pathListing, event ) :
"shortCut" : "D",
}
)
if len( self.__selectedSetExpressions( pathListing ) ) > 0 :
menuDefinition.append(
"SelectAffectedObjectsDivider", { "divider" : True }
)
menuDefinition.append(
"Select Affected Objects",
{
"command" : functools.partial( self.__selectAffected, pathListing ),
}
)

self.__contextMenu = GafferUI.Menu( menuDefinition )
self.__contextMenu.popup( pathListing )
Expand Down
Loading