Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-105977: Update restriction error reports based on latest design. #687

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
321 changes: 164 additions & 157 deletions lib/mayaUsd/ufe/private/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,113 +36,121 @@ namespace ufe {

UsdGeomXformCommonAPI convertToCompatibleCommonAPI(const UsdPrim& prim)
{
// As we are using USD's XformCommonAPI which supports only the following xformOps :
// ["xformOp:translate", "xformOp:translate:pivot", "xformOp:rotateXYZ", "xformOp:scale", "!invert!xformOp:translate:pivot"]
// We are extending the supported xform Operations with :
// ["xformOp:rotateX", "xformOp:rotateY", "xformOp:rotateZ"]
// Where we convert these into xformOp:rotateXYZ.
// As we are using USD's XformCommonAPI which supports only the following xformOps :
// ["xformOp:translate", "xformOp:translate:pivot", "xformOp:rotateXYZ", "xformOp:scale", "!invert!xformOp:translate:pivot"]
// We are extending the supported xform Operations with :
// ["xformOp:rotateX", "xformOp:rotateY", "xformOp:rotateZ"]
// Where we convert these into xformOp:rotateXYZ.

static TfToken rotX("xformOp:rotateX");
static TfToken rotY("xformOp:rotateY");
static TfToken rotZ("xformOp:rotateZ");
static TfToken rotXYZ("xformOp:rotateXYZ");
static TfToken scale("xformOp:scale");
static TfToken trans("xformOp:translate");
static TfToken pivot("xformOp:translate:pivot");
static TfToken notPivot("!invert!xformOp:translate:pivot");
static TfToken rotX("xformOp:rotateX");
static TfToken rotY("xformOp:rotateY");
static TfToken rotZ("xformOp:rotateZ");
static TfToken rotXYZ("xformOp:rotateXYZ");
static TfToken scale("xformOp:scale");
static TfToken trans("xformOp:translate");
static TfToken pivot("xformOp:translate:pivot");
static TfToken notPivot("!invert!xformOp:translate:pivot");

auto xformable = UsdGeomXformable(prim);
bool resetsXformStack;
auto xformOps = xformable.GetOrderedXformOps(&resetsXformStack);
xformable.ClearXformOpOrder();
auto primXform = UsdGeomXformCommonAPI(prim);
for (const auto& op : xformOps)
{
auto opName = op.GetOpName();
auto xformable = UsdGeomXformable(prim);
bool resetsXformStack;
auto xformOps = xformable.GetOrderedXformOps(&resetsXformStack);
xformable.ClearXformOpOrder();
auto primXform = UsdGeomXformCommonAPI(prim);
for (const auto& op : xformOps)
{
auto opName = op.GetOpName();

// RotateX, RotateY, RotateZ
if ((opName == rotX) || (opName == rotY) || (opName == rotZ))
{
float retValue;
if (op.Get<float>(&retValue))
{
if (opName == rotX)
primXform.SetRotate(GfVec3f(retValue, 0, 0));
else if (opName == rotY)
primXform.SetRotate(GfVec3f(0, retValue, 0));
else if (opName == rotZ)
primXform.SetRotate(GfVec3f(0, 0, retValue));
}
}
// RotateXYZ
else if (opName == rotXYZ)
{
GfVec3f retValue;
if (op.Get<GfVec3f>(&retValue))
{
primXform.SetRotate(retValue);
}
}
// Scale
else if (opName == scale)
{
GfVec3f retValue;
if (op.Get<GfVec3f>(&retValue))
{
primXform.SetScale(retValue);
}
}
// Translate
else if (opName == trans)
{
GfVec3d retValue;
if (op.Get<GfVec3d>(&retValue))
{
primXform.SetTranslate(retValue);
}
}
// Scale / rotate pivot
else if (opName == pivot)
{
GfVec3f retValue;
if (op.Get<GfVec3f>(&retValue))
{
primXform.SetPivot(retValue);
}
}
// Scale / rotate pivot inverse
else if (opName == notPivot)
{
// automatically added, nothing to do.
}
// Not compatible
else
{
// Restore old
xformable.SetXformOpOrder(xformOps);
std::string err = TfStringPrintf("Incompatible xform op %s:", op.GetOpName().GetString().c_str());
throw std::runtime_error(err.c_str());
}
}
return primXform;
// RotateX, RotateY, RotateZ
if ((opName == rotX) || (opName == rotY) || (opName == rotZ))
{
float retValue;
if (op.Get<float>(&retValue))
{
if (opName == rotX)
primXform.SetRotate(GfVec3f(retValue, 0, 0));
else if (opName == rotY)
primXform.SetRotate(GfVec3f(0, retValue, 0));
else if (opName == rotZ)
primXform.SetRotate(GfVec3f(0, 0, retValue));
}
}
// RotateXYZ
else if (opName == rotXYZ)
{
GfVec3f retValue;
if (op.Get<GfVec3f>(&retValue))
{
primXform.SetRotate(retValue);
}
}
// Scale
else if (opName == scale)
{
GfVec3f retValue;
if (op.Get<GfVec3f>(&retValue))
{
primXform.SetScale(retValue);
}
}
// Translate
else if (opName == trans)
{
GfVec3d retValue;
if (op.Get<GfVec3d>(&retValue))
{
primXform.SetTranslate(retValue);
}
}
// Scale / rotate pivot
else if (opName == pivot)
{
GfVec3f retValue;
if (op.Get<GfVec3f>(&retValue))
{
primXform.SetPivot(retValue);
}
}
// Scale / rotate pivot inverse
else if (opName == notPivot)
{
// automatically added, nothing to do.
}
// Not compatible
else
{
// Restore old
xformable.SetXformOpOrder(xformOps);
std::string err = TfStringPrintf("Incompatible xform op %s:", op.GetOpName().GetString().c_str());
throw std::runtime_error(err.c_str());
}
}
return primXform;
}

void applyCommandRestriction(const UsdPrim& prim, const std::string& commandName)
{
// early check to see if a particular node has any specs to contribute
// to the final composed prim. e.g (a node in payload)
if(!MayaUsdUtils::hasSpecs(prim)){
std::string err = TfStringPrintf("Cannot %s [%s] because it doesn't have any specs to contribute to the composed prim.",
commandName.c_str(),
prim.GetName().GetString().c_str());

auto layers = MayaUsdUtils::layerInCompositionArcsWithSpec(prim);
std::string layerDisplayNames;
for (auto layer : layers) {
layerDisplayNames.append("[" + layer->GetDisplayName() + "]" + ",");
}
layerDisplayNames.pop_back();
std::string err = TfStringPrintf("Cannot %s [%s]. It does not make any contributions in the current layer "
"because its specs are in an external composition arc. Please open %s to make direct edits.",
commandName.c_str(),
prim.GetName().GetString().c_str(),
layerDisplayNames.c_str());
throw std::runtime_error(err.c_str());
}

// if the current layer doesn't have any contributions
if (!MayaUsdUtils::doesEditTargetLayerContribute(prim)) {
auto strongestContributingLayer = MayaUsdUtils::strongestContributingLayer(prim);
std::string err = TfStringPrintf("Cannot %s [%s] defined on another layer. "
"Please set [%s] as the target layer to proceed",
std::string err = TfStringPrintf("Cannot %s [%s]. It is defined on another layer. Please set [%s] as the target layer to proceed.",
commandName.c_str(),
prim.GetName().GetString().c_str(),
strongestContributingLayer->GetDisplayName().c_str());
Expand All @@ -158,8 +166,7 @@ void applyCommandRestriction(const UsdPrim& prim, const std::string& commandName
layerDisplayNames.append("[" + layer->GetDisplayName() + "]" + ",");
}
layerDisplayNames.pop_back();
std::string err = TfStringPrintf("Cannot %s [%s] with definitions or opinions on other layers. "
"Opinions exist in %s",
std::string err = TfStringPrintf("Cannot %s [%s]. It has definitions or opinions on other layers. Opinions exist in %s",
commandName.c_str(),
prim.GetName().GetString().c_str(),
layerDisplayNames.c_str());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ppt-adsk Updating all the strings inside applyCommandRestriction routine.

Expand All @@ -174,82 +181,82 @@ void applyCommandRestriction(const UsdPrim& prim, const std::string& commandName

void translateOp(const UsdPrim& prim, const Ufe::Path& path, double x, double y, double z)
{
auto primXform = UsdGeomXformCommonAPI(prim);
if (!primXform.SetTranslate(GfVec3d(x, y, z)))
{
// This could mean that we have an incompatible xformOp in the stack
try {
primXform = convertToCompatibleCommonAPI(prim);
if (!primXform.SetTranslate(GfVec3d(x,y,z)))
throw std::runtime_error("Unable to SetTranslate after conversion to CommonAPI.");
}
catch (const std::exception& e) {
std::string err = TfStringPrintf("Failed to translate prim %s - %s",
path.string().c_str(), e.what());
UFE_LOG(err.c_str());
throw;
}
}
auto primXform = UsdGeomXformCommonAPI(prim);
if (!primXform.SetTranslate(GfVec3d(x, y, z)))
{
// This could mean that we have an incompatible xformOp in the stack
try {
primXform = convertToCompatibleCommonAPI(prim);
if (!primXform.SetTranslate(GfVec3d(x,y,z)))
throw std::runtime_error("Unable to SetTranslate after conversion to CommonAPI.");
}
catch (const std::exception& e) {
std::string err = TfStringPrintf("Failed to translate prim %s - %s",
path.string().c_str(), e.what());
UFE_LOG(err.c_str());
throw;
}
}
}

void rotateOp(const UsdPrim& prim, const Ufe::Path& path, double x, double y, double z)
{
auto primXform = UsdGeomXformCommonAPI(prim);
if (!primXform.SetRotate(GfVec3f(x, y, z)))
{
// This could mean that we have an incompatible xformOp in the stack
try {
primXform = convertToCompatibleCommonAPI(prim);
if (!primXform.SetRotate(GfVec3f(x, y, z)))
throw std::runtime_error("Unable to SetRotate after conversion to CommonAPI.");
}
catch (const std::exception& e) {
std::string err = TfStringPrintf("Failed to rotate prim %s - %s",
path.string().c_str(), e.what());
UFE_LOG(err.c_str());
throw;
}
}
auto primXform = UsdGeomXformCommonAPI(prim);
if (!primXform.SetRotate(GfVec3f(x, y, z)))
{
// This could mean that we have an incompatible xformOp in the stack
try {
primXform = convertToCompatibleCommonAPI(prim);
if (!primXform.SetRotate(GfVec3f(x, y, z)))
throw std::runtime_error("Unable to SetRotate after conversion to CommonAPI.");
}
catch (const std::exception& e) {
std::string err = TfStringPrintf("Failed to rotate prim %s - %s",
path.string().c_str(), e.what());
UFE_LOG(err.c_str());
throw;
}
}
}

void scaleOp(const UsdPrim& prim, const Ufe::Path& path, double x, double y, double z)
{
auto primXform = UsdGeomXformCommonAPI(prim);
if (!primXform.SetScale(GfVec3f(x, y, z)))
{
// This could mean that we have an incompatible xformOp in the stack
try {
primXform = convertToCompatibleCommonAPI(prim);
if (!primXform.SetScale(GfVec3f(x, y, z)))
throw std::runtime_error("Unable to SetScale after conversion to CommonAPI.");
}
catch (const std::exception& e) {
std::string err = TfStringPrintf("Failed to scale prim %s - %s",
path.string().c_str(), e.what());
UFE_LOG(err.c_str());
throw;
}
}
auto primXform = UsdGeomXformCommonAPI(prim);
if (!primXform.SetScale(GfVec3f(x, y, z)))
{
// This could mean that we have an incompatible xformOp in the stack
try {
primXform = convertToCompatibleCommonAPI(prim);
if (!primXform.SetScale(GfVec3f(x, y, z)))
throw std::runtime_error("Unable to SetScale after conversion to CommonAPI.");
}
catch (const std::exception& e) {
std::string err = TfStringPrintf("Failed to scale prim %s - %s",
path.string().c_str(), e.what());
UFE_LOG(err.c_str());
throw;
}
}
}

void rotatePivotTranslateOp(const UsdPrim& prim, const Ufe::Path& path, double x, double y, double z)
{
auto primXform = UsdGeomXformCommonAPI(prim);
if (!primXform.SetPivot(GfVec3f(x, y, z)))
{
// This could mean that we have an incompatible xformOp in the stack
try {
primXform = convertToCompatibleCommonAPI(prim);
if (!primXform.SetPivot(GfVec3f(x, y, z)))
throw std::runtime_error("Unable to SetPivot after conversion to CommonAPI.");
}
catch (const std::exception& e) {
std::string err = TfStringPrintf("Failed to set pivot for prim %s - %s",
path.string().c_str(), e.what());
UFE_LOG(err.c_str());
throw;
}
}
auto primXform = UsdGeomXformCommonAPI(prim);
if (!primXform.SetPivot(GfVec3f(x, y, z)))
{
// This could mean that we have an incompatible xformOp in the stack
try {
primXform = convertToCompatibleCommonAPI(prim);
if (!primXform.SetPivot(GfVec3f(x, y, z)))
throw std::runtime_error("Unable to SetPivot after conversion to CommonAPI.");
}
catch (const std::exception& e) {
std::string err = TfStringPrintf("Failed to set pivot for prim %s - %s",
path.string().c_str(), e.what());
UFE_LOG(err.c_str());
throw;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ignore the tab conversion to dot changes by enabling "Hide whitespace changes" on github.

}

} // namespace ufe
Expand Down
17 changes: 17 additions & 0 deletions lib/usd/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ hasSpecs(const UsdPrim& prim)
return found;
}

std::vector<SdfLayerHandle>
layerInCompositionArcsWithSpec(const UsdPrim& prim)
{
UsdPrimCompositionQuery query(prim);

std::vector<SdfLayerHandle> layersWithContribution;

for (const auto& compQueryArc : query.GetCompositionArcs()) {
if (compQueryArc.GetTargetNode().HasSpecs()) {
layersWithContribution.emplace_back(
compQueryArc.GetTargetNode().GetLayerStack()->GetIdentifier().rootLayer);
}
}

return layersWithContribution;
}

void
printCompositionQuery(const UsdPrim& prim, std::ostream& os)
{
Expand Down
Loading