📄 inductor.cpp
字号:
// Inductor.cpp: implementation of the CInductor class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DrawChip.h"
#include "Inductor.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CInductor, CComponent,0)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//##ModelId=3E18E0D00367
CInductor::CInductor()
{
}
//##ModelId=3E18E0D00368
CInductor::~CInductor()
{
}
//##ModelId=3E18E0D00366
CString CInductor::GetCompacity()
{
return m_strCompacity;
}
//##ModelId=3E18E0D0032C
void CInductor::SetCompacity(CString &Compacity)
{
m_strCompacity = Compacity;
}
//##ModelId=3E18E0D0032A
void CInductor::SetFrequence(CString &Frequence)
{
m_strFrequence = Frequence;
}
//##ModelId=3E18E0D002FB
CString CInductor::GetFrequence()
{
return m_strFrequence;
}
//##ModelId=3E18E0D002FA
CString CInductor::GetPressure()
{
return m_strPressure;
}
//##ModelId=3E18E0D002F8
void CInductor::SetPressure(CString &Pressure)
{
m_strPressure = Pressure;
}
//##ModelId=3E18E0D002BE
void CInductor::SetWork(CString &Work)
{
m_strWork = Work;
}
//##ModelId=3E18E0D002BD
CString CInductor::GetWork()
{
return m_strWork;
}
//##ModelId=3E18E0D00255
CInductor::CInductor(INDUCTOR Inductor)
{
//根据结构体Inductor在默认位置构造一个电阻对象
//在粘贴时使用
SetColor(Inductor.m_color);
SetLineWidth(Inductor.m_iLineWidth);
SetRotateAngle(Inductor.m_RotateAngle);
SetName(Inductor.m_strName);
SetIsSelected(Inductor.m_IsSelected);
m_strCompacity = Inductor.m_strCompacity ;
m_strPressure = Inductor.m_strPressure ;
m_strFrequence = Inductor.m_strFrequence ;
m_strWork = Inductor.m_strWork ;
//m_Rect = CRect(0,0,100,60);
m_Rect = CRect(1000,-1000,3000,-2000);
m_RectLP = m_Rect;
m_RectTracker.m_rect = m_Rect;
m_RectTracker.m_nStyle = CRectTracker::resizeOutside;
}
//##ModelId=3E18E0D00251
void CInductor::GetNumInNameSer(CObList *pObList, CObList *pNumSer, int *pMax)
{
*pMax = 0;
POSITION pos = pObList->GetHeadPosition();
CObject *pObject;
CInductor *pInductor;
CString strName;
CString strLastName;
while (pos != NULL)
{
pObject = pObList->GetAt(pos);
if (pObject->IsKindOf(RUNTIME_CLASS(CInductor)))
{
pInductor = (CInductor*)pObject;
strName = pInductor->GetName();
if ((strName.GetAt(0) == 'I') || (strName.GetAt(0) == 'i'))
//如果名称的第一个字母是R或r
{
strLastName = strName.Mid(1);
//判断余下的字符是否数字
if (IsNum(strLastName))
//余下的字符全部都是数字
{
int i;
i = atoi(strLastName);
int *p = new int(i);
pNumSer->AddHead((CObject *)p);
if (i>(*pMax))
{
*pMax = i;
}
}
else
//余下的字符不全是数字
{
//忽略不记
}
}
else
//名称的第一个字母不是R或r
{
}
}
else
{
}
pObList->GetNext(pos);
}
}
//##ModelId=3E18E0D0024F
CInductor::CInductor(CPoint *pt)
{
/*由于需要把新生成的元器件对象的m_Rect左上角坐标设置为*/
/*鼠标点按处的坐标转换成逻辑坐标后的值,并且初始化m_Rect的右下角坐标*/
/*所以将这一系列的初始化操作加到了CInductor(CPoint *pt)构造函数中*/
m_Rect.left = pt->x;
m_Rect.top = pt->y;
m_Rect.right = m_Rect.left + 2000; // 100;
m_Rect.bottom = m_Rect.top -1000; //+ 60;
m_RectLP = m_Rect;
m_RectTracker.m_rect = m_Rect;
m_RectTracker.m_nStyle = CRectTracker::resizeOutside;
}
//##ModelId=3E18E0D00223
void CInductor::Serialize(CArchive &ar)
{
CComponent::Serialize(ar);
//需要序列化m_RectLP
if (ar.IsStoring())
{
ar<<m_Rect<<m_RectLP<<m_RectTracker.m_nStyle<<m_strCompacity<<m_strPressure<<m_strFrequence<<m_strWork;
//<<m_RectTracker.m_rect
}
else
{
ar>>m_Rect>>m_RectLP>>m_RectTracker.m_nStyle>>m_strCompacity>>m_strPressure>>m_strFrequence>>m_strWork;
//>>m_RectTracker.m_rect
}
}
//##ModelId=3E18E0D00221
CString CInductor::CalculateName(CObList *pObList)
{
CObList *pNumSer = new CObList;
int max;
char buf[10];
GetNumInNameSer(pObList,pNumSer,&max);
//分析数字序列
for (int i=1;i<=max;i++)
{
if (IsInList(i,pNumSer))
{
}
else
{
break;
}
}
itoa(i,buf,10);
while (pNumSer->GetHeadPosition())
{
delete (int *)pNumSer->RemoveHead();
}
delete pNumSer;
return "I"+ CString(buf);
}
//##ModelId=3E18E0D0021F
void CInductor::Draw(CDC *pDC)
{
/*根据元器件对象的颜色和线宽属性值绘制*/
CString name = this->GetName();
int width = m_Rect.Width() ;
int height = m_Rect.Height() ;
CPen newpen(PS_SOLID,GetLineWidth(),GetColor());
CPen *pOldPen = pDC->SelectObject(&newpen);
pDC->MoveTo((int)(m_Rect.left),(int)(m_Rect.top + height*0.25));
pDC->LineTo((int)(m_Rect.left+width*0.2),(int)(m_Rect.top + height*0.25));
pDC->MoveTo((int)(m_Rect.left+width*0.2),(int)(m_Rect.top + height*0.25));
pDC->LineTo((int)(m_Rect.left +width*0.3),(int)(m_Rect.top));
pDC->MoveTo((int)(m_Rect.left +width*0.3),(int)(m_Rect.top));
pDC->LineTo((int)(m_Rect.left +width*0.4),(int)(m_Rect.top+height*0.25));
pDC->MoveTo((int)(m_Rect.left +width*0.4),(int)(m_Rect.top+height*0.25));
pDC->LineTo((int)(m_Rect.left +width*0.5),(int)(m_Rect.top));
pDC->MoveTo((int)(m_Rect.left +width*0.5),(int)(m_Rect.top));
pDC->LineTo((int)(m_Rect.left +width*0.6),(int)(m_Rect.top+height*0.25));
pDC->MoveTo((int)(m_Rect.left +width*0.6),(int)(m_Rect.top+height*0.25));
pDC->LineTo((int)(m_Rect.left +width*0.7),(int)(m_Rect.top));
pDC->MoveTo((int)(m_Rect.left +width*0.7),(int)(m_Rect.top));
pDC->LineTo((int)(m_Rect.left +width*0.8),(int)(m_Rect.top+height*0.25));
pDC->MoveTo((int)(m_Rect.left +width*0.8),(int)(m_Rect.top+height*0.25));
pDC->LineTo((int)(m_Rect.left +width),(int)(m_Rect.top+height*0.25));
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut((int)(m_Rect.left + width * 0.2),(int)(m_Rect.top + height*0.25),name);
pDC->SelectObject(pOldPen);
}
//##ModelId=3E18E0D0021D
void CInductor::CopyInToStrucIn(INDUCTOR &Inductor)
{
lstrcpy(Inductor.m_strClassType, "Inductor");
Inductor.m_color = this->GetColor();
Inductor.m_iLineWidth = this->GetLineWidth();
Inductor.m_IsSelected = this->GetIsSelected();
Inductor.m_RotateAngle =this->GetRotateAngle();
lstrcpy(Inductor.m_strName , this->GetName());
lstrcpy(Inductor.m_strCompacity , this->GetCompacity());
lstrcpy(Inductor.m_strFrequence , this->GetFrequence());
lstrcpy(Inductor.m_strPressure , this->GetPressure());
lstrcpy(Inductor.m_strWork , this->GetWork());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -