From 1c02d9d2baa4f06bdf5a967fb0acc64225811153 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Mon, 26 Aug 2024 08:49:11 -0700 Subject: [PATCH 01/15] Apple: Accessibility and Localization API schemas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds two applied API schemas to UsdUI as an attempt to make it a Universally Accessible Scene Description. Disclaimer: This addition does not represent any future feature support in our products. These schemas are borne out of discussing the needs for the ecosystem to accommodate a wider range of users. 2. Localization schema as discussed at ## Overview A brief overview of the two schemas: ### Accessibility API [Proposal](https://github.com/PixarAnimationStudios/OpenUSD-proposals/tree/main/proposals/accessibility) ``` def "Foo"( apiSchemas = ["AccessibilityAPI:default"] ) { string accessibility:label = "Short Label" string accessibility:description = "A longer description of this prim" uniform token priority = "standard" } ``` UsdUIAccessibilityAPI is a multiple apply schema. Each instance has three attributes: label: A short description of the prim description: An extended description of the prim priority: A hint to a runtime on how this instance should be valued The default instance does not namespace itself with the instance name as we believe it will be the only one specified in many cases, and the excess namespace doesn't add clarity. As a convenience, the API specifies a default name so users of Apply() do not need to specify a name most of the time. ### Localization API [Proposal](https://github.com/PixarAnimationStudios/OpenUSD-proposals/tree/main/proposals/language) ``` def "Foo" ( apiSchemas = ["LocalizationAPI:default", "LocalizationAPI:fr_CA"] ) { uniform token localization:lang = "en_US" custom string foo = "Hello" custom string foo:lang:fr_CA = "Bonjour" custom string foo:lang:hi_IN = "नमस्ते" } ``` UsdUILocalizationAPI is also a multiple apply schema. However here it uses the multiple apply to denote what language are available or that a default localization is available on a prim. It includes one attribute that doesn't use an instance name called `localization:langauge` which specifies the default language to assume. All other applications are suffixed to properties with `:lang:` ## Feedback and Remaining Work It would be greatly appreciated if feedback could be provided with a focus on the schema first so we can nail down how to represent the data in the USD. I also haven't finished wrapping the LocalizationAPI methods in Python because I would like to first get feedback on the C++ API so that I may iterate faster. Once we feel the API looks good, I'll handle the Python bindings and write appropriate tests for them as well. --- pxr/usd/usdUI/CMakeLists.txt | 28 ++ pxr/usd/usdUI/accessibilityAPI.cpp | 303 ++++++++++++ pxr/usd/usdUI/accessibilityAPI.h | 335 +++++++++++++ pxr/usd/usdUI/generatedSchema.usda | 122 +++++ pxr/usd/usdUI/localizationAPI.cpp | 456 ++++++++++++++++++ pxr/usd/usdUI/localizationAPI.h | 365 ++++++++++++++ pxr/usd/usdUI/plugInfo.json | 20 + pxr/usd/usdUI/schema.usda | 164 ++++++- .../testenv/testUsdUIAcessibilityAPI.cpp | 91 ++++ .../testenv/testUsdUILocalizationAPI.cpp | 73 +++ pxr/usd/usdUI/tokens.cpp | 34 ++ pxr/usd/usdUI/tokens.h | 70 ++- pxr/usd/usdUI/wrapAccessibilityAPI.cpp | 202 ++++++++ pxr/usd/usdUI/wrapLocalizationAPI.cpp | 186 +++++++ 14 files changed, 2447 insertions(+), 2 deletions(-) create mode 100644 pxr/usd/usdUI/accessibilityAPI.cpp create mode 100644 pxr/usd/usdUI/accessibilityAPI.h create mode 100644 pxr/usd/usdUI/localizationAPI.cpp create mode 100644 pxr/usd/usdUI/localizationAPI.h create mode 100644 pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp create mode 100644 pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp create mode 100644 pxr/usd/usdUI/wrapAccessibilityAPI.cpp create mode 100644 pxr/usd/usdUI/wrapLocalizationAPI.cpp diff --git a/pxr/usd/usdUI/CMakeLists.txt b/pxr/usd/usdUI/CMakeLists.txt index 9d10ca1915..812bb3ed04 100644 --- a/pxr/usd/usdUI/CMakeLists.txt +++ b/pxr/usd/usdUI/CMakeLists.txt @@ -42,3 +42,31 @@ pxr_register_test(testUsdUISceneGraphPrim PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUISceneGraphPrim" ) + +pxr_build_test(testUsdUIAcessibilityAPI + LIBRARIES + tf + usd + usdUI + CPPFILES + testenv/testUsdUIAcessibilityAPI.cpp +) + +pxr_register_test(testUsdUIAcessibilityAPI + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUIAcessibilityAPI" + EXPECTED_RETURN_CODE 0 +) + +pxr_build_test(testUsdUILocalizationAPI + LIBRARIES + tf + usd + usdUI + CPPFILES + testenv/testUsdUILocalizationAPI.cpp +) + +pxr_register_test(testUsdUILocalizationAPI + COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUILocalizationAPI" + EXPECTED_RETURN_CODE 0 +) \ No newline at end of file diff --git a/pxr/usd/usdUI/accessibilityAPI.cpp b/pxr/usd/usdUI/accessibilityAPI.cpp new file mode 100644 index 0000000000..8bef735352 --- /dev/null +++ b/pxr/usd/usdUI/accessibilityAPI.cpp @@ -0,0 +1,303 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdUI/accessibilityAPI.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + +} + +/* virtual */ +UsdUIAccessibilityAPI::~UsdUIAccessibilityAPI() +{ +} + +/* static */ +UsdUIAccessibilityAPI +UsdUIAccessibilityAPI::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdUIAccessibilityAPI(); + } + TfToken name; + if (!IsAccessibilityAPIPath(path, &name)) { + TF_CODING_ERROR("Invalid accessibility path <%s>.", path.GetText()); + return UsdUIAccessibilityAPI(); + } + return UsdUIAccessibilityAPI(stage->GetPrimAtPath(path.GetPrimPath()), name); +} + +UsdUIAccessibilityAPI +UsdUIAccessibilityAPI::Get(const UsdPrim &prim, const TfToken &name) +{ + return UsdUIAccessibilityAPI(prim, name); +} + +/* static */ +std::vector +UsdUIAccessibilityAPI::GetAll(const UsdPrim &prim) +{ + std::vector schemas; + + for (const auto &schemaName : + UsdAPISchemaBase::_GetMultipleApplyInstanceNames(prim, _GetStaticTfType())) { + schemas.emplace_back(prim, schemaName); + } + + return schemas; +} + + +/* static */ +bool +UsdUIAccessibilityAPI::IsSchemaPropertyBaseName(const TfToken &baseName) +{ + static TfTokenVector attrsAndRels = { + UsdSchemaRegistry::GetMultipleApplyNameTemplateBaseName( + UsdUITokens->accessibility_MultipleApplyTemplate_Label), + UsdSchemaRegistry::GetMultipleApplyNameTemplateBaseName( + UsdUITokens->accessibility_MultipleApplyTemplate_Description), + UsdSchemaRegistry::GetMultipleApplyNameTemplateBaseName( + UsdUITokens->accessibility_MultipleApplyTemplate_Priority), + }; + + return find(attrsAndRels.begin(), attrsAndRels.end(), baseName) + != attrsAndRels.end(); +} + +/* static */ +bool +UsdUIAccessibilityAPI::IsAccessibilityAPIPath( + const SdfPath &path, TfToken *name) +{ + if (!path.IsPropertyPath()) { + return false; + } + + std::string propertyName = path.GetName(); + TfTokenVector tokens = SdfPath::TokenizeIdentifierAsTokens(propertyName); + + // The baseName of the path can't be one of the + // schema properties. We should validate this in the creation (or apply) + // API. + TfToken baseName = *tokens.rbegin(); + if (IsSchemaPropertyBaseName(baseName)) { + return false; + } + + if (tokens.size() >= 2 + && tokens[0] == UsdUITokens->accessibility) { + *name = TfToken(propertyName.substr( + UsdUITokens->accessibility.GetString().size() + 1)); + return true; + } + + return false; +} + +/* virtual */ +UsdSchemaKind UsdUIAccessibilityAPI::_GetSchemaKind() const +{ + return UsdUIAccessibilityAPI::schemaKind; +} + +/* static */ +bool +UsdUIAccessibilityAPI::CanApply( + const UsdPrim &prim, const TfToken &name, std::string *whyNot) +{ + return prim.CanApplyAPI(name, whyNot); +} + +/* static */ +UsdUIAccessibilityAPI +UsdUIAccessibilityAPI::Apply(const UsdPrim &prim, const TfToken &name) +{ + if (prim.ApplyAPI(name)) { + return UsdUIAccessibilityAPI(prim, name); + } + return UsdUIAccessibilityAPI(); +} + +/* static */ +const TfType & +UsdUIAccessibilityAPI::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdUIAccessibilityAPI::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdUIAccessibilityAPI::_GetTfType() const +{ + return _GetStaticTfType(); +} + +/// Returns the property name prefixed with the correct namespace prefix, which +/// is composed of the the API's propertyNamespacePrefix metadata and the +/// instance name of the API. +static inline +TfToken +_GetNamespacedPropertyName(const TfToken instanceName, const TfToken propName) +{ + std::string propertyName = UsdUITokens->accessibility.GetString() + ":"; + if (instanceName != UsdUITokens->default_) { + propertyName += instanceName.GetString() + ":"; + } + propertyName += propName.GetString(); + return TfToken(propertyName); +} + +UsdAttribute +UsdUIAccessibilityAPI::GetLabelAttr() const +{ + return GetPrim().GetAttribute( + _GetNamespacedPropertyName( + GetName(), + UsdUITokens->label)); +} + +UsdAttribute +UsdUIAccessibilityAPI::CreateLabelAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr( + _GetNamespacedPropertyName( + GetName(), + UsdUITokens->label), + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdUIAccessibilityAPI::GetDescriptionAttr() const +{ + return GetPrim().GetAttribute( + _GetNamespacedPropertyName( + GetName(), + UsdUITokens->description)); +} + +UsdAttribute +UsdUIAccessibilityAPI::CreateDescriptionAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr( + _GetNamespacedPropertyName( + GetName(), + UsdUITokens->description), + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdUIAccessibilityAPI::GetPriorityAttr() const +{ + return GetPrim().GetAttribute( + _GetNamespacedPropertyName( + GetName(), + UsdUITokens->priority)); +} + +UsdAttribute +UsdUIAccessibilityAPI::CreatePriorityAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr( + _GetNamespacedPropertyName( + GetName(), + UsdUITokens->priority), + SdfValueTypeNames->Token, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +namespace { +static inline TfTokenVector +_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) +{ + TfTokenVector result; + result.reserve(left.size() + right.size()); + result.insert(result.end(), left.begin(), left.end()); + result.insert(result.end(), right.begin(), right.end()); + return result; +} +} + +/*static*/ +const TfTokenVector& +UsdUIAccessibilityAPI::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + UsdUITokens->accessibility_MultipleApplyTemplate_Label, + UsdUITokens->accessibility_MultipleApplyTemplate_Description, + UsdUITokens->accessibility_MultipleApplyTemplate_Priority, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + UsdAPISchemaBase::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +/*static*/ +TfTokenVector +UsdUIAccessibilityAPI::GetSchemaAttributeNames( + bool includeInherited, const TfToken &instanceName) +{ + const TfTokenVector &attrNames = GetSchemaAttributeNames(includeInherited); + if (instanceName.IsEmpty()) { + return attrNames; + } + TfTokenVector result; + result.reserve(attrNames.size()); + for (const TfToken &attrName : attrNames) { + result.push_back( + UsdSchemaRegistry::MakeMultipleApplyNameInstance(attrName, instanceName)); + } + return result; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- diff --git a/pxr/usd/usdUI/accessibilityAPI.h b/pxr/usd/usdUI/accessibilityAPI.h new file mode 100644 index 0000000000..05f0fb536c --- /dev/null +++ b/pxr/usd/usdUI/accessibilityAPI.h @@ -0,0 +1,335 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDUI_GENERATED_ACCESSIBILITYAPI_H +#define USDUI_GENERATED_ACCESSIBILITYAPI_H + +/// \file usdUI/accessibilityAPI.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdUI/api.h" +#include "pxr/usd/usd/apiSchemaBase.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdUI/tokens.h" + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// ACCESSIBILITYAPI // +// -------------------------------------------------------------------------- // + +/// \class UsdUIAccessibilityAPI +/// +/// +/// This API describes \em Accessibility information on a Prim that may be surfaced to a given runtimes +/// accessibility frameworks. +/// This information may be used by assistive tooling such as voice controls or screen readers. +/// Accessibility information is provided as a standard triplet of label, description and priority. +/// +/// OpenUSD does not provide a accessibility runtime itself, but endeavours to provide the information needed for +/// compatible runtimes to extract and present this information. +/// +/// This is a multiple apply schema, and so may have multiple namespaced accessibility triplets, where a instance +/// name may reflect a given purpose for that triplet. For example, you may desire to express different +/// information for different aspects of the prim, such as size or color. +/// +/// \note The API will use \em default as an instance name if no namespace is specified. +/// When using "default" as the name, the instance name is elided from the attribute name. +/// +/// There are several best practices for using this schema.: +/// +/// \li Most accessibility runtimes support a single accessibility description. Therefore we recommend placing +/// any critical information in the default instance. +/// +/// \li A default value should be authored if using time sampled accessibility information. +/// This helps accessibility runtimes that do not currently support time sampled information. +/// +/// \li Provide accessibility information of your scene on the default prim of the layer, and any top level prims. +/// This allows accessibility systems to provide concise scene descriptions to a user, but also allows supporting +/// accessibility systems that either do not support hierarchy information or when a user has turned off that level +/// of granularity. Accessibility information may still be provided on other prims in the hierarchy. +/// +/// \note The use of the default prim and top level prims for scene accessibility descriptions is a +/// recommended convention. Outside of that, accessibility information is not implicitly inherited through +/// a prim hierarchy. The inheritance should be left to the accessibility runtime to decide how best to +/// surface information to users. +/// +/// +/// For any described attribute \em Fallback \em Value or \em Allowed \em Values below +/// that are text/tokens, the actual token is published and defined in \ref UsdUITokens. +/// So to set an attribute to the value "rightHanded", use UsdUITokens->rightHanded +/// as the value. +/// +class UsdUIAccessibilityAPI : public UsdAPISchemaBase +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::MultipleApplyAPI; + + /// Construct a UsdUIAccessibilityAPI on UsdPrim \p prim with + /// name \p name . Equivalent to + /// UsdUIAccessibilityAPI::Get( + /// prim.GetStage(), + /// prim.GetPath().AppendProperty( + /// "accessibility:name")); + /// + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdUIAccessibilityAPI( + const UsdPrim& prim=UsdPrim(), const TfToken &name=UsdUITokens->default_) + : UsdAPISchemaBase(prim, /*instanceName*/ name) + { } + + /// Construct a UsdUIAccessibilityAPI on the prim held by \p schemaObj with + /// name \p name. Should be preferred over + /// UsdUIAccessibilityAPI(schemaObj.GetPrim(), name), as it preserves + /// SchemaBase state. + explicit UsdUIAccessibilityAPI( + const UsdSchemaBase& schemaObj, const TfToken &name=UsdUITokens->default_) + : UsdAPISchemaBase(schemaObj, /*instanceName*/ name) + { } + + /// Destructor. + USDUI_API + virtual ~UsdUIAccessibilityAPI(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + USDUI_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes for a given instance name. Does not + /// include attributes that may be authored by custom/extended methods of + /// the schemas involved. The names returned will have the proper namespace + /// prefix. + USDUI_API + static TfTokenVector + GetSchemaAttributeNames(bool includeInherited, const TfToken &instanceName); + + /// Returns the name of this multiple-apply schema instance + TfToken GetName() const { + return _GetInstanceName(); + } + + /// Return a UsdUIAccessibilityAPI holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. \p path must be of the format + /// .accessibility:name . + /// + /// This is shorthand for the following: + /// + /// \code + /// TfToken name = SdfPath::StripNamespace(path.GetToken()); + /// UsdUIAccessibilityAPI( + /// stage->GetPrimAtPath(path.GetPrimPath()), name); + /// \endcode + /// + USDUI_API + static UsdUIAccessibilityAPI + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Return a UsdUIAccessibilityAPI with name \p name holding the + /// prim \p prim. Shorthand for UsdUIAccessibilityAPI(prim, name); + USDUI_API + static UsdUIAccessibilityAPI + Get(const UsdPrim &prim, const TfToken &name); + + /// Return a vector of all named instances of UsdUIAccessibilityAPI on the + /// given \p prim. + USDUI_API + static std::vector + GetAll(const UsdPrim &prim); + + /// Checks if the given name \p baseName is the base name of a property + /// of AccessibilityAPI. + USDUI_API + static bool + IsSchemaPropertyBaseName(const TfToken &baseName); + + /// Checks if the given path \p path is of an API schema of type + /// AccessibilityAPI. If so, it stores the instance name of + /// the schema in \p name and returns true. Otherwise, it returns false. + USDUI_API + static bool + IsAccessibilityAPIPath(const SdfPath &path, TfToken *name); + + /// Returns true if this multiple-apply API schema can be applied, + /// with the given instance name, \p name, to the given \p prim. If this + /// schema can not be a applied the prim, this returns false and, if + /// provided, populates \p whyNot with the reason it can not be applied. + /// + /// Note that if CanApply returns false, that does not necessarily imply + /// that calling Apply will fail. Callers are expected to call CanApply + /// before calling Apply if they want to ensure that it is valid to + /// apply a schema. + /// + /// \sa UsdPrim::GetAppliedSchemas() + /// \sa UsdPrim::HasAPI() + /// \sa UsdPrim::CanApplyAPI() + /// \sa UsdPrim::ApplyAPI() + /// \sa UsdPrim::RemoveAPI() + /// + USDUI_API + static bool + CanApply(const UsdPrim &prim, const TfToken &name, + std::string *whyNot=nullptr); + + /// Applies this multiple-apply API schema to the given \p prim + /// along with the given instance name, \p name. + /// + /// This information is stored by adding "AccessibilityAPI:name" + /// to the token-valued, listOp metadata \em apiSchemas on the prim. + /// For example, if \p name is 'instance1', the token + /// 'AccessibilityAPI:instance1' is added to 'apiSchemas'. + /// + /// \return A valid UsdUIAccessibilityAPI object is returned upon success. + /// An invalid (or empty) UsdUIAccessibilityAPI object is returned upon + /// failure. See \ref UsdPrim::ApplyAPI() for + /// conditions resulting in failure. + /// + /// \sa UsdPrim::GetAppliedSchemas() + /// \sa UsdPrim::HasAPI() + /// \sa UsdPrim::CanApplyAPI() + /// \sa UsdPrim::ApplyAPI() + /// \sa UsdPrim::RemoveAPI() + /// + USDUI_API + static UsdUIAccessibilityAPI + Apply(const UsdPrim &prim, const TfToken &name=UsdUITokens->default_); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDUI_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDUI_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDUI_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // LABEL + // --------------------------------------------------------------------- // + /// A short label to concisely describe the prim. + /// It is not recommended to time vary the label unless the concise description changes substantially. + /// + /// | || + /// | -- | -- | + /// | Declaration | `string label` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + USDUI_API + UsdAttribute GetLabelAttr() const; + + /// See GetLabelAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDUI_API + UsdAttribute CreateLabelAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // DESCRIPTION + // --------------------------------------------------------------------- // + /// An extended description of the prim to provide more details. + /// If a label attribute is not authored in a given instance name, the description attribute should not be used + /// in it its place. A description is an optional attribute, and some accessibility systems may only use the label. + /// + /// Descriptions may be time varying for runtimes that support it. For example, you may describe what a character + /// is doing at a given time. + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `string description` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + USDUI_API + UsdAttribute GetDescriptionAttr() const; + + /// See GetDescriptionAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDUI_API + UsdAttribute CreateDescriptionAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // PRIORITY + // --------------------------------------------------------------------- // + /// A hint to the accessibility runtime of how to prioritize this instances label and description, + /// relative to others. This attribute is optional. Accessibility runtimes may choose to apply their own + /// priority systems that override this. + /// + /// Priority may not be time varying. + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform token priority = "standard"` | + /// | C++ Type | TfToken | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdUITokens "Allowed Values" | low, standard, high | + USDUI_API + UsdAttribute GetPriorityAttr() const; + + /// See GetPriorityAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDUI_API + UsdAttribute CreatePriorityAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdUI/generatedSchema.usda b/pxr/usd/usdUI/generatedSchema.usda index 7c4001ba46..ddd40dc3f3 100644 --- a/pxr/usd/usdUI/generatedSchema.usda +++ b/pxr/usd/usdUI/generatedSchema.usda @@ -130,3 +130,125 @@ class Backdrop "Backdrop" ( ) } +class "AccessibilityAPI" ( + doc = ''' + This API describes Accessibility information on a Prim that may be surfaced to a given runtimes + accessibility frameworks. + This information may be used by assistive tooling such as voice controls or screen readers. + Accessibility information is provided as a standard triplet of label, description and priority. + + OpenUSD does not provide a accessibility runtime itself, but endeavours to provide the information needed for + compatible runtimes to extract and present this information. + + This is a multiple apply schema, and so may have multiple namespaced accessibility triplets, where a instance + name may reflect a given purpose for that triplet. For example, you may desire to express different + information for different aspects of the prim, such as size or color. + + \\note The API will use default as an instance name if no namespace is specified. + When using "default" as the name, the instance name is elided from the attribute name. + + There are several best practices for using this schema.: + + - Most accessibility runtimes support a single accessibility description. Therefore we recommend placing + any critical information in the default instance. + + - A default value should be authored if using time sampled accessibility information. + This helps accessibility runtimes that do not currently support time sampled information. + + - Provide accessibility information of your scene on the default prim of the layer, and any top level prims. + This allows accessibility systems to provide concise scene descriptions to a user, but also allows supporting + accessibility systems that either do not support hierarchy information or when a user has turned off that level + of granularity. Accessibility information may still be provided on other prims in the hierarchy. + + \\note The use of the default prim and top level prims for scene accessibility descriptions is a + recommended convention. Outside of that, accessibility information is not implicitly inherited through + a prim hierarchy. The inheritance should be left to the accessibility runtime to decide how best to + surface information to users. + ''' +) +{ + string accessibility:__INSTANCE_NAME__:description ( + doc = """An extended description of the prim to provide more details. + If a label attribute is not authored in a given instance name, the description attribute should not be used + in it its place. A description is an optional attribute, and some accessibility systems may only use the label. + + Descriptions may be time varying for runtimes that support it. For example, you may describe what a character + is doing at a given time. + """ + ) + string accessibility:__INSTANCE_NAME__:label ( + doc = """A short label to concisely describe the prim. + It is not recommended to time vary the label unless the concise description changes substantially.""" + ) + uniform token accessibility:__INSTANCE_NAME__:priority = "standard" ( + allowedTokens = ["low", "standard", "high"] + doc = """A hint to the accessibility runtime of how to prioritize this instances label and description, + relative to others. This attribute is optional. Accessibility runtimes may choose to apply their own + priority systems that override this. + + Priority may not be time varying. + """ + ) +} + +class "LocalizationAPI" ( + doc = """This API describes em Language localization information for attributes. + + It may be used to provide alternate language definitions for content like strings and asset paths that are + displayed to a user. + Runtimes may present the best language for a given users preference with this information. + + OpenUSD leaves it up to the runtime that is consuming it to handle localized presentations. + As such, support for localization may vary across runtimes. + + \\important Lookup of localized attributes may be expensive, so are recommended to be used sparingly + It is recommended, but not enforced, to only use them for strings and asset paths. + Support for localization of different attributes may vary depending on the application runtime that + the data is brought into. + + + \\note Language identifiers must use the BCP-47 list of languages. However, since USD cannot currently use + hyphens in identifiers, any hyphens are replaced with underscores. This is similar in strategy to other + systems that adhere closely to the Unicode Identifier specification. e.g en-ca is en_CA . + Take care when converting language identifiers to a systems own formatting. + + A default language is specifiable on a prim. This is the language that is assumed when attributes do + not include their own identifier for language. The default language is explicitly inherited by + all prims under the current prims hierarchy. + + \\note Provide default localization information on the default prim of the layer, and any top level prims. + It is not recommended to keep declarations of the default localization to a minimum throughout the rest of + the hierarchy within a single layer. + + Attributes are suffixed with :lang: when expressing languages other than the default. + + For example, \"string text\" would implicitly be in the default localization language, but you may have + \"string text:lang:fr\" for French. + + Runtimes may provide their own logic for choosing which langauge to display, but following BCP-47, + a recommended logic set is: + + - If a preferred language is available within the set of declared languages, pick that language exactly. + e.g \"en_CA\" should not pick simply \"en\" if \"en_CA\" is available + + - If a preferred language isn't available, check for a more specific version of that language. + e.g \"de_DE\" may match to \"de_DE_u_co_phonebk\" + + - If a more specific language is not available, pick a less specific language. + e.g \"en_US\" may match to \"en\" + + - If a less specific language choice is not available, pick the attribute without language specification. + """ +) +{ + uniform token localization:__INSTANCE_NAME__:language ( + doc = """The default language for this prim hierarchy. This may only be created with the default instance name. + + \\note If no default localization language is provided, the runtime may optionally try and infer the + language of the text. + If the runtime does not infer the langauge, it should assume the language is in the users preferred language, + which may be derived from the system or current user context. + """ + ) +} + diff --git a/pxr/usd/usdUI/localizationAPI.cpp b/pxr/usd/usdUI/localizationAPI.cpp new file mode 100644 index 0000000000..c61e45cd0a --- /dev/null +++ b/pxr/usd/usdUI/localizationAPI.cpp @@ -0,0 +1,456 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdUI/localizationAPI.h" + +#include "tokens.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" + +#include "pxr/usd/sdf/types.h" +#include "pxr/usd/sdf/assetPath.h" + +PXR_NAMESPACE_OPEN_SCOPE + +// Register the schema with the TfType system. +TF_REGISTRY_FUNCTION(TfType) +{ + TfType::Define >(); + +} + +/* virtual */ +UsdUILocalizationAPI::~UsdUILocalizationAPI() +{ +} + +/* static */ +UsdUILocalizationAPI +UsdUILocalizationAPI::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdUILocalizationAPI(); + } + TfToken name; + if (!IsLocalizationAPIPath(path, &name)) { + TF_CODING_ERROR("Invalid localization path <%s>.", path.GetText()); + return UsdUILocalizationAPI(); + } + return UsdUILocalizationAPI(stage->GetPrimAtPath(path.GetPrimPath()), name); +} + +UsdUILocalizationAPI +UsdUILocalizationAPI::Get(const UsdPrim &prim, const TfToken &name) +{ + return UsdUILocalizationAPI(prim, name); +} + +/* static */ +std::vector +UsdUILocalizationAPI::GetAll(const UsdPrim &prim) +{ + std::vector schemas; + + for (const auto &schemaName : + UsdAPISchemaBase::_GetMultipleApplyInstanceNames(prim, _GetStaticTfType())) { + schemas.emplace_back(prim, schemaName); + } + + return schemas; +} + + +/* static */ +bool +UsdUILocalizationAPI::IsSchemaPropertyBaseName(const TfToken &baseName) +{ + static TfTokenVector attrsAndRels = { + UsdSchemaRegistry::GetMultipleApplyNameTemplateBaseName( + UsdUITokens->localization_MultipleApplyTemplate_Language), + }; + + return find(attrsAndRels.begin(), attrsAndRels.end(), baseName) + != attrsAndRels.end(); +} + +/* static */ +bool +UsdUILocalizationAPI::IsLocalizationAPIPath( + const SdfPath &path, TfToken *name) +{ + if (!path.IsPropertyPath()) { + return false; + } + + std::string propertyName = path.GetName(); + TfTokenVector tokens = SdfPath::TokenizeIdentifierAsTokens(propertyName); + + // The baseName of the path can't be one of the + // schema properties. We should validate this in the creation (or apply) + // API. + TfToken baseName = *tokens.rbegin(); + if (IsSchemaPropertyBaseName(baseName)) { + return false; + } + + if (tokens.size() >= 2 + && tokens[0] == UsdUITokens->localization) { + *name = TfToken(propertyName.substr( + UsdUITokens->localization.GetString().size() + 1)); + return true; + } + + return false; +} + +/* virtual */ +UsdSchemaKind UsdUILocalizationAPI::_GetSchemaKind() const +{ + return UsdUILocalizationAPI::schemaKind; +} + +/* static */ +bool +UsdUILocalizationAPI::CanApply( + const UsdPrim &prim, const TfToken &name, std::string *whyNot) +{ + return prim.CanApplyAPI(name, whyNot); +} + +/* static */ +UsdUILocalizationAPI +UsdUILocalizationAPI::Apply(const UsdPrim &prim, const TfToken &name) +{ + if (prim.ApplyAPI(name)) { + return UsdUILocalizationAPI(prim, name); + } + return UsdUILocalizationAPI(); +} + +/* static */ +const TfType & +UsdUILocalizationAPI::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdUILocalizationAPI::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdUILocalizationAPI::_GetTfType() const +{ + return _GetStaticTfType(); +} + +UsdAttribute +UsdUILocalizationAPI::GetLanguageAttr() const +{ + return GetPrim().GetAttribute(UsdUITokens->languageAttribute); +} + +UsdAttribute +UsdUILocalizationAPI::CreateLanguageAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr( + UsdUITokens->languageAttribute, + SdfValueTypeNames->Token, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +namespace { +static inline TfTokenVector +_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) +{ + TfTokenVector result; + result.reserve(left.size() + right.size()); + result.insert(result.end(), left.begin(), left.end()); + result.insert(result.end(), right.begin(), right.end()); + return result; +} +} + +/*static*/ +const TfTokenVector& +UsdUILocalizationAPI::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + UsdUITokens->localization_MultipleApplyTemplate_Language, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + UsdAPISchemaBase::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +/*static*/ +TfTokenVector +UsdUILocalizationAPI::GetSchemaAttributeNames( + bool includeInherited, const TfToken &instanceName) +{ + const TfTokenVector &attrNames = GetSchemaAttributeNames(includeInherited); + if (instanceName.IsEmpty()) { + return attrNames; + } + TfTokenVector result; + result.reserve(attrNames.size()); + for (const TfToken &attrName : attrNames) { + result.push_back( + UsdSchemaRegistry::MakeMultipleApplyNameInstance(attrName, instanceName)); + } + return result; +} + +PXR_NAMESPACE_CLOSE_SCOPE + +// ===================================================================== // +// Feel free to add custom code below this line. It will be preserved by +// the code generator. +// +// Just remember to wrap code in the appropriate delimiters: +// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +PXR_NAMESPACE_OPEN_SCOPE + +/* static */ +UsdProperty +UsdUILocalizationAPI::GetDefaultProperty(UsdProperty const &source) { + const auto nameTokens = source.SplitName(); + + if (nameTokens.size() < 3 || nameTokens[nameTokens.size() - 2] != UsdUITokens->lang) { + // The most minimal name would be foo:lang:en_us + // If we have less than 3 tokens, we assume it doesn't have a language specifier. + // If the second last element isn't lang, we can assume the same as well + return source; + } + + const auto defaultName = TfStringJoin(nameTokens.begin(), nameTokens.end()-2, ":"); + + const auto prim = source.GetPrim(); + if (!prim) { + TF_CODING_ERROR("Cannot find parent prim"); + return {}; + } + + auto prop = prim.GetProperty(TfToken(defaultName)); + return prop; +} + + +TfToken UsdUILocalizationAPI::GetPropertyLanguage(UsdProperty const &prop) { + auto nameTokens = prop.SplitName(); + if (nameTokens.size() < 3 || nameTokens[nameTokens.size() - 2] != UsdUITokens->lang) { + return TfToken(); + } + + return TfToken(nameTokens[nameTokens.size() - 1]); +} + +/* static */ +TfToken +UsdUILocalizationAPI::GetLocalizedPropertyName(UsdProperty const &source, TfToken const &localization) { + // It's fastest to just get the default attribute + const auto defaultProp = GetDefaultProperty(source); + if (!defaultProp) { + TF_CODING_ERROR("Cannot find the default-localized attribute for this property"); + return {}; + } + + const auto sep = ":"; + const auto localizedName = ( + defaultProp.GetName().GetString() + sep + + UsdUITokens->lang.GetString() + sep + + localization.GetString() + ); + + return TfToken(localizedName); +} + +/* static */ +UsdProperty +UsdUILocalizationAPI::GetLocalizedProperty(UsdProperty const &source, TfToken const &localization) { + const auto prim = source.GetPrim(); + if (!prim) { + TF_CODING_ERROR("Cannot find attributes parent prim"); + return {}; + } + + const auto localizedAttrName = GetLocalizedPropertyName(source, localization); + return prim.GetProperty(TfToken(localizedAttrName)); +} + +UsdProperty +UsdUILocalizationAPI::GetLocalizedProperty(UsdProperty const &source) const { + return GetLocalizedProperty(source, GetName()); +} + +/* static */ +UsdAttribute +UsdUILocalizationAPI::CreateLocalizedAttribute(UsdAttribute const &source, TfToken const &localization, + VtValue const &defaultValue, bool writeSparsely) { + const auto prim = source.GetPrim(); + if (!prim) { + TF_CODING_ERROR("Cannot find attributes parent prim"); + return {}; + } + + if (writeSparsely) { + // From UsdSchemaBase::_CreateAttr + auto prop = GetLocalizedProperty(source, localization); + if (prop) { + UsdAttribute attr = prim.GetAttributeAtPath(prop.GetPath()); + if (!attr) { + TF_CODING_ERROR("Could not construct attribute from property"); + return {}; + } + + VtValue fallback; + if (defaultValue.IsEmpty() || + (!attr.HasAuthoredValue() + && attr.Get(&fallback) + && fallback == defaultValue)){ + return attr; + } + } + } + + auto property = UsdUILocalizationAPI::GetDefaultProperty(source); + if (!property) { + TF_CODING_ERROR("Could not find default property"); + return {}; + } + + UsdAttribute defaultAttr = prim.GetAttributeAtPath(property.GetPath()); + if (!defaultAttr) { + TF_CODING_ERROR("Could not construct attribute from property"); + return {}; + } + + UsdAttribute attr(prim.CreateAttribute( + UsdUILocalizationAPI::GetLocalizedPropertyName(source, localization), + defaultAttr.GetTypeName(), + defaultAttr.IsCustom(), + defaultAttr.GetVariability() + )); + + if (attr && !defaultValue.IsEmpty()) { + attr.Set(defaultValue); + } + + return attr; +} + +UsdAttribute +UsdUILocalizationAPI::CreateLocalizedAttribute(UsdAttribute const &source, VtValue const &defaultValue, + bool writeSparsely) const { + return CreateLocalizedAttribute(source, GetName(), defaultValue, writeSparsely); +} + +UsdRelationship +UsdUILocalizationAPI::CreateLocalizedRelationship(UsdRelationship const &source, TfToken const &localization) { + const auto prim = source.GetPrim(); + if (!prim) { + TF_CODING_ERROR("Cannot find attributes parent prim"); + return {}; + } + + auto property = UsdUILocalizationAPI::GetDefaultProperty(source); + if (!property) { + TF_CODING_ERROR("Could not find default property"); + return {}; + } + + UsdRelationship defaultRel = prim.GetRelationshipAtPath(property.GetPath()); + if (!defaultRel) { + TF_CODING_ERROR("Could not construct relationship from property"); + return {}; + } + + UsdRelationship rel(prim.CreateRelationship( + UsdUILocalizationAPI::GetLocalizedPropertyName(source, localization), + defaultRel.IsCustom() + )); + + return rel; +} + + +UsdRelationship +UsdUILocalizationAPI::CreateLocalizedRelationship(UsdRelationship const &source) const{ + return UsdUILocalizationAPI::CreateLocalizedRelationship(source, GetName()); +} + +/* static */ +UsdProperty +UsdUILocalizationAPI::GetAppliedPropertyLocalizations(UsdProperty const &source, + std::map &localizations) { + auto prim = source.GetPrim(); + if (!prim) { + TF_CODING_ERROR("Cannot find parent prim"); + return {}; + } + auto apis = UsdUILocalizationAPI::GetAll(source.GetPrim()); + auto defaultAttr = UsdUILocalizationAPI::GetDefaultProperty(source); + auto defaultAttrName = defaultAttr.GetName().GetString(); + const auto sep = ":"; + for (const auto &api: apis) { + auto attrName = defaultAttrName + sep + UsdUITokens->lang.GetString() + sep + api.GetName().GetString(); + auto attr = prim.GetAttribute(TfToken(attrName)); + if (attr) { + localizations.insert({api.GetName(), attr}); + } + } + return defaultAttr; +} + +/* static */ +UsdProperty +UsdUILocalizationAPI::GetAllPropertyLocalizations(UsdProperty const &source, + std::map &localizations) { + auto prim = source.GetPrim(); + if (!prim) { + TF_CODING_ERROR("Cannot find parent prim"); + return {}; + } + auto defaultAttr = UsdUILocalizationAPI::GetDefaultProperty(source); + + const auto sep = ":"; + auto prefix = defaultAttr.GetName().GetString() + sep + UsdUITokens->lang.GetString() + sep; + for (const auto &props: prim.GetProperties()) { + auto attrName = props.GetName().GetString(); + if (!TfStringStartsWith(attrName, prefix)) { + continue; + } + + auto locale = UsdUILocalizationAPI::GetPropertyLanguage(props); + if (!locale.IsEmpty()) { + localizations.insert({locale, props}); + } + } + + return defaultAttr; +} + +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/usd/usdUI/localizationAPI.h b/pxr/usd/usdUI/localizationAPI.h new file mode 100644 index 0000000000..d8261a2a5b --- /dev/null +++ b/pxr/usd/usdUI/localizationAPI.h @@ -0,0 +1,365 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#ifndef USDUI_GENERATED_LOCALIZATIONAPI_H +#define USDUI_GENERATED_LOCALIZATIONAPI_H + +/// \file usdUI/localizationAPI.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdUI/api.h" +#include "pxr/usd/usd/apiSchemaBase.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdUI/tokens.h" + +#include "pxr/base/vt/value.h" + +#include "pxr/base/gf/vec3d.h" +#include "pxr/base/gf/vec3f.h" +#include "pxr/base/gf/matrix4d.h" + +#include "pxr/base/tf/token.h" +#include "pxr/base/tf/type.h" + +PXR_NAMESPACE_OPEN_SCOPE + +class SdfAssetPath; + +// -------------------------------------------------------------------------- // +// LOCALIZATIONAPI // +// -------------------------------------------------------------------------- // + +/// \class UsdUILocalizationAPI +/// +/// This API describes em Language localization information for attributes. +/// +/// It may be used to provide alternate language definitions for content like strings and asset paths that are +/// displayed to a user. +/// Runtimes may present the best language for a given users preference with this information. +/// +/// OpenUSD leaves it up to the runtime that is consuming it to handle localized presentations. +/// As such, support for localization may vary across runtimes. +/// +/// \important Lookup of localized attributes may be expensive, so are recommended to be used sparingly +/// It is recommended, but not enforced, to only use them for strings and asset paths. +/// Support for localization of different attributes may vary depending on the application runtime that +/// the data is brought into. +/// +/// +/// \note Language identifiers must use the BCP-47 list of languages. However, since USD cannot currently use +/// hyphens in identifiers, any hyphens are replaced with underscores. This is similar in strategy to other +/// systems that adhere closely to the Unicode Identifier specification. e.g en-ca is en_CA . +/// Take care when converting language identifiers to a systems own formatting. +/// +/// A default language is specifiable on a prim. This is the language that is assumed when attributes do +/// not include their own identifier for language. The default language is explicitly inherited by +/// all prims under the current prims hierarchy. +/// +/// \note Provide default localization information on the default prim of the layer, and any top level prims. +/// It is not recommended to keep declarations of the default localization to a minimum throughout the rest of +/// the hierarchy within a single layer. +/// +/// Attributes are suffixed with \em :lang: when expressing languages other than the default. +/// +/// For example, "string text" would implicitly be in the default localization language, but you may have +/// "string text:lang:fr" for French. +/// +/// Runtimes may provide their own logic for choosing which langauge to display, but following BCP-47, +/// a recommended logic set is: +/// +/// \li If a preferred language is available within the set of declared languages, pick that language exactly. +/// e.g "en_CA" should not pick simply "en" if "en_CA" is available +/// +/// \li If a preferred language isn't available, check for a more specific version of that language. +/// e.g "de_DE" may match to "de_DE_u_co_phonebk" +/// +/// \li If a more specific language is not available, pick a less specific language. +/// e.g "en_US" may match to "en" +/// +/// \li If a less specific language choice is not available, pick the attribute without language specification. +/// +/// +class UsdUILocalizationAPI : public UsdAPISchemaBase +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::MultipleApplyAPI; + + /// Construct a UsdUILocalizationAPI on UsdPrim \p prim with + /// name \p name . Equivalent to + /// UsdUILocalizationAPI::Get( + /// prim.GetStage(), + /// prim.GetPath().AppendProperty( + /// "localization:name")); + /// + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdUILocalizationAPI( + const UsdPrim& prim=UsdPrim(), const TfToken &name=UsdUITokens->default_) + : UsdAPISchemaBase(prim, /*instanceName*/ name) + { } + + /// Construct a UsdUILocalizationAPI on the prim held by \p schemaObj with + /// name \p name. Should be preferred over + /// UsdUILocalizationAPI(schemaObj.GetPrim(), name), as it preserves + /// SchemaBase state. + explicit UsdUILocalizationAPI( + const UsdSchemaBase& schemaObj, const TfToken &name=UsdUITokens->default_) + : UsdAPISchemaBase(schemaObj, /*instanceName*/ name) + { } + + /// Destructor. + USDUI_API + virtual ~UsdUILocalizationAPI(); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes. Does not include attributes that + /// may be authored by custom/extended methods of the schemas involved. + USDUI_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a vector of names of all pre-declared attributes for this schema + /// class and all its ancestor classes for a given instance name. Does not + /// include attributes that may be authored by custom/extended methods of + /// the schemas involved. The names returned will have the proper namespace + /// prefix. + USDUI_API + static TfTokenVector + GetSchemaAttributeNames(bool includeInherited, const TfToken &instanceName); + + /// Returns the name of this multiple-apply schema instance + TfToken GetName() const { + return _GetInstanceName(); + } + + /// Return a UsdUILocalizationAPI holding the prim adhering to this + /// schema at \p path on \p stage. If no prim exists at \p path on + /// \p stage, or if the prim at that path does not adhere to this schema, + /// return an invalid schema object. \p path must be of the format + /// .localization:name . + /// + /// This is shorthand for the following: + /// + /// \code + /// TfToken name = SdfPath::StripNamespace(path.GetToken()); + /// UsdUILocalizationAPI( + /// stage->GetPrimAtPath(path.GetPrimPath()), name); + /// \endcode + /// + USDUI_API + static UsdUILocalizationAPI + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Return a UsdUILocalizationAPI with name \p name holding the + /// prim \p prim. Shorthand for UsdUILocalizationAPI(prim, name); + USDUI_API + static UsdUILocalizationAPI + Get(const UsdPrim &prim, const TfToken &name); + + /// Return a vector of all named instances of UsdUILocalizationAPI on the + /// given \p prim. + USDUI_API + static std::vector + GetAll(const UsdPrim &prim); + + /// Checks if the given name \p baseName is the base name of a property + /// of LocalizationAPI. + USDUI_API + static bool + IsSchemaPropertyBaseName(const TfToken &baseName); + + /// Checks if the given path \p path is of an API schema of type + /// LocalizationAPI. If so, it stores the instance name of + /// the schema in \p name and returns true. Otherwise, it returns false. + USDUI_API + static bool + IsLocalizationAPIPath(const SdfPath &path, TfToken *name); + + /// Returns true if this multiple-apply API schema can be applied, + /// with the given instance name, \p name, to the given \p prim. If this + /// schema can not be a applied the prim, this returns false and, if + /// provided, populates \p whyNot with the reason it can not be applied. + /// + /// Note that if CanApply returns false, that does not necessarily imply + /// that calling Apply will fail. Callers are expected to call CanApply + /// before calling Apply if they want to ensure that it is valid to + /// apply a schema. + /// + /// \sa UsdPrim::GetAppliedSchemas() + /// \sa UsdPrim::HasAPI() + /// \sa UsdPrim::CanApplyAPI() + /// \sa UsdPrim::ApplyAPI() + /// \sa UsdPrim::RemoveAPI() + /// + USDUI_API + static bool + CanApply(const UsdPrim &prim, const TfToken &name, + std::string *whyNot=nullptr); + + /// Applies this multiple-apply API schema to the given \p prim + /// along with the given instance name, \p name. + /// + /// This information is stored by adding "LocalizationAPI:name" + /// to the token-valued, listOp metadata \em apiSchemas on the prim. + /// For example, if \p name is 'instance1', the token + /// 'LocalizationAPI:instance1' is added to 'apiSchemas'. + /// + /// \return A valid UsdUILocalizationAPI object is returned upon success. + /// An invalid (or empty) UsdUILocalizationAPI object is returned upon + /// failure. See \ref UsdPrim::ApplyAPI() for + /// conditions resulting in failure. + /// + /// \sa UsdPrim::GetAppliedSchemas() + /// \sa UsdPrim::HasAPI() + /// \sa UsdPrim::CanApplyAPI() + /// \sa UsdPrim::ApplyAPI() + /// \sa UsdPrim::RemoveAPI() + /// + USDUI_API + static UsdUILocalizationAPI + Apply(const UsdPrim &prim, const TfToken &name=UsdUITokens->default_); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDUI_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDUI_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDUI_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // LANGUAGE + // --------------------------------------------------------------------- // + /// The default language for this prim hierarchy. This may only be created with the default instance name. + /// + /// \note If no default localization language is provided, the runtime may optionally try and infer the + /// language of the text. + /// If the runtime does not infer the langauge, it should assume the language is in the users preferred language, + /// which may be derived from the system or current user context. + /// + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform string language` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + USDUI_API + UsdAttribute GetLanguageAttr() const; + + /// See GetLanguageAttr(), and also + /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. + /// If specified, author \p defaultValue as the attribute's default, + /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - + /// the default for \p writeSparsely is \c false. + USDUI_API + UsdAttribute CreateLanguageAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // ===================================================================== // + // Feel free to add custom code below this line, it will be preserved by + // the code generator. + // + // Just remember to: + // - Close the class declaration with }; + // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE + // - Close the include guard with #endif + // ===================================================================== // + // --(BEGIN CUSTOM CODE)-- + /// Returns the version of the property that has no localization specifics. + /// If this cannot be found, a default constructed property is returned. + /// If the input property doesn't specify a localization, it will be returned itself. + USDUI_API + static UsdProperty GetDefaultProperty(UsdProperty const &source); + + /// Returns a TfToken that represents the localization of the property + /// If a localization is not found, an empty token is returned + USDUI_API + static TfToken GetPropertyLanguage(UsdProperty const &prop); + + /// Gets the name of a sibling property with a matching localization + USDUI_API + static TfToken + GetLocalizedPropertyName(UsdProperty const &source, TfToken const &localization); + + /// Finds and returns a sibling proprety that has the specified localization. + /// If it is not found, a default constructed property is returned. + /// Only localizations that have been applied on the prim will be returned. + USDUI_API + static UsdProperty + GetLocalizedProperty(UsdProperty const &source, TfToken const &localization); + + /// A convenience method for calling the static version of this method with the localization derived + /// from the instance name + USDUI_API + UsdProperty GetLocalizedProperty(UsdProperty const &source) const; + + /// Creates an attribute with the given localization, or returns the attribute if one already exists + /// \note It is up to the developer to apply the localization API for this locale to the prim + USDUI_API + static UsdAttribute + CreateLocalizedAttribute(UsdAttribute const &source, TfToken const &localization, VtValue const &defaultValue, + bool writeSparsely=false); + + /// A convenience method for calling the static version of this method with the localization derived + /// from the instance name + USDUI_API + UsdAttribute CreateLocalizedAttribute(UsdAttribute const &source, VtValue const &defaultValue, + bool writeSparsely=false) const; + + /// Creates a relationship with the given localization, or returns the relationship if one already exists + /// \note It is up to the developer to apply the localization API for this locale to the prim + USDUI_API + static UsdRelationship + CreateLocalizedRelationship(UsdRelationship const &source, TfToken const &localization); + + /// A convenience method for calling the static version of this method with the localization derived + /// from the instance name + USDUI_API + UsdRelationship CreateLocalizedRelationship(UsdRelationship const &source) const; + + + /// Fills the map with all localized versions of the properties that have Applied schemas on the prim. + /// The version of the property without a localization specifier will be returned directly from the method + /// and not populated into the map. + /// It is upto the developer to infer the localization using the rules as described in the schema + /// In Python, the results are returned as a tuple of the property return and the dictionary. + /// /sa GetAllPropertyLocalizations + USDUI_API + static UsdProperty + GetAppliedPropertyLocalizations(UsdProperty const &source, std::map &localizations); + + /// Fills the map with all localized versions of the property, regardless of whether they are applied. + /// The version of the property without a localization specifier will be returned directly from the method + /// and not populated into the map. + /// It is upto the developer to infer the localization using the rules as described in the schema + /// In Python, the results are returned as a tuple of the property return and the dictionary. + /// /sa GetAppliedPropertyLocalizations + USDUI_API + static UsdProperty + GetAllPropertyLocalizations(UsdProperty const &source, std::map &localizations); + +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdUI/plugInfo.json b/pxr/usd/usdUI/plugInfo.json index 0b7960052e..298b19db41 100644 --- a/pxr/usd/usdUI/plugInfo.json +++ b/pxr/usd/usdUI/plugInfo.json @@ -6,6 +6,16 @@ { "Info": { "Types": { + "UsdUIAccessibilityAPI": { + "alias": { + "UsdSchemaBase": "AccessibilityAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "multipleApplyAPI" + }, "UsdUIBackdrop": { "alias": { "UsdSchemaBase": "Backdrop" @@ -17,6 +27,16 @@ "schemaIdentifier": "Backdrop", "schemaKind": "concreteTyped" }, + "UsdUILocalizationAPI": { + "alias": { + "UsdSchemaBase": "LocalizationAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "multipleApplyAPI" + }, "UsdUINodeGraphNodeAPI": { "alias": { "UsdSchemaBase": "NodeGraphNodeAPI" diff --git a/pxr/usd/usdUI/schema.usda b/pxr/usd/usdUI/schema.usda index c8b9571883..01c8420a19 100644 --- a/pxr/usd/usdUI/schema.usda +++ b/pxr/usd/usdUI/schema.usda @@ -10,7 +10,12 @@ over "GLOBAL" ( customData = { string libraryName = "usdUI" string libraryPath = "pxr/usd/usdUI" - # dictionary libraryTokens = {} + dictionary libraryTokens = { + dictionary default_ = { + string value = "default" + string doc = """Name of the anonymous instance name for the schema""" + } + } } ) { @@ -183,3 +188,160 @@ class Backdrop "Backdrop" ( ) } +class "AccessibilityAPI" ( + inherits = + doc = """ + This API describes \\em Accessibility information on a Prim that may be surfaced to a given runtimes + accessibility frameworks. + This information may be used by assistive tooling such as voice controls or screen readers. + Accessibility information is provided as a standard triplet of label, description and priority. + + OpenUSD does not provide a accessibility runtime itself, but endeavours to provide the information needed for + compatible runtimes to extract and present this information. + + This is a multiple apply schema, and so may have multiple namespaced accessibility triplets, where a instance + name may reflect a given purpose for that triplet. For example, you may desire to express different + information for different aspects of the prim, such as size or color. + + \\note The API will use \\em default as an instance name if no namespace is specified. + When using "default" as the name, the instance name is elided from the attribute name. + + There are several best practices for using this schema.: + + \\li Most accessibility runtimes support a single accessibility description. Therefore we recommend placing + any critical information in the default instance. + + \\li A default value should be authored if using time sampled accessibility information. + This helps accessibility runtimes that do not currently support time sampled information. + + \\li Provide accessibility information of your scene on the default prim of the layer, and any top level prims. + This allows accessibility systems to provide concise scene descriptions to a user, but also allows supporting + accessibility systems that either do not support hierarchy information or when a user has turned off that level + of granularity. Accessibility information may still be provided on other prims in the hierarchy. + + \\note The use of the default prim and top level prims for scene accessibility descriptions is a + recommended convention. Outside of that, accessibility information is not implicitly inherited through + a prim hierarchy. The inheritance should be left to the accessibility runtime to decide how best to + surface information to users. + """ + + customData = { + token apiSchemaType = "multipleApply" + token propertyNamespacePrefix = "accessibility" + dictionary schemaTokens = { + dictionary label = { + string value = "label" + string doc = """Name of the label attribute""" + } + dictionary description = { + string value = "description" + string doc = """Name of the description attribute""" + } + dictionary priority = { + string value = "priority" + string doc = """Name of the priority attribute""" + } + } + } +) { + string label ( + doc = """A short label to concisely describe the prim. + It is not recommended to time vary the label unless the concise description changes substantially.""" + ) + + string description ( + doc = """An extended description of the prim to provide more details. + If a label attribute is not authored in a given instance name, the description attribute should not be used + in it its place. A description is an optional attribute, and some accessibility systems may only use the label. + + Descriptions may be time varying for runtimes that support it. For example, you may describe what a character + is doing at a given time. + """ + ) + + uniform token priority = "standard" ( + doc = """A hint to the accessibility runtime of how to prioritize this instances label and description, + relative to others. This attribute is optional. Accessibility runtimes may choose to apply their own + priority systems that override this. + + Priority may not be time varying. + """ + allowedTokens = ["low", "standard", "high"] + ) +} + +class "LocalizationAPI" ( + inherits = + doc = """This API describes \em Language localization information for attributes. + + It may be used to provide alternate language definitions for content like strings and asset paths that are + displayed to a user. + Runtimes may present the best language for a given users preference with this information. + + OpenUSD leaves it up to the runtime that is consuming it to handle localized presentations. + As such, support for localization may vary across runtimes. + + \\important Lookup of localized attributes may be expensive, so are recommended to be used sparingly + It is recommended, but not enforced, to only use them for strings and asset paths. + Support for localization of different attributes may vary depending on the application runtime that + the data is brought into. + + + \\note Language identifiers must use the BCP-47 list of languages. However, since USD cannot currently use + hyphens in identifiers, any hyphens are replaced with underscores. This is similar in strategy to other + systems that adhere closely to the Unicode Identifier specification. e.g en-ca is en_CA . + Take care when converting language identifiers to a systems own formatting. + + A default language is specifiable on a prim. This is the language that is assumed when attributes do + not include their own identifier for language. The default language is explicitly inherited by + all prims under the current prims hierarchy. + + \\note Provide default localization information on the default prim of the layer, and any top level prims. + It is not recommended to keep declarations of the default localization to a minimum throughout the rest of + the hierarchy within a single layer. + + Attributes are suffixed with \\em :lang: when expressing languages other than the default. + + For example, "string text" would implicitly be in the default localization language, but you may have + "string text:lang:fr" for French. + + Runtimes may provide their own logic for choosing which langauge to display, but following BCP-47, + a recommended logic set is: + + \\li If a preferred language is available within the set of declared languages, pick that language exactly. + e.g "en_CA" should not pick simply "en" if "en_CA" is available + + \\li If a preferred language isn't available, check for a more specific version of that language. + e.g "de_DE" may match to "de_DE_u_co_phonebk" + + \\li If a more specific language is not available, pick a less specific language. + e.g "en_US" may match to "en" + + \\li If a less specific language choice is not available, pick the attribute without language specification. + """ + + customData = { + token apiSchemaType = "multipleApply" + token propertyNamespacePrefix = "localization" + dictionary schemaTokens = { + dictionary lang = { + string value = "lang" + string doc = """The token that delineates language specifications on an attribute""" + } + dictionary languageAttribute = { + string value = "localization:lang" + string doc = """The non-namespaced version of the language localization attribute""" + } + } + } +) { + uniform token language ( + doc = """The default language for this prim hierarchy. This may only be created with the default instance name. + + \\note If no default localization language is provided, the runtime may optionally try and infer the + language of the text. + If the runtime does not infer the langauge, it should assume the language is in the users preferred language, + which may be derived from the system or current user context. + """ + ) +} \ No newline at end of file diff --git a/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp b/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp new file mode 100644 index 0000000000..3bd6de344d --- /dev/null +++ b/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp @@ -0,0 +1,91 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// + +#include "pxr/pxr.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usdUI/accessibilityAPI.h" +#include "pxr/usd/usdUI/tokens.h" +#include "pxr/base/tf/diagnostic.h" + + +PXR_NAMESPACE_USING_DIRECTIVE + +int +main(int argc, char* argv[]) +{ + auto stage = UsdStage::CreateInMemory(); + + auto prim = stage->DefinePrim(SdfPath("/Root")); + VtValue value; + + // Test Default + auto defaultAPI = UsdUIAccessibilityAPI::Apply(prim); + auto namedAPI = UsdUIAccessibilityAPI::Apply(prim, TfToken("foo")); + + // Make sure we create it with the right name + std::string label = "The root prim"; + auto defaultLabelName = TfToken("accessibility:label"); + auto defaultLabel = defaultAPI.CreateLabelAttr(VtValue(label)); + TF_AXIOM(defaultLabel.GetName() == defaultLabelName); + + // Make sure we get the same name back and the values are correct + defaultLabel = defaultAPI.GetLabelAttr(); + TF_AXIOM(defaultLabel.GetName() == defaultLabelName); + + defaultLabel.Get(&value); + TF_AXIOM(value.IsHolding()); + TF_AXIOM(value.Get() == label); + + // Make sure we create the description with the right name + std::string description = "The greatest prim of all time"; + auto defaultDescriptionName = TfToken("accessibility:description"); + auto defaultDescription = defaultAPI.CreateDescriptionAttr(VtValue(std::string(description))); + TF_AXIOM(defaultDescription.GetName() == defaultDescriptionName); + + // Make sure we get the same name and value back + defaultDescription = defaultAPI.GetDescriptionAttr(); + TF_AXIOM(defaultDescription.GetName() == defaultDescriptionName); + defaultDescription.Get(&value); + TF_AXIOM(value.IsHolding()); + TF_AXIOM(value.Get() == description); + + // Make sure we create the priority with the right name + auto priority = UsdUITokens->high; + auto defaultPriorityName = TfToken("accessibility:priority"); + auto defaultPriority = defaultAPI.CreatePriorityAttr(VtValue(priority)); + TF_AXIOM(defaultPriority.GetName() == defaultPriorityName); + + // Make sure we get the same name and value back + defaultPriority = defaultAPI.GetPriorityAttr(); + TF_AXIOM(defaultPriority.GetName() == defaultPriorityName); + defaultPriority.Get(&value); + TF_AXIOM(value.IsHolding()); + TF_AXIOM(value.Get() == priority); + + // Check that the named APIs are created with the correct names and come back with the same name + auto namedLabelName = TfToken("accessibility:foo:label"); + auto namedDescriptionName = TfToken("accessibility:foo:description"); + auto namedPriorityName = TfToken("accessibility:foo:priority"); + + auto namedLabel = namedAPI.CreateLabelAttr(VtValue(label)); + TF_AXIOM(namedLabel.GetName() == namedLabelName); + namedLabel = namedAPI.GetLabelAttr(); + TF_AXIOM(namedLabel.GetName() == namedLabelName); + + auto namedDescription = namedAPI.CreateDescriptionAttr(VtValue(description)); + TF_AXIOM(namedDescription.GetName() == namedDescriptionName); + namedDescription = namedAPI.GetDescriptionAttr(); + TF_AXIOM(namedDescription.GetName() == namedDescriptionName); + + auto namedPriority = namedAPI.CreatePriorityAttr(VtValue(priority)); + TF_AXIOM(namedPriority.GetName() == namedPriorityName); + namedPriority = namedAPI.GetPriorityAttr(); + TF_AXIOM(namedPriority.GetName() == namedPriorityName); + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp b/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp new file mode 100644 index 0000000000..6faea29d39 --- /dev/null +++ b/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp @@ -0,0 +1,73 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// + +#include "pxr/pxr.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usdUI/localizationAPI.h" +#include "pxr/usd/usdUI/tokens.h" +#include "pxr/base/tf/diagnostic.h" +#include +PXR_NAMESPACE_USING_DIRECTIVE + +int +main(int argc, char* argv[]) +{ + auto en_us = TfToken("en_US"); + auto fr_ca = TfToken("fr_CA"); + auto hi_in = TfToken("hi_IN"); + + auto stage = UsdStage::CreateInMemory(); + auto prim = stage->DefinePrim(SdfPath("/Root")); + + auto api = UsdUILocalizationAPI::Apply(prim); + auto frAPI = UsdUILocalizationAPI::Apply(prim, fr_ca); + + auto language = api.CreateLanguageAttr(VtValue(en_us)); + TF_AXIOM(language.GetName() == UsdUITokens->languageAttribute); + + + // Test Default localization + auto baseName = TfToken("foo"); + auto baseAttr = prim.CreateAttribute(baseName, SdfValueTypeNames->String); + baseAttr.Set(VtValue("Hello")); + TF_AXIOM(baseAttr.GetPath() == UsdUILocalizationAPI::GetDefaultProperty(baseAttr).GetPath()); + + auto frAttrName = TfToken("foo:lang:fr_CA"); + auto frAttr = frAPI.CreateLocalizedAttribute(baseAttr, VtValue("Bonjour")); + TF_AXIOM(frAttr.GetName() == frAttrName); + TF_AXIOM(UsdUILocalizationAPI::GetDefaultProperty(frAttr).GetPath() == baseAttr.GetPath()); + TF_AXIOM(UsdUILocalizationAPI::GetPropertyLanguage(frAttr) == fr_ca); + TF_AXIOM(UsdUILocalizationAPI::GetLocalizedProperty(baseAttr, fr_ca).GetPath() == frAttr.GetPath()); + TF_AXIOM(frAttr.IsCustom() == baseAttr.IsCustom()); + TF_AXIOM(frAttr.GetTypeName() == baseAttr.GetTypeName()); + + auto hiAttrName = TfToken("foo:lang:hi_IN"); + auto hiAttr = UsdUILocalizationAPI::CreateLocalizedAttribute(baseAttr, hi_in, VtValue("नमस्ते")); + TF_AXIOM(hiAttr.GetName() == hiAttrName); + TF_AXIOM(UsdUILocalizationAPI::GetLocalizedProperty(baseAttr, hi_in).GetPath() == hiAttr.GetPath()); + + std::map properties; + auto defaultAttr = UsdUILocalizationAPI::GetAppliedPropertyLocalizations(baseAttr, properties); + TF_AXIOM(properties.size() == 1); + TF_AXIOM(properties.count(fr_ca) == 1); + TF_AXIOM(defaultAttr.GetPath() == baseAttr.GetPath()); + + properties.clear(); + defaultAttr = UsdUILocalizationAPI::GetAllPropertyLocalizations(baseAttr, properties); + TF_AXIOM(properties.size() == 2); + TF_AXIOM(properties.count(fr_ca) == 1); + TF_AXIOM(properties.count(hi_in) == 1); + TF_AXIOM(defaultAttr.GetPath() == baseAttr.GetPath()); + + auto baseRelName = TfToken("spam"); + auto baseRel = prim.CreateRelationship(baseRelName, false); + auto frRel = frAPI.CreateLocalizedRelationship(baseRel); + TF_AXIOM(UsdUILocalizationAPI::GetLocalizedProperty(baseRel, fr_ca).GetPath() == frRel.GetPath()); + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/pxr/usd/usdUI/tokens.cpp b/pxr/usd/usdUI/tokens.cpp index f55805a669..b65ea189e2 100644 --- a/pxr/usd/usdUI/tokens.cpp +++ b/pxr/usd/usdUI/tokens.cpp @@ -9,9 +9,24 @@ PXR_NAMESPACE_OPEN_SCOPE UsdUITokensType::UsdUITokensType() : + accessibility("accessibility", TfToken::Immortal), + accessibility_MultipleApplyTemplate_Description("accessibility:__INSTANCE_NAME__:description", TfToken::Immortal), + accessibility_MultipleApplyTemplate_Label("accessibility:__INSTANCE_NAME__:label", TfToken::Immortal), + accessibility_MultipleApplyTemplate_Priority("accessibility:__INSTANCE_NAME__:priority", TfToken::Immortal), closed("closed", TfToken::Immortal), + default_("default", TfToken::Immortal), + description("description", TfToken::Immortal), + high("high", TfToken::Immortal), + label("label", TfToken::Immortal), + lang("lang", TfToken::Immortal), + languageAttribute("localization:lang", TfToken::Immortal), + localization("localization", TfToken::Immortal), + localization_MultipleApplyTemplate_Language("localization:__INSTANCE_NAME__:language", TfToken::Immortal), + low("low", TfToken::Immortal), minimized("minimized", TfToken::Immortal), open("open", TfToken::Immortal), + priority("priority", TfToken::Immortal), + standard("standard", TfToken::Immortal), uiDescription("ui:description", TfToken::Immortal), uiDisplayGroup("ui:displayGroup", TfToken::Immortal), uiDisplayName("ui:displayName", TfToken::Immortal), @@ -22,13 +37,30 @@ UsdUITokensType::UsdUITokensType() : uiNodegraphNodePos("ui:nodegraph:node:pos", TfToken::Immortal), uiNodegraphNodeSize("ui:nodegraph:node:size", TfToken::Immortal), uiNodegraphNodeStackingOrder("ui:nodegraph:node:stackingOrder", TfToken::Immortal), + AccessibilityAPI("AccessibilityAPI", TfToken::Immortal), Backdrop("Backdrop", TfToken::Immortal), + LocalizationAPI("LocalizationAPI", TfToken::Immortal), NodeGraphNodeAPI("NodeGraphNodeAPI", TfToken::Immortal), SceneGraphPrimAPI("SceneGraphPrimAPI", TfToken::Immortal), allTokens({ + accessibility, + accessibility_MultipleApplyTemplate_Description, + accessibility_MultipleApplyTemplate_Label, + accessibility_MultipleApplyTemplate_Priority, closed, + default_, + description, + high, + label, + lang, + languageAttribute, + localization, + localization_MultipleApplyTemplate_Language, + low, minimized, open, + priority, + standard, uiDescription, uiDisplayGroup, uiDisplayName, @@ -39,7 +71,9 @@ UsdUITokensType::UsdUITokensType() : uiNodegraphNodePos, uiNodegraphNodeSize, uiNodegraphNodeStackingOrder, + AccessibilityAPI, Backdrop, + LocalizationAPI, NodeGraphNodeAPI, SceneGraphPrimAPI }) diff --git a/pxr/usd/usdUI/tokens.h b/pxr/usd/usdUI/tokens.h index ec080e33dc..ed2e521030 100644 --- a/pxr/usd/usdUI/tokens.h +++ b/pxr/usd/usdUI/tokens.h @@ -41,14 +41,66 @@ PXR_NAMESPACE_OPEN_SCOPE /// Use UsdUITokens like so: /// /// \code -/// gprim.GetMyTokenValuedAttr().Set(UsdUITokens->closed); +/// gprim.GetMyTokenValuedAttr().Set(UsdUITokens->accessibility); /// \endcode struct UsdUITokensType { USDUI_API UsdUITokensType(); + /// \brief "accessibility" + /// + /// Property namespace prefix for the UsdUIAccessibilityAPI schema. + const TfToken accessibility; + /// \brief "accessibility:__INSTANCE_NAME__:description" + /// + /// UsdUIAccessibilityAPI + const TfToken accessibility_MultipleApplyTemplate_Description; + /// \brief "accessibility:__INSTANCE_NAME__:label" + /// + /// UsdUIAccessibilityAPI + const TfToken accessibility_MultipleApplyTemplate_Label; + /// \brief "accessibility:__INSTANCE_NAME__:priority" + /// + /// UsdUIAccessibilityAPI + const TfToken accessibility_MultipleApplyTemplate_Priority; /// \brief "closed" /// /// Possible value for UsdUINodeGraphNodeAPI::GetExpansionStateAttr() const TfToken closed; + /// \brief "default" + /// + /// Name of the anonymous instance name for the schema + const TfToken default_; + /// \brief "description" + /// + /// Name of the description attribute + const TfToken description; + /// \brief "high" + /// + /// Possible value for UsdUIAccessibilityAPI::GetPriorityAttr() + const TfToken high; + /// \brief "label" + /// + /// Name of the label attribute + const TfToken label; + /// \brief "lang" + /// + /// The token that delineates language specifications on an attribute + const TfToken lang; + /// \brief "localization:lang" + /// + /// The non-namespaced version of the language localization attribute + const TfToken languageAttribute; + /// \brief "localization" + /// + /// Property namespace prefix for the UsdUILocalizationAPI schema. + const TfToken localization; + /// \brief "localization:__INSTANCE_NAME__:language" + /// + /// UsdUILocalizationAPI + const TfToken localization_MultipleApplyTemplate_Language; + /// \brief "low" + /// + /// Possible value for UsdUIAccessibilityAPI::GetPriorityAttr() + const TfToken low; /// \brief "minimized" /// /// Possible value for UsdUINodeGraphNodeAPI::GetExpansionStateAttr() @@ -57,6 +109,14 @@ struct UsdUITokensType { /// /// Possible value for UsdUINodeGraphNodeAPI::GetExpansionStateAttr() const TfToken open; + /// \brief "priority" + /// + /// Name of the priority attribute + const TfToken priority; + /// \brief "standard" + /// + /// Fallback value for UsdUIAccessibilityAPI::GetPriorityAttr() + const TfToken standard; /// \brief "ui:description" /// /// UsdUIBackdrop @@ -97,10 +157,18 @@ struct UsdUITokensType { /// /// UsdUINodeGraphNodeAPI const TfToken uiNodegraphNodeStackingOrder; + /// \brief "AccessibilityAPI" + /// + /// Schema identifer and family for UsdUIAccessibilityAPI + const TfToken AccessibilityAPI; /// \brief "Backdrop" /// /// Schema identifer and family for UsdUIBackdrop const TfToken Backdrop; + /// \brief "LocalizationAPI" + /// + /// Schema identifer and family for UsdUILocalizationAPI + const TfToken LocalizationAPI; /// \brief "NodeGraphNodeAPI" /// /// Schema identifer and family for UsdUINodeGraphNodeAPI diff --git a/pxr/usd/usdUI/wrapAccessibilityAPI.cpp b/pxr/usd/usdUI/wrapAccessibilityAPI.cpp new file mode 100644 index 0000000000..d03db54111 --- /dev/null +++ b/pxr/usd/usdUI/wrapAccessibilityAPI.cpp @@ -0,0 +1,202 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdUI/accessibilityAPI.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyAnnotatedBoolResult.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include + +#include + +using namespace boost::python; + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static UsdAttribute +_CreateLabelAttr(UsdUIAccessibilityAPI &self, + object defaultVal, bool writeSparsely) { + return self.CreateLabelAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateDescriptionAttr(UsdUIAccessibilityAPI &self, + object defaultVal, bool writeSparsely) { + return self.CreateDescriptionAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreatePriorityAttr(UsdUIAccessibilityAPI &self, + object defaultVal, bool writeSparsely) { + return self.CreatePriorityAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); +} + +static bool _WrapIsAccessibilityAPIPath(const SdfPath &path) { + TfToken collectionName; + return UsdUIAccessibilityAPI::IsAccessibilityAPIPath( + path, &collectionName); +} + +static std::string +_Repr(const UsdUIAccessibilityAPI &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + std::string instanceName = TfPyRepr(self.GetName()); + return TfStringPrintf( + "UsdUI.AccessibilityAPI(%s, '%s')", + primRepr.c_str(), instanceName.c_str()); +} + +struct UsdUIAccessibilityAPI_CanApplyResult : + public TfPyAnnotatedBoolResult +{ + UsdUIAccessibilityAPI_CanApplyResult(bool val, std::string const &msg) : + TfPyAnnotatedBoolResult(val, msg) {} +}; + +static UsdUIAccessibilityAPI_CanApplyResult +_WrapCanApply(const UsdPrim& prim, const TfToken& name) +{ + std::string whyNot; + bool result = UsdUIAccessibilityAPI::CanApply(prim, name, &whyNot); + return UsdUIAccessibilityAPI_CanApplyResult(result, whyNot); +} + +} // anonymous namespace + +void wrapUsdUIAccessibilityAPI() +{ + typedef UsdUIAccessibilityAPI This; + + UsdUIAccessibilityAPI_CanApplyResult::Wrap( + "_CanApplyResult", "whyNot"); + + class_ > + cls("AccessibilityAPI"); + + cls + .def(init((arg("prim"), arg("name")=UsdUITokens->default_))) + .def(init((arg("schemaObj"), arg("name")=UsdUITokens->default_))) + .def(TfTypePythonClass()) + + .def("Get", + (UsdUIAccessibilityAPI(*)(const UsdStagePtr &stage, + const SdfPath &path)) + &This::Get, + (arg("stage"), arg("path"))) + .def("Get", + (UsdUIAccessibilityAPI(*)(const UsdPrim &prim, + const TfToken &name)) + &This::Get, + (arg("prim"), arg("name"))) + .staticmethod("Get") + + .def("GetAll", + (std::vector(*)(const UsdPrim &prim)) + &This::GetAll, + arg("prim"), + return_value_policy()) + .staticmethod("GetAll") + + .def("CanApply", &_WrapCanApply, (arg("prim"), arg("name"))) + .staticmethod("CanApply") + + .def("Apply", &This::Apply, (arg("prim"), arg("name")=UsdUITokens->default_)) + .staticmethod("Apply") + + .def("GetSchemaAttributeNames", + (const TfTokenVector &(*)(bool))&This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .def("GetSchemaAttributeNames", + (TfTokenVector(*)(bool, const TfToken &)) + &This::GetSchemaAttributeNames, + arg("includeInherited"), + arg("instanceName"), + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetLabelAttr", + &This::GetLabelAttr) + .def("CreateLabelAttr", + &_CreateLabelAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetDescriptionAttr", + &This::GetDescriptionAttr) + .def("CreateDescriptionAttr", + &_CreateDescriptionAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetPriorityAttr", + &This::GetPriorityAttr) + .def("CreatePriorityAttr", + &_CreatePriorityAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("IsAccessibilityAPIPath", _WrapIsAccessibilityAPIPath) + .staticmethod("IsAccessibilityAPIPath") + .def("__repr__", ::_Repr) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { +} + +} diff --git a/pxr/usd/usdUI/wrapLocalizationAPI.cpp b/pxr/usd/usdUI/wrapLocalizationAPI.cpp new file mode 100644 index 0000000000..997d4250b7 --- /dev/null +++ b/pxr/usd/usdUI/wrapLocalizationAPI.cpp @@ -0,0 +1,186 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the terms set forth in the LICENSE.txt file available at +// https://openusd.org/license. +// +#include "pxr/usd/usdUI/localizationAPI.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.h" +#include "pxr/base/tf/pyAnnotatedBoolResult.h" +#include "pxr/base/tf/pyContainerConversions.h" +#include "pxr/base/tf/pyResultConversions.h" +#include "pxr/base/tf/pyUtils.h" +#include "pxr/base/tf/wrapTypeHelpers.h" + +#include + +#include + +using namespace boost::python; + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { + +#define WRAP_CUSTOM \ + template static void _CustomWrapCode(Cls &_class) + +// fwd decl. +WRAP_CUSTOM; + + +static UsdAttribute +_CreateLanguageAttr(UsdUILocalizationAPI &self, + object defaultVal, bool writeSparsely) { + return self.CreateLanguageAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static bool _WrapIsLocalizationAPIPath(const SdfPath &path) { + TfToken collectionName; + return UsdUILocalizationAPI::IsLocalizationAPIPath( + path, &collectionName); +} + +static std::string +_Repr(const UsdUILocalizationAPI &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + std::string instanceName = TfPyRepr(self.GetName()); + return TfStringPrintf( + "UsdUI.LocalizationAPI(%s, '%s')", + primRepr.c_str(), instanceName.c_str()); +} + +struct UsdUILocalizationAPI_CanApplyResult : + public TfPyAnnotatedBoolResult +{ + UsdUILocalizationAPI_CanApplyResult(bool val, std::string const &msg) : + TfPyAnnotatedBoolResult(val, msg) {} +}; + +static UsdUILocalizationAPI_CanApplyResult +_WrapCanApply(const UsdPrim& prim, const TfToken& name) +{ + std::string whyNot; + bool result = UsdUILocalizationAPI::CanApply(prim, name, &whyNot); + return UsdUILocalizationAPI_CanApplyResult(result, whyNot); +} + +} // anonymous namespace + +void wrapUsdUILocalizationAPI() +{ + typedef UsdUILocalizationAPI This; + + UsdUILocalizationAPI_CanApplyResult::Wrap( + "_CanApplyResult", "whyNot"); + + class_ > + cls("LocalizationAPI"); + + cls + .def(init((arg("prim"), arg("name")=UsdUITokens->default_))) + .def(init((arg("schemaObj"), arg("name")=UsdUITokens->default_))) + .def(TfTypePythonClass()) + + .def("Get", + (UsdUILocalizationAPI(*)(const UsdStagePtr &stage, + const SdfPath &path)) + &This::Get, + (arg("stage"), arg("path"))) + .def("Get", + (UsdUILocalizationAPI(*)(const UsdPrim &prim, + const TfToken &name)) + &This::Get, + (arg("prim"), arg("name"))) + .staticmethod("Get") + + .def("GetAll", + (std::vector(*)(const UsdPrim &prim)) + &This::GetAll, + arg("prim"), + return_value_policy()) + .staticmethod("GetAll") + + .def("CanApply", &_WrapCanApply, (arg("prim"), arg("name"))) + .staticmethod("CanApply") + + .def("Apply", &This::Apply, (arg("prim"), arg("name")=UsdUITokens->default_)) + .staticmethod("Apply") + + .def("GetSchemaAttributeNames", + (const TfTokenVector &(*)(bool))&This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .def("GetSchemaAttributeNames", + (TfTokenVector(*)(bool, const TfToken &)) + &This::GetSchemaAttributeNames, + arg("includeInherited"), + arg("instanceName"), + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetLanguageAttr", + &This::GetLanguageAttr) + .def("CreateLanguageAttr", + &_CreateLanguageAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("IsLocalizationAPIPath", _WrapIsLocalizationAPIPath) + .staticmethod("IsLocalizationAPIPath") + .def("__repr__", ::_Repr) + ; + + _CustomWrapCode(cls); +} + +// ===================================================================== // +// Feel free to add custom code below this line, it will be preserved by +// the code generator. The entry point for your custom code should look +// minimally like the following: +// +// WRAP_CUSTOM { +// _class +// .def("MyCustomMethod", ...) +// ; +// } +// +// Of course any other ancillary or support code may be provided. +// +// Just remember to wrap code in the appropriate delimiters: +// 'namespace {', '}'. +// +// ===================================================================== // +// --(BEGIN CUSTOM CODE)-- + +namespace { + +WRAP_CUSTOM { + _class + .def("GetDefaultProperty", &UsdUILocalizationAPI::GetDefaultProperty, (arg("source"))) + .staticmethod("GetDefaultProperty") + + .def("GetPropertyLanguage", &UsdUILocalizationAPI::GetPropertyLanguage, (arg("prop"))) + .staticmethod("GetPropertyLanguage") + + .def("GetLocalizedPropertyName", + &UsdUILocalizationAPI::GetLocalizedPropertyName, + (arg("source"), arg("localization"))) + .staticmethod("GetLocalizedPropertyName") + ; +} + +} From 8762e5ea7c2c4eb88b25a5958b8190dae7fab7ab Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Tue, 24 Sep 2024 13:31:12 -0700 Subject: [PATCH 02/15] Generate schemas with new usdGenSchema from upcoming 24.11 release --- pxr/usd/usdUI/generatedSchema.classes.txt | 4 ++++ pxr/usd/usdUI/localizationAPI.cpp | 4 +--- pxr/usd/usdUI/localizationAPI.h | 11 ++++++++--- pxr/usd/usdUI/plugInfo.json | 2 ++ pxr/usd/usdUI/wrapAccessibilityAPI.cpp | 6 +++--- pxr/usd/usdUI/wrapLocalizationAPI.cpp | 8 ++++---- pxr/usd/usdUI/wrapTokens.cpp | 17 +++++++++++++++++ 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/pxr/usd/usdUI/generatedSchema.classes.txt b/pxr/usd/usdUI/generatedSchema.classes.txt index 30c2aa5bc7..57a6fbfab5 100644 --- a/pxr/usd/usdUI/generatedSchema.classes.txt +++ b/pxr/usd/usdUI/generatedSchema.classes.txt @@ -1,14 +1,18 @@ # WARNING: THIS FILE IS GENERATED BY usdGenSchema. DO NOT EDIT. # Public Classes +accessibilityAPI backdrop +localizationAPI nodeGraphNodeAPI sceneGraphPrimAPI tokens # Python Module Files module.cpp +wrapAccessibilityAPI.cpp wrapBackdrop.cpp +wrapLocalizationAPI.cpp wrapNodeGraphNodeAPI.cpp wrapSceneGraphPrimAPI.cpp wrapTokens.cpp diff --git a/pxr/usd/usdUI/localizationAPI.cpp b/pxr/usd/usdUI/localizationAPI.cpp index c61e45cd0a..a19b2d7da3 100644 --- a/pxr/usd/usdUI/localizationAPI.cpp +++ b/pxr/usd/usdUI/localizationAPI.cpp @@ -5,8 +5,6 @@ // https://openusd.org/license. // #include "pxr/usd/usdUI/localizationAPI.h" - -#include "tokens.h" #include "pxr/usd/usd/schemaRegistry.h" #include "pxr/usd/usd/typed.h" @@ -453,4 +451,4 @@ UsdUILocalizationAPI::GetAllPropertyLocalizations(UsdProperty const &source, return defaultAttr; } -PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdUI/localizationAPI.h b/pxr/usd/usdUI/localizationAPI.h index d8261a2a5b..fbe1228b9f 100644 --- a/pxr/usd/usdUI/localizationAPI.h +++ b/pxr/usd/usdUI/localizationAPI.h @@ -83,6 +83,11 @@ class SdfAssetPath; /// \li If a less specific language choice is not available, pick the attribute without language specification. /// /// +/// For any described attribute \em Fallback \em Value or \em Allowed \em Values below +/// that are text/tokens, the actual token is published and defined in \ref UsdUITokens. +/// So to set an attribute to the value "rightHanded", use UsdUITokens->rightHanded +/// as the value. +/// class UsdUILocalizationAPI : public UsdAPISchemaBase { public: @@ -259,9 +264,9 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase /// /// | || /// | -- | -- | - /// | Declaration | `uniform string language` | - /// | C++ Type | std::string | - /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + /// | Declaration | `uniform token language` | + /// | C++ Type | TfToken | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | USDUI_API UsdAttribute GetLanguageAttr() const; diff --git a/pxr/usd/usdUI/plugInfo.json b/pxr/usd/usdUI/plugInfo.json index 298b19db41..155c150e5b 100644 --- a/pxr/usd/usdUI/plugInfo.json +++ b/pxr/usd/usdUI/plugInfo.json @@ -14,6 +14,7 @@ "bases": [ "UsdAPISchemaBase" ], + "schemaIdentifier": "AccessibilityAPI", "schemaKind": "multipleApplyAPI" }, "UsdUIBackdrop": { @@ -35,6 +36,7 @@ "bases": [ "UsdAPISchemaBase" ], + "schemaIdentifier": "LocalizationAPI", "schemaKind": "multipleApplyAPI" }, "UsdUINodeGraphNodeAPI": { diff --git a/pxr/usd/usdUI/wrapAccessibilityAPI.cpp b/pxr/usd/usdUI/wrapAccessibilityAPI.cpp index d03db54111..f3c7ce250c 100644 --- a/pxr/usd/usdUI/wrapAccessibilityAPI.cpp +++ b/pxr/usd/usdUI/wrapAccessibilityAPI.cpp @@ -16,14 +16,14 @@ #include "pxr/base/tf/pyUtils.h" #include "pxr/base/tf/wrapTypeHelpers.h" -#include +#include "pxr/external/boost/python.hpp" #include -using namespace boost::python; - PXR_NAMESPACE_USING_DIRECTIVE +using namespace pxr_boost::python; + namespace { #define WRAP_CUSTOM \ diff --git a/pxr/usd/usdUI/wrapLocalizationAPI.cpp b/pxr/usd/usdUI/wrapLocalizationAPI.cpp index 997d4250b7..6bd89d198a 100644 --- a/pxr/usd/usdUI/wrapLocalizationAPI.cpp +++ b/pxr/usd/usdUI/wrapLocalizationAPI.cpp @@ -16,14 +16,14 @@ #include "pxr/base/tf/pyUtils.h" #include "pxr/base/tf/wrapTypeHelpers.h" -#include +#include "pxr/external/boost/python.hpp" #include -using namespace boost::python; - PXR_NAMESPACE_USING_DIRECTIVE +using namespace pxr_boost::python; + namespace { #define WRAP_CUSTOM \ @@ -37,7 +37,7 @@ static UsdAttribute _CreateLanguageAttr(UsdUILocalizationAPI &self, object defaultVal, bool writeSparsely) { return self.CreateLanguageAttr( - UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); } static bool _WrapIsLocalizationAPIPath(const SdfPath &path) { diff --git a/pxr/usd/usdUI/wrapTokens.cpp b/pxr/usd/usdUI/wrapTokens.cpp index 3fba90281f..424a8ad4e6 100644 --- a/pxr/usd/usdUI/wrapTokens.cpp +++ b/pxr/usd/usdUI/wrapTokens.cpp @@ -17,9 +17,24 @@ void wrapUsdUITokens() { pxr_boost::python::class_ cls("Tokens", pxr_boost::python::no_init); + _ADD_TOKEN(cls, accessibility); + _ADD_TOKEN(cls, accessibility_MultipleApplyTemplate_Description); + _ADD_TOKEN(cls, accessibility_MultipleApplyTemplate_Label); + _ADD_TOKEN(cls, accessibility_MultipleApplyTemplate_Priority); _ADD_TOKEN(cls, closed); + _ADD_TOKEN(cls, default_); + _ADD_TOKEN(cls, description); + _ADD_TOKEN(cls, high); + _ADD_TOKEN(cls, label); + _ADD_TOKEN(cls, lang); + _ADD_TOKEN(cls, languageAttribute); + _ADD_TOKEN(cls, localization); + _ADD_TOKEN(cls, localization_MultipleApplyTemplate_Language); + _ADD_TOKEN(cls, low); _ADD_TOKEN(cls, minimized); _ADD_TOKEN(cls, open); + _ADD_TOKEN(cls, priority); + _ADD_TOKEN(cls, standard); _ADD_TOKEN(cls, uiDescription); _ADD_TOKEN(cls, uiDisplayGroup); _ADD_TOKEN(cls, uiDisplayName); @@ -30,7 +45,9 @@ void wrapUsdUITokens() _ADD_TOKEN(cls, uiNodegraphNodePos); _ADD_TOKEN(cls, uiNodegraphNodeSize); _ADD_TOKEN(cls, uiNodegraphNodeStackingOrder); + _ADD_TOKEN(cls, AccessibilityAPI); _ADD_TOKEN(cls, Backdrop); + _ADD_TOKEN(cls, LocalizationAPI); _ADD_TOKEN(cls, NodeGraphNodeAPI); _ADD_TOKEN(cls, SceneGraphPrimAPI); } From 6b8904ba89fd7e982f18a85ea4c4b179fdd772fd Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Tue, 24 Sep 2024 13:52:35 -0700 Subject: [PATCH 03/15] Codify validation rules --- pxr/usd/usdUI/localizationAPI.cpp | 36 +++++++++++++++++++++++++------ pxr/usd/usdUI/localizationAPI.h | 18 ++++++++++++---- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/pxr/usd/usdUI/localizationAPI.cpp b/pxr/usd/usdUI/localizationAPI.cpp index a19b2d7da3..3fbab9a384 100644 --- a/pxr/usd/usdUI/localizationAPI.cpp +++ b/pxr/usd/usdUI/localizationAPI.cpp @@ -232,6 +232,18 @@ PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE +/* static */ +bool UsdUILocalizationAPI::CanLocalize(UsdAttribute const &attribute) { + // Currently, only string types are localizable + return (attribute.GetTypeName() == SdfValueTypeNames->String); +} + +/* static */ +bool UsdUILocalizationAPI::CanLocalize([[maybe_unused]] UsdRelationship const &relationship) { + // Currently no relationships are allowed to be localized , but we provide the API for symmetry + return false; +} + /* static */ UsdProperty UsdUILocalizationAPI::GetDefaultProperty(UsdProperty const &source) { @@ -256,7 +268,7 @@ UsdUILocalizationAPI::GetDefaultProperty(UsdProperty const &source) { return prop; } - +/* static */ TfToken UsdUILocalizationAPI::GetPropertyLanguage(UsdProperty const &prop) { auto nameTokens = prop.SplitName(); if (nameTokens.size() < 3 || nameTokens[nameTokens.size() - 2] != UsdUITokens->lang) { @@ -307,7 +319,7 @@ UsdUILocalizationAPI::GetLocalizedProperty(UsdProperty const &source) const { /* static */ UsdAttribute UsdUILocalizationAPI::CreateLocalizedAttribute(UsdAttribute const &source, TfToken const &localization, - VtValue const &defaultValue, bool writeSparsely) { + VtValue const &defaultValue, bool writeSparsely, bool validate) { const auto prim = source.GetPrim(); if (!prim) { TF_CODING_ERROR("Cannot find attributes parent prim"); @@ -346,6 +358,11 @@ UsdUILocalizationAPI::CreateLocalizedAttribute(UsdAttribute const &source, TfTok return {}; } + if (validate && !UsdUILocalizationAPI::CanLocalize(defaultAttr)) { + TF_CODING_ERROR("This attribute type is not meant to be localized."); + return {}; + } + UsdAttribute attr(prim.CreateAttribute( UsdUILocalizationAPI::GetLocalizedPropertyName(source, localization), defaultAttr.GetTypeName(), @@ -362,12 +379,12 @@ UsdUILocalizationAPI::CreateLocalizedAttribute(UsdAttribute const &source, TfTok UsdAttribute UsdUILocalizationAPI::CreateLocalizedAttribute(UsdAttribute const &source, VtValue const &defaultValue, - bool writeSparsely) const { - return CreateLocalizedAttribute(source, GetName(), defaultValue, writeSparsely); + bool writeSparsely, bool validate) const { + return CreateLocalizedAttribute(source, GetName(), defaultValue, writeSparsely, validate); } UsdRelationship -UsdUILocalizationAPI::CreateLocalizedRelationship(UsdRelationship const &source, TfToken const &localization) { +UsdUILocalizationAPI::CreateLocalizedRelationship(UsdRelationship const &source, TfToken const &localization, bool validate) { const auto prim = source.GetPrim(); if (!prim) { TF_CODING_ERROR("Cannot find attributes parent prim"); @@ -386,6 +403,11 @@ UsdUILocalizationAPI::CreateLocalizedRelationship(UsdRelationship const &source, return {}; } + if (validate && !UsdUILocalizationAPI::CanLocalize(defaultRel)) { + TF_CODING_ERROR("This relationship is not meant to be localized."); + return {}; + } + UsdRelationship rel(prim.CreateRelationship( UsdUILocalizationAPI::GetLocalizedPropertyName(source, localization), defaultRel.IsCustom() @@ -396,8 +418,8 @@ UsdUILocalizationAPI::CreateLocalizedRelationship(UsdRelationship const &source, UsdRelationship -UsdUILocalizationAPI::CreateLocalizedRelationship(UsdRelationship const &source) const{ - return UsdUILocalizationAPI::CreateLocalizedRelationship(source, GetName()); +UsdUILocalizationAPI::CreateLocalizedRelationship(UsdRelationship const &source, bool validate) const{ + return UsdUILocalizationAPI::CreateLocalizedRelationship(source, GetName(), validate); } /* static */ diff --git a/pxr/usd/usdUI/localizationAPI.h b/pxr/usd/usdUI/localizationAPI.h index fbe1228b9f..6197035256 100644 --- a/pxr/usd/usdUI/localizationAPI.h +++ b/pxr/usd/usdUI/localizationAPI.h @@ -290,6 +290,16 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase // - Close the include guard with #endif // ===================================================================== // // --(BEGIN CUSTOM CODE)-- + /// Returns a boolean for whether an attribute can be localized or not. + /// The rules that govern this may be subject to change in the future. + USDUI_API + static bool CanLocalize(UsdAttribute const &attribute); + + /// Returns a boolean for whether a relationship can be localized or not. + /// The rules that govern this may be subject to change in the future. + USDUI_API + static bool CanLocalize(UsdRelationship const &relationship); + /// Returns the version of the property that has no localization specifics. /// If this cannot be found, a default constructed property is returned. /// If the input property doesn't specify a localization, it will be returned itself. @@ -323,24 +333,24 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase USDUI_API static UsdAttribute CreateLocalizedAttribute(UsdAttribute const &source, TfToken const &localization, VtValue const &defaultValue, - bool writeSparsely=false); + bool writeSparsely=false, bool validate=true); /// A convenience method for calling the static version of this method with the localization derived /// from the instance name USDUI_API UsdAttribute CreateLocalizedAttribute(UsdAttribute const &source, VtValue const &defaultValue, - bool writeSparsely=false) const; + bool writeSparsely=false, bool validate=true) const; /// Creates a relationship with the given localization, or returns the relationship if one already exists /// \note It is up to the developer to apply the localization API for this locale to the prim USDUI_API static UsdRelationship - CreateLocalizedRelationship(UsdRelationship const &source, TfToken const &localization); + CreateLocalizedRelationship(UsdRelationship const &source, TfToken const &localization, bool validate=true); /// A convenience method for calling the static version of this method with the localization derived /// from the instance name USDUI_API - UsdRelationship CreateLocalizedRelationship(UsdRelationship const &source) const; + UsdRelationship CreateLocalizedRelationship(UsdRelationship const &source, bool validate=true) const; /// Fills the map with all localized versions of the properties that have Applied schemas on the prim. From 0f14a9d08696f36245f0cd04a4fe26642fa45d5c Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Tue, 24 Sep 2024 13:55:18 -0700 Subject: [PATCH 04/15] Update relationship test to skip validation step --- pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp b/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp index 6faea29d39..2dddf1e6e1 100644 --- a/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp +++ b/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp @@ -66,7 +66,7 @@ main(int argc, char* argv[]) auto baseRelName = TfToken("spam"); auto baseRel = prim.CreateRelationship(baseRelName, false); - auto frRel = frAPI.CreateLocalizedRelationship(baseRel); + auto frRel = frAPI.CreateLocalizedRelationship(baseRel, false); TF_AXIOM(UsdUILocalizationAPI::GetLocalizedProperty(baseRel, fr_ca).GetPath() == frRel.GetPath()); return EXIT_SUCCESS; From f4e5a1b28ccc7064a6c558b45d9534d32a0e64ab Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Tue, 24 Sep 2024 13:57:56 -0700 Subject: [PATCH 05/15] Add documentation for validate --- pxr/usd/usdUI/localizationAPI.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pxr/usd/usdUI/localizationAPI.h b/pxr/usd/usdUI/localizationAPI.h index 6197035256..25d864baa6 100644 --- a/pxr/usd/usdUI/localizationAPI.h +++ b/pxr/usd/usdUI/localizationAPI.h @@ -329,6 +329,8 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase UsdProperty GetLocalizedProperty(UsdProperty const &source) const; /// Creates an attribute with the given localization, or returns the attribute if one already exists + /// \p validate will check if localization can be applied to this attribute. Exercise caution when skipping + /// validation. \sa CanLocalize /// \note It is up to the developer to apply the localization API for this locale to the prim USDUI_API static UsdAttribute @@ -337,17 +339,23 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase /// A convenience method for calling the static version of this method with the localization derived /// from the instance name + /// \p validate will check if localization can be applied to this attribute. Exercise caution when skipping + /// validation. \sa CanLocalize USDUI_API UsdAttribute CreateLocalizedAttribute(UsdAttribute const &source, VtValue const &defaultValue, bool writeSparsely=false, bool validate=true) const; /// Creates a relationship with the given localization, or returns the relationship if one already exists + /// \p validate will check if localization can be applied to this attribute. Exercise caution when skipping + /// validation. \sa CanLocalize /// \note It is up to the developer to apply the localization API for this locale to the prim USDUI_API static UsdRelationship CreateLocalizedRelationship(UsdRelationship const &source, TfToken const &localization, bool validate=true); /// A convenience method for calling the static version of this method with the localization derived + /// \p validate will check if localization can be applied to this attribute. Exercise caution when skipping + /// validation. \sa CanLocalize /// from the instance name USDUI_API UsdRelationship CreateLocalizedRelationship(UsdRelationship const &source, bool validate=true) const; From a5eaf3c1e721d3a24fec31bd900361b30c59b165 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Tue, 24 Sep 2024 14:02:23 -0700 Subject: [PATCH 06/15] Disallow localization of primvars --- pxr/usd/usdUI/CMakeLists.txt | 1 + pxr/usd/usdUI/localizationAPI.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/pxr/usd/usdUI/CMakeLists.txt b/pxr/usd/usdUI/CMakeLists.txt index 812bb3ed04..df4e7a42f9 100644 --- a/pxr/usd/usdUI/CMakeLists.txt +++ b/pxr/usd/usdUI/CMakeLists.txt @@ -9,6 +9,7 @@ pxr_library(usdUI vt sdf usd + usdGeom PUBLIC_HEADERS api.h diff --git a/pxr/usd/usdUI/localizationAPI.cpp b/pxr/usd/usdUI/localizationAPI.cpp index 3fbab9a384..1e8f9db427 100644 --- a/pxr/usd/usdUI/localizationAPI.cpp +++ b/pxr/usd/usdUI/localizationAPI.cpp @@ -5,6 +5,8 @@ // https://openusd.org/license. // #include "pxr/usd/usdUI/localizationAPI.h" + +#include "pxr/usd/usdGeom/primvar.h" #include "pxr/usd/usd/schemaRegistry.h" #include "pxr/usd/usd/typed.h" @@ -234,6 +236,10 @@ PXR_NAMESPACE_OPEN_SCOPE /* static */ bool UsdUILocalizationAPI::CanLocalize(UsdAttribute const &attribute) { + // Primvars are not allowed to be localized + if (UsdGeomPrimvar::IsPrimvar(attribute)) { + return false; + } // Currently, only string types are localizable return (attribute.GetTypeName() == SdfValueTypeNames->String); } From 52bd97a8ab80aca1e16f8f1b880b6d7330d48ef9 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Tue, 24 Sep 2024 16:50:10 -0700 Subject: [PATCH 07/15] Keep instance name in for default accessibility per spiff --- pxr/usd/usdUI/accessibilityAPI.cpp | 19 +++++++------------ pxr/usd/usdUI/accessibilityAPI.h | 1 - pxr/usd/usdUI/generatedSchema.usda | 5 ++--- pxr/usd/usdUI/schema.usda | 1 - .../testenv/testUsdUIAcessibilityAPI.cpp | 6 +++--- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/pxr/usd/usdUI/accessibilityAPI.cpp b/pxr/usd/usdUI/accessibilityAPI.cpp index 8bef735352..cc2c733635 100644 --- a/pxr/usd/usdUI/accessibilityAPI.cpp +++ b/pxr/usd/usdUI/accessibilityAPI.cpp @@ -164,12 +164,7 @@ static inline TfToken _GetNamespacedPropertyName(const TfToken instanceName, const TfToken propName) { - std::string propertyName = UsdUITokens->accessibility.GetString() + ":"; - if (instanceName != UsdUITokens->default_) { - propertyName += instanceName.GetString() + ":"; - } - propertyName += propName.GetString(); - return TfToken(propertyName); + return UsdSchemaRegistry::MakeMultipleApplyNameInstance(propName, instanceName); } UsdAttribute @@ -178,7 +173,7 @@ UsdUIAccessibilityAPI::GetLabelAttr() const return GetPrim().GetAttribute( _GetNamespacedPropertyName( GetName(), - UsdUITokens->label)); + UsdUITokens->accessibility_MultipleApplyTemplate_Label)); } UsdAttribute @@ -187,7 +182,7 @@ UsdUIAccessibilityAPI::CreateLabelAttr(VtValue const &defaultValue, bool writeSp return UsdSchemaBase::_CreateAttr( _GetNamespacedPropertyName( GetName(), - UsdUITokens->label), + UsdUITokens->accessibility_MultipleApplyTemplate_Label), SdfValueTypeNames->String, /* custom = */ false, SdfVariabilityVarying, @@ -201,7 +196,7 @@ UsdUIAccessibilityAPI::GetDescriptionAttr() const return GetPrim().GetAttribute( _GetNamespacedPropertyName( GetName(), - UsdUITokens->description)); + UsdUITokens->accessibility_MultipleApplyTemplate_Description)); } UsdAttribute @@ -210,7 +205,7 @@ UsdUIAccessibilityAPI::CreateDescriptionAttr(VtValue const &defaultValue, bool w return UsdSchemaBase::_CreateAttr( _GetNamespacedPropertyName( GetName(), - UsdUITokens->description), + UsdUITokens->accessibility_MultipleApplyTemplate_Description), SdfValueTypeNames->String, /* custom = */ false, SdfVariabilityVarying, @@ -224,7 +219,7 @@ UsdUIAccessibilityAPI::GetPriorityAttr() const return GetPrim().GetAttribute( _GetNamespacedPropertyName( GetName(), - UsdUITokens->priority)); + UsdUITokens->accessibility_MultipleApplyTemplate_Priority)); } UsdAttribute @@ -233,7 +228,7 @@ UsdUIAccessibilityAPI::CreatePriorityAttr(VtValue const &defaultValue, bool writ return UsdSchemaBase::_CreateAttr( _GetNamespacedPropertyName( GetName(), - UsdUITokens->priority), + UsdUITokens->accessibility_MultipleApplyTemplate_Priority), SdfValueTypeNames->Token, /* custom = */ false, SdfVariabilityUniform, diff --git a/pxr/usd/usdUI/accessibilityAPI.h b/pxr/usd/usdUI/accessibilityAPI.h index 05f0fb536c..019a0a97b5 100644 --- a/pxr/usd/usdUI/accessibilityAPI.h +++ b/pxr/usd/usdUI/accessibilityAPI.h @@ -49,7 +49,6 @@ class SdfAssetPath; /// information for different aspects of the prim, such as size or color. /// /// \note The API will use \em default as an instance name if no namespace is specified. -/// When using "default" as the name, the instance name is elided from the attribute name. /// /// There are several best practices for using this schema.: /// diff --git a/pxr/usd/usdUI/generatedSchema.usda b/pxr/usd/usdUI/generatedSchema.usda index ddd40dc3f3..6cc754bb51 100644 --- a/pxr/usd/usdUI/generatedSchema.usda +++ b/pxr/usd/usdUI/generatedSchema.usda @@ -131,7 +131,7 @@ class Backdrop "Backdrop" ( } class "AccessibilityAPI" ( - doc = ''' + doc = """ This API describes Accessibility information on a Prim that may be surfaced to a given runtimes accessibility frameworks. This information may be used by assistive tooling such as voice controls or screen readers. @@ -145,7 +145,6 @@ class "AccessibilityAPI" ( information for different aspects of the prim, such as size or color. \\note The API will use default as an instance name if no namespace is specified. - When using "default" as the name, the instance name is elided from the attribute name. There are several best practices for using this schema.: @@ -164,7 +163,7 @@ class "AccessibilityAPI" ( recommended convention. Outside of that, accessibility information is not implicitly inherited through a prim hierarchy. The inheritance should be left to the accessibility runtime to decide how best to surface information to users. - ''' + """ ) { string accessibility:__INSTANCE_NAME__:description ( diff --git a/pxr/usd/usdUI/schema.usda b/pxr/usd/usdUI/schema.usda index 01c8420a19..4dfe619d6f 100644 --- a/pxr/usd/usdUI/schema.usda +++ b/pxr/usd/usdUI/schema.usda @@ -204,7 +204,6 @@ class "AccessibilityAPI" ( information for different aspects of the prim, such as size or color. \\note The API will use \\em default as an instance name if no namespace is specified. - When using "default" as the name, the instance name is elided from the attribute name. There are several best practices for using this schema.: diff --git a/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp b/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp index 3bd6de344d..284079299b 100644 --- a/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp +++ b/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp @@ -29,7 +29,7 @@ main(int argc, char* argv[]) // Make sure we create it with the right name std::string label = "The root prim"; - auto defaultLabelName = TfToken("accessibility:label"); + auto defaultLabelName = TfToken("accessibility:default:label"); auto defaultLabel = defaultAPI.CreateLabelAttr(VtValue(label)); TF_AXIOM(defaultLabel.GetName() == defaultLabelName); @@ -43,7 +43,7 @@ main(int argc, char* argv[]) // Make sure we create the description with the right name std::string description = "The greatest prim of all time"; - auto defaultDescriptionName = TfToken("accessibility:description"); + auto defaultDescriptionName = TfToken("accessibility:default:description"); auto defaultDescription = defaultAPI.CreateDescriptionAttr(VtValue(std::string(description))); TF_AXIOM(defaultDescription.GetName() == defaultDescriptionName); @@ -56,7 +56,7 @@ main(int argc, char* argv[]) // Make sure we create the priority with the right name auto priority = UsdUITokens->high; - auto defaultPriorityName = TfToken("accessibility:priority"); + auto defaultPriorityName = TfToken("accessibility:default:priority"); auto defaultPriority = defaultAPI.CreatePriorityAttr(VtValue(priority)); TF_AXIOM(defaultPriority.GetName() == defaultPriorityName); From 89359c4acc24fd656d8829ce5f3b3a241ee0d545 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Thu, 26 Sep 2024 08:06:04 -0700 Subject: [PATCH 08/15] Use default instance name for localization --- pxr/usd/usdUI/localizationAPI.cpp | 23 +++++++++++++++++-- pxr/usd/usdUI/schema.usda | 4 ---- .../testenv/testUsdUILocalizationAPI.cpp | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pxr/usd/usdUI/localizationAPI.cpp b/pxr/usd/usdUI/localizationAPI.cpp index 1e8f9db427..0c318c141b 100644 --- a/pxr/usd/usdUI/localizationAPI.cpp +++ b/pxr/usd/usdUI/localizationAPI.cpp @@ -155,17 +155,36 @@ UsdUILocalizationAPI::_GetTfType() const return _GetStaticTfType(); } +/// Returns the property name prefixed with the correct namespace prefix, which +/// is composed of the the API's propertyNamespacePrefix metadata and the +/// instance name of the API. +static inline +TfToken +_GetNamespacedPropertyName(const TfToken instanceName, const TfToken propName) +{ + return UsdSchemaRegistry::MakeMultipleApplyNameInstance(propName, instanceName); +} + UsdAttribute UsdUILocalizationAPI::GetLanguageAttr() const { - return GetPrim().GetAttribute(UsdUITokens->languageAttribute); + return GetPrim().GetAttribute( + _GetNamespacedPropertyName( + UsdUiTokens->default_, // Always return the one from the default instance name + UsdUITokens->localization_MultipleApplyTemplate_Language)); } UsdAttribute UsdUILocalizationAPI::CreateLanguageAttr(VtValue const &defaultValue, bool writeSparsely) const { + if (GetName() != UsdUiTokens->default_) { + TF_CODING_ERROR("The language attr may only be created with the default API instance name."); + return {}; + } return UsdSchemaBase::_CreateAttr( - UsdUITokens->languageAttribute, + _GetNamespacedPropertyName( + GetName(), + UsdUITokens->localization_MultipleApplyTemplate_Language), SdfValueTypeNames->Token, /* custom = */ false, SdfVariabilityUniform, diff --git a/pxr/usd/usdUI/schema.usda b/pxr/usd/usdUI/schema.usda index 4dfe619d6f..6a51b5c907 100644 --- a/pxr/usd/usdUI/schema.usda +++ b/pxr/usd/usdUI/schema.usda @@ -327,10 +327,6 @@ class "LocalizationAPI" ( string value = "lang" string doc = """The token that delineates language specifications on an attribute""" } - dictionary languageAttribute = { - string value = "localization:lang" - string doc = """The non-namespaced version of the language localization attribute""" - } } } ) { diff --git a/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp b/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp index 2dddf1e6e1..6b3960ee05 100644 --- a/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp +++ b/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp @@ -28,7 +28,7 @@ main(int argc, char* argv[]) auto frAPI = UsdUILocalizationAPI::Apply(prim, fr_ca); auto language = api.CreateLanguageAttr(VtValue(en_us)); - TF_AXIOM(language.GetName() == UsdUITokens->languageAttribute); + TF_AXIOM(language.GetName() == TfToken("localization:default:language")); // Test Default localization From 9c6bacf4efe1baf0d3e495d18c71a8d71bd0730d Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Thu, 26 Sep 2024 08:07:09 -0700 Subject: [PATCH 09/15] Remove unprefixed localization attribute --- pxr/usd/usdUI/tokens.cpp | 2 -- pxr/usd/usdUI/tokens.h | 4 ---- pxr/usd/usdUI/wrapTokens.cpp | 1 - 3 files changed, 7 deletions(-) diff --git a/pxr/usd/usdUI/tokens.cpp b/pxr/usd/usdUI/tokens.cpp index b65ea189e2..37b9413e05 100644 --- a/pxr/usd/usdUI/tokens.cpp +++ b/pxr/usd/usdUI/tokens.cpp @@ -19,7 +19,6 @@ UsdUITokensType::UsdUITokensType() : high("high", TfToken::Immortal), label("label", TfToken::Immortal), lang("lang", TfToken::Immortal), - languageAttribute("localization:lang", TfToken::Immortal), localization("localization", TfToken::Immortal), localization_MultipleApplyTemplate_Language("localization:__INSTANCE_NAME__:language", TfToken::Immortal), low("low", TfToken::Immortal), @@ -53,7 +52,6 @@ UsdUITokensType::UsdUITokensType() : high, label, lang, - languageAttribute, localization, localization_MultipleApplyTemplate_Language, low, diff --git a/pxr/usd/usdUI/tokens.h b/pxr/usd/usdUI/tokens.h index ed2e521030..a4cc529942 100644 --- a/pxr/usd/usdUI/tokens.h +++ b/pxr/usd/usdUI/tokens.h @@ -85,10 +85,6 @@ struct UsdUITokensType { /// /// The token that delineates language specifications on an attribute const TfToken lang; - /// \brief "localization:lang" - /// - /// The non-namespaced version of the language localization attribute - const TfToken languageAttribute; /// \brief "localization" /// /// Property namespace prefix for the UsdUILocalizationAPI schema. diff --git a/pxr/usd/usdUI/wrapTokens.cpp b/pxr/usd/usdUI/wrapTokens.cpp index 424a8ad4e6..d99c0494f9 100644 --- a/pxr/usd/usdUI/wrapTokens.cpp +++ b/pxr/usd/usdUI/wrapTokens.cpp @@ -27,7 +27,6 @@ void wrapUsdUITokens() _ADD_TOKEN(cls, high); _ADD_TOKEN(cls, label); _ADD_TOKEN(cls, lang); - _ADD_TOKEN(cls, languageAttribute); _ADD_TOKEN(cls, localization); _ADD_TOKEN(cls, localization_MultipleApplyTemplate_Language); _ADD_TOKEN(cls, low); From fa316047f4150bda756bc91470381b5df271fbce Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Thu, 26 Sep 2024 11:37:13 -0700 Subject: [PATCH 10/15] Add CreateDefaultAPI and UseDefaultAPI methods --- pxr/usd/usdUI/accessibilityAPI.cpp | 19 ++++++++++++++ pxr/usd/usdUI/accessibilityAPI.h | 18 ++++++++++--- pxr/usd/usdUI/localizationAPI.cpp | 25 +++++++++++++------ pxr/usd/usdUI/localizationAPI.h | 19 +++++++++++--- .../testenv/testUsdUIAcessibilityAPI.cpp | 2 +- .../testenv/testUsdUILocalizationAPI.cpp | 2 +- pxr/usd/usdUI/wrapAccessibilityAPI.cpp | 6 ++--- pxr/usd/usdUI/wrapLocalizationAPI.cpp | 6 ++--- 8 files changed, 76 insertions(+), 21 deletions(-) diff --git a/pxr/usd/usdUI/accessibilityAPI.cpp b/pxr/usd/usdUI/accessibilityAPI.cpp index cc2c733635..b1a02303a1 100644 --- a/pxr/usd/usdUI/accessibilityAPI.cpp +++ b/pxr/usd/usdUI/accessibilityAPI.cpp @@ -296,3 +296,22 @@ PXR_NAMESPACE_CLOSE_SCOPE // 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. // ===================================================================== // // --(BEGIN CUSTOM CODE)-- + +PXR_NAMESPACE_OPEN_SCOPE + +/*static*/ +UsdUIAccessibilityAPI UsdUIAccessibilityAPI::CreateDefaultAPI(const UsdPrim& prim) { + return UsdUIAccessibilityAPI(prim, UsdUITokens->default_); +} + +/*static*/ +UsdUIAccessibilityAPI UsdUIAccessibilityAPI::CreateDefaultAPI(const UsdSchemaBase& schemaObj) { + return UsdUIAccessibilityAPI(schemaObj, UsdUITokens->default_); +} + +/*static*/ +UsdUIAccessibilityAPI UsdUIAccessibilityAPI::ApplyDefaultAPI(const UsdPrim& prim) { + return UsdUIAccessibilityAPI::Apply(prim, UsdUITokens->default_); +} + +PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file diff --git a/pxr/usd/usdUI/accessibilityAPI.h b/pxr/usd/usdUI/accessibilityAPI.h index 019a0a97b5..16ad4695ec 100644 --- a/pxr/usd/usdUI/accessibilityAPI.h +++ b/pxr/usd/usdUI/accessibilityAPI.h @@ -92,7 +92,7 @@ class UsdUIAccessibilityAPI : public UsdAPISchemaBase /// for a \em valid \p prim, but will not immediately throw an error for /// an invalid \p prim explicit UsdUIAccessibilityAPI( - const UsdPrim& prim=UsdPrim(), const TfToken &name=UsdUITokens->default_) + const UsdPrim& prim=UsdPrim(), const TfToken &name=TfToken()) : UsdAPISchemaBase(prim, /*instanceName*/ name) { } @@ -101,7 +101,7 @@ class UsdUIAccessibilityAPI : public UsdAPISchemaBase /// UsdUIAccessibilityAPI(schemaObj.GetPrim(), name), as it preserves /// SchemaBase state. explicit UsdUIAccessibilityAPI( - const UsdSchemaBase& schemaObj, const TfToken &name=UsdUITokens->default_) + const UsdSchemaBase& schemaObj, const TfToken &name) : UsdAPISchemaBase(schemaObj, /*instanceName*/ name) { } @@ -215,7 +215,7 @@ class UsdUIAccessibilityAPI : public UsdAPISchemaBase /// USDUI_API static UsdUIAccessibilityAPI - Apply(const UsdPrim &prim, const TfToken &name=UsdUITokens->default_); + Apply(const UsdPrim &prim, const TfToken &name); protected: /// Returns the kind of schema this class belongs to. @@ -327,6 +327,18 @@ class UsdUIAccessibilityAPI : public UsdAPISchemaBase // - Close the include guard with #endif // ===================================================================== // // --(BEGIN CUSTOM CODE)-- + + /// Creates an instance of the API with the default instance name. + /// /sa UsdUIAccessibilityAPI + static UsdUIAccessibilityAPI CreateDefaultAPI(const UsdPrim& prim); + + /// Creates an instance of the API with a schema object using the default instance name. + /// /sa UsdUIAccessibilityAPI + static UsdUIAccessibilityAPI CreateDefaultAPI(const UsdSchemaBase& schemaObj); + + /// Applies an instance of the API with the default instance name. + /// /sa Apply + static UsdUIAccessibilityAPI ApplyDefaultAPI(const UsdPrim& prim); }; PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdUI/localizationAPI.cpp b/pxr/usd/usdUI/localizationAPI.cpp index 0c318c141b..a553dd981b 100644 --- a/pxr/usd/usdUI/localizationAPI.cpp +++ b/pxr/usd/usdUI/localizationAPI.cpp @@ -5,8 +5,6 @@ // https://openusd.org/license. // #include "pxr/usd/usdUI/localizationAPI.h" - -#include "pxr/usd/usdGeom/primvar.h" #include "pxr/usd/usd/schemaRegistry.h" #include "pxr/usd/usd/typed.h" @@ -170,17 +168,13 @@ UsdUILocalizationAPI::GetLanguageAttr() const { return GetPrim().GetAttribute( _GetNamespacedPropertyName( - UsdUiTokens->default_, // Always return the one from the default instance name + GetName(), UsdUITokens->localization_MultipleApplyTemplate_Language)); } UsdAttribute UsdUILocalizationAPI::CreateLanguageAttr(VtValue const &defaultValue, bool writeSparsely) const { - if (GetName() != UsdUiTokens->default_) { - TF_CODING_ERROR("The language attr may only be created with the default API instance name."); - return {}; - } return UsdSchemaBase::_CreateAttr( _GetNamespacedPropertyName( GetName(), @@ -251,8 +245,25 @@ PXR_NAMESPACE_CLOSE_SCOPE // ===================================================================== // // --(BEGIN CUSTOM CODE)-- +#include "pxr/usd/usdGeom/primvar.h" + PXR_NAMESPACE_OPEN_SCOPE +/*static*/ +UsdUILocalizationAPI UsdUILocalizationAPI::CreateDefaultAPI(const UsdPrim& prim) { + return UsdUILocalizationAPI(prim, UsdUITokens->default_); +} + +/*static*/ +UsdUILocalizationAPI UsdUILocalizationAPI::CreateDefaultAPI(const UsdSchemaBase& schemaObj) { + return UsdUILocalizationAPI(schemaObj, UsdUITokens->default_); +} + +/*static*/ +UsdUILocalizationAPI UsdUILocalizationAPI::ApplyDefaultAPI(const UsdPrim& prim) { + return UsdUILocalizationAPI::Apply(prim, UsdUITokens->default_); +} + /* static */ bool UsdUILocalizationAPI::CanLocalize(UsdAttribute const &attribute) { // Primvars are not allowed to be localized diff --git a/pxr/usd/usdUI/localizationAPI.h b/pxr/usd/usdUI/localizationAPI.h index 25d864baa6..7cfdfc8277 100644 --- a/pxr/usd/usdUI/localizationAPI.h +++ b/pxr/usd/usdUI/localizationAPI.h @@ -106,7 +106,7 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase /// for a \em valid \p prim, but will not immediately throw an error for /// an invalid \p prim explicit UsdUILocalizationAPI( - const UsdPrim& prim=UsdPrim(), const TfToken &name=UsdUITokens->default_) + const UsdPrim& prim=UsdPrim(), const TfToken &name=TfToken()) : UsdAPISchemaBase(prim, /*instanceName*/ name) { } @@ -115,7 +115,7 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase /// UsdUILocalizationAPI(schemaObj.GetPrim(), name), as it preserves /// SchemaBase state. explicit UsdUILocalizationAPI( - const UsdSchemaBase& schemaObj, const TfToken &name=UsdUITokens->default_) + const UsdSchemaBase& schemaObj, const TfToken &name) : UsdAPISchemaBase(schemaObj, /*instanceName*/ name) { } @@ -229,7 +229,7 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase /// USDUI_API static UsdUILocalizationAPI - Apply(const UsdPrim &prim, const TfToken &name=UsdUITokens->default_); + Apply(const UsdPrim &prim, const TfToken &name); protected: /// Returns the kind of schema this class belongs to. @@ -290,6 +290,19 @@ class UsdUILocalizationAPI : public UsdAPISchemaBase // - Close the include guard with #endif // ===================================================================== // // --(BEGIN CUSTOM CODE)-- + + /// Creates an instance of the API with the default instance name. + /// /sa UsdUILocalizationAPI + static UsdUILocalizationAPI CreateDefaultAPI(const UsdPrim& prim); + + /// Creates an instance of the API with a schema object using the default instance name. + /// /sa UsdUILocalizationAPI + static UsdUILocalizationAPI CreateDefaultAPI(const UsdSchemaBase& schemaObj); + + /// Applies an instance of the API with the default instance name. + /// /sa Apply + static UsdUILocalizationAPI ApplyDefaultAPI(const UsdPrim& prim); + /// Returns a boolean for whether an attribute can be localized or not. /// The rules that govern this may be subject to change in the future. USDUI_API diff --git a/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp b/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp index 284079299b..e07caa5b00 100644 --- a/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp +++ b/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp @@ -24,7 +24,7 @@ main(int argc, char* argv[]) VtValue value; // Test Default - auto defaultAPI = UsdUIAccessibilityAPI::Apply(prim); + auto defaultAPI = UsdUIAccessibilityAPI::ApplyDefaultAPI(prim); auto namedAPI = UsdUIAccessibilityAPI::Apply(prim, TfToken("foo")); // Make sure we create it with the right name diff --git a/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp b/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp index 6b3960ee05..b25343e3b7 100644 --- a/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp +++ b/pxr/usd/usdUI/testenv/testUsdUILocalizationAPI.cpp @@ -24,7 +24,7 @@ main(int argc, char* argv[]) auto stage = UsdStage::CreateInMemory(); auto prim = stage->DefinePrim(SdfPath("/Root")); - auto api = UsdUILocalizationAPI::Apply(prim); + auto api = UsdUILocalizationAPI::ApplyDefaultAPI(prim); auto frAPI = UsdUILocalizationAPI::Apply(prim, fr_ca); auto language = api.CreateLanguageAttr(VtValue(en_us)); diff --git a/pxr/usd/usdUI/wrapAccessibilityAPI.cpp b/pxr/usd/usdUI/wrapAccessibilityAPI.cpp index f3c7ce250c..06a3969ed8 100644 --- a/pxr/usd/usdUI/wrapAccessibilityAPI.cpp +++ b/pxr/usd/usdUI/wrapAccessibilityAPI.cpp @@ -98,8 +98,8 @@ void wrapUsdUIAccessibilityAPI() cls("AccessibilityAPI"); cls - .def(init((arg("prim"), arg("name")=UsdUITokens->default_))) - .def(init((arg("schemaObj"), arg("name")=UsdUITokens->default_))) + .def(init((arg("prim"), arg("name")))) + .def(init((arg("schemaObj"), arg("name")))) .def(TfTypePythonClass()) .def("Get", @@ -124,7 +124,7 @@ void wrapUsdUIAccessibilityAPI() .def("CanApply", &_WrapCanApply, (arg("prim"), arg("name"))) .staticmethod("CanApply") - .def("Apply", &This::Apply, (arg("prim"), arg("name")=UsdUITokens->default_)) + .def("Apply", &This::Apply, (arg("prim"), arg("name"))) .staticmethod("Apply") .def("GetSchemaAttributeNames", diff --git a/pxr/usd/usdUI/wrapLocalizationAPI.cpp b/pxr/usd/usdUI/wrapLocalizationAPI.cpp index 6bd89d198a..f8f01bc846 100644 --- a/pxr/usd/usdUI/wrapLocalizationAPI.cpp +++ b/pxr/usd/usdUI/wrapLocalizationAPI.cpp @@ -84,8 +84,8 @@ void wrapUsdUILocalizationAPI() cls("LocalizationAPI"); cls - .def(init((arg("prim"), arg("name")=UsdUITokens->default_))) - .def(init((arg("schemaObj"), arg("name")=UsdUITokens->default_))) + .def(init((arg("prim"), arg("name")))) + .def(init((arg("schemaObj"), arg("name")))) .def(TfTypePythonClass()) .def("Get", @@ -110,7 +110,7 @@ void wrapUsdUILocalizationAPI() .def("CanApply", &_WrapCanApply, (arg("prim"), arg("name"))) .staticmethod("CanApply") - .def("Apply", &This::Apply, (arg("prim"), arg("name")=UsdUITokens->default_)) + .def("Apply", &This::Apply, (arg("prim"), arg("name"))) .staticmethod("Apply") .def("GetSchemaAttributeNames", From b9b4fc7468cac5cf414b2dccfa20504574c4f3a8 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Thu, 26 Sep 2024 11:38:01 -0700 Subject: [PATCH 11/15] Fix newline --- pxr/usd/usdUI/accessibilityAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxr/usd/usdUI/accessibilityAPI.cpp b/pxr/usd/usdUI/accessibilityAPI.cpp index b1a02303a1..57ba8336e3 100644 --- a/pxr/usd/usdUI/accessibilityAPI.cpp +++ b/pxr/usd/usdUI/accessibilityAPI.cpp @@ -314,4 +314,4 @@ UsdUIAccessibilityAPI UsdUIAccessibilityAPI::ApplyDefaultAPI(const UsdPrim& prim return UsdUIAccessibilityAPI::Apply(prim, UsdUITokens->default_); } -PXR_NAMESPACE_CLOSE_SCOPE \ No newline at end of file +PXR_NAMESPACE_CLOSE_SCOPE From 4b5fdc9039adc3565c1259797e682076fd7cef4b Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Fri, 27 Sep 2024 11:59:52 -0700 Subject: [PATCH 12/15] Use extraIncludes instead of manually declaring the include for primvars --- pxr/usd/usdUI/localizationAPI.cpp | 2 -- pxr/usd/usdUI/localizationAPI.h | 3 +++ pxr/usd/usdUI/schema.usda | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pxr/usd/usdUI/localizationAPI.cpp b/pxr/usd/usdUI/localizationAPI.cpp index a553dd981b..cd1944a8f5 100644 --- a/pxr/usd/usdUI/localizationAPI.cpp +++ b/pxr/usd/usdUI/localizationAPI.cpp @@ -245,8 +245,6 @@ PXR_NAMESPACE_CLOSE_SCOPE // ===================================================================== // // --(BEGIN CUSTOM CODE)-- -#include "pxr/usd/usdGeom/primvar.h" - PXR_NAMESPACE_OPEN_SCOPE /*static*/ diff --git a/pxr/usd/usdUI/localizationAPI.h b/pxr/usd/usdUI/localizationAPI.h index 7cfdfc8277..ed0fae4f27 100644 --- a/pxr/usd/usdUI/localizationAPI.h +++ b/pxr/usd/usdUI/localizationAPI.h @@ -16,6 +16,9 @@ #include "pxr/usd/usd/stage.h" #include "pxr/usd/usdUI/tokens.h" +#include "pxr/usd/usdGeom/primvar.h" + + #include "pxr/base/vt/value.h" #include "pxr/base/gf/vec3d.h" diff --git a/pxr/usd/usdUI/schema.usda b/pxr/usd/usdUI/schema.usda index 6a51b5c907..f332be5894 100644 --- a/pxr/usd/usdUI/schema.usda +++ b/pxr/usd/usdUI/schema.usda @@ -322,6 +322,9 @@ class "LocalizationAPI" ( customData = { token apiSchemaType = "multipleApply" token propertyNamespacePrefix = "localization" + string extraIncludes = """ +#include "pxr/usd/usdGeom/primvar.h" + """ dictionary schemaTokens = { dictionary lang = { string value = "lang" From 7ce53bd885d7cdf5e849a4d23f66322bd026d7e4 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Sat, 28 Sep 2024 10:39:22 -0700 Subject: [PATCH 13/15] Revert "Use extraIncludes instead of manually declaring the include for primvars" This reverts commit c4bce756a15d342b5598e2947bcefc708ed4eaf0. --- pxr/usd/usdUI/localizationAPI.cpp | 2 ++ pxr/usd/usdUI/localizationAPI.h | 3 --- pxr/usd/usdUI/schema.usda | 3 --- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pxr/usd/usdUI/localizationAPI.cpp b/pxr/usd/usdUI/localizationAPI.cpp index cd1944a8f5..a553dd981b 100644 --- a/pxr/usd/usdUI/localizationAPI.cpp +++ b/pxr/usd/usdUI/localizationAPI.cpp @@ -245,6 +245,8 @@ PXR_NAMESPACE_CLOSE_SCOPE // ===================================================================== // // --(BEGIN CUSTOM CODE)-- +#include "pxr/usd/usdGeom/primvar.h" + PXR_NAMESPACE_OPEN_SCOPE /*static*/ diff --git a/pxr/usd/usdUI/localizationAPI.h b/pxr/usd/usdUI/localizationAPI.h index ed0fae4f27..7cfdfc8277 100644 --- a/pxr/usd/usdUI/localizationAPI.h +++ b/pxr/usd/usdUI/localizationAPI.h @@ -16,9 +16,6 @@ #include "pxr/usd/usd/stage.h" #include "pxr/usd/usdUI/tokens.h" -#include "pxr/usd/usdGeom/primvar.h" - - #include "pxr/base/vt/value.h" #include "pxr/base/gf/vec3d.h" diff --git a/pxr/usd/usdUI/schema.usda b/pxr/usd/usdUI/schema.usda index f332be5894..6a51b5c907 100644 --- a/pxr/usd/usdUI/schema.usda +++ b/pxr/usd/usdUI/schema.usda @@ -322,9 +322,6 @@ class "LocalizationAPI" ( customData = { token apiSchemaType = "multipleApply" token propertyNamespacePrefix = "localization" - string extraIncludes = """ -#include "pxr/usd/usdGeom/primvar.h" - """ dictionary schemaTokens = { dictionary lang = { string value = "lang" From 08b810c6fb6601caeb4d88ac1c8cc0ea9b43f64f Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Fri, 20 Dec 2024 13:12:40 -0800 Subject: [PATCH 14/15] Splitting out localization from Accessibility PR https://github.com/PixarAnimationStudios/OpenUSD/pull/3271 --- pxr/usd/usdUI/CMakeLists.txt | 14 - pxr/usd/usdUI/accessibilityAPI.cpp | 317 ---------------- pxr/usd/usdUI/accessibilityAPI.h | 346 ------------------ pxr/usd/usdUI/generatedSchema.classes.txt | 2 - pxr/usd/usdUI/generatedSchema.usda | 60 --- pxr/usd/usdUI/plugInfo.json | 11 - pxr/usd/usdUI/schema.usda | 80 ---- .../testenv/testUsdUIAcessibilityAPI.cpp | 91 ----- pxr/usd/usdUI/tokens.cpp | 22 -- pxr/usd/usdUI/tokens.h | 46 +-- pxr/usd/usdUI/wrapAccessibilityAPI.cpp | 202 ---------- pxr/usd/usdUI/wrapTokens.cpp | 11 - 12 files changed, 1 insertion(+), 1201 deletions(-) delete mode 100644 pxr/usd/usdUI/accessibilityAPI.cpp delete mode 100644 pxr/usd/usdUI/accessibilityAPI.h delete mode 100644 pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp delete mode 100644 pxr/usd/usdUI/wrapAccessibilityAPI.cpp diff --git a/pxr/usd/usdUI/CMakeLists.txt b/pxr/usd/usdUI/CMakeLists.txt index df4e7a42f9..cbf5f45b85 100644 --- a/pxr/usd/usdUI/CMakeLists.txt +++ b/pxr/usd/usdUI/CMakeLists.txt @@ -44,20 +44,6 @@ pxr_register_test(testUsdUISceneGraphPrim COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUISceneGraphPrim" ) -pxr_build_test(testUsdUIAcessibilityAPI - LIBRARIES - tf - usd - usdUI - CPPFILES - testenv/testUsdUIAcessibilityAPI.cpp -) - -pxr_register_test(testUsdUIAcessibilityAPI - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUIAcessibilityAPI" - EXPECTED_RETURN_CODE 0 -) - pxr_build_test(testUsdUILocalizationAPI LIBRARIES tf diff --git a/pxr/usd/usdUI/accessibilityAPI.cpp b/pxr/usd/usdUI/accessibilityAPI.cpp deleted file mode 100644 index 57ba8336e3..0000000000 --- a/pxr/usd/usdUI/accessibilityAPI.cpp +++ /dev/null @@ -1,317 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the terms set forth in the LICENSE.txt file available at -// https://openusd.org/license. -// -#include "pxr/usd/usdUI/accessibilityAPI.h" -#include "pxr/usd/usd/schemaRegistry.h" -#include "pxr/usd/usd/typed.h" - -#include "pxr/usd/sdf/types.h" -#include "pxr/usd/sdf/assetPath.h" - -PXR_NAMESPACE_OPEN_SCOPE - -// Register the schema with the TfType system. -TF_REGISTRY_FUNCTION(TfType) -{ - TfType::Define >(); - -} - -/* virtual */ -UsdUIAccessibilityAPI::~UsdUIAccessibilityAPI() -{ -} - -/* static */ -UsdUIAccessibilityAPI -UsdUIAccessibilityAPI::Get(const UsdStagePtr &stage, const SdfPath &path) -{ - if (!stage) { - TF_CODING_ERROR("Invalid stage"); - return UsdUIAccessibilityAPI(); - } - TfToken name; - if (!IsAccessibilityAPIPath(path, &name)) { - TF_CODING_ERROR("Invalid accessibility path <%s>.", path.GetText()); - return UsdUIAccessibilityAPI(); - } - return UsdUIAccessibilityAPI(stage->GetPrimAtPath(path.GetPrimPath()), name); -} - -UsdUIAccessibilityAPI -UsdUIAccessibilityAPI::Get(const UsdPrim &prim, const TfToken &name) -{ - return UsdUIAccessibilityAPI(prim, name); -} - -/* static */ -std::vector -UsdUIAccessibilityAPI::GetAll(const UsdPrim &prim) -{ - std::vector schemas; - - for (const auto &schemaName : - UsdAPISchemaBase::_GetMultipleApplyInstanceNames(prim, _GetStaticTfType())) { - schemas.emplace_back(prim, schemaName); - } - - return schemas; -} - - -/* static */ -bool -UsdUIAccessibilityAPI::IsSchemaPropertyBaseName(const TfToken &baseName) -{ - static TfTokenVector attrsAndRels = { - UsdSchemaRegistry::GetMultipleApplyNameTemplateBaseName( - UsdUITokens->accessibility_MultipleApplyTemplate_Label), - UsdSchemaRegistry::GetMultipleApplyNameTemplateBaseName( - UsdUITokens->accessibility_MultipleApplyTemplate_Description), - UsdSchemaRegistry::GetMultipleApplyNameTemplateBaseName( - UsdUITokens->accessibility_MultipleApplyTemplate_Priority), - }; - - return find(attrsAndRels.begin(), attrsAndRels.end(), baseName) - != attrsAndRels.end(); -} - -/* static */ -bool -UsdUIAccessibilityAPI::IsAccessibilityAPIPath( - const SdfPath &path, TfToken *name) -{ - if (!path.IsPropertyPath()) { - return false; - } - - std::string propertyName = path.GetName(); - TfTokenVector tokens = SdfPath::TokenizeIdentifierAsTokens(propertyName); - - // The baseName of the path can't be one of the - // schema properties. We should validate this in the creation (or apply) - // API. - TfToken baseName = *tokens.rbegin(); - if (IsSchemaPropertyBaseName(baseName)) { - return false; - } - - if (tokens.size() >= 2 - && tokens[0] == UsdUITokens->accessibility) { - *name = TfToken(propertyName.substr( - UsdUITokens->accessibility.GetString().size() + 1)); - return true; - } - - return false; -} - -/* virtual */ -UsdSchemaKind UsdUIAccessibilityAPI::_GetSchemaKind() const -{ - return UsdUIAccessibilityAPI::schemaKind; -} - -/* static */ -bool -UsdUIAccessibilityAPI::CanApply( - const UsdPrim &prim, const TfToken &name, std::string *whyNot) -{ - return prim.CanApplyAPI(name, whyNot); -} - -/* static */ -UsdUIAccessibilityAPI -UsdUIAccessibilityAPI::Apply(const UsdPrim &prim, const TfToken &name) -{ - if (prim.ApplyAPI(name)) { - return UsdUIAccessibilityAPI(prim, name); - } - return UsdUIAccessibilityAPI(); -} - -/* static */ -const TfType & -UsdUIAccessibilityAPI::_GetStaticTfType() -{ - static TfType tfType = TfType::Find(); - return tfType; -} - -/* static */ -bool -UsdUIAccessibilityAPI::_IsTypedSchema() -{ - static bool isTyped = _GetStaticTfType().IsA(); - return isTyped; -} - -/* virtual */ -const TfType & -UsdUIAccessibilityAPI::_GetTfType() const -{ - return _GetStaticTfType(); -} - -/// Returns the property name prefixed with the correct namespace prefix, which -/// is composed of the the API's propertyNamespacePrefix metadata and the -/// instance name of the API. -static inline -TfToken -_GetNamespacedPropertyName(const TfToken instanceName, const TfToken propName) -{ - return UsdSchemaRegistry::MakeMultipleApplyNameInstance(propName, instanceName); -} - -UsdAttribute -UsdUIAccessibilityAPI::GetLabelAttr() const -{ - return GetPrim().GetAttribute( - _GetNamespacedPropertyName( - GetName(), - UsdUITokens->accessibility_MultipleApplyTemplate_Label)); -} - -UsdAttribute -UsdUIAccessibilityAPI::CreateLabelAttr(VtValue const &defaultValue, bool writeSparsely) const -{ - return UsdSchemaBase::_CreateAttr( - _GetNamespacedPropertyName( - GetName(), - UsdUITokens->accessibility_MultipleApplyTemplate_Label), - SdfValueTypeNames->String, - /* custom = */ false, - SdfVariabilityVarying, - defaultValue, - writeSparsely); -} - -UsdAttribute -UsdUIAccessibilityAPI::GetDescriptionAttr() const -{ - return GetPrim().GetAttribute( - _GetNamespacedPropertyName( - GetName(), - UsdUITokens->accessibility_MultipleApplyTemplate_Description)); -} - -UsdAttribute -UsdUIAccessibilityAPI::CreateDescriptionAttr(VtValue const &defaultValue, bool writeSparsely) const -{ - return UsdSchemaBase::_CreateAttr( - _GetNamespacedPropertyName( - GetName(), - UsdUITokens->accessibility_MultipleApplyTemplate_Description), - SdfValueTypeNames->String, - /* custom = */ false, - SdfVariabilityVarying, - defaultValue, - writeSparsely); -} - -UsdAttribute -UsdUIAccessibilityAPI::GetPriorityAttr() const -{ - return GetPrim().GetAttribute( - _GetNamespacedPropertyName( - GetName(), - UsdUITokens->accessibility_MultipleApplyTemplate_Priority)); -} - -UsdAttribute -UsdUIAccessibilityAPI::CreatePriorityAttr(VtValue const &defaultValue, bool writeSparsely) const -{ - return UsdSchemaBase::_CreateAttr( - _GetNamespacedPropertyName( - GetName(), - UsdUITokens->accessibility_MultipleApplyTemplate_Priority), - SdfValueTypeNames->Token, - /* custom = */ false, - SdfVariabilityUniform, - defaultValue, - writeSparsely); -} - -namespace { -static inline TfTokenVector -_ConcatenateAttributeNames(const TfTokenVector& left,const TfTokenVector& right) -{ - TfTokenVector result; - result.reserve(left.size() + right.size()); - result.insert(result.end(), left.begin(), left.end()); - result.insert(result.end(), right.begin(), right.end()); - return result; -} -} - -/*static*/ -const TfTokenVector& -UsdUIAccessibilityAPI::GetSchemaAttributeNames(bool includeInherited) -{ - static TfTokenVector localNames = { - UsdUITokens->accessibility_MultipleApplyTemplate_Label, - UsdUITokens->accessibility_MultipleApplyTemplate_Description, - UsdUITokens->accessibility_MultipleApplyTemplate_Priority, - }; - static TfTokenVector allNames = - _ConcatenateAttributeNames( - UsdAPISchemaBase::GetSchemaAttributeNames(true), - localNames); - - if (includeInherited) - return allNames; - else - return localNames; -} - -/*static*/ -TfTokenVector -UsdUIAccessibilityAPI::GetSchemaAttributeNames( - bool includeInherited, const TfToken &instanceName) -{ - const TfTokenVector &attrNames = GetSchemaAttributeNames(includeInherited); - if (instanceName.IsEmpty()) { - return attrNames; - } - TfTokenVector result; - result.reserve(attrNames.size()); - for (const TfToken &attrName : attrNames) { - result.push_back( - UsdSchemaRegistry::MakeMultipleApplyNameInstance(attrName, instanceName)); - } - return result; -} - -PXR_NAMESPACE_CLOSE_SCOPE - -// ===================================================================== // -// Feel free to add custom code below this line. It will be preserved by -// the code generator. -// -// Just remember to wrap code in the appropriate delimiters: -// 'PXR_NAMESPACE_OPEN_SCOPE', 'PXR_NAMESPACE_CLOSE_SCOPE'. -// ===================================================================== // -// --(BEGIN CUSTOM CODE)-- - -PXR_NAMESPACE_OPEN_SCOPE - -/*static*/ -UsdUIAccessibilityAPI UsdUIAccessibilityAPI::CreateDefaultAPI(const UsdPrim& prim) { - return UsdUIAccessibilityAPI(prim, UsdUITokens->default_); -} - -/*static*/ -UsdUIAccessibilityAPI UsdUIAccessibilityAPI::CreateDefaultAPI(const UsdSchemaBase& schemaObj) { - return UsdUIAccessibilityAPI(schemaObj, UsdUITokens->default_); -} - -/*static*/ -UsdUIAccessibilityAPI UsdUIAccessibilityAPI::ApplyDefaultAPI(const UsdPrim& prim) { - return UsdUIAccessibilityAPI::Apply(prim, UsdUITokens->default_); -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdUI/accessibilityAPI.h b/pxr/usd/usdUI/accessibilityAPI.h deleted file mode 100644 index 16ad4695ec..0000000000 --- a/pxr/usd/usdUI/accessibilityAPI.h +++ /dev/null @@ -1,346 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the terms set forth in the LICENSE.txt file available at -// https://openusd.org/license. -// -#ifndef USDUI_GENERATED_ACCESSIBILITYAPI_H -#define USDUI_GENERATED_ACCESSIBILITYAPI_H - -/// \file usdUI/accessibilityAPI.h - -#include "pxr/pxr.h" -#include "pxr/usd/usdUI/api.h" -#include "pxr/usd/usd/apiSchemaBase.h" -#include "pxr/usd/usd/prim.h" -#include "pxr/usd/usd/stage.h" -#include "pxr/usd/usdUI/tokens.h" - -#include "pxr/base/vt/value.h" - -#include "pxr/base/gf/vec3d.h" -#include "pxr/base/gf/vec3f.h" -#include "pxr/base/gf/matrix4d.h" - -#include "pxr/base/tf/token.h" -#include "pxr/base/tf/type.h" - -PXR_NAMESPACE_OPEN_SCOPE - -class SdfAssetPath; - -// -------------------------------------------------------------------------- // -// ACCESSIBILITYAPI // -// -------------------------------------------------------------------------- // - -/// \class UsdUIAccessibilityAPI -/// -/// -/// This API describes \em Accessibility information on a Prim that may be surfaced to a given runtimes -/// accessibility frameworks. -/// This information may be used by assistive tooling such as voice controls or screen readers. -/// Accessibility information is provided as a standard triplet of label, description and priority. -/// -/// OpenUSD does not provide a accessibility runtime itself, but endeavours to provide the information needed for -/// compatible runtimes to extract and present this information. -/// -/// This is a multiple apply schema, and so may have multiple namespaced accessibility triplets, where a instance -/// name may reflect a given purpose for that triplet. For example, you may desire to express different -/// information for different aspects of the prim, such as size or color. -/// -/// \note The API will use \em default as an instance name if no namespace is specified. -/// -/// There are several best practices for using this schema.: -/// -/// \li Most accessibility runtimes support a single accessibility description. Therefore we recommend placing -/// any critical information in the default instance. -/// -/// \li A default value should be authored if using time sampled accessibility information. -/// This helps accessibility runtimes that do not currently support time sampled information. -/// -/// \li Provide accessibility information of your scene on the default prim of the layer, and any top level prims. -/// This allows accessibility systems to provide concise scene descriptions to a user, but also allows supporting -/// accessibility systems that either do not support hierarchy information or when a user has turned off that level -/// of granularity. Accessibility information may still be provided on other prims in the hierarchy. -/// -/// \note The use of the default prim and top level prims for scene accessibility descriptions is a -/// recommended convention. Outside of that, accessibility information is not implicitly inherited through -/// a prim hierarchy. The inheritance should be left to the accessibility runtime to decide how best to -/// surface information to users. -/// -/// -/// For any described attribute \em Fallback \em Value or \em Allowed \em Values below -/// that are text/tokens, the actual token is published and defined in \ref UsdUITokens. -/// So to set an attribute to the value "rightHanded", use UsdUITokens->rightHanded -/// as the value. -/// -class UsdUIAccessibilityAPI : public UsdAPISchemaBase -{ -public: - /// Compile time constant representing what kind of schema this class is. - /// - /// \sa UsdSchemaKind - static const UsdSchemaKind schemaKind = UsdSchemaKind::MultipleApplyAPI; - - /// Construct a UsdUIAccessibilityAPI on UsdPrim \p prim with - /// name \p name . Equivalent to - /// UsdUIAccessibilityAPI::Get( - /// prim.GetStage(), - /// prim.GetPath().AppendProperty( - /// "accessibility:name")); - /// - /// for a \em valid \p prim, but will not immediately throw an error for - /// an invalid \p prim - explicit UsdUIAccessibilityAPI( - const UsdPrim& prim=UsdPrim(), const TfToken &name=TfToken()) - : UsdAPISchemaBase(prim, /*instanceName*/ name) - { } - - /// Construct a UsdUIAccessibilityAPI on the prim held by \p schemaObj with - /// name \p name. Should be preferred over - /// UsdUIAccessibilityAPI(schemaObj.GetPrim(), name), as it preserves - /// SchemaBase state. - explicit UsdUIAccessibilityAPI( - const UsdSchemaBase& schemaObj, const TfToken &name) - : UsdAPISchemaBase(schemaObj, /*instanceName*/ name) - { } - - /// Destructor. - USDUI_API - virtual ~UsdUIAccessibilityAPI(); - - /// Return a vector of names of all pre-declared attributes for this schema - /// class and all its ancestor classes. Does not include attributes that - /// may be authored by custom/extended methods of the schemas involved. - USDUI_API - static const TfTokenVector & - GetSchemaAttributeNames(bool includeInherited=true); - - /// Return a vector of names of all pre-declared attributes for this schema - /// class and all its ancestor classes for a given instance name. Does not - /// include attributes that may be authored by custom/extended methods of - /// the schemas involved. The names returned will have the proper namespace - /// prefix. - USDUI_API - static TfTokenVector - GetSchemaAttributeNames(bool includeInherited, const TfToken &instanceName); - - /// Returns the name of this multiple-apply schema instance - TfToken GetName() const { - return _GetInstanceName(); - } - - /// Return a UsdUIAccessibilityAPI holding the prim adhering to this - /// schema at \p path on \p stage. If no prim exists at \p path on - /// \p stage, or if the prim at that path does not adhere to this schema, - /// return an invalid schema object. \p path must be of the format - /// .accessibility:name . - /// - /// This is shorthand for the following: - /// - /// \code - /// TfToken name = SdfPath::StripNamespace(path.GetToken()); - /// UsdUIAccessibilityAPI( - /// stage->GetPrimAtPath(path.GetPrimPath()), name); - /// \endcode - /// - USDUI_API - static UsdUIAccessibilityAPI - Get(const UsdStagePtr &stage, const SdfPath &path); - - /// Return a UsdUIAccessibilityAPI with name \p name holding the - /// prim \p prim. Shorthand for UsdUIAccessibilityAPI(prim, name); - USDUI_API - static UsdUIAccessibilityAPI - Get(const UsdPrim &prim, const TfToken &name); - - /// Return a vector of all named instances of UsdUIAccessibilityAPI on the - /// given \p prim. - USDUI_API - static std::vector - GetAll(const UsdPrim &prim); - - /// Checks if the given name \p baseName is the base name of a property - /// of AccessibilityAPI. - USDUI_API - static bool - IsSchemaPropertyBaseName(const TfToken &baseName); - - /// Checks if the given path \p path is of an API schema of type - /// AccessibilityAPI. If so, it stores the instance name of - /// the schema in \p name and returns true. Otherwise, it returns false. - USDUI_API - static bool - IsAccessibilityAPIPath(const SdfPath &path, TfToken *name); - - /// Returns true if this multiple-apply API schema can be applied, - /// with the given instance name, \p name, to the given \p prim. If this - /// schema can not be a applied the prim, this returns false and, if - /// provided, populates \p whyNot with the reason it can not be applied. - /// - /// Note that if CanApply returns false, that does not necessarily imply - /// that calling Apply will fail. Callers are expected to call CanApply - /// before calling Apply if they want to ensure that it is valid to - /// apply a schema. - /// - /// \sa UsdPrim::GetAppliedSchemas() - /// \sa UsdPrim::HasAPI() - /// \sa UsdPrim::CanApplyAPI() - /// \sa UsdPrim::ApplyAPI() - /// \sa UsdPrim::RemoveAPI() - /// - USDUI_API - static bool - CanApply(const UsdPrim &prim, const TfToken &name, - std::string *whyNot=nullptr); - - /// Applies this multiple-apply API schema to the given \p prim - /// along with the given instance name, \p name. - /// - /// This information is stored by adding "AccessibilityAPI:name" - /// to the token-valued, listOp metadata \em apiSchemas on the prim. - /// For example, if \p name is 'instance1', the token - /// 'AccessibilityAPI:instance1' is added to 'apiSchemas'. - /// - /// \return A valid UsdUIAccessibilityAPI object is returned upon success. - /// An invalid (or empty) UsdUIAccessibilityAPI object is returned upon - /// failure. See \ref UsdPrim::ApplyAPI() for - /// conditions resulting in failure. - /// - /// \sa UsdPrim::GetAppliedSchemas() - /// \sa UsdPrim::HasAPI() - /// \sa UsdPrim::CanApplyAPI() - /// \sa UsdPrim::ApplyAPI() - /// \sa UsdPrim::RemoveAPI() - /// - USDUI_API - static UsdUIAccessibilityAPI - Apply(const UsdPrim &prim, const TfToken &name); - -protected: - /// Returns the kind of schema this class belongs to. - /// - /// \sa UsdSchemaKind - USDUI_API - UsdSchemaKind _GetSchemaKind() const override; - -private: - // needs to invoke _GetStaticTfType. - friend class UsdSchemaRegistry; - USDUI_API - static const TfType &_GetStaticTfType(); - - static bool _IsTypedSchema(); - - // override SchemaBase virtuals. - USDUI_API - const TfType &_GetTfType() const override; - -public: - // --------------------------------------------------------------------- // - // LABEL - // --------------------------------------------------------------------- // - /// A short label to concisely describe the prim. - /// It is not recommended to time vary the label unless the concise description changes substantially. - /// - /// | || - /// | -- | -- | - /// | Declaration | `string label` | - /// | C++ Type | std::string | - /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | - USDUI_API - UsdAttribute GetLabelAttr() const; - - /// See GetLabelAttr(), and also - /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. - /// If specified, author \p defaultValue as the attribute's default, - /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - - /// the default for \p writeSparsely is \c false. - USDUI_API - UsdAttribute CreateLabelAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; - -public: - // --------------------------------------------------------------------- // - // DESCRIPTION - // --------------------------------------------------------------------- // - /// An extended description of the prim to provide more details. - /// If a label attribute is not authored in a given instance name, the description attribute should not be used - /// in it its place. A description is an optional attribute, and some accessibility systems may only use the label. - /// - /// Descriptions may be time varying for runtimes that support it. For example, you may describe what a character - /// is doing at a given time. - /// - /// - /// | || - /// | -- | -- | - /// | Declaration | `string description` | - /// | C++ Type | std::string | - /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | - USDUI_API - UsdAttribute GetDescriptionAttr() const; - - /// See GetDescriptionAttr(), and also - /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. - /// If specified, author \p defaultValue as the attribute's default, - /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - - /// the default for \p writeSparsely is \c false. - USDUI_API - UsdAttribute CreateDescriptionAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; - -public: - // --------------------------------------------------------------------- // - // PRIORITY - // --------------------------------------------------------------------- // - /// A hint to the accessibility runtime of how to prioritize this instances label and description, - /// relative to others. This attribute is optional. Accessibility runtimes may choose to apply their own - /// priority systems that override this. - /// - /// Priority may not be time varying. - /// - /// - /// | || - /// | -- | -- | - /// | Declaration | `uniform token priority = "standard"` | - /// | C++ Type | TfToken | - /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | - /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | - /// | \ref UsdUITokens "Allowed Values" | low, standard, high | - USDUI_API - UsdAttribute GetPriorityAttr() const; - - /// See GetPriorityAttr(), and also - /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. - /// If specified, author \p defaultValue as the attribute's default, - /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - - /// the default for \p writeSparsely is \c false. - USDUI_API - UsdAttribute CreatePriorityAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; - -public: - // ===================================================================== // - // Feel free to add custom code below this line, it will be preserved by - // the code generator. - // - // Just remember to: - // - Close the class declaration with }; - // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE - // - Close the include guard with #endif - // ===================================================================== // - // --(BEGIN CUSTOM CODE)-- - - /// Creates an instance of the API with the default instance name. - /// /sa UsdUIAccessibilityAPI - static UsdUIAccessibilityAPI CreateDefaultAPI(const UsdPrim& prim); - - /// Creates an instance of the API with a schema object using the default instance name. - /// /sa UsdUIAccessibilityAPI - static UsdUIAccessibilityAPI CreateDefaultAPI(const UsdSchemaBase& schemaObj); - - /// Applies an instance of the API with the default instance name. - /// /sa Apply - static UsdUIAccessibilityAPI ApplyDefaultAPI(const UsdPrim& prim); -}; - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif diff --git a/pxr/usd/usdUI/generatedSchema.classes.txt b/pxr/usd/usdUI/generatedSchema.classes.txt index 57a6fbfab5..13e164c2fd 100644 --- a/pxr/usd/usdUI/generatedSchema.classes.txt +++ b/pxr/usd/usdUI/generatedSchema.classes.txt @@ -1,7 +1,6 @@ # WARNING: THIS FILE IS GENERATED BY usdGenSchema. DO NOT EDIT. # Public Classes -accessibilityAPI backdrop localizationAPI nodeGraphNodeAPI @@ -10,7 +9,6 @@ tokens # Python Module Files module.cpp -wrapAccessibilityAPI.cpp wrapBackdrop.cpp wrapLocalizationAPI.cpp wrapNodeGraphNodeAPI.cpp diff --git a/pxr/usd/usdUI/generatedSchema.usda b/pxr/usd/usdUI/generatedSchema.usda index 6cc754bb51..c497c971f4 100644 --- a/pxr/usd/usdUI/generatedSchema.usda +++ b/pxr/usd/usdUI/generatedSchema.usda @@ -130,66 +130,6 @@ class Backdrop "Backdrop" ( ) } -class "AccessibilityAPI" ( - doc = """ - This API describes Accessibility information on a Prim that may be surfaced to a given runtimes - accessibility frameworks. - This information may be used by assistive tooling such as voice controls or screen readers. - Accessibility information is provided as a standard triplet of label, description and priority. - - OpenUSD does not provide a accessibility runtime itself, but endeavours to provide the information needed for - compatible runtimes to extract and present this information. - - This is a multiple apply schema, and so may have multiple namespaced accessibility triplets, where a instance - name may reflect a given purpose for that triplet. For example, you may desire to express different - information for different aspects of the prim, such as size or color. - - \\note The API will use default as an instance name if no namespace is specified. - - There are several best practices for using this schema.: - - - Most accessibility runtimes support a single accessibility description. Therefore we recommend placing - any critical information in the default instance. - - - A default value should be authored if using time sampled accessibility information. - This helps accessibility runtimes that do not currently support time sampled information. - - - Provide accessibility information of your scene on the default prim of the layer, and any top level prims. - This allows accessibility systems to provide concise scene descriptions to a user, but also allows supporting - accessibility systems that either do not support hierarchy information or when a user has turned off that level - of granularity. Accessibility information may still be provided on other prims in the hierarchy. - - \\note The use of the default prim and top level prims for scene accessibility descriptions is a - recommended convention. Outside of that, accessibility information is not implicitly inherited through - a prim hierarchy. The inheritance should be left to the accessibility runtime to decide how best to - surface information to users. - """ -) -{ - string accessibility:__INSTANCE_NAME__:description ( - doc = """An extended description of the prim to provide more details. - If a label attribute is not authored in a given instance name, the description attribute should not be used - in it its place. A description is an optional attribute, and some accessibility systems may only use the label. - - Descriptions may be time varying for runtimes that support it. For example, you may describe what a character - is doing at a given time. - """ - ) - string accessibility:__INSTANCE_NAME__:label ( - doc = """A short label to concisely describe the prim. - It is not recommended to time vary the label unless the concise description changes substantially.""" - ) - uniform token accessibility:__INSTANCE_NAME__:priority = "standard" ( - allowedTokens = ["low", "standard", "high"] - doc = """A hint to the accessibility runtime of how to prioritize this instances label and description, - relative to others. This attribute is optional. Accessibility runtimes may choose to apply their own - priority systems that override this. - - Priority may not be time varying. - """ - ) -} - class "LocalizationAPI" ( doc = """This API describes em Language localization information for attributes. diff --git a/pxr/usd/usdUI/plugInfo.json b/pxr/usd/usdUI/plugInfo.json index 155c150e5b..b94fc9a6ff 100644 --- a/pxr/usd/usdUI/plugInfo.json +++ b/pxr/usd/usdUI/plugInfo.json @@ -6,17 +6,6 @@ { "Info": { "Types": { - "UsdUIAccessibilityAPI": { - "alias": { - "UsdSchemaBase": "AccessibilityAPI" - }, - "autoGenerated": true, - "bases": [ - "UsdAPISchemaBase" - ], - "schemaIdentifier": "AccessibilityAPI", - "schemaKind": "multipleApplyAPI" - }, "UsdUIBackdrop": { "alias": { "UsdSchemaBase": "Backdrop" diff --git a/pxr/usd/usdUI/schema.usda b/pxr/usd/usdUI/schema.usda index 6a51b5c907..e90ecd5e65 100644 --- a/pxr/usd/usdUI/schema.usda +++ b/pxr/usd/usdUI/schema.usda @@ -188,86 +188,6 @@ class Backdrop "Backdrop" ( ) } -class "AccessibilityAPI" ( - inherits = - doc = """ - This API describes \\em Accessibility information on a Prim that may be surfaced to a given runtimes - accessibility frameworks. - This information may be used by assistive tooling such as voice controls or screen readers. - Accessibility information is provided as a standard triplet of label, description and priority. - - OpenUSD does not provide a accessibility runtime itself, but endeavours to provide the information needed for - compatible runtimes to extract and present this information. - - This is a multiple apply schema, and so may have multiple namespaced accessibility triplets, where a instance - name may reflect a given purpose for that triplet. For example, you may desire to express different - information for different aspects of the prim, such as size or color. - - \\note The API will use \\em default as an instance name if no namespace is specified. - - There are several best practices for using this schema.: - - \\li Most accessibility runtimes support a single accessibility description. Therefore we recommend placing - any critical information in the default instance. - - \\li A default value should be authored if using time sampled accessibility information. - This helps accessibility runtimes that do not currently support time sampled information. - - \\li Provide accessibility information of your scene on the default prim of the layer, and any top level prims. - This allows accessibility systems to provide concise scene descriptions to a user, but also allows supporting - accessibility systems that either do not support hierarchy information or when a user has turned off that level - of granularity. Accessibility information may still be provided on other prims in the hierarchy. - - \\note The use of the default prim and top level prims for scene accessibility descriptions is a - recommended convention. Outside of that, accessibility information is not implicitly inherited through - a prim hierarchy. The inheritance should be left to the accessibility runtime to decide how best to - surface information to users. - """ - - customData = { - token apiSchemaType = "multipleApply" - token propertyNamespacePrefix = "accessibility" - dictionary schemaTokens = { - dictionary label = { - string value = "label" - string doc = """Name of the label attribute""" - } - dictionary description = { - string value = "description" - string doc = """Name of the description attribute""" - } - dictionary priority = { - string value = "priority" - string doc = """Name of the priority attribute""" - } - } - } -) { - string label ( - doc = """A short label to concisely describe the prim. - It is not recommended to time vary the label unless the concise description changes substantially.""" - ) - - string description ( - doc = """An extended description of the prim to provide more details. - If a label attribute is not authored in a given instance name, the description attribute should not be used - in it its place. A description is an optional attribute, and some accessibility systems may only use the label. - - Descriptions may be time varying for runtimes that support it. For example, you may describe what a character - is doing at a given time. - """ - ) - - uniform token priority = "standard" ( - doc = """A hint to the accessibility runtime of how to prioritize this instances label and description, - relative to others. This attribute is optional. Accessibility runtimes may choose to apply their own - priority systems that override this. - - Priority may not be time varying. - """ - allowedTokens = ["low", "standard", "high"] - ) -} class "LocalizationAPI" ( inherits = diff --git a/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp b/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp deleted file mode 100644 index e07caa5b00..0000000000 --- a/pxr/usd/usdUI/testenv/testUsdUIAcessibilityAPI.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the terms set forth in the LICENSE.txt file available at -// https://openusd.org/license. -// - -#include "pxr/pxr.h" -#include "pxr/usd/usd/stage.h" -#include "pxr/usd/usd/prim.h" -#include "pxr/usd/usdUI/accessibilityAPI.h" -#include "pxr/usd/usdUI/tokens.h" -#include "pxr/base/tf/diagnostic.h" - - -PXR_NAMESPACE_USING_DIRECTIVE - -int -main(int argc, char* argv[]) -{ - auto stage = UsdStage::CreateInMemory(); - - auto prim = stage->DefinePrim(SdfPath("/Root")); - VtValue value; - - // Test Default - auto defaultAPI = UsdUIAccessibilityAPI::ApplyDefaultAPI(prim); - auto namedAPI = UsdUIAccessibilityAPI::Apply(prim, TfToken("foo")); - - // Make sure we create it with the right name - std::string label = "The root prim"; - auto defaultLabelName = TfToken("accessibility:default:label"); - auto defaultLabel = defaultAPI.CreateLabelAttr(VtValue(label)); - TF_AXIOM(defaultLabel.GetName() == defaultLabelName); - - // Make sure we get the same name back and the values are correct - defaultLabel = defaultAPI.GetLabelAttr(); - TF_AXIOM(defaultLabel.GetName() == defaultLabelName); - - defaultLabel.Get(&value); - TF_AXIOM(value.IsHolding()); - TF_AXIOM(value.Get() == label); - - // Make sure we create the description with the right name - std::string description = "The greatest prim of all time"; - auto defaultDescriptionName = TfToken("accessibility:default:description"); - auto defaultDescription = defaultAPI.CreateDescriptionAttr(VtValue(std::string(description))); - TF_AXIOM(defaultDescription.GetName() == defaultDescriptionName); - - // Make sure we get the same name and value back - defaultDescription = defaultAPI.GetDescriptionAttr(); - TF_AXIOM(defaultDescription.GetName() == defaultDescriptionName); - defaultDescription.Get(&value); - TF_AXIOM(value.IsHolding()); - TF_AXIOM(value.Get() == description); - - // Make sure we create the priority with the right name - auto priority = UsdUITokens->high; - auto defaultPriorityName = TfToken("accessibility:default:priority"); - auto defaultPriority = defaultAPI.CreatePriorityAttr(VtValue(priority)); - TF_AXIOM(defaultPriority.GetName() == defaultPriorityName); - - // Make sure we get the same name and value back - defaultPriority = defaultAPI.GetPriorityAttr(); - TF_AXIOM(defaultPriority.GetName() == defaultPriorityName); - defaultPriority.Get(&value); - TF_AXIOM(value.IsHolding()); - TF_AXIOM(value.Get() == priority); - - // Check that the named APIs are created with the correct names and come back with the same name - auto namedLabelName = TfToken("accessibility:foo:label"); - auto namedDescriptionName = TfToken("accessibility:foo:description"); - auto namedPriorityName = TfToken("accessibility:foo:priority"); - - auto namedLabel = namedAPI.CreateLabelAttr(VtValue(label)); - TF_AXIOM(namedLabel.GetName() == namedLabelName); - namedLabel = namedAPI.GetLabelAttr(); - TF_AXIOM(namedLabel.GetName() == namedLabelName); - - auto namedDescription = namedAPI.CreateDescriptionAttr(VtValue(description)); - TF_AXIOM(namedDescription.GetName() == namedDescriptionName); - namedDescription = namedAPI.GetDescriptionAttr(); - TF_AXIOM(namedDescription.GetName() == namedDescriptionName); - - auto namedPriority = namedAPI.CreatePriorityAttr(VtValue(priority)); - TF_AXIOM(namedPriority.GetName() == namedPriorityName); - namedPriority = namedAPI.GetPriorityAttr(); - TF_AXIOM(namedPriority.GetName() == namedPriorityName); - - return EXIT_SUCCESS; -} \ No newline at end of file diff --git a/pxr/usd/usdUI/tokens.cpp b/pxr/usd/usdUI/tokens.cpp index 37b9413e05..014fbb9f7a 100644 --- a/pxr/usd/usdUI/tokens.cpp +++ b/pxr/usd/usdUI/tokens.cpp @@ -9,23 +9,13 @@ PXR_NAMESPACE_OPEN_SCOPE UsdUITokensType::UsdUITokensType() : - accessibility("accessibility", TfToken::Immortal), - accessibility_MultipleApplyTemplate_Description("accessibility:__INSTANCE_NAME__:description", TfToken::Immortal), - accessibility_MultipleApplyTemplate_Label("accessibility:__INSTANCE_NAME__:label", TfToken::Immortal), - accessibility_MultipleApplyTemplate_Priority("accessibility:__INSTANCE_NAME__:priority", TfToken::Immortal), closed("closed", TfToken::Immortal), default_("default", TfToken::Immortal), - description("description", TfToken::Immortal), - high("high", TfToken::Immortal), - label("label", TfToken::Immortal), lang("lang", TfToken::Immortal), localization("localization", TfToken::Immortal), localization_MultipleApplyTemplate_Language("localization:__INSTANCE_NAME__:language", TfToken::Immortal), - low("low", TfToken::Immortal), minimized("minimized", TfToken::Immortal), open("open", TfToken::Immortal), - priority("priority", TfToken::Immortal), - standard("standard", TfToken::Immortal), uiDescription("ui:description", TfToken::Immortal), uiDisplayGroup("ui:displayGroup", TfToken::Immortal), uiDisplayName("ui:displayName", TfToken::Immortal), @@ -36,29 +26,18 @@ UsdUITokensType::UsdUITokensType() : uiNodegraphNodePos("ui:nodegraph:node:pos", TfToken::Immortal), uiNodegraphNodeSize("ui:nodegraph:node:size", TfToken::Immortal), uiNodegraphNodeStackingOrder("ui:nodegraph:node:stackingOrder", TfToken::Immortal), - AccessibilityAPI("AccessibilityAPI", TfToken::Immortal), Backdrop("Backdrop", TfToken::Immortal), LocalizationAPI("LocalizationAPI", TfToken::Immortal), NodeGraphNodeAPI("NodeGraphNodeAPI", TfToken::Immortal), SceneGraphPrimAPI("SceneGraphPrimAPI", TfToken::Immortal), allTokens({ - accessibility, - accessibility_MultipleApplyTemplate_Description, - accessibility_MultipleApplyTemplate_Label, - accessibility_MultipleApplyTemplate_Priority, closed, default_, - description, - high, - label, lang, localization, localization_MultipleApplyTemplate_Language, - low, minimized, open, - priority, - standard, uiDescription, uiDisplayGroup, uiDisplayName, @@ -69,7 +48,6 @@ UsdUITokensType::UsdUITokensType() : uiNodegraphNodePos, uiNodegraphNodeSize, uiNodegraphNodeStackingOrder, - AccessibilityAPI, Backdrop, LocalizationAPI, NodeGraphNodeAPI, diff --git a/pxr/usd/usdUI/tokens.h b/pxr/usd/usdUI/tokens.h index a4cc529942..93714247d5 100644 --- a/pxr/usd/usdUI/tokens.h +++ b/pxr/usd/usdUI/tokens.h @@ -41,26 +41,10 @@ PXR_NAMESPACE_OPEN_SCOPE /// Use UsdUITokens like so: /// /// \code -/// gprim.GetMyTokenValuedAttr().Set(UsdUITokens->accessibility); +/// gprim.GetMyTokenValuedAttr().Set(UsdUITokens->closed); /// \endcode struct UsdUITokensType { USDUI_API UsdUITokensType(); - /// \brief "accessibility" - /// - /// Property namespace prefix for the UsdUIAccessibilityAPI schema. - const TfToken accessibility; - /// \brief "accessibility:__INSTANCE_NAME__:description" - /// - /// UsdUIAccessibilityAPI - const TfToken accessibility_MultipleApplyTemplate_Description; - /// \brief "accessibility:__INSTANCE_NAME__:label" - /// - /// UsdUIAccessibilityAPI - const TfToken accessibility_MultipleApplyTemplate_Label; - /// \brief "accessibility:__INSTANCE_NAME__:priority" - /// - /// UsdUIAccessibilityAPI - const TfToken accessibility_MultipleApplyTemplate_Priority; /// \brief "closed" /// /// Possible value for UsdUINodeGraphNodeAPI::GetExpansionStateAttr() @@ -69,18 +53,6 @@ struct UsdUITokensType { /// /// Name of the anonymous instance name for the schema const TfToken default_; - /// \brief "description" - /// - /// Name of the description attribute - const TfToken description; - /// \brief "high" - /// - /// Possible value for UsdUIAccessibilityAPI::GetPriorityAttr() - const TfToken high; - /// \brief "label" - /// - /// Name of the label attribute - const TfToken label; /// \brief "lang" /// /// The token that delineates language specifications on an attribute @@ -93,10 +65,6 @@ struct UsdUITokensType { /// /// UsdUILocalizationAPI const TfToken localization_MultipleApplyTemplate_Language; - /// \brief "low" - /// - /// Possible value for UsdUIAccessibilityAPI::GetPriorityAttr() - const TfToken low; /// \brief "minimized" /// /// Possible value for UsdUINodeGraphNodeAPI::GetExpansionStateAttr() @@ -105,14 +73,6 @@ struct UsdUITokensType { /// /// Possible value for UsdUINodeGraphNodeAPI::GetExpansionStateAttr() const TfToken open; - /// \brief "priority" - /// - /// Name of the priority attribute - const TfToken priority; - /// \brief "standard" - /// - /// Fallback value for UsdUIAccessibilityAPI::GetPriorityAttr() - const TfToken standard; /// \brief "ui:description" /// /// UsdUIBackdrop @@ -153,10 +113,6 @@ struct UsdUITokensType { /// /// UsdUINodeGraphNodeAPI const TfToken uiNodegraphNodeStackingOrder; - /// \brief "AccessibilityAPI" - /// - /// Schema identifer and family for UsdUIAccessibilityAPI - const TfToken AccessibilityAPI; /// \brief "Backdrop" /// /// Schema identifer and family for UsdUIBackdrop diff --git a/pxr/usd/usdUI/wrapAccessibilityAPI.cpp b/pxr/usd/usdUI/wrapAccessibilityAPI.cpp deleted file mode 100644 index 06a3969ed8..0000000000 --- a/pxr/usd/usdUI/wrapAccessibilityAPI.cpp +++ /dev/null @@ -1,202 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the terms set forth in the LICENSE.txt file available at -// https://openusd.org/license. -// -#include "pxr/usd/usdUI/accessibilityAPI.h" -#include "pxr/usd/usd/schemaBase.h" - -#include "pxr/usd/sdf/primSpec.h" - -#include "pxr/usd/usd/pyConversions.h" -#include "pxr/base/tf/pyAnnotatedBoolResult.h" -#include "pxr/base/tf/pyContainerConversions.h" -#include "pxr/base/tf/pyResultConversions.h" -#include "pxr/base/tf/pyUtils.h" -#include "pxr/base/tf/wrapTypeHelpers.h" - -#include "pxr/external/boost/python.hpp" - -#include - -PXR_NAMESPACE_USING_DIRECTIVE - -using namespace pxr_boost::python; - -namespace { - -#define WRAP_CUSTOM \ - template static void _CustomWrapCode(Cls &_class) - -// fwd decl. -WRAP_CUSTOM; - - -static UsdAttribute -_CreateLabelAttr(UsdUIAccessibilityAPI &self, - object defaultVal, bool writeSparsely) { - return self.CreateLabelAttr( - UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); -} - -static UsdAttribute -_CreateDescriptionAttr(UsdUIAccessibilityAPI &self, - object defaultVal, bool writeSparsely) { - return self.CreateDescriptionAttr( - UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); -} - -static UsdAttribute -_CreatePriorityAttr(UsdUIAccessibilityAPI &self, - object defaultVal, bool writeSparsely) { - return self.CreatePriorityAttr( - UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); -} - -static bool _WrapIsAccessibilityAPIPath(const SdfPath &path) { - TfToken collectionName; - return UsdUIAccessibilityAPI::IsAccessibilityAPIPath( - path, &collectionName); -} - -static std::string -_Repr(const UsdUIAccessibilityAPI &self) -{ - std::string primRepr = TfPyRepr(self.GetPrim()); - std::string instanceName = TfPyRepr(self.GetName()); - return TfStringPrintf( - "UsdUI.AccessibilityAPI(%s, '%s')", - primRepr.c_str(), instanceName.c_str()); -} - -struct UsdUIAccessibilityAPI_CanApplyResult : - public TfPyAnnotatedBoolResult -{ - UsdUIAccessibilityAPI_CanApplyResult(bool val, std::string const &msg) : - TfPyAnnotatedBoolResult(val, msg) {} -}; - -static UsdUIAccessibilityAPI_CanApplyResult -_WrapCanApply(const UsdPrim& prim, const TfToken& name) -{ - std::string whyNot; - bool result = UsdUIAccessibilityAPI::CanApply(prim, name, &whyNot); - return UsdUIAccessibilityAPI_CanApplyResult(result, whyNot); -} - -} // anonymous namespace - -void wrapUsdUIAccessibilityAPI() -{ - typedef UsdUIAccessibilityAPI This; - - UsdUIAccessibilityAPI_CanApplyResult::Wrap( - "_CanApplyResult", "whyNot"); - - class_ > - cls("AccessibilityAPI"); - - cls - .def(init((arg("prim"), arg("name")))) - .def(init((arg("schemaObj"), arg("name")))) - .def(TfTypePythonClass()) - - .def("Get", - (UsdUIAccessibilityAPI(*)(const UsdStagePtr &stage, - const SdfPath &path)) - &This::Get, - (arg("stage"), arg("path"))) - .def("Get", - (UsdUIAccessibilityAPI(*)(const UsdPrim &prim, - const TfToken &name)) - &This::Get, - (arg("prim"), arg("name"))) - .staticmethod("Get") - - .def("GetAll", - (std::vector(*)(const UsdPrim &prim)) - &This::GetAll, - arg("prim"), - return_value_policy()) - .staticmethod("GetAll") - - .def("CanApply", &_WrapCanApply, (arg("prim"), arg("name"))) - .staticmethod("CanApply") - - .def("Apply", &This::Apply, (arg("prim"), arg("name"))) - .staticmethod("Apply") - - .def("GetSchemaAttributeNames", - (const TfTokenVector &(*)(bool))&This::GetSchemaAttributeNames, - arg("includeInherited")=true, - return_value_policy()) - .def("GetSchemaAttributeNames", - (TfTokenVector(*)(bool, const TfToken &)) - &This::GetSchemaAttributeNames, - arg("includeInherited"), - arg("instanceName"), - return_value_policy()) - .staticmethod("GetSchemaAttributeNames") - - .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, - return_value_policy()) - .staticmethod("_GetStaticTfType") - - .def(!self) - - - .def("GetLabelAttr", - &This::GetLabelAttr) - .def("CreateLabelAttr", - &_CreateLabelAttr, - (arg("defaultValue")=object(), - arg("writeSparsely")=false)) - - .def("GetDescriptionAttr", - &This::GetDescriptionAttr) - .def("CreateDescriptionAttr", - &_CreateDescriptionAttr, - (arg("defaultValue")=object(), - arg("writeSparsely")=false)) - - .def("GetPriorityAttr", - &This::GetPriorityAttr) - .def("CreatePriorityAttr", - &_CreatePriorityAttr, - (arg("defaultValue")=object(), - arg("writeSparsely")=false)) - - .def("IsAccessibilityAPIPath", _WrapIsAccessibilityAPIPath) - .staticmethod("IsAccessibilityAPIPath") - .def("__repr__", ::_Repr) - ; - - _CustomWrapCode(cls); -} - -// ===================================================================== // -// Feel free to add custom code below this line, it will be preserved by -// the code generator. The entry point for your custom code should look -// minimally like the following: -// -// WRAP_CUSTOM { -// _class -// .def("MyCustomMethod", ...) -// ; -// } -// -// Of course any other ancillary or support code may be provided. -// -// Just remember to wrap code in the appropriate delimiters: -// 'namespace {', '}'. -// -// ===================================================================== // -// --(BEGIN CUSTOM CODE)-- - -namespace { - -WRAP_CUSTOM { -} - -} diff --git a/pxr/usd/usdUI/wrapTokens.cpp b/pxr/usd/usdUI/wrapTokens.cpp index d99c0494f9..4256a8ebd1 100644 --- a/pxr/usd/usdUI/wrapTokens.cpp +++ b/pxr/usd/usdUI/wrapTokens.cpp @@ -17,23 +17,13 @@ void wrapUsdUITokens() { pxr_boost::python::class_ cls("Tokens", pxr_boost::python::no_init); - _ADD_TOKEN(cls, accessibility); - _ADD_TOKEN(cls, accessibility_MultipleApplyTemplate_Description); - _ADD_TOKEN(cls, accessibility_MultipleApplyTemplate_Label); - _ADD_TOKEN(cls, accessibility_MultipleApplyTemplate_Priority); _ADD_TOKEN(cls, closed); _ADD_TOKEN(cls, default_); - _ADD_TOKEN(cls, description); - _ADD_TOKEN(cls, high); - _ADD_TOKEN(cls, label); _ADD_TOKEN(cls, lang); _ADD_TOKEN(cls, localization); _ADD_TOKEN(cls, localization_MultipleApplyTemplate_Language); - _ADD_TOKEN(cls, low); _ADD_TOKEN(cls, minimized); _ADD_TOKEN(cls, open); - _ADD_TOKEN(cls, priority); - _ADD_TOKEN(cls, standard); _ADD_TOKEN(cls, uiDescription); _ADD_TOKEN(cls, uiDisplayGroup); _ADD_TOKEN(cls, uiDisplayName); @@ -44,7 +34,6 @@ void wrapUsdUITokens() _ADD_TOKEN(cls, uiNodegraphNodePos); _ADD_TOKEN(cls, uiNodegraphNodeSize); _ADD_TOKEN(cls, uiNodegraphNodeStackingOrder); - _ADD_TOKEN(cls, AccessibilityAPI); _ADD_TOKEN(cls, Backdrop); _ADD_TOKEN(cls, LocalizationAPI); _ADD_TOKEN(cls, NodeGraphNodeAPI); From a309a748800a5460eea61f1a088865f18052abf3 Mon Sep 17 00:00:00 2001 From: Dhruv Govil Date: Fri, 20 Dec 2024 13:18:58 -0800 Subject: [PATCH 15/15] Rebase onto latest pxr-dev --- pxr/usd/usdUI/generatedSchema.module.h | 1 + 1 file changed, 1 insertion(+) diff --git a/pxr/usd/usdUI/generatedSchema.module.h b/pxr/usd/usdUI/generatedSchema.module.h index 4688d2cbb3..21a5d28868 100644 --- a/pxr/usd/usdUI/generatedSchema.module.h +++ b/pxr/usd/usdUI/generatedSchema.module.h @@ -9,4 +9,5 @@ TF_WRAP(UsdUINodeGraphNodeAPI); TF_WRAP(UsdUISceneGraphPrimAPI); TF_WRAP(UsdUIBackdrop); +TF_WRAP(UsdUILocalizationAPI); TF_WRAP(UsdUITokens);