Skip to content

Commit

Permalink
implement PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wen Tan committed Apr 27, 2018
1 parent 97af892 commit e6a2f63
Showing 1 changed file with 57 additions and 31 deletions.
88 changes: 57 additions & 31 deletions lib/AL_USDMaya/AL/usdmaya/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "maya/MGlobal.h"
#include "maya/MFnDependencyNode.h"
#include "maya/MItDependencyNodes.h"
#include "maya/MFnDagNode.h"

#include <iostream>

Expand Down Expand Up @@ -100,53 +99,79 @@ AL::event::CallbackId Global::m_postRead;
AL::event::CallbackId Global::m_fileNew;

//----------------------------------------------------------------------------------------------------------------------

//class of MObjects
MSelectionList selected;
static MSelectionList g_selected;

//Store the current selection list, but dont store AL_USD proxies
static void storeSelection()
{
MGlobal::displayInfo("storeSelection()");
//set "selected" to the current selection list
MGlobal::getActiveSelectionList(selected);
for( int i=0; i<selected.length(); ++i )
TF_DEBUG(ALUSDMAYA_EVENTS).Msg("storeSelection\n");
MGlobal::getActiveSelectionList(g_selected);

// some utils that test for AL types, but which only initialise function sets when it's possible
// that the type may be a plugin shape or transform. Avoids a tonne of function set initialisations
// and string compares on the types.
auto isProxyShape = [] (MDagPath p) {
if(p.node().hasFn(MFn::kPluginShape)) {
return MFnDagNode(p).typeName() == "AL_usdmaya_ProxyShape";
}
return false;
};
auto isTransform = [] (MDagPath p) {
if(p.node().hasFn(MFn::kPluginTransformNode)) {
return MFnDagNode(p).typeName() == "AL_usdmaya_Transform";
}
return false;
};

for(int i = 0; i < g_selected.length(); /* empty */ )
{
MObject obj;
selected.getDependNode(i,obj);
MFnDependencyNode fnParent(obj);
// Remove if type is AL_usdmaya_Transform
if (fnParent.typeName() == "AL_usdmaya_Transform")
// grab item as a dag path (skip over materials/textures/etc)
MDagPath selectedPath;
if(!g_selected.getDagPath(i, selectedPath))
{
MGlobal::unselectByName(fnParent.name().asChar());
++i;
continue;
}
MFnDagNode fnDagNode(obj);
// Unselect nodes which have AL_usdmaya_ProxyShape as a child
for( int i=0; i!=fnDagNode.childCount(); ++i ) {
MObject obj = fnDagNode.child(i);
MFnDagNode fnChild(obj);
if (fnChild.typeName() == "AL_usdmaya_ProxyShape")

// test for any selected proxy shapes or transform nodes
if(isProxyShape(selectedPath) || isTransform(selectedPath))
{
// remove node from selection list
g_selected.remove(i);
continue;
}

// test for any parents of proxy shapes selected (don't iterate over all children, just the shape nodes below)
uint32_t num = 0, j;
selectedPath.numberOfShapesDirectlyBelow(num);
for(j = 0; j < num; ++j)
{
MDagPath child = selectedPath;
child.extendToShapeDirectlyBelow(j); //< only care about shape nodes (rather than ALL children!)
if(isProxyShape(child))
{
MGlobal::unselectByName(fnParent.name().asChar());
MGlobal::unselectByName(fnChild.name().asChar());
g_selected.remove(i);
break;
}
}

// if none found, increment count
if(j == num)
{
++i;
}
}
//Reset selection list after removal of AL proxies
MGlobal::getActiveSelectionList(selected);

}

//Reselect the selection stored in storeSelection()
static void restoreSelection()
{
MGlobal::displayInfo("restoreSelection()");
// iterate through the list of items set by storeSelection()
for( int i=0; i<selected.length(); ++i )
{
MObject obj;
selected.getDependNode(i,obj);
MFnDependencyNode fn(obj);
MGlobal::selectByName(fn.name().asChar());
}
TF_DEBUG(ALUSDMAYA_EVENTS).Msg("restoreSelection\n");
MGlobal::setActiveSelectionList(g_selected);
}

//----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -289,6 +314,7 @@ static void _preFileSave()
// those AL::usdmaya::nodes::Transform nodes that are created because they are required, or have been requested).

// Selection will be restored to the selection prior to the clearing in the post save.

storeSelection();

MGlobal::clearSelectionList();
Expand Down Expand Up @@ -333,7 +359,7 @@ static void postFileSave(void*)

nodes::LayerManager* layerManager = nodes::LayerManager::findManager();
if (layerManager)
{
{
AL_MAYA_CHECK_ERROR2(layerManager->clearSerialisationAttributes(), "postFileSave");
}
// Restore selection cleared by _preFileSave()
Expand Down

0 comments on commit e6a2f63

Please sign in to comment.