⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icchip.cpp

📁 电子元器件绘制系统
💻 CPP
字号:
// IcChip.cpp: implementation of the CIcChip class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DrawChip.h"
#include "IcChip.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_SERIAL(CIcChip, CComponent,0)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//##ModelId=3E18E0D10244
CIcChip::CIcChip()
{
	//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("C");
}

//##ModelId=3E18E0D10245
CIcChip::~CIcChip()
{

}

//##ModelId=3E18E0D101D7
CString CIcChip::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 "C"+ CString(buf);
}

//##ModelId=3E18E0D101A8
void CIcChip::CopyChipToStruChip(ICCHIP &IcChip)
{
	lstrcpy(IcChip.m_strClassType, "IcChip");			
	IcChip.m_color = this->GetColor();
	IcChip.m_iLineWidth = this->GetLineWidth();
	IcChip.m_IsSelected = this->GetIsSelected();			
	lstrcpy(IcChip.m_ChipNum,this->GetChipNum());
	lstrcpy(IcChip.m_Encapsulate,this->GetEncapsulate());
	lstrcpy(IcChip.m_StCurrent,this->GetStCurrent());
	lstrcpy(IcChip.m_StPower,this->GetStPower());
	IcChip.m_RotateAngle =this->GetRotateAngle();			
	lstrcpy(IcChip.m_strName , this->GetName());
}

//##ModelId=3E18E0D101A6
void CIcChip::SetChipNum(CString &ChipNum)
{
	m_ChipNum = ChipNum;
}

//##ModelId=3E18E0D101A4
void CIcChip::SetEncapsulate(CString &Encapsulate)
{
	m_Encapsulate = Encapsulate;
}

//##ModelId=3E18E0D1016A
void CIcChip::SetStCurrent(CString &StCurrent)
{
	m_StCurrent = StCurrent;
}

//##ModelId=3E18E0D10168
void CIcChip::SetStPower(CString &StPower)
{
	m_StPower = StPower;
}

//##ModelId=3E18E0D1013C
CString CIcChip::GetChipNum()
{
	return m_ChipNum;
}

//##ModelId=3E18E0D1013B
CString CIcChip::GetEncapsulate()
{
	return m_Encapsulate;
}

//##ModelId=3E18E0D1013A
CString CIcChip::GetStCurrent()
{
	return m_StCurrent;
}

//##ModelId=3E18E0D10139
CString CIcChip::GetStPower()
{
	return m_StPower;
}

//##ModelId=3E18E0D10137
CIcChip::CIcChip(ICCHIP IcChip)
{
	//根据结构体IcChip在默认位置构造一个芯片对象
	//在粘贴时使用
	SetColor(IcChip.m_color);
	SetLineWidth(IcChip.m_iLineWidth);
	SetRotateAngle(IcChip.m_RotateAngle);
	SetName(IcChip.m_strName);
	SetIsSelected(IcChip.m_IsSelected);
	m_ChipNum = IcChip.m_ChipNum ;
	m_Encapsulate = IcChip.m_Encapsulate ;
	m_StCurrent = IcChip.m_StCurrent ;
	m_StPower = IcChip.m_StPower ;
	//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=3E18E0D10101
CIcChip::CIcChip(CPoint *pt)
{
	/*由于需要把新生成的元器件对象的m_Rect左上角坐标设置为*/
	/*鼠标点按处的坐标转换成逻辑坐标后的值,并且初始化m_Rect的右下角坐标*/
	/*所以将这一系列的初始化操作加到了CIcChip(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=3E18E0D100FF
void CIcChip::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+width*0.25),(int)(m_Rect.top + height*0.1));
	pDC->Rectangle((int)(m_Rect.left+width*0.25),(int)(m_Rect.top + height*0.15),(int)(m_Rect.left + width*0.75),(int)(m_Rect.top + height*0.45));

	/*the left two lines*/
	pDC->MoveTo(m_Rect.left,(int)(m_Rect.top + height *0.25));
	pDC->LineTo((int)(m_Rect.left+width*0.25),(int)(m_Rect.top + height *0.25));

	pDC->MoveTo (m_Rect.left,(int)(m_Rect.top + height*0.35));
	pDC->LineTo((int)(m_Rect.left+width*0.25),(int)(m_Rect.top + height*0.35));
	/*end of the left two lines*/

	/*the right two lines*/
	pDC->MoveTo((int)(m_Rect.left+width*0.75),(int)(m_Rect.top +height*0.25));
	pDC->LineTo((int)(m_Rect.left +width),(int)(m_Rect.top +height*0.25));

	pDC->MoveTo((int)(m_Rect.left+width*0.75),(int)(m_Rect.top +height*0.35));
	pDC->LineTo((int)(m_Rect.left +width),(int)(m_Rect.top +height*0.35));
	/*end of the right two lines*/

	/*the top three lines*/
	pDC->MoveTo((int)(m_Rect.left+width*0.35),m_Rect.top);
	pDC->LineTo((int)(m_Rect.left +width*0.35),(int)(m_Rect.top +height*0.15));
	
	pDC->MoveTo((int)(m_Rect.left+width*0.5),m_Rect.top);
	pDC->LineTo((int)(m_Rect.left +width*0.5),(int)(m_Rect.top +height*0.15));

	pDC->MoveTo((int)(m_Rect.left+width*0.65),m_Rect.top);
	pDC->LineTo((int)(m_Rect.left +width*0.65),(int)(m_Rect.top +height*0.15));
	/*end of the top three lines*/

	/*the bottom three lines*/
	pDC->MoveTo((int)(m_Rect.left+width*0.35),(int)(m_Rect.top+height *0.45));
	pDC->LineTo((int)(m_Rect.left +width*0.35),(int)(m_Rect.top +height*0.6));
	
	pDC->MoveTo((int)(m_Rect.left+width*0.5),(int)(m_Rect.top+height*0.45));
	pDC->LineTo((int)(m_Rect.left +width*0.5),(int)(m_Rect.top +height*0.6));

	pDC->MoveTo((int)(m_Rect.left+width*0.65),(int)(m_Rect.top+height*0.45));
	pDC->LineTo((int)(m_Rect.left +width*0.65),(int)(m_Rect.top +height*0.6));
	/*end of the bottom three lines*/

	pDC->SetBkMode(TRANSPARENT);
	pDC->TextOut((int)(m_Rect.left + width * 0.4),(int)(m_Rect.top + height*0.6),name);

	pDC->SelectObject(pOldPen);
}

//##ModelId=3E18E0D100FB
void CIcChip::GetNumInNameSer(CObList *pObList, CObList *pNumSer, int *pMax)
{
	*pMax = 0;
	POSITION pos = pObList->GetHeadPosition();	
	CObject *pObject;
	CIcChip *pIcChip;
	CString strName;
	CString strLastName;	
	while (pos != NULL)
	{
		pObject = pObList->GetAt(pos);
		if (pObject->IsKindOf(RUNTIME_CLASS(CIcChip)))
		{
			pIcChip = (CIcChip*)pObject;
			strName = pIcChip->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=3E18E0D100CA
void CIcChip::Serialize(CArchive &ar)
{
	CComponent::Serialize(ar);
	//需要序列化m_RectLP
	if (ar.IsStoring())
	{
		ar<<m_Rect<<m_RectLP<<m_RectTracker.m_nStyle<<m_ChipNum<<m_Encapsulate<<m_StCurrent<<m_StPower;
		//<<m_RectTracker.m_rect
	}
	else
	{
		ar>>m_Rect>>m_RectLP>>m_RectTracker.m_nStyle>>m_ChipNum>>m_Encapsulate>>m_StCurrent>>m_StPower;
		//>>m_RectTracker.m_rect
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -