#include "sceneAssemblyStrings.h"
#include "adskSceneMetadataCmd.h"
#include <maya/MSyntax.h>
#include <maya/MGlobal.h>
#include <maya/adskDataAssociations.h>
#include <maya/adskDataAccessor.h>
#include <maya/adskDataAccessorMaya.h>
#include <maya/adskDataStream.h>
#include <iostream>
#include <string>
using namespace std;
const char gStructureName [] = "adskSceneMetadataCmdStructure";
const char gMemberName [] = "adskSceneMetadataCmdDataString";
const char gStreamName [] = "adskSceneMetadataCmdStream";
AdskSceneMetadataCmd::AdskSceneMetadataCmd()
: fMode(kEdit)
{
}
AdskSceneMetadataCmd::~AdskSceneMetadataCmd()
{
}
void* AdskSceneMetadataCmd::creator()
{
return new AdskSceneMetadataCmd();
}
MSyntax AdskSceneMetadataCmd::cmdSyntax()
{
return syntax;
}
const char* AdskSceneMetadataCmd::name()
{
return "adskSceneMetadataCmd";
}
{
if ( !status )
{
return status;
}
if (argsDb.isEdit())
{
if (argsDb.isQuery())
{
}
fMode = kEdit;
}
else if (argsDb.isQuery())
{
fMode = kQuery;
}
fChannelName.parse ( argsDb, "-channelName" );
fData.parse ( argsDb, "-data" );
if ( !fData.isModeValid(fMode) )
{
}
if ( !fChannelName.isSet() || !fChannelName.isArgValid() || fChannelName.arg() == "" )
{
}
status = argsDb.getObjects( objs );
switch ( fMode )
{
case kEdit: status = doEdit( scenePath ); break;
case kQuery: status = doQuery( scenePath ); break;
default: break;
}
return status;
}
{
return setMetadata( scenePath );
}
{
return getMetadata( scenePath );
}
{
std::string errors;
std::auto_ptr< Accessor > accessor( getAccessorForScene( scenePath ) );
if ( NULL == accessor.get() )
{
}
if (
MS::kSuccess != getSceneAssociations(*(accessor.get()), associations) )
{
}
std::string channelName( fChannelName.arg().asChar() );
if ( NULL == channel )
{
setResult( "" );
}
if ( 0 == channel->dataStreamCount() )
{
errorString.
format( errorString, fChannelName.arg() );
displayError( errorString );
}
Stream *stream = channel->dataStream( 0 );
{
errorString.
format( errorString, fChannelName.arg() );
displayError( errorString );
}
{
errorString.
format( errorString, gMemberName, fChannelName.arg() );
displayError( errorString );
}
if ( Member::kString != handle.
dataType() )
{
errorString.
format( errorString, fChannelName.arg() );
displayError( errorString );
}
setResult( strings[0] );
}
{
std::string errors;
std::auto_ptr< Accessor > accessor( getAccessorForScene( scenePath ) );
if ( NULL == accessor.get() )
{
setResult( false );
}
if (
MS::kSuccess != getSceneAssociations(*(accessor.get()), associations) )
{
setResult( false );
}
for ( Structure::ListIterator itrStructList = Structure::allStructures().begin(); itrStructList != Structure::allStructures().end(); ++itrStructList )
{
if ( std::string((*itrStructList)->name()) == std::string(gStructureName) )
{
structure = *itrStructList;
break;
}
}
if ( NULL == structure )
{
structure = Structure::create();
structure->
setName( gStructureName );
structure->
addMember( Member::kString, 1, gMemberName );
Structure::registerStructure( *structure );
}
if ( accessorStructures.find( structure ) == accessorStructures.end() )
{
updatedStructures.insert( structure );
accessor->setStructures( updatedStructures );
}
std::string channelName( fChannelName.arg().asChar() );
Stream stream( *structure, std::string( gStreamName ) );
channel.setDataStream( stream );
std::string dataString( fData.arg().asChar() );
if ( 0 != handle.
fromStr( dataString, 0, errors ) )
{
errorString.
format( errorString, fChannelName.arg(), errors.c_str() );
displayError( errorString );
setResult( false );
}
if ( !accessor->write( errors ) )
{
displayError( errorString );
setResult( false );
}
setResult( true );
}
std::auto_ptr< Accessor > AdskSceneMetadataCmd::getAccessorForScene(
MString scenePath )
{
std::string errors;
std::string stdScenePath( scenePath.
asChar() );
std::auto_ptr< Accessor > accessor( Accessor::accessorByExtension( stdScenePath ) );
if ( NULL == accessor.get() )
{
errorString.
format( errorString, scenePath );
displayError( errorString );
return std::auto_ptr< Accessor >();
}
std::set< std::string > wantedAssociations;
wantedAssociations.insert( AccessorMaya::getSceneAssociationsName() );
if ( !accessor->read( stdScenePath,
NULL,
&wantedAssociations,
errors ) )
{
errorString.
format( errorString, scenePath, errors.c_str() );
displayError( errorString );
return std::auto_ptr< Accessor >();
}
return accessor;
}
{
Accessor::AssociationsMap::const_iterator iterAssociations = associationsMap.find( AccessorMaya::getSceneAssociationsName() );
if ( iterAssociations == associationsMap.end() )
{
out_associations = Associations::create();
accessor.
associations()[AccessorMaya::getSceneAssociationsName()] = out_associations;
}
else
{
out_associations = (*iterAssociations).second;
}
}