Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: michaeljones/maya-plugin-handler
base: f68f424118
...
head fork: michaeljones/maya-plugin-handler
compare: 71909b474b
Checking mergeability… Don't worry, you can still create the pull request.
  • 7 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 09, 2012
Michael Jones Support de/registering ControlCommands in both approaches 40ef6a1
Michael Jones Correct de/registerCommand implementation as the MSyntaxCreator is op…
…tional

Previously we were treating it as a required member of the class in the
template approach.
2358db3
Michael Jones Switch to putting all classes in "mph" namespace
maya-plugin-handler/helper. Preferable to the half-in-half-out setup we
had before with the extra long namespace name.
33bedfc
Michael Jones Update README with namespace and links to example code 819a071
Michael Jones Supprt de/registering Shapes in both approaches 866068d
Michael Jones Support de/registering Transforms for both approaches 2859096
Michael Jones Add disclaimer to README 71909b4
View
21 README.md
@@ -11,6 +11,10 @@ Status
The code is in early stages and hasn't be tested with complex production
plugins. It works in the basic tests but might fail in other scenarios.
+Also, note that not all functions are tested in the tests. It is a lot of work
+to create an example of every Maya MPx class in order to test the registration
+properly.
+
Why?
----
@@ -40,7 +44,7 @@ Polymorphic Approach
This allows us to write a function like:
```
-MStatus handlePlugin( PluginHandler& handler )
+MStatus handlePlugin( mph::PluginHandler& handler )
{
return handler.handleNode(
"locatorExample",
@@ -61,7 +65,7 @@ MStatus initializePlugin( MObject obj )
{
MFnPlugin plugin( obj, "Michael Jones", "0.1", "Any");
- InitializePluginHandler handler( plugin );
+ mph::InitializePluginHandler handler( plugin );
return handlePlugin( handler );
}
@@ -69,7 +73,7 @@ MStatus uninitializePlugin( MObject obj)
{
MFnPlugin plugin( obj );
- UninitializePluginHandler handler( plugin );
+ mph::UninitializePluginHandler handler( plugin );
return handlePlugin( handler );
}
```
@@ -81,7 +85,7 @@ optional arguments.
The `UninitializePluginHandler` ignores most of the arguments and uses the
appropriate identifier for the necessary `deregister` method on the MFnPlugin.
-See `tests/example-plugin.cc` for a complete example.
+See [tests/example-plugin.cc][polymorphic-example] for a more complete example.
Template Approach
-----------------
@@ -107,7 +111,7 @@ MStatus initializePlugin( MObject obj )
{
MFnPlugin plugin( obj, "Michael Jones", "0.1", "Any");
- InitializeOpinionatedPluginHandler handler( plugin );
+ mph::InitializeOpinionatedPluginHandler handler( plugin );
return handlePlugin( handler );
}
@@ -115,7 +119,7 @@ MStatus uninitializePlugin( MObject obj)
{
MFnPlugin plugin( obj );
- UninitializeOpinionatedPluginHandler handler( plugin );
+ mph::UninitializeOpinionatedPluginHandler handler( plugin );
return handlePlugin( handler );
}
```
@@ -130,4 +134,9 @@ and syntax functions, however some registration details are not needed anywhere
else so having them as static members of the classes seems a little
unnecessary.
+See [tests/example-plugin.cc][template-example] for a more complete example.
+
+
+[polymorphic-example]: https://github.com/michaeljones/maya-plugin-handler/blob/master/tests/example-plugin.cc "Polymorphic example"
+[template-example]: https://github.com/michaeljones/maya-plugin-handler/blob/master/tests/opinionated-example-plugin.cc "Templated example"
View
117 src/OpinionatedPluginHandler.hh
@@ -3,7 +3,7 @@
#include <maya/MFnPlugin.h>
-namespace OpinionatedPluginHandler
+namespace mph
{
//
@@ -133,7 +133,43 @@ public:
static const MPxData::Type dataType() { return T::dataType; };
};
-}; // end OpinionatedPluginHandler namespace
+
+//
+// Compile time detection of T::syntaxCreator member
+//
+// Works as the nodeType detection above so we leave out the comments
+//
+template< class T >
+class SyntaxCreatorIsPresent
+{
+ class Yes { char a[10]; };
+ class No { char a[1]; };
+
+ template< class U, MCreateSyntaxFunction > struct Check {};
+ template< class U > static Yes func( Check< U, &U::syntaxCreator >* );
+ template< class U > static No func( ... );
+
+public:
+
+ enum { value = sizeof( func< T >( 0 ) ) == sizeof( Yes ) ? 1 : 0 };
+};
+
+
+template< class T, int >
+class SyntaxCreator
+{
+public:
+
+ static const MCreateSyntaxFunction syntaxCreator() { return NULL; }
+};
+
+template< class T >
+class SyntaxCreator< T, 1 >
+{
+public:
+
+ static const MCreateSyntaxFunction syntaxCreator() { return T::syntaxCreator; };
+};
//
// InitializeOpinionatedPluginHandler
@@ -153,13 +189,37 @@ public:
NodeT::id,
NodeT::creator,
NodeT::initialize,
- OpinionatedPluginHandler::NodeType<
- NodeT,
- OpinionatedPluginHandler::NodeTypeIsPresent< NodeT >::value
- >::nodeType(),
- OpinionatedPluginHandler::Classification<
- NodeT,
- OpinionatedPluginHandler::ClassificationIsPresent< NodeT >::value
+ NodeType< NodeT, NodeTypeIsPresent< NodeT >::value >::nodeType(),
+ Classification< NodeT, ClassificationIsPresent< NodeT >::value >::classification()
+ );
+ }
+
+ template< class ShapeT >
+ MStatus handleShape()
+ {
+ return m_pluginFn.registerShape(
+ ShapeT::nodeName,
+ ShapeT::id,
+ ShapeT::creator,
+ ShapeT::initialize,
+ ShapeT::uiCreator,
+ Classification< ShapeT, ClassificationIsPresent< ShapeT >::value >::classification()
+ );
+ }
+
+ template< class TransformT >
+ MStatus handleTransform()
+ {
+ return m_pluginFn.registerTransform(
+ TransformT::nodeName,
+ TransformT::id,
+ TransformT::creator,
+ TransformT::initialize,
+ TransformT::xformCreatorFunction,
+ TransformT::xformId,
+ Classification<
+ TransformT,
+ ClassificationIsPresent< TransformT >::value
>::classification()
);
}
@@ -170,7 +230,10 @@ public:
return m_pluginFn.registerCommand(
CommandT::commandName,
CommandT::creator,
- CommandT::syntaxCreator
+ SyntaxCreator<
+ CommandT,
+ SyntaxCreatorIsPresent< CommandT >::value
+ >::syntaxCreator()
);
}
@@ -181,10 +244,16 @@ public:
DataT::dataName,
DataT::id,
DataT::creator,
- OpinionatedPluginHandler::DataType<
- DataT,
- OpinionatedPluginHandler::DataTypeIsPresent< DataT >::value
- >::dataType()
+ DataType< DataT, DataTypeIsPresent< DataT >::value >::dataType()
+ );
+ }
+
+ template< class ControlCommandT >
+ MStatus handleControlCommand()
+ {
+ return m_pluginFn.registerControlCommand(
+ ControlCommandT::commandName,
+ ControlCommandT::creator
);
}
@@ -210,6 +279,18 @@ public:
return m_pluginFn.deregisterNode( NodeT::id );
}
+ template< class ShapeT >
+ MStatus handleShape()
+ {
+ return m_pluginFn.deregisterNode( ShapeT::id );
+ }
+
+ template< class TransformT >
+ MStatus handleTransform()
+ {
+ return m_pluginFn.deregisterNode( TransformT::id );
+ }
+
template< class CommandT >
MStatus handleCommand()
{
@@ -222,11 +303,19 @@ public:
return m_pluginFn.deregisterData( DataT::id );
}
+ template< class ControlCommandT >
+ MStatus handleControlCommand()
+ {
+ return m_pluginFn.deregisterControlCommand( ControlCommandT::commandName );
+ }
+
private:
MFnPlugin& m_pluginFn;
};
+}; // end namespace mph
+
#endif // OPINIONATEDPLUGINHANDLER_HH
View
111 src/PluginHandler.hh
@@ -3,6 +3,8 @@
#include <maya/MFnPlugin.h>
+namespace mph {
+
class PluginHandler
{
public:
@@ -18,6 +20,25 @@ public:
const MString* classification = NULL
) = 0;
+ virtual MStatus handleShape(
+ const MString& typeName,
+ const MTypeId& typeId,
+ MCreatorFunction creatorFunction,
+ MInitializeFunction initFunction,
+ MCreatorFunction uiCreatorFunction,
+ const MString* classification = NULL
+ ) = 0;
+
+ virtual MStatus handleTransform(
+ const MString& typeName,
+ const MTypeId& typeId,
+ MCreatorFunction creatorFunction,
+ MInitializeFunction initFunction,
+ MCreateXformMatrixFunction xformCreatorFunction,
+ const MTypeId& xformId,
+ const MString* classification = NULL
+ ) = 0;
+
virtual MStatus handleCommand(
const MString& commandName,
MCreatorFunction creatorFunction,
@@ -30,6 +51,11 @@ public:
MCreatorFunction creatorFunction,
MPxData::Type type = MPxData::kData
) = 0;
+
+ virtual MStatus handleControlCommand(
+ const MString& commandName,
+ MCreatorFunction creatorFunction
+ ) = 0;
};
class InitializePluginHandler : public PluginHandler
@@ -58,6 +84,46 @@ public:
);
}
+ MStatus handleShape(
+ const MString& typeName,
+ const MTypeId& typeId,
+ MCreatorFunction creatorFunction,
+ MInitializeFunction initFunction,
+ MCreatorFunction uiCreatorFunction,
+ const MString* classification = NULL
+ )
+ {
+ return m_pluginFn.registerShape(
+ typeName,
+ typeId,
+ creatorFunction,
+ initFunction,
+ uiCreatorFunction,
+ classification
+ );
+ }
+
+ MStatus handleTransform(
+ const MString& typeName,
+ const MTypeId& typeId,
+ MCreatorFunction creatorFunction,
+ MInitializeFunction initFunction,
+ MCreateXformMatrixFunction xformCreatorFunction,
+ const MTypeId& xformId,
+ const MString* classification = NULL
+ )
+ {
+ return m_pluginFn.registerTransform(
+ typeName,
+ typeId,
+ creatorFunction,
+ initFunction,
+ xformCreatorFunction,
+ xformId,
+ classification
+ );
+ }
+
MStatus handleCommand(
const MString& commandName,
MCreatorFunction creatorFunction,
@@ -86,6 +152,17 @@ public:
);
}
+ MStatus handleControlCommand(
+ const MString& commandName,
+ MCreatorFunction creatorFunction
+ )
+ {
+ return m_pluginFn.registerControlCommand(
+ commandName,
+ creatorFunction
+ );
+ }
+
private:
MFnPlugin& m_pluginFn;
@@ -111,6 +188,31 @@ public:
return m_pluginFn.deregisterNode( typeId );
}
+ MStatus handleShape(
+ const MString&,
+ const MTypeId& typeId,
+ MCreatorFunction,
+ MInitializeFunction,
+ MCreatorFunction,
+ const MString* = NULL
+ )
+ {
+ return m_pluginFn.deregisterNode( typeId );
+ }
+
+ MStatus handleTransform(
+ const MString&,
+ const MTypeId& typeId,
+ MCreatorFunction,
+ MInitializeFunction,
+ MCreateXformMatrixFunction,
+ const MTypeId&,
+ const MString* = NULL
+ )
+ {
+ return m_pluginFn.deregisterNode( typeId );
+ }
+
MStatus handleCommand(
const MString& commandName,
MCreatorFunction,
@@ -130,6 +232,13 @@ public:
return m_pluginFn.deregisterData( typeId );
}
+ MStatus handleControlCommand(
+ const MString& commandName,
+ MCreatorFunction
+ )
+ {
+ return m_pluginFn.deregisterControlCommand( commandName );
+ }
private:
@@ -137,5 +246,7 @@ private:
};
+}; // end namespace mph
+
#endif // PLUGINHANDLER_HH
View
6 tests/example-plugin.cc
@@ -7,7 +7,7 @@
#include <maya/MObject.h>
#include <maya/MStatus.h>
-MStatus handlePlugin( PluginHandler& handler )
+MStatus handlePlugin( mph::PluginHandler& handler )
{
MStatus status;
status = handler.handleNode(
@@ -39,7 +39,7 @@ MStatus initializePlugin( MObject obj )
MStatus result;
MFnPlugin plugin( obj, "Michael Jones", "0.1", "Any");
- InitializePluginHandler handler( plugin );
+ mph::InitializePluginHandler handler( plugin );
handlePlugin( handler );
return result;
@@ -51,7 +51,7 @@ MStatus uninitializePlugin( MObject obj)
MFnPlugin plugin( obj );
- UninitializePluginHandler handler( plugin );
+ mph::UninitializePluginHandler handler( plugin );
handlePlugin( handler );
return result;
View
4 tests/examples.cc
@@ -13,8 +13,8 @@ MString FullOpinionatedLocator::classification( "customClassification" );
MTypeId PartialOpinionatedNode::id( 0x80004 );
MString PartialOpinionatedNode::nodeName( "partialOpinionatedNode" );
-MString OpinionatedCommand::commandName( "opinionatedCommand" );
-
+MString FullOpinionatedCommand::commandName( "fullOpinionatedCommand" );
+MString PartialOpinionatedCommand::commandName( "partialOpinionatedCommand" );
MTypeId FullOpinionatedData::id( 0x80005 );
MString FullOpinionatedData::dataName( "fullOpinionatedData" );
View
12 tests/examples.hh
@@ -65,15 +65,23 @@ public:
static MString nodeName;
};
-class OpinionatedCommand : public MPxCommand
+class FullOpinionatedCommand : public MPxCommand
{
public:
- static void* creator() { return new Command; }
+ static void* creator() { return new FullOpinionatedCommand; }
static MSyntax syntaxCreator() { return MSyntax(); }
static MString commandName;
+};
+class PartialOpinionatedCommand : public MPxCommand
+{
+public:
+
+ static void* creator() { return new PartialOpinionatedCommand; }
+
+ static MString commandName;
};
class FullOpinionatedData : public MPxData
View
7 tests/opinionated-example-plugin.cc
@@ -15,7 +15,8 @@ MStatus handlePlugin( OpinionatedPluginHandlerT& handler )
handler.template handleNode< FullOpinionatedLocator >();
handler.template handleNode< PartialOpinionatedNode >();
- handler.template handleCommand< OpinionatedCommand >();
+ handler.template handleCommand< FullOpinionatedCommand >();
+ handler.template handleCommand< PartialOpinionatedCommand >();
handler.template handleData< FullOpinionatedData >();
handler.template handleData< PartialOpinionatedData >();
@@ -29,7 +30,7 @@ MStatus initializePlugin( MObject obj )
MStatus result;
MFnPlugin plugin( obj, "Michael Jones", "0.1", "Any");
- InitializeOpinionatedPluginHandler handler( plugin );
+ mph::InitializeOpinionatedPluginHandler handler( plugin );
handlePlugin( handler );
return result;
@@ -41,7 +42,7 @@ MStatus uninitializePlugin( MObject obj)
MFnPlugin plugin( obj );
- UninitializeOpinionatedPluginHandler handler( plugin );
+ mph::UninitializeOpinionatedPluginHandler handler( plugin );
handlePlugin( handler );
return result;

No commit comments for this range

Something went wrong with that request. Please try again.