def nodeMenuCreateCommand( menu ) : nodeGraph = menu.ancestor( GafferUI.NodeGraph ) assert( nodeGraph is not None ) gadgetWidget = nodeGraph.graphGadgetWidget() graphGadget = nodeGraph.graphGadget() script = nodeGraph.scriptNode() with Gaffer.UndoScope( script ) : backdrop = Gaffer.Backdrop() Gaffer.NodeAlgo.applyUserDefaults( backdrop ) graphGadget.getRoot().addChild( backdrop ) if script.selection() : nodeGadget = graphGadget.nodeGadget( backdrop ) nodeGadget.frame( [ x for x in script.selection() ] ) else : menuPosition = menu.popupPosition( relativeTo = gadgetWidget ) nodePosition = gadgetWidget.getViewportGadget().rasterToGadgetSpace( imath.V2f( menuPosition.x, menuPosition.y ), gadget = graphGadget ).p0 graphGadget.setNodePosition( backdrop, imath.V2f( nodePosition.x, nodePosition.y ) ) return backdrop
def testBoundAccessors(self): b = Gaffer.Backdrop() g = GafferUI.BackdropNodeGadget(b) self.assertEqual(g.getBound(), imath.Box2f(imath.V2f(-10), imath.V2f(10))) g.setBound(imath.Box2f(imath.V2f(-1, -2), imath.V2f(3, 4))) self.assertEqual(g.getBound(), imath.Box2f(imath.V2f(-1, -2), imath.V2f(3, 4)))
def testCanPositionNodeWithinBackdrop( self ) : s = Gaffer.ScriptNode() s["b"] = Gaffer.Backdrop() s["n"] = Gaffer.Node() g = GafferUI.GraphGadget( s ) backdropBound = g.nodeGadget( s["b"] ).transformedBound( g ) fallbackPosition = IECore.V2f( backdropBound.center().x, backdropBound.center().y ) g.getLayout().positionNode( g, s["n"], fallbackPosition ) self.assertEqual( g.getNodePosition( s["n"] ), fallbackPosition )
def testNoExtraPlugsAfterCopyPaste(self): script = Gaffer.ScriptNode() script["b"] = Gaffer.Backdrop() script["n"] = Gaffer.Node() graphGadget = GafferUI.GraphGadget(script) backdropGadget = graphGadget.nodeGadget(script["b"]) self.assertIsInstance(backdropGadget, GafferUI.BackdropNodeGadget) backdropGadget.frame([script["n"]]) script.execute( script.serialise(filter=Gaffer.StandardSet([script["b"]]))) self.assertEqual(script["b1"].keys(), script["b"].keys())
def nodeMenuCreateCommand(menu): nodeGraph = menu.ancestor(GafferUI.NodeGraph) assert (nodeGraph is not None) script = nodeGraph.scriptNode() with Gaffer.UndoContext(script): backdrop = Gaffer.Backdrop() nodeGraph.graphGadget().getRoot().addChild(backdrop) if script.selection(): nodeGadget = nodeGraph.graphGadget().nodeGadget(backdrop) nodeGadget.frame([x for x in script.selection()]) return backdrop
def newBackdrop(parent, type_="default"): """ Creates a new backdrop, initializing it with default tile, width and color based on the supplied type_ - @see backdropDefaults. """ with Gaffer.UndoScope(parent.ancestor(Gaffer.ScriptNode)): b = Gaffer.Backdrop() b.addChild( Gaffer.Box2fPlug( "__uiBound", defaultValue=imath.Box2f(imath.V2f(-10, -10), imath.V2f(10, 10)), flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, )) conform(b, type_) parent.addChild(b) GafferUI.NodeEditor.acquire(b, floating=True) return b
def encloseSelectionWithBackdrop(parent, padding=2): """ Roughly encloses the selection in a backdrop node. If there are other backdrops in the selection, they will be re-layered on top of the new one. """ scriptNode = parent.ancestor(Gaffer.ScriptNode) or parent sel = scriptNode.selection() if len(sel) == 0: return with Gaffer.UndoScope(scriptNode): extents = imath.Box2f() extents.makeEmpty() color = None existingBackdrops = [] for s in sel: p = s["__uiPosition"].getValue() b = s["__uiBound"].getValue( ) if "__uiBound" in s else defaultNodeSize extents.extendBy(p + b.min()) extents.extendBy(p + b.max()) if isinstance(s, Gaffer.Backdrop): color = Gaffer.Metadata.value(s, "nodeGadget:color") existingBackdrops.append(s) extents.extendBy(extents.min() - imath.V2f(padding)) extents.extendBy(extents.max() + imath.V2f(padding)) # We need to remove the existing backdrops, add the underlying one # then add the old ones back, otherwise the new one will be on top for b in existingBackdrops: parent.removeChild(b) backdrop = Gaffer.Backdrop() backdrop["title"].setValue("") setColor(backdrop, color) backdrop.addChild( Gaffer.V2fPlug( "__uiPosition", defaultValue=imath.V2f(0, 0), flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, )) backdrop.addChild( Gaffer.Box2fPlug( "__uiBound", defaultValue=imath.Box2f(imath.V2f(-10, -10), imath.V2f(10, 10)), flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, )) backdrop["__uiPosition"].setValue(extents.min()) backdrop["__uiBound"].setValue( imath.Box2f(imath.V2f(0.0), extents.max() - extents.min())) parent.addChild(backdrop) for b in existingBackdrops: parent.addChild(b) return backdrop