?? switch.cpp
字號:
// Switch.cpp: implementation of the CSwitch class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DrawChip.h"
#include "Switch.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CSwitch, CComponent,0)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//##ModelId=3E18E0CB0034
CSwitch::CSwitch()
{
m_Rect = CRect(0,0,100,60);
m_RectLP = m_Rect;
m_RectTracker.m_rect = m_Rect;
m_RectTracker.m_nStyle = CRectTracker::resizeOutside;
}
//##ModelId=3E18E0CB0035
CSwitch::~CSwitch()
{
}
//##ModelId=3E18E0CB0032
void CSwitch::SetType(CString &strType)
{
m_strType = strType;
}
//##ModelId=3E18E0CA03E4
CString CSwitch::GetType()
{
return m_strType;
}
//##ModelId=3E18E0CA03B0
void CSwitch::GetNumInNameSer(CObList *pObList, CObList *pNumSer, int *pMax)
{
*pMax = 0;
POSITION pos = pObList->GetHeadPosition();
CObject *pObject;
CSwitch *pSwitch;
CString strName;
CString strLastName;
while (pos != NULL)
{
pObject = pObList->GetAt(pos);
if (pObject->IsKindOf(RUNTIME_CLASS(CSwitch)))
{
pSwitch = (CSwitch*)pObject;
strName = pSwitch->GetName();
if ((strName.GetAt(0) == 'W') || (strName.GetAt(0) == 'w'))
//如果名稱的第一個字母是W或w
{
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=3E18E0CA03AE
CString CSwitch::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 "W"+ CString(buf);
}
//##ModelId=3E18E0CA03AC
void CSwitch::Serialize(CArchive &ar)
{
CComponent::Serialize(ar);
//需要序列化m_RectLP
if (ar.IsStoring())
{
ar<<m_Rect<<m_RectLP<<m_RectTracker.m_nStyle<<m_strType;
//<<m_RectTracker.m_rect
}
else
{
ar>>m_Rect>>m_RectLP>>m_RectTracker.m_nStyle>>m_strType;
//>>m_RectTracker.m_rect
}
}
//##ModelId=3E18E0CA0375
void CSwitch::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.2),(int)(m_Rect.top+height*0.3));
pDC->MoveTo((int)(m_Rect.left+width*0.2),(int)(m_Rect.top+height*0.3));
pDC->LineTo((int)(m_Rect.left+width*0.5),(int)(m_Rect.top));
pDC->Ellipse((int)(m_Rect.left+width*0.2),(int)(m_Rect.top+height*0.3-width*0.1)
,(int)(m_Rect.left+width*0.4),(int)(m_Rect.top+height*0.3+width*0.1));
pDC->Ellipse((int)(m_Rect.left+width*0.6),(int)(m_Rect.top+height*0.3-width*0.1)
,(int)(m_Rect.left+width*0.8),(int)(m_Rect.top+height*0.3+width*0.1));
pDC->MoveTo((int)(m_Rect.left+width*0.8),(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.2),(int)(m_Rect.top+height*0.3-width*0.1),name);
pDC->SelectObject(pOldPen);
}
//##ModelId=3E18E0CA0373
CSwitch::CSwitch(SWITCH Switch)
{
//根據結構體Switch在默認位置構造一個開關對象
//在粘貼時使用
SetColor(Switch.m_color);
SetLineWidth(Switch.m_iLineWidth);
SetRotateAngle(Switch.m_RotateAngle);
SetName(Switch.m_strName);
SetIsSelected(Switch.m_IsSelected);
m_strType = Switch.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=3E18E0CA0371
CSwitch::CSwitch(CPoint *pt)
{
/*由于需要把新生成的元器件對象的m_Rect左上角坐標設置為*/
/*鼠標點按處的坐標轉換成邏輯坐標后的值,并且初始化m_Rect的右下角坐標*/
/*所以將這一系列的初始化操作加到了CSwitch(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=3E18E0CA0340
void CSwitch::CopySwToStrucSw(SWITCH &Switch)
{
lstrcpy(Switch.m_strClassType, "Switch");
Switch.m_color = this->GetColor();
Switch.m_iLineWidth = this->GetLineWidth();
Switch.m_IsSelected = this->GetIsSelected();
lstrcpy(Switch.m_strType , this->GetType());
Switch.m_RotateAngle = this->GetRotateAngle();
lstrcpy(Switch.m_strName , this->GetName());
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -