MStatus PRTAttrs::updateRuleFiles(MFnDependencyNode & node, MString & rulePkg) { PRTNode* prtNode = (PRTNode*)node.userNode(); MStatus stat; std::string utf8Path(rulePkg.asUTF8()); std::vector<char> percentEncodedPath(2*utf8Path.size()+1); size_t len = percentEncodedPath.size(); prt::StringUtils::percentEncode(utf8Path.c_str(), &percentEncodedPath[0], &len); if(len > percentEncodedPath.size()+1){ percentEncodedPath.resize(len); prt::StringUtils::percentEncode(utf8Path.c_str(), &percentEncodedPath[0], &len); } std::string uri(FILE_PREFIX); uri.append(&percentEncodedPath[0]); prtNode->mLRulePkg = uri; if(prtNode->mCreatedInteractively) { int count = (int)node.attributeCount(&stat); MCHECK(stat); MObjectArray attrs; for(int i = 0; i < count; i++) { MObject attr = node.attribute(i, &stat); if(stat != MS::kSuccess) continue; attrs.append(attr); } for(unsigned int i = 0; i < attrs.length(); i++) { MPlug plug(node.object(), attrs[i]); MString name = plug.partialName(); if(prtNode->mBriefName2prtAttr.count(name.asWChar())) node.removeAttribute(attrs[i]); } prtNode->destroyEnums(); } else { node.removeAttribute(node.attribute(NAME_GENERATE, &stat)); MCHECK(stat); } prtNode->mRuleFile.clear(); prtNode->mStartRule.clear(); MString unpackDir = MGlobal::executeCommandStringResult("workspace -q -fullName"); unpackDir += "/assets"; prt::Status resolveMapStatus = prt::STATUS_UNSPECIFIED_ERROR; std::wstring utf16URI; utf16URI.resize(uri.size()+1); len = utf16URI.size(); if(prt::StringUtils::toUTF16FromUTF8(uri.c_str(), &utf16URI[0], &len)) { utf16URI.resize(len); prt::StringUtils::toUTF16FromUTF8(uri.c_str(), &utf16URI[0], &len); } prtNode->mResolveMap = prt::createResolveMap(utf16URI.c_str(), unpackDir.asWChar(), &resolveMapStatus); if(resolveMapStatus == prt::STATUS_OK) { size_t nKeys; const wchar_t * const* keys = prtNode->mResolveMap->getKeys(&nKeys); std::wstring sCGB(L".cgb"); for(size_t k = 0; k < nKeys; k++) { std::wstring key = std::wstring(keys[k]); if(std::equal(sCGB.rbegin(), sCGB.rend(), key.rbegin())) { prtNode->mRuleFile = key; break; } } } else { prtNode->mResolveMap = 0; } if(prtNode->mRuleFile.length() > 0) updateStartRules(node); return MS::kSuccess; }
Helium::TUID Maya::GetNodeID( const MObject& node, bool create ) { if (node == MObject::kNullObj) { return Helium::TUID::Null; } MObject attr = MObject::kNullObj; MStatus status = MS::kFailure; MFnDependencyNode nodeFn (node); if ( create ) { // // GUID->TUID legacy handling // // look for the old GUID attribute attr = nodeFn.attribute(MString (s_GUIDAttributeName), &status); // if we found it if ( status == MS::kSuccess && !attr.isNull() ) { // get the GUID value MString str; MPlug plug (node, attr); status = plug.getValue(str); HELIUM_ASSERT( status != MS::kFailure ); // parse it Helium::GUID id; bool parsed = id.FromString(str.asTChar()); HELIUM_ASSERT( parsed ); // convert it to a TUID and set the new attribute Helium::TUID tuid; tuid.FromGUID( id ); status = SetNodeID( node, tuid ); HELIUM_ASSERT( status != MS::kFailure ); // check to see if we are a locked node bool nodeWasLocked = nodeFn.isLocked(); if ( nodeWasLocked ) { // turn off any node locking so an attribute can be added nodeFn.setLocked( false ); } // unlock the attribute status = plug.setLocked( false ); HELIUM_ASSERT( status != MS::kFailure ); // remove the attribute status = nodeFn.removeAttribute( attr ); HELIUM_ASSERT( status != MS::kFailure ); // reset to the prior state of wasLocked if ( nodeWasLocked ) { nodeFn.setLocked( nodeWasLocked ); } } } // look for the TUID attribute attr = nodeFn.attribute(MString (s_TUIDAttributeName)); // retrieve the attribute value (may be empty if we are not creating a new id) MString str; MPlug plug (node, attr); plug.getValue(str); // if we don't have an existing id and we should create one if ( str.length() == 0 && create ) { // generate a new ID Helium::TUID id( Helium::TUID::Generate() ); // set the new ID value on the node if( SetNodeID( node, id ) ) { return id; } else { return Helium::TUID::Null; } } // parse the value (this may be null if we did not create the attribute) Helium::TUID id; id.FromString(str.asTChar()); return id; }