📄 transistor.cpp
字号:
// Transistor.cpp: implementation of the CTransistor class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DrawChip.h"
#include "Transistor.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CTransistor, CComponent,0)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//##ModelId=3E18E0CA0227
CTransistor::CTransistor()
{
//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;
SetName("T");
}
//##ModelId=3E18E0CA0262
CTransistor::~CTransistor()
{
}
//##ModelId=3E18E0C7035C
void CTransistor::SetPower(CString &Power)
{
m_strPower = Power;
}
//##ModelId=3E18E0C70321
CString CTransistor::GetPower()
{
return m_strPower;
}
//##ModelId=3E18E0C702F1
void CTransistor::SetType(CString &Type)
{
m_strType = Type;
}
//##ModelId=3E18E0C702F0
CString CTransistor::GetType()
{
return m_strType;
}
//##ModelId=3E18E0C702EE
void CTransistor::SetFrequence(CString &Frequence)
{
m_strFrequence = Frequence;
}
//##ModelId=3E18E0C702BF
CString CTransistor::GetFrequence()
{
return m_strFrequence;
}
//##ModelId=3E18E0C702BD
void CTransistor::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->Ellipse((int)(m_Rect.left+width*0.2),(int)(m_Rect.top+height*0.2),
(int)(m_Rect.left+width*0.6),(int)(m_Rect.top+height*0.2-width*0.4));
pDC->MoveTo((int)(m_Rect.left),(int)(m_Rect.top+height*0.2-width*0.2));
pDC->LineTo((int)(m_Rect.left+width*0.3),(int)(m_Rect.top+height*0.2-width*0.2));
pDC->MoveTo((int)(m_Rect.left+width*0.3),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1));
pDC->LineTo((int)(m_Rect.left+width*0.3),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)));
pDC->MoveTo((int)(m_Rect.left+width*0.3),(int)(m_Rect.top+height*0.2-width*0.2));
pDC->LineTo((int)(m_Rect.left+width*0.5),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1));
pDC->MoveTo((int)(m_Rect.left+width*0.3),(int)(m_Rect.top+height*0.2-width*0.2));
pDC->LineTo((int)(m_Rect.left+width*0.5),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)));
pDC->MoveTo((int)(m_Rect.left+width*0.5),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1));
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 +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)));
pDC->LineTo((int)(m_Rect.left+width*0.5),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)+height*0.2));
pDC->MoveTo((int)(m_Rect.left+width*0.5),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)));
pDC->LineTo((int)(m_Rect.left+width*0.45),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)-height*0.2));
pDC->MoveTo((int)(m_Rect.left+width*0.5),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)));
pDC->LineTo((int)(m_Rect.left+width*0.35),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)-height*0.05));
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut((int)(m_Rect.left+width*0.1),(int)(m_Rect.top +height*0.2-(2-sqrt(3))*width*0.1-width*0.2*sqrt(3)+height*0.2),name);
pDC->SelectObject(pOldPen);
}
//##ModelId=3E18E0C70286
CString CTransistor::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);
//itoa(i,buf,10);
//删除链表
//TRACE("pNumSer->Count() = %d\n", pNumSer->GetCount());
while (pNumSer->GetHeadPosition())
{
delete (int *)pNumSer->RemoveHead();
}
delete pNumSer;
return "T"+ CString(buf);
}
//##ModelId=3E18E0C70284
CTransistor::CTransistor(CPoint *pt)
{
/*由于需要把新生成的元器件对象的m_Rect左上角坐标设置为*/
/*鼠标点按处的坐标转换成逻辑坐标后的值,并且初始化m_Rect的右下角坐标*/
/*所以将这一系列的初始化操作加到了CTransistor(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=3E18E0C70282
void CTransistor::Serialize(CArchive &ar)
{
CComponent::Serialize(ar);
//需要序列化m_RectLP
if (ar.IsStoring())
{
ar<<m_Rect<<m_RectLP<<m_RectTracker.m_nStyle<<m_strPower<<m_strType<<m_strFrequence<<m_strSwitch;
//<<m_RectTracker.m_rect
}
else
{
ar>>m_Rect>>m_RectLP>>m_RectTracker.m_nStyle>>m_strPower>>m_strType>>m_strFrequence>>m_strSwitch;
//>>m_RectTracker.m_rect
}
}
//##ModelId=3E18E0C70280
void CTransistor::SetSwitch(CString &strSwitch)
{
m_strSwitch = strSwitch;
}
//##ModelId=3E18E0C70252
CString CTransistor::GetSwitch()
{
return m_strSwitch;
}
//##ModelId=3E18E0C70250
void CTransistor::CopyTranToStruTran(TRANSISTOR &Transistor)
{
lstrcpy(Transistor.m_strClassType, "Transistor");
Transistor.m_color = this->GetColor();
Transistor.m_iLineWidth = this->GetLineWidth();
Transistor.m_IsSelected = this->GetIsSelected();
Transistor.m_RotateAngle =this->GetRotateAngle();
lstrcpy(Transistor.m_strType , this->GetType());
lstrcpy(Transistor.m_strPower , this->GetPower());
lstrcpy(Transistor.m_strFrequence,this->GetFrequence());
lstrcpy(Transistor.m_strSwitch ,this->GetSwitch());
lstrcpy(Transistor.m_strName , this->GetName());
}
//##ModelId=3E18E0C7024E
CTransistor::CTransistor(TRANSISTOR Transistor)
{
//根据结构体Transistor在默认位置构造一个三极管对象
//在粘贴时使用
SetColor(Transistor.m_color);
SetLineWidth(Transistor.m_iLineWidth);
SetRotateAngle(Transistor.m_RotateAngle);
SetIsSelected(Transistor.m_IsSelected);
SetName(Transistor.m_strName);
m_strPower = Transistor.m_strPower ;
m_strFrequence = Transistor.m_strFrequence ;
m_strType = Transistor.m_strType ;
m_strSwitch = Transistor.m_strSwitch;
//m_Rect = CRect(0,0,100,60);
//m_Rect = CRect(0,0,2000,-1000);
/*由于在MM_HIMETRIC映射模式下视图的原点在左上角,有一部分是被工具条*/
/*掩盖住的,而且也应该把复制过来的元器件图形放在可打印的地方,所以*/
/*它的外接矩形的左上角定义为CPoint(1000,-1000)即距离打印纸左边1cm*/
/*距离上边框1cm处*/
m_Rect = CRect(1000,-1000,3000,-2000);
m_RectLP = m_Rect;
m_RectTracker.m_rect = m_Rect;
m_RectTracker.m_nStyle = CRectTracker::resizeOutside;
}
//##ModelId=3E18E0C701E0
void CTransistor::GetNumInNameSer(CObList *pObList, CObList *pNumSer, int *pMax)
{
*pMax = 0;
POSITION pos = pObList->GetHeadPosition();
CObject *pObject;
CTransistor *pTransistor;
CString strName;
CString strLastName;
while (pos != NULL)
{
pObject = pObList->GetAt(pos);
if (pObject->IsKindOf(RUNTIME_CLASS(CTransistor)))
{
pTransistor = (CTransistor*)pObject;
strName = pTransistor->GetName();
if ((strName.GetAt(0) == 'T') || (strName.GetAt(0) == 't'))
//如果名称的第一个字母是T或t
{
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
//名称的第一个字母不是T或t
{
}
}
else
{
}
pObList->GetNext(pos);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -