5.2 KiB
5.2 KiB
1. Core Command Infrastructure
- 1.1 Create
src/core/CommandHistory.h— defineICommandpure-virtual interface (Execute,Undo,GetDescription) andCommandHistoryclass withPush,Undo,Redo,Clear,CanUndo,CanRedo,GetUndoDescription,GetRedoDescription - 1.2 Create
src/core/CommandHistory.cpp— implementCommandHistorywith undo/redo stacks (std::vector<std::unique_ptr<ICommand>>);Pushexecutes command, pushes to undo stack, clears redo stack - 1.3 Add
CommandHistoryas a member ofApplicationand passCommandHistory*into all panel and manager constructors/init methods - 1.4 Call
m_commandHistory.Clear()insideApplication::RefreshManagers()so history resets on every stage lifecycle event - 1.5 Add
CMakeLists.txtentries for all new source files (CommandHistory.cppand all command.cppfiles added in subsequent tasks)
2. Transform Commands
- 2.1 Create
src/core/commands/TransformCommand.h/.cpp— stores primSdfPath,SdfLayerHandleedit target, and pre/post TRS (GfVec3dtranslate,GfVec3frotate,GfVec3fscale);Execute()applies post-values,Undo()applies pre-values viaUsdGeomXformCommonAPI+UsdEditContext - 2.2 Modify
TransformManipulator— acceptCommandHistory*in constructor/init; on drag-begin snapshot TRS intom_dragStartTRS; on drag-end (detectwasDrawing && !m_isDragging) pushTransformCommandonly when delta is non-zero - 2.3 Modify
PropertyPanel— acceptCommandHistory*; capture pre-edit TRS before field edit begins; pushTransformCommandinsideImGui::IsItemDeactivatedAfterEdit()blocks for translate, rotate, and scale fields
3. Scene Hierarchy Commands
- 3.1 Create
src/core/commands/CreatePrimCommand.h/.cpp— storesSdfPath,TfToken typeName,SdfLayerHandle;Execute()callsstage->DefinePrim;Undo()callsstage->RemovePrim - 3.2 Create
src/core/commands/DeletePrimCommand.h/.cpp— on construction serialises the target prim's spec viaSdfCopySpecinto an anonymous layer;Execute()removes the prim;Undo()restores from the anonymous layer viaSdfCopySpec - 3.3 Create
src/core/commands/AddReferenceCommand.h/.cpp— stores created prim path andSdfReference;Execute()wraps in Xform and adds reference;Undo()removes the prim - 3.4 Create
src/core/commands/ReplaceReferenceCommand.h/.cpp— stores prim path, oldSdfReference, newSdfReference;Execute()applies new reference;Undo()restores old - 3.5 Modify
SceneHierarchyPanel— acceptCommandHistory*; replace directApplication::CreatePrimOnStagecalls withPush(CreatePrimCommand); replace direct delete withPush(DeletePrimCommand); replaceAddReferenceToStagewithPush(AddReferenceCommand); replaceProcessPendingReplaceRefwithPush(ReplaceReferenceCommand)
4. Attribute Edit Commands
- 4.1 Create
src/core/commands/AttributeSetCommand.h/.cpp— storesstd::string description,std::function<void()> executeFunc,std::function<void()> undoFunc; captures old value before set usingUsdAttribute::Get<T>at the call site - 4.2 Modify
PropertyManager::SetPropertyValueandSetPropertyValueInLayer— read old value, constructAttributeSetCommandwith closures for old/new applies, push toCommandHistory
5. Layer Operation Commands
- 5.1 Create
src/core/commands/LayerCreateCommand.h/.cpp— stores layer file path and insertion index;Execute()callsLayerManager::CreateSublayer;Undo()callsLayerManager::RemoveSublayer - 5.2 Create
src/core/commands/LayerRemoveCommand.h/.cpp— stores layer path and original index;Execute()removes;Undo()re-inserts at saved index - 5.3 Create
src/core/commands/LayerReorderCommand.h/.cpp— stores full ordered-path list before and after;Execute()applies new order;Undo()restores old order by rewritingrootLayer->GetSubLayerPaths() - 5.4 Modify
LayerPanel— acceptCommandHistory*; wrap Create, Remove, MoveUp, and MoveDown calls with the corresponding commands
6. Hotkeys and Menu Integration
- 6.1 In
Application's main-loop (orImGuiContext), detectCtrl+ZandCtrl+Y/Ctrl+Shift+Zkey combinations when no ImGui text widget has input focus (!ImGui::GetIO().WantTextInput); callm_commandHistory.Undo()/m_commandHistory.Redo()accordingly - 6.2 Add Edit menu (or extend existing menu bar) with Undo and Redo items; display
GetUndoDescription()/GetRedoDescription()in item labels; disable items viaImGui::BeginDisabled(!CanUndo())/(!CanRedo())
7. Build and Verification
- 7.1 Run
cmake --preset defaultandcmake --build build --config Release— compilation succeeds; LNK1104 only occurs becauseUsdLayerManager.exeis currently running (expected) - 7.2 Run
cmake --install build --config Releaseand launchinstall/bin/App.exe; manually verify: create a prim, undo removes it, redo restores it - 7.3 Manually verify gizmo drag undo: translate a prim with the Move gizmo, press Ctrl+Z, confirm prim returns to original position
- 7.4 Run
ctest --test-dir build -C Releaseand confirm all tests pass