摘 要 该文介绍了一种建立在DOS界面下生成图素文件的通用图形编辑程序的设计方法。
目前用作DDC的PC总线工控机(IPC)大部分工作在DOS界面上,而DOS不具有像Windows那样美观方便的图形用户接口(GUI)。生成工艺流程图等复杂图形若用程序设计语言直接编程需花费大量精力和代码,且不易修改。设计出数据文件小,占用内存少的图形编辑软件是控制界的一个研究课题。这里介绍一种生成图素数据文件的通用图形编辑软件的设计方法。
一、数据结构与数据文件格式
由于所有的操作都基本建立在图素的基础之上,故数据结构也以图素为中心。以下以圆、直线、矩形、字符串为例,其它图素类似。
1.定义所需图素
struct circle /*定义圆 */
{
int x,y,r; /* 圆心,半径 */
char linecolor,linestyle; /* 圆外围线的颜色,线型 */
char fillcolor,fillstyle; /* 填充颜色,模式 */
};
struct line /* 定义直线 */
{
int x1,y1;
int x2,y2;
char linecolor,linestyle,linethick; /* 线颜色,模式,粗细 */
};
struct box /* 定义矩形 */
{
int x1,y1;
int x2,y2;
char linecolor,linestyle;
char fillcolor,fillstyle;
};
struct string /* 定义字符串 */
{
int x,y;
char str[10]
char backcolor,dir;
char str-color,str-style;
};
.
. /* 定义其它图素 */
.
2.将各图素置于一条链表之中
typedef struct tagElementList
{
char ElementType; /* 标识元素类别 */
int ElementID; /* 元素标识符,在接口中用来控制其属性 */
union tagElement {
struct circle circle;
struct box box;
struct string string;
struct line line;
.
. /* 可在此说明其它元素 */
.
}Element;
struct tagElementList *next;
}ElementList;
利用这种数据结构可在内存中形成一个图素链表,所有操作都可以此链表为基础。
3.定义几个指针,以备各种操作
ElementList *List-head. *List-end,*List-temp, *List-here;
4.定义一个全局变量,记录图素个[1] [2] [3] [4] 下一页
|