#include "sceneAssemblyStrings.h"
#include "adskRepresentationCmd.h"
#include "assemblyDefinition.h"
#include <maya/MSyntax.h>
#include <maya/MGlobal.h>
#include <iostream>
#include <string>
#include <ciso646>
#if defined( _WIN32 ) || defined( _LIBCPP_VERSION )
#include <unordered_map>
#define ADSTD std
#else
#include <tr1/unordered_map>
#define ADSTD std::tr1
#endif
using namespace std;
namespace {
class RegistryEntry {
public:
RegistryEntry() : fTypeLabel() {}
~RegistryEntry() {}
MString typeLabel()
const {
return fTypeLabel; }
MString aeRepresentationProc()
const {
return fAERepresentationProc; }
void setTypeLabel(
const MString& typeLabel) {
fTypeLabel = typeLabel;
}
void setAERepresentationProc(
const MString& proc) {
fAERepresentationProc = proc;
}
private:
};
typedef ADSTD::unordered_map< std::string, RegistryEntry > AdskRepresentationRegistry;
AdskRepresentationRegistry fRegistry;
}
AdskRepresentationCmd::AdskRepresentationCmd()
: fMode(kEdit)
{}
AdskRepresentationCmd::~AdskRepresentationCmd()
{}
void* AdskRepresentationCmd::creator()
{
return new AdskRepresentationCmd();
}
MSyntax AdskRepresentationCmd::cmdSyntax()
{
return syntax;
}
const char* AdskRepresentationCmd::name()
{
return "adskRepresentation";
}
{
if (!status) return status;
if (argsDb.isEdit()) {
if (argsDb.isQuery()) {
return MS::kFailure;
}
fMode = kEdit;
}
else if (argsDb.isQuery()) {
fMode = kQuery;
}
fTypeLabelFlag.parse( argsDb, "-typeLabel");
fAERepresentationProcFlag.parse( argsDb, "-updateAERepresentationProc");
fListRepTypesFlag.parse( argsDb, "-listRepTypes");
if (!fListRepTypesFlag.isModeValid(fMode)) {
return MS::kFailure;
}
status = argsDb.getObjects(objs);
if(needObjectArg()) {
return MS::kFailure;
}
} else {
repType = objs[0];
}
switch (fMode) {
case kEdit: status = doEdit(repType); break;
case kQuery: status = doQuery(repType); break;
}
return status;
}
{
if (fTypeLabelFlag.isSet()) {
assert(fTypeLabelFlag.isArgValid());
AdskRepresentationRegistry::iterator found = fRegistry.find(repType.
asChar());
RegistryEntry entry = (found == fRegistry.end()) ? RegistryEntry() : found->second;
entry.setTypeLabel(fTypeLabelFlag.arg());
fRegistry[string(repType.
asChar())] = entry;
setResult(fTypeLabelFlag.arg());
}
else if (fAERepresentationProcFlag.isSet()) {
assert(fAERepresentationProcFlag.isArgValid());
AdskRepresentationRegistry::iterator found = fRegistry.find(repType.
asChar());
RegistryEntry entry = (found == fRegistry.end()) ? RegistryEntry() : found->second;
entry.setAERepresentationProc(fAERepresentationProcFlag.arg());
fRegistry[string(repType.
asChar())] = entry;
setResult(fAERepresentationProcFlag.arg());
}
return MS::kSuccess;
}
{
if (fTypeLabelFlag.isSet()) {
AdskRepresentationRegistry::const_iterator found = fRegistry.find(repType.
asChar());
if (found == fRegistry.end()) {
return MS::kFailure;
}
setResult(found->second.typeLabel());
}else if (fAERepresentationProcFlag.isSet()) {
AdskRepresentationRegistry::const_iterator found = fRegistry.find(repType.
asChar());
if (found == fRegistry.end()) {
return MS::kFailure;
}
setResult(found->second.aeRepresentationProc());
}else if (fListRepTypesFlag.isSet()) {
MStringArray representations = AssemblyDefinition::registeredTypes();
setResult(representations);
}
return MS::kSuccess;
}
bool AdskRepresentationCmd::needObjectArg() const
{
return !fListRepTypesFlag.isSet();
}