mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-17 08:57:09 +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:
107
src/Editor/Undo/CRotateNodeCommand.cpp
Normal file
107
src/Editor/Undo/CRotateNodeCommand.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "CRotateNodeCommand.h"
|
||||
#include "EUndoCommand.h"
|
||||
#include "../CWorldEditor.h"
|
||||
|
||||
CRotateNodeCommand::CRotateNodeCommand()
|
||||
: QUndoCommand("Rotate"),
|
||||
mpEditor(nullptr),
|
||||
mCommandEnded(false)
|
||||
{
|
||||
}
|
||||
|
||||
CRotateNodeCommand::CRotateNodeCommand(INodeEditor *pEditor, const QList<CSceneNode*>& nodes, const CVector3f& /*pivot*/, const CQuaternion& delta, ETransformSpace transformSpace)
|
||||
: QUndoCommand("Rotate"),
|
||||
mpEditor(pEditor),
|
||||
mCommandEnded(false)
|
||||
{
|
||||
mNodeList.reserve(nodes.size());
|
||||
|
||||
foreach (CSceneNode *pNode, nodes)
|
||||
{
|
||||
SNodeRotate rotate;
|
||||
rotate.pNode = pNode;
|
||||
rotate.initialPos = pNode->LocalPosition();
|
||||
rotate.initialRot = pNode->LocalRotation();
|
||||
pNode->Rotate(delta, transformSpace);
|
||||
rotate.newPos = pNode->LocalPosition();
|
||||
rotate.newRot = pNode->LocalRotation();
|
||||
mNodeList.push_back(rotate);
|
||||
}
|
||||
|
||||
mpEditor->SelectionTransformed();
|
||||
}
|
||||
|
||||
CRotateNodeCommand::~CRotateNodeCommand()
|
||||
{
|
||||
}
|
||||
|
||||
int CRotateNodeCommand::id() const
|
||||
{
|
||||
return eRotateNodeCmd;
|
||||
}
|
||||
|
||||
bool CRotateNodeCommand::mergeWith(const QUndoCommand *other)
|
||||
{
|
||||
if (mCommandEnded) return false;
|
||||
|
||||
if (other->id() == eRotateNodeCmd)
|
||||
{
|
||||
const CRotateNodeCommand *pCmd = static_cast<const CRotateNodeCommand*>(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;
|
||||
mNodeList[iNode].newRot = pCmd->mNodeList[iNode].newRot;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CRotateNodeCommand::undo()
|
||||
{
|
||||
if (!mpEditor) return;
|
||||
|
||||
foreach (SNodeRotate rotate, mNodeList)
|
||||
{
|
||||
rotate.pNode->SetPosition(rotate.initialPos);
|
||||
rotate.pNode->SetRotation(rotate.initialRot);
|
||||
}
|
||||
|
||||
mpEditor->RecalculateSelectionBounds();
|
||||
mpEditor->SelectionTransformed();
|
||||
mpEditor->UpdateGizmoUI();
|
||||
}
|
||||
|
||||
void CRotateNodeCommand::redo()
|
||||
{
|
||||
if (!mpEditor) return;
|
||||
|
||||
foreach (SNodeRotate rotate, mNodeList)
|
||||
{
|
||||
rotate.pNode->SetPosition(rotate.newPos);
|
||||
rotate.pNode->SetRotation(rotate.newRot);
|
||||
}
|
||||
|
||||
mpEditor->RecalculateSelectionBounds();
|
||||
mpEditor->SelectionTransformed();
|
||||
mpEditor->UpdateGizmoUI();
|
||||
}
|
||||
|
||||
CRotateNodeCommand* CRotateNodeCommand::End()
|
||||
{
|
||||
CRotateNodeCommand *pCmd = new CRotateNodeCommand();
|
||||
pCmd->mCommandEnded = true;
|
||||
return pCmd;
|
||||
}
|
||||
Reference in New Issue
Block a user