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


// Ellipse.cpp: implementation of the CEllipse class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Ellipse.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CEllipse::CEllipse() 
{ 
 
} 
 
CEllipse::~CEllipse() 
{ 
 
} 
 
CEllipse::CEllipse(CSuperPoint begpt, CSuperPoint endpt):CShape(), 
			m_upper_left(begpt),m_bottom_right(endpt) 
{ 
	m_pointcount=13; 
	this->m_whatshape=Ellipse; 
	this->CalcSelf(); 
	this->CalcCenterPoint(); 
    this->CalcCenterRECT(); 
} 
 
void CEllipse::PreDraw(HDC &hdc) 
{ 
	POINT PT[13]; 
	for(int i=0;i<13;i++) 
	{ 
		PT[i]=m_copypoint[i].GetPoint(); 
	} 
	PolyBezier(hdc, PT, 13); 
 
} 
 
void CEllipse::DrawSelf(HDC &hdc) 
{ 
	POINT PT[13]; 
	for(int i=0;i<13;i++) 
	{ 
		PT[i]=m_point[i].GetPoint(); 
	} 
	PolyBezier(hdc, PT, 13); 
 
	if(m_selected)   //如果这是一个被选中图形 在操作后的图形上打上标记 
   { 
    for(int i=0;i<12;i++) 
	{ 
     m_point[i].SetStatus(); 
    } 
	 m_centerpoint.SetStatus(); 
    SetMark(hdc); 
    Lock(hdc); 
   } 
 
 
} 
 
void CEllipse::CalcCenterPoint() 
{ 
	POINT tmpPt; 
    tmpPt.x=(m_point[0].GetPoint().x+m_point[6].GetPoint().x)/2; 
	tmpPt.y=(m_point[0].GetPoint().y+m_point[6].GetPoint().y)/2; 
//	tmpPt.x=(m_upper_left.GetPoint().x+m_bottom_right.GetPoint().x)/2; 
//	tmpPt.y=(m_upper_left.GetPoint().y+m_bottom_right.GetPoint().y)/2; 
	m_centerpoint=tmpPt; 
 
} 
 
void CEllipse::CalcCenterRECT() 
{ 
	int maxX,maxY; 
	int minX,minY; 
	maxX=maxY=-1; 
	minX=minY=65536; 
	for(int i=0;i<13;i++) 
	{ 
		if(m_point[i].GetPoint().x>maxX) 
		{ 
			maxX=m_point[i].GetPoint().x; 
		} 
		if(m_point[i].GetPoint().y>maxY) 
		{ 
			maxY=m_point[i].GetPoint().y; 
		} 
		if(m_point[i].GetPoint().x<minX) 
		{ 
			minX=m_point[i].GetPoint().x; 
		} 
		if(m_point[i].GetPoint().y<minY) 
		{ 
			minY=m_point[i].GetPoint().y; 
		} 
		 
	} 
	m_rect.left = minX-5; 
	m_rect.top  = minY-5; 
	m_rect.right = maxX+5; 
	m_rect.bottom = maxY+5; 
 
} 
 
 
 
void CEllipse::CalcSelf() 
{ 
	const double M = 0.55228474983; 
	int left=m_upper_left.GetPoint().x; 
	int top=m_upper_left.GetPoint().y; 
	int right=m_bottom_right.GetPoint().x; 
	int bottom=m_bottom_right.GetPoint().y; 
	int dx = (int) ((right - left) * (1-M) / 2); 
	int dy = (int) ((bottom - top) * (1-M) / 2); 
	POINT PT[13]; 
	PT[ 0].x = right;            //   .   .   .   .   . 
	PT[ 0].y = (top+bottom)/2;   //       4   3   2 
	PT[ 1].x = right;            // 
	PT[ 1].y = top + dy;         //   5               1 
	PT[ 2].x = right - dx;       // 
	PT[ 2].y = top;              //   6              0,12 
	PT[ 3].x = (left+right)/2;   // 
	PT[ 3].y = top;              //   7               11 
					  // 
	PT[ 4].x = left + dx;        //       8   9   10 
	PT[ 4].y = top; 
	PT[ 5].x = left; 
	PT[ 5].y = top + dy; 
	PT[ 6].x = left; 
	PT[ 6].y = (top+bottom)/2; 
 
	PT[ 7].x = left; 
	PT[ 7].y = bottom - dy; 
	PT[ 8].x = left + dx; 
	PT[ 8].y = bottom; 
	PT[ 9].x = (left+right)/2; 
	PT[ 9].y = bottom; 
	PT[10].x = right - dx; 
	PT[10].y = bottom; 
	PT[11].x = right; 
	PT[11].y = bottom - dy; 
	PT[12].x = right; 
	PT[12].y = (top+bottom)/2; 
	 
	for(int i=0;i<13;i++) 
	{ 
		m_point[i]=PT[i]; 
	} 
 
} 
 
CShape* CEllipse::GetShapeCopy() 
{ 
	CShape * pcopy=new CEllipse; 
	*pcopy=*this;   //值拷贝 
 
	return pcopy ; 
 
} 
 
bool CEllipse::IsBound(CSuperPoint &curPt) 
{ 
	for(int nI=0;nI<m_pointcount-1;nI++) 
	{ 
		if(curPt.IsOnLine(m_point[nI],m_point[nI+1])) 
		return true; 
	}	  
 return false; 
 
} 
 
void CEllipse::ClearMark(HDC &hdc) 
{ 
	for(int nI=0;nI<m_pointcount-1;nI++) 
	   { 
		m_point[nI].ClearMark(hdc); 
	   } 
	m_centerpoint.ClearMark(hdc); 
} 
 
void CEllipse::SetMark(HDC &hdc) 
{ 
	for(int nI=0;nI<m_pointcount-1;nI++) 
   { 
    m_point[nI].SetMark(hdc); 
   } 
	m_centerpoint.SetMark(hdc); 
 
} 
 
void CEllipse::Lock(HDC &hdc) 
{ 
	this->m_selected = true;	//已锁定 
	for(int nI=0;nI<m_pointcount;nI++) 
	{ 
	 m_point[nI].SetLockMark(hdc); 
	} 
	m_centerpoint.SetLockMark(hdc); 
} 
 
void CEllipse::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); 
	} 
//	m_centerpoint.RotateOnFix(this->GetCenterPoint(),angle); 
	 PreDraw(hdc);  
 
 
} 
 
void CEllipse::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_centerpoint.Move(dx,dy); 
	 PreDraw(hdc);  
 
} 
 
void CEllipse::UnLock(HDC &hdc) 
{ 
	this->m_selected = false; 
    for(int nI=0;nI<m_pointcount;nI++) 
	{ 
	 m_point[nI].ClearLockMark(hdc); 
	} 
	m_centerpoint.ClearLockMark(hdc); 
} 
 
void CEllipse::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);  
   
    this->CalcCenterPoint(); 
    this->CalcCenterRECT(); 
 
   ::InvalidateRect(g_hwnd,&m_rect,true); 
 
	m_operStatus=FirstOper; 
} 
 
void CEllipse::MirrorSelf(HDC &hdc, double angle, CSuperPoint &ptPos) 
{ 
	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].MirrorOnAxis(angle,ptPos); 
		m_centerpoint.MirrorOnAxis(angle,ptPos); 
	}	 
	 PreDraw(hdc);  
 
} 
 
void CEllipse::ZoomSelf(HDC &hdc, double scale) 
{ 
	 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].ZoomIn(scale,m_centerpoint); 
//		m_centerpoint.ZoomIn(scale,this->GetCenterPoint()); 
	}	 
	 PreDraw(hdc);  
} 
 
void CEllipse::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); 
		} 
 
 
	POINT PT[13]; 
	for(int i=0;i<13;i++) 
	{ 
		PT[i]=m_point[i].GetPoint(); 
	} 
	PolyBezier(hdc, PT, 13); 
} 
 
CEllipse::CEllipse(POINT *point, int ptcount, LOGPEN &pen, LOGBRUSH &brush):CShape() 
{ 
	for(int nI=0;nI<ptcount;nI++) 
  { 
	  m_point[nI]=point[nI]; 
  } 
 
	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=ptcount; 
	this->m_whatshape=Ellipse; 
	this->CalcCenterPoint(); 
	this->CalcCenterRECT(); 
 
}