www.pudn.com > my2cadtest07261930.rar > Circle.cpp, change:2006-07-25,size:7716b


// Circle.cpp: implementation of the CCircle class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Circle.h" 
#include "math.h" 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CCircle::CCircle(CSuperPoint begPT,CSuperPoint endPT) 
{ 
	this->m_whatshape=Circle; 
	m_radius = begPT.DistanceTo(endPT); 
 
	POINT potC(begPT.GetPoint()); 
	POINT potT = {begPT.GetPoint().x,begPT.GetPoint().y - m_radius}; 
	POINT potR = {begPT.GetPoint().x + m_radius,begPT.GetPoint().y}; 
	POINT potB = {begPT.GetPoint().x,begPT.GetPoint().y + m_radius}; 
	POINT potL = {begPT.GetPoint().x - m_radius,begPT.GetPoint().y}; 
	 
	m_point[0] = potC; 
	m_point[1] = potT; 
	m_point[2] = potR; 
	m_point[3] = potB; 
	m_point[4] = potL; 
	 
	m_pointcount = 5; 
 
	this->CalcCenterPoint(); 
	this->CalcCenterRECT(); 
} 
 
 
CCircle::CCircle(POINT *point,int ptcount, LOGPEN &pen, LOGBRUSH &brush):CShape() 
{ 
    this->CalcFivePoint(point[0],point[1]); 
	 
	m_penstruct.lopnColor=pen.lopnColor; 
	m_penstruct.lopnStyle=pen.lopnStyle; 
	m_penstruct.lopnWidth.x=pen.lopnWidth.x; 
	m_penstruct.lopnWidth.y=pen.lopnWidth.y; 
 
	m_brushstruct.lbColor=brush.lbColor; 
	m_brushstruct.lbStyle=brush.lbStyle; 
	m_brushstruct.lbHatch=brush.lbHatch; 
 
	m_pointcount=5; 
	this->m_whatshape=Circle; 
	 
	this->CalcCenterPoint(); 
	this->CalcCenterRECT(); 
 
} 
 
void CCircle::CalcFivePoint(POINT LTpt,POINT RBpt) 
{ 
 
    m_radius=abs(LTpt.x-RBpt.x)/2; 
	 
    POINT potC = {(LTpt.x+RBpt.x)/2,(LTpt.y+RBpt.y)/2}; 
	POINT potT = {potC.x,potC.y - m_radius}; 
	POINT potR = {potC.x + m_radius,potC.y}; 
	POINT potB = {potC.x,potC.y + m_radius}; 
	POINT potL = {potC.x - m_radius,potC.y}; 
 
    m_point[0] = potC; 
	m_point[1] = potT; 
	m_point[2] = potR; 
	m_point[3] = potB; 
	m_point[4] = potL; 
	 
} 
 
CCircle::~CCircle() 
{ 
 
} 
 
CShape * CCircle::GetShapeCopy() 
{ 
	CShape * pcopy=new CCircle; 
	*pcopy=*this;   //值拷贝 
   
	return pcopy ; 
} 
 
void CCircle::DrawSelf(HDC &hdc) 
{ 
	POINT ptCenter = m_point[0]; 
	int nLeft   = ptCenter.x - m_radius; 
	int nTop    = ptCenter.y - m_radius; 
	int nRight  = ptCenter.x + m_radius; 
	int nBottom = ptCenter.y + m_radius; 
	::Ellipse(hdc,nLeft,nTop,nRight,nBottom); 
 
	if(m_selected)   //如果这是一个被选中图形 在操作后的图形上打上标记 
   { 
    m_point[0].SetStatus(); 
    m_point[1].SetStatus(); 
    m_point[2].SetStatus(); 
    m_point[3].SetStatus(); 
    m_point[4].SetStatus(); 
    SetMark(hdc); 
    Lock(hdc); 
	} 
 
 
} 
 
bool CCircle::IsBound(CSuperPoint &curPt) 
{ 
    if( m_pointcount < 1 ) 
    { 
        return false; 
    } 
	bool isSelected = false; 
	isSelected = curPt.IsOnLine(m_point[0],m_radius); 
	return isSelected; 
} 
 
void CCircle::ClearMark(HDC &hdc) 
{ 
	for(int nI=0;nI<m_pointcount;nI++) 
	{ 
	 m_point[nI].ClearMark(hdc); 
	} 
} 
 
void CCircle::SetMark(HDC &hdc) 
{ 
   for(int nI=0;nI<m_pointcount;nI++) 
   { 
    m_point[nI].SetMark(hdc); 
   } 
} 
 
void CCircle::UnLock(HDC &hdc) 
{ 
	this->m_selected = false; 
    for(int nI=0;nI<m_pointcount;nI++) 
	{ 
	 m_point[nI].ClearLockMark(hdc); 
	} 
} 
 
void CCircle::Lock(HDC &hdc) 
{ 
	this->m_selected = true;	//已锁定 
	for(int nI=0;nI<m_pointcount;nI++) 
	{ 
	 m_point[nI].SetLockMark(hdc); 
	} 
} 
 
void CCircle::MoveSelf(HDC &hdc, int dx, int dy) 
{ 
	penattrib->GetPen(hdc,true); 
 
    if(m_operStatus==FirstOper) 
	{	 		 
      m_operStatus=NoFirstOper;	 
	} 
    else 
	{ 
      PreDraw(hdc);  
	} 
	 
    for(int nI=0;nI<m_pointcount;nI++) 
	{ 
		m_copypoint[nI]=m_point[nI]; 
        m_copypoint[nI].Move(dx,dy); 
	} 
	 m_radius=m_point[0].DistanceTo(m_point[1]); 
	 PreDraw(hdc); 
    penattrib->ReleasePen(true); 
	 
} 
 
void CCircle::ZoomSelf(HDC &hdc, double scale) 
{ 
	penattrib->GetPen(hdc,true); 
 
    if(m_operStatus==FirstOper) 
	{	 		 
      m_operStatus=NoFirstOper;	 
	} 
    else 
	{ 
      PreDraw(hdc);  
	} 
	   
	m_copypoint[0]=m_point[0]; 
        
	POINT potT = {m_copypoint[0].GetPoint().x,m_copypoint[0].GetPoint().y - m_radius}; 
	POINT potR = {m_copypoint[0].GetPoint().x + m_radius,m_copypoint[0].GetPoint().y}; 
	POINT potB = {m_copypoint[0].GetPoint().x,m_copypoint[0].GetPoint().y + m_radius}; 
	POINT potL = {m_copypoint[0].GetPoint().x - m_radius,m_copypoint[0].GetPoint().y}; 
	m_copypoint[1] = potT; 
	m_copypoint[2] = potR; 
	m_copypoint[3] = potB; 
	m_copypoint[4] = potL; 
						 
//  m_copypoint[nI].ZoomIn(scale,m_point[0]); 
	 
    m_radius=m_point[0].DistanceTo(m_point[1]); 
	m_radius = scale*m_radius; 
	PreDraw(hdc); 
 
    penattrib->ReleasePen(true); 
} 
 
void CCircle::RotateSelf(HDC &hdc, double angle) 
{ 
	penattrib->GetPen(hdc,true); 
 
    if(m_operStatus==FirstOper) 
	{	 		 
      m_operStatus=NoFirstOper;	 
	} 
    else 
	{ 
      PreDraw(hdc);  
	} 
	 
    for(int nI=0;nI<m_pointcount;nI++) 
	{ 
		m_copypoint[nI]=m_point[nI]; 
        m_copypoint[nI].RotateOnFix(this->GetCenterPoint(),angle); 
	}	 
	 PreDraw(hdc);  
    penattrib->ReleasePen(true); 
 
} 
 
void CCircle::MirrorSelf(HDC &hdc, double angle, CSuperPoint &ptPos) 
{ 
	penattrib->GetPen(hdc,true); 
 
    if(m_operStatus==FirstOper) 
	{	 		 
      m_operStatus=NoFirstOper;	 
	} 
    else 
	{ 
      PreDraw(hdc);  
	} 
//	m_copypoint[0]=m_point[0]; 
//	m_copypoint[0].MirrorOnAxis(angle,ptPos); 
   for(int nI=0;nI<m_pointcount;nI++) 
	{ 
	   m_copypoint[nI]=m_point[nI]; 
       m_copypoint[nI].MirrorOnAxis(angle,ptPos); 
	} 
    m_radius = m_point[0].DistanceTo(m_point[1]); 
	 PreDraw(hdc); 
    penattrib->ReleasePen(true); 
	 
} 
 
void CCircle::EnterOper(HDC &hdc) 
{ 
  	   
     for(int nI=0;nI<m_pointcount;nI++) 
	 { 
	 m_point[nI]=m_copypoint[nI];	   
	 } 
	 ::InvalidateRect(g_hwnd,&m_rect,true); 
 
     penattrib->GetPen(hdc,false,false); 
     DrawSelf(hdc);  
     penattrib->ReleasePen(false,false); 
	  
	m_operStatus=FirstOper; 
	this->CalcCenterPoint(); 
	this->CalcCenterRECT(); 
    ::InvalidateRect(g_hwnd,&m_rect,true); 
} 
 
void CCircle::PreDraw(HDC &hdc) 
{ 
     
	POINT ptCenter = m_copypoint[0]; 
	int nLeft   = ptCenter.x - m_radius; 
	int nTop    = ptCenter.y - m_radius; 
	int nRight  = ptCenter.x + m_radius; 
	int nBottom = ptCenter.y + m_radius; 
	::Ellipse(hdc,nLeft,nTop,nRight,nBottom); 
 
 
} 
 
void CCircle::SavetoEmf(HDC &hdc) 
{ 
 	if	( 
		penattrib->GetPenStyle().lopnColor!=m_penstruct.lopnColor|| 
		penattrib->GetPenStyle().lopnWidth.x!=m_penstruct.lopnWidth.x|| 
		penattrib->GetPenStyle().lopnStyle!=m_penstruct.lopnStyle 
		) 
		{ 
            penattrib->ReleasePen(false); 
			penattrib->SetPenStyle(m_penstruct); 
			penattrib->GetPen(hdc,false); 
		} 
 
	if	( 
		penattrib->GetBrushStyle().lbColor!=m_brushstruct.lbColor|| 
		penattrib->GetBrushStyle().lbHatch!=m_brushstruct.lbHatch|| 
		penattrib->GetBrushStyle().lbStyle!=m_brushstruct.lbStyle 
		) 
		{ 
		    penattrib->ReleaseBrush(); 
			penattrib->SetBrushStyle(m_brushstruct); 
			penattrib->GetBrush(hdc); 
		} 
 
	int nLeft   = m_point[0].GetPoint().x - m_radius; 
	int nTop    = m_point[0].GetPoint().y - m_radius; 
	int nRight  = m_point[0].GetPoint().x + m_radius; 
	int nBottom = m_point[0].GetPoint().y + m_radius; 
	::Ellipse(hdc,nLeft,nTop,nRight,nBottom); 
 
} 
 
void CCircle::SavetoTXT() 
{ 
 
} 
 
void CCircle::CalcCenterPoint() 
{ 
	m_centerpoint = m_point[0]; 
} 
 
void CCircle::CalcCenterRECT() 
{ 
  
	m_rect.left = m_centerpoint.GetPoint().x - m_radius - 6; 
	m_rect.top  = m_centerpoint.GetPoint().y - m_radius - 6; 
	m_rect.right = m_centerpoint.GetPoint().x + m_radius + 6; 
	m_rect.bottom = m_centerpoint.GetPoint().y + m_radius + 6; 
 
}