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

📄 resistor.cpp

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

#include "stdafx.h"
#include "DrawChip.h"
#include "Resistor.h"
#include "transistor.h"
#include "component.h"

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

IMPLEMENT_SERIAL(CResistor, CComponent,0)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//##ModelId=3E18E0CC013B
CResistor::CResistor()
{	
	//m_Rect = CRect(0,0,100,60);	
	m_Rect = CRect(0,0,2000,-1000);	
	m_RectLP = m_Rect;
	m_RectTracker.m_rect = m_Rect;
	m_RectTracker.m_nStyle = CRectTracker::resizeOutside;
	SetName("R");
}

//##ModelId=3E18E0CC013C
CResistor::~CResistor()
{

}

//##ModelId=3E18E0CB039A
CString CResistor::GetReType()
{
	return m_ReType;
}

//##ModelId=3E18E0CB0399
CString CResistor::GetReValue()
{
	return m_ReValue;
}

//##ModelId=3E18E0CB0368
void CResistor::SetReType(CString &ReType)
{
	m_ReType = ReType;
}

//##ModelId=3E18E0CB0366
void CResistor::SetReValue(CString &ReValue)
{
	m_ReValue = ReValue;
}

//##ModelId=3E18E0CB032F
CString CResistor::CalculateName(CObList *pObList)
//在绘制时系统给出的默认名称,这个名称是根据当前链表中
//对象情况而定的,具体功能同VB等开发工具中拖拉控件时产生
//名称的情况
{
	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 "R"+ CString(buf);

	//return "R" + CString(buf);
	//return "Rn";
}

//##ModelId=3E18E0CB032D
void CResistor::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.5));	
	pDC->LineTo((int)(m_Rect.left +width  * 0.3),(int)(m_Rect.top + height*0.5));
	pDC->Rectangle ((int)(m_Rect.left + width * 0.3 ),(int)(m_Rect.top + height * 0.25),
		            (int)(m_Rect.left + width * 0.7 ),(int)( m_Rect.top + height * 0.75));
	pDC->MoveTo ((int)(m_Rect.left + width * 0.7) ,(int)(m_Rect.top + height * 0.5));
	pDC->LineTo((int)(m_Rect.left + width) ,(int)(m_Rect.top + height * 0.5));

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

	pDC->SelectObject(pOldPen);
}

//##ModelId=3E18E0CB032B
void CResistor::PrepareDrawChipDC(CDC *pDC)
{

}

//##ModelId=3E18E0CB0301
void CResistor::Serialize(CArchive &ar)
{
	CComponent::Serialize(ar);
	//需要序列化m_RectLP
	if (ar.IsStoring())
	{
		ar<<m_Rect<<m_RectLP<<m_RectTracker.m_nStyle<<m_ReType<<m_ReValue;
		//<<m_RectTracker.m_rect
	}
	else
	{
		ar>>m_Rect>>m_RectLP>>m_RectTracker.m_nStyle>>m_ReType>>m_ReValue;
		//>>m_RectTracker.m_rect
	}
}

//##ModelId=3E18E0CB02FF
CResistor::CResistor(CPoint *pt)
{
	/*由于需要把新生成的元器件对象的m_Rect左上角坐标设置为*/
	/*鼠标点按处的坐标转换成逻辑坐标后的值,并且初始化m_Rect的右下角坐标*/
	/*所以将这一系列的初始化操作加到了CResistor(CPoint *pt)构造函数中*/
	m_Rect.left = pt->x;
	m_Rect.top = pt->y;
	//m_Rect.right = m_Rect.left  + 100;
	//m_Rect.bottom = m_Rect.top + 60;	
	m_Rect.right = m_Rect.left  + 2000;
	m_Rect.bottom = m_Rect.top - 1000;
	m_RectLP = m_Rect;
	m_RectTracker.m_rect = m_Rect;
	m_RectTracker.m_nStyle = CRectTracker::resizeOutside;
}

//##ModelId=3E18E0CB02FB
void CResistor::GetNumInNameSer(CObList *pObList,CObList *pNumSer,int *pMax)
//取得链表中电阻名称是以R或r开头,后面为数字的名称中的数字序列
//其中pNumSer存放数字序列,pMax存放的是数字中的最大值
{
	*pMax = 0;
	POSITION pos = pObList->GetHeadPosition();	
	CObject *pObject;
	CResistor *pResistor;
	CString strName;
	CString strLastName;	
	while (pos != NULL)
	{
		pObject = pObList->GetAt(pos);
		if (pObject->IsKindOf(RUNTIME_CLASS(CResistor)))
		{
			pResistor = (CResistor*)pObject;
			strName = pResistor->GetName();
			if ((strName.GetAt(0) == 'R') || (strName.GetAt(0) == 'r'))
			//如果名称的第一个字母是R或r
			{
				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=3E18E0CB02F9
CResistor::CResistor(RESISTOR Resistor)
{
	//根据结构体Resistor在默认位置构造一个电阻对象
	//在粘贴时使用
	SetColor(Resistor.m_color);
	SetLineWidth(Resistor.m_iLineWidth);
	SetRotateAngle(Resistor.m_RotateAngle);
	SetName(Resistor.m_strName);
	SetIsSelected(Resistor.m_IsSelected);
	m_ReType = Resistor.m_ReType;
	m_ReValue = Resistor.m_ReValue;
	//m_Rect = CRect(0,0,100,60);	
	//m_Rect = CRect(0,0,2000,-1000);	
	/*由于在MM_HIMETRIC映射模式下视图的原点在左上角,有一部分是被工具条*/
	/*掩盖住的,而且也应该把复制过来的元器件图形放在可打印的地方,所以*/
	/*它的外接矩形的左上角定义为CPoint(1000,-1000)即距离打印纸左边1cm*/
	/*距离上边框1cm处*/
	m_Rect = CRect(1000,-1000,3000,-2000);	
	m_RectLP = m_Rect;
	m_RectTracker.m_rect = m_Rect;
	m_RectTracker.m_nStyle = CRectTracker::resizeOutside;	
}


//##ModelId=3E18E0CB02BE
void CResistor::CopyReToStruRe(RESISTOR &Resistor)
/*把对象的数据赋值给结构,在复制功能时用到*/
{
	lstrcpy(Resistor.m_strClassType, "Resistor");			
	Resistor.m_color = this->GetColor();
	Resistor.m_iLineWidth = this->GetLineWidth();
	Resistor.m_IsSelected = this->GetIsSelected();			
	lstrcpy(Resistor.m_ReType , this->GetReType());
	lstrcpy(Resistor.m_ReValue , this->GetReValue());
	Resistor.m_RotateAngle =this->GetRotateAngle();			
	lstrcpy(Resistor.m_strName , this->GetName());
}

⌨️ 快捷键说明

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