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.
103 lines
1.8 KiB
C++
103 lines
1.8 KiB
C++
#pragma once
|
|
#include "stdafx.h"
|
|
#include "ActionCurveEditAddPoint.h"
|
|
#include "SigmaDoc.h"
|
|
#include "Visitor.h"
|
|
|
|
namespace NAction
|
|
{
|
|
CActionCurveEditAddPoint::CActionCurveEditAddPoint()
|
|
: CActionItem(nullptr, 0)
|
|
{
|
|
}
|
|
|
|
CActionCurveEditAddPoint::CActionCurveEditAddPoint(CSigmaDoc * pDoc, UINT actionType, POSITION pos)
|
|
:CActionItem(pDoc, actionType),
|
|
m_posOfCurve(pos),
|
|
m_index(-1)
|
|
{
|
|
}
|
|
|
|
void CActionCurveEditAddPoint::Undo()
|
|
{
|
|
CCurveEx * pCurve = GetCurve();
|
|
if (pCurve == 0)
|
|
return;
|
|
|
|
if (m_index < 0 || m_index >= pCurve->num)
|
|
return;
|
|
|
|
CPointList ptList;
|
|
dfPoint dd;
|
|
|
|
for (int i = 0; i < pCurve->num; i++)
|
|
{
|
|
dd.x0 = pCurve->x[i];
|
|
dd.y0 = pCurve->y[i];
|
|
dd.z0 = pCurve->z[i];
|
|
dd.l = pCurve->l[i];
|
|
|
|
if (i == m_index)
|
|
{
|
|
nodeAdded = dd;
|
|
continue;
|
|
}
|
|
|
|
ptList.AddTail(dd);
|
|
}
|
|
|
|
pCurve->SetPoints(ptList, pCurve->nPoint, pCurve->bAutoLocation);
|
|
}
|
|
|
|
void CActionCurveEditAddPoint::Redo()
|
|
{
|
|
CCurveEx * pCurve = CActionCurveEditAddPoint::GetCurve();
|
|
if (pCurve == 0)
|
|
return;
|
|
|
|
if (m_index < 0 || m_index >= pCurve->num)
|
|
return;
|
|
|
|
CPointList ptList;
|
|
dfPoint dd;
|
|
for (int i = 0; i < pCurve->num; i++)
|
|
{
|
|
dd.x0 = pCurve->x[i];
|
|
dd.y0 = pCurve->y[i];
|
|
dd.z0 = pCurve->z[i];
|
|
dd.l = pCurve->l[i];
|
|
|
|
if (i == m_index)
|
|
{
|
|
ptList.AddTail(nodeAdded);
|
|
}
|
|
|
|
ptList.AddTail(dd);
|
|
}
|
|
|
|
pCurve->SetPoints(ptList, pCurve->nPoint, pCurve->bAutoLocation);
|
|
}
|
|
|
|
void CActionCurveEditAddPoint::SetIndexOfNodeAdded(int index)
|
|
{
|
|
m_index = index;
|
|
}
|
|
|
|
void CActionCurveEditAddPoint::accept(CActionVisitor& visitor)
|
|
{
|
|
visitor.visit(*this);
|
|
}
|
|
|
|
CCurveEx * CActionCurveEditAddPoint::GetCurve()
|
|
{
|
|
COne * pOne = GetDoc()->GetDraw()->GetAt(m_posOfCurve);
|
|
if (pOne == 0)
|
|
return 0;
|
|
|
|
if (pOne->GetType() != DOUBLEFOX_CURVE)
|
|
return 0;
|
|
|
|
CCurveEx * pCurve = (CCurveEx*)GetDoc()->GetDraw()->GetAtValue(m_posOfCurve);
|
|
return pCurve;
|
|
}
|
|
} |