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.

328 lines
6.8 KiB
C++

1 month ago
#include "StdAfx.h"
#include ".\itemcurveedit.h"
#include "SigmaDoc.h"
#include "SigmaView.h"
#include ".\actionmodifieditem.h"
#include "ActionBackupItem.h"
#include "DrawOperator/TypeDefine.h"
#include "ActionCurveEdit.h"
#include "ActionCurveEditAddPoint.h"
#include "ActionCurveEditDeletePoint.h"
#include "HandleDrawer.h"
1 month ago
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<C4B1><E0BCAD>ʵ<EFBFBD><CAB5>
#include "CurveEditorDefault.h"
#include "CurveEditorLinear.h"
#include "CurveEditorCosine.h"
#include "CurveEditorSpline.h"
1 month ago
namespace NItem
{
#define TRACKER_SOLID 1
#define TRACKER_RECT 2
#define TRACKER_CIRCLE 4
#define TRACKER_NO_EDIT TRACKER_SOLID | TRACKER_CIRCLE
1 month ago
// ========== <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5> ==========
1 month ago
CItemCurveEdit::CItemCurveEdit(CSigmaDoc* pDoc)
: CItemCurve(pDoc)
1 month ago
, m_pDoc(pDoc)
1 month ago
{
this->SetType(ITEM_CURVE_EDIT);
1 month ago
// Ĭ<><C4AC>ʹ<EFBFBD><CAB9> Default ģʽ<C4A3><EFBFBD><E0BCAD>
m_currentEditor = CreateEditor(DRAG_NODE_DEFAULT);
1 month ago
}
CItemCurveEdit::~CItemCurveEdit(void)
{
}
1 month ago
int CItemCurveEdit::GetCurrentEditMode() const
1 month ago
{
1 month ago
if (std::dynamic_pointer_cast<CurveEditorDefault>(m_currentEditor))
1 month ago
{
1 month ago
return DRAG_NODE_DEFAULT;
1 month ago
}
1 month ago
if (std::dynamic_pointer_cast<CurveEditorLinear>(m_currentEditor))
1 month ago
{
1 month ago
return DRAG_NODE_LINE;
1 month ago
}
1 month ago
if (std::dynamic_pointer_cast<CurveEditorCosine>(m_currentEditor))
1 month ago
{
1 month ago
return DRAG_NODE_COS;
1 month ago
}
1 month ago
if (std::dynamic_pointer_cast<CurveEditorSpline>(m_currentEditor))
1 month ago
{
1 month ago
return DRAG_NODE_SPLINE;
1 month ago
}
1 month ago
return -1;
1 month ago
}
1 month ago
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0BCAD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
std::shared_ptr<CurveEditorBase> CItemCurveEdit::CreateEditor(int mode)
1 month ago
{
1 month ago
switch (mode)
1 month ago
{
1 month ago
case DRAG_NODE_DEFAULT:
return std::make_shared<CurveEditorDefault>(m_pDoc);
case DRAG_NODE_LINE:
return std::make_shared<CurveEditorLinear>(m_pDoc);
case DRAG_NODE_COS:
return std::make_shared<CurveEditorCosine>(m_pDoc);
1 month ago
case DRAG_NODE_SPLINE:
1 month ago
return std::make_shared<CurveEditorSpline>(m_pDoc);
default:
return std::make_shared<CurveEditorDefault>(m_pDoc);
1 month ago
}
}
1 month ago
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>л<EFBFBD><D0BB><EFBFBD><E0BCAD>
void CItemCurveEdit::SetCurveState(int state, CDC* pDC)
1 month ago
{
1 month ago
// <20><><EFBFBD><EFBFBD>״̬ӳ<CCAC><EFBFBD>༭ģʽ
int mode = DRAG_NODE_DEFAULT;
switch (state)
1 month ago
{
1 month ago
case CURVE_STATE_LINE:
mode = DRAG_NODE_DEFAULT;
1 month ago
break;
1 month ago
case CURVE_STATE_ARC:
mode = DRAG_NODE_COS;
1 month ago
break;
1 month ago
case CURVE_STATE_SPLINE:
mode = DRAG_NODE_SPLINE;
break;
default:
// WARNING:
// <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>Ϊ DRAG_NODE_DEFAULT
// ԭ<><D4AD>: state <20><>ģʽ<C4A3>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>ڴ˴<DAB4><CBB4>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ı༭״̬
1 month ago
return;
1 month ago
}
1 month ago
1 month ago
SwitchEditMode(mode);
CItemCurve::SetCurveState(state, pDC);
1 month ago
}
1 month ago
// <20><>ʽ<EFBFBD>л<EFBFBD><D0BB>༭ģʽ
void CItemCurveEdit::SwitchEditMode(int mode)
1 month ago
{
1 month ago
// ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>
// 1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0B4A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>״̬ͬ<CCAC><CDAC> Bug <20><><EFBFBD>µĵ<C2B5><C4B5><EFBFBD>ʱ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>仯ʱ<E4BBAF><CAB1><EFBFBD>ٲ<EFBFBD><D9B2>ؽ<EFBFBD> Editor<6F><72>
// 3. ״̬<D7B4><CCAC><EFBFBD><EFBFBD><EBA3BA><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ģʽʱ<CABD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><CDB8><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>±꣨HandleIndex<65><78><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>ģʽ<C4A3>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ұ<EFBFBD>ȫ<EFBFBD><C8AB>
if (GetCurrentEditMode() == mode)
1 month ago
{
return;
}
1 month ago
// <20><><EFBFBD>浱ǰ״̬
POSITION oldPos = GetPos();
// <20><><EFBFBD><EFBFBD><EFBFBD>±༭<C2B1><E0BCAD>
m_currentEditor = CreateEditor(mode);
// ͬ<><CDAC>״̬
if (oldPos && m_currentEditor)
1 month ago
{
1 month ago
m_currentEditor->SetPos(oldPos);
1 month ago
}
}
1 month ago
// ========== <20><><EFBFBD>з<EFBFBD><D0B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD> m_currentEditor ==========
1 month ago
1 month ago
void CItemCurveEdit::OnDraw(CXyDC* pDC)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->OnDraw(pDC);
1 month ago
}
1 month ago
void CItemCurveEdit::OnLButtonDblClk(UINT nFlags, CPoint point)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->OnLButtonDblClk(nFlags, point);
1 month ago
}
1 month ago
void CItemCurveEdit::OnLButtonDown(CDC* pDC, UINT nFlags, CPoint point, int vk)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->OnLButtonDown(pDC, nFlags, point, vk);
1 month ago
}
1 month ago
int CItemCurveEdit::OnMouseMove(CDC* pDC, UINT nFlags, CPoint point)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->OnMouseMove(pDC, nFlags, point);
return 0;
1 month ago
}
1 month ago
void CItemCurveEdit::OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point, int vk)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->OnLButtonUp(pDC, nFlags, point, vk);
1 month ago
}
1 month ago
BOOL CItemCurveEdit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->OnSetCursor(pWnd, nHitTest, message);
return TRUE;
1 month ago
}
1 month ago
BOOL CItemCurveEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->OnKeyDown(nChar, nRepCnt, nFlags);
return FALSE;
1 month ago
}
1 month ago
BOOL CItemCurveEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->OnKeyUp(nChar, nRepCnt, nFlags);
return FALSE;
1 month ago
}
int CItemCurveEdit::GetSubMenu()
{
1 month ago
if (m_currentEditor)
return m_currentEditor->GetSubMenu();
1 month ago
return 6;
}
1 month ago
void CItemCurveEdit::SetPos(POSITION pos)
1 month ago
{
1 month ago
CItem::SetPos(pos);
if (m_currentEditor)
m_currentEditor->SetPos(pos);
1 month ago
}
1 month ago
void CItemCurveEdit::Clear(void)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->Clear();
1 month ago
}
1 month ago
void CItemCurveEdit::Draw(CDC* pDC)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->Draw(pDC);
1 month ago
}
1 month ago
void CItemCurveEdit::DrawAssistant(CDC* pDC, int mouseX, int mouseY)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->DrawAssistant(pDC, mouseX, mouseY);
1 month ago
}
1 month ago
int CItemCurveEdit::GetNumberOfNode()
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->GetNumberOfNode();
return -1;
1 month ago
}
1 month ago
void CItemCurveEdit::EreaseHandles(CDC* pDC)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->EreaseHandles(pDC);
1 month ago
}
1 month ago
void CItemCurveEdit::EndEdit(void)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->EndEdit();
1 month ago
}
void CItemCurveEdit::CancelAll(void)
{
1 month ago
if (m_currentEditor)
m_currentEditor->CancelAll();
1 month ago
}
1 month ago
BOOL CItemCurveEdit::IsCanCancelAll(void)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->IsCanCancelAll();
1 month ago
return FALSE;
}
int CItemCurveEdit::HitTestHandle(CPoint point)
{
1 month ago
if (m_currentEditor)
return m_currentEditor->HitTestHandle(point);
1 month ago
return -1;
}
1 month ago
void CItemCurveEdit::DeleteHandle(int nIndex)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->DeleteHandle(nIndex);
1 month ago
}
1 month ago
int CItemCurveEdit::AddHandle(CPoint point)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->AddHandle(point);
return -1;
1 month ago
}
1 month ago
CCurveEx* CItemCurveEdit::GetCurCurve(void)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->GetControlCurve();
return nullptr;
1 month ago
}
1 month ago
void CItemCurveEdit::AttachProcess(CPointList & oldPoints, CPointList & newPoints)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->AttachProcess(oldPoints, newPoints);
1 month ago
}
1 month ago
void CItemCurveEdit::DrawMoveLine(void)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->DrawMoveLine();
1 month ago
}
1 month ago
void CItemCurveEdit::GetMarkCurve(void)
1 month ago
{
1 month ago
if (m_currentEditor)
m_currentEditor->GetMarkCurve();
1 month ago
}
1 month ago
BOOL CItemCurveEdit::IsCanAddHandle(CPoint point, double* pl0)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->IsCanAddHandle(point, pl0);
return FALSE;
1 month ago
}
1 month ago
void CItemCurveEdit::GetXY(CCurveEx* pValue, int nIndex, dfPoint& point)
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->GetXY(pValue, nIndex, point);
1 month ago
}
1 month ago
CPoint2D CItemCurveEdit::GetCDown() const
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->GetCDown();
return CPoint2D{ 0.0, 0.0 };
1 month ago
}
1 month ago
CPoint2D CItemCurveEdit::GetCLast() const
1 month ago
{
1 month ago
if (m_currentEditor)
return m_currentEditor->GetCDown();
return CPoint2D{ 0.0, 0.0 };
1 month ago
}
1 month ago
}//namespace