Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends

MPxContext Class Reference

This reference page is linked to from the following overview topics: Using the Maya Python API.


Search for all occurrences

Detailed 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:

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:

componentScaleManip.cpp, customAttrManip.cpp, helixTool.cpp, lassoTool.cpp, marqueeTool.cpp, meshRemapTool.cpp, meshRemapTool.h, meshReorderTool.cpp, meshReorderTool.h, moveManip.cpp, moveNumericTool.cpp, moveTool.cpp, rotateManip.cpp, and surfaceBumpManip.cpp.

#include <MPxContext.h>

Inheritance diagram for MPxContext:
Inheritance graph
[legend]

List of all members.

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.
virtual  ~MPxContext ()
  Default destructor.
virtual void  toolOnSetup (MEvent &event)
  This method is called when the context is activated, i.e when the toolButton for the context is pressed.
virtual void  toolOffCleanup ()
  This method is called when the context is deactivated, i.e when another context is activated.
virtual MStatus  doPress (MEvent &event)
  This method is called when any mouse button is pressed.
virtual MStatus  doRelease (MEvent &event)
  This method is called when any mouse button is released.
virtual MStatus  doDrag (MEvent &event)
  This method is called when a mouse drag event occurs.
virtual MStatus  doHold (MEvent &event)
  This method is called when a mouse button is pressed but before the mouse is dragged.
virtual MStatus  doEnterRegion (MEvent &event)
  This method is called when the mouse pointer enters a screen panel region.
virtual MStatus  helpStateHasChanged (MEvent &event)
  This method is called whenever the help state may need to be updated.
virtual void  deleteAction ()
  This method is called when the delete or backspace key is pressed.
virtual void  completeAction ()
  This method is called when the complete key is pressed.
virtual MStatus  addManipulator (const MObject &manipulator)
  This method adds a manipulator to the context.
virtual MStatus  deleteManipulators ()
  This method deletes all the manipulators that belong to the context.
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.
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.
virtual void  abortAction ()
  This method is called when the abort key is pressed.
virtual bool  processNumericalInput (const MDoubleArray &values, const MIntArray &flags, bool isAbsolute)
  This method processes the input from the numerical input field.
virtual bool  feedbackNumericalInput () const
  This method is called to update the numerical feedback.
virtual MSyntax::MArgType  argTypeNumericalInput (unsigned int index) const
  This method is used by the feedback line to determine what units to display.
virtual MString  stringClassName () const
  This method is called to determine the name that uniquely identifies the context.
virtual void  getClassName (MString &name) const
  NO SCRIPT SUPPORT.
MStatus  getImage (MString &image, ImageIndex index) const
  NO SCRIPT SUPPORT.

Static Public Member Functions

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

Protected Member Functions

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

Static Protected Member Functions

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

Friends

class  MPxSelectionContext
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

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] event The button press event information.

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

Examples:
componentScaleManip.cpp, customAttrManip.cpp, helixTool.cpp, lassoTool.cpp, marqueeTool.cpp, meshRemapTool.h, meshReorderTool.h, moveManip.cpp, moveNumericTool.cpp, moveTool.cpp, rotateManip.cpp, and surfaceBumpManip.cpp.
void toolOffCleanup ( ) [virtual]

This method is called when the context is deactivated, i.e when another context is activated.

Users can override this method and use it to reset any user defined data to a specific state.

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

Examples:
componentScaleManip.cpp, customAttrManip.cpp, moveManip.cpp, rotateManip.cpp, and surfaceBumpManip.cpp.
MStatus doPress ( MEvent event ) [virtual]

This method is called when any mouse button is pressed.

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

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] event The button press event information.
Returns:
Status code
Status Codes:

Reimplemented in MPxSelectionContext.

Examples:
helixTool.cpp, lassoTool.cpp, and marqueeTool.cpp.
MStatus doRelease ( MEvent event ) [virtual]

This method is called when any mouse button is released.

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

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] event The mouse button release information.
Returns:
Status code
Status Codes:

Reimplemented in MPxSelectionContext.

Examples:
helixTool.cpp, lassoTool.cpp, and marqueeTool.cpp.
MStatus doDrag ( MEvent event ) [virtual]

This method is called when a mouse drag event occurs.

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

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] event The mouse drag event information.
Returns:
Status code
Status Codes:

Reimplemented in MPxSelectionContext.

Examples:
helixTool.cpp, lassoTool.cpp, and marqueeTool.cpp.
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 overriden if the user needs to do anything on a button hold.

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] event The mouse button hold event information.
Returns:
Status code
Status Codes:

Reimplemented in MPxSelectionContext.

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.

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

Parameters:
[in] event The enter region event information.
Returns:
Status code
Status Codes:
Examples:
customAttrManip.cpp, helixTool.cpp, marqueeTool.cpp, moveNumericTool.cpp, and moveTool.cpp.
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] event The event information.
Returns:
Status code
Status Codes:

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.

Examples:
meshRemapTool.h.
MStatus addManipulator ( const MObject manipulator ) [virtual]

This method adds a manipulator to the context.

Parameters:
[in] manipulator the manipulator to be added to the context
Returns:

Reimplemented in MPxSelectionContext.

MStatus deleteManipulators ( ) [virtual]

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

Returns:

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] image the name of an XPM file to be used as the icon
[in] index the index of the image being set; three image representations are permitted: kImage1, kImage2, kImage3
Returns:

Reimplemented in MPxSelectionContext.

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] index the index for the image being retrieved; three image representations are permitted: kImage1, kImage2, kImage3
[out] ReturnStatus Status code (see below)
Returns:
String name
Status Codes:

Reimplemented in MPxSelectionContext.

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] str The new help string.
Returns:
Status code
Status Codes:
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] str The new title string.
Returns:
Status code
Status Codes:
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] newCursor The new cursor.
Returns:
Status code
Status Codes:
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] event Current event information.
Returns:
Status code
Status Codes:
MStatus dragMarquee ( MEvent event ) [protected]

USE _dragMarquee() IN SCRIPT.

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

Parameters:
[in] event Current event information.
Returns:
Status code
Status Codes:
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] event Current event information.
[out] top highest value
[out] left left-most value
[out] bottom lowest value
[out] right right-most value
Returns:
Status Code
Status Codes:
MPxToolCommand * newToolCommand ( ) [protected, virtual]

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.

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] values the values from the numerical input field
[in] flags used in conjunction with the ignoreEntry method, determines whether or not a given entry should be ignored
[in] isAbsolute whether 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] index the 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] name string that uniquely identifies the context
Examples:
helixTool.cpp.
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] image the returned name of an XPM Icon file
[in] index the index for the image being retrieved; three image representations are permitted: kImage1, kImage2, kImage3
Returns:

Reimplemented in MPxSelectionContext.

const char * className ( ) [static]

Returns the name of this class.

Returns:
Name of this class.

Reimplemented in MPxSelectionContext.

bool ignoreEntry ( const MIntArray flags,
unsigned int  entry 
) [static, protected]

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] flags used in conjunction with the processNumericalInput method, determines whether or not a given entry should be ignored.
[in] entry the entry specified by a (0-based) index
Returns:
  • true the given entry should be ignored
  • false the given entry should not be ignored

MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext
MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext MPxContext