#include "exportMetadataCmd.h"
#include "metadataPluginStrings.h"
#include <maya/MObject.h>
#include <maya/MSyntax.h>
#include <maya/MPxCommand.h>
#include <maya/MStatus.h>
#include <maya/MString.h>
#include <maya/MStringResource.h>
#include <maya/MArgDatabase.h>
#include <maya/MFileObject.h>
#include <maya/MFnDependencyNode.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <maya/adskDataChannel.h>
#include <maya/adskDataAssociations.h>
#include <maya/adskDataAssociationsSerializer.h>
#include <maya/adskDataChannelSerializer.h>
#include <maya/adskDataStreamSerializer.h>
#include <maya/adskDataStructureSerializer.h>
void* exportMetadataCmd::creator()
{
return new exportMetadataCmd ;
}
const char* exportMetadataCmd::name()
{
return "exportMetadata";
}
MSyntax exportMetadataCmd::cmdSyntax()
{
MSyntax mySyntax = metadataBase::cmdSyntax();
return mySyntax;
}
exportMetadataCmd::exportMetadataCmd()
{
}
exportMetadataCmd::~exportMetadataCmd()
{
}
{
return metadataBase::checkArgs( argsDb );
}
MStatus exportMetadataCmd::doCreate()
{
assert( fSerializer );
assert( fObjects.length() == 1 );
assert( status );
if( ! status ) return status;
displayInfo( node.name(&status) );
std::string errors;
if( fFile )
{
MString path( fFile->resolvedFullName() );
std::ofstream destination( fFile->resolvedFullName().asChar() );
if( fSerializer->write( *associationsToWrite, destination, errors ) == 0 )
{
setResult( path );
}
else
{
displayError( errMsg );
}
destination.close();
}
else
{
std::stringstream writtenData;
if( fSerializer->write( *associationsToWrite, writtenData, errors ) == 0 )
{
setResult( writtenData.str().c_str() );
}
else
{
displayError( errMsg );
}
}
if( errors.length() > 0 )
{
displayError( errors.c_str() );
}
}
MStatus exportMetadataCmd::doQuery()
{
assert( fSerializer );
std::set<const adsk::Data::StreamSerializer*>::iterator sFmtIt;
for( sFmtIt = adsk::Data::StreamSerializer::allFormats().begin();
sFmtIt != adsk::Data::StreamSerializer::allFormats().end(); sFmtIt++ )
{
MString fmtName( fmt->formatType() );
msg.
format( fmtMsg, fmtType, fmtName );
appendToResult( msg );
}
std::set<const adsk::Data::ChannelSerializer*>::iterator cFmtIt;
for( cFmtIt = adsk::Data::ChannelSerializer::allFormats().begin();
cFmtIt != adsk::Data::ChannelSerializer::allFormats().end(); cFmtIt++ )
{
MString fmtName( fmt->formatType() );
msg.
format( fmtMsg, fmtType, fmtName );
appendToResult( msg );
}
std::set<const adsk::Data::AssociationsSerializer*>::iterator aFmtIt;
for( aFmtIt = adsk::Data::AssociationsSerializer::allFormats().begin();
aFmtIt != adsk::Data::AssociationsSerializer::allFormats().end(); aFmtIt++ )
{
MString fmtName( fmt->formatType() );
msg.
format( fmtMsg, fmtType, fmtName );
appendToResult( msg );
}
std::set<const adsk::Data::StructureSerializer*>::iterator fmtIt;
for( fmtIt = adsk::Data::StructureSerializer::allFormats().begin();
fmtIt != adsk::Data::StructureSerializer::allFormats().end(); fmtIt++ )
{
MString fmtName( fmt->formatType() );
msg.
format( fmtMsg, fmtType, fmtName );
appendToResult( msg );
}
return status;
}