Skip to content

Commit

Permalink
UVView, SceneView : Prefer ScriptNodeAlgo to ContextAlgo
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Sep 10, 2024
1 parent fb131f4 commit fc679f9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 54 deletions.
9 changes: 2 additions & 7 deletions include/GafferSceneUI/SceneView.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ class GAFFERSCENEUI_API SceneView : public GafferUI::View
static void registerRenderer( const std::string &name, const RendererSettingsCreator &settingsCreator );
static std::vector<std::string> registeredRenderers();

protected :

void contextChanged( const IECore::InternedString &name ) override;

private :

// The filter for a preprocessing node used to hide things.
Expand All @@ -120,12 +116,11 @@ class GAFFERSCENEUI_API SceneView : public GafferUI::View

Imath::Box3f framingBound() const;

void selectedPathsChanged();
void visibleSetChanged();
bool keyPress( GafferUI::GadgetPtr gadget, const GafferUI::KeyEvent &event );
void transferSelectionToContext();
void plugSet( Gaffer::Plug *plug );

Gaffer::Signals::ScopedConnection m_selectionChangedConnection;

SceneGadgetPtr m_sceneGadget;

/// \todo Refactor all these bolt-on classes to follow the model of
Expand Down
5 changes: 1 addition & 4 deletions include/GafferSceneUI/UVView.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ class GAFFERSCENEUI_API UVView : public GafferUI::View
using UVViewSignal = Gaffer::Signals::Signal<void (UVView *)>;
UVViewSignal &stateChangedSignal();

protected :

void contextChanged( const IECore::InternedString &name ) override;

private :

Gaffer::CompoundObjectPlug *texturesPlug();
Expand All @@ -114,6 +110,7 @@ class GAFFERSCENEUI_API UVView : public GafferUI::View
void plugDirtied( const Gaffer::Plug *plug );
void preRender();
void visibilityChanged();
void selectedPathsChanged();
void updateTextureGadgets( const IECore::ConstCompoundObjectPtr &textures );
void gadgetStateChanged( const GafferUI::Gadget *gadget, bool running );

Expand Down
54 changes: 23 additions & 31 deletions src/GafferSceneUI/SceneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include "GafferSceneUI/SceneView.h"

#include "GafferSceneUI/ContextAlgo.h"
#include "GafferSceneUI/ScriptNodeAlgo.h"

#include "GafferScene/AttributeQuery.h"
#include "GafferScene/CustomAttributes.h"
Expand Down Expand Up @@ -2053,6 +2053,11 @@ SceneView::SceneView( ScriptNodePtr scriptNode )

m_sceneGadget->setScene( preprocessedInPlug<ScenePlug>() );

// Connect to ScriptNodeAlgo for selection and visible set updates.

ScriptNodeAlgo::selectedPathsChangedSignal( scriptNode.get() ).connect( boost::bind( &SceneView::selectedPathsChanged, this ) );
ScriptNodeAlgo::visibleSetChangedSignal( scriptNode.get() ).connect( boost::bind( &SceneView::visibleSetChanged, this ) );

}

SceneView::~SceneView()
Expand Down Expand Up @@ -2130,25 +2135,6 @@ std::vector<std::string> SceneView::registeredRenderers()
return Renderer::registeredRenderers();
}

void SceneView::contextChanged( const IECore::InternedString &name )
{
if( ContextAlgo::affectsSelectedPaths( name ) )
{
m_sceneGadget->setSelection( ContextAlgo::getSelectedPaths( getContext() ) );
return;
}
else if( ContextAlgo::affectsVisibleSet( name ) )
{
m_sceneGadget->setVisibleSet( ContextAlgo::getVisibleSet( getContext() ) );
return;
}
else if( boost::starts_with( name.value(), "ui:" ) )
{
// ui context entries shouldn't affect computation.
return;
}
}

Imath::Box3f SceneView::framingBound() const
{
PathMatcher omitted;
Expand Down Expand Up @@ -2178,6 +2164,16 @@ Imath::Box3f SceneView::framingBound() const
return b;
}

void SceneView::selectedPathsChanged()
{
m_sceneGadget->setSelection( ScriptNodeAlgo::getSelectedPaths( scriptNode() ) );
}

void SceneView::visibleSetChanged()
{
m_sceneGadget->setVisibleSet( ScriptNodeAlgo::getVisibleSet( scriptNode() ) );
}

bool SceneView::keyPress( GafferUI::GadgetPtr gadget, const GafferUI::KeyEvent &event )
{
if( event.key == "Down" )
Expand Down Expand Up @@ -2240,13 +2236,9 @@ void SceneView::frame( const PathMatcher &filter, const Imath::V3f &direction )

void SceneView::expandSelection( size_t depth )
{
// Note that we are scoping this context when expandDescendants computes a new value for the expanded paths.
// This could result in unnecessary cache misses due to changing the context entry, but it's OK because the
// selected paths is a "ui:" prefixed context variable, and Context is hardcoded to ignore variables with
// this prefix during hashing
Context::Scope scope( getContext() );
PathMatcher selection = ContextAlgo::expandDescendants( getContext(), m_sceneGadget->getSelection(), preprocessedInPlug<ScenePlug>(), depth - 1 );
ContextAlgo::setSelectedPaths( getContext(), selection );
PathMatcher selection = ScriptNodeAlgo::expandDescendantsInVisibleSet( scriptNode(), m_sceneGadget->getSelection(), preprocessedInPlug<ScenePlug>(), depth - 1 );
ScriptNodeAlgo::setSelectedPaths( scriptNode(), selection );
}

void SceneView::collapseSelection()
Expand All @@ -2257,25 +2249,25 @@ void SceneView::collapseSelection()
return;
}

PathMatcher expanded = ContextAlgo::getExpandedPaths( getContext() );
VisibleSet visibleSet = ScriptNodeAlgo::getVisibleSet( scriptNode() );

for( PathMatcher::Iterator it = selection.begin(), eIt = selection.end(); it != eIt; ++it )
{
if( !expanded.removePath( *it ) )
if( !visibleSet.expansions.removePath( *it ) )
{
if( it->size() <= 1 )
{
continue;
}
selection.removePath( *it );
ScenePlug::ScenePath parentPath( it->begin(), it->end() - 1 );
expanded.removePath( parentPath );
visibleSet.expansions.removePath( parentPath );
selection.addPath( parentPath );
}
}

ContextAlgo::setExpandedPaths( getContext(), expanded );
ContextAlgo::setSelectedPaths( getContext(), selection );
ScriptNodeAlgo::setVisibleSet( scriptNode(), visibleSet );
ScriptNodeAlgo::setSelectedPaths( scriptNode(), selection );
}

void SceneView::plugSet( Gaffer::Plug *plug )
Expand Down
22 changes: 10 additions & 12 deletions src/GafferSceneUI/UVView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

#include "GafferSceneUI/UVView.h"

#include "GafferSceneUI/ContextAlgo.h"
#include "GafferSceneUI/SceneGadget.h"
#include "GafferSceneUI/ScriptNodeAlgo.h"

#include "GafferScene/Isolate.h"
#include "GafferScene/PathFilter.h"
Expand Down Expand Up @@ -613,6 +613,7 @@ UVView::UVView( Gaffer::ScriptNodePtr scriptNode )
plugDirtiedSignal().connect( boost::bind( &UVView::plugDirtied, this, ::_1 ) );
viewportGadget()->preRenderSignal().connect( boost::bind( &UVView::preRender, this ) );
viewportGadget()->visibilityChangedSignal().connect( boost::bind( &UVView::visibilityChanged, this ) );
ScriptNodeAlgo::selectedPathsChangedSignal( scriptNode.get() ).connect( boost::bind( &UVView::selectedPathsChanged, this ) );
}

UVView::~UVView()
Expand All @@ -632,17 +633,6 @@ void UVView::setContext( Gaffer::ContextPtr context )
}
}

void UVView::contextChanged( const IECore::InternedString &name )
{
if( ContextAlgo::affectsSelectedPaths( name ) )
{
const PathMatcher paths = ContextAlgo::getSelectedPaths( getContext() );
StringVectorDataPtr data = new StringVectorData;
paths.paths( data->writable() );
uvScene()->visiblePathsPlug()->setValue( data );
}
}

// We're accessing plugs by name rather than by index to allow for
// plugs added by bolt-on components like DisplayTransform. This is
// OK because none of our accessors are performance critical.
Expand Down Expand Up @@ -807,6 +797,14 @@ void UVView::visibilityChanged()
}
}

void UVView::selectedPathsChanged()
{
const PathMatcher paths = ScriptNodeAlgo::getSelectedPaths( scriptNode() );
StringVectorDataPtr data = new StringVectorData;
paths.paths( data->writable() );
uvScene()->visiblePathsPlug()->setValue( data );
}

void UVView::updateTextureGadgets( const IECore::ConstCompoundObjectPtr &textures )
{
m_textureGadgetsDirty = false;
Expand Down

0 comments on commit fc679f9

Please sign in to comment.