📄 entity.h
字号:
#ifndef _ENTITY_H_
#define _ENTITY_H_
#include "base.h"
#define PICK_RADIUS 0.01 // 选取半径
#define ENTITY_NUM 9 // 图元的种类数
enum EEntityType // 图元的类型
{
etUnknow = 0,
etPoint = 1,
etLine = 2,
etRectangle = 3,
etCircle = 4,
etArc = 5,
etBspline = 6,
etEllipse = 7,
etText = 8
};
enum EDrawMode // 绘图模式
{
dmNormal = 0, // 正常状态
dmSelect = 1, // 选中状态
dmPrompt = 2, // 提示状态
dmDrag = 3, // 拖动状态
dmInvalid = 4 // 擦除状态
};
//////////////////////////
// define API function
//
void SetDrawEnvir(CDC* pDC, int drawMode, CPen* pPen);
class CEntity : public CObject
{
DECLARE_SERIAL(CEntity)
protected:
// 成员变量
int m_type; // 图元类型(EEntityType)
COLORREF m_color ; // 图元颜色
UINT m_lineStyle ; // 图元的线型
int m_lineWidth ; // 图元的线宽
public:
// 构造函数和析构函数
CEntity() ;
CEntity(const CEntity& entity);
~CEntity() {}
CEntity operator = (const CEntity& entity); // 重载等号
virtual CEntity* Copy() { return NULL; } // 指针拷贝
// 初始化成员变量值
virtual void Init();
// 返回图元的类型(EEntityType)
virtual int GetType() { return m_type; }
// 返回图元颜色
COLORREF GetColor() { return m_color; }
// 设置图元颜色
void SetColor(COLORREF color) { m_color = color; }
// 绘制图元对象
virtual void Draw(CDC * pDC, int drawMode = dmNormal ) {};
// 图元对象串行化(或称序列化)
virtual void Serialize(CArchive& ar) ;
};
////////////////////////////
// CLine 直线类定义
//
class CLine : public CEntity
{
DECLARE_SERIAL(CLine)
protected:
// 成员变量——起点和终点
Position m_begin , m_end ;
public:
// 构造函数和析构函数
CLine() ;
CLine(const CLine& line);
CLine(const Position& begin,const Position& end);
~CLine() ;
CLine& operator = (const CLine& line);
CEntity* Copy();
int GetType();
void Init();
// 返回起点值
Position GetBeginPos();
// 返回终点值
Position GetEndPos();
void Draw(CDC * pDC, int drawMode = dmNormal ) ;
void Serialize(CArchive& ar) ;
};
////////////////////////////
// CRectangle 矩形类定义
//
class CRectangle : public CEntity
{
DECLARE_SERIAL(CRectangle)
protected:
// 成员变量——左上角点和右下角点
Position m_LeftTop , m_RightBottom ;
public:
// 构造函数和析构函数
CRectangle() ;
CRectangle(const CRectangle& rect);
CRectangle(const Position& LeftTop,const Position& RightBottom);
~CRectangle() ;
CRectangle& operator = (const CRectangle& rect);
CEntity* Copy();
int GetType();
void Init();
// 返回左上角点的值
Position GetLeftTopPos();
// 返回右下角点的值
Position GetRightBottomPos();
void Draw(CDC * pDC, int drawMode = dmNormal ) ;
void Serialize(CArchive& ar) ;
};
/////////////////
// CCircle 圆类的定义
//
class CCircle : public CEntity
{
DECLARE_SERIAL(CCircle)
protected:
// 成员变量——圆心点和半径
Position m_center ;
double m_dRadius ;
public:
// 构造函数和析构函数
CCircle() ;
CCircle(const CCircle& circle);
CCircle(const Position& center,const double& radius);
CCircle(const Position& center,const Position& aroud);
~CCircle() ;
CEntity* Copy();
int GetType();
void Init();
// 返回圆心点
Position GetCenterPos();
// 返回半径
double GetRadius();
void Draw(CDC * pDC, int drawMode = dmNormal ) ;
void Serialize(CArchive& ar) ;
};
////////////////////////////
// CArc 圆弧类定义
//
class CArc : public CEntity
{
DECLARE_SERIAL(CArc)
protected:
// 成员变量——圆心点、起始点和终止点
Position m_center ;
Position m_begin ;
Position m_end ;
public:
// 构造函数和析构函数
CArc() ;
CArc(const CArc& arc);
CArc(const Position& center,const Position& startPos, const Position& endPos);
~CArc() ;
CEntity* Copy();
int GetType();
void Init();
Position GetStartPos();
Position GetEndPos();
Position GetCenterPos() ;
void Draw(CDC * pDC, int drawMode = dmNormal ) ;
void Serialize(CArchive& ar) ;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -