www.gusucode.com > VC++开发的电路板画图设计软件源代码源码程序 > VC++开发的电路板画图设计软件源代码源码程序\code\Eline.cpp

    //Download by http://www.NewXing.com
// Eline.cpp: implementation of the CResis class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Pointtest.h"
#include "Eline.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CResis::CResis(int nType,CBaseList* pBaseList) : CBase(ID_RESISTANCE,pBaseList)
{
	left = CPoint(0,0);
	right = CPoint(0,0);
	Content_Of_Ob = "R";
	AddString(ID_RESISTANCE);
	Value = 1;
}
CResis::CResis(CBase* pp1,CBase* pp2,CBaseList* pBaseList) : CBase(ID_RESISTANCE,pBaseList)
{
	p1 = pp1;
	p2 = pp2;
	AddSon(p1);
	AddSon(p2);
	left = CPoint(0,0);
	right = CPoint(0,0);
	Content_Of_Ob = "R";
	AddString(ID_RESISTANCE);
	Value = 1;
}
CResis::~CResis()
{
}
void CResis::Draw(CDC* pDC)
{
	if(IsSelected()){
		CPen pen(PS_SOLID, 2,RED);
		CPen *Oldpen = pDC->SelectObject(&pen);
		pDC->SetBkMode(TRANSPARENT);
		pDC->MoveTo(left);
		pDC->LineTo(p1->CenterPoint);
		pDC->MoveTo(right);
		pDC->LineTo(p2->CenterPoint);
		pDC->MoveTo(aa);
		pDC->LineTo(dd);
		pDC->LineTo(bb);
		pDC->LineTo(cc);
		pDC->LineTo(aa);
		pDC->SelectObject(Oldpen);
	}else{
		CPen pen(PS_SOLID, 2,BLACK);
		CPen *Oldpen = pDC->SelectObject(&pen);
		pDC->SetBkMode(TRANSPARENT);
		pDC->MoveTo(left);
		pDC->LineTo(p1->CenterPoint);
		pDC->MoveTo(right);
		pDC->LineTo(p2->CenterPoint);
		pDC->MoveTo(aa);
		pDC->LineTo(dd);
		pDC->LineTo(bb);
		pDC->LineTo(cc);
		pDC->LineTo(aa);
		pDC->SelectObject(Oldpen);
	}
	TextOut(pDC);
}
void CResis::SetPoint(CPoint pp)
{
	TextPoint = left = right = CenterPoint = pp;
	left = pp - CPoint(20,0);
	right = pp + CPoint(20,0);
	p1->CenterPoint = pp - CPoint(30,0);
	p2->CenterPoint = pp + CPoint(29,0);
	cc = aa = left;
	dd = bb = right;
	aa.Offset(CSize(0,10));
	cc.Offset(CSize(0,-10));
	bb.Offset(CSize(0,-10));
	dd.Offset(CSize(0,10));
	RotateCell(TotalAngle);
}
void CResis::OffSet(CSize size)
{
	CenterPoint.Offset(size);
	left.Offset(size);
	right.Offset(size);
	p1->OffSet(size);
	p2->OffSet(size);
	aa.Offset(size);
	bb.Offset(size);
	cc.Offset(size);
	dd.Offset(size);
}
CRect CResis::GetGraphRect()
{
	CPoint up_left,down_right;
	up_left = down_right = CenterPoint;
	up_left.Offset(-20,-10);
	down_right.Offset(20,10);
	return CRect(up_left,down_right);	
}
void CResis::RotateCell(double angle)
{
	left = Rotate(angle,left);
	right = Rotate(angle,right);
	p1->CenterPoint = Rotate(angle,p1->CenterPoint);
	p2->CenterPoint = Rotate(angle,p2->CenterPoint);
	aa = Rotate(angle,aa);
	bb = Rotate(angle,bb);
	cc = Rotate(angle,cc);
	dd = Rotate(angle,dd);
}