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.

130 lines
3.6 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.

//////////////////////////////////////////////////////////////////////////////
//文件: CItem类扩展
//主要功能:
// 操作各类元素或完成一定的功能
//
//程序编写: 2006-12-07
//
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include "item.h"
#include "SpatialIndex.h"
namespace NItem
{
#define PEN_COLOR RGB(255,0,0)
#define CURVE_STATE_LINE 0
#define CURVE_STATE_ARC 1
#define CURVE_STATE_ANGLE 2
#define CURVE_STATE_SPLINE 3
#define CURVE_STATE_MERGE 4 //合并坐标功能
#define CURVE_STATE_DRAWING 5
class CItemCurve :
public CItem
{
public:
CItemCurve(CSigmaDoc * ppDoc);
virtual ~CItemCurve(void);
BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) override;
void OnLButtonDblClk(UINT nFlags, CPoint point) override;
void OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk) override;
void RemoveAssistantLineTailPoint();
int OnMouseMove(CDC* pDC, UINT nFlags, CPoint point) override;
void DrawAssistant(CDC * pScreenDC, int mouseX, int mouseY) override;//图件屏幕重绘后,重绘临时线
void OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point, int vk) override;
BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) override;
BOOL OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) override;
virtual void OnDraw(CXyDC* pXyDC, CDC* pDC) override;
int GetSubMenu() override;
virtual void SetCurveState(int state, CDC * pDC);
void RestoreCurveState(void);
dfPoint GetRealPoint(CPointList& pl, UINT nFlags, CPoint point);
static int PopupNameDialog(CXy* pxy, POSITION pos);
void Reset(void);
virtual void OnCancel(void) override;
bool GetAngleAndDistance(double &angle, double &distance) const;
protected:
class REDO_ITEM
{
public:
REDO_ITEM(void)
{
num=1;
bHead=FALSE;
pos=NULL;
};
dfPoint point;
BOOL bHead; //FALSE为结尾Redo,TRUE为开始Redo
int num; //Redo的点个数
POSITION pos; //PointList中的位置NULL表示删除点否则表示增加点
};
CList<REDO_ITEM,REDO_ITEM> RedoList,UndoList;
CPen m_pen;
BOOL m_bStretchStart;
dfPoint CurPoint;
void GetAnglePoint(dfPoint &ddp, double angle);
private:
void storeAngleAndDistance(dfPoint& point1, dfPoint& point2);
void clearAngleAndDistance();
// 记录当前画线当前点和前一个点的角度
double m_angle = std::numeric_limits<double>::quiet_NaN();
// 记录当前画线当前点和前一个点的距离
double m_distance = std::numeric_limits<double>::quiet_NaN();
public:
int m_oldLineState;
int m_AddLineState;
CPointList PointList;
dfPoint m_dpLastMousePos;
BOOL m_bContinuePen;
BOOL m_bAuxiliaryCurveRedraw;//全图重绘,重画的临时线,包括橡皮筋线
virtual void AutoClose(void);
virtual void AddPoint(dfPoint point);
virtual POSITION AddPoint(dfPoint point, BOOL bHead);
virtual int RemoveAt(POSITION pos);
POSITION InsertPointWithPointDistance(double x, double y);
void AddPointFromCoordinate(double x, double y);
void Draw(CXyDC* pDC, CPointList& pl, COLORREF color);
void DrawAssistantCurve();
void DrawAssistantLineLastSegment();
void RemoveAssistantLineFirstPoint();
void DrawRubberLine();
void EraseRubberLine();
void EraseAuxiliaryLines(CDC * pScreenDC);
void EraseScreenLines();
void RedrawScreenLines();
virtual POSITION NextCurve(void);
virtual void Undo(void);
virtual void Redo(void);
virtual BOOL IsCanUndo(void);
virtual BOOL IsCanRedo(void);
void ClearRedoList(void);
BOOL IsLineState(void);
COne* CItemCurve::CreateOne();
double m_isSnapEnabled = true;
double m_snapRange = 20.0;
// 这里用指针是为了能够延迟构造 CSpatialIndex尽管我们目前仍然是构造函数里面构造的
// 后面会在 CXy 中统一构造空间索引,到时这个就不需要了
std::unique_ptr<CSpatialIndex> m_pSpatialIndex;
//void OnMouseMove(UINT nFlags, CPoint point);
};
};