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

📄 arc.cpp

📁 通过可执行文件中的菜单“绘图”
💻 CPP
字号:
#include "stdafx.h"
#include "math.h"

#include "VCad.h"
#include "VCadDoc.h"
#include "VCadView.h"

#include "Entity.h"

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

//	定义 CArc 类

IMPLEMENT_SERIAL(CArc, CEntity, 0)

CArc::CArc()
{
	Init();
}

CArc::CArc(const CArc& arc)
{
	m_center = arc.m_center;
	m_begin  = arc.m_begin ;
	m_end    = arc.m_end ;
}

CArc::CArc(const Position& center,const Position& pos1, const Position& pos2)
{
	Init();
	m_center = center ;
	m_begin = pos1 ;
	double  radius = m_center.Distance(m_begin) ;

	double	angle1 = GetAngleToXAxis(center, pos1);	
	double  angle2 = GetAngleToXAxis(center, pos2);

	m_begin = pos1;
	m_end.x = radius * cos(angle2) + m_center.x ;
	m_end.y = radius * sin(angle2) + m_center.y ;
}

CArc::~CArc()
{
}

CEntity*	CArc::Copy()
{
	CArc*	pEntity = new CArc(m_center, m_begin, m_end);
	return pEntity;
}

void CArc::Init()
{
	CEntity::Init();

	m_type = etArc;
	m_center.Init();
	m_begin.Init() ;
	m_end.Init() ;
}

int	CArc::GetType()
{
	return etArc;
}

Position CArc::GetEndPos()
{
	return m_end;
}

Position CArc::GetStartPos()
{
	return m_begin;
}
Position CArc::GetCenterPos()
{
	return m_center ;
}

/////////////////////
void CArc::Draw(CDC * pDC, int drawMode /* = dmNormal */)
{
	// 如果起始点和终止点重合,则不进行绘制
	if(m_begin.IsSame(m_end))
		return;
	// 圆弧半径
	double radius = m_center.Distance(m_begin) ;
	// 得到圆弧的外接矩形框
	Position	offset(-radius,radius);
	Position	ltpos = m_center + offset;
	Position	rbpos = m_center - offset;
	// 屏幕坐标的圆心点、起始点和终止点
	CPoint sltp, srbp, ssp, sep ;
	// 将世界坐标转化为屏幕坐标
	g_pView->WorldtoScreen(m_end, sep ) ;
	g_pView->WorldtoScreen(m_begin, ssp) ;
	g_pView->WorldtoScreen(ltpos,sltp) ;
	g_pView->WorldtoScreen(rbpos,srbp) ;
	// 得到原来的绘图模式	
	int		n = GetROP2(pDC->GetSafeHdc());
	// 创建画笔的原则:
	// 如果在正常的绘图模式下,使用成员变量创建画笔
	// 如果是其它的模式,使用全局函数"SetDrawEnvir"创建画笔
	CPen	pen; 
	if( drawMode == dmNormal ) 
		pen.CreatePen(m_lineStyle,m_lineWidth,m_color) ;
	else
		::SetDrawEnvir(pDC, drawMode, &pen);
	// 得到原来的画笔
	CPen* pOldPen = pDC->SelectObject(&pen) ;
	pDC->SetMapMode(MM_LOENGLISH); 
	pDC->SelectStockObject(NULL_BRUSH) ;
	// 根据屏幕坐标绘制图元,
	//提示:圆弧按逆时针绘制
	pDC->Arc(sltp.x,sltp.y,srbp.x,srbp.y ,ssp.x, ssp.y, sep.x, sep.y) ;
	// 恢复原来的画笔 
	pDC->SelectObject(pOldPen) ;
	// 恢复原来的绘图模式
	pDC->SetROP2(n);
}

void CArc::Serialize(CArchive& ar) 
{
	CEntity::Serialize(ar);
	m_center.Serialize(ar);
	m_begin.Serialize(ar) ;
	m_end.Serialize(ar) ;
}

⌨️ 快捷键说明

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