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

Viewer grid #854

Merged
merged 7 commits into from
Jun 10, 2014
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
6 changes: 6 additions & 0 deletions include/GafferSceneUI/SceneView.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class SceneView : public GafferUI::View3D
Gaffer::StringPlug *lookThroughCameraPlug();
const Gaffer::StringPlug *lookThroughCameraPlug() const;

Gaffer::CompoundPlug *gridPlug();
const Gaffer::CompoundPlug *gridPlug() const;

void expandSelection( size_t depth = 1 );
void collapseSelection();

Expand Down Expand Up @@ -104,6 +107,9 @@ class SceneView : public GafferUI::View3D

GafferUI::RenderableGadgetPtr m_renderableGadget;

class Grid;
boost::shared_ptr<Grid> m_grid;

static size_t g_firstPlugIndex;
static ViewDescription<SceneView> g_viewDescription;

Expand Down
29 changes: 12 additions & 17 deletions include/GafferUI/ContainerGadget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011-2012, John Haddon. All rights reserved.
// Copyright (c) 2011-2014, John Haddon. All rights reserved.
// Copyright (c) 2012, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -43,6 +43,13 @@
namespace GafferUI
{

/// Provides a useful base class for gadgets which are intended
/// primarily to provide layouts of child Gadgets. Note that any
/// Gadget can have children though.
/// \todo Consider a virtual method which is called to compute
/// the transforms for children when they have been dirtied. This would
/// simplify derived classes and provide greater justification for the
/// existence of this base class.
class ContainerGadget : public Gadget
{

Expand All @@ -52,31 +59,19 @@ class ContainerGadget : public Gadget
virtual ~ContainerGadget();

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferUI::ContainerGadget, ContainerGadgetTypeId, Gadget );

/// ContainerGadgets accept any number of other Gadgets as children. Derived classes
/// may further restrict this if they wish, but they must not accept non-Gadget children.
virtual bool acceptsChild( const Gaffer::GraphComponent *potentialChild ) const;
/// Returns the union of the transformed bounding boxes of all children.
virtual Imath::Box3f bound() const;
//@}

/// The padding is a region added around the contents of the children.
/// It is specified as the final bounding box when the child bounding
/// box is ( ( 0, 0, 0 ), ( 0, 0, 0 ) ). That is, padding.min is added to bound.min
/// and padding.max is added to bound.max.
void setPadding( const Imath::Box3f &padding );
const Imath::Box3f &getPadding() const;

protected :

/// Implemented to render all the children.
virtual void doRender( const Style *style ) const;

/// Applies the padding to the default union-of-children
/// bounding box.
virtual Imath::Box3f bound() const;

private :

void childAdded( GraphComponent *parent, GraphComponent *child );
void childRemoved( GraphComponent *parent, GraphComponent *child );
void childRenderRequest( Gadget *child );

Imath::Box3f m_padding;

Expand Down
37 changes: 25 additions & 12 deletions include/GafferUI/Gadget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011-2013, John Haddon. All rights reserved.
// Copyright (c) 2011-2014, John Haddon. All rights reserved.
// Copyright (c) 2011-2012, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -69,8 +69,6 @@ IE_CORE_FORWARDDECLARE( Style );
/// Gadgets are zoomable UI elements. They draw themselves using OpenGL, and provide an interface for
/// handling events. To present a Gadget in the user interface, it should be placed in the viewport of
/// a GadgetWidget.
/// \todo I'm not sure I like having the transform on the Gadget - perhaps ContainerGadget
/// should have a virtual childTransform() method instead?
class Gadget : public Gaffer::GraphComponent
{

Expand All @@ -89,8 +87,8 @@ class Gadget : public Gaffer::GraphComponent
/// @name Parent-child relationships
////////////////////////////////////////////////////////////////////
//@{
/// By default Gadgets do not accept children. Derive from ContainerGadget
/// if you wish to accept children.
/// Gadgets accept any number of other Gadgets as children. Derived classes
/// may further restrict this if they wish, but they must not accept non-Gadget children.
virtual bool acceptsChild( const Gaffer::GraphComponent *potentialChild ) const;
/// Gadgets only accept other Gadgets as parent.
virtual bool acceptsParent( const Gaffer::GraphComponent *potentialParent ) const;
Expand All @@ -115,10 +113,19 @@ class Gadget : public Gaffer::GraphComponent
//@}

/// @name State
/// \todo Add setEnabled()/getEnabled() and setVisible()/getVisible()
/// methods matching those we have on the Widget class.
/// \todo Add setEnabled()/getEnabled() methods matching those we
/// have on the Widget class.
////////////////////////////////////////////////////////////////////
//@{
/// Sets the visibility status for this Gadget. Note that even if this
/// Gadget has getVisible() == true, it will not be visible on screen
/// unless the same is true for all its ancestors.
void setVisible( bool visible );
/// Returns the visibility status for this Gadget.
bool getVisible() const;
/// Returns true if this Gadget and all its parents up to the specified
/// ancestor are visible.
bool visible( Gadget *relativeTo = NULL );
/// Sets whether or not this Gadget should be rendered in a highlighted
/// state. This status is not inherited by child Gadgets. Note that highlighted
/// drawing has not yet been implemented for all Gadget types. Derived
Expand Down Expand Up @@ -152,8 +159,10 @@ class Gadget : public Gaffer::GraphComponent
/// but it must be passed by Gadget implementations when rendering child
/// Gadgets in doRender().
void render( const Style *currentStyle = 0 ) const;
/// The bounding box of the Gadget before transformation.
virtual Imath::Box3f bound() const = 0;
/// The bounding box of the Gadget before transformation. The default
/// implementation returns the union of the transformed bounding boxes
/// of all the children.
virtual Imath::Box3f bound() const;
/// The bounding box transformed by the result of getTransform().
Imath::Box3f transformedBound() const;
/// The bounding box transformed by the result of fullTransform( ancestor ).
Expand Down Expand Up @@ -241,18 +250,22 @@ class Gadget : public Gaffer::GraphComponent

protected :

/// The subclass specific part of render(). This must be implemented
/// appropriately by all subclasses. The public render() method
/// The subclass specific part of render(). The public render() method
/// sets the GL state up with the name attribute and transform for
/// this Gadget, makes sure the style is bound and then calls doRender().
virtual void doRender( const Style *style ) const = 0;
/// The default implementation just renders all the visible child Gadgets.
virtual void doRender( const Style *style ) const;

private :

void styleChanged();
void childAdded( GraphComponent *parent, GraphComponent *child );
void childRemoved( GraphComponent *parent, GraphComponent *child );
void childRenderRequest( Gadget *child );

ConstStylePtr m_style;

bool m_visible;
bool m_highlighted;

Imath::M44f m_transform;
Expand Down
6 changes: 3 additions & 3 deletions include/GafferUI/NodeGadget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011-2012, John Haddon. All rights reserved.
// Copyright (c) 2011-2014, John Haddon. All rights reserved.
// Copyright (c) 2011-2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -49,14 +49,14 @@ IE_CORE_FORWARDDECLARE( Nodule )
IE_CORE_FORWARDDECLARE( NodeGadget )

/// A base class for representing nodes within a GraphGadget.
class NodeGadget : public IndividualContainer
class NodeGadget : public Gadget
{

public :

virtual ~NodeGadget();

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferUI::NodeGadget, NodeGadgetTypeId, ContainerGadget );
IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferUI::NodeGadget, NodeGadgetTypeId, Gadget );

Gaffer::Node *node();
const Gaffer::Node *node() const;
Expand Down
3 changes: 2 additions & 1 deletion include/GafferUI/StandardNodeGadget.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class StandardNodeGadget : public NodeGadget
void setLabelsVisibleOnHover( bool labelsVisible );
bool getLabelsVisibleOnHover() const;

Imath::Box3f bound() const;
virtual bool acceptsChild( const Gaffer::GraphComponent *potentialChild ) const;
virtual Imath::Box3f bound() const;

protected :

Expand Down
34 changes: 25 additions & 9 deletions include/GafferUI/ViewportGadget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, John Haddon. All rights reserved.
// Copyright (c) 2012-2014, John Haddon. All rights reserved.
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -48,25 +48,41 @@
namespace GafferUI
{

/// \todo I'm not sure this should derive from IndividualContainer - the bound and
/// padding don't apply in any sensible way.
class ViewportGadget : public IndividualContainer
/// Provides a viewport through which to view and interact with Gadgets - typically this
/// will be the top level Gadget in any hierarchy. The ViewportGadget is typically hosted
/// within a Widget UI via a GadgetWidget, and forwards all event signals it receives to
/// its child gadgets, transforming the event from the 2d space of the widget to the 3d
/// space of the gadget as it goes. The framing of the child gadgets is specified using a
/// Camera, which may be specified both programatically and through user interaction.
class ViewportGadget : public Gadget
{

public :

typedef boost::signal<void (ViewportGadget *)> UnarySignal;

ViewportGadget( GadgetPtr child=0 );
ViewportGadget( GadgetPtr primaryChild = NULL );
virtual ~ViewportGadget();

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferUI::ViewportGadget, ViewportGadgetTypeId, IndividualContainer );
IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferUI::ViewportGadget, ViewportGadgetTypeId, Gadget );

/// Accepts no parents - the ViewportGadget must always be the topmost Gadget.
virtual bool acceptsParent( const Gaffer::GraphComponent *potentialParent ) const;

virtual std::string getToolTip( const IECore::LineSegment3f &position ) const;

/// Typically mouse event signals are emitted for the gadget under
/// the mouse, but in the case that there is no such gadget, they
/// are emitted on the primary child. The primary child is currently
/// also the only gadget to have key press/release signals emitted on
/// it.
/// \todo It might be nice in future to remove this concept and to have
/// all children treated equally - at present we need the concept so that
/// the node graph and viewer can use clicks in empty space to perform selection,
/// but there may be other ways of achieving that.
void setPrimaryChild( GadgetPtr gadget );
Gadget *getPrimaryChild();
const Gadget *getPrimaryChild() const;

const Imath::V2i &getViewport() const;
void setViewport( const Imath::V2i &viewport );
/// A signal emitted when the viewport is changed by
Expand Down Expand Up @@ -101,8 +117,8 @@ class ViewportGadget : public IndividualContainer
/// to use V3fs?
void gadgetsAt( const Imath::V2f &rasterPosition, std::vector<GadgetPtr> &gadgets ) const;

IECore::LineSegment3f rasterToGadgetSpace( const Imath::V2f &rasterPosition, const Gadget *gadget = 0 ) const;
Imath::V2f gadgetToRasterSpace( const Imath::V3f &gadgetPosition, const Gadget *gadget = 0 ) const;
IECore::LineSegment3f rasterToGadgetSpace( const Imath::V2f &rasterPosition, const Gadget *gadget ) const;
Imath::V2f gadgetToRasterSpace( const Imath::V3f &gadgetPosition, const Gadget *gadget ) const;

/// The SelectionScope class can be used by child Gadgets to perform
/// OpenGL selection from event signal callbacks.
Expand Down
36 changes: 36 additions & 0 deletions python/GafferSceneUI/SceneViewToolbar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
##########################################################################
#
# Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
# Copyright (c) 2014, John Haddon. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
Expand Down Expand Up @@ -132,3 +133,38 @@ def _updateFromPlug( self ) :
"to choose another camera."
)

##########################################################################
# Grid
##########################################################################

class _GridPlugValueWidget( GafferUI.PlugValueWidget ) :

def __init__( self, plug, **kw ) :

menu = GafferUI.Menu( Gaffer.WeakMethod( self.__menuDefinition ) )
menuButton = GafferUI.MenuButton( menu=menu, image = "grid.png", hasFrame=False )

GafferUI.PlugValueWidget.__init__( self, menuButton, plug, **kw )

def hasLabel( self ) :

return True

def _updateFromPlug( self ) :

pass

def __menuDefinition( self ) :

m = IECore.MenuDefinition()
m.append(
"/Show Grid",
{
"checkBox" : self.getPlug()["visible"].getValue(),
"command" : lambda checked : self.getPlug()["visible"].setValue( checked ),
}
)

return m

GafferUI.PlugValueWidget.registerCreator( GafferSceneUI.SceneView.staticTypeId(), "grid", _GridPlugValueWidget )
2 changes: 1 addition & 1 deletion python/GafferUI/BoxUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def nodeMenuCreateCommand( menu ) :
assert( nodeGraph is not None )

script = nodeGraph.scriptNode()
graphGadget = nodeGraph.graphGadgetWidget().getViewportGadget().getChild()
graphGadget = nodeGraph.graphGadget()

return Gaffer.Box.create( graphGadget.getRoot(), script.selection() )

Expand Down
8 changes: 4 additions & 4 deletions python/GafferUI/NodeGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__( self, scriptNode, **kw ) :
graphGadget = GafferUI.GraphGadget( self.scriptNode() )
self.__rootChangedConnection = graphGadget.rootChangedSignal().connect( Gaffer.WeakMethod( self.__rootChanged ) )

self.__gadgetWidget.getViewportGadget().setChild( graphGadget )
self.__gadgetWidget.getViewportGadget().setPrimaryChild( graphGadget )
self.__gadgetWidget.getViewportGadget().setDragTracking( True )
self.__frame( scriptNode.selection() )

Expand All @@ -76,10 +76,10 @@ def graphGadgetWidget( self ) :

## Returns the internal Gadget used to draw the graph. This may be
# modified directly to set up appropriate filters etc. This is just
# a convenience method returning graphGadgetWidget().getViewportGadget().getChild().
# a convenience method returning graphGadgetWidget().getViewportGadget().getPrimaryChild().
def graphGadget( self ) :

return self.graphGadgetWidget().getViewportGadget().getChild()
return self.graphGadgetWidget().getViewportGadget().getPrimaryChild()

## Frames the specified nodes in the viewport. If extend is True
# then the current framing will be extended to include the specified
Expand Down Expand Up @@ -273,7 +273,7 @@ def __buttonPress( self, widget, event ) :
def __nodeGadgetAt( self, position ) :

viewport = self.__gadgetWidget.getViewportGadget()
line = viewport.rasterToGadgetSpace( IECore.V2f( position.x, position.y ) )
line = viewport.rasterToGadgetSpace( IECore.V2f( position.x, position.y ), gadget = self.graphGadget() )
return self.graphGadget().nodeGadgetAt( line )

def __keyPress( self, widget, event ) :
Expand Down
2 changes: 1 addition & 1 deletion python/GafferUI/NodeMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def f( menu ) :
nodeGraph = menu.ancestor( GafferUI.NodeGraph )
assert( nodeGraph is not None )
gadgetWidget = nodeGraph.graphGadgetWidget()
graphGadget = gadgetWidget.getViewportGadget().getChild()
graphGadget = nodeGraph.graphGadget()

script = nodeGraph.scriptNode()

Expand Down
Loading