You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/Module/GeoSigmaDraw/ActionRotationItem.cpp

73 lines
1.5 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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);
}