#include "importMetadataCmd.h"
#include "metadataPluginStrings.h"
#include <maya/MObject.h>
#include <maya/MSyntax.h>
#include <maya/MStatus.h>
#include <maya/MString.h>
#include <maya/MStringResource.h>
#include <maya/MArgDatabase.h>
#include <maya/MFileObject.h>
#include <maya/adskDataStream.h>
#include <maya/adskDataChannel.h>
#include <maya/adskDataAssociations.h>
#include <maya/adskDataAssociationsSerializer.h>
#include <maya/adskDataChannelSerializer.h>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
static const char* flagString ( "-s" );
static const char* flagStringLong ( "-string" );
void* importMetadataCmd::creator()
{
return new importMetadataCmd;
}
const char* importMetadataCmd::name()
{
return "importMetadata";
}
MSyntax importMetadataCmd::cmdSyntax()
{
MSyntax syntax = metadataBase::cmdSyntax();
return syntax;
}
importMetadataCmd::importMetadataCmd()
{
}
importMetadataCmd::~importMetadataCmd()
{
}
bool
importMetadataCmd::isUndoable() const
{
return fMode == kCreate;
}
{
MStatus status = metadataBase::checkArgs( argsDb );
fStringFlag.parse(argsDb, flagString);
if( fStringFlag.isSet() )
{
if( fFile )
{
msg.
format( fmt, flagString );
displayWarning( msg );
}
if( !fStringFlag.isModeValid(fMode) )
{
msg.
format( fmt, flagString );
displayError(msg);
}
if( ! fStringFlag.isArgValid() )
{
displayError( errMsg );
}
fString = fStringFlag.arg();
}
else if( ! fFile )
{
msg.
format( fmt, flagString );
displayError( msg );
}
else if( ! fFile->exists() )
{
displayError(msg);
}
return status;
}
MStatus importMetadataCmd::doCreate()
{
assert( fSerializer );
std::string errors;
if( fString.length() > 0 )
{
std::stringstream inStream( fString.asChar() );
associationsRead = fSerializer->read( inStream, errors );
if( ! associationsRead )
{
displayError(msg);
}
}
else if( fFile )
{
std::ifstream inStream( fFile->resolvedFullName().asChar() );
associationsRead = fSerializer->read( inStream, errors );
inStream.close();
if( ! associationsRead )
{
msg.
format( fmt, fFile->resolvedFullName(), err );
displayError(msg);
}
}
else
{
assert( fFile );
}
assert( associationsRead );
for( unsigned int i=0; i<fObjects.length(); ++i )
{
displayInfo( node.name(&status) );
fDGModifier.setMetadata( fObjects[i], *associationsRead );
{
for( unsigned int c=0; c<associationsRead->channelCount(); ++c )
{
{
if( cStream )
{
msg.
format( resultFmt, node.name(), cName, sName );
appendToResult( msg );
}
}
}
}
else
{
msg.
format( fmt, node.name() );
displayError( msg );
}
}
return status;
}
MStatus importMetadataCmd::redoIt()
{
return fDGModifier.doIt();
}
MStatus importMetadataCmd::undoIt()
{
return fDGModifier.undoIt();
}