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


 
#include "stdafx.h" 
#include "RotateTool.h" 
 
extern CList<CShape *> m_list; 
 
CRotateTool::CRotateTool(HWND hWnd):CTool(hWnd) 
{ 
 
} 
 
CRotateTool::~CRotateTool() 
{ 
 
} 
 
void CRotateTool::OnLButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
  POINT curPT; 
 curPT.x=LOWORD(lParam); 
 curPT.y=HIWORD(lParam); 
  
 switch (m_status) 
 { 
 case NoClick: 
	 { 
		 for(int nI=0;nI<m_list.GetCount();nI++)  //单个图形操作 
			 { 
				 if(m_list[nI].node->IsLock())       
				 { 
					   for(int nJ=0;nJ<m_list[nI].node->GetPointCount();nJ++) 
						   { 
							   int distance=m_list[nI].node->GetPointArr()[nJ].DistanceTo(curPT); 
							   if(distance<6) 
								   { 
									 m_catchShape=m_list[nI].node; 
 
									 m_catchShapeList.AddTail(m_catchShape); 
 
									 m_begPT=curPT; 
									 m_status=FirstClick; 
									 return; 
								   } 
							    
						   }                  					    
				 } 
			 } 
 
          for( nI=0;nI<m_list.GetCount();nI++)  //多图一起操作 
			 { 
				 if(m_list[nI].node->IsLock())       
				 { 
					m_catchShape=m_list[nI].node; 
					m_catchShapeList.AddTail(m_catchShape); 
                    m_begPT=curPT; 
					m_status=FirstClick; 
				 } 
			 } 
 
	 } 
 break; 
 case FirstClick: 
	 if( m_catchShapeList.GetCount()!=0 ) 
		{        
		  for(int i=0;i<m_catchShapeList.GetCount();i++) 
		  { 
		    m_catchShapeList[i].node->EnterOper(m_hdc);			 
		  }	 
          m_catchShapeList.DeleteAll(); 
          m_catchShape=NULL; 
          ReleaseDC(m_hWnd,m_hdc); 
		} 
		m_status = NoClick;	 
		m_list.SetEditStatus(true); 
		break; 
 } 
 return;	 
} 
 
void CRotateTool::OnMouseMove(WPARAM wParam,LPARAM lParam) 
{ 
     
    POINT curPoint; 
    curPoint.x = LOWORD(lParam); 
    curPoint.y = HIWORD(lParam); 
    this->m_endPT = curPoint; 
     
  
	if( m_catchShapeList.GetCount()!=0 )          //有抓住图形 
	{        
		//计算鼠标前次点与图形中心点的连线与X轴的夹角 
		double angleOrg= m_begPT.AngleWithX(m_catchShape->GetCenterPoint()); 
		 
		//计算鼠标当前点与图形中心点的连线与X轴的夹角 
		double angleNew = m_endPT.AngleWithX(m_catchShape->GetCenterPoint()); 
		 
		//旋转角度 
		double dbAngle = (double)(angleNew - angleOrg) ; 
		 
		//图形旋转 
       HDC m_hdc = GetDC(m_hWnd); 
       for(int i=0;i<m_catchShapeList.GetCount();i++) 
	   { 
		   m_catchShapeList[i].node->RotateSelf(m_hdc,dbAngle);	 
	   } 
 
	} 
	else 
	{ 
	 return;	  
	} 
 
} 
 
void CRotateTool::OnRButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
   HDC m_hdc = GetDC(m_hWnd); 
	for(int i=0;i<m_catchShapeList.GetCount();i++) 
	{ 
		m_catchShapeList[i].node->RollBackOper(m_hdc); 
	} 
          m_catchShapeList.DeleteAll(); 
          m_catchShape=NULL; 
	m_status = NoClick; 
    ReleaseDC(m_hWnd,m_hdc); 
	 
}