mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-09 05:27:41 +00:00
Mass refactoring part 1/2: establishing multiple subprojects, moving source files to their new location, adding resources/templates to version control
This commit is contained in:
96
src/Editor/Undo/CTranslateNodeCommand.cpp
Normal file
96
src/Editor/Undo/CTranslateNodeCommand.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "CTranslateNodeCommand.h"
|
||||
#include "EUndoCommand.h"
|
||||
#include "../CWorldEditor.h"
|
||||
|
||||
CTranslateNodeCommand::CTranslateNodeCommand()
|
||||
: QUndoCommand("Translate"),
|
||||
mpEditor(nullptr),
|
||||
mCommandEnded(false)
|
||||
{
|
||||
}
|
||||
|
||||
CTranslateNodeCommand::CTranslateNodeCommand(INodeEditor *pEditor, const QList<CSceneNode*>& nodes, const CVector3f& delta, ETransformSpace transformSpace)
|
||||
: QUndoCommand("Translate"),
|
||||
mpEditor(pEditor),
|
||||
mCommandEnded(false)
|
||||
{
|
||||
mNodeList.reserve(nodes.size());
|
||||
|
||||
foreach (CSceneNode *pNode, nodes)
|
||||
{
|
||||
SNodeTranslate translate;
|
||||
translate.pNode = pNode;
|
||||
translate.initialPos = pNode->LocalPosition();
|
||||
pNode->Translate(delta, transformSpace);
|
||||
translate.newPos = pNode->LocalPosition();
|
||||
mNodeList.push_back(translate);
|
||||
}
|
||||
|
||||
mpEditor->SelectionTransformed();
|
||||
}
|
||||
|
||||
CTranslateNodeCommand::~CTranslateNodeCommand()
|
||||
{
|
||||
}
|
||||
|
||||
int CTranslateNodeCommand::id() const
|
||||
{
|
||||
return eTranslateNodeCmd;
|
||||
}
|
||||
|
||||
bool CTranslateNodeCommand::mergeWith(const QUndoCommand *other)
|
||||
{
|
||||
if (mCommandEnded) return false;
|
||||
|
||||
if (other->id() == eTranslateNodeCmd)
|
||||
{
|
||||
const CTranslateNodeCommand *pCmd = static_cast<const CTranslateNodeCommand*>(other);
|
||||
|
||||
if (pCmd->mCommandEnded)
|
||||
{
|
||||
mCommandEnded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((mpEditor == pCmd->mpEditor) && (mNodeList.size() == pCmd->mNodeList.size()))
|
||||
{
|
||||
for (int iNode = 0; iNode < mNodeList.size(); iNode++)
|
||||
mNodeList[iNode].newPos = pCmd->mNodeList[iNode].newPos;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CTranslateNodeCommand::undo()
|
||||
{
|
||||
if (!mpEditor) return;
|
||||
|
||||
foreach (SNodeTranslate translate, mNodeList)
|
||||
translate.pNode->SetPosition(translate.initialPos);
|
||||
|
||||
mpEditor->RecalculateSelectionBounds();
|
||||
mpEditor->SelectionTransformed();
|
||||
mpEditor->UpdateGizmoUI();
|
||||
}
|
||||
|
||||
void CTranslateNodeCommand::redo()
|
||||
{
|
||||
if (!mpEditor) return;
|
||||
|
||||
foreach (SNodeTranslate translate, mNodeList)
|
||||
translate.pNode->SetPosition(translate.newPos);
|
||||
|
||||
mpEditor->RecalculateSelectionBounds();
|
||||
mpEditor->SelectionTransformed();
|
||||
mpEditor->UpdateGizmoUI();
|
||||
}
|
||||
|
||||
CTranslateNodeCommand* CTranslateNodeCommand::End()
|
||||
{
|
||||
CTranslateNodeCommand *pCmd = new CTranslateNodeCommand();
|
||||
pCmd->mCommandEnded = true;
|
||||
return pCmd;
|
||||
}
|
||||
Reference in New Issue
Block a user