From 990c78e7efecc8f855a2dcd5b3060339a26dc3bb Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 14 Oct 2014 14:19:20 +0100 Subject: [PATCH] Added Group::nextInPlug() method. Fixes #1036. --- include/GafferScene/Group.h | 9 ++++ include/GafferSceneBindings/GroupBinding.h | 47 ++++++++++++++++++ python/GafferSceneTest/GroupTest.py | 19 ++++++++ src/GafferScene/Group.cpp | 10 ++++ src/GafferSceneBindings/GroupBinding.cpp | 54 +++++++++++++++++++++ src/GafferSceneModule/GafferSceneModule.cpp | 4 +- 6 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 include/GafferSceneBindings/GroupBinding.h create mode 100644 src/GafferSceneBindings/GroupBinding.cpp diff --git a/include/GafferScene/Group.h b/include/GafferScene/Group.h index d2bdca0156f..4e8c0c7886f 100644 --- a/include/GafferScene/Group.h +++ b/include/GafferScene/Group.h @@ -56,6 +56,15 @@ class Group : public SceneProcessor IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferScene::Group, GroupTypeId, SceneProcessor ); + /// The Group adds new input plugs as needed as the existing + /// ones receive input connections. This method returns the + /// most recently added plug - the one that should be used + /// to connect a new input. + /// \todo If SceneProcessor::inPlug() was an ArrayPlug as + /// per #996, we wouldn't need this method. + ScenePlug *nextInPlug(); + const ScenePlug *nextInPlug() const; + Gaffer::StringPlug *namePlug(); const Gaffer::StringPlug *namePlug() const; diff --git a/include/GafferSceneBindings/GroupBinding.h b/include/GafferSceneBindings/GroupBinding.h new file mode 100644 index 00000000000..f3777cd6ad3 --- /dev/null +++ b/include/GafferSceneBindings/GroupBinding.h @@ -0,0 +1,47 @@ +////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2014, Image Engine Design Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above +// copyright notice, this list of conditions and the following +// disclaimer. +// +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided with +// the distribution. +// +// * Neither the name of John Haddon nor the names of +// any other contributors to this software may be used to endorse or +// promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////// + +#ifndef GAFFERSCENEBINDINGS_GROUPBINDING_H +#define GAFFERSCENEBINDINGS_GROUPBINDING_H + +namespace GafferSceneBindings +{ + +void bindGroup(); + +} // namespace GafferSceneBindings + +#endif // GAFFERSCENEBINDINGS_GROUPBINDING_H diff --git a/python/GafferSceneTest/GroupTest.py b/python/GafferSceneTest/GroupTest.py index cbe7ca59a5a..dfd1ce05b85 100644 --- a/python/GafferSceneTest/GroupTest.py +++ b/python/GafferSceneTest/GroupTest.py @@ -709,6 +709,25 @@ def testDifferentSetsInEachInput( self ) : } ) ) + def testNextInPlug( self ) : + + g = GafferScene.Group() + self.assertTrue( g.nextInPlug().isSame( g["in"] ) ) + + p = GafferScene.Plane() + g["in"].setInput( p["out"] ) + self.assertTrue( g.nextInPlug().isSame( g["in1"] ) ) + + g["in"].setInput( None ) + self.assertTrue( g.nextInPlug().isSame( g["in"] ) ) + + g["in"].setInput( p["out"] ) + g["in1"].setInput( p["out"] ) + self.assertTrue( g.nextInPlug().isSame( g["in2"] ) ) + + g["in"].setInput( None ) + self.assertTrue( g.nextInPlug().isSame( g["in2"] ) ) + def setUp( self ) : self.__originalCacheMemoryLimit = Gaffer.ValuePlug.getCacheMemoryLimit() diff --git a/src/GafferScene/Group.cpp b/src/GafferScene/Group.cpp index 313ecd5d69a..38301369aa2 100644 --- a/src/GafferScene/Group.cpp +++ b/src/GafferScene/Group.cpp @@ -76,6 +76,16 @@ Group::~Group() { } +ScenePlug *Group::nextInPlug() +{ + return m_inPlugs.inputs().back().get(); +} + +const ScenePlug *Group::nextInPlug() const +{ + return m_inPlugs.inputs().back().get(); +} + Gaffer::StringPlug *Group::namePlug() { return getChild( g_firstPlugIndex ); diff --git a/src/GafferSceneBindings/GroupBinding.cpp b/src/GafferSceneBindings/GroupBinding.cpp new file mode 100644 index 00000000000..dbaa69b18c9 --- /dev/null +++ b/src/GafferSceneBindings/GroupBinding.cpp @@ -0,0 +1,54 @@ +////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2014, Image Engine Design Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above +// copyright notice, this list of conditions and the following +// disclaimer. +// +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided with +// the distribution. +// +// * Neither the name of John Haddon nor the names of +// any other contributors to this software may be used to endorse or +// promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////// + +#include "boost/python.hpp" + +#include "GafferBindings/DependencyNodeBinding.h" + +#include "GafferScene/Group.h" + +#include "GafferSceneBindings/GroupBinding.h" + +using namespace boost::python; +using namespace IECorePython; +using namespace GafferScene; + +void GafferSceneBindings::bindGroup() +{ + GafferBindings::DependencyNodeClass() + .def( "nextInPlug", (ScenePlug *(Group::*)())&Group::nextInPlug, return_value_policy() ) + ; +} diff --git a/src/GafferSceneModule/GafferSceneModule.cpp b/src/GafferSceneModule/GafferSceneModule.cpp index 092bddb48af..fc45b3e21e4 100644 --- a/src/GafferSceneModule/GafferSceneModule.cpp +++ b/src/GafferSceneModule/GafferSceneModule.cpp @@ -48,7 +48,6 @@ #include "GafferScene/PrimitiveVariableProcessor.h" #include "GafferScene/DeletePrimitiveVariables.h" #include "GafferScene/MeshType.h" -#include "GafferScene/Group.h" #include "GafferScene/Plane.h" #include "GafferScene/Seeds.h" #include "GafferScene/Instancer.h" @@ -94,6 +93,7 @@ #include "GafferSceneBindings/CoordinateSystemBinding.h" #include "GafferSceneBindings/DeleteGlobalsBinding.h" #include "GafferSceneBindings/ExternalProceduralBinding.h" +#include "GafferSceneBindings/GroupBinding.h" using namespace boost::python; using namespace GafferScene; @@ -112,7 +112,6 @@ BOOST_PYTHON_MODULE( _GafferScene ) GafferBindings::DependencyNodeClass(); GafferBindings::DependencyNodeClass(); GafferBindings::DependencyNodeClass(); - GafferBindings::DependencyNodeClass(); GafferBindings::DependencyNodeClass(); GafferBindings::DependencyNodeClass(); GafferBindings::DependencyNodeClass(); @@ -132,6 +131,7 @@ BOOST_PYTHON_MODULE( _GafferScene ) bindSceneProcedural(); bindShader(); bindOptions(); + bindGroup(); GafferBindings::DependencyNodeClass(); GafferBindings::DependencyNodeClass();