#define _MApiVersion
#include <maya/MCursor.h>
#include <maya/MGlobal.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MIOStream.h>
#include <maya/MItMeshVertex.h>
#include <maya/MPlug.h>
#include "meshReorderTool.h"
#include "meshMapUtils.h"
meshReorderTool::meshReorderTool()
{
    setTitleString ( "Mesh Reorder Tool" );
    reset();
}
meshReorderTool::~meshReorderTool() {}
void* meshReorderTool::creator()
{
    return new meshReorderTool;
}
void meshReorderTool::toolOnSetup ( 
MEvent & )
 
{
    reset();
}
void meshReorderTool::reset()
{
    fNumSelectedPoints = 0;
    fSelectedPathSrc.clear();
    fSelectedComponentSrc.clear();
    fSelectVtxSrc.clear();
    fSelectedFaceSrc = -1;
    fCurrentHelpString = "Select 1st point on mesh.";
    helpStateHasChanged( e );
}
{
    char buf[1024];
    
    
    
    
    
    if( fSelectionList.length() != 1 )
    {
    }
    
    
    
    selectionIt.getStrings( selections );
    
    if( selections.
length() != 1 )
 
    {
    }
    if (selectionIt.isDone ())
    {
    }
    {
    }
    {
    }
    MPlug   historyPlug = meshFn.findPlug(
"inMesh", 
true);
 
    {
    }
    {
    }
    if (fIt.count() != 1 )
    {
        sprintf(buf, " Invalid selection '%s'. Vertices must be picked one at a time.", selections[0].asChar() );
    }
    else
    {
        sprintf(buf, "Accepting vertex '%s'", selections[0].asChar() );
    }
    
    
    
    fSelectedPathSrc.append( path );
    fSelectedComponentSrc.append( component );
    
    
    
    
    if( fNumSelectedPoints == 2 )
    {
        if( ( stat = meshMapUtils::validateFaceSelection( fSelectedPathSrc, fSelectedComponentSrc, &fSelectedFaceSrc, &fSelectVtxSrc ) ) != 
MStatus::kSuccess )
 
        {
            reset();
            return stat;
        }
        char cmdString[200];
        sprintf(cmdString, "meshReorder %s.vtx[%d] %s.vtx[%d] %s.vtx[%d]", 
                            fSelectedPathSrc[0].partialPathName().asChar(), fSelectVtxSrc[0],
                            fSelectedPathSrc[1].partialPathName().asChar(), fSelectVtxSrc[1],
                            fSelectedPathSrc[2].partialPathName().asChar(), fSelectVtxSrc[2]);
        if (stat)
        {
        }
        
        
        
        
        
        
        reset();    
    }
    else
    {
        
        
        
        fNumSelectedPoints++;   
    }
    helpStateHasChanged( event );
    return stat;
}
{
    switch (fNumSelectedPoints)
    {
        case 0:
         fCurrentHelpString = "Select 1st vertex on mesh";
         break;
        case 1:
         fCurrentHelpString = "Select 2nd vertex, connected to 1st vertex and on the same face";
         break;
        case 2:
         fCurrentHelpString = "Select 3rd vertex, connected to 2nd vertex and on the same face";
         break;
        default:
         
         break;
     }
    setHelpString( fCurrentHelpString );
}
{
    return new meshReorderTool;
}
void* meshReorderContextCmd::creator()
{
    return new meshReorderContextCmd;
}