📄 crsocket.cpp
字号:
// CrSocket.cpp: implementation of the CCrSocket class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DrawChip.h"
#include "CrSocket.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CCrSocket, CMySocket,0)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//##ModelId=3E18E0E603BA
CCrSocket::CCrSocket()
{
}
//##ModelId=3E18E0E603BB
CCrSocket::~CCrSocket()
{
}
//##ModelId=3E18E0E603B6
void CCrSocket::GetNumInNameSer(CObList *pObList, CObList *pNumSer, int *pMax)
{
*pMax = 0;
POSITION pos = pObList->GetHeadPosition();
CObject *pObject;
CCrSocket *pCrSocket;
CString strName;
CString strLastName;
while (pos != NULL)
{
pObject = pObList->GetAt(pos);
if (pObject->IsKindOf(RUNTIME_CLASS(CCrSocket)))
{
pCrSocket = (CCrSocket*)pObject;
strName = pCrSocket->GetName();
if ((strName.GetAt(0) == 'S') || (strName.GetAt(0) == 's'))
//如果名称的第一个字母是D或d
{
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
//名称的第一个字母不是S或s
{
}
}
else
{
}
pObList->GetNext(pos);
}
}
//##ModelId=3E18E0E6037F
CString CCrSocket::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 "S"+ CString(buf);
}
//##ModelId=3E18E0E6037D
void CCrSocket::Serialize(CArchive &ar)
{
CMySocket::Serialize(ar);
}
//##ModelId=3E18E0E6037B
CCrSocket::CCrSocket(CPoint *pt)
{
/*由于需要把新生成的元器件对象的m_Rect左上角坐标设置为*/
/*鼠标点按处的坐标转换成逻辑坐标后的值,并且初始化m_Rect的右下角坐标*/
/*所以将这一系列的初始化操作加到了CCrSocket(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=3E18E0E6034D
CCrSocket::CCrSocket(MYSOCKET mySocket)
{
//根据结构体mySocket在默认位置构造一个插座对象
//在粘贴时使用
SetColor(mySocket.m_color);
SetLineWidth(mySocket.m_iLineWidth);
SetRotateAngle(mySocket.m_RotateAngle);
SetName(mySocket.m_strName);
SetIsSelected(mySocket.m_IsSelected);
CString &strType = (CString)mySocket.m_Type;
CString &strPressure = (CString)mySocket.m_Pressure;
CString &strCurrent = (CString)mySocket.m_Current;
this->SetType(strType);
this->SetPressure (strPressure);
this->SetCurrent (strCurrent);
//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=3E18E0E6034B
void CCrSocket::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),(int)(m_Rect.top+height*0.1),(int)(m_Rect.left + width*0.14),(int)(m_Rect.top - width*0.14+ height*0.1));
pDC->Ellipse((int)(m_Rect.left+width*0.14*2),(int)(m_Rect.top+height*0.1),(int)(m_Rect.left+width*0.14*3),(int)(m_Rect.top - width*0.14+ height*0.1));
pDC->Ellipse((int)(m_Rect.left+width*0.14*4),(int)(m_Rect.top+height*0.1),(int)(m_Rect.left+width*0.14*5),(int)(m_Rect.top - width*0.14+ height*0.1));
pDC->Ellipse((int)(m_Rect.left+width*0.14*6),(int)(m_Rect.top+height*0.1),(int)(m_Rect.left+width*0.14*7),(int)(m_Rect.top - width*0.14+ height*0.1));
pDC->Ellipse((int)(m_Rect.left + width*0.14),(int)(m_Rect.top-width*0.14+height*0.2),(int)(m_Rect.left+width*0.14*2),(int)(m_Rect.top - width*0.14*2 + height*0.2));
pDC->Ellipse((int)(m_Rect.left+width*0.14*3),(int)(m_Rect.top-width*0.14+height*0.2),(int)(m_Rect.left+width*0.14*4),(int)(m_Rect.top - width*0.14*2 + height*0.2));
pDC->Ellipse((int)(m_Rect.left+width*0.14*5),(int)(m_Rect.top-width*0.14+height*0.2),(int)(m_Rect.left+width*0.14*6),(int)(m_Rect.top - width*0.14*2 + height*0.2));
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut((int)(m_Rect.left + width * 0.4),(int)(m_Rect.top - width*0.14*2 + height*0.2),name);
pDC->SelectObject(pOldPen);
}
//##ModelId=3E18E0E60349
void CCrSocket::CopyMySocketToStruSocket(MYSOCKET &mySocket)
{
lstrcpy(mySocket.m_strClassType, "crSocket");
mySocket.m_color = this->GetColor();
mySocket.m_iLineWidth = this->GetLineWidth();
mySocket.m_IsSelected = this->GetIsSelected();
lstrcpy(mySocket.m_Type,this->GetType());
lstrcpy(mySocket.m_Pressure,this->GetPressure());
lstrcpy(mySocket.m_Current,this->GetCurrent());
mySocket.m_RotateAngle =this->GetRotateAngle();
lstrcpy(mySocket.m_strName , this->GetName());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -