@@ -206,20 +206,7 @@ void LiveScene::path( Path &p ) const
206206 throw Exception ( " IECoreMaya::LiveScene::path: Dag path no longer exists!" );
207207 }
208208
209- std::string pathStr ( m_dagPath.fullPathName ().asChar () );
210- boost::tokenizer<boost::char_separator<char > > t ( pathStr, boost::char_separator<char >( " |" ) );
211-
212- p.clear ();
213-
214- for (
215- boost::tokenizer<boost::char_separator<char > >::iterator it = t.begin ();
216- it != t.end ();
217- ++it
218- )
219- {
220- p.push_back ( Name ( *it ) );
221- }
222-
209+ dagPathToPath ( m_dagPath, p );
223210}
224211
225212Imath::Box3d LiveScene::readBound ( double time ) const
@@ -1122,6 +1109,66 @@ void LiveScene::hash( HashType hashType, double time, MurmurHash &h ) const
11221109 throw Exception ( " Hashes currently not supported in IECoreMaya::LiveScene objects." );
11231110}
11241111
1112+ void LiveScene::dagPathToPath ( MDagPath dagPath, IECoreScene::SceneInterface::Path &path )
1113+ {
1114+ tbb::recursive_mutex::scoped_lock l ( g_mutex );
1115+ path.clear ();
1116+
1117+ if ( dagPath.isValid () )
1118+ {
1119+ // Only transforms can be part of the path
1120+ if ( !dagPath.hasFn ( MFn::kTransform ) )
1121+ {
1122+ dagPath.pop ();
1123+ }
1124+
1125+ const std::string pathStr ( dagPath.fullPathName ().asChar () );
1126+ const boost::tokenizer< boost::char_separator<char > > tokens ( pathStr, boost::char_separator<char >( " |" ) );
1127+ for ( const auto &token : tokens )
1128+ {
1129+ path.push_back ( token );
1130+ }
1131+
1132+ return ;
1133+ }
1134+
1135+ throw Exception ( " IECoreMaya::LiveScene::dagPathToPath invalid dag path." );
1136+ }
1137+
1138+ void LiveScene::pathToDagPath ( const IECoreScene::SceneInterface::Path &path, MDagPath &dagPath )
1139+ {
1140+ tbb::recursive_mutex::scoped_lock l ( g_mutex );
1141+
1142+ if ( path.empty () )
1143+ {
1144+ MItDag itDag;
1145+ itDag.getPath ( dagPath );
1146+ return ;
1147+ }
1148+
1149+ std::string dagPathStr;
1150+ for ( const auto &name : path )
1151+ {
1152+ dagPathStr += " |" ;
1153+ dagPathStr += name;
1154+ }
1155+
1156+ MSelectionList sel;
1157+ if ( sel.add ( dagPathStr.c_str () ) && sel.getDagPath ( 0 , dagPath ) )
1158+ {
1159+ return ;
1160+ }
1161+
1162+ // Invalid dag path
1163+ std::string pathStr;
1164+ IECoreScene::SceneInterface::pathToString ( path, pathStr );
1165+ throw Exception (
1166+ boost::str (
1167+ boost::format ( " IECoreMaya::LiveScene::pathToDagPath invalid conversion to dag path from \" %1%\" ." ) % pathStr
1168+ )
1169+ );
1170+ }
1171+
11251172void LiveScene::registerCustomObject ( HasFn hasFn, ReadFn readFn )
11261173{
11271174 CustomReader r;
0 commit comments