From 696d90909d77dfe7651e870de68111788f1685c6 Mon Sep 17 00:00:00 2001 From: davidsminor Date: Fri, 16 May 2014 14:23:31 -0700 Subject: [PATCH] Scene shape component names SceneShapeInterface::componentNames() and SceneShapeInterface::selectionName() now automatically refresh the gl scene when they're called, in case they get called before a maya viewport refresh has happened --- python/IECoreMaya/FnSceneShape.py | 10 ++++++---- src/IECoreMaya/SceneShapeInterface.cpp | 4 ++++ test/IECoreMaya/FnSceneShapeTest.py | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/python/IECoreMaya/FnSceneShape.py b/python/IECoreMaya/FnSceneShape.py index ddbea44bf2..981dfd8119 100644 --- a/python/IECoreMaya/FnSceneShape.py +++ b/python/IECoreMaya/FnSceneShape.py @@ -132,7 +132,8 @@ def selectComponentNames( self, componentNames ) : componentNames = set( componentNames ) fullPathName = self.fullPathName() - allnames = self.componentNames() + allNames = self.componentNames() + toSelect = [] for i, name in enumerate( allNames ): if name in componentNames: toSelect.append( fullPathName + ".f[" + str( i ) + "]" ) @@ -140,8 +141,9 @@ def selectComponentNames( self, componentNames ) : maya.cmds.select( clear=True ) maya.cmds.selectMode( component=True ) maya.cmds.hilite( fullPathName ) - for s in toSelect : - maya.cmds.select( s, add=True ) + if toSelect: + maya.cmds.select( toSelect, r=True ) + ## Returns the full path name to this node. def fullPathName( self ) : @@ -157,7 +159,7 @@ def fullPathName( self ) : def sceneInterface( self ) : return _IECoreMaya._sceneShapeSceneInterface( self ) - + def componentNames( self ) : return _IECoreMaya._sceneShapeComponentNames( self ) diff --git a/src/IECoreMaya/SceneShapeInterface.cpp b/src/IECoreMaya/SceneShapeInterface.cpp index 596b7ce7fe..8f82834d17 100644 --- a/src/IECoreMaya/SceneShapeInterface.cpp +++ b/src/IECoreMaya/SceneShapeInterface.cpp @@ -1384,11 +1384,15 @@ int SceneShapeInterface::selectionIndex( const IECore::InternedString &name ) IECore::InternedString SceneShapeInterface::selectionName( int index ) { + // make sure the gl scene's been built, as this keeps m_indexToNameMap up to date + const_cast( this )->glScene(); return m_indexToNameMap[index]; } const std::vector< InternedString > & SceneShapeInterface::componentNames() const { + // make sure the gl scene's been built, as this keeps m_indexToNameMap up to date + const_cast( this )->glScene(); return m_indexToNameMap; } diff --git a/test/IECoreMaya/FnSceneShapeTest.py b/test/IECoreMaya/FnSceneShapeTest.py index 9d4f68ccb6..4cbe092ad5 100644 --- a/test/IECoreMaya/FnSceneShapeTest.py +++ b/test/IECoreMaya/FnSceneShapeTest.py @@ -195,8 +195,21 @@ def testConvertAllToGeometry( self ): self.assertEqual( maya.cmds.getAttr( "|test|sceneShape_1|sceneShape_SceneShape1.queryPaths[1]" ), "/" ) self.assertTrue( maya.cmds.isConnected( "|test|sceneShape_1|sceneShape_SceneShape1.outObjects[1]", "|test|sceneShape_1|sceneShape_Shape1.inMesh" ) ) - + def testComponentNames( self ): + + maya.cmds.file( new=True, f=True ) + fn = IECoreMaya.FnSceneShape.create( "test" ) + maya.cmds.setAttr( fn.fullPathName()+'.file', FnSceneShapeTest.__testFile,type='string' ) + maya.cmds.setAttr( fn.fullPathName()+".drawGeometry", 0 ) + self.assertEqual( fn.componentNames(), [] ) + + maya.cmds.setAttr( fn.fullPathName()+".drawGeometry", 1 ) + self.assertEqual( fn.componentNames(), ['/', '/1', '/1/child', '/1/child/3'] ) + + fn.selectComponentNames( ['/', '/1', '/1/child/3'] ) + self.assertEqual( fn.selectedComponentNames(), set( ['/', '/1', '/1/child/3'] ) ) + def tearDown( self ) : if os.path.exists( FnSceneShapeTest.__testFile ) :