⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawchipview.cpp

📁 本人买的<<VC++项目开发实例>>源代码配套光盘.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	m_bSwitch = FALSE;
	m_bDiode = FALSE;
	m_bInductor = FALSE;
	m_bIcChip = FALSE;
	m_bPaSocket = FALSE;
	m_bCrSocket = FALSE;
	LONG Cur; 
	
	Cur = (LONG)((CDrawChipApp*)AfxGetApp())->LoadStandardCursor(IDC_ARROW);// LoadCursor(IDC_DRAW_RESISTOR);	
	ASSERT(Cur);
	::SetClassLong(this->m_hWnd,GCL_HCURSOR,Cur);	
}

//##ModelId=3C466BA6039F
void CDrawChipView::OnUpdateDrawNothing(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_bNothing);
}

//##ModelId=3C466BA7013D
void CDrawChipView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	/*根据当前的状态决定做的事情*/
	CClientDC dc(this);
	OnPrepareDC(&dc);
	//lpPoint存放当前鼠标点按点的逻辑坐标
	CPoint *lpPoint = new CPoint(point);		
	//lpPoint->x = point.x;	
	//lpPoint->y = point.y;
	dc.DPtoLP(lpPoint);

	int x = lpPoint->x;
	int y = lpPoint->y;

	CDrawChipDoc *pDoc = GetDocument();
	CObList *pObList = &(pDoc->m_ChipObList);
	CObList *pTempObList = &(pDoc->m_ChipObList);
	POSITION CurPos = NULL;//如果点按在元器件上,它才有意义,它就是这个被点按的元器件在链表中的位置
	BOOL IsSel = FALSE;//如果点按在元器件上,它才有意义,它就是这个被点按的元器件的IsSelected属性值
	BOOL IsInChip =FALSE;
	IsInChip = IsInChipRect(point,pObList,&CurPos,&IsSel);
	int iBeSelCount = BeSelectedNum(pObList);
	CRect rectInvalidate;//存放更新的区域
	CString strName;
	CSize Textsize;//记录元器件对象名称字符的宽度和高度

	
	if (m_bResistor)
	//当前处于绘制电阻状态
	{
		CResistor *pResistor = new CResistor(lpPoint);		
		AddChipToList(pResistor,pObList);

		strName = pResistor->GetName();		
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);		
		rectInvalidate = pResistor->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;

		dc.LPtoDP(&rectInvalidate);		
	}
	if (m_bCompacity)
	//当前处于绘制电容状态
	{
		CCompacity *pCompacity = new CCompacity(lpPoint);		
		AddChipToList(pCompacity,pObList);

		strName = pCompacity->GetName();
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pCompacity->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;		
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		dc.LPtoDP(&rectInvalidate);
	}
	if (m_bSwitch)
	//当前处于绘制开关状态
	{
		CSwitch *pSwitch = new CSwitch(lpPoint);		
		AddChipToList(pSwitch,pObList);

		strName = pSwitch->GetName();
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pSwitch->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		dc.LPtoDP(&rectInvalidate);
	}	
	if (m_bDiode)
	//当前处于绘制二极管状态
	{
		CDiode *pDiode = new CDiode(lpPoint);
		AddChipToList(pDiode,pObList);

		strName = pDiode->GetName();
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pDiode->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		dc.LPtoDP(&rectInvalidate);
	}
	if (m_bInductor)
	//当前处于绘制电感状态
	{
		CInductor *pInductor = new CInductor(lpPoint);		
		AddChipToList(pInductor,pObList);

		strName = pInductor->GetName();
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pInductor->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		dc.LPtoDP(&rectInvalidate);
	}
	if (m_bPower)
	//当前处于绘制电感状态
	{
		CPower *pPower = new CPower(lpPoint);		
		AddChipToList(pPower,pObList);
		strName = pPower->GetName();
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pPower->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		dc.LPtoDP(&rectInvalidate);
	}
	if (m_bIcChip)
	//当前处于绘制电感状态
	{
		CIcChip *pIcChip = new CIcChip(lpPoint);		
		AddChipToList(pIcChip,pObList);
		strName = pIcChip->GetName();
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pIcChip->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		dc.LPtoDP(&rectInvalidate);
	}
	if (m_bPaSocket)
	//当前处于绘制平行插座状态
	{		
		CPaSocket *pPaSocket = new CPaSocket(lpPoint);
		AddChipToList(pPaSocket,pObList);
		strName = pPaSocket->GetName();		
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pPaSocket->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		//TRACE("%s, %d, %d\n", strName, Textsize.cx, Textsize.cy);
		dc.LPtoDP(&rectInvalidate);
	}

	if (m_bCrSocket)
	//当前处于绘制平行插座状态
	{		
		CCrSocket *pCrSocket = new CCrSocket(lpPoint);
		AddChipToList(pCrSocket,pObList);
		strName = pCrSocket->GetName();		
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pCrSocket->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		dc.LPtoDP(&rectInvalidate);
	}
	if (m_bTransistor)
	//当前处于绘制三极管状态
	{		
		CTransistor *pTransistor = new CTransistor(lpPoint);
		AddChipToList(pTransistor ,pObList);
		strName = pTransistor ->GetName();		
		::GetTextExtentPoint32(dc, (const char *)&strName, strName.GetLength(), &Textsize);
		rectInvalidate = pTransistor ->m_Rect;		
		rectInvalidate.bottom = rectInvalidate.bottom - Textsize.cy;//+ Textsize.cy;
		rectInvalidate.right = rectInvalidate.right + Textsize.cx;
		dc.LPtoDP(&rectInvalidate);
	}


	pDoc->SetModifiedFlag(TRUE);

	if (m_bNothing)
	//当前处于选择状态
	{
		if (nFlags & MK_SHIFT)
		//shift按下
		{
			if (!IsInChip)//点在空白处
			{
				if (iBeSelCount == 0)
				{
					goto End;//点在空白处,而且当前没有被选中的,所以不用更新屏幕
				}
				else
					SetAllChipNotIsSel(pObList);				
			}
			else         //点在元器件处
			{				
				CComponent *pComponent;
				pComponent = (CComponent *)pObList->GetAt(CurPos);
				if (IsSel)//当前点按的元器件已经处于选中状态
				{					
					pComponent->SetIsSelected(FALSE);					
				}
				else     //当前点按的元器件没有处于选中状态
				{
					pComponent->SetIsSelected(TRUE);
				}				
			}
			Invalidate();
			goto End;
		}
		else
		//shift没有按下
		{
			if (!IsInChip)//点在空白处
			{
				if (iBeSelCount == 0)
				{
					//点在空白处,而且没有被选中的,所以不用更新屏幕
				}
				else
				{
					SetAllChipNotIsSel(pObList);
					Invalidate();				
				}
				goto End;
			}
			else         //点在元器件处
			{
				CResistor *pResistor;
				CCompacity *pCompacity;
				CSwitch *pSwitch;
				CDiode *pDiode;
				CInductor *pInductor;
				CPower *pPower;
				CIcChip *pIcChip;
				CPaSocket *pPaSocket;
				CCrSocket *pCrSocket;
				CTransistor *pTransistor;

				CComponent *pComponent;
				pComponent = (CComponent *)pObList->GetAt(CurPos);
				if (IsSel)//当前点按的元器件已经处于选中状态
				{
					if (iBeSelCount>=2)//当前链表中处于选中状态的有多个
					{
						//做集体移动
						int orgX = point.x ;
						int orgY= point.y;	
						int xPos,yPos;
						int deltaX,deltaY;						
						POSITION tmpPos ; 
						CObject *tmpPObject;
						CResistor *tmpPResistor;
						CCompacity *tmpPCompacity;
						CSwitch *tmpPSwitch;
						CDiode *tmpPDiode;
						CInductor *tmpPInductor;
						CPower *tmpPPower;
						CIcChip *tmpPIcChip;
						CPaSocket *tmpPPaSocket;
						CCrSocket *tmpPCrSocket;
						CTransistor *tmpPTransistor;

						int left,top,right,bottom;
						CRect tmpRect;
						MSG msg;
						this->SetCapture();
						AfxLockTempMaps();
						for(;;)
						{
							if(this->GetCapture() != this)
							{
								::ReleaseCapture();
								AfxUnlockTempMaps();
								break;
							}
							::GetMessage(&msg, this->m_hWnd, 0, 0);
							::TranslateMessage(&msg);	
							
							switch(msg.message)
							{
							case WM_LBUTTONUP:
								::ReleaseCapture();
								AfxUnlockTempMaps();							
								break;
							case WM_MOUSEMOVE:								
								//计算各个元器件的偏移				
								
								xPos = msg.pt.x;
								yPos = msg.pt.y;								
								//xPos = GET_X_LPARAM(msg.lParam); 
								//yPos = GET_Y_LPARAM(msg.lParam); 
								deltaX = xPos - orgX;
								deltaY = yPos - orgY;//point.y - orgY;
								
								/*遍历链表,把链表中处于选中状态的元器件图形的位置做修改*/
								tmpPos  = pObList->GetHeadPosition();
								while ( tmpPos != NULL)
								{
									tmpPObject = pObList->GetAt(tmpPos);						
									
									if (tmpPObject->IsKindOf(RUNTIME_CLASS(CResistor)))
									{
										tmpPResistor = (CResistor *)tmpPObject;
										if (tmpPResistor->GetIsSelected())
										//如果这个元器件处于选中状态
										{											
											top = tmpPResistor->m_Rect.top;
											left = tmpPResistor->m_Rect.left;
											right = tmpPResistor->m_Rect.right;
											bottom = tmpPResistor->m_Rect.bottom;
											tmpRect = CRect(left,top,right,bottom);
											dc.LPtoDP(tmpRect);
											tmpRect.OffsetRect(deltaX,deltaY);
											tmpPResistor->m_RectTracker.m_rect = tmpRect;
											dc.DPtoLP(tmpRect);
											tmpPResistor->m_Rect = tmpRect;
											tmpPResistor->m_RectLP = tmpRect;										
										}
									}
									if (tmpPObject->IsKindOf(RUNTIME_CLASS(CCompacity)))
									{
										tmpPCompacity = (CCompacity *)tmpPObject;
										if (tmpPCompacity->GetIsSelected())
										//如果这个元器件处于选中状态
										{											
											top = tmpPCompacity->m_Rect.top;
											left = tmpPCompacity->m_Rect.left;
											right = tmpPCompacity->m_Rect.right;
											bottom = tmpPCompacity->m_Rect.bottom;
											tmpRect = CRect(left,top,right,bottom);
											dc.LPtoDP(tmpRect);
											tmpRect.OffsetRect(deltaX,deltaY);
											tmpPCompacity->m_RectTracker.m_rect = tmpRect;
											dc.DPtoLP(tmpRect);
											tmpPCompacity->m_Rect = tmpRect;
											tmpPCompacity->m_RectLP = tmpRect;
										}
									}
									if (tmpPObject->IsKindOf(RUNTIME_CLASS(CSwitch)))
									{
										tmpPSwitch = (CSwitch *)tmpPObject;
										if (tmpPSwitch->GetIsSelected())
										//如果这个元器件处于选中状态
										{										
											top = tmpPSwitch->m_Rect.top;
											left = tmpPSwitch->m_Rect.left;
											right = tmpPSwitch->m_Rect.right;
											bottom = tmpPSwitch->m_Rect.bottom;
											tmpRect = CRect(left,top,right,bottom);
											dc.LPtoDP(tmpRect);
											tmpRect.OffsetRect(deltaX,deltaY);
											tmpPSwitch->m_RectTracker.m_rect = tmpRect;
											dc.DPtoLP(tmpRect);
											tmpPSwitch->m_Rect = tmpRect;
											tmpPSwitch->m_RectLP = tmpRect;											
										}
									}
									if (tmpPObject->IsKindOf(RUNTIME_CLASS(CDiode)))
									{
										tmpPDiode = (CDiode *)tmpPObject;
										if (tmpPDiode->GetIsSelected())
										//如果这个元器件处于选中状态
										{										
											top = tmpPDiode->m_Rect.top;
											left = tmpPDiode->m_Rect.left;
											right = tmpPDiode->m_Rect.right;
											bottom = tmpPDiode->m_Rect.bottom;
											tmpRect = CRect(left,top,right,bottom);
											dc.LPtoDP(tmpRect);
											tmpRect.OffsetRect(deltaX,deltaY);
											tmpPDiode->m_RectTracker.m_rect = tmpRect;
											dc.DPtoLP(tmpRect);
											tmpPDiode->m_Rect = tmpRect;
											tmpPDiode->m_RectLP = tmpRect;											
										}
									}
									if (tmpPObject->IsKindOf(RUNTIME_CLASS(CInductor)))
									{
										tmpPInductor = (CInductor *)tmpPObject;
										if (tmpPInductor->GetIsSelected())
										//如果这个元器件处于选中状态
										{										
											top = tmpPInductor->m_Rect.top;
											left = tmpPInductor->m_Rect.left;
											right = tmpPInductor->m_Rect.right;
											bottom = tmpPInductor->m_Rect.bottom;
											tmpRect = CRect(left,top,right,bottom);
											dc.LPtoDP(tmpRect);
											tmpRect.OffsetRect(deltaX,deltaY);
											tmpPInductor->m_RectTracker.m_rect = tmpRect;
											dc.DPtoLP(tmpRect);
											tmpPInductor->m_Rect = tmpRect;
											tmpPInductor->m_RectLP = tmpRect;											
										}
									}
									if (tmpPObject->IsKindOf(RUNTIME_CLASS(CPower)))
									{
										tmpPPower = (CPower *)tmpPObject;
										if (tmpPPower->GetIsSelected())
										//如果这个元器件处于选中状态
										{										
											top = tmpPPower->m_Rect.top;
											left = tmpPPower->m_Rect.left;
											right = tmpPPower->m_Rect.right;
											bottom = tmpPPower->m_Rect.bottom;
											tmpRect = CRect(left,top,right,bottom);
											dc.LPtoDP(tmpRect);
											tmpRect.OffsetRect(deltaX,deltaY);
											tmpPPower->m_RectTracker.m_rect = tmpRect;
											dc.DPtoLP(tmpRect);
											tmpPPower->m_Rect = tmpRect;
											tmpPPower->m_RectLP = tmpRect;											
										}
									}
									if (tmpPObject->IsKindOf(RUNTIME_CLASS(CIcChip)))
									{
										tmpPIcChip = (CIcChip *)tmpPObject;
										if (tmpPIcChip->GetIsSelected())
										//如果这个元器件处于选中状态
										{										
											top = tmpPIcChip->m_Rect.top;
											left = tmpPIcChip->m_Rect.left;
											right = tmpPIcChip->m_Rect.right;
											bottom = tmpPIcChip->m_Rect.bottom;
											tmpRect = CRect(left,top,right,bottom);
											dc.LPtoDP(tmpRect);
											tmpRect.OffsetRect(deltaX,deltaY);
											tmpPIcChip->m_RectTracker.m_rect = tmpRect;
											dc.DPtoLP(tmpRect);
											tmpPIcChip->m_Rect = tmpRect;
											tmpPIcChip->m_RectLP = tmpRect;											
										}
									}
									if (tmpPObject->IsKindOf(RUNTIME_CLASS(CPaSocket)))
									{
										tmpPPaSocket = (CPaSocket *)tmpPObject;
										if (tmpPPaSocket->GetIsSelected())
										//如果这个元器件处于选中状态
										{										
											top = tmpPPaSocket->m_Rect.top;
											left = tmpPPaSocket->m_Rect.left;
											right = tmpPPaSocket->m_Rect.right;
											bottom = tmpPPaSocket->m_Rect.bottom;
											tmpRect = CRect(left,top,right,bottom);
											dc.LPtoDP(tmpRect);
											tmpRect.OffsetRect(deltaX,deltaY);
											tmpPPaSocket->m_RectTracker.m_rect = tmpRect;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -