xmlAssembly/CacheRep.cpp
 
 
 
xmlAssembly/CacheRep.cpp
//-
//**************************************************************************/
// Copyright (c) 2012 Autodesk, Inc.
// All rights reserved.
//
// These coded instructions, statements, and computer programs contain
// unpublished proprietary information written by Autodesk, Inc., and are
// protected by Federal copyright law. They may not be disclosed to third
// parties or copied or duplicated in any form, in whole or in part, without
// the prior written consent of Autodesk, Inc.
//**************************************************************************/
//+

#include <CacheRep.h>

#include "XMLAssembly.h"
#include "FnAssetInstance.h"
#include "AssetGuidManager.h"
#include "AssetLibManager.h"
#include "Utility.h"
#include "XMLStrings.h"

#include <maya/MObjectArray.h>
#include <maya/MDagModifier.h>
#include <maya/MFnDagNode.h>
#include <maya/MFnContainerNode.h>
#include <maya/MPlug.h>
#include <maya/MStringArray.h>


//==============================================================================
// CLASS CacheRep
//==============================================================================

//------------------------------------------------------------------------------
//
CacheRep::CacheRep(
         MObject assembly, const MString& guid
        )
        : BaseClass(assembly, guid)
{}

//------------------------------------------------------------------------------
//
CacheRep::~CacheRep()
{}

//------------------------------------------------------------------------------
//
bool CacheRep::activate()
{
    if( !isValidRepresentation())
    {
        //TODO::display errors
        return false;
    }
        if (BaseClass::activate())
    {
                return true;
    }
        
        // get cache file
        MStringArray filenameArray;
    theGuidManager.findPathByGuid( fGuid, filenameArray);
    MString filename;
        if (filenameArray.length() == 0)
    {
        //TODO::display errors
                return false;
    }
    filename = filenameArray[ 0];
    if( filename.length() == 0)
    {
        //TODO::display errors
        return false;
    }
    
        
        CurrentContainerGuard guard( fAssembly);

        // Create a gpuCache node in, and parent it to our container.
        MDagModifier dagMod;
        MStatus status;
        MObject cacheObj = dagMod.createNode(
                MString("gpuCache"), fAssembly, &status);

        if (status != MStatus::kSuccess) {
                return false;
        }
        status = dagMod.doIt();
        if (status != MStatus::kSuccess) {
                return false;
        }

        // Set the cache attribute to point to our Alembic file.
        MFnDependencyNode cache(cacheObj);
        MPlug fnPlug = cache.findPlug(MString("cacheFileName"), true, &status);
        if (status != MStatus::kSuccess) {
                return false;
        }
        // TODO: convert relative file path to absolute path
        MString resolvedPath = theAssetLibMgr.getAbsoluteFilename( filename);
        fnPlug.setValue( resolvedPath);

        registerRepNode(cacheObj);
        
        return status == MStatus::kSuccess;
}

//------------------------------------------------------------------------------
//
MString CacheRep::type()
{
        return XMLStrings::kwCacheType;
}

//------------------------------------------------------------------------------
//
MString CacheRep::getType() const
{
        return type();
}