#include <maya/MStatus.h>
#include <maya/MObject.h>
#include <maya/MFnPlugin.h>
#include <maya/MString.h>
#include <maya/MVector.h>
#include <maya/MStringArray.h>
#include <maya/MPxFileTranslator.h>
#include <maya/MGlobal.h>
#include <maya/MItDag.h>
#include <maya/MObject.h>
#include <maya/MPlug.h>
#include <maya/MItSelectionList.h>
#include <maya/MSelectionList.h>
#include <maya/MIOStream.h>
#include <maya/MFStream.h>
#include <maya/MFileIO.h>
#include <maya/MFnTransform.h>
#include <maya/MNamespace.h>
#include <string.h>
public:
    
    LepTranslator () {};
    
    virtual            ~LepTranslator () {};
    
    
    
    
    
    
    
    
    
    
    static void* creator();
    
    
    
    
    
    
    
    
    
                                                const char* buffer,
                                                short size) const;
    
    
private:
    
    
};
void* LepTranslator::creator()
{
    return new LepTranslator();
}
MString const LepTranslator::magic(
"<LEP>");
 
{    
    const int maxLineSize = 1024;
    char buf[maxLineSize];
    ifstream inputfile(fname.
asChar(), ios::in);
    if (!inputfile) {
        
        cerr << fname << ": could not be opened for reading\n";
    }
    if (!inputfile.getline (buf, maxLineSize)) {
        cerr << "file " << fname << " contained no lines ... aborting\n";
    }
    if (0 != strncmp(buf, magic.asChar(), magic.length())) {
        cerr << "first line of file " << fname;
        cerr << 
" did not contain " << magic.
asChar() << 
" ... aborting\n";
    }
    while (inputfile.getline (buf, maxLineSize)) {
    }
    inputfile.close();
    return rval;
}
const char* primitiveStrings[] = {
    "nurbsSphere",
    "nurbsCone",
    "nurbsCylinder",
};
const unsigned numPrimitives = sizeof(primitiveStrings) / sizeof(char*);
const char* primitiveCommands[] = {
    "sphere",
    "cone",
    "cylinder",
};
{
    bool showPositions = false;
    unsigned int  i;
    ofstream newf(fname.
asChar(), ios::out);
    if (!newf) {
        
        cerr << fname << ": could not be opened for reading\n";
    }
    newf.setf(ios::unitbuf);
        
        options.
split(
';', optionList);    
        
        for( i = 0; i < optionList.
length(); ++i ){
 
            optionList[i].split( '=', theOption );
            if( theOption[0] == 
MString(
"showPositions") &&
 
                if( theOption[1].asInt() > 0 ){
                    showPositions = true;
                }else{
                    showPositions = false;
                }
            }
        }
    }
    
    newf << "<LEP>\n";
    if ( !status) {
        status.
perror (
"Failure in DAG iterator setup");
    }
    bool done = false;
    while (true) 
    {
        switch (mode)
        {
                if (dagIterator.isDone ())
                    done = true;
                else {
                    currentNode = dagIterator.item ();
                    dagIterator.next ();
                }
                break;
                if (selIterator.isDone ())
                    done = true;
                else {
                    selIterator.getDependNode (currentNode);
                    selIterator.next ();
                }
                break;
            default:
                cerr << "Unrecognized write mode: " << mode << endl;
                break;
        }
        if (done)
            break;
        
        {
            for (i = 0; i < numPrimitives; ++i) {                
                if(nodeNameNoNamespace.
indexW(primitiveStrings[i]) >= 0){
 
                    
                    newf << primitiveCommands[i] << " -n " << nodeNameNoNamespace << endl;
                    if (showPositions) {
                        newf << 
"move " << pos.
x << 
" " << pos.
y << 
" " << pos.
z << endl;
                    }
                }
            }
        }
    }
    newf.close();
}
MString LepTranslator::defaultExtension ()
 const 
{
    return "lep";
}
                                        const char* buffer,
                                        short size) const
{
    
    
    MFileKind rval = kNotMyFileType;
    if ((size >= (short)magic.length()) &&
        (0 == strncmp(buffer, magic.asChar(), magic.length()))) 
    {
        rval = kIsMyFileType;
    }
    return rval;
}
{
    MFnPlugin plugin( obj, PLUGIN_COMPANY, 
"3.0", 
"Any");
 
    
    
    
    
    
    
    
    status =  plugin.registerFileTranslator( "Lep",
                                        "lepTranslator.rgb",
                                        LepTranslator::creator,
                                        "lepTranslatorOpts",
                                        "showPositions=1",
                                        true );
    if (!status) 
    {
        status.
perror(
"registerFileTranslator");
        return status;
    }
    return status;
}
{
    status =  plugin.deregisterFileTranslator( "Lep" );
    if (!status)
    {
        status.
perror(
"deregisterFileTranslator");
        return status;
    }
    return status;
}