www.pudn.com > my2cadtest07261930.rar > CatchTool.cpp, change:2006-07-22,size:3324b


 
 
#include "stdafx.h" 
#include "CatchTool.h" 
#include "list.h" 
 
#include "Line.h" 
#include "AnyPolygon.h" 
 
#include "Shape.h" 
 
extern CList<CShape *> m_list; 
 
CCatchTool::CCatchTool(HWND hWnd):CTool(hWnd),m_catchID(-1) 
{ 
 
} 
 
CCatchTool::~CCatchTool() 
{ 
 
} 
 
void CCatchTool::OnMouseMove(WPARAM wParam,LPARAM lParam) 
{ 
	m_hdc=::GetDC(m_hWnd); 
    CSuperPoint curPT(LOWORD(lParam),HIWORD(lParam)); 
     
	if(m_status!=FirstClick) 
	{ 
	 
		for(int i=0;i<m_list.GetCount();i++) 
			{ 
				if(!m_list[i].node->IsBound(curPT)) 
				{ 
					m_list[i].node->ClearMark(m_hdc); 
					m_catchID=-1; 
					 
				} 
				else 
				{ 
					m_list[i].node->SetMark(m_hdc); 
					m_catchID=i; 
					break;             
				} 
			} 
	} 
    else 
    { 
		m_endPT=curPT; 
		penattrib->GetPen(m_hdc,true); 
        this->DrawCatchRect(m_hdc); 
        penattrib->ReleasePen(true); 
    } 
 
 
	::ReleaseDC(m_hWnd,m_hdc); 
 
} 
     
void  CCatchTool::DrawCatchRect(HDC &hdc) 
{ 
      ::Rectangle(hdc,m_begPT.GetPoint().x,m_begPT.GetPoint().y, 
		m_oldPT.GetPoint().x,m_oldPT.GetPoint().y); 
     
	  ::Rectangle(hdc,m_begPT.GetPoint().x,	m_begPT.GetPoint().y, 
		m_endPT.GetPoint().x,m_endPT.GetPoint().y); 
 
     	m_oldPT = m_endPT; 
	 
} 
 
void CCatchTool::OnLButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
	HDC m_hdc=::GetDC(m_hWnd); 
	if(m_catchID != -1) 
	   { 
			if(m_list[m_catchID].node->IsLock()) 
			{ 
			   m_list[m_catchID].node->UnLock(m_hdc); 
			} 
			else 
			{ 
			   m_list[m_catchID].node->Lock(m_hdc); 
			} 
		} 
     else 
	 { 
		  POINT curpt; 
		  curpt.x=LOWORD(lParam); 
		  curpt.y=HIWORD(lParam); 
		   
          switch(m_status) 
		  { 
		    case NoClick: 
                 m_begPT=m_endPT=m_oldPT=curpt; 
                 m_status=FirstClick; 
                 break; 
    
		  } 
 
	 } 
	::ReleaseDC(m_hWnd,m_hdc); 
} 
 
void CCatchTool::OnLButtonUp(WPARAM wParam,LPARAM lParam) 
{ 
  if(m_status==FirstClick) 
	  { 
		  m_status=NoClick; 
 
           
		   
		  this->CalcRECT(); 
		  ::InvalidateRect(m_hWnd,&m_catchRect,true); 
      
		  for(int i=0;i<m_list.GetCount();i++) 
			  { 
					RECT tmpRect; 
					 tmpRect= m_list[i].node->GetRECT(); 
 
					bool bool1 = ( m_catchRect.bottom >= (tmpRect.bottom-5)) ; 
					bool bool2 = ( m_catchRect.left   <= (tmpRect.left+5)); 
					bool bool3 = (m_catchRect.right  >= (tmpRect.right-5)); 
					bool bool4 = (m_catchRect.top    <= (tmpRect.top+5)); 
					if((bool1)&&(bool2)&&(bool3)&&(bool4)) 
					{ 
				         
						if(!m_list[i].node->IsLock()) 
						{						 
								m_list[i].node->SetMark(m_hdc); 
								m_list[i].node->Lock(m_hdc); 
						} 
					    else 
						{ 
                            m_list[i].node->UnLock(m_hdc); 
						} 
 
                    } 
			  } 
 
	  } 
 
} 
   
 
void CCatchTool::CalcRECT() 
{ 
 
    UINT Top; 
	UINT Left; 
	UINT Bottom; 
	UINT Right; 
	POINT pt[2]; 
    pt[0] = m_begPT.GetPoint(); 
    pt[1] = m_endPT.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_catchRect.left = Left-5; 
	m_catchRect.top  = Top-5; 
	m_catchRect.right = Right+5; 
	m_catchRect.bottom = Bottom+5; 
 
}