/* static */ UsdUISceneGraphPrimAPI UsdUISceneGraphPrimAPI::Apply(const UsdStagePtr &stage, const SdfPath &path) { // Ensure we have a valid stage, path and prim if (!stage) { TF_CODING_ERROR("Invalid stage"); return UsdUISceneGraphPrimAPI(); } if (path == SdfPath::AbsoluteRootPath()) { TF_CODING_ERROR("Cannot apply an api schema on the pseudoroot"); return UsdUISceneGraphPrimAPI(); } auto prim = stage->GetPrimAtPath(path); if (!prim) { TF_CODING_ERROR("Prim at <%s> does not exist.", path.GetText()); return UsdUISceneGraphPrimAPI(); } TfToken apiName("SceneGraphPrimAPI"); // Get the current listop at the edit target UsdEditTarget editTarget = stage->GetEditTarget(); SdfPrimSpecHandle primSpec = editTarget.GetPrimSpecForScenePath(path); SdfTokenListOp listOp = primSpec->GetInfo(UsdTokens->apiSchemas) .UncheckedGet<SdfTokenListOp>(); // Append our name to the prepend list, if it doesnt exist locally TfTokenVector prepends = listOp.GetPrependedItems(); if (std::find(prepends.begin(), prepends.end(), apiName) != prepends.end()) { return UsdUISceneGraphPrimAPI(); } SdfTokenListOp prependListOp; prepends.push_back(apiName); prependListOp.SetPrependedItems(prepends); auto result = listOp.ApplyOperations(prependListOp); if (!result) { TF_CODING_ERROR("Failed to prepend api name to current listop."); return UsdUISceneGraphPrimAPI(); } // Set the listop at the current edit target and return the API prim primSpec->SetInfo(UsdTokens->apiSchemas, VtValue(*result)); return UsdUISceneGraphPrimAPI(prim); }
char * getApiName(void){ return apiName(); }