返回列表 发帖
摘要
visual c++ 是运行于windows平台上的可视化集成开发环境,它是microsoft公司开发的microsoft visual studio 系列的一部分. visual c++ 集程序的界面设计.代码编辑.编译.连接和调试等功能于一体,为编程人员提供了一个方便而完整的开发界面和许多的有效的辅助开发工具.
在工程软件中,经常需要绘图表示工业现场的布置图,而且要求绘图软件能够将绘图元素的对象化,有利于修改.这个绘图软件就能够满足这要求,它是一个用于对象化的绘图软件,用于辅助客户完成常用图形的绘制.存储等操作的软件.
【关键字】 c++语言 序列化技术 crecttracker技术 对象实时编辑技术
visual c operates the visual integrated development environment on windows platform, it is a part of microsoft visual studio series which microsoft company develops . the interface that visual c collects the procedure is designed. code editor. compile. connect and debug function on an organic whole , offer one convenience intact development interface and a lot of effective assisting the developing instrument to programming personnel. in the project software , often need drawing to show the arrangement of the industrial scene is pursued , require mapping software can draw target of element, favorable to , fix. this mapping software can meet this requirement , it is that one is used in target mapping software, for assisting the customer to finish the drawing of the daily figure. the ones that store etc. and operate are soft
【key word】c++ the language  sequence turn the technique  crecttracker technique object solid hour edit a technique



目录
摘    要…………………………………………………………………………………………2
目    录…………………………………………………………………………………………3
1绘图软件的介绍……………………………………………………………………………….4  
1.1绘图软件的特色……………………………………………………………………….....4
1.2绘图元素对象化 …………………………………………………………………………..4
1.3图形对象的动态修改……………………………………………………………………...4
1.4存取操作…………………………………………………………………………………….4
1.5绘图软件的功能…………………………………………………………………………….4
2.系统设计与选型……………………………………………………………………………… 7
2.1 软件工具的选型………………………………………………………………………….. 7
2.2 visual c++6.0 编程环境简介…………………………………………………………….7
2.3 绘图软件模块分工设计…………………………………………………………………. 16
3. 绘图软件功能模块的创建…………………………………………………………………19 . 3.1 clne类记录直线信息……………………………………………………………………..19
3.2.carc类记录弧线信息……………………………………………………………………..22
3.3.cellipse类记录椭圆信息………………………………………………………………. 25
3.4.crectangle类记录矩形信息……………………………………………………………. 28
3.5.ctext类记录文本信息………………………………………………………………….. 32
3.6.clineproperties类显示和修改cline和carc类信息………………………………..33
3.7.cellpseproerties类显示和修改cellipse和crectangle类的信息………………. 37
3.8.ctextproperties类显示和修改ctext 类信息………………………………………..42
3.9.cmydrawview类实现绘图操作………………………………………………………….. 43
3.10.工具栏的设计…………………………………………………………………………… 44
3.11.绘制绘图元素…………………………………………………………………………… 47
3.12.选择绘图元素…………………………………………………………………………… 50
3.13.鼠标形态的自适应……………………………………………………………………… 53
3.14.显示绘图元素的属性…………………………………………………………………… 53
3.15.删除绘图元素…………………………………………………………………………… 55
3.16.cmydrawdoc类实现文档的存取操作…………………………………………………… 57
3.17.打开文档………………………………………………………………………………… 58
3.18.序列化…………………………………………………………………………………… 59
4.结束语………………………………………………………………………………………. 61
5.参考文献…………………………………………………………………… ……………….62




2.3绘图软件模块分工设计
利用visual c++6.0新建一个项目。项目名称为mydraw,项目类型为单文档。
整个项目中,包括以下13个类,如图
  
各类的分工如下
caboutdlg: 显示“关于”对话框。
carc:      弧线类,记录弧线的信息。
cellipse:  椭圆类,记录椭圆的信息。
cellipseproperties: 显示和修改椭圆.矩形属性。
cline :直线类,记录直线的信息。
clineproperties: 显示和修改直线.弧线属性。
cmainframe:    主框架类。
cddddapp:      应用程序类。
cdddddoc       文档类
cddddview      视图类
crectangle     矩形类,记录矩形的信息。
ctext:         文本类,记录文本的信息。
ctextproperties: 显示和修改文本的属性。
3. 绘图软件功能模块的创建
3.1 clne类记录直线信息
     cline类主要有俩大功能:定义直线对象的属性和实现直线对象的序列化
     cline类中,直线对象被定义了以下6个属性。
(0)bisselected: bool型, 指示直线是否处于选中状态。
startx:int型,直线的起点x坐标。
starty:int型,直线的起点y坐标。
endx:  int型,直线的终点x坐标。
endy:  int型,直线的终点y坐标。
linepen: logpen型,绘制直线采用的画笔。
cline类的头文件line.h文件的内容如下:
#if _msc_ver > 1000
#pragma once
#endif // _msc_ver > 1000

class cline:public cobject
{
//    declare_dynamic(cline)
    declare_serial(cline)
public:
        bool bisselected;
        int startx;
        int starty;
        int endx;
        int endy;

        logpen linepen;
        cline();
        virtual ~cline();
        here
        cfontdialog dlg(&m_font);
        if(dlg.domodal()==idok)
        {
                dlg.getcurrentfont(&m_font);
                m_textcolor=dlg.m_cf.rgbcolors;
        }
}
在调用ctextproperties类时会改变控件变量。成员变量的值,使他们能够反映文本参数。
同样,在对话框中修改参数后,会将修改后的结果保存在控件变量和成员变量中,通过读取控件变量和成员变量就可以得到修改后文本参数。
3.9.cmydrawview类实现绘图操作
为cmydrawview类添加俩个成员变量:
public:
cptrlist     m_objectlist
crecttracker m_tracker
其中m_objectlist存储了绘图对象的连表,成员变量m_tracker用于显示选中的绘图对象四周的调节框,通过该调节框还可以更改绘图对象的位置大小。
在cmydrawview类的构造函数cmydrawview()中,程序首先设m_tracker的风格是:在选择对象的内部显示调节框,并且在选择对象的四周显示虚线;然后设置m_tracker的位置和大小;最后设置m_tracker中调节点的大小,代码如下:

cmydrawview::cmydrawview()
{
                m_tracker.m_nstyle=crecttracker::resizeinside|
                crecttracker::dottedline;
        m_tracker.m_rect.setrect(0,0,0,0);
        m_tracker.m_nhandlesize=8;
}
3.10工具栏的设计
在resourceview中,双击toolbar中的idr_mainframe项,就会显示主页面中工具栏的编辑窗口,在其中添加5个工具栏按钮直线。椭圆。矩形。弧线 文本。
新添加的5个工具栏按钮的作用是向绘图对象的链表m_objectlist中添加直线 椭圆 矩形 弧线和文本等绘图元素。
添加5个工具栏按钮的响应函数, 代码如下:
void cmydrawview:nbuttonline()
{
        cline* pline=new cline;
        m_objectlist.addtail(pline);
        invalidate();
}

void cmydrawview:nbuttonellipse()
{
        cellipse* pellipse=new cellipse;
        m_objectlist.addtail(pellipse);
        invalidate();
}

void cmydrawview:nbuttonrectangle()
{
                crectangle* prectangle=new crectangle;
        m_objectlist.addtail(prectangle);
        invalidate();
}

void cmydrawview:nbuttonarc()
{
        carc* parc=new carc;
        srand(::gettickcount());
        if(rand()%10+1>5)//²úéúò»¸ö1µ½10µäëæ»úêý
                parc->direction=0;
        else
                parc->direction=1;
        m_objectlist.addtail(parc);
        invalidate();
}

void cmydrawview:nbuttontext()
{
        ctext* ptext=new ctext;
        m_objectlist.addtail(ptext);
        invalidate();
}
3.11.绘制绘图元素
cmydrawview类的ondraw函数用于完成绘图元素的绘制功能,
ondraw函数代码如下:
void cmydrawview:ndraw(cdc* pdc)
{
        cmydrawdoc* pdoc = getdocument();
        assert_valid(pdoc);
        position pos = m_objectlist.getheadposition();
        cellipse* pellipse = null;
        cline* pline=null;
        crectangle* prectangle=null;
        carc* parc=null;
        ctext* ptext=null;

        cobject* pobject=null;
       
        while(pos != null)
        {
                pobject=(cobject*)m_objectlist.getnext(pos);
                if (pobject->iskindof(runtime_class(cellipse)))
                {
                        pellipse = (cellipse*)pobject;
                        if(pellipse != null)
                        {
                                if (pellipse->bisselected)
                                {
                                        pellipse->startx=m_tracker.m_rect.left;
                                        pellipse->starty=m_tracker.m_rect.top;
                                        pellipse->endx=m_tracker.m_rect.right;
                                        pellipse->endy=m_tracker.m_rect.bottom;
                                }
                                drawellipse(pdc,pellipse);
                                if (pellipse->bisselected)
                                {
                                        m_tracker.draw(pdc);
                                }
                        }
                }省略绘制直线、弧线和文本代码
                else if (pobject->iskindof(runtime_class(crectangle)))
                {
                        prectangle = (crectangle*)pobject;
                        if(prectangle != null)
                        {
                                if (prectangle->bisselected)
                                {
                                        prectangle->startx=m_tracker.m_rect.left;
                                        prectangle->starty=m_tracker.m_rect.top;
                                        prectangle->endx=m_tracker.m_rect.right;
                                        prectangle->endy=m_tracker.m_rect.bottom;
                                }
                                drawrectangle(pdc,prectangle);
                                if (prectangle->bisselected)
                                {
                                        m_tracker.draw(pdc);
                                }
                        }
                }
        }
}
3.12选择绘图元素
cmydrawview类的onlbuttondown函数用于响应wm_lbuttondown消息,
wm_lbuttondown消息的响应代码如下:
void cmydrawview:nlbuttondown(uint nflags, cpoint point)
{
        cellipse* pellipse = null;
        cline* pline=null;
        crectangle* prectangle=null;
        carc* parc=null;
        ctext* ptext=null;
       
        position pos = m_objectlist.getheadposition();
        cobject* phititem;
        while(pos != null)
        {
                phititem=(cobject*)m_objectlist.getnext(pos);
                if (phititem->iskindof(runtime_class(cellipse)))
                {
                        pellipse = (cellipse*)phititem;
                        if(pellipse != null)
                        {
                                crect rc;
                                rc.left=pellipse->startx;
                                rc.top=pellipse->starty;
                                rc.right=pellipse->endx;
                                rc.bottom=pellipse->endy;
                                if (rc.ptinrect(point))
                                {
                                        clearselection();
                                        pellipse->bisselected=true;
                                        m_tracker.m_rect.setrect(pellipse->startx,pellipse->starty,
                                                pellipse->endx,pellipse->endy);  
                                }
                                else
                                {
                                        pellipse->bisselected=false;
                                }
                        }
                }省略选择直线、弧线和文本的代码
                else if (phititem->iskindof(runtime_class(crectangle)))
                {
                        prectangle = (crectangle*)phititem;
                        if(prectangle != null)
                        {
                                crect rc;
                                rc.left=prectangle->startx;
                                rc.top=prectangle->starty;
                                rc.right=prectangle->endx;
                                rc.bottom=prectangle->endy;
                                if (rc.ptinrect(point))
                                {
                                        clearselection();
                                        prectangle->bisselected=true;
                                        m_tracker.m_rect.setrect(prectangle->startx,
                                                prectangle->starty,prectangle->endx,prectangle->endy);  
                                }
                                else
                                {
                                        prectangle->bisselected=false;
                                }
                        }
                }
        }
       
        m_tracker.track(this,point);//
        invalidate();
}
3.13鼠标形态的自适应
wm_setcursor消息的响应代码如下:
bool cmydrawview:nsetcursor(cwnd* pwnd, uint nhittest, uint message)
{
        // todo: add your message handler code here and/or call default
if(m_tracker.setcursor(pwnd,nhittest))
                return true;
        return cview:nsetcursor(pwnd, nhittest, message);
}
3.14.显示绘图元素的属性
wm_setcursor消息的响应代码如下:
void cmydrawview:nlbuttondblclk(uint nflags, cpoint point)
{
        cellipse* pellipse = null;
        cline* pline=null;
        crectangle* prectangle=null;
        carc* parc=null;
        ctext* ptext=null;

        position pos = m_objectlist.getheadposition();
        cobject* phititem;
        while(pos != null)
        {
                phititem=(cobject*)m_objectlist.getnext(pos);
                if (phititem->iskindof(runtime_class(cline)))
                {
                        pline = (cline*)phititem;
                        if(pline != null)
                        {
                                if (pline->bisselected)
                                {
                                        clineproperties linedlg;
                                        cstring str_linewidth;
                                        str_linewidth.format("%d",pline->linepen.lopnwidth.x);
                                        linedlg.m_linewidth=str_linewidth;
                                       
                                        if (pline->linepen.lopnstyle==ps_dash)
                                                linedlg.m_linestyle="虚线 ";
                                        else if (pline->linepen.lopnstyle==ps_dot)
                                                linedlg.m_linestyle="点线";
                                        else if(pline->linepen.lopnstyle==ps_dashdot)
                                                linedlg.m_linestyle="点划线";
                                        else
                                                linedlg.m_linestyle="实线";
                                       
                                        linedlg.m_linecolor=pline->linepen.lopncolor;  
                                        if (linedlg.domodal()==idok)
                                        {
                                                pline->linepen.lopnwidth.x=atoi(linedlg.m_linewidth);
                                               
                                                if (linedlg.m_linestyle=="虚线")
                                                        pline->linepen.lopnstyle=ps_dash;
                                                else if (linedlg.m_linestyle=="点线")
                                                        pline->linepen.lopnstyle=ps_dot;
                                                else if(linedlg.m_linestyle=="点划线")
                                                        pline->linepen.lopnstyle=ps_dashdot;
                                                else
                                                        pline->linepen.lopnstyle=ps_solid;
                                               
                                                pline->linepen.lopncolor=linedlg.m_linecolor;  
                                                invalidate();
                                        }
                                }
                        }
                }此处省略显示椭圆、矩形、弧线和文本属性的代码
               
        cview::onlbuttondblclk(nflags, point);
}
3.15.删除绘图元素
wm_keyup消息的响应代码如下:
void cmydrawview::onkeyup(uint nchar, uint nrepcnt, uint nflags)
{
        cellipse* pellipse = null;
        cline* pline=null;
        crectangle* prectangle=null;
        carc* parc=null;
        ctext* ptext=null;
       
        if (46==nchar)
        {
                position pos = m_objectlist.gettailposition();
                cobject* phititem;
                while(pos != null)
                {
                        position curpos=pos;
                        phititem=(cobject*)m_objectlist.getprev(pos);
                        if (phititem->iskindof(runtime_class(cellipse)))
                        {
                                pellipse = (cellipse*)phititem;
                                if(pellipse != null)
                                {
                                        if (pellipse->bisselected)
                                        {
                                                m_objectlist.removeat(curpos);
                                                invalidate();
                                                break;
                                        }
                                }
                        }此处省略删除直线、矩形、弧线和文本的代码
        cview::onkeyup(nchar, nrepcnt, nflags);
}
3.16.cmydrawdoc类实现文档的存取操作
新建文档
新建文档时,会激活文档类的onnewdocument函数。由于存储绘图元素的链表m_objectlist在试图类中,所以首先得到视图类的对象myview,然后删除链表m_objectlis中的所有绘图元素:
bool cmydrawdoc::onnewdocument()
{
        if (!cdocument::onnewdocument())
                return false;
       
        // todo: add reinitialization code here
        // (sdi documents will reuse this document)
        position viewpos=this->getfirstviewposition();
        cmydrawview * myview=(cmydrawview *)this->getnextview(viewpos);
        myview->m_objectlist.removeall();  
        return true;
}
3.17打开文档
如果用户选择打开的文件是空的,也就是说文件的大小为0,那么就自动删除视图类中链表m_objectlist的所有绘图元素:
bool cmydrawdoc::onopendocument(lpctstr lpszpathname)
{
        if (!cdocument::onopendocument(lpszpathname))
                return false;
       
        // todo: add your specialized creation code here
    ofstruct of;
    handle hfile = null;;
        hfile=(handle)openfile(lpszpathname,&of,of_read|of_share_compat);
        if (hfile!=(handle)hfile_error)
        {
                dword dwhighword = null;
                dword dwsizelow = getfilesize(hfile,&dwhighword );
                dword dwfilesize = dwsizelow;
                if(0==dwfilesize)
                {
                        position viewpos=this->getfirstviewposition();
                        cmydrawview * myview=(cmydrawview *)this->getnextview(viewpos);
                        myview->m_objectlist.removeall();  
                }
        }
        return true;
}
3.18序列化
cmydrawdoc类的serialze函数用于完成序列化操作,代码如下:
void cmydrawdoc::serialize(carchive& ar)
{
        position pos;
        if (ar.isstoring())
        {
                // todo: add storing code here
                position viewpos=this->getfirstviewposition();
                cmydrawview * myview=(cmydrawview *)this->getnextview(viewpos);
                pos = myview->m_objectlist.getheadposition();
                while(pos != null)
                {
                        ar << (cobject*)(myview->m_objectlist.getnext(pos));
                }
        }
        else
        {
           position viewpos=this->getfirstviewposition();
                cmydrawview * myview=(cmydrawview *)this->getnextview(viewpos);
                myview->m_objectlist.removeall();  

                cobject * pobject;
                do{
                        try
                        {
                                ar >> pobject;
                                myview->m_objectlist.addtail(pobject);
                        }
                        catch(cexception * e)
                        {
                                e->delete();
                                break;
                        }
        }while(pobject != null);
       
}





4.结束语
在整个设计和开发中,我碰到了许多无法解决的问题,如在程序中本来语句没有错误,可就是在运行中无法按自己的意愿实现,当时指导老师又不在,我检查了一遍又一遍,可就是一筹莫展,但是我在别的类中浏览时,发现了数据类型的不匹配,这么一个小小的错误却导致了错误的运行结果。这使我认识到了,在编写语句时一定要认真,严谨。虽然在程序设计中,错了改,改了错,但是这使我学到了课堂上无法学到的知识,这是我在大学生涯中一个不小的收获。假若没有这次的毕业设计,我真的无法明白设计、编写一软件需要付出如此的艰辛,这是我以前无法想象的。但是我在整个设计过程中,慢慢地喜欢上了编写软件,它在不知不觉中给你带来莫大的乐趣。特别是在成功完成一功能模块时,给人一种很大的成就感。
在本次毕业设计中,我从指导老师身上学到了很多东西。冯静认真负责的工作态度,严谨的治学精神和深厚的理论水平都使我收益匪浅。他无论在理论上还是在实践中,都给与我很大的帮助,使我得到不少的提高这对于我以后的工作和学习都有一种巨大的帮助,感谢他耐心的辅导。另外,在系统开发过程中刘瑞许同学也给于我很大的帮助,帮助解决了不少的难点,使得系统能及时开发完成,还有同班的同学同样给与我不少帮助,这里表示感谢!








5.参考文献
[1] 伍俊良.《visual c++ 课程设计与系统开发案例》.清华大学出版社
[2] 杨小平.《visual c++ 项目案例导航》.科学出版社
[3] 邓宗明,张晓竞.《visual c++ 编程实用技术与案例》.清华大学出版社
[4] 郑阿奇.《visual c++ 实用教程》.电子工业出版社
[5] 萨师煊,王珊.《数据库系统概论》.高等教育出版社
[6] 郑人杰,殷人昆,陶永雷.实用软件工程.清华大学出版社.1997.4
[7] 门槛创作室 《visual c++6.0 实例教程》 电子工业出版社
{8} bjarne stroustrup 《the c++ programming languague》电子科技出版社 1997

ding

TOP

TOP

TOP

TOP

gfsdlkfgjksdjkfgj ls;djflgsdfdf

TOP

呵呵

TOP

真好需要看看

TOP

TOP

TOP

返回列表

Powered by Discuz! 7.2   论坛QQ群:逐梦论坛群

© 2001-2021 Comsenz Inc. 鲁公网安备 37120302000001号