|
|
#include "stdafx.h"
|
|
|
#include "ActionRotationItem.h"
|
|
|
#include "Util.h"
|
|
|
#include "BlobSerializer.h"
|
|
|
#include "SigmaDoc.h"
|
|
|
|
|
|
CActionRotationItem::CActionRotationItem()
|
|
|
: CActionItem(nullptr, 0)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
CActionRotationItem::CActionRotationItem(CSigmaDoc* ppDoc, UINT actionType, double x, double y, double angle)
|
|
|
: CActionItem(ppDoc, actionType),
|
|
|
m_x(x), m_y(y), m_angle(angle)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
CActionRotationItem::CActionRotationItem(CSigmaDoc* ppDoc, UINT actionType, double x, double y, double angle, const CPositionList &elements)
|
|
|
: CActionItem(ppDoc, actionType),
|
|
|
m_x(x), m_y(y), m_angle(angle)
|
|
|
{
|
|
|
CListAddRange(m_elements, elements);
|
|
|
}
|
|
|
|
|
|
void CActionRotationItem::Undo()
|
|
|
{
|
|
|
Rotation(-m_angle);
|
|
|
}
|
|
|
|
|
|
void CActionRotationItem::Redo()
|
|
|
{
|
|
|
Rotation(m_angle);
|
|
|
}
|
|
|
|
|
|
void CActionRotationItem::Do()
|
|
|
{
|
|
|
Rotation(m_angle);
|
|
|
}
|
|
|
|
|
|
void CActionRotationItem::Rotation(double angle)
|
|
|
{
|
|
|
// 如果角度为 0,则不需要进行任何旋转
|
|
|
if (fabs(angle) < std::numeric_limits<double>::epsilon())
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!m_elements.IsEmpty()) // 要旋转的是指定图元
|
|
|
{
|
|
|
CPtrList* pValues = GetDoc()->GetDraw()->GetValueList();
|
|
|
POSITION pos = m_elements.GetHeadPosition();
|
|
|
while (pos != nullptr)
|
|
|
{
|
|
|
POSITION pt = m_elements.GetNext(pos);
|
|
|
COne* pOne = reinterpret_cast<COne*>(pValues->GetAt(pt));
|
|
|
if (pOne != nullptr)
|
|
|
{
|
|
|
pOne->Rotate(m_x, m_y, angle);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else // 要旋转的是整个图件的图元
|
|
|
{
|
|
|
GetDoc()->GetDraw()->Rotate(m_x, m_y, angle);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void CActionRotationItem::accept(CActionVisitor& visitor)
|
|
|
{
|
|
|
visitor.visit(*this);
|
|
|
}
|