#include <stdlib.h>
#include <string.h>
#include <maya/MFStream.h>
#include <maya/MGlobal.h>
#include <maya/MString.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxFileTranslator.h>
#include <maya/MSelectionList.h>
#include <maya/MFnAnimCurve.h>
#include <maya/MAnimCurveClipboard.h>
#include <maya/MAnimCurveClipboardItem.h>
#include <maya/MAnimCurveClipboardItemArray.h>
#include "animImportExport.h"
#include "animFileUtils.h"
#include "animImportExportStrings.h"
#if defined (OSMac_)
# include <sys/param.h>
extern "C" int strcasecmp (const char *, const char *);
#endif
const char *const animImportOptionScript = "animImportOptions";
const char *const animImportDefaultOptions =
"targetTime=4;copies=1;option=replace;pictures=0;connect=0;";
static MStatus registerMStringResources(
void)
{
}
animImport::animImport()
{
}
animImport::~animImport()
{
}
void *animImport::creator()
{
return new animImport();
}
FileAccessMode mode)
{
#if defined (OSMac_)
char fname[MAXPATHLEN];
strcpy (fname, fileName.
asChar());
ifstream animFile(fname);
#else
ifstream animFile(fileName.
asChar());
#endif
const MString flagTargetTime(
"targetTime");
const MString flagCopies(
"copies");
const MString flagOption(
"option");
const MString flagConnect(
"connect");
options.
split(
';', optionList);
unsigned nOptions = optionList.
length();
for (unsigned i = 0; i < nOptions; i++) {
optionList[i].split('=', theOption);
continue;
}
if (theOption[0] == flagCopies && theOption.
length() > 1) {
copyValue = theOption[1];;
}
else if (theOption[0] == flagOption && theOption.
length() > 1) {
flagValue = theOption[1];
}
else if (theOption[0] == flagConnect && theOption.
length() > 1) {
if (theOption[1].asInt() != 0) {
connectValue += theOption[1];
}
}
else if (theOption[0] == flagTime && theOption.
length() > 1) {
timeValue += theOption[1];
}
}
pasteFlags += " -copies ";
pasteFlags += copyValue;
pasteFlags += " ";
}
pasteFlags += " -option \"";
pasteFlags += flagValue;
pasteFlags += "\" ";
}
if (connectValue.
length() > 0) {
pasteFlags += " -connect ";
pasteFlags += connectValue;
pasteFlags += " ";
}
pasteFlags += " -time ";
if (useQuotes) pasteFlags += "\"";
pasteFlags += timeValue;
if (useQuotes) pasteFlags += "\"";
pasteFlags += " ";
}
}
if (mode == kImportAccessMode) {
status = importAnim(animFile, pasteFlags);
}
animFile.close();
return status;
}
bool animImport::haveReadMethod() const
{
return true;
}
bool animImport::haveWriteMethod() const
{
return false;
}
bool animImport::canBeOpened() const
{
return false;
}
MString animImport::defaultExtension()
const
{
}
const char* buffer,
short size) const
{
int nameLength = (int)strlen(name);
if ((nameLength > 5) && !strcasecmp(name+nameLength-5, ".anim")) {
return kIsMyFileType;
}
if (strncmp(buffer, "animVersion", 11) == 0) {
return kIsMyFileType;
}
return kNotMyFileType;
}
animImport::importAnim(ifstream &animFile,
const MString &pasteFlags)
{
}
(status = fReader.readClipboard(animFile,
return status;
}
}
MString command(
"pasteKey -cb api ");
command += pasteFlags;
int result;
return status;
}
return status;
}
const char *const animExportOptionScript = "animExportOptions";
const char *const animExportDefaultOptions = "precision=8;nodeNames=1;verboseUnits=0;whichRange=1;range=0:10;options=keys;hierarchy=none;controlPoints=0;shapes=1;helpPictures=0;useChannelBox=0;copyKeyCmd=";
const int kDefaultPrecision = 8;
animExport::animExport()
{
}
animExport::~animExport()
{
}
void *animExport::creator()
{
return new animExport();
}
FileAccessMode mode)
{
#if defined (OSMac_)
char fname[MAXPATHLEN];
strcpy (fname, fileName.
asChar());
ofstream animFile(fname);
#else
ofstream animFile(fileName.
asChar());
#endif
MString copyFlags(
"copyKey -cb api -fea 1 ");
int precision = kDefaultPrecision;
bool nodeNames = true;
bool verboseUnits = false;
const MString flagPrecision(
"precision");
const MString flagNodeNames(
"nodeNames");
const MString flagVerboseUnits(
"verboseUnits");
const MString flagCopyKeyCmd(
"copyKeyCmd");
options.
split(
';', optionList);
unsigned nOptions = optionList.
length();
for (unsigned i = 0; i < nOptions; i++) {
optionList[i].split('=', theOption);
continue;
}
if (theOption[0] == flagPrecision && theOption.
length() > 1) {
if (theOption[1].isInt()) {
precision = theOption[1].asInt();
}
} else if ( theOption[0] ==
flagNodeNames && theOption.
length() > 1) {
if (theOption[1].isInt()) {
nodeNames = (theOption[1].asInt()) ? true : false;
}
}
else if ( theOption[0] ==
flagVerboseUnits && theOption.
length() > 1) {
if (theOption[1].isInt()) {
verboseUnits = (theOption[1].asInt()) ? true : false;
}
} else if ( theOption[0] ==
flagCopyKeyCmd && theOption.
length() > 1) {
const char *optStr = theOption[1].asChar();
size_t nChars = strlen(optStr);
char *copyStr = new char[nChars+1];
copyStr = strcpy(copyStr, optStr);
for (size_t j = 0; j < nChars; j++) {
if (copyStr[j] == '>') {
copyStr[j] = '"';
}
}
copyFlags += copyStr;
delete [] copyStr;
}
}
}
animFile.precision(precision);
status = exportSelected(animFile, copyFlags, nodeNames, verboseUnits);
animFile.flush();
animFile.close();
return status;
}
bool animExport::haveReadMethod() const
{
return false;
}
bool animExport::haveWriteMethod() const
{
return true;
}
MString animExport::defaultExtension()
const
{
}
const char* buffer,
short size) const
{
int nameLength = (int)strlen(name);
if ((nameLength > 5) && !strcasecmp(name+nameLength-5, ".anim")) {
return kIsMyFileType;
}
return kNotMyFileType;
}
MStatus animExport::exportSelected( ofstream &animFile,
bool nodeNames ,
bool verboseUnits )
{
}
int result = 0;
return status;
}
}
fWriter.writeClipboard(animFile,
nodeNames, verboseUnits))) {
}
return status;
}
{
MFnPlugin impPlugIn(obj, PLUGIN_COMPANY,
"3.0",
"Any");
stat = impPlugIn.registerUIStrings(registerMStringResources, "animImportExportInitStrings");
{
stat.
perror(
"registerUIStrings");
return stat;
}
stat = impPlugIn.registerFileTranslator("animImport", "none",
animImport::creator,
(char *)animImportOptionScript,
(char *)animImportDefaultOptions,
true);
return stat;
}
MFnPlugin expPlugIn(obj, PLUGIN_COMPANY,
"3.0",
"Any");
stat = expPlugIn.registerFileTranslator("animExport", "",
animExport::creator,
(char *)animExportOptionScript,
(char *)animExportDefaultOptions,
true);
return stat;
}
{
stat = impPlugIn.deregisterFileTranslator("animImport");
return stat;
}
stat = expPlugIn.deregisterFileTranslator("animExport");
return stat;
}