74 #include "AL/maya/FileTranslatorOptions.h"
76 #include "maya/MPxFileTranslator.h"
77 #include "maya/MGlobal.h"
78 #include "maya/MFileObject.h"
84 #define AL_MAYA_TRANSLATOR_BEGIN(ClassName, TranslatorName, HaveRead, HaveWrite, DefaultExtension, FilterString) \
85 class ClassName : public AL::maya::FileTranslatorBase<ClassName> { \
87 static constexpr const char* const kTranslatorName = TranslatorName; \
88 static constexpr const char* const kClassName = #ClassName; \
89 static void* creator() { return new ClassName; } \
91 bool haveReadMethod() const { return HaveRead; } \
92 bool haveWriteMethod() const { return HaveWrite; } \
93 MString defaultExtension() const { return DefaultExtension; } \
94 MString filter() const { return FilterString; } \
98 #define AL_MAYA_TRANSLATOR_END() };
104 class FileTranslatorBase
105 :
public MPxFileTranslator
111 template<
typename FnPlugin>
115 if(MS::kSuccess == T::specifyOptions(options))
119 MStatus status = plugin.registerFileTranslator(
124 m_defaultOptionString.asChar());
127 MGlobal::displayError(MString(
"Failed to register translator: ") + T::kTranslatorName);
131 MGlobal::displayError(MString(
"Failed to generate options for translator: ") + T::kTranslatorName);
137 template<
typename FnPlugin>
139 {
return plugin.deregisterFileTranslator(T::kTranslatorName); }
145 {
return MS::kSuccess; }
153 {
return MS::kFailure; }
161 {
return MS::kFailure; }
165 MStatus
reader(
const MFileObject &file,
const MString &optionsString,
const FileAccessMode mode)
override
167 MStatus status = m_optionParser.
parse(optionsString);
168 if(MS::kSuccess == status)
170 return reader(file, m_optionParser, mode);
172 MGlobal::displayError(
"Unable to parse the file translator options");
176 MStatus
writer(
const MFileObject &file,
const MString &optionsString,
const FileAccessMode mode)
override
178 MStatus status = m_optionParser.
parse(optionsString);
179 if(MS::kSuccess == status)
181 return writer(file, m_optionParser, mode);
183 MGlobal::displayError(
"Unable to parse the file translator options");
187 static MString m_defaultOptionString;
188 static OptionsParser m_optionParser;
191 template<
typename T> MString FileTranslatorBase<T>::m_defaultOptionString;
192 template<
typename T> OptionsParser FileTranslatorBase<T>::m_optionParser;
static MStatus specifyOptions(FileTranslatorOptions &options)
default fall back in case no options are needed in the derived translator
Definition: FileTranslatorBase.h:144
virtual MStatus reader(const MFileObject &file, const OptionsParser &options, FileAccessMode mode)
Override this method to read your files (do not use the version from MPxFileTranslator!) ...
Definition: FileTranslatorBase.h:152
static MStatus registerTranslator(FnPlugin &plugin)
unregister the file translator
Definition: FileTranslatorBase.h:112
Utility class that constructs the file translator export GUI from the export options you want to supp...
Definition: FileTranslatorOptions.h:148
Utility class that parses the file translator options passed through by Maya.
Definition: FileTranslatorOptions.h:17
virtual MStatus writer(const MFileObject &file, const OptionsParser &options, FileAccessMode mode)
Override this method to write your files (do not use the version from MPxFileTranslator!) ...
Definition: FileTranslatorBase.h:160
static MStatus deregisterTranslator(FnPlugin &plugin)
unregister the file translator
Definition: FileTranslatorBase.h:138
MStatus generateScript(OptionsParser &optionParser, MString &defaultOptionString)
This method generates the MEL script for the import/export GUI, and evaluates it behind the scenes...
MStatus parse(const MString &optionString)
Given a string containing a semi-colon separated list of options passed to a file translator plugin...