📄 compacity.cpp
字号:
// Compacity.cpp: implementation of the CCompacity class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DrawChip.h"
#include "Compacity.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CCompacity, CComponent,0)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//##ModelId=3E18E0E80033
CCompacity::CCompacity()
{
}
//##ModelId=3E18E0E80034
CCompacity::~CCompacity()
{
}
//##ModelId=3E18E0E703AC
void CCompacity::SetCompacity(const CString &compacity)
{
m_strCompacity = compacity;
}
//##ModelId=3E18E0E70375
CString CCompacity::GetCompacity()
{
return m_strCompacity;
}
//##ModelId=3E18E0E70373
void CCompacity::SetType(const CString &type)
{
m_strType = type;
}
//##ModelId=3E18E0E70372
CString CCompacity::GetType()
{
return m_strType;
}
//##ModelId=3E18E0E70370
void CCompacity::SetPressure(const CString &pressure)
{
m_strPressure = pressure;
}
//##ModelId=3E18E0E70341
CString CCompacity::GetPressure()
{
return m_strPressure;
}
//##ModelId=3E18E0E7033F
void CCompacity::SetFrequence(const CString &frequence)
{
m_strFrequence = frequence;
}
//##ModelId=3E18E0E7033E
CString CCompacity::GetFrequence()
{
return m_strFrequence;
}
//##ModelId=3E18E0E7030A
void CCompacity::Serialize(CArchive &ar)
{
CComponent::Serialize(ar);
//需要序列化m_RectLP
if (ar.IsStoring())
{
ar<<m_Rect<<m_RectLP<<m_RectTracker.m_nStyle<<m_strType<<m_strCompacity<<m_strPressure<<m_strFrequence;
//<<m_RectTracker.m_rect
}
else
{
ar>>m_Rect>>m_RectLP>>m_RectTracker.m_nStyle>>m_strType>>m_strCompacity>>m_strPressure>>m_strFrequence;
//>>m_RectTracker.m_rect
}
}
//##ModelId=3E18E0E70308
void CCompacity::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(m_Rect.left,(int)(m_Rect.top + height*0.3));
pDC->LineTo((int)(m_Rect.left +width*0.4),(int)(m_Rect.top + height*0.3));
pDC->MoveTo((int)(m_Rect.left +width*0.4),(int)(m_Rect.top + height*0.15));
pDC->LineTo((int)(m_Rect.left +width*0.4),(int)(m_Rect.top + height*0.45));
pDC->MoveTo((int)(m_Rect.left +width*0.6),(int)(m_Rect.top + height*0.15));
pDC->LineTo((int)(m_Rect.left +width*0.6),(int)(m_Rect.top + height*0.45));
pDC->MoveTo((int)(m_Rect.left + width*0.6),(int)(m_Rect.top + height*0.3));
pDC->LineTo((int)(m_Rect.left + width),(int)(m_Rect.top + height*0.3));
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut((int)(m_Rect.left + width * 0.4),(int)(m_Rect.top + height*0.55),name);
pDC->SelectObject(pOldPen);
}
//##ModelId=3E18E0E70306
CString CCompacity::CalculateName(CObList *pObList)
{
//waiting to develop
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 "C"+ CString(buf);
}
//##ModelId=3E18E0E70304
CCompacity::CCompacity(CPoint *pt)
{
/*由于需要把新生成的元器件对象的m_Rect左上角坐标设置为*/
/*鼠标点按处的坐标转换成逻辑坐标后的值,并且初始化m_Rect的右下角坐标*/
/*所以将这一系列的初始化操作加到了CCompacity(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=3E18E0E702D5
void CCompacity::GetNumInNameSer(CObList *pObList, CObList *pNumSer, int *pMax)
//取得链表中电容名称是以C或c开头,后面为数字的名称中的数字序列
//其中pNumSer存放数字序列,pMax存放的是数字中的最大值
{
*pMax = 0;
POSITION pos = pObList->GetHeadPosition();
CObject *pObject;
CCompacity *pCompacity;
CString strName;
CString strLastName;
while (pos != NULL)
{
pObject = pObList->GetAt(pos);
if (pObject->IsKindOf(RUNTIME_CLASS(CCompacity)))
{
pCompacity = (CCompacity*)pObject;
strName = pCompacity->GetName();
if ((strName.GetAt(0) == 'C') || (strName.GetAt(0) == 'c'))
//如果名称的第一个字母是C或c
{
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
//名称的第一个字母不是C或c
{
}
}
else
{
}
pObList->GetNext(pos);
}
}
//##ModelId=3E18E0E702D3
CCompacity::CCompacity(COMPACITY Compacity)
{
//根据结构体Resistor在默认位置构造一个电阻对象
//在粘贴时使用
SetColor(Compacity.m_color);
SetLineWidth(Compacity.m_iLineWidth);
SetRotateAngle(Compacity.m_RotateAngle);
SetName(Compacity.m_strName);
SetIsSelected(Compacity.m_IsSelected);
SetCompacity(Compacity.m_strCompacity);
SetFrequence(Compacity.m_strFrequence);
SetPressure(Compacity.m_strPressure);
SetType(Compacity.m_strType);
//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=3E18E0E702D1
void CCompacity::CopyComToStrucCom(COMPACITY &Compacity)
{
lstrcpy(Compacity.m_strClassType, "Compacity");
Compacity.m_color = this->GetColor();
Compacity.m_RotateAngle =this->GetRotateAngle();
Compacity.m_iLineWidth = this->GetLineWidth();
Compacity.m_IsSelected = this->GetIsSelected();
lstrcpy(Compacity.m_strCompacity,this->GetCompacity());
lstrcpy(Compacity.m_strFrequence ,this->GetFrequence());
lstrcpy(Compacity.m_strName ,this->GetName());
lstrcpy(Compacity.m_strPressure,this->GetPressure());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -