📄 selecttool.cpp
字号:
// SelectTool.cpp: implementation of the CSelectTool class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Pointtest.h"
#include "SelectTool.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSelectTool::CSelectTool(CWnd* cWnd,CElist* pList,CPointList* pOintList,CLineList* pLineList,CTextList* pText)
:CBaseTool(cWnd,pList,pOintList,pLineList,pText)
{
SelectedPoint = NULL;
SelectedPoint1 = NULL;
PointSelect = FALSE;
ObSelect = FALSE;
ControlKey = FALSE;
ArrowSelect = FALSE;
for(int i=0;i<3;i++)
cell[i] = "";
}
CSelectTool::~CSelectTool()
{
}
void CSelectTool::OnLButtonDown(UINT nFlags, CPoint point)
{
CanDraw = TRUE;
CaptureScr();
CDC* pDC = m_pWnd->GetDC();
ControlKey = (MK_CONTROL & nFlags);
ObSelect = m_pList->PtInGraph(point,ControlKey);
TextSelect = m_pTextList->PtInGraph(point,ControlKey);
ArrowSelect = m_pList->PtInArrow(point);
if(ArrowSelect){
}else if(ObSelect||TextSelect){//select element
if(SelectedPoint)
SelectedPoint = NULL;
Draw();
}else if(PointSelect){//select point
if(SelectedPoint){
Draw();
pDC->MoveTo(SelectedPoint->CenterPoint);
pDC->LineTo(point);
}
}else{
ObSelect = m_pLineList->PtInGraph(point,ControlKey);
if(ObSelect){
Draw();
}
}
BeginPoint = point;//passed
//Draw();
m_pWnd->ReleaseDC(pDC);
}
void CSelectTool::OnLButtonUp(UINT nFlags, CPoint point)
{
if(!CanDraw) return;
CanDraw = FALSE;
if(ObSelect||TextSelect){
if(SelectedPoint)
SelectedPoint = NULL;
// EndPoint = point;
// m_pList->MoveSelected(EndPoint-BeginPoint);
// m_pTextList->MoveSelected(EndPoint-BeginPoint);
// BeginPoint = EndPoint;
m_pTextList->ReSetMoveFlag();
Draw();
}else if(PointSelect){
if(SelectedPoint){
SelectedPoint1 = m_PointList->PtInGraph(point);
if((SelectedPoint1!=SelectedPoint)&&SelectedPoint1){
m_pLine = new CLine(SelectedPoint,SelectedPoint1,m_pLineList);
SelectedPoint->AddSon(m_pLine);
SelectedPoint1->AddSon(m_pLine);
}
SelectedPoint = NULL;
SelectedPoint1 = NULL;
}
}else{
EndPoint = point;
m_pList->ObInRegion(GetRect(BeginPoint,EndPoint));
}
ReleaseScr();
Draw();
}
void CSelectTool::OnMouseMove(UINT nFlags, CPoint point)
{
if(!CanDraw){
m_PointList->DeSelect();
SelectedPoint = m_PointList->PtInGraph( point );
if(!SelectedPoint)
PointSelect = FALSE;
Draw();
}
if(CanDraw){
if(ArrowSelect){
EndPoint = point;
m_pList->MovePoint(point,EndPoint-BeginPoint);
BeginPoint = EndPoint;
Draw();
}else if(ObSelect||TextSelect){
if(SelectedPoint)
SelectedPoint = NULL;
EndPoint = point;
m_pList->MoveSelected(EndPoint-BeginPoint);
m_pTextList->MoveSelected(EndPoint-BeginPoint);
BeginPoint = EndPoint;
Draw();
}else if(PointSelect){
if(SelectedPoint){
SelectedPoint1 = m_PointList->PtInGraph(point);
Draw();
CDC* pDC = m_pWnd->GetDC();
pDC->MoveTo(SelectedPoint->CenterPoint);
pDC->LineTo(point);
m_pWnd->ReleaseDC(pDC);
}
}else{
EndPoint = point;//passed
Draw(BeginPoint,EndPoint);
}
}else if(SelectedPoint){
PointSelect = TRUE;
}
}
void CSelectTool::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CBase* aa;
UINT nId;
aa = m_pList->PtDbInGraph(point);
if(aa){
if(GetCellString(aa)){
CPropertiy dlg(cell[0]);
dlg.m_value = aa->Value;
dlg.m_properte = cell[1];
dlg.m_unit = cell[2];
dlg.m_remark = aa->Content_Of_Ob;
nId = aa->GetType();
if(nId==ID_RHEOSTAT||nId==ID_VOLTAGE_METER||nId==ID_CURRENT_METER){
dlg.m_MaxValue = aa->MaxValue;
}
if(IDOK == dlg.DoModal()){
aa->Value = dlg.m_value;
aa->Content_Of_Ob = dlg.m_remark;
if(nId==ID_RHEOSTAT||nId==ID_VOLTAGE_METER||nId==ID_CURRENT_METER){
aa->MaxValue = dlg.m_MaxValue;
aa->SetEValue();
}
}
}
}
}
BOOL CSelectTool::GetCellString(CBase* aa)
{
switch(aa->GetType()){
case ID_RESISTANCE:
cell[0] = "电阻属性";
cell[1] = "电阻阻值";
cell[2] = "欧姆";
break;
case ID_RHEOSTAT:
cell[0] = "变阻器属性";
cell[1] = "变阻器阻值";
cell[2] = "欧姆";
break;
case ID_CAPACITANCE:
cell[0] = "电容属性";
cell[1] = "电容值";
cell[2] = "微法";
break;
case ID_DIODE:
cell[0] = "二极管属性";
cell[1] = "二极管正向阻值";
cell[2] = "欧姆";
break;
case ID_GROUND:
cell[0] = "接地属性";
cell[1] = "接地内阻值";
cell[2] = "欧姆";
break;
case ID_INDUCTANCE:
cell[0] = "电感属性";
cell[1] = "电感值";
cell[2] = "亨";
break;
case ID_VOLTAGE_METER:
cell[0] = "电压表属性";
cell[1] = "电压表内阻值";
cell[2] = "欧姆";
break;
case ID_CURRENT_METER:
cell[0] = "电流表属性";
cell[1] = "电流表内阻值";
cell[2] = "欧姆";
break;
case ID_SWITCH:
cell[0] = "开关属性";
cell[1] = "开关内阻值";
cell[2] = "欧姆";
break;
case ID_POWER:
cell[0] = "电源属性";
cell[1] = "电源电压值";
cell[2] = "伏特";
break;
case ID_LIGHT:
cell[0] = "电灯属性";
cell[1] = "电灯阻值";
cell[2] = "欧姆";
break;
default:
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -