MPxContext Class Reference

#include <MPxContext.h>

Class Description

Base class for user defined contexts.

This is the base class for user defined contexts.

Contexts provide a way to create interactive tools in Maya. A context class defines what happens when interactive events, such as mouse events, occur within an interactive panel in Maya.

Since there are default actions for all tools in Maya, such as the right mouse button event which brings up an options menu, only as subset of the events that occur in a view can be overridden. The events that can be overridden are:

  • doPress - mouse button press event (left & middle only)
  • doRelease - mouse buttons release event (left & middle only)
  • doDrag - mouse button drag event (left & middle only)
  • doHold - mouse button hold event (left & middle only)
  • deleteAction - delete/backspace key event
  • completeAction - complete key event
  • abortAction - abort/escape key event

A context is activated by pressing the toolButton for that context. Once the context is activated, it will handle the events that occur within 3d panel.

A context is deactivated when some other tool button is pressed.

There can be more than one instance of a context in Maya, for example, dragging a tool icon into the shelf creates another instance of that context. Since there can be multiple instances of the same context there is a command class, MPxContextCommand, which is responsible for the creation of contexts. See MPxContextCommand for more information.

+ Examples:
+ Inheritance diagram for MPxContext:

Public Types

enum  ImageIndex { kImage1 = 0, kImage2, kImage3 }
 Used to select between the three possible images associated with the context. More...
 

Public Member Functions

 MPxContext ()
 Class contstructor. More...
 
virtual ~MPxContext ()
 Default destructor. More...
 
virtual void toolOnSetup (MEvent &event)
 This method is called when the context is activated, i.e when the toolButton for the context is pressed. More...
 
virtual void toolOffCleanup ()
 This method is called when the context is deactivated, i.e when another context is activated. More...
 
virtual MStatus doPress (MEvent &event, MHWRender::MUIDrawManager &drawMgr, const MHWRender::MFrameContext &context)
 This method is not available in Python. More...
 
virtual MStatus doRelease (MEvent &event, MHWRender::MUIDrawManager &drawMgr, const MHWRender::MFrameContext &context)
 This method is not available in Python. More...
 
virtual MStatus doDrag (MEvent &event, MHWRender::MUIDrawManager &drawMgr, const MHWRender::MFrameContext &context)
 This method is not available in Python. More...
 
virtual MStatus doHold (MEvent &event, MHWRender::MUIDrawManager &drawMgr, const MHWRender::MFrameContext &context)
 This method is not available in Python. More...
 
virtual MStatus drawFeedback (MHWRender::MUIDrawManager &drawMgr, const MHWRender::MFrameContext &context)
 This method is not available in Python. More...
 
virtual MStatus doPtrMoved (MEvent &event, MHWRender::MUIDrawManager &drawMgr, const MHWRender::MFrameContext &context)
 This method is called when a mouse move event occurs. More...
 
virtual MStatus doPress (MEvent &event)
 This method is called when any mouse button is pressed. More...
 
virtual MStatus doRelease (MEvent &event)
 This method is called when any mouse button is released. More...
 
virtual MStatus doDrag (MEvent &event)
 This method is called when a mouse drag event occurs. More...
 
virtual MStatus doHold (MEvent &event)
 This method is called when a mouse button is pressed but before the mouse is dragged. More...
 
virtual MStatus doPtrMoved (MEvent &event)
 This method is called when a mouse move event occurs. More...
 
virtual MStatus doEnterRegion (MEvent &event)
 This method is called when the mouse pointer enters a screen panel region. More...
 
virtual MStatus helpStateHasChanged (MEvent &event)
 This method is called whenever the help state may need to be updated. More...
 
virtual void deleteAction ()
 This method is called when the delete or backspace key is pressed. More...
 
virtual void completeAction ()
 This method is called when the complete key is pressed. More...
 
virtual MStatus addManipulator (const MObject &manipulator)
 This method adds a manipulator to the context. More...
 
virtual MStatus deleteManipulators ()
 This method deletes all the manipulators that belong to the context. More...
 
MStatus setImage (const MString &image, ImageIndex index)
 This method is used to set an XPM icon image that is to be used to represent this tool context in various places including the tool bar and can be queried from mel using the contextInfo command. More...
 
MString image (ImageIndex index, MStatus *ReturnStatus=NULL) const
 This method is used to retrieve an XPM icon image that has previously been set for this tool context. More...
 
virtual void abortAction ()
 This method is called when the abort key is pressed. More...
 
virtual bool processNumericalInput (const MDoubleArray &values, const MIntArray &flags, bool isAbsolute)
 This method processes the input from the numerical input field. More...
 
virtual bool feedbackNumericalInput () const
 This method is called to update the numerical feedback. More...
 
virtual MSyntax::MArgType argTypeNumericalInput (unsigned int index) const
 This method is used by the feedback line to determine what units to display. More...
 
virtual MString stringClassName () const
 This method is called to determine the name that uniquely identifies the context. More...
 
virtual void getClassName (MString &name) const
 NO SCRIPT SUPPORT. More...
 
MStatus getImage (MString &image, ImageIndex index) const
 NO SCRIPT SUPPORT. More...
 

Static Public Member Functions

static const char * className ()
 Returns the name of this class. More...
 

Protected Member Functions

MStatus setHelpString (const MString &str)
 USE _setHelpString() IN SCRIPT. More...
 
MStatus setTitleString (const MString &str)
 USE _setTitleString() IN SCRIPT. More...
 
MStatus setCursor (const MCursor &cursor)
 USE _setCursor() IN SCRIPT. More...
 
MStatus beginMarquee (MEvent &event)
 USE _beginMarquee() IN SCRIPT. More...
 
MStatus dragMarquee (MEvent &event)
 USE _dragMarquee() IN SCRIPT. More...
 
MStatus releaseMarquee (MEvent &event, short &top, short &left, short &bottom, short &right)
 USE _releaseMarquee() IN SCRIPT. More...
 
virtual MPxToolCommandnewToolCommand ()
 CALL _newToolCommand() IN SCRIPT. More...
 

Static Protected Member Functions

static bool ignoreEntry (const MIntArray &flags, unsigned int entry)
 USE _ignoreEntry() IN SCRIPT. More...
 

Friends

class MPxSelectionContext
 
class MPxTexContext
 
class MToolsInfo
 

Member Enumeration Documentation

enum ImageIndex

Used to select between the three possible images associated with the context.

Enumerator
kImage1 

 

kImage2 

 

kImage3 

 

Constructor & Destructor Documentation

OPENMAYA_MAJOR_NAMESPACE_OPEN MPxContext ( )

Class contstructor.

This constructor will only be called from MPxContextCommand::makeObj. Users must override this method.

~MPxContext ( )
virtual

Default destructor.

Users can override this method to free any user instantiated data when the context is destroyed.

Member Function Documentation

void toolOnSetup ( MEvent event)
virtual

This method is called when the context is activated, i.e when the toolButton for the context is pressed.

Users can override this method and use it to set up any user defined data that needs to be initialized on each activation.

Parameters
[in]eventThe button press event information.

Reimplemented in MTemplateSelectionContext< ContextNameString, ContextClass, NodeType, ManipulatorClass, ManipulatorNodeName >.

+ Examples:
MStatus doPress ( MEvent event,
MHWRender::MUIDrawManager drawMgr,
const MHWRender::MFrameContext context 
)
virtual

This method is not available in Python.

This method is called when any mouse button is pressed.

The base method does nothing and should be overridden if the user needs to do anything on a button press.

This method is called only when in Viewport 2.0. MUIDrawManager must be used for any viewport drawing done in this method. Direct calls to OpenGL or DirectX are unsupported and may result in instability or unpredictable behavior.

MUIDrawManager allows for drawing primitives in the 3D modeling space. Those primitives will then be projected onto a 2D overlay plane before being displayed.

The event can be used to get more explicit information about the press such as the button number. See MEvent for more information.

Parameters
[in]eventThe button press event information.
[in]drawMgrThe UI draw manager, it can be used to draw some simple geometry including text.
[in]contextFrame level context information
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxTexContext, and MPxSelectionContext.

+ Examples:
MStatus doRelease ( MEvent event,
MHWRender::MUIDrawManager drawMgr,
const MHWRender::MFrameContext context 
)
virtual

This method is not available in Python.

This method is called when any mouse button is released.

The base method does nothing and should be overridden if the user needs to do anything on a button release.

This method is called only when in Viewport 2.0. MUIDrawManager must be used for any viewport drawing done in this method. Direct calls to OpenGL or DirectX are unsupported and may result in instability or unpredictable behavior.

MUIDrawManager allows for drawing primitives in the 3D modeling space. Those primitives will then be projected onto a 2D overlay plane before being displayed.

The event can be used to get more explicit information about the release such as the button number. See MEvent for more information.

Parameters
[in]eventThe button press event information.
[in]drawMgrThe UI draw manager, it can be used to draw some simple geometry including text.
[in]contextFrame level context information
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxTexContext, and MPxSelectionContext.

+ Examples:
MStatus doDrag ( MEvent event,
MHWRender::MUIDrawManager drawMgr,
const MHWRender::MFrameContext context 
)
virtual

This method is not available in Python.

This method is called when a mouse drag event occurs.

The base method does nothing and should be overridden if the user needs to do anything during a mouse drag.

This method is called only when in Viewport 2.0. MUIDrawManager must be used for any viewport drawing done in this method. Direct calls to OpenGL or DirectX are unsupported and may result in instability or unpredictable behavior.

MUIDrawManager allows for drawing primitives in the 3D modeling space. Those primitives will then be projected onto a 2D overlay plane before being displayed.

The event can be used to get more explicit information about the drag such as the cursor location. See MEvent for more information.

Parameters
[in]eventThe button press event information.
[in]drawMgrThe UI draw manager, it can be used to draw some simple geometry including text.
[in]contextFrame level context information
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxTexContext, and MPxSelectionContext.

+ Examples:
MStatus doHold ( MEvent event,
MHWRender::MUIDrawManager drawMgr,
const MHWRender::MFrameContext context 
)
virtual

This method is not available in Python.

This method is called when a mouse button is pressed but before the mouse is dragged.

The base method does nothing and should be overridden if the user needs to do anything on a button hold.

This method is called only when in Viewport 2.0. MUIDrawManager must be used for any viewport drawing done in this method. Direct calls to OpenGL or DirectX are unsupported and may result in instability or unpredictable behavior.

MUIDrawManager allows for drawing primitives in the 3D modeling space. Those primitives will then be projected onto a 2D overlay plane before being displayed.

The event can be used to get more explicit information about the hold such as the button number. See MEvent for more information.

Parameters
[in]eventThe button press event information.
[in]drawMgrThe UI draw manager, it can be used to draw some simple geometry including text.
[in]contextFrame level context information
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxSelectionContext.

MStatus drawFeedback ( MHWRender::MUIDrawManager drawMgr,
const MHWRender::MFrameContext context 
)
virtual

This method is not available in Python.

This method is called to draw primitives when your context is activated.

This method is called only when using Viewport 2.0. MUIDrawManager must be used for any viewport drawing done in this method. Direct calls to OpenGL or DirectX are unsupported and may result in instability or unpredictable behavior.

MUIDrawManager allows for drawing primitives in the 3D modeling space. Those primitives will then be projected onto a 2D overlay plane before being displayed.

Parameters
[in]drawMgrThe UI draw manager. It can be used to draw some simple geometry including text.
[in]contextFrame level context information
Returns
Status code
Status Codes:
  • MS::kSuccess
+ Examples:
MStatus doPtrMoved ( MEvent event,
MHWRender::MUIDrawManager drawMgr,
const MHWRender::MFrameContext context 
)
virtual

This method is called when a mouse move event occurs.

The base method does nothing and should be overridden if the user needs to do anything during a mouse drag.

This method is called only when in Viewport 2.0. MUIDrawManager must be used for any viewport drawing done in this method. Direct calls to OpenGL or DirectX are unsupported and may result in instability or unpredictable behavior.

MUIDrawManager allows for drawing primitives in the 3D modeling space. Those primitives will then be projected onto a 2D overlay plane before being displayed.

The event can be used to get more explicit information about the drag such as the cursor location. See MEvent for more information.

Parameters
[in]eventThe button press event information.
[in]drawMgrThe UI draw manager, it can be used to draw some simple geometry including text.
[in]contextFrame level context information
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxTexContext.

MStatus doPress ( MEvent event)
virtual

This method is called when any mouse button is pressed.

The base method does nothing and should be overridden if the user needs to do anything on a button press.

This method is called only when it is in either default viewport renderer or hardware viewport renderer, not viewport 2.0.

The event can be used to get more explicit information about the press such as the button number. See MEvent for more information.

Parameters
[in]eventThe button press event information.
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxSelectionContext.

MStatus doRelease ( MEvent event)
virtual

This method is called when any mouse button is released.

The base method does nothing and should be overridden if the user needs to do anything on a button release.

This method is called only when it is in either default viewport renderer or hardware viewport renderer, not viewport 2.0.

The event can be used to get more explicit information about the release such as the button number. See MEvent for more information.

Parameters
[in]eventThe mouse button release information.
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxSelectionContext.

MStatus doDrag ( MEvent event)
virtual

This method is called when a mouse drag event occurs.

The base method does nothing and should be overridden if the user needs to do anything during a mouse drag.

This method is called only when it is in either default viewport renderer or hardware viewport renderer, not viewport 2.0.

The event can be used to get more explicit information about the drag such as the cursor location. See MEvent for more information.

Parameters
[in]eventThe mouse drag event information.
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxSelectionContext.

MStatus doHold ( MEvent event)
virtual

This method is called when a mouse button is pressed but before the mouse is dragged.

The base method does nothing and should be overridden if the user needs to do anything on a button hold.

This method is called only when it is in either default viewport renderer or hardware viewport renderer, not viewport 2.0.

The event can be used to get more explicit information about the hold such as the button number. See MEvent for more information.

Parameters
[in]eventThe mouse button hold event information.
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxSelectionContext.

MStatus doPtrMoved ( MEvent event)
virtual

This method is called when a mouse move event occurs.

The base method does nothing and should be overridden if the user needs to do anything during a mouse drag.

This method is called only when it is in either default viewport renderer or hardware viewport renderer, not viewport 2.0.

The event can be used to get more explicit information about the drag such as the cursor location. See MEvent for more information.

Parameters
[in]eventThe mouse drag event information.
Returns
Status code
Status Codes:
  • MS::kSuccess
MStatus doEnterRegion ( MEvent event)
virtual

This method is called when the mouse pointer enters a screen panel region.

The base method sets the help string and the cursor which may have been set via setHelpString and setCursor respectively.

This same method is called for default viewport renderer regions, hardware viewport renderer regions, and viewport 2.0 regions. There is not a separate method for VP 2.0 regions as there is with MPxContext::doPress(), MPxContext::doHold(), and MPxContext::doRelease().

The event can be used to get more explicit information about the event. See MEvent for more information.

Parameters
[in]eventThe enter region event information.
Returns
Status code
Status Codes:
  • MS::kSuccess
+ Examples:
MStatus helpStateHasChanged ( MEvent event)
virtual

This method is called whenever the help state may need to be updated.

The base method does nothing and should be overriden if the user needs to change the help information based on events.

The event can be used to get more explicit information about the event. See MEvent for more information.

Parameters
[in]eventThe event information.
Returns
Status code
Status Codes:
  • MS::kSuccess

Reimplemented in MPxSelectionContext.

void deleteAction ( )
virtual

This method is called when the delete or backspace key is pressed.

The default behaviour for this method is to delete the items on the current selection list. Users can override this method if they wish to do anything else when this event occurs.

void completeAction ( )
virtual

This method is called when the complete key is pressed.

The default complete key in Maya is the enter key. Users can override this method if a tool has several steps. For example, a tool may have several steps where the user must select objects and then press the completion key before proceeding.

MStatus addManipulator ( const MObject manipulator)
virtual

This method adds a manipulator to the context.

Parameters
[in]manipulatorthe manipulator to be added to the context
Returns
  • MS::kSuccess operation successful
  • MS::kFailure operation failed

Reimplemented in MPxSelectionContext.

MStatus deleteManipulators ( )
virtual

This method deletes all the manipulators that belong to the context.

Returns
  • MS::kSuccess operation successful
  • MS::kFailure operation failed

Reimplemented in MPxSelectionContext.

MStatus setImage ( const MString image,
ImageIndex  index 
)

This method is used to set an XPM icon image that is to be used to represent this tool context in various places including the tool bar and can be queried from mel using the contextInfo command.

Parameters
[in]imagethe name of an XPM file to be used as the icon
[in]indexthe index of the image being set; three image representations are permitted: kImage1, kImage2, kImage3
Returns
  • MS::kSuccess operation successful
  • MS::kFailure operation failed
MString image ( ImageIndex  index,
MStatus ReturnStatus = NULL 
) const

This method is used to retrieve an XPM icon image that has previously been set for this tool context.

This icon image will be used to represent this tool context in various places including the tool bar and can be queried from mel using the contextInfo command.

Parameters
[in]indexthe index for the image being retrieved; three image representations are permitted: kImage1, kImage2, kImage3
[out]ReturnStatusStatus code (see below)
Returns
String name
Status Codes:
  • MS::kSuccess operation successful
  • MS::kFailure operation failed
MStatus setHelpString ( const MString str)
protected

USE _setHelpString() IN SCRIPT.

Set the help string to the given MString.

This string will appear in the help line in Maya.

Parameters
[in]strThe new help string.
Returns
Status code
Status Codes:
  • MS::kSuccess
MStatus setTitleString ( const MString str)
protected

USE _setTitleString() IN SCRIPT.

Set the title of the context to the MString that is passed in.

This string will appear in the help line when this context is activated.

Parameters
[in]strThe new title string.
Returns
Status code
Status Codes:
  • MS::kSuccess
MStatus setCursor ( const MCursor newCursor)
protected

USE _setCursor() IN SCRIPT.

Set the cursor used by the context to the MCursor that is passed in.

Parameters
[in]newCursorThe new cursor.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kInsufficientMemory Out of memory.
MStatus beginMarquee ( MEvent event)
protected

USE _beginMarquee() IN SCRIPT.

Start drawing a dragged out marquee box.

A marquee box is a rectangular area of the screen specified by two points representing opposite corners of the rectangle. Marquee's are commonly used in the selection of multiple items from a region of the screen. The marquee rectangle acts as a guideline for the region of the screen that will be effected.

Parameters
[in]eventCurrent event information.
Returns
Status code
Status Codes:
  • MS::kSuccess
MStatus dragMarquee ( MEvent event)
protected

USE _dragMarquee() IN SCRIPT.

Draws a rectangle representing the dragged out area initiated with the beginMarquee method.

Parameters
[in]eventCurrent event information.
Returns
Status code
Status Codes:
  • MS::kSuccess
MStatus releaseMarquee ( MEvent event,
short &  top,
short &  left,
short &  bottom,
short &  right 
)
protected

USE _releaseMarquee() IN SCRIPT.

End the marquee drawing cycle and return the coordinates corresponding to the dragged out area.

The rectangular guideline representing the dragged area is cleared.

Parameters
[in]eventCurrent event information.
[out]tophighest value
[out]leftleft-most value
[out]bottomlowest value
[out]rightright-most value
Returns
Status Code
Status Codes:
  • MS::kSuccess
MPxToolCommand * newToolCommand ( )
protectedvirtual

CALL _newToolCommand() IN SCRIPT.

Create a new instance of the tool command associated with this context.

The tool command (derived from MPxToolCommand) is the command that was registered along with the context command in :

MFnPlugin::registerContextCommand( contextCommand, contextCommandCreator,
toolCommand, toolCommandCreator )
Returns
A new instance of the MPxToolCommand.

Reimplemented in MPxSelectionContext, and MPxTexContext.

void abortAction ( )
virtual

This method is called when the abort key is pressed.

The default abort key in Maya is the escape key. Users can override this method if they wish to perform certain operations when the abort key is pressed.

Reimplemented in MPxSelectionContext.

bool processNumericalInput ( const MDoubleArray values,
const MIntArray flags,
bool  isAbsolute 
)
virtual

This method processes the input from the numerical input field.

Users can override this method if they wish to process numerical input. For a given entry in the numeric input field, if the user types a dot ".", this indicates that the entry should not be modified. The overridden version of this method should take this into account using the ignoreEntry method with the flags that are passed in. The overridden version of this method should also process the numeric input as an absolute input or relative input depending on whether the isAbsolute flag is true or not. The return value should indicate whether or not the numerical input has been processed.

Parameters
[in]valuesthe values from the numerical input field
[in]flagsused in conjunction with the ignoreEntry method, determines whether or not a given entry should be ignored
[in]isAbsolutewhether or not the input should be interpreted as absolute
Returns
false the default return value

Reimplemented in MPxSelectionContext.

bool feedbackNumericalInput ( ) const
virtual

This method is called to update the numerical feedback.

The format and values for the feedback line can be set through the methods in MFeedbackLine, specifically setFormat and setValue. The return value should indicate whether or not the numerical feedback has been provided.

Returns
false the default return value

Reimplemented in MPxSelectionContext.

MSyntax::MArgType argTypeNumericalInput ( unsigned int  index) const
virtual

This method is used by the feedback line to determine what units to display.

Users should override this method to return the appropriate argument type for the given index of the numeric input field. Specifically, this method should be overridden to return one of the following:

Parameters
[in]indexthe index of the numerical input whose argument type is requested
Returns
MSyntax::kNoArg the default return value

Reimplemented in MPxSelectionContext.

MString stringClassName ( ) const
virtual

This method is called to determine the name that uniquely identifies the context.

Either this method, or the getClassName method, should be overridden such that the name is set to the appropriate string. For example:

MString MPxExampleContext::stringClassName() const
{ return "exampleTool"; }

This name is used by Maya to call the appropriate tool property sheet MEL scripts, specifically:

  • nameProperties.mel
  • nameValues.mel

If this method is not overriden, by default it will set the string to "defaultTool".

Returns
String that uniquely identifies the context
void getClassName ( MString name) const
virtual

NO SCRIPT SUPPORT.

This method is called to determine the name that uniquely identifies the context.

Either this method, or the stringClassName method which returns a string, should be overridden such that the name is set to the appropriate string. For example:

void MPxExampleContext::getClassName(MString &name) const
{ name.set("exampleTool"); }

This name is used by Maya to call the appropriate tool property sheet MEL scripts, specifically:

  • nameProperties.mel
  • nameValues.mel

If this method is not overriden, by default it will set the string to "defaultTool".

Python Notes

This method is not supported in Python. For contexts implemented in Python please see stringClassName() which returns a string.

Parameters
[out]namestring that uniquely identifies the context
+ Examples:
MStatus getImage ( MString image,
ImageIndex  index 
) const

NO SCRIPT SUPPORT.

This method is used to retrieve an XPM icon image that has previously been set for this tool context.

This icon image will be used to represent this tool context in various places including the tool bar and can be queried from mel using the contextInfo command.

Python Notes

This method is not supported in Python. See the version which returns a string.

Parameters
[out]imagethe returned name of an XPM Icon file
[in]indexthe index for the image being retrieved; three image representations are permitted: kImage1, kImage2, kImage3
Returns
  • MS::kSuccess operation successful
  • MS::kFailure operation failed
const char * className ( )
static

Returns the name of this class.

Returns
Name of this class.
bool ignoreEntry ( const MIntArray flags,
unsigned int  entry 
)
staticprotected

USE _ignoreEntry() IN SCRIPT.

This is a helper method which can be called from processNumericalInput to examine a flags array and return true if the requested (0-based) entry is to be ignored.

Parameters
[in]flagsused in conjunction with the processNumericalInput method, determines whether or not a given entry should be ignored.
[in]entrythe entry specified by a (0-based) index
Returns
  • true the given entry should be ignored
  • false the given entry should not be ignored

The documentation for this class was generated from the following files:
  • MPxContext.h
  • MPxContext.cpp