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/ActionCurveEditDeletePoint.cpp

100 lines
1.8 KiB
C++

#pragma once
#include "stdafx.h"
#include "ActionCurveEditDeletePoint.h"
#include "SigmaDoc.h"
#include "Visitor.h"
namespace NAction
{
CActionCurveEditDeletePoint::CActionCurveEditDeletePoint()
: CActionItem(nullptr, 0)
{
}
CActionCurveEditDeletePoint::CActionCurveEditDeletePoint(CSigmaDoc * pDoc, UINT actionType, POSITION pos)
:CActionItem(pDoc, actionType),
m_posOfCurve(pos),
m_index(-1)
{
}
void CActionCurveEditDeletePoint::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)
{
ptList.AddTail(nodeAdded);
}
ptList.AddTail(dd);
}
pCurve->SetPoints(ptList, pCurve->nPoint, pCurve->bAutoLocation);
}
void CActionCurveEditDeletePoint::Redo()
{
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)
continue;
ptList.AddTail(dd);
}
pCurve->SetPoints(ptList, pCurve->nPoint, pCurve->bAutoLocation);
}
void CActionCurveEditDeletePoint::SetNodeDeleted(dfPoint & node, int index)
{
nodeAdded = node;
m_index = index;
}
void CActionCurveEditDeletePoint::accept(CActionVisitor& visitor)
{
visitor.visit(*this);
}
CCurveEx * CActionCurveEditDeletePoint::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;
}
}