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


 
#include "stdafx.h" 
#include "MirrorTool.h" 
 
extern CList<CShape *> m_list; 
 
CMirrorTool::CMirrorTool(HWND hWnd) 
    :CTool(hWnd),m_mirroline(hWnd,true),m_copyshape(NULL) //对称轴不是我们要划的图形不需要保存 
{ 
     
 
} 
 
CMirrorTool::~CMirrorTool() 
{ 
 
} 
 
void CMirrorTool::OnLButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
  m_mirroline.OnLButtonDown(wParam,lParam); 
   
  POINT curPoint; 
  curPoint.x = LOWORD(lParam); 
  curPoint.y = HIWORD(lParam); 
 
  switch(m_status) 
  { 
  case NoClick: 
	  { 
		  m_catchShapeList.DeleteAll();    //清空镜像图形链表 
 
        for(int nI=0;nI<m_list.GetCount();nI++) 
        { 
			if( m_list[nI].node->IsLock() ) //如果是个选中的图形 
               { 
				   m_copyshape = m_list[nI].node->GetShapeCopy(); 
				   m_catchShapeList.AddTail(m_copyshape);		        //设置将要转动的几何图形 
				 			        
				   m_status=FirstClick; 
				   m_begPT=curPoint; 
				   m_oldPT=curPoint; 
			} 
		} 
		break;                     
	  } 
  case FirstClick:	   
	  { 
          HDC hdc=GetDC(m_hWnd);  
		  for(int nJ=0;nJ<m_catchShapeList.GetCount();nJ++) 
			  {	   
				m_catchShapeList[nJ].node->EnterOper(hdc); 
				m_list.AddTail(m_catchShapeList[nJ].node); 
			  } 
		  m_catchShapeList.DeleteAll(); 
		  m_status=NoClick; 
		   
         ::InvalidateRect(m_hWnd,NULL,true); 
         ReleaseDC(m_hWnd,hdc); 
         m_list.SetEditStatus(true); 
	  } 
      break; 
  } 
 
} 
 
void CMirrorTool::OnMouseMove(WPARAM wParam,LPARAM lParam) 
{ 
	HDC hdc=GetDC(m_hWnd); 
	 
	if((m_catchShapeList.GetCount())!=0)      //遍历到有已经选种的图形 
   
	{ 
		       
	       m_mirroline.OnMouseMove(wParam,lParam); 
		    
		   POINT curPoint; 
		   curPoint.x = LOWORD(lParam); 
		   curPoint.y = HIWORD(lParam); 
 
		   m_endPT=curPoint; 
 
		   double angleX=m_endPT.AngleWithX(m_begPT);    //镜象轴与X轴的夹角 
 
		   for(int nI=0;nI<m_catchShapeList.GetCount();nI++) 
		   { 
			 m_catchShapeList[nI].node->MirrorSelf(hdc,angleX,m_endPT); 
		   } 
   
	   } 
 
	ReleaseDC(m_hWnd,hdc); 
} 
 
void CMirrorTool::OnRButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
   HDC m_hdc = GetDC(m_hWnd); 
	m_mirroline.OnLButtonDown(wParam,lParam); 
	int iCount = m_catchShapeList.GetCount(); 
	for( int i = 0 ; i < iCount; i++) 
	{ 
		m_catchShapeList[i].node->RollBackOper(m_hdc); 
	} 
	m_catchShapeList.DeleteAll(); 
 
	if( m_status == FirstClick ) 
	{ 
		m_status = NoClick; 
 
        ::InvalidateRect(m_hWnd,NULL,true); 
	     
	} 
	 
    ReleaseDC(m_hWnd,m_hdc); 
 
}