电子元器件系统.docx

上传人:b****3 文档编号:2970098 上传时间:2022-11-16 格式:DOCX 页数:24 大小:22KB
下载 相关 举报
电子元器件系统.docx_第1页
第1页 / 共24页
电子元器件系统.docx_第2页
第2页 / 共24页
电子元器件系统.docx_第3页
第3页 / 共24页
电子元器件系统.docx_第4页
第4页 / 共24页
电子元器件系统.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

电子元器件系统.docx

《电子元器件系统.docx》由会员分享,可在线阅读,更多相关《电子元器件系统.docx(24页珍藏版)》请在冰豆网上搜索。

电子元器件系统.docx

电子元器件系统

电子元器件系统代码分析

一、类的定义与实现

1、器件类

●器件类定义

classCComponent:

publicCObject

{

public:

staticCOLORREFm_fillColor;//由类的所有对象共享

BOOLIsNum(CStringstr);

BOOLIsInList(inti,CObList*pNumList);

DECLARE_SERIAL(CComponent)

voidSerialize(CArchive&ar);

voidSetName(constCString&Name);

CStringGetName();

virtualvoidDraw(CDC*pDC);

virtualCStringCalculateName(CObList*pList);

floatGetRotateAngle();

voidSetRotateAngle(floatangle);

BOOLGetIsSelected();

voidSetIsSelected(BOOLIsSel);

intGetLineWidth();

voidSetLineWidth(intLWidth);

voidSetColor(COLORREFcolor);

COLORREFGetColor();

CComponent();

virtual~CComponent();

private:

floatm_RotateAngle;

BOOLm_IsSelected;

intm_iLineWidth;

COLORREFm_Color;

CStringm_strName;

};

●器件类实现

COLORREFCComponent:

:

m_fillColor=RGB(176,176,176);

//在文件范围内初始化

CComponent:

:

CComponent()

{

m_RotateAngle=0;

m_IsSelected=FALSE;

//m_iLineWidth=4;

m_iLineWidth=40;

m_Color=RGB(0,0,255);

}

CComponent:

:

~CComponent()

{

}

COLORREFCComponent:

:

GetColor()

{

returnm_Color;

}

voidCComponent:

:

SetColor(COLORREFcolor)

{

m_Color=color;

}

voidCComponent:

:

SetLineWidth(intLWidth)

{

m_iLineWidth=LWidth;

}

intCComponent:

:

GetLineWidth()

{

returnm_iLineWidth;

}

voidCComponent:

:

SetIsSelected(BOOLIsSel)

{

m_IsSelected=IsSel;

}

BOOLCComponent:

:

GetIsSelected()

{

returnm_IsSelected;

}

voidCComponent:

:

SetRotateAngle(floatangle)

{

m_RotateAngle=angle;

}

floatCComponent:

:

GetRotateAngle()

{

returnm_RotateAngle;

}

CStringCComponent:

:

CalculateName(CObList*pObList)

{

return"器件";

}

voidCComponent:

:

Draw(CDC*pDC)

{

}

CStringCComponent:

:

GetName()

{

returnm_strName;

}

voidCComponent:

:

SetName(constCString&Name)

{

m_strName=Name;

}

voidCComponent:

:

Serialize(CArchive&ar)

{

if(ar.IsStoring())

{

ar<

}

else

{

ar>>m_Color>>m_iLineWidth>>m_strName>>m_RotateAngle;

}

}

BOOLCComponent:

:

IsInList(inti,CObList*pNumList)

//判断数字i是否在链表pNumList中

{

POSITIONpos=pNumList->GetHeadPosition();

CObject*pObject;

int*p;

while(pos!

=NULL)

{

pObject=pNumList->GetAt(pos);

p=(int*)pObject;

if(i==(*p))

{

returnTRUE;

}

pNumList->GetNext(pos);

}

returnFALSE;

}

BOOLCComponent:

:

IsNum(CStringstr)

//判断一个字符串是否是数字,在各个派生类的CalculateName函数中

//使用,系统提供的函数atoi()将类似于"12ert"之类的串转换为12,

//这显然是不正确的,因此自己开发了这个小函数

{

intlen=str.GetLength();

charch;

for(inti=1;i<=len;i++)

{

ch=str.GetAt(i-1);

if(!

(ch<='9'&&ch>='0'))

{

returnFALSE;

}

}

returnTRUE;

}

2、电阻类的定义与实现

●电阻类的定义

#include"Component.h"//包含基类的头文件

typedefstructstruc_Resistor

{

charm_strClassType[20];

//COLORREFm_color;

//intm_iLineWidth;

BOOLm_IsSelected;

//floatm_RotateAngle;

charm_strName[100];

//charm_ReType[100];//电阻的类型

//charm_ReValue[100];//电阻的阻值

}RESISTOR;

classCResistor:

publicCComponent

{

public:

voidCopyReToStruRe(RESISTOR&Resistor);

//将电阻对象拷贝到电阻结构中

CResistor(RESISTORResistor);

voidGetNumInNameSer(CObList*pObList,CObList*pNumSer,int*pMax);

//取得已绘制的电阻名称中的数字序列

CResistor(CPoint*pt);

DECLARE_SERIAL(CResistor)

voidSerialize(CArchive&ar);

voidPrepareDrawChipDC(CDC*pDC);

voidDraw(CDC*pDC);

CStringCalculateName(CObList*pObList);

voidSetReValue(CString&ReValue);

voidSetReType(CString&ReType);

CStringGetReValue();

CStringGetReType();

CRectm_Rect;

CRectm_RectLP;

CRectTrackerm_RectTracker;

CResistor();

virtual~CResistor();

private:

CStringm_ReType;

CStringm_ReValue;

};

●电阻类的实现

CResistor:

:

CResistor()

{

//m_Rect=CRect(0,0,100,60);

m_Rect=CRect(0,0,2000,-1000);

m_RectLP=m_Rect;

m_RectTracker.m_rect=m_Rect;

m_RectTracker.m_nStyle=CRectTracker:

:

resizeOutside;

SetName("R");

}

CResistor:

:

~CResistor()

{

}

CStringCResistor:

:

GetReType()

{

returnm_ReType;

}

CStringCResistor:

:

GetReValue()

{

returnm_ReValue;

}

voidCResistor:

:

SetReType(CString&ReType)

{

m_ReType=ReType;

}

voidCResistor:

:

SetReValue(CString&ReValue)

{

m_ReValue=ReValue;

}

CStringCResistor:

:

CalculateName(CObList*pObList)

//在绘制时系统给出的默认名称,这个名称是根据当前链表中

//对象情况而定的,具体功能同VB等开发工具中拖拉控件时产生

//名称的情况

{

CObList*pNumSer=newCObList;

intmax;

charbuf[10];

GetNumInNameSer(pObList,pNumSer,&max);

//分析数字序列

for(inti=1;i<=max;i++)

{

if(IsInList(i,pNumSer))//在基类中有定义

{

}

else

{

break;

}

}

itoa(i,buf,10);

//itoa(i,buf,10);

//删除链表

//TRACE("pNumSer->Count()=%d\n",pNumSer->GetCount());

while(pNumSer->GetHeadPosition())

{

delete(int*)pNumSer->RemoveHead();

}

deletepNumSer;

return"R"+CString(buf);

}

voidCResistor:

:

Draw(CDC*pDC)

{

/*根据元器件对象的颜色和线宽属性值绘制*/

CStringname=this->GetName();

intwidth=m_Rect.Width();

intheight=m_Rect.Height();//返回的是负值;

CPen

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 外语学习 > 其它语言学习

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1