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.

102 lines
2.6 KiB
C++

#pragma once
#include "Item.h"
#include "CurveNodeDrawer.h"
#include "IntersectionEraser.h"
#include "DrawOperator/RTree.h"
class CItemEraser : public CItem
{
public:
CItemEraser(CSigmaDoc* ppDoc);
~CItemEraser();
void OnLButtonDblClk(UINT nFlags, CPoint point) override;
void OnLButtonDown(CDC *pDC, UINT nFlags, CPoint point, int vk) override;
void OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point, int vk) override;
void OnRButtonDown(UINT nFlags, CPoint point) override;
BOOL OnRButtonUp(UINT nFlags, CPoint point) override;
void OnMouseWheel(uint32_t button, int32_t clicks, int32_t x, int32_t y, int32_t delta) override;
int OnMouseMove(CDC* pDC, UINT nFlags, CPoint point) override;
void DrawAssistant(CDC* pDC, int mouseX, int mouseY) override;//图件屏幕重绘后,重绘临时线
BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) override;
BOOL OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) override;
void OnDraw(CXyDC* pXyDC, CDC* pDC) override;
void OnCancel(void) override;
EraserMode GetEraserMode() const;
void SetEraserMode(EraserMode mode);
int GetEraserRadius() const;
void SetEraserRadius(int radius);
private:
std::vector<CPoint> GetScreenPoints(const std::vector<CPoint2D>& points) const;
void ZoomEraseRadius(int radius);
void DrawCircle(CDC* pDC, int centerX, int centerY, int radius);
/**
* 绘制橡皮擦
*
* \param dc CDC 对象
* \param centerX 橡皮擦中心位置 X 坐标
* \param centerY 橡皮擦中心位置 X 坐标
* \param radius
*/
void DrawEraser(CDC* pDC, int centerX, int centerY, int radius);
/**
* 绘制曲线上的节点,方便用户操作
*
* \param dc
*/
void DrawCurveNode(CDC* pDC);
int m_lastX = -1;
int m_lastY = -1;
int m_lastRadius = -1;
void ResetLast(int x, int y, int radius);
static constexpr int ZOOM_VALUE = 10;
static constexpr int MIN_ERASE_RADIUS = 10;
static constexpr int MAX_ERASE_RADIUS = 40;
// 右键点击去除曲线点时的最大搜索范围,在这个范围内我们就认为被点中了
static constexpr double MAX_SEARCH_RADIUS = 2;
RTree<POSITION, double, 2>* GetSpatialTree();
/**
* 获取橡皮擦路径
*
* \return
*/
std::unique_ptr<CCurveEx> GetEraserPath() const;
void SetAction(const CPositionList& plAdd, const CPositionList& plDel);
void Erase();
void Redraw();
const CString redraw = "redraw";
bool m_start = false;
std::vector<CPoint2D> m_path;
COLORREF m_penColor = RGB(255, 0, 0);
int m_eraseRadius = 10; // 删除半径
EraserMode m_mode = EraserMode::Nodes;
std::unique_ptr<CurveNodeDrawer> m_nodeDrawer;
std::optional<std::pair<CRect, CRect8>> m_lastView;
std::unique_ptr<RTree<POSITION, double, 2>> m_rtree;
bool isViewChanged = true;
size_t m_token = 0;
};