diff --git a/pxr/usd/usdGeom/CMakeLists.txt b/pxr/usd/usdGeom/CMakeLists.txt index 5bb5826164..d04e8f0953 100644 --- a/pxr/usd/usdGeom/CMakeLists.txt +++ b/pxr/usd/usdGeom/CMakeLists.txt @@ -3,7 +3,7 @@ set(PXR_PACKAGE usdGeom) set(optionalPublicClasses "") if (PXR_ENABLE_TEXT_SUPPORT) - list(APPEND optionalPublicClasses simpleText) + list(APPEND optionalPublicClasses simpleText genericText) endif() pxr_library(usdGeom @@ -109,6 +109,8 @@ pxr_library(usdGeom wrapXformable.cpp wrapXformOp.cpp wrapXformCommonAPI.cpp + wrapSimpleText.cpp + wrapGenericText.cpp PYMODULE_FILES __init__.py diff --git a/pxr/usd/usdGeom/generatedSchema.usda b/pxr/usd/usdGeom/generatedSchema.usda index 4662c81793..848245afc3 100644 --- a/pxr/usd/usdGeom/generatedSchema.usda +++ b/pxr/usd/usdGeom/generatedSchema.usda @@ -1573,6 +1573,126 @@ class SimpleText "SimpleText" ( ) } +class GenericText "GenericText" ( + doc = "Class for multiple lines or multiple styles text." +) +{ + uniform bool doubleSided = 0 ( + doc = """Although some renderers treat all parametric or polygonal + surfaces as if they were effectively laminae with outward-facing + normals on both sides, some renderers derive significant optimizations + by considering these surfaces to have only a single outward side, + typically determined by control-point winding order and/or + orientation. By doing so they can perform \"backface culling\" to + avoid drawing the many polygons of most closed surfaces that face away + from the viewer. + + However, it is often advantageous to model thin objects such as paper + and cloth as single, open surfaces that must be viewable from both + sides, always. Setting a gprim's doubleSided attribute to + \\c true instructs all renderers to disable optimizations such as + backface culling for the gprim, and attempt (not all renderers are able + to do so, but the USD reference GL renderer always will) to provide + forward-facing normals on each side of the surface for lighting + calculations.""" + ) + float3[] extent ( + doc = """Extent is a three dimensional range measuring the geometric + extent of the authored gprim in its own local space (i.e. its own + transform not applied), without accounting for any shader-induced + displacement. Whenever any geometry-affecting attribute is authored + for any gprim in a layer, extent must also be authored at the same + timesample; failure to do so will result in incorrect bounds-computation. + \\sa \\ref UsdGeom_Boundable_Extent. + + An authored extent on a prim which has children is expected to include + the extent of all children, as they will be pruned from BBox computation + during traversal.""" + ) + uniform token markupLanguage = "nomarkup" ( + allowedTokens = ["nomarkup", "mtext"] + doc = "The markup language." + ) + string markupString ( + doc = "The markup string data." + ) + uniform token orientation = "rightHanded" ( + allowedTokens = ["rightHanded", "leftHanded"] + doc = """Orientation specifies whether the gprim's surface normal + should be computed using the right hand rule, or the left hand rule. + Please see for a deeper explanation and + generalization of orientation to composed scenes with transformation + hierarchies.""" + ) + color3f[] primvars:backgroundColor ( + doc = "Background color for the text." + ) + color3f[] primvars:displayColor ( + doc = '''It is useful to have an "official" colorSet that can be used + as a display or modeling color, even in the absence of any specified + shader for a gprim. DisplayColor serves this role; because it is a + UsdGeomPrimvar, it can also be used as a gprim override for any shader + that consumes a displayColor parameter.''' + ) + float[] primvars:displayOpacity ( + doc = """Companion to displayColor that specifies opacity, broken + out as an independent attribute rather than an rgba color, both so that + each can be independently overridden, and because shaders rarely consume + rgba parameters.""" + ) + rel proxyPrim ( + doc = '''The proxyPrim relationship allows us to link a + prim whose purpose is "render" to its (single target) + purpose="proxy" prim. This is entirely optional, but can be + useful in several scenarios: + + - In a pipeline that does pruning (for complexity management) + by deactivating prims composed from asset references, when we + deactivate a purpose="render" prim, we will be able to discover + and additionally deactivate its associated purpose="proxy" prim, + so that preview renders reflect the pruning accurately. + + - DCC importers may be able to make more aggressive optimizations + for interactive processing and display if they can discover the proxy + for a given render prim. + + - With a little more work, a Hydra-based application will be able + to map a picked proxy prim back to its render geometry for selection. + + \\note It is only valid to author the proxyPrim relationship on + prims whose purpose is "render".''' + ) + uniform token purpose = "default" ( + allowedTokens = ["default", "render", "proxy", "guide"] + doc = """Purpose is a classification of geometry into categories that + can each be independently included or excluded from traversals of prims + on a stage, such as rendering or bounding-box computation traversals. + + See for more detail about how + purpose is computed and used.""" + ) + token visibility = "inherited" ( + allowedTokens = ["inherited", "invisible"] + doc = '''Visibility is meant to be the simplest form of "pruning" + visibility that is supported by most DCC apps. Visibility is + animatable, allowing a sub-tree of geometry to be present for some + segment of a shot, and absent from others; unlike the action of + deactivating geometry prims, invisible geometry is still + available for inspection, for positioning, for defining volumes, etc.''' + ) + uniform token[] xformOpOrder ( + doc = """Encodes the sequence of transformation operations in the + order in which they should be pushed onto a transform stack while + visiting a UsdStage's prims in a graph traversal that will effect + the desired positioning for this prim and its descendant prims. + + You should rarely, if ever, need to manipulate this attribute directly. + It is managed by the AddXformOp(), SetResetXformStack(), and + SetXformOpOrder(), and consulted by GetOrderedXformOps() and + GetLocalTransformation().""" + ) +} + class "PointBased" ( doc = """Base class for all UsdGeomGprims that possess points, providing common attributes such as normals and velocities.""" diff --git a/pxr/usd/usdGeom/genericText.cpp b/pxr/usd/usdGeom/genericText.cpp new file mode 100644 index 0000000000..e953065a39 --- /dev/null +++ b/pxr/usd/usdGeom/genericText.cpp @@ -0,0 +1,198 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/usd/usdGeom/genericText.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 >(); + + // Register the usd prim typename as an alias under UsdSchemaBase. This + // enables one to call + // TfType::Find().FindDerivedByName("GenericText") + // to find TfType, which is how IsA queries are + // answered. + TfType::AddAlias("GenericText"); +} + +/* virtual */ +UsdGeomGenericText::~UsdGeomGenericText() +{ +} + +/* static */ +UsdGeomGenericText +UsdGeomGenericText::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdGeomGenericText(); + } + return UsdGeomGenericText(stage->GetPrimAtPath(path)); +} + +/* static */ +UsdGeomGenericText +UsdGeomGenericText::Define( + const UsdStagePtr &stage, const SdfPath &path) +{ + static TfToken usdPrimTypeName("GenericText"); + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdGeomGenericText(); + } + return UsdGeomGenericText( + stage->DefinePrim(path, usdPrimTypeName)); +} + +/* virtual */ +UsdSchemaKind UsdGeomGenericText::_GetSchemaKind() const +{ + return UsdGeomGenericText::schemaKind; +} + +/* static */ +const TfType & +UsdGeomGenericText::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdGeomGenericText::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdGeomGenericText::_GetTfType() const +{ + return _GetStaticTfType(); +} + +UsdAttribute +UsdGeomGenericText::GetMarkupStringAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->markupString); +} + +UsdAttribute +UsdGeomGenericText::CreateMarkupStringAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->markupString, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomGenericText::GetMarkupLanguageAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->markupLanguage); +} + +UsdAttribute +UsdGeomGenericText::CreateMarkupLanguageAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->markupLanguage, + SdfValueTypeNames->Token, + /* custom = */ false, + SdfVariabilityUniform, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdGeomGenericText::GetBackgroundColorAttr() const +{ + return GetPrim().GetAttribute(UsdGeomTokens->primvarsBackgroundColor); +} + +UsdAttribute +UsdGeomGenericText::CreateBackgroundColorAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->primvarsBackgroundColor, + SdfValueTypeNames->Color3fArray, + /* custom = */ false, + SdfVariabilityVarying, + 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& +UsdGeomGenericText::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + UsdGeomTokens->markupString, + UsdGeomTokens->markupLanguage, + UsdGeomTokens->primvarsBackgroundColor, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + UsdGeomGprim::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +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/usdGeom/genericText.h b/pxr/usd/usdGeom/genericText.h new file mode 100644 index 0000000000..1e954fc3fb --- /dev/null +++ b/pxr/usd/usdGeom/genericText.h @@ -0,0 +1,242 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#ifndef USDGEOM_GENERATED_GENERICTEXT_H +#define USDGEOM_GENERATED_GENERICTEXT_H + +/// \file usdGeom/genericText.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdGeom/api.h" +#include "pxr/usd/usdGeom/gprim.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdGeom/tokens.h" + +#include + + +#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; + +// -------------------------------------------------------------------------- // +// GENERICTEXT // +// -------------------------------------------------------------------------- // + +/// \class UsdGeomGenericText +/// +/// Class for multiple lines or multiple styles text. +/// +/// 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 UsdGeomTokens. +/// So to set an attribute to the value "rightHanded", use UsdGeomTokens->rightHanded +/// as the value. +/// +class UsdGeomGenericText : public UsdGeomGprim +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped; + + /// Construct a UsdGeomGenericText on UsdPrim \p prim . + /// Equivalent to UsdGeomGenericText::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdGeomGenericText(const UsdPrim& prim=UsdPrim()) + : UsdGeomGprim(prim) + { + } + + /// Construct a UsdGeomGenericText on the prim held by \p schemaObj . + /// Should be preferred over UsdGeomGenericText(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdGeomGenericText(const UsdSchemaBase& schemaObj) + : UsdGeomGprim(schemaObj) + { + } + + /// Destructor. + USDGEOM_API + virtual ~UsdGeomGenericText(); + + /// 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. + USDGEOM_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdGeomGenericText 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. This is shorthand for the following: + /// + /// \code + /// UsdGeomGenericText(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDGEOM_API + static UsdGeomGenericText + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path + /// is defined (according to UsdPrim::IsDefined()) on this stage. + /// + /// If a prim adhering to this schema at \p path is already defined on this + /// stage, return that prim. Otherwise author an \a SdfPrimSpec with + /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for + /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s + /// with \p specifier == \a SdfSpecifierDef and empty typeName at the + /// current EditTarget for any nonexistent, or existing but not \a Defined + /// ancestors. + /// + /// The given \a path must be an absolute prim path that does not contain + /// any variant selections. + /// + /// If it is impossible to author any of the necessary PrimSpecs, (for + /// example, in case \a path cannot map to the current UsdEditTarget's + /// namespace) issue an error and return an invalid \a UsdPrim. + /// + /// Note that this method may return a defined prim whose typeName does not + /// specify this schema class, in case a stronger typeName opinion overrides + /// the opinion at the current EditTarget. + /// + USDGEOM_API + static UsdGeomGenericText + Define(const UsdStagePtr &stage, const SdfPath &path); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDGEOM_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDGEOM_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDGEOM_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // MARKUPSTRING + // --------------------------------------------------------------------- // + /// The markup string data. + /// + /// | || + /// | -- | -- | + /// | Declaration | `string markupString` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + USDGEOM_API + UsdAttribute GetMarkupStringAttr() const; + + /// See GetMarkupStringAttr(), 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. + USDGEOM_API + UsdAttribute CreateMarkupStringAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // MARKUPLANGUAGE + // --------------------------------------------------------------------- // + /// The markup language. + /// + /// | || + /// | -- | -- | + /// | Declaration | `uniform token markupLanguage = "nomarkup"` | + /// | C++ Type | TfToken | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | + /// | \ref SdfVariability "Variability" | SdfVariabilityUniform | + /// | \ref UsdGeomTokens "Allowed Values" | nomarkup, mtext | + USDGEOM_API + UsdAttribute GetMarkupLanguageAttr() const; + + /// See GetMarkupLanguageAttr(), 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. + USDGEOM_API + UsdAttribute CreateMarkupLanguageAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // BACKGROUNDCOLOR + // --------------------------------------------------------------------- // + /// Background color for the text. + /// + /// | || + /// | -- | -- | + /// | Declaration | `color3f[] primvars:backgroundColor` | + /// | C++ Type | VtArray | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Color3fArray | + USDGEOM_API + UsdAttribute GetBackgroundColorAttr() const; + + /// See GetBackgroundColorAttr(), 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. + USDGEOM_API + UsdAttribute CreateBackgroundColorAttr(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/usdGeom/plugInfo.json b/pxr/usd/usdGeom/plugInfo.json index 26fcfbbcc2..e09c95dc58 100644 --- a/pxr/usd/usdGeom/plugInfo.json +++ b/pxr/usd/usdGeom/plugInfo.json @@ -150,6 +150,17 @@ "implementsComputeExtent": true, "schemaKind": "concreteTyped" }, + "UsdGeomGenericText": { + "alias": { + "UsdSchemaBase": "GenericText" + }, + "autoGenerated": true, + "bases": [ + "UsdGeomGprim" + ], + "implementsComputeExtent": true, + "schemaKind": "concreteTyped" + }, "UsdGeomGprim": { "alias": { "UsdSchemaBase": "Gprim" diff --git a/pxr/usd/usdGeom/schema.usda b/pxr/usd/usdGeom/schema.usda index 575fa9dfa8..67c77111da 100644 --- a/pxr/usd/usdGeom/schema.usda +++ b/pxr/usd/usdGeom/schema.usda @@ -897,6 +897,38 @@ class SimpleText "SimpleText" ( ) } +class GenericText "GenericText" ( + doc = """Class for multiple lines or multiple styles text.""" + + inherits = + customData = { + dictionary extraPlugInfo = { + bool implementsComputeExtent = true + } + string extraIncludes =""" +#include + """ + } +) { + # markupString + string markupString ( + doc = """The markup string data.""" + ) + + # markupLanguage + uniform token markupLanguage = "nomarkup" ( + allowedTokens = ["nomarkup", "mtext"] + doc = """The markup language.""" + ) + + color3f[] primvars:backgroundColor ( + customData = { + string apiName = "backgroundColor" + } + doc = """Background color for the text.""" + ) +} + class "PointBased" ( doc = """Base class for all UsdGeomGprims that possess points, providing common attributes such as normals and velocities.""" diff --git a/pxr/usd/usdGeom/tokens.cpp b/pxr/usd/usdGeom/tokens.cpp index e4aec7b381..3ff60d705e 100644 --- a/pxr/usd/usdGeom/tokens.cpp +++ b/pxr/usd/usdGeom/tokens.cpp @@ -95,6 +95,8 @@ UsdGeomTokensType::UsdGeomTokensType() : length("length", TfToken::Immortal), linear("linear", TfToken::Immortal), loop("loop", TfToken::Immortal), + markupLanguage("markupLanguage", TfToken::Immortal), + markupString("markupString", TfToken::Immortal), metersPerUnit("metersPerUnit", TfToken::Immortal), modelApplyDrawMode("model:applyDrawMode", TfToken::Immortal), modelCardGeometry("model:cardGeometry", TfToken::Immortal), @@ -110,6 +112,8 @@ UsdGeomTokensType::UsdGeomTokensType() : motionBlurScale("motion:blurScale", TfToken::Immortal), motionNonlinearSampleCount("motion:nonlinearSampleCount", TfToken::Immortal), motionVelocityScale("motion:velocityScale", TfToken::Immortal), + mtext("mtext", TfToken::Immortal), + nomarkup("nomarkup", TfToken::Immortal), none("none", TfToken::Immortal), nonOverlapping("nonOverlapping", TfToken::Immortal), nonperiodic("nonperiodic", TfToken::Immortal), @@ -264,6 +268,8 @@ UsdGeomTokensType::UsdGeomTokensType() : length, linear, loop, + markupLanguage, + markupString, metersPerUnit, modelApplyDrawMode, modelCardGeometry, @@ -279,6 +285,8 @@ UsdGeomTokensType::UsdGeomTokensType() : motionBlurScale, motionNonlinearSampleCount, motionVelocityScale, + mtext, + nomarkup, none, nonOverlapping, nonperiodic, diff --git a/pxr/usd/usdGeom/tokens.h b/pxr/usd/usdGeom/tokens.h index 782375613a..ca12436118 100644 --- a/pxr/usd/usdGeom/tokens.h +++ b/pxr/usd/usdGeom/tokens.h @@ -338,6 +338,14 @@ struct UsdGeomTokensType { /// /// Possible value for UsdGeomMesh::GetSubdivisionSchemeAttr() const TfToken loop; + /// \brief "markupLanguage" + /// + /// UsdGeomGenericText + const TfToken markupLanguage; + /// \brief "markupString" + /// + /// UsdGeomGenericText + const TfToken markupString; /// \brief "metersPerUnit" /// /// Stage-level metadata that encodes a scene's linear unit of measure as meters per encoded unit. @@ -398,6 +406,14 @@ struct UsdGeomTokensType { /// /// UsdGeomMotionAPI const TfToken motionVelocityScale; + /// \brief "mtext" + /// + /// Possible value for UsdGeomGenericText::GetMarkupLanguageAttr() + const TfToken mtext; + /// \brief "nomarkup" + /// + /// Possible value for UsdGeomGenericText::GetMarkupLanguageAttr(), Default value for UsdGeomGenericText::GetMarkupLanguageAttr() + const TfToken nomarkup; /// \brief "none" /// /// Possible value for UsdGeomMesh::GetFaceVaryingLinearInterpolationAttr(), Possible value for UsdGeomMesh::GetInterpolateBoundaryAttr(), Possible value for UsdGeomMesh::GetSubdivisionSchemeAttr() @@ -476,7 +492,7 @@ struct UsdGeomTokensType { const TfToken power; /// \brief "primvars:backgroundColor" /// - /// UsdGeomSimpleText + /// UsdGeomGenericText, UsdGeomSimpleText const TfToken primvarsBackgroundColor; /// \brief "primvars:displayColor" /// diff --git a/pxr/usd/usdGeom/wrapGenericText.cpp b/pxr/usd/usdGeom/wrapGenericText.cpp new file mode 100644 index 0000000000..61c700cecf --- /dev/null +++ b/pxr/usd/usdGeom/wrapGenericText.cpp @@ -0,0 +1,166 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/usd/usdGeom/genericText.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.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 +_CreateMarkupStringAttr(UsdGeomGenericText &self, + object defaultVal, bool writeSparsely) { + return self.CreateMarkupStringAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static UsdAttribute +_CreateMarkupLanguageAttr(UsdGeomGenericText &self, + object defaultVal, bool writeSparsely) { + return self.CreateMarkupLanguageAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); +} + +static UsdAttribute +_CreateBackgroundColorAttr(UsdGeomGenericText &self, + object defaultVal, bool writeSparsely) { + return self.CreateBackgroundColorAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Color3fArray), writeSparsely); +} + +static std::string +_Repr(const UsdGeomGenericText &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdGeom.GenericText(%s)", + primRepr.c_str()); +} + +} // anonymous namespace + +void wrapUsdGeomGenericText() +{ + typedef UsdGeomGenericText This; + + class_ > + cls("GenericText"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("Define", &This::Define, (arg("stage"), arg("path"))) + .staticmethod("Define") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetMarkupStringAttr", + &This::GetMarkupStringAttr) + .def("CreateMarkupStringAttr", + &_CreateMarkupStringAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetMarkupLanguageAttr", + &This::GetMarkupLanguageAttr) + .def("CreateMarkupLanguageAttr", + &_CreateMarkupLanguageAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetBackgroundColorAttr", + &This::GetBackgroundColorAttr) + .def("CreateBackgroundColorAttr", + &_CreateBackgroundColorAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .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/usdGeom/wrapTokens.cpp b/pxr/usd/usdGeom/wrapTokens.cpp index 4f7c762834..c3b1fe50cf 100644 --- a/pxr/usd/usdGeom/wrapTokens.cpp +++ b/pxr/usd/usdGeom/wrapTokens.cpp @@ -133,6 +133,8 @@ void wrapUsdGeomTokens() _AddToken(cls, "length", UsdGeomTokens->length); _AddToken(cls, "linear", UsdGeomTokens->linear); _AddToken(cls, "loop", UsdGeomTokens->loop); + _AddToken(cls, "markupLanguage", UsdGeomTokens->markupLanguage); + _AddToken(cls, "markupString", UsdGeomTokens->markupString); _AddToken(cls, "metersPerUnit", UsdGeomTokens->metersPerUnit); _AddToken(cls, "modelApplyDrawMode", UsdGeomTokens->modelApplyDrawMode); _AddToken(cls, "modelCardGeometry", UsdGeomTokens->modelCardGeometry); @@ -148,6 +150,8 @@ void wrapUsdGeomTokens() _AddToken(cls, "motionBlurScale", UsdGeomTokens->motionBlurScale); _AddToken(cls, "motionNonlinearSampleCount", UsdGeomTokens->motionNonlinearSampleCount); _AddToken(cls, "motionVelocityScale", UsdGeomTokens->motionVelocityScale); + _AddToken(cls, "mtext", UsdGeomTokens->mtext); + _AddToken(cls, "nomarkup", UsdGeomTokens->nomarkup); _AddToken(cls, "none", UsdGeomTokens->none); _AddToken(cls, "nonOverlapping", UsdGeomTokens->nonOverlapping); _AddToken(cls, "nonperiodic", UsdGeomTokens->nonperiodic); diff --git a/pxr/usd/usdText/CMakeLists.txt b/pxr/usd/usdText/CMakeLists.txt index 385e67a3e4..6349067ebc 100644 --- a/pxr/usd/usdText/CMakeLists.txt +++ b/pxr/usd/usdText/CMakeLists.txt @@ -13,6 +13,8 @@ pxr_library(usdText textRenderingTechniqueAPI textRenderingTechnique textLayout + columnStyle + columnStyleAPI tokens PUBLIC_HEADERS @@ -28,6 +30,8 @@ pxr_library(usdText wrapTextRenderingTechniqueAPI.cpp wrapTextRenderingTechnique.cpp wrapTextLayout.cpp + wrapColumnStyle.cpp + wrapColumnStyleAPI.cpp wrapTokens.cpp PYMODULE_FILES diff --git a/pxr/usd/usdText/columnStyle.cpp b/pxr/usd/usdText/columnStyle.cpp new file mode 100644 index 0000000000..f0a11e6a64 --- /dev/null +++ b/pxr/usd/usdText/columnStyle.cpp @@ -0,0 +1,288 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/usd/usdText/columnStyle.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 >(); + + // Register the usd prim typename as an alias under UsdSchemaBase. This + // enables one to call + // TfType::Find().FindDerivedByName("ColumnStyle") + // to find TfType, which is how IsA queries are + // answered. + TfType::AddAlias("ColumnStyle"); +} + +/* virtual */ +UsdTextColumnStyle::~UsdTextColumnStyle() +{ +} + +/* static */ +UsdTextColumnStyle +UsdTextColumnStyle::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextColumnStyle(); + } + return UsdTextColumnStyle(stage->GetPrimAtPath(path)); +} + +/* static */ +UsdTextColumnStyle +UsdTextColumnStyle::Define( + const UsdStagePtr &stage, const SdfPath &path) +{ + static TfToken usdPrimTypeName("ColumnStyle"); + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextColumnStyle(); + } + return UsdTextColumnStyle( + stage->DefinePrim(path, usdPrimTypeName)); +} + +/* virtual */ +UsdSchemaKind UsdTextColumnStyle::_GetSchemaKind() const +{ + return UsdTextColumnStyle::schemaKind; +} + +/* static */ +const TfType & +UsdTextColumnStyle::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdTextColumnStyle::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdTextColumnStyle::_GetTfType() const +{ + return _GetStaticTfType(); +} + +UsdAttribute +UsdTextColumnStyle::GetColumnWidthAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->columnWidth); +} + +UsdAttribute +UsdTextColumnStyle::CreateColumnWidthAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->columnWidth, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextColumnStyle::GetColumnHeightAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->columnHeight); +} + +UsdAttribute +UsdTextColumnStyle::CreateColumnHeightAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->columnHeight, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextColumnStyle::GetOffsetAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->offset); +} + +UsdAttribute +UsdTextColumnStyle::CreateOffsetAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->offset, + SdfValueTypeNames->Float2, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextColumnStyle::GetMarginAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->margin); +} + +UsdAttribute +UsdTextColumnStyle::CreateMarginAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->margin, + SdfValueTypeNames->Float4, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextColumnStyle::GetBlockAlignmentAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->blockAlignment); +} + +UsdAttribute +UsdTextColumnStyle::CreateBlockAlignmentAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->blockAlignment, + SdfValueTypeNames->Token, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextColumnStyle::GetOrientationAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->orientation); +} + +UsdAttribute +UsdTextColumnStyle::CreateOrientationAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->orientation, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextColumnStyle::GetEscapementAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->escapement); +} + +UsdAttribute +UsdTextColumnStyle::CreateEscapementAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->escapement, + SdfValueTypeNames->Float, + /* custom = */ false, + SdfVariabilityVarying, + defaultValue, + writeSparsely); +} + +UsdAttribute +UsdTextColumnStyle::GetDirectionAttr() const +{ + return GetPrim().GetAttribute(UsdTextTokens->direction); +} + +UsdAttribute +UsdTextColumnStyle::CreateDirectionAttr(VtValue const &defaultValue, bool writeSparsely) const +{ + return UsdSchemaBase::_CreateAttr(UsdTextTokens->direction, + SdfValueTypeNames->String, + /* custom = */ false, + SdfVariabilityVarying, + 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& +UsdTextColumnStyle::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames = { + UsdTextTokens->columnWidth, + UsdTextTokens->columnHeight, + UsdTextTokens->offset, + UsdTextTokens->margin, + UsdTextTokens->blockAlignment, + UsdTextTokens->orientation, + UsdTextTokens->escapement, + UsdTextTokens->direction, + }; + static TfTokenVector allNames = + _ConcatenateAttributeNames( + UsdTyped::GetSchemaAttributeNames(true), + localNames); + + if (includeInherited) + return allNames; + else + return localNames; +} + +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/usdText/columnStyle.h b/pxr/usd/usdText/columnStyle.h new file mode 100644 index 0000000000..de3a40896c --- /dev/null +++ b/pxr/usd/usdText/columnStyle.h @@ -0,0 +1,351 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#ifndef USDTEXT_GENERATED_COLUMNSTYLE_H +#define USDTEXT_GENERATED_COLUMNSTYLE_H + +/// \file usdText/columnStyle.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdText/api.h" +#include "pxr/usd/usd/typed.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdText/tokens.h" + +#include + + +#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; + +// -------------------------------------------------------------------------- // +// COLUMNSTYLE // +// -------------------------------------------------------------------------- // + +/// \class UsdTextColumnStyle +/// +/// Class for style of a column. +/// +/// 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 UsdTextTokens. +/// So to set an attribute to the value "rightHanded", use UsdTextTokens->rightHanded +/// as the value. +/// +class UsdTextColumnStyle : public UsdTyped +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped; + + /// Construct a UsdTextColumnStyle on UsdPrim \p prim . + /// Equivalent to UsdTextColumnStyle::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdTextColumnStyle(const UsdPrim& prim=UsdPrim()) + : UsdTyped(prim) + { + } + + /// Construct a UsdTextColumnStyle on the prim held by \p schemaObj . + /// Should be preferred over UsdTextColumnStyle(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdTextColumnStyle(const UsdSchemaBase& schemaObj) + : UsdTyped(schemaObj) + { + } + + /// Destructor. + USDTEXT_API + virtual ~UsdTextColumnStyle(); + + /// 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. + USDTEXT_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdTextColumnStyle 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. This is shorthand for the following: + /// + /// \code + /// UsdTextColumnStyle(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDTEXT_API + static UsdTextColumnStyle + Get(const UsdStagePtr &stage, const SdfPath &path); + + /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path + /// is defined (according to UsdPrim::IsDefined()) on this stage. + /// + /// If a prim adhering to this schema at \p path is already defined on this + /// stage, return that prim. Otherwise author an \a SdfPrimSpec with + /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for + /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s + /// with \p specifier == \a SdfSpecifierDef and empty typeName at the + /// current EditTarget for any nonexistent, or existing but not \a Defined + /// ancestors. + /// + /// The given \a path must be an absolute prim path that does not contain + /// any variant selections. + /// + /// If it is impossible to author any of the necessary PrimSpecs, (for + /// example, in case \a path cannot map to the current UsdEditTarget's + /// namespace) issue an error and return an invalid \a UsdPrim. + /// + /// Note that this method may return a defined prim whose typeName does not + /// specify this schema class, in case a stronger typeName opinion overrides + /// the opinion at the current EditTarget. + /// + USDTEXT_API + static UsdTextColumnStyle + Define(const UsdStagePtr &stage, const SdfPath &path); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDTEXT_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDTEXT_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDTEXT_API + const TfType &_GetTfType() const override; + +public: + // --------------------------------------------------------------------- // + // COLUMNWIDTH + // --------------------------------------------------------------------- // + /// The width of the column. + /// + /// | || + /// | -- | -- | + /// | Declaration | `float columnWidth = 0` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + USDTEXT_API + UsdAttribute GetColumnWidthAttr() const; + + /// See GetColumnWidthAttr(), 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. + USDTEXT_API + UsdAttribute CreateColumnWidthAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // COLUMNHEIGHT + // --------------------------------------------------------------------- // + /// The height of the column. + /// + /// | || + /// | -- | -- | + /// | Declaration | `float columnHeight = 0` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + USDTEXT_API + UsdAttribute GetColumnHeightAttr() const; + + /// See GetColumnHeightAttr(), 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. + USDTEXT_API + UsdAttribute CreateColumnHeightAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // OFFSET + // --------------------------------------------------------------------- // + /// The 2D offset from the previous column. + /// + /// | || + /// | -- | -- | + /// | Declaration | `float2 offset = (0, 0)` | + /// | C++ Type | GfVec2f | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float2 | + USDTEXT_API + UsdAttribute GetOffsetAttr() const; + + /// See GetOffsetAttr(), 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. + USDTEXT_API + UsdAttribute CreateOffsetAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // MARGIN + // --------------------------------------------------------------------- // + /// The margins at the four direction. + /// + /// | || + /// | -- | -- | + /// | Declaration | `float4 margin = (0, 0, 0, 0)` | + /// | C++ Type | GfVec4f | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float4 | + USDTEXT_API + UsdAttribute GetMarginAttr() const; + + /// See GetMarginAttr(), 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. + USDTEXT_API + UsdAttribute CreateMarginAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // BLOCKALIGNMENT + // --------------------------------------------------------------------- // + /// The text alignment in the block. + /// + /// | || + /// | -- | -- | + /// | Declaration | `token blockAlignment = "top"` | + /// | C++ Type | TfToken | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token | + /// | \ref UsdTextTokens "Allowed Values" | top, center, bottom | + USDTEXT_API + UsdAttribute GetBlockAlignmentAttr() const; + + /// See GetBlockAlignmentAttr(), 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. + USDTEXT_API + UsdAttribute CreateBlockAlignmentAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // ORIENTATION + // --------------------------------------------------------------------- // + /// The Orientation. + /// + /// | || + /// | -- | -- | + /// | Declaration | `float orientation = 0` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + USDTEXT_API + UsdAttribute GetOrientationAttr() const; + + /// See GetOrientationAttr(), 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. + USDTEXT_API + UsdAttribute CreateOrientationAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // ESCAPEMENT + // --------------------------------------------------------------------- // + /// The Escapement. + /// + /// | || + /// | -- | -- | + /// | Declaration | `float escapement = 0` | + /// | C++ Type | float | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float | + USDTEXT_API + UsdAttribute GetEscapementAttr() const; + + /// See GetEscapementAttr(), 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. + USDTEXT_API + UsdAttribute CreateEscapementAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + +public: + // --------------------------------------------------------------------- // + // DIRECTION + // --------------------------------------------------------------------- // + /// The Direction. + /// + /// | || + /// | -- | -- | + /// | Declaration | `string direction = "Default"` | + /// | C++ Type | std::string | + /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | + USDTEXT_API + UsdAttribute GetDirectionAttr() const; + + /// See GetDirectionAttr(), 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. + USDTEXT_API + UsdAttribute CreateDirectionAttr(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/usdText/columnStyleAPI.cpp b/pxr/usd/usdText/columnStyleAPI.cpp new file mode 100644 index 0000000000..274aefea0e --- /dev/null +++ b/pxr/usd/usdText/columnStyleAPI.cpp @@ -0,0 +1,192 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/usd/usdText/columnStyleAPI.h" +#include "pxr/usd/usd/schemaRegistry.h" +#include "pxr/usd/usd/typed.h" +#include "pxr/usd/usd/tokens.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 >(); + +} + +TF_DEFINE_PRIVATE_TOKENS( + _schemaTokens, + (ColumnStyleAPI) +); + +/* virtual */ +UsdTextColumnStyleAPI::~UsdTextColumnStyleAPI() +{ +} + +/* static */ +UsdTextColumnStyleAPI +UsdTextColumnStyleAPI::Get(const UsdStagePtr &stage, const SdfPath &path) +{ + if (!stage) { + TF_CODING_ERROR("Invalid stage"); + return UsdTextColumnStyleAPI(); + } + return UsdTextColumnStyleAPI(stage->GetPrimAtPath(path)); +} + + +/* virtual */ +UsdSchemaKind UsdTextColumnStyleAPI::_GetSchemaKind() const +{ + return UsdTextColumnStyleAPI::schemaKind; +} + +/* static */ +bool +UsdTextColumnStyleAPI::CanApply( + const UsdPrim &prim, std::string *whyNot) +{ + return prim.CanApplyAPI(whyNot); +} + +/* static */ +UsdTextColumnStyleAPI +UsdTextColumnStyleAPI::Apply(const UsdPrim &prim) +{ + if (prim.ApplyAPI()) { + return UsdTextColumnStyleAPI(prim); + } + return UsdTextColumnStyleAPI(); +} + +/* static */ +const TfType & +UsdTextColumnStyleAPI::_GetStaticTfType() +{ + static TfType tfType = TfType::Find(); + return tfType; +} + +/* static */ +bool +UsdTextColumnStyleAPI::_IsTypedSchema() +{ + static bool isTyped = _GetStaticTfType().IsA(); + return isTyped; +} + +/* virtual */ +const TfType & +UsdTextColumnStyleAPI::_GetTfType() const +{ + return _GetStaticTfType(); +} + +/*static*/ +const TfTokenVector& +UsdTextColumnStyleAPI::GetSchemaAttributeNames(bool includeInherited) +{ + static TfTokenVector localNames; + static TfTokenVector allNames = + UsdAPISchemaBase::GetSchemaAttributeNames(true); + + if (includeInherited) + return allNames; + else + return localNames; +} + +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 +UsdRelationship +UsdTextColumnStyleAPI::GetBindingRel() const +{ + return GetPrim().GetRelationship(UsdTextTokens->columnStyleBinding); +} + +UsdTextColumnStyleAPI::ColumnStyleBinding::ColumnStyleBinding( + const UsdRelationship &bindingRel, SdfPath const& textPrimPath) : + _bindingRel(bindingRel) +{ + // Get the columnstyle path. One text prim can bind several column styles. + SdfPathVector targetPaths; + _bindingRel.GetForwardedTargets(&targetPaths); + if (targetPaths.size() >= 1 && + targetPaths.front().IsPrimPath()) { + for (auto path : targetPaths) + _columnStylePaths.push_back(path); + } + + // Add a binding to the cache. + if (!_columnStylePaths.empty()) { + for (auto path : _columnStylePaths) + UsdTextColumnStyleAPI::AddBindToCache(path, textPrimPath); + } + +} + +std::vector +UsdTextColumnStyleAPI::ColumnStyleBinding::GetColumnStyles() const +{ + std::vector columnStyles; + // Get the columnstyle prim. + if (!_columnStylePaths.empty()) { + for(auto path : _columnStylePaths) + columnStyles.push_back(UsdTextColumnStyle(_bindingRel.GetStage()->GetPrimAtPath( + path))); + } + return columnStyles; +} + +UsdTextColumnStyleAPI::ColumnStyleBinding +UsdTextColumnStyleAPI::GetColumnStyleBinding(SdfPath const& primPath) const +{ + UsdRelationship bindingRel = GetBindingRel(); + return ColumnStyleBinding(bindingRel, primPath); +} + +bool +UsdTextColumnStyleAPI::CanContainPropertyName(const TfToken &name) +{ + return TfStringStartsWith(name, UsdTextTokens->columnStyle); +} + +UsdTextColumnStyleAPI::ColumnStyleBindingCache UsdTextColumnStyleAPI::_styleBindingCache; + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/usd/usdText/columnStyleAPI.h b/pxr/usd/usdText/columnStyleAPI.h new file mode 100644 index 0000000000..b50663b625 --- /dev/null +++ b/pxr/usd/usdText/columnStyleAPI.h @@ -0,0 +1,259 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#ifndef USDTEXT_GENERATED_COLUMNSTYLEAPI_H +#define USDTEXT_GENERATED_COLUMNSTYLEAPI_H + +/// \file usdText/columnStyleAPI.h + +#include "pxr/pxr.h" +#include "pxr/usd/usdText/api.h" +#include "pxr/usd/usd/apiSchemaBase.h" +#include "pxr/usd/usd/prim.h" +#include "pxr/usd/usd/stage.h" +#include "pxr/usd/usdText/tokens.h" + +#include "pxr/usd/usdText/columnStyle.h" +#include + + +#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; + +// -------------------------------------------------------------------------- // +// COLUMNSTYLEAPI // +// -------------------------------------------------------------------------- // + +/// \class UsdTextColumnStyleAPI +/// +/// . +/// +class UsdTextColumnStyleAPI : public UsdAPISchemaBase +{ +public: + /// Compile time constant representing what kind of schema this class is. + /// + /// \sa UsdSchemaKind + static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI; + + /// Construct a UsdTextColumnStyleAPI on UsdPrim \p prim . + /// Equivalent to UsdTextColumnStyleAPI::Get(prim.GetStage(), prim.GetPath()) + /// for a \em valid \p prim, but will not immediately throw an error for + /// an invalid \p prim + explicit UsdTextColumnStyleAPI(const UsdPrim& prim=UsdPrim()) + : UsdAPISchemaBase(prim) + { + } + + /// Construct a UsdTextColumnStyleAPI on the prim held by \p schemaObj . + /// Should be preferred over UsdTextColumnStyleAPI(schemaObj.GetPrim()), + /// as it preserves SchemaBase state. + explicit UsdTextColumnStyleAPI(const UsdSchemaBase& schemaObj) + : UsdAPISchemaBase(schemaObj) + { + } + + /// Destructor. + USDTEXT_API + virtual ~UsdTextColumnStyleAPI(); + + /// 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. + USDTEXT_API + static const TfTokenVector & + GetSchemaAttributeNames(bool includeInherited=true); + + /// Return a UsdTextColumnStyleAPI 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. This is shorthand for the following: + /// + /// \code + /// UsdTextColumnStyleAPI(stage->GetPrimAtPath(path)); + /// \endcode + /// + USDTEXT_API + static UsdTextColumnStyleAPI + Get(const UsdStagePtr &stage, const SdfPath &path); + + + /// Returns true if this single-apply API schema can be applied to + /// the given \p prim. If this schema can not be a applied to 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() + /// + USDTEXT_API + static bool + CanApply(const UsdPrim &prim, std::string *whyNot=nullptr); + + /// Applies this single-apply API schema to the given \p prim. + /// This information is stored by adding "ColumnStyleAPI" to the + /// token-valued, listOp metadata \em apiSchemas on the prim. + /// + /// \return A valid UsdTextColumnStyleAPI object is returned upon success. + /// An invalid (or empty) UsdTextColumnStyleAPI 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() + /// + USDTEXT_API + static UsdTextColumnStyleAPI + Apply(const UsdPrim &prim); + +protected: + /// Returns the kind of schema this class belongs to. + /// + /// \sa UsdSchemaKind + USDTEXT_API + UsdSchemaKind _GetSchemaKind() const override; + +private: + // needs to invoke _GetStaticTfType. + friend class UsdSchemaRegistry; + USDTEXT_API + static const TfType &_GetStaticTfType(); + + static bool _IsTypedSchema(); + + // override SchemaBase virtuals. + USDTEXT_API + const TfType &_GetTfType() const override; + +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)-- + using ColumnStyleBindingCache = + tbb::concurrent_unordered_multimap; + + USDTEXT_API + UsdRelationship GetBindingRel() const; + + class ColumnStyleBinding { + public: + /// Default constructor initializes a columnstyleBinding object with + /// invalid style and bindingRel data members. + ColumnStyleBinding() + {} + + /// Explicit constructor. + USDTEXT_API + explicit ColumnStyleBinding(const UsdRelationship &bindingRel, + SdfPath const& textPrimPath); + + /// Gets the columnstyle prim that this binding binds to. + USDTEXT_API + std::vector GetColumnStyles() const; + + /// Returns the path to the columnstyle that is bound to by this + /// binding. + const std::vector &GetColumnStylePaths() const { + return _columnStylePaths; + } + + /// Returns the binding-relationship that represents this binding. + const UsdRelationship &GetBindingRel() const { + return _bindingRel; + } + + private: + // The path to the columnstyle that is bound to. + std::vector _columnStylePaths; + + // The binding relationship. + UsdRelationship _bindingRel; + }; + + /// Get the binding. + USDTEXT_API + ColumnStyleBinding GetColumnStyleBinding(SdfPath const& prim) const; + + /// Test whether a given \p name contains the "columnStyle:" prefix + /// + USDTEXT_API + static bool CanContainPropertyName(const TfToken &name); + + /// Add a binding to a columnstyle and the text prim to the cache. + USDTEXT_API + static bool AddBindToCache(SdfPath const& columnStylePrimPath, + SdfPath const& textPrimPath) + { + _styleBindingCache.emplace(columnStylePrimPath, textPrimPath); + return true; + } + + /// Find the text prims who have the binding to the specified columnstyle. + USDTEXT_API + static bool FindBindedText(SdfPath const& columnStylePrimPath, + std::pair& pathPair) + { + pathPair = _styleBindingCache.equal_range(columnStylePrimPath); + if (pathPair.first != _styleBindingCache.end()) + return true; + else + return false; + } + +private: + // A cache that save the map between columnstyle and its binded text prim. + static ColumnStyleBindingCache _styleBindingCache; +}; + +PXR_NAMESPACE_CLOSE_SCOPE + +#endif diff --git a/pxr/usd/usdText/generatedSchema.usda b/pxr/usd/usdText/generatedSchema.usda index 3f2534ee08..14a2b86925 100644 --- a/pxr/usd/usdText/generatedSchema.usda +++ b/pxr/usd/usdText/generatedSchema.usda @@ -67,6 +67,37 @@ class TextRenderingTechnique "TextRenderingTechnique" ( ) } +class ColumnStyle "ColumnStyle" ( + doc = "Class for style of a column." +) +{ + token blockAlignment = "top" ( + allowedTokens = ["top", "center", "bottom"] + doc = "The text alignment in the block." + ) + float columnHeight = 0 ( + doc = "The height of the column." + ) + float columnWidth = 0 ( + doc = "The width of the column." + ) + string direction = "Default" ( + doc = "The Direction." + ) + float escapement = 0 ( + doc = "The Escapement." + ) + float4 margin = (0, 0, 0, 0) ( + doc = "The margins at the four direction." + ) + float2 offset = (0, 0) ( + doc = "The 2D offset from the previous column." + ) + float orientation = 0 ( + doc = "The Orientation." + ) +} + class "TextStyleAPI" ( doc = "." ) @@ -79,3 +110,9 @@ class "TextRenderingTechniqueAPI" ( { } +class "ColumnStyleAPI" ( + doc = "." +) +{ +} + diff --git a/pxr/usd/usdText/plugInfo.json b/pxr/usd/usdText/plugInfo.json index 9adb1c5990..f5897b2d5b 100644 --- a/pxr/usd/usdText/plugInfo.json +++ b/pxr/usd/usdText/plugInfo.json @@ -6,6 +6,26 @@ { "Info": { "Types": { + "UsdTextColumnStyle": { + "alias": { + "UsdSchemaBase": "ColumnStyle" + }, + "autoGenerated": true, + "bases": [ + "UsdTyped" + ], + "schemaKind": "concreteTyped" + }, + "UsdTextColumnStyleAPI": { + "alias": { + "UsdSchemaBase": "ColumnStyleAPI" + }, + "autoGenerated": true, + "bases": [ + "UsdAPISchemaBase" + ], + "schemaKind": "singleApplyAPI" + }, "UsdTextTextLayout": { "alias": { "UsdSchemaBase": "TextLayout" diff --git a/pxr/usd/usdText/schema.usda b/pxr/usd/usdText/schema.usda index ef6098c29b..29850ac2eb 100644 --- a/pxr/usd/usdText/schema.usda +++ b/pxr/usd/usdText/schema.usda @@ -114,6 +114,44 @@ class TextRenderingTechnique "TextRenderingTechnique" ( ) } +class ColumnStyle "ColumnStyle" ( + inherits = + doc = """Class for style of a column.""" + customData = { + string extraIncludes =""" +#include + """ + } +) { + float columnWidth = 0.0 ( + doc = """The width of the column.""" + ) + float columnHeight = 0.0 ( + doc = """The height of the column.""" + ) + float2 offset = (0.0, 0.0) ( + doc = """The 2D offset from the previous column.""" + ) + float4 margin = (0.0, 0.0, 0.0, 0.0) ( + doc = """The margins at the four direction.""" + ) + token blockAlignment = "top" ( + allowedTokens = ["top", "center", "bottom"] + doc = """The text alignment in the block.""" + ) + float orientation = 0.0 ( + doc = """The Orientation.""" + ) + + float escapement = 0.0 ( + doc = """The Escapement.""" + ) + + string direction = "Default" ( + doc = """The Direction.""" + ) +} + class "TextStyleAPI" ( inherits = @@ -163,4 +201,30 @@ class "TextRenderingTechniqueAPI" } } ) { +} + +class "ColumnStyleAPI" +( + inherits = + doc = """.""" + customData = { + string extraIncludes = """ +#include "pxr/usd/usdText/columnStyle.h" +#include + """ + token apiSchemaType = "singleApply" + dictionary schemaTokens = { + dictionary columnStyle = { + string value = "columnStyle" + string doc = """. + """ + } + dictionary columnStyleBinding = { + string value = "columnStyle:binding" + string doc = """. + """ + } + } + } +) { } \ No newline at end of file diff --git a/pxr/usd/usdText/tokens.cpp b/pxr/usd/usdText/tokens.cpp index dd4bf77d31..57810b236f 100644 --- a/pxr/usd/usdText/tokens.cpp +++ b/pxr/usd/usdText/tokens.cpp @@ -26,12 +26,21 @@ PXR_NAMESPACE_OPEN_SCOPE UsdTextTokensType::UsdTextTokensType() : + blockAlignment("blockAlignment", TfToken::Immortal), bold("bold", TfToken::Immortal), + bottom("bottom", TfToken::Immortal), + center("center", TfToken::Immortal), charSpacing("charSpacing", TfToken::Immortal), + columnHeight("columnHeight", TfToken::Immortal), + columnStyle("columnStyle", TfToken::Immortal), + columnStyleBinding("columnStyle:binding", TfToken::Immortal), + columnWidth("columnWidth", TfToken::Immortal), direction("direction", TfToken::Immortal), escapement("escapement", TfToken::Immortal), italic("italic", TfToken::Immortal), + margin("margin", TfToken::Immortal), obliqueAngle("obliqueAngle", TfToken::Immortal), + offset("offset", TfToken::Immortal), orientation("orientation", TfToken::Immortal), overlineType("overlineType", TfToken::Immortal), shaderBased("ShaderBased", TfToken::Immortal), @@ -44,16 +53,26 @@ UsdTextTokensType::UsdTextTokensType() : textStyleBinding("textStyle:binding", TfToken::Immortal), textureBased("TextureBased", TfToken::Immortal), textWidthFactor("textWidthFactor", TfToken::Immortal), + top("top", TfToken::Immortal), typeface("typeface", TfToken::Immortal), underlineType("underlineType", TfToken::Immortal), weight("weight", TfToken::Immortal), allTokens({ + blockAlignment, bold, + bottom, + center, charSpacing, + columnHeight, + columnStyle, + columnStyleBinding, + columnWidth, direction, escapement, italic, + margin, obliqueAngle, + offset, orientation, overlineType, shaderBased, @@ -66,6 +85,7 @@ UsdTextTokensType::UsdTextTokensType() : textStyleBinding, textureBased, textWidthFactor, + top, typeface, underlineType, weight diff --git a/pxr/usd/usdText/tokens.h b/pxr/usd/usdText/tokens.h index 0d40601887..517f7cdb61 100644 --- a/pxr/usd/usdText/tokens.h +++ b/pxr/usd/usdText/tokens.h @@ -58,37 +58,73 @@ PXR_NAMESPACE_OPEN_SCOPE /// Use UsdTextTokens like so: /// /// \code -/// gprim.GetMyTokenValuedAttr().Set(UsdTextTokens->bold); +/// gprim.GetMyTokenValuedAttr().Set(UsdTextTokens->blockAlignment); /// \endcode struct UsdTextTokensType { USDTEXT_API UsdTextTokensType(); + /// \brief "blockAlignment" + /// + /// UsdTextColumnStyle + const TfToken blockAlignment; /// \brief "bold" /// /// UsdTextTextStyle const TfToken bold; + /// \brief "bottom" + /// + /// Possible value for UsdTextColumnStyle::GetBlockAlignmentAttr() + const TfToken bottom; + /// \brief "center" + /// + /// Possible value for UsdTextColumnStyle::GetBlockAlignmentAttr() + const TfToken center; /// \brief "charSpacing" /// /// UsdTextTextStyle const TfToken charSpacing; + /// \brief "columnHeight" + /// + /// UsdTextColumnStyle + const TfToken columnHeight; + /// \brief "columnStyle" + /// + /// . + const TfToken columnStyle; + /// \brief "columnStyle:binding" + /// + /// . + const TfToken columnStyleBinding; + /// \brief "columnWidth" + /// + /// UsdTextColumnStyle + const TfToken columnWidth; /// \brief "direction" /// - /// UsdTextTextLayout + /// UsdTextColumnStyle, UsdTextTextLayout const TfToken direction; /// \brief "escapement" /// - /// UsdTextTextLayout + /// UsdTextColumnStyle, UsdTextTextLayout const TfToken escapement; /// \brief "italic" /// /// UsdTextTextStyle const TfToken italic; + /// \brief "margin" + /// + /// UsdTextColumnStyle + const TfToken margin; /// \brief "obliqueAngle" /// /// UsdTextTextStyle const TfToken obliqueAngle; + /// \brief "offset" + /// + /// UsdTextColumnStyle + const TfToken offset; /// \brief "orientation" /// - /// UsdTextTextLayout + /// UsdTextColumnStyle, UsdTextTextLayout const TfToken orientation; /// \brief "overlineType" /// @@ -134,6 +170,10 @@ struct UsdTextTokensType { /// /// UsdTextTextStyle const TfToken textWidthFactor; + /// \brief "top" + /// + /// Possible value for UsdTextColumnStyle::GetBlockAlignmentAttr(), Default value for UsdTextColumnStyle::GetBlockAlignmentAttr() + const TfToken top; /// \brief "typeface" /// /// UsdTextTextStyle diff --git a/pxr/usd/usdText/wrapColumnStyle.cpp b/pxr/usd/usdText/wrapColumnStyle.cpp new file mode 100644 index 0000000000..88ace50ab3 --- /dev/null +++ b/pxr/usd/usdText/wrapColumnStyle.cpp @@ -0,0 +1,236 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/usd/usdText/columnStyle.h" +#include "pxr/usd/usd/schemaBase.h" + +#include "pxr/usd/sdf/primSpec.h" + +#include "pxr/usd/usd/pyConversions.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 +_CreateColumnWidthAttr(UsdTextColumnStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateColumnWidthAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} + +static UsdAttribute +_CreateColumnHeightAttr(UsdTextColumnStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateColumnHeightAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} + +static UsdAttribute +_CreateOffsetAttr(UsdTextColumnStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateOffsetAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float2), writeSparsely); +} + +static UsdAttribute +_CreateMarginAttr(UsdTextColumnStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateMarginAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float4), writeSparsely); +} + +static UsdAttribute +_CreateBlockAlignmentAttr(UsdTextColumnStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateBlockAlignmentAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Token), writeSparsely); +} + +static UsdAttribute +_CreateOrientationAttr(UsdTextColumnStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateOrientationAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} + +static UsdAttribute +_CreateEscapementAttr(UsdTextColumnStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateEscapementAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Float), writeSparsely); +} + +static UsdAttribute +_CreateDirectionAttr(UsdTextColumnStyle &self, + object defaultVal, bool writeSparsely) { + return self.CreateDirectionAttr( + UsdPythonToSdfType(defaultVal, SdfValueTypeNames->String), writeSparsely); +} + +static std::string +_Repr(const UsdTextColumnStyle &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdText.ColumnStyle(%s)", + primRepr.c_str()); +} + +} // anonymous namespace + +void wrapUsdTextColumnStyle() +{ + typedef UsdTextColumnStyle This; + + class_ > + cls("ColumnStyle"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("Define", &This::Define, (arg("stage"), arg("path"))) + .staticmethod("Define") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .def("GetColumnWidthAttr", + &This::GetColumnWidthAttr) + .def("CreateColumnWidthAttr", + &_CreateColumnWidthAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetColumnHeightAttr", + &This::GetColumnHeightAttr) + .def("CreateColumnHeightAttr", + &_CreateColumnHeightAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOffsetAttr", + &This::GetOffsetAttr) + .def("CreateOffsetAttr", + &_CreateOffsetAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetMarginAttr", + &This::GetMarginAttr) + .def("CreateMarginAttr", + &_CreateMarginAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetBlockAlignmentAttr", + &This::GetBlockAlignmentAttr) + .def("CreateBlockAlignmentAttr", + &_CreateBlockAlignmentAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetOrientationAttr", + &This::GetOrientationAttr) + .def("CreateOrientationAttr", + &_CreateOrientationAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetEscapementAttr", + &This::GetEscapementAttr) + .def("CreateEscapementAttr", + &_CreateEscapementAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .def("GetDirectionAttr", + &This::GetDirectionAttr) + .def("CreateDirectionAttr", + &_CreateDirectionAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + + .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/usdText/wrapColumnStyleAPI.cpp b/pxr/usd/usdText/wrapColumnStyleAPI.cpp new file mode 100644 index 0000000000..467cfdd4c3 --- /dev/null +++ b/pxr/usd/usdText/wrapColumnStyleAPI.cpp @@ -0,0 +1,146 @@ +// +// Copyright 2016 Pixar +// +// Licensed under the Apache License, Version 2.0 (the "Apache License") +// with the following modification; you may not use this file except in +// compliance with the Apache License and the following modification to it: +// Section 6. Trademarks. is deleted and replaced with: +// +// 6. Trademarks. This License does not grant permission to use the trade +// names, trademarks, service marks, or product names of the Licensor +// and its affiliates, except as required to comply with Section 4(c) of +// the License and to reproduce the content of the NOTICE file. +// +// You may obtain a copy of the Apache License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the Apache License with the above modification is +// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the Apache License for the specific +// language governing permissions and limitations under the Apache License. +// +#include "pxr/usd/usdText/columnStyleAPI.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 std::string +_Repr(const UsdTextColumnStyleAPI &self) +{ + std::string primRepr = TfPyRepr(self.GetPrim()); + return TfStringPrintf( + "UsdText.ColumnStyleAPI(%s)", + primRepr.c_str()); +} + +struct UsdTextColumnStyleAPI_CanApplyResult : + public TfPyAnnotatedBoolResult +{ + UsdTextColumnStyleAPI_CanApplyResult(bool val, std::string const &msg) : + TfPyAnnotatedBoolResult(val, msg) {} +}; + +static UsdTextColumnStyleAPI_CanApplyResult +_WrapCanApply(const UsdPrim& prim) +{ + std::string whyNot; + bool result = UsdTextColumnStyleAPI::CanApply(prim, &whyNot); + return UsdTextColumnStyleAPI_CanApplyResult(result, whyNot); +} + +} // anonymous namespace + +void wrapUsdTextColumnStyleAPI() +{ + typedef UsdTextColumnStyleAPI This; + + UsdTextColumnStyleAPI_CanApplyResult::Wrap( + "_CanApplyResult", "whyNot"); + + class_ > + cls("ColumnStyleAPI"); + + cls + .def(init(arg("prim"))) + .def(init(arg("schemaObj"))) + .def(TfTypePythonClass()) + + .def("Get", &This::Get, (arg("stage"), arg("path"))) + .staticmethod("Get") + + .def("CanApply", &_WrapCanApply, (arg("prim"))) + .staticmethod("CanApply") + + .def("Apply", &This::Apply, (arg("prim"))) + .staticmethod("Apply") + + .def("GetSchemaAttributeNames", + &This::GetSchemaAttributeNames, + arg("includeInherited")=true, + return_value_policy()) + .staticmethod("GetSchemaAttributeNames") + + .def("_GetStaticTfType", (TfType const &(*)()) TfType::Find, + return_value_policy()) + .staticmethod("_GetStaticTfType") + + .def(!self) + + + .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/usdText/wrapTokens.cpp b/pxr/usd/usdText/wrapTokens.cpp index 8491cf0d6a..b6a8599431 100644 --- a/pxr/usd/usdText/wrapTokens.cpp +++ b/pxr/usd/usdText/wrapTokens.cpp @@ -64,12 +64,21 @@ void wrapUsdTextTokens() { boost::python::class_ cls("Tokens", boost::python::no_init); + _AddToken(cls, "blockAlignment", UsdTextTokens->blockAlignment); _AddToken(cls, "bold", UsdTextTokens->bold); + _AddToken(cls, "bottom", UsdTextTokens->bottom); + _AddToken(cls, "center", UsdTextTokens->center); _AddToken(cls, "charSpacing", UsdTextTokens->charSpacing); + _AddToken(cls, "columnHeight", UsdTextTokens->columnHeight); + _AddToken(cls, "columnStyle", UsdTextTokens->columnStyle); + _AddToken(cls, "columnStyleBinding", UsdTextTokens->columnStyleBinding); + _AddToken(cls, "columnWidth", UsdTextTokens->columnWidth); _AddToken(cls, "direction", UsdTextTokens->direction); _AddToken(cls, "escapement", UsdTextTokens->escapement); _AddToken(cls, "italic", UsdTextTokens->italic); + _AddToken(cls, "margin", UsdTextTokens->margin); _AddToken(cls, "obliqueAngle", UsdTextTokens->obliqueAngle); + _AddToken(cls, "offset", UsdTextTokens->offset); _AddToken(cls, "orientation", UsdTextTokens->orientation); _AddToken(cls, "overlineType", UsdTextTokens->overlineType); _AddToken(cls, "shaderBased", UsdTextTokens->shaderBased); @@ -82,6 +91,7 @@ void wrapUsdTextTokens() _AddToken(cls, "textStyleBinding", UsdTextTokens->textStyleBinding); _AddToken(cls, "textureBased", UsdTextTokens->textureBased); _AddToken(cls, "textWidthFactor", UsdTextTokens->textWidthFactor); + _AddToken(cls, "top", UsdTextTokens->top); _AddToken(cls, "typeface", UsdTextTokens->typeface); _AddToken(cls, "underlineType", UsdTextTokens->underlineType); _AddToken(cls, "weight", UsdTextTokens->weight);