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

More code clean up in UsdTransform3dMayaXformStack #959

Merged
merged 1 commit into from
Dec 2, 2020
Merged
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
29 changes: 3 additions & 26 deletions lib/mayaUsd/ufe/UsdTransform3dMayaXformStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ class UsdTRSUndoableCmdBase : public Ufe::SetVector3dUndoableCommand
private:
const UsdTimeCode _readTime;
const UsdTimeCode _writeTime;
VtValue _prevOpValue;
VtValue _newOpValue;
TfToken _attrName;
UsdGeomXformOp _op;
OpFunc _opFunc;
UsdUndoableItem _undoableItem;
Expand Down Expand Up @@ -194,14 +192,12 @@ class UsdTRSUndoableCmdBase : public Ufe::SetVector3dUndoableCommand
}
void handleSet(UsdTRSUndoableCmdBase* cmd, const VtValue& v) override
{
// Add undoblock to capture edits
UsdUndoBlock undoBlock(&cmd->_undoableItem);

// Going from initial to executing / executed state, save value.
cmd->_op = cmd->_opFunc(*cmd);
cmd->_attrName = cmd->_op.GetOpName();
cmd->_prevOpValue = getValue(cmd->_op.GetAttr(), cmd->readTime());
cmd->_newOpValue = v;

// Add undoblock to capture edits
UsdUndoBlock undoBlock(&cmd->_undoableItem);
cmd->setValue(v);
cmd->_state = &UsdTRSUndoableCmdBase::_executeState;
}
Expand All @@ -225,8 +221,6 @@ class UsdTRSUndoableCmdBase : public Ufe::SetVector3dUndoableCommand
// Undo
cmd->_undoableItem.undo();

cmd->recreateOp();
cmd->setValue(cmd->_prevOpValue);
cmd->_state = &UsdTRSUndoableCmdBase::_undoneState;
}
void handleSet(UsdTRSUndoableCmdBase* cmd, const VtValue& v) override
Expand All @@ -246,7 +240,6 @@ class UsdTRSUndoableCmdBase : public Ufe::SetVector3dUndoableCommand

// Can ignore the value, we already have it --- or assert they're
// equal, perhaps.
cmd->recreateOp();
cmd->setValue(cmd->_newOpValue);
cmd->_state = &UsdTRSUndoableCmdBase::_redoneState;
}
Expand All @@ -260,8 +253,6 @@ class UsdTRSUndoableCmdBase : public Ufe::SetVector3dUndoableCommand
// Undo
cmd->_undoableItem.undo();

cmd->recreateOp();
cmd->setValue(cmd->_prevOpValue);
cmd->_state = &UsdTRSUndoableCmdBase::_undoneState;
}
};
Expand All @@ -276,9 +267,7 @@ class UsdTRSUndoableCmdBase : public Ufe::SetVector3dUndoableCommand
// Always read from proxy shape time.
_readTime(getTime(path))
, _writeTime(writeTime_)
, _prevOpValue()
, _newOpValue(newOpValue)
, _attrName()
, _op()
, _opFunc(std::move(opFunc))
{
Expand All @@ -289,18 +278,6 @@ class UsdTRSUndoableCmdBase : public Ufe::SetVector3dUndoableCommand
void undo() override { _state->handleUndo(this); }
void redo() override { handleSet(_newOpValue); }

void recreateOp()
{
auto sceneItem
= std::dynamic_pointer_cast<UsdSceneItem>(Ufe::Hierarchy::createItem(path()));
TF_AXIOM(sceneItem);
auto prim = sceneItem->prim();
TF_AXIOM(prim);
auto attr = prim.GetAttribute(_attrName);
TF_AXIOM(attr);
_op = UsdGeomXformOp(attr);
}

void handleSet(const VtValue& v) { _state->handleSet(this, v); }

void setValue(const VtValue& v) { _op.GetAttr().Set(v, _writeTime); }
Expand Down