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

📄 diode.cpp

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

#include "stdafx.h"
#include "DrawChip.h"
#include "Diode.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CDiode, CComponent,0)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//##ModelId=3E18E0E60203
CDiode::CDiode()
{

}

//##ModelId=3E18E0E60230
CDiode::~CDiode()
{

}

//##ModelId=3E18E0E60201
void CDiode::SetFrequence(CString &Frequence)
{
	m_strFrequence = Frequence;
}

//##ModelId=3E18E0E60200
CString CDiode::GetFrequence()
{
	return m_strFrequence;
}

//##ModelId=3E18E0E601FE
void CDiode::SetPower(CString &Power)
{
	m_strPower = Power;
}

//##ModelId=3E18E0E601C4
CString CDiode::GetPower()
{
	return m_strPower;
}

//##ModelId=3E18E0E601C2
void CDiode::SetSwitch(CString &Switch)
{
	m_strSwitch = Switch;
}

//##ModelId=3E18E0E60195
CString CDiode::GetSwitch()
{
	return m_strSwitch;
}

//##ModelId=3E18E0E60193
void CDiode::SetType(CString &Type)
{
	m_strType = Type;
}

//##ModelId=3E18E0E60192
CString CDiode::GetType()
{
	return m_strType;
}

//##ModelId=3E18E0E60190
void CDiode::Serialize(CArchive &ar)
{
	CComponent::Serialize(ar);
	//需要序列化m_RectLP
	if (ar.IsStoring())
	{
		ar<<m_Rect<<m_RectLP<<m_RectTracker.m_nStyle<<m_strFrequence<<m_strPower<<m_strSwitch<<m_strType;
		//<<m_RectTracker.m_rect
	}
	else
	{
		ar>>m_Rect>>m_RectLP>>m_RectTracker.m_nStyle>>m_strFrequence>>m_strPower>>m_strSwitch>>m_strType;
		//>>m_RectTracker.m_rect
	}
}

//##ModelId=3E18E0E60124
CDiode::CDiode(DIODE Diode)
{
	//根据结构体Diode在默认位置构造一个二极管对象
	//在粘贴时使用
	SetColor(Diode.m_color);
	SetLineWidth(Diode.m_iLineWidth);
	SetRotateAngle(Diode.m_RotateAngle);
	SetName(Diode.m_strName);
	SetIsSelected(Diode.m_IsSelected);
	m_strFrequence = Diode.m_strFrequence ;
	m_strPower = Diode.m_strPower ;
	m_strType = Diode.m_strType ;
	m_strSwitch = Diode.m_strSwitch ;
	//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=3E18E0E60122
CDiode::CDiode(CPoint *pt)
{
	/*由于需要把新生成的元器件对象的m_Rect左上角坐标设置为*/
	/*鼠标点按处的坐标转换成逻辑坐标后的值,并且初始化m_Rect的右下角坐标*/
	/*所以将这一系列的初始化操作加到了CDiode(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=3E18E0E600E9
void CDiode::GetNumInNameSer(CObList *pObList, CObList *pNumSer, int *pMax)
{
	*pMax = 0;
	POSITION pos = pObList->GetHeadPosition();	
	CObject *pObject;
	CDiode *pDiode;
	CString strName;
	CString strLastName;	
	while (pos != NULL)
	{
		pObject = pObList->GetAt(pos);
		if (pObject->IsKindOf(RUNTIME_CLASS(CDiode)))
		{
			pDiode = (CDiode*)pObject;
			strName = pDiode->GetName();
			if ((strName.GetAt(0) == 'D') || (strName.GetAt(0) == 'd'))
			//如果名称的第一个字母是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
			//名称的第一个字母不是R或r
			{
			}
		}
		else		
		{
		}
		pObList->GetNext(pos);
	}	
}

//##ModelId=3E18E0E600E7
CString CDiode::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 "D"+ CString(buf);
}

//##ModelId=3E18E0E600B8
void CDiode::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.25));
	pDC->LineTo((int)(m_Rect.left + width*0.3),(int)(m_Rect.top + height*0.25));
	
	pDC->MoveTo((int)(m_Rect.left +width*0.3),(int)(m_Rect.top));
	pDC->LineTo((int)(m_Rect.left +width*0.3),(int)(m_Rect.top+height*0.5 ));

	CPoint pt[3];
	pt[0] = CPoint((int)(m_Rect.left + width*0.3),(int)(m_Rect.top + height*0.25));
	pt[1] = CPoint((int)(m_Rect.left+width*0.7),(int)(m_Rect.top));
	pt[2] = CPoint((int)(m_Rect.left+width*0.7),(int)(m_Rect.top + height*0.5));
	pDC->Polygon(pt,3);

	pDC->MoveTo((int)(m_Rect.left+width*0.7),(int)(m_Rect.top +height*0.25));
	pDC->LineTo((int)(m_Rect.left +width),(int)(m_Rect.top +height*0.25));

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

	pDC->SelectObject(pOldPen);
}

//##ModelId=3E18E0E600B6
void CDiode::CopyDiToStrucDi(DIODE &Diode)
{
	lstrcpy(Diode.m_strClassType, "Diode");			
	Diode.m_color = this->GetColor();
	Diode.m_iLineWidth = this->GetLineWidth();
	Diode.m_IsSelected = this->GetIsSelected();
	Diode.m_RotateAngle =this->GetRotateAngle();						
	lstrcpy(Diode.m_strName , this->GetName());
	lstrcpy(Diode.m_strType , this->GetType());				
	lstrcpy(Diode.m_strFrequence , this->GetFrequence());
	lstrcpy(Diode.m_strPower , this->GetPower());
	lstrcpy(Diode.m_strSwitch , this->GetSwitch());
}

⌨️ 快捷键说明

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