drawDoc.h
上传用户:y440e3
上传日期:2010-03-08
资源大小:200k
文件大小:15k
- // DrawDoc.h : interface of the CDrawDoc class
- //
- /////////////////////////////////////////////////////////////////////////////
- #if !defined(AFX_DrawDOC_H__0EFFC62E_8953_11D2_AE7B_444553540000__INCLUDED_)
- #define AFX_DrawDOC_H__0EFFC62E_8953_11D2_AE7B_444553540000__INCLUDED_
- #if _MSC_VER >= 1000
- #pragma once
- #endif // _MSC_VER >= 1000
- #define pi 3.1415926
- #include "data1ret.h"
- #include "data2set.h"
- #include "linkdataset.h"
- typedef struct //用来存储逆操作信息的结构
- {
- unsigned char Lb; //操作的类别
- long l_Start; //在外部文件中的位置
- int Index; //在删除和增加操作操作时是删除图形元素的数量
- }UndoStruct;
- typedef struct //用来存储层的信息的结构
- {
- char m_Name[21];//层的名称
- BOOL b_Display; //是否显示1-显示0-隐藏
- int reserved; //备用
- }LayerStruct;
- class CGraphPara //用来存储图形的基本参数的类
- {
- protected:
- int n_ColorNumbAll; //总的颜色数
- int n_LayerNumbAll; //总的图层数
- int n_ColorNumb; //系统当前具有的颜色数
- int n_LayerNumb; //系统当前具有的图层数
- long* m_ColorList; //用来存储颜色列表
- LayerStruct* m_LayerList;//用来存储层的列表
- public:
- CGraphPara()
- {
- n_ColorNumb=100; //最多具有100种颜色
- n_LayerNumb=100; //最多具有100层
- m_ColorList=new long[n_ColorNumb];
- m_LayerList=new LayerStruct[n_LayerNumb];
- n_ColorNumb=4; //目前有4种颜色
- n_LayerNumb=1; //目前有一层
- //以下初始化几种颜色和一个层
- m_ColorList[0]=RGB(0,0,0);
- m_ColorList[1]=RGB(255,0,0);
- m_ColorList[2]=RGB(0,255,0);
- m_ColorList[3]=RGB(0,0,255);
- m_LayerList[0].b_Display=1;
- strcpy(m_LayerList[0].m_Name,"Layer 0");
- }
-
- ~CGraphPara()
- {
- delete m_LayerList;
- delete m_ColorList;
- }
- public:
- COLORREF GetColor(int n); //得到第n种颜色的实际颜色
- BOOL GetDisplayStatue(int n); //得到第n层的显示状态
- };
- typedef struct
- {
- float x;
- float y;
- float z;
- }PointStruct;
- class CDraw:public CObject //基本图形类,用来存储图形的颜色、线型、层等信息
- {
- protected:
- CDraw(){} //构造函数
- short m_ColorPen; //笔色
- short m_ColorBrush; //填充刷颜色
- short m_LineWide; //线宽(像素)
- short m_LineType; //线型(像素)
- short m_Layer; //所处层
- int m_id_only; //图形元素唯一的识别号
- BOOL b_Delete; //是否处于删除状态
- // DECLARE_SERIAL(CDraw); //串形化
- public:
- CDraw(short ColorPen,short ColorBrush,short LineWide,
- short LineType,short Layer,int id_only,BOOL Delete)
- //构造函数
- {
- m_ColorPen=ColorPen;
- m_ColorBrush=ColorBrush;
- m_LineWide=LineWide;
- m_LineType=LineType;
- m_Layer=Layer;
- b_Delete=Delete;
- m_id_only=id_only;
- }
- //计算点到直线的距离的函数
- float PointLine(float xx,float yy,float x1,float y1,float x2,float y2);
- //判断点是否在一个多边形区域中的函数
- BOOL PointRgn(float x,float y,int Numble,PointStruct *PointList,float blc);
- BOOL IsDelete(); //判断一个图形元素是否删除的函数
- float CalDisp(float x1,float y1,float x2,float y2);//计算两点间的距离的函数
- void Delete(BOOL Is); //删除或恢复删除图形元素的函数
- //从一个文件中存储或读出图形坐标数据的函数
- virtual void Save(CFile* file,BOOL Yn);
- virtual void Serialize(CArchive& ar); //文档串形化函数
- void toChar(char *p_Char);
- char *toData(char *p_Char);
- virtual void Draw(CDC *pDC,int m_DrawMode,int m_DrawMode1,short BackColor)=0;
- int GetID();
- // int ArcRgn(float x,float y,float r,float angl1,float angl2,int nPoint,PointStruct* Pointxy,int *nCross,PointStruct *Pointxy1);
- float GetAngle(float x,float y,float xx,float yy);
- // int ArcLine(float x,float y,float r,float *angl1,float *angl2,float *X1,float *Y1,float *X2,float *Y2);
- // int CircleLine(float x,float y,float r,float *X1,float *Y1,float *X2,float *Y2);
- // int PLineRgn(int nPoint1,PointStruct* Pointxy1,int nPoint2,PointStruct* Pointxy2,int *nCross,PointStruct* Pointxy3);
- // int CircleCircle(CCircle* cir1,CCircle* cir2,float *angl1,float *angl2);
- // int ArcCircle(CArc* arc1,CCircle* cir2,int *nCross,PointStruct* Pointxy1);
- }
- ;
- class CLine:public CDraw //直线类
- {
- protected:
- DECLARE_SERIAL(CLine); //声明串形化
- public:
- float m_X1,m_X2,m_Y1,m_Y2; //直线的起点和终点
- CLine(){} //不带任何参数的构造函数
- //以下是有初始化参数的构造函数
- CLine(short ColorPen,short ColorBrush,
- short LineWide,short LineType,short Layer,int id_only,
- BOOL Delete,float X1,float Y1,float X2,float Y2)
- :CDraw(ColorPen,ColorBrush,LineWide,LineType,Layer,id_only,Delete)
- {
- m_X1=X1;
- m_Y1=Y1;
- m_X2=X2;
- m_Y2=Y2;
- }
- //直线的绘制函数
- virtual void Draw(CDC *pDC,int m_DrawMode,int m_DrawMode1,short BackColor);
- //得到边界矩形的函数
- void GetRect(float *minX,float *minY,float *maxX,float *maxY);
- BOOL IsPoint(float x,float y,float jl); //判断是否被点选中的函数
- virtual void Serialize(CArchive& ar); //串形化函数
- //从剪裁板中读出或写入剪裁板的函数
- void Save(CFile* file,BOOL Yn);
- void toChar(char *p_Char);
- char *toData(char *p_Char);
- void Move(float x_Move,float y_Move);
- int LineLine(CLine* line1,float *xxx1,float *yyy1,float *xxx2,float *yyy2);
- };
- class CCircle:public CDraw //圆及圆形区域类
- {
- protected:
- DECLARE_SERIAL(CCircle);
- public:
- float m_CircleX,m_CircleY,m_CircleR; //圆心及半径
- BOOL b_Fill; //是否填充 1-圆形区域 0-普通圆
- CCircle() //不带任何参数的构造函数
- {}
- CCircle(short ColorPen,short ColorBrush,
- short LineWide,short LineType,short Layer,int id_only,
- BOOL Delete,float CircleX,float CircleY,float CircleR,BOOL Fill)
- :CDraw(ColorPen,ColorBrush,LineWide,LineType,Layer,id_only,Delete)
- {
- m_CircleX=CircleX;
- m_CircleY=CircleY;
- m_CircleR=CircleR;
- b_Fill=Fill;
- }
- virtual void Draw(CDC *pDC,int m_DrawMode,int m_DrawMode1,short BackColor);
- void GetRect(float *minX,float *minY,float *maxX,float *maxY);
- virtual IsPoint(float x,float y,float jl);
- BOOL IsCircle();
- virtual void Save(CFile* file,BOOL Yn);
- virtual void Serialize(CArchive& ar);
- void toChar(char *p_Char);
- char *toData(char *p_Char);
- void Move(float x_Move,float y_Move);
- int CircleLine(CLine* line1,float *angle1,float *angle2,float *X1, float *Y1, float *X2, float *Y2);
- int CircleCircle(CCircle* cir1,float *angl1,float *angl2);
- };
- class CArc:public CCircle //圆弧类
- {
- protected:
- DECLARE_SERIAL(CArc);
- public:
- float m_Angle1,m_Angle2; //圆弧的起点和终点角度
- CArc() //不带任何参数的构造函数
- {}
- CArc(short ColorPen,short ColorBrush,short LineWide
- ,short LineType,short Layer,int id_only,BOOL Delete,float CircleX
- ,float CircleY,float CircleR,BOOL Fill,float Angle1,float Angle2)
- :CCircle(ColorPen,ColorBrush,LineWide,LineType,Layer,Delete,id_only,CircleX,
- CircleY,CircleR,Fill)
- {
- m_Angle1=Angle1;
- m_Angle2=Angle2;
- }
- virtual void Draw(CDC *pDC,int m_DrawMode,int m_DrawMode1,short BackColor);
- void Init(short ColorPen,short ColorBrush,short LineWide,short LineType,short Layer,float CircleX,float CircleY,float CircleR,BOOL Fill,float Angle1,float Angle2);
- void GetRect(float *minX,float *minY,float *maxX,float *maxY);
- virtual BOOL IsPoint(float x,float y,float jl);
- BOOL IsInArc(float angle);
- void Save(CFile* file,BOOL Yn);
- virtual void Serialize(CArchive& ar);
- void toChar(char *p_Char);
- char *toData(char *p_Char);
- int ArcLine(CLine *line1, float *angle1, float *angle2, float *X1, float *Y1, float *X2, float *Y2);
- int ArcCircle(CCircle* cir1,int *nCross,PointStruct* Pointxy1);
- };
- class CPline:public CDraw //连续直线或多边形区域类
- {
- protected:
- int m_Numble; //连续直线或多边形区域的顶点数
- BOOL b_Fill; //是否为连续直线
- DECLARE_SERIAL(CPline); //声明串形化
- ;
- public:
- PointStruct* m_PointList; //存储顶点的数组指针
- CPline() //不带任何参数的构造函数
- { m_Numble=0;}
- CPline(short ColorPen,short ColorBrush,
- short LineWide,short LineType,short Layer,int id_only,
- BOOL Delete,int Numble,PointStruct* PointList,BOOL Fill)
- :CDraw(ColorPen,ColorBrush,LineWide,LineType,Layer,id_only,Delete)
- {
- m_Numble=Numble;
- b_Fill=Fill;
- m_PointList=new PointStruct[Numble+1]; //分配空间
- if(Numble>0)
- {
- for(int i=0;i<Numble;i++)
- m_PointList[i]=PointList[i];
- }
- }
- ~CPline() //析够函数
- {
- if(m_Numble>0)
- delete m_PointList;
- }
- virtual void Draw(CDC *pDC,int m_DrawMode,int m_DrawMode1,short BackColor);
- void GetRect(float *minX,float *minY,float *maxX,float *maxY);
- BOOL IsPoint(float x,float y,float jl,float blc);
- BOOL IsPLine();
- void Save(CFile* file,BOOL Yn);
- virtual void Serialize(CArchive& ar);
- void toChar(char *p_Char);
- char *toData(char *p_Char);
- int GetNumb();
- void Move(float x_Move,float y_Move);
- int LineRgn(CLine* line1,int *nCross,PointStruct* Pointxy1);
- int PLineRgn(CPline* pline1,int *nCross,PointStruct* Pointxy1);
- int ArcRgn(CArc* arc1,int *nCross,PointStruct *Pointxy1);
- };
- class CText:public CDraw //标注文本类
- {
- protected:
- float m_StartX; //文本起点横坐标
- float m_StartY; //起点纵坐标
- float m_Angle1; //标注角度
- float m_Angle2; //字体旋转角度
- float m_TextHeight; //字体高度
- float m_TextWide; //字体宽度
- float m_OffWide; //间隔宽度
- unsigned char m_TextFont; //字体
- CString c_Text; //标注的文本信息
- int m_TextLong; //标注信息的长度
- DECLARE_SERIAL(CText);
- public:
- CText() //不带任何参数的构造函数
- {}
- CText(short ColorPen,short ColorBrush,short LineWide
- ,short LineType,short Layer,int id_only,BOOL Delete,float StartX,
- float StartY,float Angle1,float Angle2,float TextHeight,float TextWide,
- float OffWide,unsigned char TextFont,CString Text)
- :CDraw(ColorPen,ColorBrush,LineWide,LineType,Layer,id_only,Delete)
- {
- m_StartX=StartX;
- m_StartY=StartY;
- m_Angle1=Angle1;
- m_Angle2=Angle2;
- m_TextHeight=TextHeight;
- m_TextWide=TextWide;
- m_OffWide=OffWide;
- m_TextLong=Text.GetLength(); //计算字符的长度
- c_Text=Text;
- }
- virtual void Draw(CDC *pDC,int m_DrawMode,int m_DrawMode1,short BackColor);
- void Init(short ColorPen,short ColorBrush,short LineWide,short LineType,short Layer,float StartX,float StartY,float Angle1,float Angle2,float TextHeight,float TextWide,float OffWide,unsigned char TextFont,CString Text);
- void GetRect(float *minX,float *minY,float *maxX,float *maxY);
- BOOL IsPoint(float x,float y,float jl,float blc);
- void Save(CFile* file,BOOL Yn);
- virtual void Serialize(CArchive& ar);
- void toChar(char *p_Char);
- char *toData(char *p_Char);
- int GetLong();
- void Move(float x_Move,float y_Move);
- };
- typedef struct
- {
- short int Lb; //类别 1-直线 2-连续直线或多边形区域 3-圆 4-圆弧 5-文本
- short int Index; //序号
- short int pbh; //判别号
- }GraphSelectStruct; //用来存储选中图形元素的结构
- typedef struct
- {
- short only_ID;
- char Name[20];
- } DataInfoStru;
- typedef struct //用来记录历史屏幕参数的结构
- {
- float blc; //比例尺
- float sx; //屏幕左下角的横坐标
- float sy; //屏幕左下角的纵坐标
- }ScreenStruct;
- class CDrawDoc : public COleDocument
- {
- protected: // create from serialization only
- CDrawDoc();
- DECLARE_DYNCREATE(CDrawDoc)
-
- private:
- CTypedPtrArray<CObArray,CLine*>m_LineArray; //管理直线对象指针的对象
- CTypedPtrArray<CObArray,CPline*>m_PLineArray; //管理连续直线对象指针的对象
- CTypedPtrArray<CObArray,CCircle*>m_CircleArray;//管理圆对象指针的对象
- CTypedPtrArray<CObArray,CArc*>m_ArcArray; //管理圆弧对象指针的对象
- CTypedPtrArray<CObArray,CText*>m_TextArray; //管理标注文字对象指针的对象
- // Attributes
- public:
- BOOL b_IsOleSelect; //是否选中了OLE对象
- CGraphPara m_GraphPara; //定义一个管理图形参数的对象
- GraphSelectStruct *GraphSelect; //存储选中元素的性质
- int n_GraphSelect; //选中图形元素的数目
- int m_CurrentScreen; //当前屏幕的序号
- int m_MaxScreen; //最多能够有的屏幕数
- ScreenStruct* m_Screen; //记录屏幕参数的结构指针
- CLine* line1;
- Data1Set m_data1;
- CData2Set m_data2;
- CLinkDataSet m_linkdata1;
- int *m_Index;
- DataInfoStru DataInfo[30];
- short m_NumbData;
- protected:
- CString FilePath,FileName; //存储逆操作文档的路径和文件名
- CFile Fundo; //用来存储逆操作信息的文件指针
- UndoStruct* m_UndoList; //存储逆操作的索引信息
- int n_CurUnIndex,n_MaxUnIndex; //当前处于操作的次数和总的操作次数
- UINT DrawFormat;
- // Operations
- public:
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CDrawDoc)
- public:
- virtual BOOL OnNewDocument(); //建立新文档时调用
- virtual void Serialize(CArchive& ar); //串形化函数
- virtual void DeleteContents(); //删除文档时调用
- virtual void OnCloseDocument(); //关闭文档时调用
- virtual BOOL OnOpenDocument(LPCTSTR lpszPathName); //打开文档时调用
- virtual BOOL OnSaveDocument(LPCTSTR lpszPathName); //保存文档时调用
- //}}AFX_VIRTUAL
- // Implementation
- public:
- void Draw(CDC *pDC,int m_DrawMode,int m_DrawMode1,short BackColor);
- void DrawGraph(CDC* pDC,int Lb,int Index,int Mode,int Mode1,short BackColor);
- void OnEditUndo(); //逆操作函数
- int GetMaxIndex(int Lb);//得到各类图形元素顶最大索引号
- //以下两个重载函数用来记录一步操作
- BOOL AddUndo(int Lb,int Numble,GraphSelectStruct* GraphList);
- BOOL AddUndo(float sx,float sy,float blc);
- BOOL WriteClipBoard(); //将图形元素写入剪裁板
- BOOL ReadClipBoard(float x,float y);
- BOOL AddSelectList(int Lb,int Index,int Pbh); //增加一个选中的图形元素
- //得到所有图形元素的边界按矩形
- BOOL GetRect(float *m_Xmin,float *m_Ymin,float *m_Xmax,float *m_Ymax);
- //进行选中图形元素的操作
- BOOL PointSelect(float x,float y,float jl,float blc,int *Lb,int *Index,int *pbh);
- CLine* AddLine(short ColorPen,short ColorBrush,short
- LineWide,short LineType,short Layer,int id_only,float X1,float Y1,
- float X2,float Y2); //增加一条直线
- CLine* AddLine(); //增加一条直线
- CLine* GetLine(int Index); //得到第Index条直线
- int GetNumbLines(); //得到直线的数目
- CPline* AddPLine(short ColorPen,short ColorBrush,
- short LineWide,short LineType,short Layer,int id_only,int Numble,
- PointStruct* PointList,BOOL b_Fill);
- CPline* AddPLine();
- CPline* GetPLine(int Index);
- int GetNumbPLines();
- CCircle* AddCircle(short ColorPen,short ColorBrush,
- short LineWide,short LineType,short Layer,int id_only,
- float CircleX,float CircleY,float CircleR,BOOL Fill);
- CCircle* AddCircle();
- CCircle* GetCircle(int Index);
- int GetNumbCircles();
- CArc* AddArc(short ColorPen,short ColorBrush,short
- LineWide,short LineType,short Layer,int id_only,float CircleX,
- float CircleY,float CircleR,BOOL Fill,float Angle1,float Angle2);
- CArc* AddArc();
- CArc* GetArc(int Index);
- int GetNumbArcs();
- CText* AddText(short ColorPen,short ColorBrush,short
- LineWide,short LineType,short Layer,int id_only,float StartX,
- float StartY,float Angle1,float Angle2,float TextHeight,float TextWide,
- float OffWide,unsigned char TextFont,int TextLong,CString);
- CText* AddText();
- void AddScreen(float StartX,float StartY,float blc);//增加一个图形屏幕
- CText* GetText(int Index);
- int GetNumbTexts();
- int GetLineId();
- int GetPLineId();
- int GetCircleId();
- int GetArcId();
- int GetTextId();
- CDataBaseSet *GetDataSet(int Index);
- short GetDataID(int Index);
- short GetDataIndex(int ID);
- virtual ~CDrawDoc();
- #ifdef _DEBUG
- virtual void AssertValid() const;
- virtual void Dump(CDumpContext& dc) const;
- #endif
- protected:
- // Generated message map functions
- protected:
- //{{AFX_MSG(CDrawDoc)
- afx_msg void OnUpdateSelectClear(CCmdUI* pCmdUI);//是否能够执行"放弃选择“
- afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI); //是否能够执行"Undo"菜单
- afx_msg void OnTest();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- /////////////////////////////////////////////////////////////////////////////
- //{{AFX_INSERT_LOCATION}}
- // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
- #endif // !defined(AFX_DrawDOC_H__0EFFC62E_8953_11D2_AE7B_444553540000__INCLUDED_)