Skip to content

Commit

Permalink
Merge pull request #959 from Autodesk/sabrih/fix_undo_redo_transforma…
Browse files Browse the repository at this point in the history
…tion

More code clean up in UsdTransform3dMayaXformStack
  • Loading branch information
ppt-adsk authored Dec 2, 2020
2 parents 4d8d5ac + 3f99a2a commit 4e8282c
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions lib/mayaUsd/ufe/UsdTransform3dMayaXformStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,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 @@ -192,14 +190,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 @@ -223,8 +219,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 @@ -244,7 +238,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 @@ -258,8 +251,6 @@ class UsdTRSUndoableCmdBase : public Ufe::SetVector3dUndoableCommand
// Undo
cmd->_undoableItem.undo();

cmd->recreateOp();
cmd->setValue(cmd->_prevOpValue);
cmd->_state = &UsdTRSUndoableCmdBase::_undoneState;
}
};
Expand All @@ -274,9 +265,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 @@ -287,18 +276,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

0 comments on commit 4e8282c

Please sign in to comment.