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


// Curve.cpp: implementation of the CCurve class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Curve.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CCurve::CCurve() 
{ 
 
} 
 
CCurve::~CCurve() 
{ 
 
} 
 
void CCurve::CalcCenterPoint() 
{ 
	POINT tmpPt; 
	tmpPt.x=tmpPt.y=0; 
	for(int i=0;i<m_pointcount;i++) 
	{ 
		tmpPt.x+=m_point[i].GetPoint().x; 
		tmpPt.y+=m_point[i].GetPoint().y; 
	} 
	tmpPt.x=tmpPt.x/m_pointcount; 
	tmpPt.y=tmpPt.y/m_pointcount; 
	m_centerpoint=tmpPt; 
 
} 
 
void CCurve::CalcCenterRECT() 
{ 
	int maxX,maxY; 
	int minX,minY; 
	maxX=maxY=-1; 
	minX=minY=65536; 
	for(int i=0;i<m_pointcount;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 CCurve::ClearMark(HDC &hdc) 
{ 
	for(int nI=0;nI<m_pointcount;nI+=5) 
	   { 
		m_point[nI].ClearMark(hdc); 
	   } 
	m_centerpoint.ClearMark(hdc); 
 
} 
 
void CCurve::DrawSelf(HDC &hdc) 
{ 
	POINT PT[500]; 
	for(int i=0;i<m_pointcount;i++) 
	{ 
		PT[i]=m_point[i].GetPoint(); 
	} 
	Polyline(hdc, PT, m_pointcount); 
 
	if(m_selected)   //如果这是一个被选中图形 在操作后的图形上打上标记 
   { 
    for(int i=0;i<m_pointcount;i++) 
		{ 
		 m_point[i].SetStatus(); 
		} 
	 m_centerpoint.SetStatus(); 
    SetMark(hdc); 
    Lock(hdc); 
	} 
	 
} 
 
void CCurve::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; 
 
} 
 
CShape* CCurve::GetShapeCopy() 
{ 
	CShape* pcopy=new CCurve; 
	*pcopy=*this;   //值拷贝 
 
	return pcopy ; 
 
} 
 
bool CCurve::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 CCurve::Lock(HDC &hdc) 
{ 
	this->m_selected = true;	//已锁定 
	for(int nI=0;nI<m_pointcount;nI+=5) 
	{ 
	 m_point[nI].SetLockMark(hdc); 
	} 
	m_centerpoint.SetLockMark(hdc); 
 
} 
 
void CCurve::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 CCurve::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 CCurve::PreDraw(HDC &hdc) 
{ 
	POINT PT[500]; 
	for(int i=0;i<m_pointcount;i++) 
	{ 
		PT[i]=m_copypoint[i].GetPoint(); 
	} 
	Polyline(hdc, PT, m_pointcount); 
 
} 
 
void CCurve::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);  
 
} 
 
void CCurve::SetMark(HDC &hdc) 
{ 
	for(int nI=0;nI<m_pointcount;nI+=5) 
	{ 
		m_point[nI].SetMark(hdc); 
	} 
		m_centerpoint.SetMark(hdc); 
 
} 
 
void CCurve::UnLock(HDC &hdc) 
{ 
	this->m_selected = false; 
    for(int nI=0;nI<m_pointcount;nI+=5) 
	{ 
	 m_point[nI].ClearLockMark(hdc); 
	} 
	m_centerpoint.ClearLockMark(hdc); 
 
} 
 
void CCurve::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);  
 
} 
 
CCurve::CCurve(POINT *point, int ptcount):CShape() 
{ 
	this->m_whatshape=Curve; 
 
	for(int nI=0;nI<ptcount;nI++) 
	{ 
		m_point[nI]=point[nI]; 
	} 
	m_pointcount=ptcount; 
 
	this->CalcCenterPoint(); 
	this->CalcCenterRECT(); 
} 
 
void CCurve::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[500]; 
	for(int i=0;i<m_pointcount;i++) 
	{ 
		PT[i]=m_point[i].GetPoint(); 
	} 
	Polyline(hdc, PT, m_pointcount); 
 
} 
 
CCurve::CCurve(POINT *point, int ptcount, LOGPEN &pen, LOGBRUSH &brush) 
{ 
	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; 
*/ 
	this->m_whatshape=Curve; 
	for(int nI=0;nI<ptcount;nI++) 
	{ 
		m_point[nI]=point[nI]; 
	} 
	m_pointcount=ptcount; 
 
 
	this->CalcCenterPoint(); 
	this->CalcCenterRECT(); 
}