コード例 #1
0
ファイル: adaptor.cpp プロジェクト: PixarAnimationStudios/USD
void
UsdMayaAdaptor::UnapplySchemaByName(
    const TfToken& schemaName,
    MDGModifier& modifier)
{
    if (!*this) {
        TF_CODING_ERROR("Adaptor is not valid");
        return;
    }

    // Remove from schema list.
    TfTokenVector currentSchemas = GetAppliedSchemas();
    currentSchemas.erase(
            std::remove(
                currentSchemas.begin(), currentSchemas.end(), schemaName),
            currentSchemas.end());
    if (currentSchemas.empty()) {
        ClearMetadata(UsdTokens->apiSchemas, modifier);
    }
    else {
        SetMetadata(
                UsdTokens->apiSchemas,
                _GetListOpForTokenVector(currentSchemas),
                modifier);
    }
}
コード例 #2
0
ファイル: prim.cpp プロジェクト: lvxejay/USD
bool
UsdPrim::_HasAPI(const TfType& schemaType, bool validateSchemaType) const 
{
    if (validateSchemaType) {
        if (schemaType.IsUnknown()) {
            TF_CODING_ERROR("Unknown schema type (%s) is invalid for HasAPI query",
                            schemaType.GetTypeName().c_str());
            return false;
        }

        // Note that this is only hit in python code paths,
        // C++ clients would hit the static_asserts defined in prim.h
        auto schemaRegistry = UsdSchemaRegistry::GetInstance();
        if (schemaRegistry.IsConcrete(schemaType)) {
            TF_CODING_ERROR("Provided schema type must be non-concrete");  
            return false;
        }

        if (schemaRegistry.IsTyped(schemaType)) {
            TF_CODING_ERROR("Provided schema type must be untyped");
            return false;
        }
    }

    // Get our composed set of applied schemas
    static const auto usdSchemaBase = TfType::FindByName("UsdSchemaBase");
    auto appliedSchemas = GetAppliedSchemas();
    if (appliedSchemas.empty()) {
        return false;
    }

    auto foundMatch = [&appliedSchemas](const std::string& alias) {
        return std::find(appliedSchemas.begin(), appliedSchemas.end(), alias) 
               != appliedSchemas.end();
    };

    // See if our schema is directly authored
    for (const auto& alias : usdSchemaBase.GetAliases(schemaType)) {
        if (foundMatch(alias)) { return true; }
    }

    // If we couldn't find it directly authored in apiSchemas, 
    // consider derived types. For example, if a user queries
    // prim.HasAPI<UsdModelAPI>() on a prim with 
    // apiSchemas = ["UsdGeomModelAPI"], we should return true
    std::set<TfType> derivedTypes;
    schemaType.GetAllDerivedTypes(&derivedTypes);
    for (const auto& derived : derivedTypes) {
        for (const auto& alias : usdSchemaBase.GetAliases(derived)) {
            if (foundMatch(alias)) { return true; }
        }
    }

    return false;
}
コード例 #3
0
ファイル: adaptor.cpp プロジェクト: PixarAnimationStudios/USD
UsdMayaAdaptor::SchemaAdaptor
UsdMayaAdaptor::ApplySchemaByName(
    const TfToken& schemaName,
    MDGModifier& modifier)
{
    if (!*this) {
        TF_CODING_ERROR("Adaptor is not valid");
        return SchemaAdaptor();
    }

    // Get the schema's TfType; its name should be registered as an alias.
    const TfType schemaType =
            TfType::Find<UsdSchemaBase>().FindDerivedByName(schemaName);

    // Make sure that this is an API schema. Only API schemas can be applied.
    if (!schemaType.IsA<UsdAPISchemaBase>()) {
        TF_CODING_ERROR("'%s' is not a registered API schema",
                schemaName.GetText());
        return SchemaAdaptor();
    }

    // Make sure that this is an "apply" schema.
    if (!UsdSchemaRegistry::GetInstance().IsAppliedAPISchema(schemaType)) {
        TF_CODING_ERROR("'%s' is not an applied API schema",
                schemaName.GetText());
        return SchemaAdaptor();
    }

    // Get the schema definition. If it's registered, there should be a def.
    SdfPrimSpecHandle primDef =
            UsdSchemaRegistry::GetInstance().GetPrimDefinition(schemaName);
    if (!primDef) {
        TF_CODING_ERROR("Can't find schema definition for name '%s'",
                schemaName.GetText());
        return SchemaAdaptor();
    }

    // Add to schema list (if not yet present).
    TfTokenVector currentSchemas = GetAppliedSchemas();
    if (std::find(currentSchemas.begin(), currentSchemas.end(), schemaName) ==
            currentSchemas.end()) {
        currentSchemas.push_back(schemaName);
        SetMetadata(
                UsdTokens->apiSchemas,
                _GetListOpForTokenVector(currentSchemas),
                modifier);
    }

    return SchemaAdaptor(_handle.object(), primDef);
}