Skip to content

Commit

Permalink
Merge pull request #6021 from johnhaddon/scriptNodeAlgoPrecursorPR
Browse files Browse the repository at this point in the history
Miscellaneous ScriptNodeAlgo precursor work
  • Loading branch information
johnhaddon authored Sep 2, 2024
2 parents 149c7e6 + e10b34b commit e4f7574
Show file tree
Hide file tree
Showing 57 changed files with 368 additions and 364 deletions.
6 changes: 6 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ API
- PlugValueWidget :
- A `DeprecationWarning` is now emitted for any subclasses still implementing the legacy `_updateFromPlug()` or `_updateFromPlugs()` methods. Implement `_updateFromValues()`, `_updateFromMetadata()` and `_updateFromEditable()` instead.
- A `DeprecationWarning` is now emitted by `_plugConnections()`. Use `_blockedUpdateFromValues()` instead.
- Added `scriptNode()` convenience method.
- NodeGadget, ConnectionGadget : Added `updateFromContextTracker()` virtual methods.
- Path : Added `inspectionContext()` virtual method.
- PathColumn :
Expand All @@ -58,6 +59,7 @@ API
- ArrayPlug :
- It is now legal to construct an ArrayPlug with a minimum size of 0. Previously the minimum size was 1.
- Added `elementPrototype()` method.
- View : Added `scriptNode()` method.

Breaking Changes
----------------
Expand All @@ -79,6 +81,10 @@ Breaking Changes
- ArrayPlug :
- Renamed `element` constructor argument to `elementPrototype`.
- Deprecated the passing of `element = nullptr` to the constructor.
- View :
- Changed constructor arguments for View and all subclasses. A ScriptNode must now be passed.
- Changed `ViewCreator` signature.
- LightTool : Removed `selection()` and `selectionChangedSignal()`.

Build
-----
Expand Down
2 changes: 1 addition & 1 deletion include/GafferImageUI/ImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class GAFFERIMAGEUI_API ImageView : public GafferUI::View

public :

explicit ImageView( const std::string &name = defaultName<ImageView>() );
explicit ImageView( Gaffer::ScriptNodePtr scriptNode );
~ImageView() override;

GAFFER_NODE_DECLARE_TYPE( GafferImageUI::ImageView, ImageViewTypeId, GafferUI::View );
Expand Down
8 changes: 0 additions & 8 deletions include/GafferSceneUI/LightTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ class GAFFERSCENEUI_API LightTool : public GafferSceneUI::SelectionTool

GAFFER_NODE_DECLARE_TYPE( GafferSceneUI::LightTool, LightToolTypeId, SelectionTool );

const IECore::PathMatcher selection() const;

using SelectionChangedSignal = Gaffer::Signals::Signal<void (LightTool &)>;
SelectionChangedSignal &selectionChangedSignal();

private :

GafferScene::ScenePlug *scenePlug();
Expand All @@ -96,10 +91,7 @@ class GAFFERSCENEUI_API LightTool : public GafferSceneUI::SelectionTool

bool m_priorityPathsDirty;

SelectionChangedSignal m_selectionChangedSignal;

bool m_dragging;
Gaffer::ScriptNodePtr m_scriptNode;

Gaffer::Signals::ScopedConnection m_contextChangedConnection;
Gaffer::Signals::ScopedConnection m_preRenderConnection;
Expand Down
2 changes: 1 addition & 1 deletion include/GafferSceneUI/SceneView.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GAFFERSCENEUI_API SceneView : public GafferUI::View

public :

explicit SceneView( const std::string &name = defaultName<SceneView>() );
explicit SceneView( Gaffer::ScriptNodePtr scriptNode );
~SceneView() override;

GAFFER_NODE_DECLARE_TYPE( GafferSceneUI::SceneView, SceneViewTypeId, GafferUI::View );
Expand Down
2 changes: 1 addition & 1 deletion include/GafferSceneUI/ShaderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GAFFERSCENEUI_API ShaderView : public GafferImageUI::ImageView

public :

explicit ShaderView( const std::string &name = defaultName<ShaderView>() );
explicit ShaderView( Gaffer::ScriptNodePtr scriptNode );
~ShaderView() override;

GAFFER_NODE_DECLARE_TYPE( GafferSceneUI::ShaderView, ShaderViewTypeId, GafferImageUI::ImageView );
Expand Down
2 changes: 1 addition & 1 deletion include/GafferSceneUI/UVView.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GAFFERSCENEUI_API UVView : public GafferUI::View

public :

explicit UVView( const std::string &name = defaultName<UVView>() );
explicit UVView( Gaffer::ScriptNodePtr scriptNode );
~UVView() override;

GAFFER_NODE_DECLARE_TYPE( GafferSceneUI::UVView, UVViewTypeId, View );
Expand Down
13 changes: 10 additions & 3 deletions include/GafferUI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class GAFFERUI_API View : public Gaffer::Node
template<typename T=Gaffer::Plug>
const T *inPlug() const;

/// Returns the ScriptNode this view was created for.
Gaffer::ScriptNode *scriptNode();
const Gaffer::ScriptNode *scriptNode() const;

/// The current EditScope for the view is specified by connecting
/// an `EditScope::outPlug()` into this plug.
Gaffer::Plug *editScopePlug();
Expand Down Expand Up @@ -131,7 +135,7 @@ class GAFFERUI_API View : public Gaffer::Node
//@{
/// Creates a View for the specified plug.
static ViewPtr create( Gaffer::PlugPtr input );
using ViewCreator = std::function<ViewPtr ( Gaffer::PlugPtr )>;
using ViewCreator = std::function<ViewPtr ( Gaffer::ScriptNodePtr )>;
/// Registers a function which will return a View instance for a
/// plug of a specific type.
static void registerView( IECore::TypeId plugType, ViewCreator creator );
Expand All @@ -147,7 +151,7 @@ class GAFFERUI_API View : public Gaffer::Node
/// class should construct a plug of a suitable type and pass it
/// to the View constructor. For instance, the SceneView will pass
/// a ScenePlug so that only scenes may be viewed.
View( const std::string &name, Gaffer::PlugPtr input );
View( const std::string &name, Gaffer::ScriptNodePtr scriptNode, Gaffer::PlugPtr input );

/// The View may want to perform preprocessing of the input before
/// displaying it, for instance by applying a LUT to an image. This
Expand Down Expand Up @@ -185,14 +189,17 @@ class GAFFERUI_API View : public Gaffer::Node
{
ViewDescription( IECore::TypeId plugType );
ViewDescription( IECore::TypeId nodeType, const std::string &plugPathRegex );
static ViewPtr creator( Gaffer::PlugPtr input );
};

bool acceptsInput( const Gaffer::Plug *plug, const Gaffer::Plug *inputPlug ) const override;

private :

void toolsChildAdded( Gaffer::GraphComponent *child );
void toolPlugSet( Gaffer::Plug *plug );

const Gaffer::ScriptNodePtr m_scriptNode;

using ToolPlugSetMap = std::unordered_map<Tool *, Gaffer::Signals::ScopedConnection>;
ToolPlugSetMap m_toolPlugSetConnections;

Expand Down
12 changes: 2 additions & 10 deletions include/GafferUI/View.inl
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,13 @@ T *View::preprocessedInPlug()
template<typename T>
View::ViewDescription<T>::ViewDescription( IECore::TypeId plugType )
{
View::registerView( plugType, &creator );
View::registerView( plugType, []( Gaffer::ScriptNodePtr script ) { return new T( script ); } );
}

template<typename T>
View::ViewDescription<T>::ViewDescription( const IECore::TypeId nodeType, const std::string &plugPathRegex )
{
View::registerView( nodeType, plugPathRegex, &creator );
View::registerView( nodeType, plugPathRegex, []( Gaffer::ScriptNodePtr script ) { return new T( script ); } );
}

template<typename T>
ViewPtr View::ViewDescription<T>::creator( Gaffer::PlugPtr input )
{
ViewPtr result = new T();
result->inPlug<Gaffer::Plug>()->setInput( input );
return result;
};

} // namespace GafferUI
4 changes: 2 additions & 2 deletions python/GafferImageUI/ChannelMaskPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ def menuItem( matchPattern ) :

def __setValue( self, unused, value ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
plug.setValue( value )

def __toggleCustom( self, checked ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
if not checked :
Gaffer.Metadata.deregisterValue( plug, self.__customMetadataName )
Expand Down
4 changes: 2 additions & 2 deletions python/GafferImageUI/ChannelPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ def __menuDefinition( self ) :

def __setValue( self, unused, value ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
plug.setValue( value )
Gaffer.Metadata.deregisterValue( plug, "channelPlugValueWidget:isCustom" )

def __applyCustom( self, unused ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
Gaffer.Metadata.registerValue( plug, "channelPlugValueWidget:isCustom", True )

Expand Down
4 changes: 2 additions & 2 deletions python/GafferImageUI/FormatPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ def __menuDefinition( self ) :

def __applyFormat( self, unused, fmt ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
Gaffer.Metadata.registerValue( plug, "formatPlugValueWidget:mode", "standard" )
plug.setValue( fmt )

def __applyCustomFormat( self, unused ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :

if self.__currentFormat == GafferImage.Format() :
# Format is empty. It's kindof confusing to display that
Expand Down
2 changes: 1 addition & 1 deletion python/GafferImageUI/RGBAChannelsPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ def _menuDefinition( self ) :

def __setValue( self, unused, value ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
plug.setValue( value )
2 changes: 1 addition & 1 deletion python/GafferImageUI/ViewPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ def _menuDefinition( self ) :

def __setValue( self, unused, value ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
plug.setValue( value )
23 changes: 12 additions & 11 deletions python/GafferImageUITest/ImageViewTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ class ImageViewTest( GafferUITest.TestCase ) :

def testFactory( self ) :

image = GafferImage.Constant()
view = GafferUI.View.create( image["out"] )
script = Gaffer.ScriptNode()
script["image"] = GafferImage.Constant()
view = GafferUI.View.create( script["image"]["out"] )

self.assertTrue( isinstance( view, GafferImageUI.ImageView ) )
self.assertTrue( view["in"].getInput().isSame( image["out"] ) )
self.assertTrue( view["in"].getInput().isSame( script["image"]["out"] ) )

def testDeriving( self ) :

class MyView( GafferImageUI.ImageView ) :

def __init__( self, viewedPlug = None ) :
def __init__( self, scriptNode ) :

GafferImageUI.ImageView.__init__( self, "MyView" )
GafferImageUI.ImageView.__init__( self, scriptNode )

converter = Gaffer.Node()
converter["in"] = Gaffer.StringPlug()
Expand All @@ -72,22 +73,22 @@ def __init__( self, viewedPlug = None ) :

self._insertConverter( converter )

self["in"].setInput( viewedPlug )

GafferUI.View.registerView( GafferTest.StringInOutNode, "out", MyView )

string = GafferTest.StringInOutNode()
script = Gaffer.ScriptNode()
script["string"] = GafferTest.StringInOutNode()

view = GafferUI.View.create( string["out"] )
view = GafferUI.View.create( script["string"]["out"] )
self.assertTrue( isinstance( view, MyView ) )
self.assertTrue( view["in"].getInput().isSame( string["out"] ) )
self.assertTrue( view["in"].getInput().isSame( script["string"]["out"] ) )
self.assertTrue( isinstance( view["in"], Gaffer.StringPlug ) )
view["displayTransform"]["exposure"].setValue( 1 )
view["displayTransform"]["gamma"].setValue( 0.5 )

def testImageGadget( self ) :

view = GafferImageUI.ImageView()
script = Gaffer.ScriptNode()
view = GafferImageUI.ImageView( script )
self.assertIsInstance( view.imageGadget(), GafferImageUI.ImageGadget )
self.assertTrue( view.viewportGadget().isAncestorOf( view.imageGadget() ) )

Expand Down
22 changes: 7 additions & 15 deletions python/GafferSceneUI/SceneHistoryUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,19 @@ def __hierarchyViewKeyPress( hierarchyView, event ) :

def __nodeEditorKeyPress( nodeEditor, event ) :

layout = nodeEditor.ancestor( GafferUI.CompoundEditor )
if layout is None :
focusNode = nodeEditor.scriptNode().getFocus()
if focusNode is None :
return False

## \todo In Gaffer 0.61, we should get the scene directly from the focus node.
scene = None
for hierarchyView in layout.editors( GafferSceneUI.HierarchyView ) :
if hierarchyView.scene() is not None :
scene = hierarchyView.scene()
break

if scene is None :
for viewer in layout.editors( GafferUI.Viewer ) :
if isinstance( viewer.view(), GafferSceneUI.SceneView ) :
scene = viewer.view()["in"]
break
scene = next(
( p for p in GafferScene.ScenePlug.RecursiveOutputRange( focusNode ) if not p.getName().startswith( "__" ) ),
None
)

if scene is None :
return False

context = layout.scriptNode().context()
context = nodeEditor.scriptNode().context()

if event == __editSourceKeyPress :
selectedPath = __contextSelectedPath( context )
Expand Down
2 changes: 1 addition & 1 deletion python/GafferSceneUI/SetExpressionPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def __setPlugValues( self, *unused ) :
return

text = self.__codeWidget.getText()
with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
plug.setValue( text )

Expand Down
2 changes: 1 addition & 1 deletion python/GafferSceneUI/ShaderUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _updateFromEditable( self ) :

def __reloadButtonClicked( self, button ) :

with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
plug.node().reloadShader()

Expand Down
2 changes: 1 addition & 1 deletion python/GafferSceneUI/StandardOptionsUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def __menuDefinition( self ) :
def __togglePurpose( self, checked, purpose ) :

with self.context() :
with Gaffer.UndoScope( next( iter( self.getPlugs() ) ).ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.scriptNode() ) :
for plug in self.getPlugs() :
value = plug.getValue()
# Conform value so that only valid purposes are present, and they are
Expand Down
2 changes: 1 addition & 1 deletion python/GafferSceneUI/UVInspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__( self, scriptNode, **kw ) :

GafferSceneUI.SceneEditor.__init__( self, column, scriptNode, **kw )

self.__uvView = GafferSceneUI.UVView()
self.__uvView = GafferSceneUI.UVView( scriptNode )
self.__uvView["in"].setInput( self.settings()["in"] )
Gaffer.NodeAlgo.applyUserDefaults( self.__uvView )
self.__uvView.setContext( self.context() )
Expand Down
Loading

0 comments on commit e4f7574

Please sign in to comment.