MPxEditData Class Reference

#include <MPxEditData.h>

Class Description

Base class used to associate user-defined data with edits.

MPxEditData is a pure virtual base class, used to derive custom data objects which can be associated with individual MEdit objects.

A small set of comparison methods need to be defined to support query operations and use of associative data structures. The base class defines no other data or behavior.

Derived classes are free to add data members and methods as required.

Use in Python

As a convenience, Maya implements performIsEqual and performIsLessThan as the == and < operators, respectively. Python implementations can then provide comparison methods __eq__ and __lt__, as expected.

Python Accessor Methods _setValue and _getValue

It is expected that classes derived from MPxEditData will define one or more data members to store the object's value and this data will be used by the virtual methods performIsEqual and performIsLessThan for comparison.

In Python, derived class objects passed to the virtual comparison method implementations will only be visible as MPxEditData base class objects, not the actual derived class objects.

For this reason, Python classes derived from MPxEditData have two additional methods, _setValue and _getValue that provide a mechanism for the derived class to access its custom data value using the base class interface.

Since these interfaces are defined directly in Python, the data value can be any valid Python type.

def _setValue(data):
# Called by the class to store the data value of the object
# The data value can be of any valid Python type
def _getValue():
# Called by the class to retrieve the data value that was
# previously set using _setValue

Python Accessor Methods _setStringValue and _getStringValue

To handle the common case of having a Python string as a tag value, similarly to _setValue and _getValue, Python classes derived from MPxEditData also have methods _setStringValue and _getStringValue.

The argument to _setStringValue is expected to be a plain Python string, not a Unicode string. The MPxEditData object takes a copy of the argument to _setStringValue, and returns a copy of its string from _getStringValue.

MString _getStringValue() const {
// Return a copy of the string last given to _setStringValue, or an
// empty string if none has been set.
}
void _setStringValue(const MString& value) {
// Copies the value argument string into the MPxEditData object.
}

Ownership of the MPxEditData Object

MPxEditData objects associated with an MEdit must be dynamically allocated. Ownership of the editData will be assumed by Maya and subsequent management of the data object, including its eventual deletion will be handled along with the edit it is associated with. For this reason, an editData object should only be associated with a single edit, the same object should not be shared or associated with other edits. If multiple edits have editData of the same value, each edit must have its own unique copy.

In Python, the OpenMayaMPx asMPxPtr method is used to transfer ownership of a dynamically allocated object to Maya. The Python example below demonstrates how this could be implemented.

Python Example

# Example MPxEditData class implemented in Python
import Maya.OpenMayaMPx as OpenMayaMPx
class testEditDataType(OpenMayaMPx.MPxEditData):
"""
Simple tag class that is intended to store a string value
"""
_tagValue = ''
def __init__(self, tagValue):
OpenMayaMPx.MPxEditData.__init__(self)
# Python derived classes need to use _setValue() here
# and then _getValue() in performIsEqual/performIsLessThan methods
# (because python does not have a dynamic_cast like C++ to use
# on variable 'other' to get access to the derived class data)
self._tagValue = tagValue
self._setValue(self._tagValue)
def __eq__(self, other):
# Note: use of _getValue is not actually necessary for accessing
# data members of 'self'. It is however necessary for 'other'
# since 'other' is only available here as a base class MPxEditData object.
thisValue = self._getValue()
otherValue = other._getValue()
return bool(thisValue == otherValue)
def __lt__(self, other):
thisValue = self._getValue()
otherValue = other._getValue()
return bool(thisValue < otherValue)
def performIsEqual(self, other):
return self == other
def performIsLessThan(self, other):
return self < other
@staticmethod
def creator(tagValue):
"""
Create a tag with the given value.
This creator method correctly returns pointer whose ownership
has been transferred to maya.
"""
return OpenMayaMPx.asMPxPtr(testEditDataType(tagValue))

Public Member Functions

 MPxEditData ()
 Class constructor.
 
virtual ~MPxEditData ()
 Class destructor.
 
bool isEqual (const MPxEditData *other) const
 Compares two MPxEditData objects for equality. More...
 
bool isLessThan (const MPxEditData *other) const
 Compares two MPxEditData objects to determine their relative order for sorting purposes. More...
 

Static Public Member Functions

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

Protected Member Functions

virtual bool performIsEqual (const MPxEditData *other) const =0
 This member function must be implemented by derived classes. More...
 
virtual bool performIsLessThan (const MPxEditData *other) const =0
 This member function must be implemented by derived classes. More...
 

Member Function Documentation

bool isEqual ( const MPxEditData other) const

Compares two MPxEditData objects for equality.

The base class method makes use of the derived class performIsEqual to determine the equality of two objects. Note that the base method will simply return false if the two MPxEditData objects are of different types.

Parameters
[in]otherAn editData object to compare with this object
Returns
True if both MPxEditData objects refer to the same value, false otherwise.
bool isLessThan ( const MPxEditData other) const

Compares two MPxEditData objects to determine their relative order for sorting purposes.

The base class method makes use of the derived class implementation of performIsLessThan to determine the ordering of two MPxEditData objects. Note that the base method will simply order the values by typeid if the two objects are not of the same type.

Parameters
[in]otherAn editData object to compare with this object
Returns
True if this object value is less than the specified MPxEditData object value, false otherwise.
const char * className ( )
static

Returns the name of this class.

Returns
The name of this class.
bool performIsEqual ( const MPxEditData other) const
protectedpure virtual

This member function must be implemented by derived classes.

It should compare two MPxEditData objects for equality. This member function is meant to be called by the isEqual member function.

Parameters
[in]otherAn editData object to compare with this object
Returns
True if both MPxEditData objects refer to the same value, false otherwise.
bool performIsLessThan ( const MPxEditData other) const
protectedpure virtual

This member function must be implemented by derived classes.

It should compare two MPxEditData objects to determine their relative order for sorting purposes. This member function is meant to be called by the isLessThan member function.

Parameters
[in]otherAn editData object to compare with this object
Returns
True if this object value is less than the specified MPxEditData object value, false otherwise.

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