www.pudn.com > my2cadtest07261930.rar > Line.cpp, change:2006-07-26,size:6008b


#include "stdafx.h" 
#include "Line.h" 
 
CLine::CLine(CSuperPoint begPT,CSuperPoint endPT):CShape() 
{ 
  this->m_whatshape=Line;	 
  m_point[0]=begPT; 
  m_point[1]=endPT; 
  m_pointcount=2; 
  this->CalcCenterPoint(); 
  this->CalcCenterRECT(); 
} 
 
CLine::CLine(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=Line; 
	this->CalcCenterPoint(); 
	this->CalcCenterRECT(); 
 
} 
 
void CLine::CalcCenterRECT() 
{ 
    UINT Top; 
	UINT Left; 
	UINT Bottom; 
	UINT Right; 
	POINT pt[2]; 
 
	for( int nI = 0; nI < 2; nI++ ) 
	{ 
		pt[nI] = m_point[nI].GetPoint(); 
	} 
 
	Left = (( pt[0].x < pt[1].x )? pt[0].x : pt[1].x ); 
 
	Right = (( pt[0].x > pt[1].x )? pt[0].x: pt[1].x ); 
 
	Top = (( pt[0].y < pt[1].y )? pt[0].y : pt[1].y ); 
 
	Bottom = (( pt[0].y > pt[1].y )? pt[0].y : pt[1].y ); 
 
	m_rect.left = Left - 8; 
	m_rect.top  = Top - 8; 
	m_rect.right = Right + 8; 
	m_rect.bottom = Bottom + 8; 
	 
} 
 
 
 
void CLine::CalcCenterPoint() 
{ 
  POINT curpoint; 
  curpoint.x=(m_point[0].GetPoint().x+m_point[1].GetPoint().x)/2; 
  curpoint.y=(m_point[0].GetPoint().y+m_point[1].GetPoint().y)/2;	 
  m_centerpoint=curpoint; 
} 
 
void CLine::PreDraw(HDC &hdc) 
{ 
   
    ::MoveToEx(hdc,m_copypoint[0].GetPoint().x,m_copypoint[0].GetPoint().y,NULL);		 
	::LineTo(hdc,m_copypoint[1].GetPoint().x,m_copypoint[1].GetPoint().y); 
 
} 
 
 
CLine::~CLine() 
{ 
 
} 
 
CShape * CLine::GetShapeCopy() 
{ 
  CShape * pcopy=new CLine; 
  *pcopy=*this;   //值拷贝 
   
  return pcopy ; 
 
} 
 
 
bool CLine::IsBound(CSuperPoint &curPt) 
{ 
	 
 return curPt.IsOnLine(m_point[0],m_point[1]); 
 
} 
 
void CLine::SetMark(HDC &hdc) 
{ 
	m_point[0].SetMark(hdc); 
	m_point[1].SetMark(hdc); 
} 
 
void CLine::ClearMark(HDC &hdc) 
{ 
	m_point[0].ClearMark(hdc); 
	m_point[1].ClearMark(hdc); 
} 
 
void CLine::Lock(HDC &hdc) 
{ 
	this->m_selected = true;	//已锁定 
	m_point[0].SetLockMark(hdc); 
	m_point[1].SetLockMark(hdc); 
} 
 
void CLine::UnLock(HDC &hdc) 
{ 
	this->m_selected = false; 
	m_point[0].ClearLockMark(hdc); 
	m_point[1].ClearLockMark(hdc); 
 
} 
 
void CLine::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); 
 
  this->CalcCenterPoint(); 
  this->CalcCenterRECT(); 
  ::InvalidateRect(g_hwnd,&m_rect,true); 
   
	m_operStatus=FirstOper; 
    penattrib->ReleasePen(false); 
 
  
} 
 
void CLine::DrawSelf(HDC &hdc) 
{ 
	 
  ::MoveToEx(hdc,m_point[0].GetPoint().x,m_point[0].GetPoint().y,NULL);		 
  ::LineTo(hdc,m_point[1].GetPoint().x,m_point[1].GetPoint().y);	 
   if(m_selected)   //如果这是一个被选中图形 在操作后的图形上打上标记 
   { 
    m_point[0].SetStatus(); 
    m_point[1].SetStatus(); 
    SetMark(hdc); 
    Lock(hdc); 
   } 
} 
 
void CLine::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[2]; 
	for(int nI=0;nI<m_pointcount;nI++) 
	{ 
      pt[nI]=m_point[nI].GetPoint(); 
	}	 
	::Polygon(hdc,pt,m_pointcount); 
	 
//  ::MoveToEx(hdc,m_point[0].GetPoint().x,m_point[0].GetPoint().y,NULL);		 
//  ::LineTo(hdc,m_point[1].GetPoint().x,m_point[1].GetPoint().y); 
           
} 
 
 
 
 
void CLine::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); 
	}	 
	 PreDraw(hdc);  
 
    penattrib->ReleasePen(true); 
 
} 
 
void CLine::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); 
	}	 
	 PreDraw(hdc);  
    penattrib->ReleasePen(true); 
} 
 
 
void CLine::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(m_centerpoint,angle); 
	}	 
	 PreDraw(hdc);  
 
    penattrib->ReleasePen(true); 
} 
 
 
void CLine::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); 
	}	 
	 PreDraw(hdc);  
 
    penattrib->ReleasePen(true); 
}